From fe63c52b3ef42c0db004b3c2f50e759e7d61a279 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Wed, 23 Oct 2024 20:22:48 +0700 Subject: [PATCH] Fix for overriding UART0 pins, reverted and fixed tests for ESP32-S3 conditional code. --- main/ioports_analog.c | 12 ++++++------ main/my_machine.h | 2 +- main/uart_serial.c | 29 +++++++++++++++-------------- main/usb_serial.c | 5 +++-- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/main/ioports_analog.c b/main/ioports_analog.c index 94c0a9b..4b2610a 100644 --- a/main/ioports_analog.c +++ b/main/ioports_analog.c @@ -61,7 +61,7 @@ static wait_on_input_ptr wait_on_input_digital; #if AUX_ANALOG_IN -#ifdef CONFIG_IDF_TARGET_ESP32 +#if CONFIG_IDF_TARGET_ESP32 static const adc_map_t adc_map[] = { { ADC1_CHANNEL_0, GPIO_NUM_36 }, @@ -74,7 +74,7 @@ static const adc_map_t adc_map[] = { { ADC1_CHANNEL_7, GPIO_NUM_35 } }; -#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#elif CONFIG_IDF_TARGET_ESP32S3 static const adc_map_t adc_map[] = { { ADC1_CHANNEL_0, GPIO_NUM_1 }, @@ -173,7 +173,7 @@ static bool init_pwm0 (xbar_t *pin, pwm_config_t *config, bool persistent) ledc_channel_config_t *ch_config = &pwm_out[ch].ch_config; static ledc_timer_config_t pwm_timer = { -#ifdef CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S3 .speed_mode = LEDC_LOW_SPEED_MODE, #else .speed_mode = LEDC_HIGH_SPEED_MODE, @@ -188,7 +188,7 @@ static bool init_pwm0 (xbar_t *pin, pwm_config_t *config, bool persistent) init_ok = true; ch_config->gpio_num = AUXOUTPUT0_PWM_PIN, -#ifdef CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S3 ch_config->speed_mode = LEDC_SPEED_MODE_MAX; #else ch_config->speed_mode = LEDC_HIGH_SPEED_MODE; @@ -252,7 +252,7 @@ static bool init_pwm1 (xbar_t *pin, pwm_config_t *config, bool persistent) ledc_channel_config_t *ch_config = &pwm_out[ch].ch_config; static ledc_timer_config_t pwm_timer = { -#ifdef CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S3 .speed_mode = LEDC_LOW_SPEED_MODE, #else .speed_mode = LEDC_HIGH_SPEED_MODE, @@ -267,7 +267,7 @@ static bool init_pwm1 (xbar_t *pin, pwm_config_t *config, bool persistent) init_ok = true; ch_config->gpio_num = AUXOUTPUT1_PWM_PIN, -#ifdef CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S3 ch_config->speed_mode = LEDC_SPEED_MODE_MAX; #else ch_config->speed_mode = LEDC_HIGH_SPEED_MODE; diff --git a/main/my_machine.h b/main/my_machine.h index a357fa6..7fa86cd 100644 --- a/main/my_machine.h +++ b/main/my_machine.h @@ -44,7 +44,7 @@ // Configuration // Uncomment to enable, for some a value > 1 may be assigned, if so the default value is shown. -#ifdef CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S3 #define USB_SERIAL_CDC 1 // Serial communication via native USB. #endif diff --git a/main/uart_serial.c b/main/uart_serial.c index b4e2525..b739282 100644 --- a/main/uart_serial.c +++ b/main/uart_serial.c @@ -28,7 +28,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" -#if !defined(CONFIG_IDF_TARGET_ESP32S3) +#if !CONFIG_IDF_TARGET_ESP32S3 #include "esp32/rom/ets_sys.h" #include "esp32/rom/uart.h" #endif @@ -56,7 +56,7 @@ #define UART_INTR_SOURCE(u) ((u==0)?ETS_UART0_INTR_SOURCE:( (u==1)?ETS_UART1_INTR_SOURCE:((u==2)?ETS_UART2_INTR_SOURCE:0))) -#ifdef CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S3 #ifndef UART_RX_PIN #define UART_RX_PIN 44 #endif @@ -75,7 +75,7 @@ typedef void (*uart_isr_ptr)(void *arg); typedef struct { -#ifdef CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S3 uart_dev_t *dev; #else volatile uart_dev_t *dev; @@ -282,7 +282,7 @@ static void uartConfig (uart_t *uart, uint32_t baud_rate) // uart->tx_len = 128; uart_ll_set_mode(uart->dev, UART_MODE_UART); -#ifdef CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S3 periph_module_reset((periph_module_t)(PERIPH_UART0_MODULE + uart->num)); periph_module_enable((periph_module_t)(PERIPH_UART0_MODULE + uart->num)); @@ -317,23 +317,24 @@ static void uartConfig (uart_t *uart, uint32_t baud_rate) // Note: UART0 pin mappings are set at boot, no need to set here unless override is required -#if SERIAL2_ENABLE || SERIAL3_ENABLE - - switch(uart->num) { -#ifdef CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S3 #if UART_RX_PIN != 44 || UART_TX_PIN != 43 - case 0: - uart_set_pin(uart->num, UART_TX_PIN, UART_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - break; +#define UART0_PINS_REDEFINED #endif #else #if UART_RX_PIN != 34 || UART_TX_PIN != 35 - case 0: - uart_set_pin(uart->num, UART_TX_PIN, UART_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - break; +#define UART0_PINS_REDEFINED #endif #endif +#if SERIAL2_ENABLE || SERIAL3_ENABLE || defined(UART0_PINS_REDEFINED) + + switch(uart->num) { + #ifdef UART0_PINS_REDEFINED + case 0: + uart_set_pin(uart->num, UART_TX_PIN, UART_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + break; + #endif #if SERIAL2_ENABLE case 1: #ifdef UART2_TX_PIN diff --git a/main/usb_serial.c b/main/usb_serial.c index 31906d1..50606fe 100644 --- a/main/usb_serial.c +++ b/main/usb_serial.c @@ -29,7 +29,9 @@ */ -#ifdef CONFIG_IDF_TARGET_ESP32S3 +#include "sdkconfig.h" + +#if CONFIG_IDF_TARGET_ESP32S3 #include #include "esp_log.h" @@ -37,7 +39,6 @@ #include "freertos/task.h" #include "tinyusb.h" #include "tusb_cdc_acm.h" -#include "sdkconfig.h" #include