AP_Notify: Remove indirection on RGBLed of init()->hw_init()

Saves a bit of flash, and just makes the code a bit more obvious
This commit is contained in:
Michael du Breuil 2021-03-28 18:44:23 -07:00 committed by Andrew Tridgell
parent 5304dfe213
commit c0017abb63
27 changed files with 28 additions and 36 deletions

View File

@ -47,7 +47,7 @@ DiscoLED::DiscoLED():
{ {
} }
bool DiscoLED::hw_init() bool DiscoLED::init()
{ {
/* If led sysfs api is present, use it, else use pwm sysfs api to /* If led sysfs api is present, use it, else use pwm sysfs api to
drive Disco leds */ drive Disco leds */

View File

@ -28,9 +28,9 @@ class DiscoLED: public RGBLed
{ {
public: public:
DiscoLED(); DiscoLED();
bool init(void) override;
protected: protected:
bool hw_init(void) override;
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;
private: private:

View File

@ -27,7 +27,7 @@ DiscreteRGBLed::DiscreteRGBLed(uint16_t red, uint16_t green, uint16_t blue, bool
} }
bool DiscreteRGBLed::hw_init(void) bool DiscreteRGBLed::init(void)
{ {
red_pin = hal.gpio->channel(red_pin_number); red_pin = hal.gpio->channel(red_pin_number);
green_pin = hal.gpio->channel(green_pin_number); green_pin = hal.gpio->channel(green_pin_number);

View File

@ -23,9 +23,9 @@
class DiscreteRGBLed: public RGBLed { class DiscreteRGBLed: public RGBLed {
public: public:
DiscreteRGBLed(uint16_t red, uint16_t green, uint16_t blue, bool polarity); DiscreteRGBLed(uint16_t red, uint16_t green, uint16_t blue, bool polarity);
bool init(void) override;
protected: protected:
bool hw_init(void) override;
bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) override; bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) override;
private: private:

View File

@ -30,7 +30,7 @@ Led_Sysfs::Led_Sysfs(const char *red, const char *green, const char *blue,
{ {
} }
bool Led_Sysfs::hw_init() bool Led_Sysfs::init()
{ {
if (red_led.init() && green_led.init() && blue_led.init()) { if (red_led.init() && green_led.init() && blue_led.init()) {
return true; return true;

View File

@ -29,9 +29,9 @@ public:
Led_Sysfs(const char *red, const char *green, const char *blue, Led_Sysfs(const char *red, const char *green, const char *blue,
uint8_t off_brightness = 0xff , uint8_t low_brightness = 0x00, uint8_t off_brightness = 0xff , uint8_t low_brightness = 0x00,
uint8_t medium_brightness = 0x00, uint8_t high_brightness = 0x00); uint8_t medium_brightness = 0x00, uint8_t high_brightness = 0x00);
bool init(void) override;
protected: protected:
bool hw_init(void) override;
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;
private: private:

View File

@ -61,7 +61,7 @@ bool NCP5623::write_pwm(uint8_t _rgb[3])
return true; return true;
} }
bool NCP5623::hw_init(void) bool NCP5623::init(void)
{ {
uint8_t addrs[] = { NCP5623_LED_I2C_ADDR, NCP5623_C_LED_I2C_ADDR }; uint8_t addrs[] = { NCP5623_LED_I2C_ADDR, NCP5623_C_LED_I2C_ADDR };
for (uint8_t i=0; i<ARRAY_SIZE(addrs); i++) { for (uint8_t i=0; i<ARRAY_SIZE(addrs); i++) {

View File

@ -23,8 +23,8 @@
class NCP5623 : public RGBLed { class NCP5623 : public RGBLed {
public: public:
NCP5623(uint8_t bus); NCP5623(uint8_t bus);
bool init(void) override;
protected: protected:
bool hw_init(void) override;
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;
private: private:
AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev; AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev;

View File

@ -37,7 +37,7 @@ PCA9685LED_I2C::PCA9685LED_I2C() :
{ {
} }
bool PCA9685LED_I2C::hw_init() bool PCA9685LED_I2C::init()
{ {
_dev = hal.i2c_mgr->get_device(1, PCA9685_ADDRESS); _dev = hal.i2c_mgr->get_device(1, PCA9685_ADDRESS);

View File

@ -23,8 +23,8 @@ class PCA9685LED_I2C : public RGBLed
{ {
public: public:
PCA9685LED_I2C(void); PCA9685LED_I2C(void);
bool init(void) override;
protected: protected:
bool hw_init(void) override;
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;
private: private:

View File

@ -34,7 +34,7 @@ PixRacerLED::PixRacerLED() :
{ {
} }
bool PixRacerLED::hw_init(void) 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
@ -58,6 +58,6 @@ bool PixRacerLED::hw_set_rgb(uint8_t r, uint8_t g, uint8_t b)
} }
#else #else
bool PixRacerLED::hw_init(void) { return true; } bool PixRacerLED::init(void) { return true; }
bool PixRacerLED::hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) { return true; } bool PixRacerLED::hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) { return true; }
#endif #endif

View File

@ -23,8 +23,8 @@ class PixRacerLED: public RGBLed
{ {
public: public:
PixRacerLED(); PixRacerLED();
bool init(void) override;
protected: protected:
bool hw_init(void) override;
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;
}; };

View File

@ -44,7 +44,7 @@ RCOutputRGBLed::RCOutputRGBLed(uint8_t red_channel, uint8_t green_channel,
{ {
} }
bool RCOutputRGBLed::hw_init() bool RCOutputRGBLed::init()
{ {
hal.rcout->enable_ch(_red_channel); hal.rcout->enable_ch(_red_channel);
hal.rcout->enable_ch(_green_channel); hal.rcout->enable_ch(_green_channel);

View File

@ -9,9 +9,9 @@ public:
uint8_t led_medium, uint8_t led_dim); uint8_t led_medium, uint8_t led_dim);
RCOutputRGBLed(uint8_t red_channel, uint8_t green_channel, RCOutputRGBLed(uint8_t red_channel, uint8_t green_channel,
uint8_t blue_channel); uint8_t blue_channel);
bool init() override;
protected: protected:
bool hw_init() override;
virtual bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) override; virtual bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) override;
virtual uint16_t get_duty_cycle_for_color(const uint8_t color, const uint16_t usec_period) const; virtual uint16_t get_duty_cycle_for_color(const uint8_t color, const uint16_t usec_period) const;

View File

@ -32,11 +32,6 @@ RGBLed::RGBLed(uint8_t led_off, uint8_t led_bright, uint8_t led_medium, uint8_t
} }
bool RGBLed::init()
{
return hw_init();
}
// set_rgb - set color as a combination of red, green and blue values // set_rgb - set color as a combination of red, green and blue values
void RGBLed::_set_rgb(uint8_t red, uint8_t green, uint8_t blue) void RGBLed::_set_rgb(uint8_t red, uint8_t green, uint8_t blue)
{ {

View File

@ -26,9 +26,6 @@ class RGBLed: public NotifyDevice {
public: public:
RGBLed(uint8_t led_off, uint8_t led_bright, uint8_t led_medium, uint8_t led_dim); RGBLed(uint8_t led_off, uint8_t led_bright, uint8_t led_medium, uint8_t led_dim);
// init - initialised the LED
virtual bool init(void) override;
// set_rgb - set color as a combination of red, green and blue levels from 0 ~ 15 // set_rgb - set color as a combination of red, green and blue levels from 0 ~ 15
virtual void set_rgb(uint8_t red, uint8_t green, uint8_t blue); virtual void set_rgb(uint8_t red, uint8_t green, uint8_t blue);
@ -45,7 +42,6 @@ public:
protected: protected:
// methods implemented in hardware specific classes // methods implemented in hardware specific classes
virtual bool hw_init(void) = 0;
virtual bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) = 0; virtual bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) = 0;
// set_rgb - set color as a combination of red, green and blue levels from 0 ~ 15 // set_rgb - set color as a combination of red, green and blue levels from 0 ~ 15

View File

@ -208,7 +208,7 @@ void *SITL_SFML_LED::update_thread_start(void *obj)
return nullptr; return nullptr;
} }
bool SITL_SFML_LED::hw_init() bool SITL_SFML_LED::init()
{ {
pthread_create(&thread, NULL, update_thread_start, this); pthread_create(&thread, NULL, update_thread_start, this);

View File

@ -33,9 +33,9 @@ class SITL_SFML_LED: public RGBLed
{ {
public: public:
SITL_SFML_LED(); SITL_SFML_LED();
bool init(void) override;
protected: protected:
bool hw_init(void) override;
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;
private: private:

View File

@ -34,9 +34,10 @@ public:
void get_rgb(uint8_t& red, uint8_t& green, uint8_t& blue); void get_rgb(uint8_t& red, uint8_t& green, uint8_t& blue);
bool init() override {return true;};
protected: protected:
bool hw_init() override {return true;};
bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) override {return true;} bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) override {return true;}
private: private:

View File

@ -23,7 +23,7 @@ SerialLED::SerialLED(uint8_t led_off, uint8_t led_bright, uint8_t led_medium, ui
{ {
} }
bool SerialLED::hw_init() bool SerialLED::init()
{ {
enable_mask = init_ports(); enable_mask = init_ports();
return true; return true;

View File

@ -28,12 +28,12 @@ public:
uint8_t g; uint8_t g;
} RGB; } RGB;
bool init(void) override;
virtual uint16_t init_ports() { return 0; }; virtual uint16_t init_ports() { return 0; };
protected: protected:
bool hw_init(void) override;
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;
private: private:

View File

@ -44,7 +44,7 @@ ToshibaLED_I2C::ToshibaLED_I2C(uint8_t bus)
{ {
} }
bool ToshibaLED_I2C::hw_init(void) bool ToshibaLED_I2C::init(void)
{ {
// first look for led on external bus // first look for led on external bus
_dev = std::move(hal.i2c_mgr->get_device(_bus, TOSHIBA_LED_I2C_ADDR)); _dev = std::move(hal.i2c_mgr->get_device(_bus, TOSHIBA_LED_I2C_ADDR));

View File

@ -23,8 +23,8 @@ class ToshibaLED_I2C : public RGBLed
{ {
public: public:
ToshibaLED_I2C(uint8_t bus); ToshibaLED_I2C(uint8_t bus);
bool init(void) override;
protected: protected:
bool hw_init(void) override;
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;
private: private:

View File

@ -43,7 +43,7 @@ UAVCAN_RGB_LED::UAVCAN_RGB_LED(uint8_t led_index, uint8_t led_off,
{ {
} }
bool UAVCAN_RGB_LED::hw_init() bool UAVCAN_RGB_LED::init()
{ {
return true; return true;
} }

View File

@ -7,9 +7,9 @@ public:
UAVCAN_RGB_LED(uint8_t led_index, uint8_t led_off, uint8_t led_full, UAVCAN_RGB_LED(uint8_t led_index, uint8_t led_off, uint8_t led_full,
uint8_t led_medium, uint8_t led_dim); uint8_t led_medium, uint8_t led_dim);
UAVCAN_RGB_LED(uint8_t led_index); UAVCAN_RGB_LED(uint8_t led_index);
bool init() override;
protected: protected:
bool hw_init() override;
virtual bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) override; virtual bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) override;
private: private:

View File

@ -35,7 +35,7 @@ VRBoard_LED::VRBoard_LED():
{ {
} }
bool VRBoard_LED::hw_init(void){ bool VRBoard_LED::init(void){
// setup the main LEDs as outputs // setup the main LEDs as outputs
hal.gpio->pinMode(HAL_GPIO_A_LED_PIN, HAL_GPIO_OUTPUT); 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_B_LED_PIN, HAL_GPIO_OUTPUT);

View File

@ -26,8 +26,8 @@
class VRBoard_LED: public RGBLed { class VRBoard_LED: public RGBLed {
public: public:
VRBoard_LED(); VRBoard_LED();
bool init(void) override;
protected: protected:
bool hw_init(void) override;
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;
}; };