mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-06 19:00:27 +08:00
Add modular SPI-based serial LED driver that uses SPI MOSI to generate WS2812 timing waveforms. Uses 8-bit encoding at 6.4MHz SPI clock where each WS2812 bit becomes one SPI byte. SerialLED_SPI is a standalone class that can be composed into any RCOutput implementation. RCOutput_RPI provides the RCOutput wrapper for Raspberry Pi boards. Features: - Supports MODE_NEOPIXEL (GRB) and MODE_NEOPIXELRGB (RGB) color ordering - Up to 128 LEDs per channel - Uses /dev/spidev0.0 (GPIO10/pin 19) on Raspberry Pi - Thread-safe with mutex protection - Embedded object instead of heap allocation for SerialLED_SPI - Uses calloc/free for dynamic arrays (less overhead than new/delete)
70 lines
1.8 KiB
C++
70 lines
1.8 KiB
C++
/*
|
|
* Code by Andy Piper <github@andypiper.com>
|
|
*
|
|
* This file is free software: you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the
|
|
* Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This file is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* RCOutput driver for Raspberry Pi boards.
|
|
*/
|
|
#include "RCOutput_RPI.h"
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
namespace Linux {
|
|
|
|
void RCOutput_RPI::init()
|
|
{
|
|
#if HAL_LINUX_SERIALLED_ENABLED
|
|
// Initialize serial LED driver using SPI0
|
|
_serial_led.init("/dev/spidev0.0", 1);
|
|
#endif
|
|
}
|
|
|
|
bool RCOutput_RPI::set_serial_led_num_LEDs(const uint16_t chan, uint8_t num_leds, output_mode mode, uint32_t clock_mask)
|
|
{
|
|
#if HAL_LINUX_SERIALLED_ENABLED
|
|
if (!_serial_led.initialized()) {
|
|
return false;
|
|
}
|
|
return _serial_led.set_num_leds(chan, num_leds, mode);
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
bool RCOutput_RPI::set_serial_led_rgb_data(const uint16_t chan, int8_t led, uint8_t red, uint8_t green, uint8_t blue)
|
|
{
|
|
#if HAL_LINUX_SERIALLED_ENABLED
|
|
if (!_serial_led.initialized()) {
|
|
return false;
|
|
}
|
|
return _serial_led.set_rgb_data(chan, led, red, green, blue);
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
bool RCOutput_RPI::serial_led_send(const uint16_t chan)
|
|
{
|
|
#if HAL_LINUX_SERIALLED_ENABLED
|
|
if (!_serial_led.initialized()) {
|
|
return false;
|
|
}
|
|
return _serial_led.send(chan);
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
} // namespace Linux
|