47 #include <px4_platform_common/getopt.h> 48 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp> 55 #define NCP5623_LED_CURRENT 0x20 56 #define NCP5623_LED_PWM0 0x40 57 #define NCP5623_LED_PWM1 0x60 58 #define NCP5623_LED_PWM2 0x80 60 #define NCP5623_LED_BRIGHT 0x1f 61 #define NCP5623_LED_OFF 0x00 109 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(get_device_id()))
118 while (
_running && ++counter < 10) {
126 uint8_t
msg[1] = { 0x00 };
127 msg[0] = ((reg & 0xe0) | (data & 0x1f));
129 int ret = transfer(&msg[0], 1,
nullptr, 0);
187 switch (led_control_data.
leds[0].
color) {
188 case led_control_s::COLOR_RED:
192 case led_control_s::COLOR_GREEN:
196 case led_control_s::COLOR_BLUE:
200 case led_control_s::COLOR_AMBER:
201 case led_control_s::COLOR_YELLOW:
205 case led_control_s::COLOR_PURPLE:
209 case led_control_s::COLOR_CYAN:
213 case led_control_s::COLOR_WHITE:
238 uint8_t
msg[7] = {0x20, 0x70, 0x40, 0x70, 0x60, 0x70, 0x80};
246 return transfer(&msg[0], 7,
nullptr, 0);
254 maxbrt = maxbrt > 31 ? 31 : maxbrt;
255 maxbrt = maxbrt < 0 ? 0 : maxbrt;
267 PX4_INFO(
"missing command: try 'start', 'stop'");
268 PX4_INFO(
"options:");
269 PX4_INFO(
" -b i2cbus (%d)", PX4_I2C_BUS_LED);
270 PX4_INFO(
" -a addr (0x%x)",
ADDR);
277 int rgbledadr =
ADDR;
283 const char *myoptarg =
nullptr;
285 while ((ch = px4_getopt(argc, argv,
"a:b:", &myoptind, &myoptarg)) != EOF) {
288 rgbledadr = strtol(myoptarg,
nullptr, 0);
292 i2cdevice = strtol(myoptarg,
nullptr, 0);
301 if (myoptind >= argc) {
306 const char *verb = argv[myoptind];
308 if (!strcmp(verb,
"start")) {
309 if (g_rgbled !=
nullptr) {
310 PX4_WARN(
"already started");
314 if (i2cdevice == -1) {
316 i2cdevice = PX4_I2C_BUS_EXPANSION;
319 if (g_rgbled !=
nullptr &&
OK != g_rgbled->init()) {
324 if (g_rgbled ==
nullptr) {
326 if (PX4_I2C_BUS_LED == PX4_I2C_BUS_EXPANSION) {
327 PX4_WARN(
"no RGB led on bus #%d", i2cdevice);
331 i2cdevice = PX4_I2C_BUS_LED;
335 if (g_rgbled ==
nullptr) {
338 if (g_rgbled ==
nullptr) {
339 PX4_WARN(
"alloc failed");
343 if (
OK != g_rgbled->init()) {
346 PX4_WARN(
"no RGB led on bus #%d", i2cdevice);
355 if (g_rgbled ==
nullptr) {
356 PX4_WARN(
"not started");
361 if (!strcmp(verb,
"stop")) {
#define ADDR
I2C adress of NCP5623C.
__EXPORT int param_get(param_t param, void *val)
Copy the value of a parameter.
int maximum_update_interval() const
get maxium time between two consecutive calls to update() in us.
LedControlDataSingle leds[BOARD_MAX_LEDS]
volatile bool _should_run
int write(uint8_t reg, uint8_t data)
#define NCP5623_LED_PWM1
pwm1 register
LedController _led_controller
#define NCP5623_LED_PWM0
pwm0 register
uint8_t brightness
brightness in [0, 255]
#define NCP5623_LED_CURRENT
Current register.
Global flash based parameter store.
uint8_t color
one of led_control_s::COLOR_*
static char msg[NUM_MSG][CONFIG_USART1_TXBUFSIZE]
void rgbled_ncp5623c_usage()
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
RGBLED_NPC5623C(int bus, int rgbled)
void init()
Activates/configures the hardware registers.
#define NCP5623_LED_BRIGHT
full brightness
#define RGBLED1_DEVICE_PATH
bool updated()
Check if there is a new update.
__EXPORT param_t param_find(const char *name)
Look up a parameter by name.
int send_led_rgb()
Send RGB PWM settings to LED driver according to current color and brightness.
#define NCP5623_LED_PWM2
pwm2 register
uORB::Subscription _parameter_update_sub
int update(LedControlData &control_data)
Update and retrieve the Led state.
void Run() override
Main loop function.
__EXPORT int rgbled_ncp5623c_main(int argc, char *argv[])
Led controller helper class, used by Led drivers.
bool copy(void *dst)
Copy the struct.
class LedController Handles the led_control topic: blinking, priorities and state updates...
virtual ~RGBLED_NPC5623C()
Base class for devices connected via I2C.