Skip to content

Commit

Permalink
apa102: fix end frame
Browse files Browse the repository at this point in the history
end frame used to supply clock pulses so that
data goes to next led

Signed-off-by: Cyril Fougeray <cyril.fougeray@toolsforhumanity.com>
  • Loading branch information
fouge committed Jun 11, 2024
1 parent 563bfc7 commit 85209f6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions drivers/led_strip/apa102.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ static int apa102_update(const struct device *dev, void *buf, size_t size)
{
const struct apa102_config *config = dev->config;
static const uint8_t zeros[] = { 0, 0, 0, 0 };
static const uint8_t ones[] = { 0xFF, 0xFF, 0xFF, 0xFF };

/*
* the only function of the “End frame” is to supply more clock pulses
* to the string until the data has permeated to the last LED. The
* number of clock pulses required is exactly half the total number
* of LEDs in the string
*/
BUILD_ASSERT(sizeof(struct led_rgb) == 4);
uint8_t ones[((size / sizeof(struct led_rgb)) / sizeof(uint8_t) / 2) + 1];

memset(ones, 0xFF, sizeof(ones));

const struct spi_buf tx_bufs[] = {
{
/* Start frame: at least 32 zeros */
Expand Down Expand Up @@ -50,13 +61,14 @@ static int apa102_update(const struct device *dev, void *buf, size_t size)
return spi_write_dt(&config->bus, &tx);
}

static int apa102_update_rgb(const struct device *dev, struct led_rgb *pixels,
static int apa102_update_rgb(const struct device *dev,
struct led_rgb *pixels,
size_t count)
{
uint8_t *p = (uint8_t *)pixels;
size_t i;
/* SOF (3 bits) followed by the 0 to 31 global dimming level */
uint8_t prefix = 0xE0;
const uint8_t prefix = 0xE0;

/* Rewrite to the on-wire format */
for (i = 0; i < count; i++) {
Expand Down

0 comments on commit 85209f6

Please sign in to comment.