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

Support for ESP-IDF v5.2 #148

Merged
merged 2 commits into from
Mar 21, 2024
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
23 changes: 18 additions & 5 deletions src/dmx/hal/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
#include "rdm/include/driver.h"
#include "rdm/include/uid.h"

#if ESP_IDF_VERSION_MAJOR >= 5
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
#include "esp_private/esp_clk.h"
#include "esp_private/periph_ctrl.h"
#include "esp_timer.h"
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
#include "soc/uart_periph.h"
#endif
#else
#include "driver/periph_ctrl.h"
#include "driver/timer.h"
Expand Down Expand Up @@ -335,10 +338,20 @@ bool dmx_uart_init(dmx_port_t dmx_num, void *isr_context, int isr_flags) {
periph_module_reset(uart_periph_signal[dmx_num].module);
#endif
}
#if ESP_IDF_VERSION_MAJOR >= 5
uart_ll_set_sclk(uart->dev, UART_SCLK_DEFAULT);
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
uint32_t sclk_freq;
#if CONFIG_IDF_TARGET_ESP32C6
// UART2 on C6 is a LP UART, with fixed GPIO pins for tx, rx, and rts
if (dmx_num == 2) {
LP_CLKRST.lpperi.lp_uart_clk_sel = 0; // Use LP_UART_SCLK_LP_FAST
} else {
uart_ll_set_sclk(uart->dev, UART_SCLK_DEFAULT);
}
uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq);
#else
uart_ll_set_sclk(uart->dev, UART_SCLK_DEFAULT);
uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq);
#endif
uart_ll_set_baudrate(uart->dev, DMX_BAUD_RATE, sclk_freq);
#else
uart_ll_set_sclk(uart->dev, UART_SCLK_APB);
Expand Down Expand Up @@ -380,7 +393,7 @@ bool dmx_uart_set_pin(dmx_port_t dmx_num, int tx, int rx, int rts) {

uint32_t dmx_uart_get_baud_rate(dmx_port_t dmx_num) {
struct dmx_uart_t *uart = &dmx_uart_context[dmx_num];
#if ESP_IDF_VERSION_MAJOR >= 5
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
uint32_t sclk_freq;
uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq);
return uart_ll_get_baudrate(uart->dev, sclk_freq);
Expand All @@ -391,7 +404,7 @@ uint32_t dmx_uart_get_baud_rate(dmx_port_t dmx_num) {

void dmx_uart_set_baud_rate(dmx_port_t dmx_num, uint32_t baud_rate) {
struct dmx_uart_t *uart = &dmx_uart_context[dmx_num];
#if ESP_IDF_VERSION_MAJOR >= 5
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
uint32_t sclk_freq;
uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq);
uart_ll_set_baudrate(uart->dev, baud_rate, sclk_freq);
Expand Down