Skip to content

Commit

Permalink
leds: add RGBxI format
Browse files Browse the repository at this point in the history
  • Loading branch information
SpComb committed Feb 8, 2024
1 parent 4823246 commit 16c68ff
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
39 changes: 38 additions & 1 deletion components/leds/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ unsigned leds_format_count(size_t len, enum leds_format format, unsigned group)
case LEDS_FORMAT_RGBW:
return len / (4 * group) * group;

case LEDS_FORMAT_RGBXI:
return len / (3 + group) * group;

case LEDS_FORMAT_RGBWXI:
return len / (4 + group) * group;

Expand Down Expand Up @@ -123,6 +126,36 @@ void leds_set_format_rgbw(struct leds *leds, const uint8_t *data, size_t len, st
}
}

void leds_set_format_rgbxi(struct leds *leds, const uint8_t *data, size_t len, struct leds_format_params params)
{
enum leds_parameter_type parameter_type = leds_parameter_type(leds);
uint8_t parameter_default = leds_parameter_default(leds);

LOG_DEBUG("len=%u offset=%u count=%u segment=%u group=%u", len, params.offset, params.count, params.segment, params.group);

size_t off = 0;

for (unsigned g = 0; g * params.group < params.count && len >= off + 3 + params.group; g++) {
struct leds_color group_color = {};

group_color.r = data[off++];
group_color.g = data[off++];
group_color.b = data[off++];
group_color.parameter = parameter_default;

LOG_DEBUG("\tg=%u off=%u rgb=%02x%02x%02x", g, off, group_color.r, group_color.g, group_color.b);

for (unsigned i = 0; i < params.group && g * params.group + i < params.count; i++) {
uint8_t intensity = data[off++];
struct leds_color pixel_color = leds_color_intensity(group_color, parameter_type, intensity);

for (unsigned j = 0; j < params.segment; j++) {
leds->pixels[params.offset + (g * params.group + i) * params.segment + j] = pixel_color;
}
}
}
}

void leds_set_format_rgbwxi(struct leds *leds, const uint8_t *data, size_t len, struct leds_format_params params)
{
enum leds_parameter_type parameter_type = leds_parameter_type(leds);
Expand All @@ -132,7 +165,7 @@ void leds_set_format_rgbwxi(struct leds *leds, const uint8_t *data, size_t len,
size_t off = 0;

for (unsigned g = 0; g * params.group < params.count && len >= off + 4 + params.group; g++) {
struct leds_color group_color;
struct leds_color group_color = {};

group_color.r = data[off++];
group_color.g = data[off++];
Expand Down Expand Up @@ -197,6 +230,10 @@ int leds_set_format(struct leds *leds, enum leds_format format, const void *data
leds_set_format_rgbw(leds, data, len, params);
return 0;

case LEDS_FORMAT_RGBXI:
leds_set_format_rgbxi(leds, data, len, params);
return 0;

case LEDS_FORMAT_RGBWXI:
leds_set_format_rgbwxi(leds, data, len, params);
return 0;
Expand Down
2 changes: 2 additions & 0 deletions components/leds/include/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ enum leds_format {
LEDS_FORMAT_GRB,
LEDS_FORMAT_RGBA,
LEDS_FORMAT_RGBW,

LEDS_FORMAT_RGBXI, // grouped RGB + intensity
LEDS_FORMAT_RGBWXI, // grouped RGBW + intensity
};

Expand Down
13 changes: 7 additions & 6 deletions main/leds_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ const struct config_enum leds_gpio_mode_enum[] = {
#endif

const struct config_enum leds_format_enum[] = {
{ "RGB", LEDS_FORMAT_RGB },
{ "BGR", LEDS_FORMAT_BGR },
{ "GRB", LEDS_FORMAT_GRB },
{ "RGBA", LEDS_FORMAT_RGBA },
{ "RGBW", LEDS_FORMAT_RGBW },
{ "RGBWxI", LEDS_FORMAT_RGBWXI },
{ "RGB", LEDS_FORMAT_RGB },
{ "BGR", LEDS_FORMAT_BGR },
{ "GRB", LEDS_FORMAT_GRB },
{ "RGBA", LEDS_FORMAT_RGBA },
{ "RGBW", LEDS_FORMAT_RGBW },
{ "RGBxI", LEDS_FORMAT_RGBXI },
{ "RGBWxI", LEDS_FORMAT_RGBWXI },
{}
};

Expand Down

0 comments on commit 16c68ff

Please sign in to comment.