From d9aa0c9cf062d1d428170ba4b9fcc0680a8c4e41 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 1 Mar 2023 13:57:09 +1100 Subject: [PATCH] AP_Notify: add defines for some AP_Notify LED libraries allow ProfiLEDs (serial and SPI) and NeoPixel to be compiled out --- libraries/AP_Notify/AP_Notify.cpp | 6 ++++++ libraries/AP_Notify/AP_Notify.h | 4 ++++ libraries/AP_Notify/AP_Notify_config.h | 18 ++++++++++++++++++ libraries/AP_Notify/NeoPixel.cpp | 9 +++++++-- libraries/AP_Notify/NeoPixel.h | 6 ++++++ libraries/AP_Notify/ProfiLED.cpp | 10 +++++++++- libraries/AP_Notify/ProfiLED.h | 15 +++++++++++++-- libraries/AP_Notify/SerialLED.cpp | 5 ++++- libraries/AP_Notify/SerialLED.h | 6 ++++++ 9 files changed, 73 insertions(+), 6 deletions(-) diff --git a/libraries/AP_Notify/AP_Notify.cpp b/libraries/AP_Notify/AP_Notify.cpp index 32cf337272..094412c03d 100644 --- a/libraries/AP_Notify/AP_Notify.cpp +++ b/libraries/AP_Notify/AP_Notify.cpp @@ -325,15 +325,21 @@ void AP_Notify::add_backends(void) ADD_BACKEND(new PCA9685LED_I2C()); break; #endif +#if AP_NOTIFY_NEOPIXEL_ENABLED case Notify_LED_NeoPixel: ADD_BACKEND(new NeoPixel()); break; +#endif +#if AP_NOTIFY_PROFILED_ENABLED case Notify_LED_ProfiLED: ADD_BACKEND(new ProfiLED()); break; +#endif +#if AP_NOTIFY_PROFILED_SPI_ENABLED case Notify_LED_ProfiLED_SPI: ADD_BACKEND(new ProfiLED_SPI()); break; +#endif case Notify_LED_OreoLED: #if AP_NOTIFY_OREOLED_ENABLED if (_oreo_theme) { diff --git a/libraries/AP_Notify/AP_Notify.h b/libraries/AP_Notify/AP_Notify.h index e73a32dc76..5649966f37 100644 --- a/libraries/AP_Notify/AP_Notify.h +++ b/libraries/AP_Notify/AP_Notify.h @@ -74,8 +74,12 @@ public: Notify_LED_NCP5623_I2C_External = (1 << 6), // External NCP5623 Notify_LED_NCP5623_I2C_Internal = (1 << 7), // Internal NCP5623 #endif +#if AP_NOTIFY_NEOPIXEL_ENABLED Notify_LED_NeoPixel = (1 << 8), // NeoPixel 5050 AdaFruit 1655 SK6812 Worldsemi WS2812B +#endif +#if AP_NOTIFY_PROFILED_ENABLED Notify_LED_ProfiLED = (1 << 9), // ProfiLED +#endif Notify_LED_Scripting = (1 << 10),// Colour accessor for scripting Notify_LED_DShot = (1 << 11),// Use dshot commands to set ESC LEDs Notify_LED_ProfiLED_SPI = (1 << 12), // ProfiLED diff --git a/libraries/AP_Notify/AP_Notify_config.h b/libraries/AP_Notify/AP_Notify_config.h index fdcace890c..14b5d3fc67 100644 --- a/libraries/AP_Notify/AP_Notify_config.h +++ b/libraries/AP_Notify/AP_Notify_config.h @@ -4,6 +4,7 @@ #if HAL_GCS_ENABLED #include #endif +#include #ifndef AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED #define AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED HAL_GCS_ENABLED @@ -21,6 +22,14 @@ #define AP_NOTIFY_PCA9685_ENABLED 1 #endif +#ifndef AP_NOTIFY_PROFILED_SPI_ENABLED +#define AP_NOTIFY_PROFILED_SPI_ENABLED 1 +#endif + +#ifndef AP_NOTIFY_SERIALLED_ENABLED +#define AP_NOTIFY_SERIALLED_ENABLED AP_SERIALLED_ENABLED +#endif + #ifndef AP_NOTIFY_TOSHIBALED_ENABLED #define AP_NOTIFY_TOSHIBALED_ENABLED 1 #endif @@ -28,3 +37,12 @@ #ifndef AP_NOTIFY_OREOLED_ENABLED #define AP_NOTIFY_OREOLED_ENABLED 0 #endif + +// Serial LED backends: +#ifndef AP_NOTIFY_PROFILED_ENABLED +#define AP_NOTIFY_PROFILED_ENABLED AP_NOTIFY_SERIALLED_ENABLED +#endif + +#ifndef AP_NOTIFY_NEOPIXEL_ENABLED +#define AP_NOTIFY_NEOPIXEL_ENABLED AP_NOTIFY_SERIALLED_ENABLED +#endif diff --git a/libraries/AP_Notify/NeoPixel.cpp b/libraries/AP_Notify/NeoPixel.cpp index d2f2bb884c..08a3fd16a5 100644 --- a/libraries/AP_Notify/NeoPixel.cpp +++ b/libraries/AP_Notify/NeoPixel.cpp @@ -13,8 +13,11 @@ along with this program. If not, see . */ -#include "AP_Notify/AP_Notify.h" #include "NeoPixel.h" + +#if AP_NOTIFY_NEOPIXEL_ENABLED + +#include "AP_Notify/AP_Notify.h" #include "SRV_Channel/SRV_Channel.h" // This limit is from the dshot driver rcout groups limit @@ -63,4 +66,6 @@ uint16_t NeoPixel::init_ports() } return mask; -} \ No newline at end of file +} + +#endif // AP_NOTIFY_NEOPIXEL_ENABLED diff --git a/libraries/AP_Notify/NeoPixel.h b/libraries/AP_Notify/NeoPixel.h index 801a8c7c7c..89c5266792 100644 --- a/libraries/AP_Notify/NeoPixel.h +++ b/libraries/AP_Notify/NeoPixel.h @@ -14,6 +14,10 @@ */ #pragma once +#include "AP_Notify_config.h" + +#if AP_NOTIFY_NEOPIXEL_ENABLED + #include "RGBLed.h" #include "SerialLED.h" #include @@ -24,3 +28,5 @@ public: uint16_t init_ports() override; }; + +#endif // AP_NOTIFY_NEOPIXEL_ENABLED diff --git a/libraries/AP_Notify/ProfiLED.cpp b/libraries/AP_Notify/ProfiLED.cpp index 15945a15d6..872e7819a2 100644 --- a/libraries/AP_Notify/ProfiLED.cpp +++ b/libraries/AP_Notify/ProfiLED.cpp @@ -13,8 +13,10 @@ along with this program. If not, see . */ -#include "AP_Notify/AP_Notify.h" #include "ProfiLED.h" + +#include "AP_Notify/AP_Notify.h" + #include "SRV_Channel/SRV_Channel.h" #include #include @@ -29,6 +31,8 @@ extern const AP_HAL::HAL& hal; +#if AP_NOTIFY_PROFILED_ENABLED + ProfiLED::ProfiLED() : SerialLED(ProfiLED_OFF, ProfiLED_HIGH, ProfiLED_MEDIUM, ProfiLED_LOW) { @@ -62,7 +66,9 @@ uint16_t ProfiLED::init_ports() return mask; } +#endif // AP_NOTIFY_PROFILED_ENABLED +#if AP_NOTIFY_PROFILED_SPI_ENABLED ProfiLED_SPI::ProfiLED_SPI() : RGBLed(ProfiLED_OFF, ProfiLED_HIGH, ProfiLED_MEDIUM, ProfiLED_LOW) {} @@ -161,3 +167,5 @@ void ProfiLED_SPI::update_led_strip() { send_buf_len = 0; } } + +#endif // AP_NOTIFY_PROFILED_SPI_ENABLED diff --git a/libraries/AP_Notify/ProfiLED.h b/libraries/AP_Notify/ProfiLED.h index 10fc69e425..926477c0fc 100644 --- a/libraries/AP_Notify/ProfiLED.h +++ b/libraries/AP_Notify/ProfiLED.h @@ -14,10 +14,13 @@ */ #pragma once -#include "RGBLed.h" -#include "SerialLED.h" +#include "AP_Notify_config.h" + #include +#if AP_NOTIFY_PROFILED_ENABLED +#include "SerialLED.h" + class ProfiLED: public SerialLED { public: ProfiLED(); @@ -25,6 +28,11 @@ public: uint16_t init_ports() override; }; +#endif // AP_NOTIFY_PROFILED_ENABLED + +#if AP_NOTIFY_PROFILED_SPI_ENABLED +#include +#include "RGBLed.h" class ProfiLED_SPI: public RGBLed { public: @@ -53,3 +61,6 @@ private: uint32_t _last_init_ms; void update_led_strip(); }; + + +#endif // AP_NOTIFY_PROFILED_SPI_ENABLED diff --git a/libraries/AP_Notify/SerialLED.cpp b/libraries/AP_Notify/SerialLED.cpp index be333ad7a2..8f8ee500fa 100644 --- a/libraries/AP_Notify/SerialLED.cpp +++ b/libraries/AP_Notify/SerialLED.cpp @@ -13,9 +13,10 @@ along with this program. If not, see . */ -#include "AP_Notify/AP_Notify.h" #include "SerialLED.h" +#if AP_NOTIFY_SERIALLED_ENABLED + extern const AP_HAL::HAL& hal; SerialLED::SerialLED(uint8_t led_off, uint8_t led_bright, uint8_t led_medium, uint8_t led_dim) : @@ -55,3 +56,5 @@ bool SerialLED::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) return true; } + +#endif // AP_NOTIFY_SERIALLED_ENABLED diff --git a/libraries/AP_Notify/SerialLED.h b/libraries/AP_Notify/SerialLED.h index 16c723218e..ba29be20ff 100644 --- a/libraries/AP_Notify/SerialLED.h +++ b/libraries/AP_Notify/SerialLED.h @@ -14,6 +14,10 @@ */ #pragma once +#include "AP_Notify_config.h" + +#if AP_NOTIFY_SERIALLED_ENABLED + #include "RGBLed.h" #include #include @@ -41,3 +45,5 @@ private: HAL_Semaphore _sem; }; + +#endif // AP_NOTIFY_SERIALLED_ENABLED