Skip to content

Commit

Permalink
AP_Notify: stop using linux board subtype in Notify LED setup
Browse files Browse the repository at this point in the history
... instead have the board definitions define things like we do for ChibiOS
  • Loading branch information
peterbarker committed Jul 11, 2024
1 parent f9036b2 commit 624419a
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 20 deletions.
14 changes: 6 additions & 8 deletions libraries/AP_Notify/AP_Notify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions libraries/AP_Notify/AP_Notify_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions libraries/AP_Notify/DiscoLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "AP_Notify_config.h"

#if AP_NOTIFY_DISCO_LED_ENABLED

#include <AP_HAL/AP_HAL.h>

#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#include "DiscoLED.h"

#include <AP_HAL_Linux/Led_Sysfs.h>
Expand Down Expand Up @@ -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
7 changes: 5 additions & 2 deletions libraries/AP_Notify/DiscoLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
*/
#pragma once

#include "AP_Notify_config.h"

#if AP_NOTIFY_DISCO_LED_ENABLED

#include <AP_HAL/AP_HAL_Boards.h>

#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#include <AP_HAL_Linux/Led_Sysfs.h>
#include <AP_HAL_Linux/PWM_Sysfs.h>

Expand Down Expand Up @@ -53,4 +56,4 @@ class DiscoLED: public RGBLed

enum led_backend backend;
};
#endif
#endif // AP_NOTIFY_DISCO_LED_ENABLED
9 changes: 4 additions & 5 deletions libraries/AP_Notify/Led_Sysfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <AP_HAL/AP_HAL.h>
#include "AP_Notify_config.h"

#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#include "Led_Sysfs.h"
#if AP_NOTIFY_SYSFS_LED_ENABLED

#include <AP_HAL_Linux/Led_Sysfs.h>
#include "Led_Sysfs.h"

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):
Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions libraries/AP_Notify/Led_Sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
*/
#pragma once

#include <AP_HAL/AP_HAL_Boards.h>
#include "AP_Notify_config.h"

#if AP_NOTIFY_SYSFS_LED_ENABLED

#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#include <AP_HAL_Linux/Led_Sysfs.h>

#include "RGBLed.h"
Expand All @@ -39,4 +40,4 @@ class Led_Sysfs: public RGBLed
Linux::Led_Sysfs green_led;
Linux::Led_Sysfs blue_led;
};
#endif
#endif // AP_NOTIFY_SYSFS_LED_ENABLED
6 changes: 6 additions & 0 deletions libraries/AP_Notify/NavigatorLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <AP_HAL/AP_HAL.h>
#include "AP_Notify/AP_Notify.h"
#include "NavigatorLED.h"
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions libraries/AP_Notify/NavigatorLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
*/
#pragma once

#include "AP_Notify_config.h"

#if AP_NOTIFY_NAVIGATOR_LED_ENABLED

#include "RGBLed.h"
#include <AP_Common/AP_Common.h>

Expand All @@ -30,3 +34,5 @@ class NavigatorLED: public RGBLed {
void _setup_data(uint8_t red, uint8_t green, uint8_t blue);
AP_HAL::OwnPtr<AP_HAL::SPIDevice> _dev;
};

#endif // AP_NOTIFY_NAVIGATOR_LED_ENABLED
7 changes: 7 additions & 0 deletions libraries/AP_Notify/RCOutputRGBLed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "AP_Notify_config.h"

#if AP_NOTIFY_RCOUTPUTRGBLED_LED_ENABLED

#include "RCOutputRGBLed.h"

#include <AP_Math/AP_Math.h>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions libraries/AP_Notify/RCOutputRGBLed.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,7 +21,9 @@ class RCOutputRGBLed: public RGBLed {
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)
Expand All @@ -29,7 +32,9 @@ class RCOutputRGBLedInverted : public RCOutputRGBLed {
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,
Expand All @@ -45,3 +50,4 @@ class RCOutputRGBLedOff : public RCOutputRGBLed {
return RCOutputRGBLed::hw_set_rgb(_led_off, _led_off, _led_off);
}
};
#endif // AP_NOTIFY_RCOUTPUTRGBLEDOFF_LED_ENABLED

0 comments on commit 624419a

Please sign in to comment.