Skip to content

Commit

Permalink
Fixed tests for ESP32-S3 conditional code, added overridable symbols …
Browse files Browse the repository at this point in the history
…for UART0 RX/TX pins.
  • Loading branch information
terjeio committed Oct 19, 2024
1 parent 6c54c57 commit 41307cd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
12 changes: 6 additions & 6 deletions main/ioports_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static wait_on_input_ptr wait_on_input_digital;

#if AUX_ANALOG_IN

#if CONFIG_IDF_TARGET_ESP32
#ifdef CONFIG_IDF_TARGET_ESP32

static const adc_map_t adc_map[] = {
{ ADC1_CHANNEL_0, GPIO_NUM_36 },
Expand All @@ -74,7 +74,7 @@ static const adc_map_t adc_map[] = {
{ ADC1_CHANNEL_7, GPIO_NUM_35 }
};

#elif CONFIG_IDF_TARGET_ESP32S3
#elif defined(CONFIG_IDF_TARGET_ESP32S3)

static const adc_map_t adc_map[] = {
{ ADC1_CHANNEL_0, GPIO_NUM_1 },
Expand Down Expand Up @@ -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 = {
#if CONFIG_IDF_TARGET_ESP32S3
#ifdef CONFIG_IDF_TARGET_ESP32S3
.speed_mode = LEDC_LOW_SPEED_MODE,
#else
.speed_mode = LEDC_HIGH_SPEED_MODE,
Expand All @@ -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,
#if CONFIG_IDF_TARGET_ESP32S3
#ifdef CONFIG_IDF_TARGET_ESP32S3
ch_config->speed_mode = LEDC_SPEED_MODE_MAX;
#else
ch_config->speed_mode = LEDC_HIGH_SPEED_MODE;
Expand Down Expand Up @@ -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 = {
#if CONFIG_IDF_TARGET_ESP32S3
#ifdef CONFIG_IDF_TARGET_ESP32S3
.speed_mode = LEDC_LOW_SPEED_MODE,
#else
.speed_mode = LEDC_HIGH_SPEED_MODE,
Expand All @@ -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,
#if CONFIG_IDF_TARGET_ESP32S3
#ifdef CONFIG_IDF_TARGET_ESP32S3
ch_config->speed_mode = LEDC_SPEED_MODE_MAX;
#else
ch_config->speed_mode = LEDC_HIGH_SPEED_MODE;
Expand Down
2 changes: 1 addition & 1 deletion main/my_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
// Configuration
// Uncomment to enable, for some a value > 1 may be assigned, if so the default value is shown.

#if CONFIG_IDF_TARGET_ESP32S3
#ifdef CONFIG_IDF_TARGET_ESP32S3
#define USB_SERIAL_CDC 1 // Serial communication via native USB.
#endif

Expand Down
2 changes: 1 addition & 1 deletion main/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool spi_bus_init (spi_host_device_t *host)
.intr_flags = ESP_INTR_FLAG_IRAM
};

#if CONFIG_IDF_TARGET_ESP32S3
#ifdef CONFIG_IDF_TARGET_ESP32S3
dma_ch = SPI_DMA_CH_AUTO;
host_id = SDSPI_DEFAULT_HOST;
#else
Expand Down
50 changes: 36 additions & 14 deletions main/uart_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#if !CONFIG_IDF_TARGET_ESP32S3
#if !defined(CONFIG_IDF_TARGET_ESP32S3)
#include "esp32/rom/ets_sys.h"
#include "esp32/rom/uart.h"
#endif
Expand All @@ -55,10 +55,27 @@
#define UART_TXD_IDX(u) ((u==0)?U0TXD_OUT_IDX:( (u==1)?U1TXD_OUT_IDX:( (u==2)?U2TXD_OUT_IDX:0)))
#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
#ifndef UART_RX_PIN
#define UART_RX_PIN 44
#endif
#ifndef UART_TX_PIN
#define UART_TX_PIN 43
#endif
#else
#ifndef UART_RX_PIN
#define UART_RX_PIN 34
#endif
#ifndef UART_TX_PIN
#define UART_TX_PIN 35
#endif
#endif

typedef void (*uart_isr_ptr)(void *arg);

typedef struct {
#if CONFIG_IDF_TARGET_ESP32S3
#ifdef CONFIG_IDF_TARGET_ESP32S3
uart_dev_t *dev;
#else
volatile uart_dev_t *dev;
Expand Down Expand Up @@ -171,23 +188,15 @@ void serialRegisterStreams (void)
static const periph_pin_t tx0 = {
.function = Output_TX,
.group = PinGroup_UART,
#if CONFIG_IDF_TARGET_ESP32S3
.pin = 43,
#else
.pin = 35,
#endif
.pin = UART_TX_PIN,
.mode = { .mask = PINMODE_OUTPUT },
.description = "Primary UART"
};

static const periph_pin_t rx0 = {
.function = Input_RX,
.group = PinGroup_UART,
#if CONFIG_IDF_TARGET_ESP32S3
.pin = 44,
#else
.pin = 34,
#endif
.pin = UART_RX_PIN,
.mode = { .mask = PINMODE_NONE },
.description = "Primary UART"
};
Expand Down Expand Up @@ -273,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);

#if CONFIG_IDF_TARGET_ESP32S3
#ifdef 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));
Expand Down Expand Up @@ -308,9 +317,22 @@ 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
#if SERIAL2_ENABLE || SERIAL3_ENABLE

switch(uart->num) {
#ifdef 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;
#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;
#endif
#endif

#if SERIAL2_ENABLE
case 1:
Expand Down
2 changes: 1 addition & 1 deletion main/usb_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

#if CONFIG_IDF_TARGET_ESP32S3
#ifdef CONFIG_IDF_TARGET_ESP32S3

#include <stdint.h>
#include "esp_log.h"
Expand Down

0 comments on commit 41307cd

Please sign in to comment.