From 501d0d87594de6dc511f868ad20d699f98b655b0 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 11 Jul 2024 12:23:52 +1000 Subject: [PATCH] AP_Notify: stop using linux board subtype in Notify LED setup ... instead have the board definitions define things like we do for ChibiOS --- libraries/AP_Notify/AP_Notify.cpp | 14 ++++++-------- libraries/AP_Notify/AP_Notify_config.h | 24 ++++++++++++++++++++++++ libraries/AP_Notify/DiscoLED.cpp | 8 ++++++-- libraries/AP_Notify/DiscoLED.h | 7 +++++-- libraries/AP_Notify/Led_Sysfs.cpp | 9 ++++----- libraries/AP_Notify/Led_Sysfs.h | 7 ++++--- libraries/AP_Notify/NavigatorLED.cpp | 6 ++++++ libraries/AP_Notify/NavigatorLED.h | 6 ++++++ libraries/AP_Notify/RCOutputRGBLed.cpp | 7 +++++++ libraries/AP_Notify/RCOutputRGBLed.h | 6 ++++++ 10 files changed, 74 insertions(+), 20 deletions(-) diff --git a/libraries/AP_Notify/AP_Notify.cpp b/libraries/AP_Notify/AP_Notify.cpp index a74655db83..da5ebde379 100644 --- a/libraries/AP_Notify/AP_Notify.cpp +++ b/libraries/AP_Notify/AP_Notify.cpp @@ -287,19 +287,17 @@ void AP_Notify::add_backends(void) break; case Notify_LED_Board: // select the most appropriate built in LED driver type -#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX - #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 +#if AP_NOTIFY_SYSFS_LED_ENABLED ADD_BACKEND(NEW_NOTHROW Led_Sysfs("rgb_led0", "rgb_led2", "rgb_led1")); - #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE +#elif AP_NOTIFY_RCOUTPUTRGBLEDINVERTED_LED_ENABLED ADD_BACKEND(NEW_NOTHROW RCOutputRGBLedInverted(12, 13, 14)); - #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH +#elif AP_NOTIFY_RCOUTPUTRGBLED_LED_ENABLED ADD_BACKEND(NEW_NOTHROW RCOutputRGBLed(HAL_RCOUT_RGBLED_RED, HAL_RCOUT_RGBLED_GREEN, HAL_RCOUT_RGBLED_BLUE)); - #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO +#elif AP_NOTIFY_DISCO_LED_ENABLED ADD_BACKEND(NEW_NOTHROW DiscoLED()); - #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR +#elif AP_NOTIFY_NAVIGATOR_LED_ENABLED ADD_BACKEND(NEW_NOTHROW NavigatorLED()); - #endif -#endif // CONFIG_HAL_BOARD == HAL_BOARD_LINUX +#endif #if AP_NOTIFY_EXTERNALLED_ENABLED ADD_BACKEND(NEW_NOTHROW ExternalLED()); // despite the name this is a built in set of onboard LED's diff --git a/libraries/AP_Notify/AP_Notify_config.h b/libraries/AP_Notify/AP_Notify_config.h index 62238d28ed..23b7c6c8b1 100644 --- a/libraries/AP_Notify/AP_Notify_config.h +++ b/libraries/AP_Notify/AP_Notify_config.h @@ -37,6 +37,14 @@ #define AP_NOTIFY_LP5562_ENABLED 1 #endif +#ifndef AP_NOTIFY_DISCO_LED_ENABLED +#define AP_NOTIFY_DISCO_LED_ENABLED 0 +#endif + +#ifndef AP_NOTIFY_NAVIGATOR_LED_ENABLED +#define AP_NOTIFY_NAVIGATOR_LED_ENABLED 0 +#endif + #ifndef AP_NOTIFY_GPIO_LED_3_ENABLED #define AP_NOTIFY_GPIO_LED_3_ENABLED 0 #endif @@ -51,6 +59,22 @@ #define AP_NOTIFY_GPIO_LED_RGB_ENABLED 0 #endif +#ifndef AP_NOTIFY_RCOUTPUTRGBLEDINVERTED_LED_ENABLED +#define AP_NOTIFY_RCOUTPUTRGBLEDINVERTED_LED_ENABLED 0 +#endif + +#ifndef AP_NOTIFY_RCOUTPUTRGBLEDOFF_LED_ENABLED +#define AP_NOTIFY_RCOUTPUTRGBLEDOFF_LED_ENABLED 0 +#endif + +#ifndef AP_NOTIFY_RCOUTPUTRGBLED_LED_ENABLED +#define AP_NOTIFY_RCOUTPUTRGBLED_LED_ENABLED AP_NOTIFY_RCOUTPUTRGBLEDINVERTED_LED_ENABLED || AP_NOTIFY_RCOUTPUTRGBLEDOFF_LED_ENABLED +#endif + +#ifndef AP_NOTIFY_SYSFS_LED_ENABLED +#define AP_NOTIFY_SYSFS_LED_ENABLED 0 +#endif + #ifndef AP_NOTIFY_IS31FL3195_ENABLED #define AP_NOTIFY_IS31FL3195_ENABLED 1 #endif diff --git a/libraries/AP_Notify/DiscoLED.cpp b/libraries/AP_Notify/DiscoLED.cpp index 845972e623..ec2030d894 100644 --- a/libraries/AP_Notify/DiscoLED.cpp +++ b/libraries/AP_Notify/DiscoLED.cpp @@ -14,9 +14,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ + +#include "AP_Notify_config.h" + +#if AP_NOTIFY_DISCO_LED_ENABLED + #include -#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX #include "DiscoLED.h" #include @@ -92,4 +96,4 @@ bool DiscoLED::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) return true; } -#endif +#endif // AP_NOTIFY_DISCO_LED_ENABLED diff --git a/libraries/AP_Notify/DiscoLED.h b/libraries/AP_Notify/DiscoLED.h index 3c7585327e..d32ccf818f 100644 --- a/libraries/AP_Notify/DiscoLED.h +++ b/libraries/AP_Notify/DiscoLED.h @@ -16,9 +16,12 @@ */ #pragma once +#include "AP_Notify_config.h" + +#if AP_NOTIFY_DISCO_LED_ENABLED + #include -#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX #include #include @@ -53,4 +56,4 @@ private: enum led_backend backend; }; -#endif +#endif // AP_NOTIFY_DISCO_LED_ENABLED diff --git a/libraries/AP_Notify/Led_Sysfs.cpp b/libraries/AP_Notify/Led_Sysfs.cpp index 3bdec24cb7..e611062a0f 100644 --- a/libraries/AP_Notify/Led_Sysfs.cpp +++ b/libraries/AP_Notify/Led_Sysfs.cpp @@ -14,13 +14,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include +#include "AP_Notify_config.h" + +#if AP_NOTIFY_SYSFS_LED_ENABLED -#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX #include "Led_Sysfs.h" -#include - Led_Sysfs::Led_Sysfs(const char *red, const char *green, const char *blue, uint8_t off_brightness, uint8_t low_brightness, uint8_t medium_brightness, uint8_t high_brightness): RGBLed(off_brightness, high_brightness, medium_brightness, low_brightness), @@ -47,4 +46,4 @@ bool Led_Sysfs::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) return true; } -#endif +#endif // AP_NOTIFY_SYSFS_LED_ENABLED diff --git a/libraries/AP_Notify/Led_Sysfs.h b/libraries/AP_Notify/Led_Sysfs.h index be8fab15e8..caab49c848 100644 --- a/libraries/AP_Notify/Led_Sysfs.h +++ b/libraries/AP_Notify/Led_Sysfs.h @@ -16,9 +16,10 @@ */ #pragma once -#include +#include "AP_Notify_config.h" + +#if AP_NOTIFY_SYSFS_LED_ENABLED -#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX #include #include "RGBLed.h" @@ -39,4 +40,4 @@ private: Linux::Led_Sysfs green_led; Linux::Led_Sysfs blue_led; }; -#endif +#endif // AP_NOTIFY_SYSFS_LED_ENABLED diff --git a/libraries/AP_Notify/NavigatorLED.cpp b/libraries/AP_Notify/NavigatorLED.cpp index 8c7b706aa1..7bdc68e397 100644 --- a/libraries/AP_Notify/NavigatorLED.cpp +++ b/libraries/AP_Notify/NavigatorLED.cpp @@ -19,6 +19,10 @@ // not used. The data is sent to the neopixel in 24 'SPI bytes', where each // spi byte is formatted to appear as a single bit of data to the neopixel. +#include "AP_Notify_config.h" + +#if AP_NOTIFY_NAVIGATOR_LED_ENABLED + #include #include "AP_Notify/AP_Notify.h" #include "NavigatorLED.h" @@ -79,3 +83,5 @@ void NavigatorLED::_setup_data(uint8_t red, uint8_t green, uint8_t blue) _data[16 + i] = (blue & (1<<(7-i))) ? LED_T1 : LED_T0; } } + +#endif // AP_NOTIFY_NAVIGATOR_LED_ENABLED diff --git a/libraries/AP_Notify/NavigatorLED.h b/libraries/AP_Notify/NavigatorLED.h index 9f93857eb1..f6ef3a2387 100644 --- a/libraries/AP_Notify/NavigatorLED.h +++ b/libraries/AP_Notify/NavigatorLED.h @@ -14,6 +14,10 @@ */ #pragma once +#include "AP_Notify_config.h" + +#if AP_NOTIFY_NAVIGATOR_LED_ENABLED + #include "RGBLed.h" #include @@ -30,3 +34,5 @@ private: void _setup_data(uint8_t red, uint8_t green, uint8_t blue); AP_HAL::OwnPtr _dev; }; + +#endif // AP_NOTIFY_NAVIGATOR_LED_ENABLED diff --git a/libraries/AP_Notify/RCOutputRGBLed.cpp b/libraries/AP_Notify/RCOutputRGBLed.cpp index b9049f1468..b9147126f9 100644 --- a/libraries/AP_Notify/RCOutputRGBLed.cpp +++ b/libraries/AP_Notify/RCOutputRGBLed.cpp @@ -15,6 +15,10 @@ * with this program. If not, see . */ +#include "AP_Notify_config.h" + +#if AP_NOTIFY_RCOUTPUTRGBLED_LED_ENABLED + #include "RCOutputRGBLed.h" #include @@ -58,10 +62,12 @@ uint16_t RCOutputRGBLed::get_duty_cycle_for_color(const uint8_t color, const uin return usec_period * color / _led_bright; } +#if AP_NOTIFY_RCOUTPUTRGBLEDINVERTED_LED_ENABLED uint16_t RCOutputRGBLedInverted::get_duty_cycle_for_color(const uint8_t color, const uint16_t usec_period) const { return usec_period * (255 - color) / _led_bright; } +#endif // AP_NOTIFY_RCOUTPUTRGBLEDINVERTED_LED_ENABLED bool RCOutputRGBLed::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) @@ -91,3 +97,4 @@ bool RCOutputRGBLed::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) return true; } +#endif // AP_NOTIFY_RCOUTPUTRGBLED_LED_ENABLED diff --git a/libraries/AP_Notify/RCOutputRGBLed.h b/libraries/AP_Notify/RCOutputRGBLed.h index aeae109e94..865d13fcfc 100644 --- a/libraries/AP_Notify/RCOutputRGBLed.h +++ b/libraries/AP_Notify/RCOutputRGBLed.h @@ -2,6 +2,7 @@ #include "RGBLed.h" +#if AP_NOTIFY_RCOUTPUTRGBLED_LED_ENABLED class RCOutputRGBLed: public RGBLed { public: RCOutputRGBLed(uint8_t red_channel, uint8_t green_channel, @@ -20,7 +21,9 @@ private: uint8_t _green_channel; uint8_t _blue_channel; }; +#endif // AP_NOTIFY_RCOUTPUTRGBLED_LED_ENABLED +#if AP_NOTIFY_RCOUTPUTRGBLEDINVERTED_LED_ENABLED class RCOutputRGBLedInverted : public RCOutputRGBLed { public: RCOutputRGBLedInverted(uint8_t red_channel, uint8_t green_channel, uint8_t blue_channel) @@ -29,7 +32,9 @@ public: protected: virtual uint16_t get_duty_cycle_for_color(const uint8_t color, const uint16_t usec_period) const override; }; +#endif // AP_NOTIFY_RCOUTPUTRGBLEDINVERTED_LED_ENABLED +#if AP_NOTIFY_RCOUTPUTRGBLEDOFF_LED_ENABLED class RCOutputRGBLedOff : public RCOutputRGBLed { public: RCOutputRGBLedOff(uint8_t red_channel, uint8_t green_channel, @@ -45,3 +50,4 @@ public: return RCOutputRGBLed::hw_set_rgb(_led_off, _led_off, _led_off); } }; +#endif // AP_NOTIFY_RCOUTPUTRGBLEDOFF_LED_ENABLED