diff --git a/libraries/AP_Notify/AP_BoardLED.cpp b/libraries/AP_Notify/AP_BoardLED.cpp index 8e137c43e0..164e39a4a7 100644 --- a/libraries/AP_Notify/AP_BoardLED.cpp +++ b/libraries/AP_Notify/AP_BoardLED.cpp @@ -12,13 +12,14 @@ 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_GPIO_LED_3_ENABLED + #include "AP_BoardLED.h" - #include "AP_Notify.h" -#if (defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN) && \ - defined(HAL_GPIO_C_LED_PIN)) - static_assert((HAL_GPIO_A_LED_PIN != HAL_GPIO_B_LED_PIN) && (HAL_GPIO_A_LED_PIN != HAL_GPIO_C_LED_PIN) && (HAL_GPIO_B_LED_PIN != HAL_GPIO_C_LED_PIN), "Duplicate LED assignments detected"); @@ -168,7 +169,5 @@ void AP_BoardLED::update(void) break; } } -#else -bool AP_BoardLED::init(void) {return true;} -void AP_BoardLED::update(void) {return;} -#endif + +#endif // AP_NOTIFY_GPIO_LED_3_ENABLED diff --git a/libraries/AP_Notify/AP_BoardLED.h b/libraries/AP_Notify/AP_BoardLED.h index 810cacbde8..adede6cd7b 100644 --- a/libraries/AP_Notify/AP_BoardLED.h +++ b/libraries/AP_Notify/AP_BoardLED.h @@ -14,6 +14,10 @@ */ #pragma once +#include "AP_Notify_config.h" + +#if AP_NOTIFY_GPIO_LED_3_ENABLED + #include #include @@ -29,9 +33,8 @@ public: void update(void) override; private: -#if (defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN) && \ - defined(HAL_GPIO_C_LED_PIN)) // counter incremented at 50Hz uint8_t _counter; -#endif }; + +#endif // AP_NOTIFY_GPIO_LED_3_ENABLED diff --git a/libraries/AP_Notify/AP_BoardLED2.cpp b/libraries/AP_Notify/AP_BoardLED2.cpp index 24a80e4559..ef2cbd18ed 100644 --- a/libraries/AP_Notify/AP_BoardLED2.cpp +++ b/libraries/AP_Notify/AP_BoardLED2.cpp @@ -11,16 +11,19 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . + + + show all status on only 2 leds */ + +#include "AP_Notify_config.h" + +#if AP_NOTIFY_GPIO_LED_2_ENABLED + #include "AP_BoardLED2.h" #include "AP_Notify.h" - -// show all status on only 2 leds - -#if defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN) - static_assert((HAL_GPIO_A_LED_PIN != HAL_GPIO_B_LED_PIN), "Duplicate LED assignments detected"); extern const AP_HAL::HAL& hal; @@ -263,7 +266,5 @@ void AP_BoardLED2::update(void) break; } } -#else -bool AP_BoardLED2::init(void) {return true;} -void AP_BoardLED2::update(void) {return;} -#endif + +#endif // AP_NOTIFY_GPIO_LED_2_ENABLED diff --git a/libraries/AP_Notify/AP_BoardLED2.h b/libraries/AP_Notify/AP_BoardLED2.h index 2d6b5e19a0..94791d41bf 100644 --- a/libraries/AP_Notify/AP_BoardLED2.h +++ b/libraries/AP_Notify/AP_BoardLED2.h @@ -14,7 +14,9 @@ */ #pragma once +#include "AP_Notify_config.h" +#if AP_NOTIFY_GPIO_LED_2_ENABLED #include #include @@ -33,9 +35,9 @@ public: private: // counter incremented at 50Hz uint8_t _counter; -#if defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN) uint16_t _sat_cnt; uint8_t save_trim_counter; uint8_t arm_counter = 0; -#endif }; + +#endif // AP_NOTIFY_GPIO_LED_2_ENABLED diff --git a/libraries/AP_Notify/AP_Notify.cpp b/libraries/AP_Notify/AP_Notify.cpp index 4bbebe497f..46f6fec3ec 100644 --- a/libraries/AP_Notify/AP_Notify.cpp +++ b/libraries/AP_Notify/AP_Notify.cpp @@ -307,15 +307,13 @@ void AP_Notify::add_backends(void) ADD_BACKEND(NEW_NOTHROW ExternalLED()); // despite the name this is a built in set of onboard LED's #endif -#if defined(HAL_HAVE_PIXRACER_LED) +#if AP_NOTIFY_GPIO_LED_RGB_ENABLED ADD_BACKEND(NEW_NOTHROW PixRacerLED()); -#elif (defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN) && defined(HAL_GPIO_C_LED_PIN)) - #if AP_NOTIFY_VRBOARD_LED_ENABLED +#elif AP_NOTIFY_VRBOARD_LED_ENABLED ADD_BACKEND(NEW_NOTHROW VRBoard_LED()); - #else +#elif AP_NOTIFY_GPIO_LED_3_ENABLED ADD_BACKEND(NEW_NOTHROW AP_BoardLED()); - #endif -#elif (defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN)) +#elif AP_NOTIFY_GPIO_LED_2_ENABLED ADD_BACKEND(NEW_NOTHROW AP_BoardLED2()); #endif break; diff --git a/libraries/AP_Notify/AP_Notify_config.h b/libraries/AP_Notify/AP_Notify_config.h index fb702a8d1e..62238d28ed 100644 --- a/libraries/AP_Notify/AP_Notify_config.h +++ b/libraries/AP_Notify/AP_Notify_config.h @@ -37,6 +37,20 @@ #define AP_NOTIFY_LP5562_ENABLED 1 #endif +#ifndef AP_NOTIFY_GPIO_LED_3_ENABLED +#define AP_NOTIFY_GPIO_LED_3_ENABLED 0 +#endif + +// this isn't the second-generation of board LEDs, this is a setup +// where there are two LEDs used: +#ifndef AP_NOTIFY_GPIO_LED_2_ENABLED +#define AP_NOTIFY_GPIO_LED_2_ENABLED 0 +#endif + +#ifndef AP_NOTIFY_GPIO_LED_RGB_ENABLED +#define AP_NOTIFY_GPIO_LED_RGB_ENABLED 0 +#endif + #ifndef AP_NOTIFY_IS31FL3195_ENABLED #define AP_NOTIFY_IS31FL3195_ENABLED 1 #endif diff --git a/libraries/AP_Notify/PixRacerLED.cpp b/libraries/AP_Notify/PixRacerLED.cpp index 3e543a0cf3..19da44e3e5 100644 --- a/libraries/AP_Notify/PixRacerLED.cpp +++ b/libraries/AP_Notify/PixRacerLED.cpp @@ -13,20 +13,22 @@ along with this program. If not, see . */ +#include "AP_Notify_config.h" + +#if AP_NOTIFY_GPIO_LED_RGB_ENABLED + #include "PixRacerLED.h" #include -#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS - -#ifndef HAL_GPIO_A_LED_PIN -#define HAL_GPIO_A_LED_PIN -1 +#ifndef AP_NOTIFY_GPIO_LED_RGB_RED_PIN +#error "define AP_NOTIFY_GPIO_LED_RGB_RED_PIN" #endif -#ifndef HAL_GPIO_B_LED_PIN -#define HAL_GPIO_B_LED_PIN -1 +#ifndef AP_NOTIFY_GPIO_LED_RGB_GREEN_PIN +#error "define AP_NOTIFY_GPIO_LED_RGB_GREEN_PIN" #endif -#ifndef HAL_GPIO_C_LED_PIN -#define HAL_GPIO_C_LED_PIN -1 +#ifndef AP_NOTIFY_GPIO_LED_RGB_BLUE_PIN +#error "define AP_NOTIFY_GPIO_LED_RGB_BLUE_PIN" #endif extern const AP_HAL::HAL& hal; @@ -41,25 +43,22 @@ bool PixRacerLED::init(void) // when HAL_GPIO_LED_ON is 0 then we must not use pinMode() // as it could remove the OPENDRAIN attribute on the pin #if HAL_GPIO_LED_ON != 0 - hal.gpio->pinMode(HAL_GPIO_A_LED_PIN, HAL_GPIO_OUTPUT); - hal.gpio->pinMode(HAL_GPIO_B_LED_PIN, HAL_GPIO_OUTPUT); - hal.gpio->pinMode(HAL_GPIO_C_LED_PIN, HAL_GPIO_OUTPUT); + hal.gpio->pinMode(AP_NOTIFY_GPIO_LED_RGB_RED_PIN, HAL_GPIO_OUTPUT); + hal.gpio->pinMode(AP_NOTIFY_GPIO_LED_RGB_GREEN_PIN, HAL_GPIO_OUTPUT); + hal.gpio->pinMode(AP_NOTIFY_GPIO_LED_RGB_BLUE_PIN, HAL_GPIO_OUTPUT); #endif - hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_OFF); - hal.gpio->write(HAL_GPIO_B_LED_PIN, HAL_GPIO_LED_OFF); - hal.gpio->write(HAL_GPIO_C_LED_PIN, HAL_GPIO_LED_OFF); + hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_RED_PIN, HAL_GPIO_LED_OFF); + hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_GREEN_PIN, HAL_GPIO_LED_OFF); + hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_BLUE_PIN, HAL_GPIO_LED_OFF); return true; } bool PixRacerLED::hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) { - hal.gpio->write(HAL_GPIO_A_LED_PIN, (r > 0)?HAL_GPIO_LED_ON:HAL_GPIO_LED_OFF); - hal.gpio->write(HAL_GPIO_B_LED_PIN, (g > 0)?HAL_GPIO_LED_ON:HAL_GPIO_LED_OFF); - hal.gpio->write(HAL_GPIO_C_LED_PIN, (b > 0)?HAL_GPIO_LED_ON:HAL_GPIO_LED_OFF); + hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_RED_PIN, (r > 0)?HAL_GPIO_LED_ON:HAL_GPIO_LED_OFF); + hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_GREEN_PIN, (g > 0)?HAL_GPIO_LED_ON:HAL_GPIO_LED_OFF); + hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_BLUE_PIN, (b > 0)?HAL_GPIO_LED_ON:HAL_GPIO_LED_OFF); return true; } -#else -bool PixRacerLED::init(void) { return true; } -bool PixRacerLED::hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) { return true; } -#endif +#endif // AP_NOTIFY_GPIO_LED_RGB_ENABLED diff --git a/libraries/AP_Notify/PixRacerLED.h b/libraries/AP_Notify/PixRacerLED.h index 43dc34ac03..ca93161abe 100644 --- a/libraries/AP_Notify/PixRacerLED.h +++ b/libraries/AP_Notify/PixRacerLED.h @@ -14,6 +14,10 @@ */ #pragma once +#include "AP_Notify_config.h" + +#if AP_NOTIFY_GPIO_LED_RGB_ENABLED + #include "RGBLed.h" class PixRacerLED: public RGBLed @@ -25,3 +29,5 @@ public: protected: bool hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) override; }; + +#endif // AP_NOTIFY_GPIO_LED_RGB_ENABLED