periph_conf_common.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2023 Gunar Schorcht
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
23 #if defined(CPU_FAM_ESP32)
25 #elif defined(CPU_FAM_ESP32C3)
27 #elif defined(CPU_FAM_ESP32H2)
29 #elif defined(CPU_FAM_ESP32S2)
31 #elif defined(CPU_FAM_ESP32S3)
33 #else
34 # error "ESP32x SoC family not supported"
35 #endif
36 
37 /* include periph_cpu.h to make it visible in any case */
38 #include "periph_cpu.h"
39 #include "kernel_defines.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
57 #ifndef ADC_GPIOS
58 #define ADC_GPIOS { }
59 #endif
60 
64 static const gpio_t adc_channels[] = ADC_GPIOS;
65 
74 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
89 #ifndef DAC_GPIOS
90 #define DAC_GPIOS { }
91 #endif
92 
96 static const gpio_t dac_channels[] = DAC_GPIOS;
97 
106 #define DAC_NUMOF ARRAY_SIZE(dac_channels)
114 #if defined(I2C0_SCL) && !defined(I2C0_SCL_PULLUP)
116 #define I2C0_SCL_PULLUP true
117 #endif
118 
119 #if defined(I2C0_SDA) && !defined(I2C0_SDA_PULLUP)
121 #define I2C0_SDA_PULLUP true
122 #endif
123 
124 #if (SOC_I2C_NUM > 1) && defined(I2C1_SCL) && !defined(I2C1_SCL_PULLUP)
126 #define I2C1_SCL_PULLUP true
127 #endif
128 
129 #if (SOC_I2C_NUM > 1) && defined(I2C1_SDA) && !defined(I2C1_SDA_PULLUP)
131 #define I2C1_SDA_PULLUP true
132 #endif
133 
137 static const i2c_conf_t i2c_config[] = {
138 #if defined(I2C0_SCL) && defined(I2C0_SDA) && defined(I2C0_SPEED)
139  {
140  .module = PERIPH_I2C0_MODULE,
141  .speed = I2C0_SPEED,
142  .scl = I2C0_SCL,
143  .sda = I2C0_SDA,
144  .scl_pullup = I2C0_SCL_PULLUP,
145  .sda_pullup = I2C0_SCL_PULLUP,
146  },
147 #endif
148 #if (SOC_I2C_NUM > 1) && defined(I2C1_SCL) && defined(I2C1_SDA) && defined(I2C1_SPEED)
149  {
150  .module = PERIPH_I2C1_MODULE,
151  .speed = I2C1_SPEED,
152  .scl = I2C1_SCL,
153  .sda = I2C1_SDA,
154  .scl_pullup = I2C1_SCL_PULLUP,
155  .sda_pullup = I2C1_SCL_PULLUP,
156  },
157 #endif
158 };
159 
168 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
169 
180 #ifdef PWM0_GPIOS
181 static const gpio_t pwm0_gpios[] = PWM0_GPIOS;
182 #endif
183 
187 #ifdef PWM1_GPIOS
188 static const gpio_t pwm1_gpios[] = PWM1_GPIOS;
189 #endif
190 
194 #ifdef PWM2_GPIOS
195 static const gpio_t pwm2_gpios[] = PWM2_GPIOS;
196 #endif
197 
201 #ifdef PWM3_GPIOS
202 static const gpio_t pwm3_gpios[] = PWM3_GPIOS;
203 #endif
204 
208 static const pwm_config_t pwm_config[] =
209 {
210 #ifdef PWM0_GPIOS
211  {
212  .module = PERIPH_LEDC_MODULE,
213  .group = LEDC_LOW_SPEED_MODE,
214  .timer = LEDC_TIMER_0,
215  .ch_numof = ARRAY_SIZE(pwm0_gpios),
216  .gpios = pwm0_gpios,
217  },
218 #endif
219 #ifdef PWM1_GPIOS
220  {
221  .module = PERIPH_LEDC_MODULE,
222 #ifdef SOC_LEDC_SUPPORT_HS_MODE
223  .group = LEDC_HIGH_SPEED_MODE,
224 #else
225  .group = LEDC_LOW_SPEED_MODE,
226 #endif
227  .timer = LEDC_TIMER_1,
228  .ch_numof = ARRAY_SIZE(pwm1_gpios),
229  .gpios = pwm1_gpios,
230  },
231 #endif
232 #ifdef PWM2_GPIOS
233  {
234  .module = PERIPH_LEDC_MODULE,
235  .group = LEDC_LOW_SPEED_MODE,
236  .timer = LEDC_TIMER_2,
237  .ch_numof = ARRAY_SIZE(pwm2_gpios),
238  .gpios = pwm2_gpios,
239  },
240 #endif
241 #ifdef PWM3_GPIOS
242  {
243  .module = PERIPH_LEDC_MODULE,
244 #ifdef SOC_LEDC_SUPPORT_HS_MODE
245  .group = LEDC_HIGH_SPEED_MODE,
246 #else
247  .group = LEDC_LOW_SPEED_MODE,
248 #endif
249  .timer = LEDC_TIMER_3,
250  .ch_numof = ARRAY_SIZE(pwm3_gpios),
251  .gpios = pwm3_gpios,
252  },
253 #endif
254 };
255 
263 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
264 
283 #ifndef HAVE_RMT_CHANNEL_CONFIG
285 #ifdef WS281X_PARAM_PIN
286  { 0, WS281X_PARAM_PIN },
287 #else
288  /* default for boards that don't define WS281X_PARAM_PIN */
289  { 0, GPIO0 },
290 #endif
291 };
292 #endif
293 
297 #define RMT_CH_NUMOF ARRAY_SIZE(rmt_channel_config)
298 
309 static const spi_conf_t spi_config[] = {
310 #if defined(SPI0_CTRL)
311  {
312  .ctrl = SPI0_CTRL,
313  .sck = SPI0_SCK,
314  .mosi = SPI0_MOSI,
315  .miso = SPI0_MISO,
316  .cs = SPI0_CS0,
317  },
318 #endif
319 #if defined(SPI1_CTRL) && (SOC_SPI_PERIPH_NUM > 2)
320  {
321  .ctrl = SPI1_CTRL,
322  .sck = SPI1_SCK,
323  .mosi = SPI1_MOSI,
324  .miso = SPI1_MISO,
325  .cs = SPI1_CS0,
326  },
327 #endif
328 };
329 
338 #define SPI_NUMOF ARRAY_SIZE(spi_config)
339 
340 #if IS_USED(MODULE_PERIPH_SPI)
341 static_assert(SPI_NUMOF != 0, "No SPI devices defined");
342 #endif
353 static const uart_conf_t uart_config[] = {
354  {
355  .txd = UART0_TXD,
356  .rxd = UART0_RXD,
357  },
358 #if (SOC_UART_NUM > 1) && defined(UART1_TXD) && defined(UART1_RXD)
359  {
360  .txd = UART1_TXD,
361  .rxd = UART1_RXD,
362  },
363 #endif
364 #if (SOC_UART_NUM > 2) && defined(UART2_TXD) && defined(UART2_RXD)
365  {
366  .txd = UART2_TXD,
367  .rxd = UART2_RXD,
368  },
369 #endif
370 };
371 
380 #define UART_NUMOF ARRAY_SIZE(uart_config)
383 #ifdef SOC_USB_OTG_SUPPORTED
389 #include "usbdev_esp32.h"
390 
395  {
396  .periph = USB_OTG_FS_PERIPH_BASE,
397  .type = DWC2_USB_OTG_FS,
399  }
400 };
401 
405 #define USBDEV_NUMOF ARRAY_SIZE(dwc2_usb_otg_fshs_config)
406 
408 #endif /* SOC_USB_OTG_SUPPORTED */
409 
410 #ifdef __cplusplus
411 } /* end extern "C" */
412 #endif
413 
#define WS281X_PARAM_PIN
GPIO pin connected to the data pin of the first LED.
Definition: board.h:71
#define static_assert(cond,...)
static_assert for c-version < c11
Definition: assert.h:153
#define I2C0_SPEED
I2C bus speed of I2C_DEV(0)
Definition: periph_conf.h:65
#define I2C0_SCL
SCL signal of I2C_DEV(0)
Definition: periph_conf.h:68
#define I2C0_SDA
SDA signal of I2C_DEV(0)
Definition: periph_conf.h:71
#define PWM1_GPIOS
PWM_DEV(1) is not used.
Definition: periph_conf.h:108
#define SPI1_MOSI
HSPI MOSI.
Definition: periph_conf.h:163
#define SPI1_SCK
HSPI SCK.
Definition: periph_conf.h:157
#define SPI1_MISO
HSPI MISO.
Definition: periph_conf.h:160
#define SPI1_CS0
HSPI CS0.
Definition: periph_conf.h:166
#define SPI1_CTRL
HSPI is used as SPI_DEV(1)
Definition: periph_conf.h:154
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition: container.h:82
static const uart_conf_t uart_config[]
Static array with configuration for declared UART devices.
#define DAC_GPIOS
Declaration of GPIOs that can be used as DAC channels.
static const pwm_config_t pwm_config[]
GPIOs used as channels for the according PWM device.
static const gpio_t dac_channels[]
Static array with declared DAC channels.
static const spi_conf_t spi_config[]
Static array with configuration for declared SPI devices.
static const rmt_channel_config_t rmt_channel_config[]
RMT channel configuration.
static const gpio_t adc_channels[]
Static array with declared ADC channels.
static const i2c_conf_t i2c_config[]
Static array with configuration for declared I2C devices.
#define SPI_NUMOF
Number of SPI interfaces.
#define ADC_GPIOS
Declaration of GPIOs that can be used as ADC channels.
#define SPI0_MOSI
HSPI / SPI_DEV(0) MOSI pin.
#define SPI0_CTRL
HSPI / SPI_DEV(0) controller.
#define SPI0_CS0
HSPI / SPI_DEV(0) CS default pin, only used when cs parameter in spi_acquire is GPIO_UNDEF.
#define SPI0_SCK
HSPI / SPI_DEV(0) SCK pin.
#define SPI0_MISO
HSPI / SPI_DEV(0) MISO pin.
static const dwc2_usb_otg_fshs_config_t dwc2_usb_otg_fshs_config[]
Common USB OTG FS configuration.
@ UART1_RXD
UART1 RXD.
Definition: cc2538_gpio.h:281
@ UART0_RXD
UART0 RXD.
Definition: cc2538_gpio.h:279
@ UART0_TXD
UART0 TXD.
Definition: cc2538_gpio.h:250
@ UART1_TXD
UART1 TXD.
Definition: cc2538_gpio.h:252
Common macros and compiler attributes/pragmas configuration.
Common declarations of ESP32 periphery for all ESP32 boards.
Common peripheral configurations for ESP32-C3 boards.
Common peripheral configurations for ESP32-H2 boards.
Common peripheral configurations for ESP32-S2 boards.
Common peripheral configurations for ESP32-S3 boards.
#define GPIO0
GPIO0.
USB OTG configuration.
uintptr_t periph
USB peripheral base address.
I2C configuration structure.
Definition: periph_cpu.h:298
uint8_t module
I2C module identifier.
Definition: periph_cpu.h:468
PWM configuration structure type.
Definition: periph_cpu.h:576
uint8_t module
LEDC module identifier.
Definition: periph_cpu.h:577
RMT channel configuration.
Definition: periph_cpu.h:616
SPI device configuration.
Definition: periph_cpu.h:336
spi_ctrl_t ctrl
SPI controller used for the interface.
Definition: periph_cpu.h:864
UART device configuration.
Definition: periph_cpu.h:217
gpio_t txd
GPIO used as TxD pin.
Definition: periph_cpu.h:977
@ DWC2_USB_OTG_PHY_BUILTIN
on-chip FS PHY
@ DWC2_USB_OTG_FS
Full speed peripheral.