Skip to content

Commit

Permalink
AP_Notify: add support for controlling ProfiLED via IOMCU safety pins
Browse files Browse the repository at this point in the history
  • Loading branch information
bugobliterator committed Aug 2, 2024
1 parent 3c3cf90 commit 78f30ed
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
14 changes: 12 additions & 2 deletions libraries/AP_Notify/AP_Notify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "ProfiLED.h"
#include "ScriptingLED.h"
#include "DShotLED.h"
#include "ProfiLED_IOMCU.h"

extern const AP_HAL::HAL& hal;

Expand Down Expand Up @@ -90,7 +91,11 @@ AP_Notify *AP_Notify::_singleton;

#ifndef DEFAULT_NTF_LED_TYPES
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
#define DEFAULT_NTF_LED_TYPES (Notify_LED_Board | I2C_LEDS)
#if HAL_WITH_IO_MCU
#define DEFAULT_NTF_LED_TYPES (Notify_LED_Board | Notify_LED_ProfiLED_IOMCU | I2C_LEDS)
#else
#define DEFAULT_NTF_LED_TYPES (Notify_LED_Board | I2C_LEDS)
#endif

// Linux boards
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX
Expand Down Expand Up @@ -215,7 +220,7 @@ const AP_Param::GroupInfo AP_Notify::var_info[] = {
// @Param: LED_TYPES
// @DisplayName: LED Driver Types
// @Description: Controls what types of LEDs will be enabled
// @Bitmask: 0:Built-in LED, 1:Internal ToshibaLED, 2:External ToshibaLED, 3:External PCA9685, 4:Oreo LED, 5:DroneCAN, 6:NCP5623 External, 7:NCP5623 Internal, 8:NeoPixel, 9:ProfiLED, 10:Scripting, 11:DShot, 12:ProfiLED_SPI, 13:LP5562 External, 14: LP5562 Internal, 15:IS31FL3195 External, 16: IS31FL3195 Internal, 17: DiscreteRGB, 18: NeoPixelRGB
// @Bitmask: 0:Built-in LED, 1:Internal ToshibaLED, 2:External ToshibaLED, 3:External PCA9685, 4:Oreo LED, 5:DroneCAN, 6:NCP5623 External, 7:NCP5623 Internal, 8:NeoPixel, 9:ProfiLED, 10:Scripting, 11:DShot, 12:ProfiLED_SPI, 13:LP5562 External, 14: LP5562 Internal, 15:IS31FL3195 External, 16: IS31FL3195 Internal, 17: DiscreteRGB, 18: NeoPixelRGB, 19:ProfiLED_IOMCU
// @User: Advanced
AP_GROUPINFO("LED_TYPES", 6, AP_Notify, _led_type, DEFAULT_NTF_LED_TYPES),

Expand Down Expand Up @@ -380,6 +385,11 @@ void AP_Notify::add_backends(void)
ADD_BACKEND(NEW_NOTHROW DShotLED());
break;
#endif
#if HAL_WITH_IO_MCU
case Notify_LED_ProfiLED_IOMCU:
ADD_BACKEND(NEW_NOTHROW ProfiLED_IOMCU());
break;
#endif
#if AP_NOTIFY_LP5562_ENABLED
case Notify_LED_LP5562_I2C_External:
FOREACH_I2C_EXTERNAL(b) {
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Notify/AP_Notify.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class AP_Notify
#endif
#if AP_NOTIFY_NEOPIXEL_ENABLED
Notify_LED_NeoPixelRGB = (1 << 18), // NeoPixel AdaFruit 4544 Worldsemi WS2811
#endif
#if HAL_WITH_IO_MCU
Notify_LED_ProfiLED_IOMCU = (1 << 19), // ProfiLED IOMCU
#endif
Notify_LED_MAX
};
Expand Down
40 changes: 40 additions & 0 deletions libraries/AP_Notify/ProfiLED_IOMCU.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

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

#if HAL_WITH_IO_MCU
#include <AP_IOMCU/AP_IOMCU.h>

class ProfiLED_IOMCU : public RGBLed {
public:
ProfiLED_IOMCU() : RGBLed(0, 0xFF, 0x7F, 0x33) {}

bool init(void) override { return true; }

protected:
bool hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) override {
const auto iomcu = AP::iomcu();
if (iomcu == nullptr) {
return false;
}
iomcu->set_profiled(r, g, b);
return true;
}
};

#endif

0 comments on commit 78f30ed

Please sign in to comment.