AP_Notify: create sanity in GPIO-based LED defines

This commit is contained in:
Peter Barker 2024-07-09 13:19:52 +10:00 committed by Peter Barker
parent 096cfdcb61
commit 8370e0b08b
8 changed files with 71 additions and 49 deletions

View File

@ -12,13 +12,14 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "AP_Notify_config.h"
#if AP_NOTIFY_GPIO_LED_3_ENABLED
#include "AP_BoardLED.h" #include "AP_BoardLED.h"
#include "AP_Notify.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) && static_assert((HAL_GPIO_A_LED_PIN != HAL_GPIO_B_LED_PIN) &&
(HAL_GPIO_A_LED_PIN != HAL_GPIO_C_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"); (HAL_GPIO_B_LED_PIN != HAL_GPIO_C_LED_PIN), "Duplicate LED assignments detected");
@ -168,7 +169,5 @@ void AP_BoardLED::update(void)
break; break;
} }
} }
#else
bool AP_BoardLED::init(void) {return true;} #endif // AP_NOTIFY_GPIO_LED_3_ENABLED
void AP_BoardLED::update(void) {return;}
#endif

View File

@ -14,6 +14,10 @@
*/ */
#pragma once #pragma once
#include "AP_Notify_config.h"
#if AP_NOTIFY_GPIO_LED_3_ENABLED
#include <AP_Common/AP_Common.h> #include <AP_Common/AP_Common.h>
#include <AP_HAL/AP_HAL_Boards.h> #include <AP_HAL/AP_HAL_Boards.h>
@ -29,9 +33,8 @@ public:
void update(void) override; void update(void) override;
private: private:
#if (defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN) && \
defined(HAL_GPIO_C_LED_PIN))
// counter incremented at 50Hz // counter incremented at 50Hz
uint8_t _counter; uint8_t _counter;
#endif
}; };
#endif // AP_NOTIFY_GPIO_LED_3_ENABLED

View File

@ -11,16 +11,19 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
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_BoardLED2.h"
#include "AP_Notify.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"); static_assert((HAL_GPIO_A_LED_PIN != HAL_GPIO_B_LED_PIN), "Duplicate LED assignments detected");
extern const AP_HAL::HAL& hal; extern const AP_HAL::HAL& hal;
@ -263,7 +266,5 @@ void AP_BoardLED2::update(void)
break; break;
} }
} }
#else
bool AP_BoardLED2::init(void) {return true;} #endif // AP_NOTIFY_GPIO_LED_2_ENABLED
void AP_BoardLED2::update(void) {return;}
#endif

View File

@ -14,7 +14,9 @@
*/ */
#pragma once #pragma once
#include "AP_Notify_config.h"
#if AP_NOTIFY_GPIO_LED_2_ENABLED
#include <AP_Common/AP_Common.h> #include <AP_Common/AP_Common.h>
#include <AP_HAL/AP_HAL_Boards.h> #include <AP_HAL/AP_HAL_Boards.h>
@ -33,9 +35,9 @@ public:
private: private:
// counter incremented at 50Hz // counter incremented at 50Hz
uint8_t _counter; uint8_t _counter;
#if defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN)
uint16_t _sat_cnt; uint16_t _sat_cnt;
uint8_t save_trim_counter; uint8_t save_trim_counter;
uint8_t arm_counter = 0; uint8_t arm_counter = 0;
#endif
}; };
#endif // AP_NOTIFY_GPIO_LED_2_ENABLED

View File

@ -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 ADD_BACKEND(NEW_NOTHROW ExternalLED()); // despite the name this is a built in set of onboard LED's
#endif #endif
#if defined(HAL_HAVE_PIXRACER_LED) #if AP_NOTIFY_GPIO_LED_RGB_ENABLED
ADD_BACKEND(NEW_NOTHROW PixRacerLED()); ADD_BACKEND(NEW_NOTHROW PixRacerLED());
#elif (defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN) && defined(HAL_GPIO_C_LED_PIN)) #elif AP_NOTIFY_VRBOARD_LED_ENABLED
#if AP_NOTIFY_VRBOARD_LED_ENABLED
ADD_BACKEND(NEW_NOTHROW VRBoard_LED()); ADD_BACKEND(NEW_NOTHROW VRBoard_LED());
#else #elif AP_NOTIFY_GPIO_LED_3_ENABLED
ADD_BACKEND(NEW_NOTHROW AP_BoardLED()); ADD_BACKEND(NEW_NOTHROW AP_BoardLED());
#endif #elif AP_NOTIFY_GPIO_LED_2_ENABLED
#elif (defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN))
ADD_BACKEND(NEW_NOTHROW AP_BoardLED2()); ADD_BACKEND(NEW_NOTHROW AP_BoardLED2());
#endif #endif
break; break;

