1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:12:57 +01:00

drivers/ws281x: improve timing for ESP32x

If overhead like the loop control or the calculation of the waiting times for the next bit are performed while waiting for the end of the LOW phase, the time required for such operations is included in the LOW phase. This makes both the LOW phase and the period more precise.
This commit is contained in:
Gunar Schorcht 2023-01-04 07:57:52 +01:00
parent 71e5b2cb5e
commit c40e015804

View File

@ -70,18 +70,23 @@ void ws281x_write_buffer(ws281x_t *dev, const void *buf, size_t size)
on_wait = zero_on;
off_wait = zero_off;
}
data <<= 1;
while (cpu_hal_get_cycle_count() < current_wait) { }
/* end of LOW phase and start of HIGH phase */
start = cpu_hal_get_cycle_count();
gpio_set(dev->params.pin);
current_wait = start + on_wait;
while (cpu_hal_get_cycle_count() < current_wait) { }
gpio_clear(dev->params.pin);
/* end of HIGH phase and start of HIGH phase */
start = cpu_hal_get_cycle_count();
gpio_clear(dev->params.pin);
current_wait = start + off_wait;
while (cpu_hal_get_cycle_count() < current_wait) { }
data <<= 1;
}
pos++;
}
/* final LOW phase */
current_wait = cpu_hal_get_cycle_count();
/* end of final LOW phase */
}
int ws281x_init(ws281x_t *dev, const ws281x_params_t *params)