diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2020-04-15 13:28:54 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2020-04-15 13:29:43 -0400 |
commit | 0ae20421d18bd53ee98e03e825a0b2a468fa5639 (patch) | |
tree | 03c5a9a4a8b9c5fa8efc683c048a3711fa4c7748 /src/neopixel.c | |
parent | a7f7cc507547758879890b206030e508ac8dbdb0 (diff) | |
download | kutter-0ae20421d18bd53ee98e03e825a0b2a468fa5639.tar.gz kutter-0ae20421d18bd53ee98e03e825a0b2a468fa5639.tar.xz kutter-0ae20421d18bd53ee98e03e825a0b2a468fa5639.zip |
neopixel: Allow host software to configure neopixel timing
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/neopixel.c')
-rw-r--r-- | src/neopixel.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/neopixel.c b/src/neopixel.c index 5988562b..f7e961fc 100644 --- a/src/neopixel.c +++ b/src/neopixel.c @@ -78,8 +78,6 @@ neopixel_delay(neopixel_time_t start, neopixel_time_t ticks) #define PULSE_LONG_TICKS nsecs_to_ticks(650) #define PULSE_SHORT_TICKS nsecs_to_ticks(200) #define BIT_MIN_TICKS nsecs_to_ticks(1250) -#define BIT_MAX_TICKS nsecs_to_ticks(4000) -#define RESET_MIN_TICKS timer_from_us(50) /**************************************************************** @@ -88,7 +86,8 @@ neopixel_delay(neopixel_time_t start, neopixel_time_t ticks) struct neopixel_s { struct gpio_out pin; - uint32_t last_req_time; + neopixel_time_t bit_max_ticks; + uint32_t last_req_time, reset_min_ticks; }; void @@ -98,21 +97,27 @@ command_config_neopixel(uint32_t *args) struct neopixel_s *n = oid_alloc(args[0], command_config_neopixel , sizeof(*n)); n->pin = pin; + n->bit_max_ticks = args[2]; + n->reset_min_ticks = args[3]; } -DECL_COMMAND(command_config_neopixel, "config_neopixel oid=%c pin=%u"); +DECL_COMMAND(command_config_neopixel, "config_neopixel oid=%c pin=%u" + " bit_max_ticks=%u reset_min_ticks=%u"); static int send_data(struct neopixel_s *n, uint8_t *data, uint_fast8_t data_len) { - // Make sure at least 50us has passed since last request - uint32_t last_req_time = n->last_req_time, cur = timer_read_time(); - while (cur - last_req_time < RESET_MIN_TICKS) { + // Make sure the reset time has elapsed since last request + uint32_t last_req_time = n->last_req_time, rmt = n->reset_min_ticks; + uint32_t cur = timer_read_time(); + while (cur - last_req_time < rmt) { irq_poll(); cur = timer_read_time(); } + // Transmit data struct gpio_out pin = n->pin; neopixel_time_t last_start = neopixel_get_time(); + neopixel_time_t bit_max_ticks = n->bit_max_ticks; while (data_len--) { uint_fast8_t byte = *data++; uint_fast8_t bits = 8; @@ -125,7 +130,7 @@ send_data(struct neopixel_s *n, uint8_t *data, uint_fast8_t data_len) gpio_out_toggle_noirq(pin); irq_enable(); - if (neopixel_check_elapsed(last_start, start, BIT_MAX_TICKS)) + if (neopixel_check_elapsed(last_start, start, bit_max_ticks)) goto fail; last_start = start; byte <<= 1; @@ -144,7 +149,7 @@ send_data(struct neopixel_s *n, uint8_t *data, uint_fast8_t data_len) gpio_out_toggle_noirq(pin); irq_enable(); - if (neopixel_check_elapsed(last_start, start, BIT_MAX_TICKS)) + if (neopixel_check_elapsed(last_start, start, bit_max_ticks)) goto fail; last_start = start; byte <<= 1; |