From 552ed255f6719450645566ee377e0f17ecb8d8a9 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 27 Jul 2017 07:43:59 -0600 Subject: [PATCH] Add support for inverted LEDS. See common anode RGB LED discussion in the Yahoo group --- drivers/leds/Kconfig | 9 +++++++++ drivers/leds/rgbled.c | 12 +++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index edcbb97528..0d7b47e347 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -48,6 +48,15 @@ config RGBLED This selection enables building of the "upper-half" RGB LED driver. See include/nuttx/rgbled.h for further PWM driver information. +config RGBLED_INVERT + bool "Invert RGB LED Output" + depends on RGBLED + default n + ---help--- + If the board has a common anode RGB LED (a LOW output turns ON + each LED), this selection inverts the outputs so that the + colors are displayed correctly. + config PCA9635PW bool "PCA9635PW I2C LED Driver" default n diff --git a/drivers/leds/rgbled.c b/drivers/leds/rgbled.c index 81b2ff5591..bb85d3f5e3 100644 --- a/drivers/leds/rgbled.c +++ b/drivers/leds/rgbled.c @@ -304,9 +304,15 @@ static ssize_t rgbled_write(FAR struct file *filep, FAR const char *buffer, /* Convert 8bit to 16bits */ - red <<= 8; - green <<= 8; - blue <<= 8; + red = (red << 8) | red; + green = (green << 8) | green; + blue = (blue << 8) | blue; + +#ifdef CONFIG_RGBLED_INVERT + red ^= 0xffff; + green ^= 0xffff; + blue ^= 0xffff; +#endif /* Setup LED R */