Skip to content

Commit

Permalink
drivers/ws281x: use ESP-IDF CPU HAL
Browse files Browse the repository at this point in the history
  • Loading branch information
gschorcht committed Apr 6, 2022
1 parent b613766 commit 7209985
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions drivers/ws281x/esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @{
*
* @file
* @brief Implementation of `ws281x_write_buffer()` for the ESP32 CPU
* @brief Implementation of `ws281x_write_buffer()` for the ESP32x CPU
*
* @author Christian Friedrich Coors <[email protected]>
*
Expand All @@ -27,19 +27,14 @@
#include "ws281x_params.h"
#include "ws281x_constants.h"
#include "periph_cpu.h"

#include "esp_private/esp_clk.h"
#include "xtensa/core-macros.h"
#include "hal/cpu_hal.h"
#include "soc/rtc.h"

#define ENABLE_DEBUG 0
#include "debug.h"

static inline __attribute__((always_inline)) uint32_t get_cycle_count(void) {
uint32_t ccount;
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
return ccount;
}

void ws281x_write_buffer(ws281x_t *dev, const void *buf, size_t size)
{
assert(dev);
Expand Down Expand Up @@ -74,14 +69,14 @@ void ws281x_write_buffer(ws281x_t *dev, const void *buf, size_t size)
on_wait = zero_on;
off_wait = zero_off;
}
start = get_cycle_count();
start = cpu_hal_get_cycle_count();
gpio_set(dev->params.pin);
current_wait = start + on_wait;
while (get_cycle_count() < current_wait) { }
while (cpu_hal_get_cycle_count() < current_wait) { }
gpio_clear(dev->params.pin);
start = get_cycle_count();
start = cpu_hal_get_cycle_count();
current_wait = start + off_wait;
while (get_cycle_count() < current_wait) { }
while (cpu_hal_get_cycle_count() < current_wait) { }
data <<= 1;
}
pos++;
Expand Down

0 comments on commit 7209985

Please sign in to comment.