View File

@ -37,6 +37,20 @@
#define AP_NOTIFY_LP5562_ENABLED 1 #define AP_NOTIFY_LP5562_ENABLED 1
#endif #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 #ifndef AP_NOTIFY_IS31FL3195_ENABLED
#define AP_NOTIFY_IS31FL3195_ENABLED 1 #define AP_NOTIFY_IS31FL3195_ENABLED 1
#endif #endif

View File

@ -13,20 +13,22 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "AP_Notify_config.h"
#if AP_NOTIFY_GPIO_LED_RGB_ENABLED
#include "PixRacerLED.h" #include "PixRacerLED.h"
#include <AP_HAL/HAL.h> #include <AP_HAL/HAL.h>
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS #ifndef AP_NOTIFY_GPIO_LED_RGB_RED_PIN
#error "define AP_NOTIFY_GPIO_LED_RGB_RED_PIN"
#ifndef HAL_GPIO_A_LED_PIN
#define HAL_GPIO_A_LED_PIN -1
#endif #endif
#ifndef HAL_GPIO_B_LED_PIN #ifndef AP_NOTIFY_GPIO_LED_RGB_GREEN_PIN
#define HAL_GPIO_B_LED_PIN -1 #error "define AP_NOTIFY_GPIO_LED_RGB_GREEN_PIN"
#endif #endif
#ifndef HAL_GPIO_C_LED_PIN #ifndef AP_NOTIFY_GPIO_LED_RGB_BLUE_PIN
#define HAL_GPIO_C_LED_PIN -1 #error "define AP_NOTIFY_GPIO_LED_RGB_BLUE_PIN"
#endif #endif
extern const AP_HAL::HAL& hal; 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() // when HAL_GPIO_LED_ON is 0 then we must not use pinMode()
// as it could remove the OPENDRAIN attribute on the pin // as it could remove the OPENDRAIN attribute on the pin
#if HAL_GPIO_LED_ON != 0 #if HAL_GPIO_LED_ON != 0
hal.gpio->pinMode(HAL_GPIO_A_LED_PIN, HAL_GPIO_OUTPUT); hal.gpio->pinMode(AP_NOTIFY_GPIO_LED_RGB_RED_PIN, HAL_GPIO_OUTPUT);
hal.gpio->pinMode(HAL_GPIO_B_LED_PIN, HAL_GPIO_OUTPUT); hal.gpio->pinMode(AP_NOTIFY_GPIO_LED_RGB_GREEN_PIN, HAL_GPIO_OUTPUT);
hal.gpio->pinMode(HAL_GPIO_C_LED_PIN, HAL_GPIO_OUTPUT); hal.gpio->pinMode(AP_NOTIFY_GPIO_LED_RGB_BLUE_PIN, HAL_GPIO_OUTPUT);
#endif #endif
hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_OFF); hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_RED_PIN, HAL_GPIO_LED_OFF);
hal.gpio->write(HAL_GPIO_B_LED_PIN, HAL_GPIO_LED_OFF); hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_GREEN_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_BLUE_PIN, HAL_GPIO_LED_OFF);
return true; return true;
} }
bool PixRacerLED::hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) 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(AP_NOTIFY_GPIO_LED_RGB_RED_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(AP_NOTIFY_GPIO_LED_RGB_GREEN_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_BLUE_PIN, (b > 0)?HAL_GPIO_LED_ON:HAL_GPIO_LED_OFF);
return true; return true;
} }
#else #endif // AP_NOTIFY_GPIO_LED_RGB_ENABLED
bool PixRacerLED::init(void) { return true; }
bool PixRacerLED::hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) { return true; }
#endif

View File

@ -14,6 +14,10 @@
*/ */
#pragma once #pragma once
#include "AP_Notify_config.h"
#if AP_NOTIFY_GPIO_LED_RGB_ENABLED
#include "RGBLed.h" #include "RGBLed.h"
class PixRacerLED: public RGBLed class PixRacerLED: public RGBLed
@ -25,3 +29,5 @@ public:
protected: protected:
bool hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) override; bool hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) override;
}; };
#endif // AP_NOTIFY_GPIO_LED_RGB_ENABLED