Skip to content

Commit

Permalink
samples: led_lp50xx: fix color mapping
Browse files Browse the repository at this point in the history
Some boards may have a color mapping that is different from RGB and this
mapping should be used when providing the buffer to led_set_color().

Signed-off-by: Mathieu Anquetin <[email protected]>
  • Loading branch information
man-gc committed Jun 29, 2023
1 parent 7fc90f6 commit cefd3d8
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions samples/drivers/led_lp50xx/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <zephyr/devicetree.h>
#include <zephyr/drivers/led.h>
#include <zephyr/drivers/led/lp50xx.h>
#include <zephyr/dt-bindings/led/led.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/util.h>

Expand Down Expand Up @@ -46,21 +47,47 @@ static uint8_t colors[][3] = {
*/
static int run_led_test(const struct device *lp50xx_dev, uint8_t led)
{
const struct led_info *info;
uint8_t idx;
int err;

LOG_INF("Testing LED %d (LED API)", led);

err = led_get_info(lp50xx_dev, led, &info);
if (err < 0) {
LOG_ERR("Failed to get LED %d info", led);
return err;
}

for (idx = 0; idx < ARRAY_SIZE(colors); idx++) {
uint16_t level;
uint8_t color;
uint8_t buf[3];

for(color = 0; color < info->num_colors; color++) {

Check failure on line 67 in samples/drivers/led_lp50xx/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

samples/drivers/led_lp50xx/src/main.c:67 space required before the open parenthesis '('
switch(info->color_mapping[color]) {

Check failure on line 68 in samples/drivers/led_lp50xx/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

samples/drivers/led_lp50xx/src/main.c:68 space required before the open parenthesis '('
case LED_COLOR_ID_RED:
buf[color] = colors[idx][0];
continue;
case LED_COLOR_ID_GREEN:
buf[color] = colors[idx][1];
continue;
case LED_COLOR_ID_BLUE:
buf[color] = colors[idx][2];
continue;
default:
LOG_ERR("Invalid color: %d",
info->color_mapping[color]);
return -EINVAL;
}
}

/* Update LED color. */
err = led_set_color(lp50xx_dev, led, 3, colors[idx]);
err = led_set_color(lp50xx_dev, led, 3, buf);
if (err < 0) {
LOG_ERR("Failed to set LED %d color to "
"%02x:%02x:%02x, err=%d", led,
colors[idx][0], colors[idx][1],
colors[idx][2], err);
buf[0], buf[1], buf[2], err);
return err;
}
k_sleep(SLEEP_DELAY);
Expand Down

0 comments on commit cefd3d8

Please sign in to comment.