Skip to content

Commit

Permalink
Merge pull request #9051 from tannewt/fix_h2
Browse files Browse the repository at this point in the history
Fix RMT clock speed on H2
  • Loading branch information
dhalbert authored Mar 14, 2024
2 parents 636b9df + d34af65 commit fcac731
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ports/espressif/common-hal/neopixel_write/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#include "shared-bindings/neopixel_write/__init__.h"

#include "esp_clk_tree.h"
#include "py/mphal.h"
#include "py/runtime.h"

Expand All @@ -61,10 +62,14 @@ static uint64_t next_start_raw_ticks = 0;

void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout, uint8_t *pixels, uint32_t numBytes) {
// Reserve channel
uint32_t clock_speed;
esp_clk_tree_src_get_freq_hz(RMT_CLK_SRC_DEFAULT,
ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED,
&clock_speed);
rmt_tx_channel_config_t config = {
.gpio_num = digitalinout->pin->number,
.clk_src = RMT_CLK_SRC_DEFAULT,
.resolution_hz = 40000000,
.resolution_hz = clock_speed,
.trans_queue_depth = 1,
};

Expand All @@ -81,7 +86,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout,
}
CHECK_ESP_RESULT(result);

size_t ns_per_tick = 1e9 / 40000000;
size_t ns_per_tick = 1e9 / clock_speed;
uint16_t ws2812_t0h_ticks = WS2812_T0H_NS / ns_per_tick;
uint16_t ws2812_t0l_ticks = WS2812_T0L_NS / ns_per_tick;
uint16_t ws2812_t1h_ticks = WS2812_T1H_NS / ns_per_tick;
Expand Down

0 comments on commit fcac731

Please sign in to comment.