Skip to content

Commit b224e7d

Browse files
authored
Merge pull request #148 from someweisguy:feature/idf-5_2
Support for ESP-IDF v5.2
2 parents 7d89cc4 + 252b91f commit b224e7d

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/dmx/hal/uart.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
#include "rdm/include/driver.h"
88
#include "rdm/include/uid.h"
99

10-
#if ESP_IDF_VERSION_MAJOR >= 5
10+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
1111
#include "esp_private/esp_clk.h"
1212
#include "esp_private/periph_ctrl.h"
1313
#include "esp_timer.h"
14+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
15+
#include "soc/uart_periph.h"
16+
#endif
1417
#else
1518
#include "driver/periph_ctrl.h"
1619
#include "driver/timer.h"
@@ -335,10 +338,20 @@ bool dmx_uart_init(dmx_port_t dmx_num, void *isr_context, int isr_flags) {
335338
periph_module_reset(uart_periph_signal[dmx_num].module);
336339
#endif
337340
}
338-
#if ESP_IDF_VERSION_MAJOR >= 5
339-
uart_ll_set_sclk(uart->dev, UART_SCLK_DEFAULT);
341+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
340342
uint32_t sclk_freq;
343+
#if CONFIG_IDF_TARGET_ESP32C6
344+
// UART2 on C6 is a LP UART, with fixed GPIO pins for tx, rx, and rts
345+
if (dmx_num == 2) {
346+
LP_CLKRST.lpperi.lp_uart_clk_sel = 0; // Use LP_UART_SCLK_LP_FAST
347+
} else {
348+
uart_ll_set_sclk(uart->dev, UART_SCLK_DEFAULT);
349+
}
341350
uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq);
351+
#else
352+
uart_ll_set_sclk(uart->dev, UART_SCLK_DEFAULT);
353+
uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq);
354+
#endif
342355
uart_ll_set_baudrate(uart->dev, DMX_BAUD_RATE, sclk_freq);
343356
#else
344357
uart_ll_set_sclk(uart->dev, UART_SCLK_APB);
@@ -380,7 +393,7 @@ bool dmx_uart_set_pin(dmx_port_t dmx_num, int tx, int rx, int rts) {
380393

381394
uint32_t dmx_uart_get_baud_rate(dmx_port_t dmx_num) {
382395
struct dmx_uart_t *uart = &dmx_uart_context[dmx_num];
383-
#if ESP_IDF_VERSION_MAJOR >= 5
396+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
384397
uint32_t sclk_freq;
385398
uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq);
386399
return uart_ll_get_baudrate(uart->dev, sclk_freq);
@@ -391,7 +404,7 @@ uint32_t dmx_uart_get_baud_rate(dmx_port_t dmx_num) {
391404

392405
void dmx_uart_set_baud_rate(dmx_port_t dmx_num, uint32_t baud_rate) {
393406
struct dmx_uart_t *uart = &dmx_uart_context[dmx_num];
394-
#if ESP_IDF_VERSION_MAJOR >= 5
407+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
395408
uint32_t sclk_freq;
396409
uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq);
397410
uart_ll_set_baudrate(uart->dev, baud_rate, sclk_freq);

0 commit comments

Comments
 (0)