Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/ws281x: esp32 neopixel driver to set the rmt symbol high/low lengths at init instead of every write #21068

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions drivers/ws281x/esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static uint32_t _ws281x_one_on;
static uint32_t _ws281x_one_off;
static uint32_t _ws281x_zero_on;
static uint32_t _ws281x_zero_off;
static uint8_t channel;

static uint8_t _rmt_channel(ws281x_t *dev)
{
Expand All @@ -71,23 +72,6 @@ void ws281x_write_buffer(ws281x_t *dev, const void *buf, size_t size)
assert(dev);

#ifdef MODULE_WS281X_ESP32_HW
/* determine used RMT channel from configured GPIO */
uint8_t channel = _rmt_channel(dev);

/* determine the current clock frequency */
uint32_t freq;
if (rmt_get_counter_clock(channel, &freq) != ESP_OK) {
LOG_ERROR("[ws281x_esp32] Could not get RMT counter clock\n");
return;
}

/* compute phase times used in ws2812_rmt_adapter once rmt_write_sample is called */
uint32_t total_cycles = freq / (NS_PER_SEC / WS281X_T_DATA_NS);
_ws281x_one_on = freq / (NS_PER_SEC / WS281X_T_DATA_ONE_NS);
_ws281x_one_off = total_cycles - _ws281x_one_on;
_ws281x_zero_on = freq / (NS_PER_SEC / WS281X_T_DATA_ZERO_NS);
_ws281x_zero_off = total_cycles - _ws281x_zero_on;

rmt_write_sample(channel, (const uint8_t *)buf, size, false);
#else
const uint8_t *pos = buf;
Expand Down Expand Up @@ -192,7 +176,7 @@ int ws281x_init(ws281x_t *dev, const ws281x_params_t *params)
"[ws281x_esp32] RMT configuration problem");

/* determine used RMT channel from configured GPIO */
uint8_t channel = _rmt_channel(dev);
channel = _rmt_channel(dev);

rmt_config_t cfg = RMT_DEFAULT_CONFIG_TX(params->pin, channel);
cfg.clk_div = 2;
Expand All @@ -203,6 +187,21 @@ int ws281x_init(ws281x_t *dev, const ws281x_params_t *params)
LOG_ERROR("[ws281x_esp32] RMT initialization failed\n");
return -EIO;
}

/* determine the current clock frequency */
uint32_t freq;
if (rmt_get_counter_clock(channel, &freq) != ESP_OK) {
LOG_ERROR("[ws281x_esp32] Could not get RMT counter clock\n");
return -EIO;
}

/* compute phase times used in ws2812_rmt_adapter */
uint32_t total_cycles = freq / (NS_PER_SEC / WS281X_T_DATA_NS);
_ws281x_one_on = freq / (NS_PER_SEC / WS281X_T_DATA_ONE_NS);
_ws281x_one_off = total_cycles - _ws281x_one_on;
_ws281x_zero_on = freq / (NS_PER_SEC / WS281X_T_DATA_ZERO_NS);
_ws281x_zero_off = total_cycles - _ws281x_zero_on;

#else
if (gpio_init(dev->params.pin, GPIO_OUT)) {
return -EIO;
Expand Down
Loading