periph_conf_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Gunar Schorcht
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
24 #ifndef PERIPH_CONF_COMMON_H
25 #define PERIPH_CONF_COMMON_H
26 
27 #if defined(CPU_FAM_ESP32)
29 #elif defined(CPU_FAM_ESP32C3)
31 #elif defined(CPU_FAM_ESP32S2)
33 #elif defined(CPU_FAM_ESP32S3)
35 #else
36 #error "ESP32x SoC family not supported"
37 #endif
38 
39 /* include periph_cpu.h to make it visible in any case */
40 #include "periph_cpu.h"
41 #include "kernel_defines.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
59 #ifndef ADC_GPIOS
60 #define ADC_GPIOS { }
61 #endif
62 
66 static const gpio_t adc_channels[] = ADC_GPIOS;
67 
76 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
91 #ifndef DAC_GPIOS
92 #define DAC_GPIOS { }
93 #endif
94 
98 static const gpio_t dac_channels[] = DAC_GPIOS;
99 
108 #define DAC_NUMOF ARRAY_SIZE(dac_channels)
116 #if defined(I2C0_SCL) && !defined(I2C0_SCL_PULLUP)
118 #define I2C0_SCL_PULLUP true
119 #endif
120 
121 #if defined(I2C0_SDA) && !defined(I2C0_SDA_PULLUP)
123 #define I2C0_SDA_PULLUP true
124 #endif
125 
126 #if (SOC_I2C_NUM > 1) && defined(I2C1_SCL) && !defined(I2C1_SCL_PULLUP)
128 #define I2C1_SCL_PULLUP true
129 #endif
130 
131 #if (SOC_I2C_NUM > 1) && defined(I2C1_SDA) && !defined(I2C1_SDA_PULLUP)
133 #define I2C1_SDA_PULLUP true
134 #endif
135 
139 static const i2c_conf_t i2c_config[] = {
140 #if defined(I2C0_SCL) && defined(I2C0_SDA) && defined(I2C0_SPEED)
141  {
142  .module = PERIPH_I2C0_MODULE,
143  .speed = I2C0_SPEED,
144  .scl = I2C0_SCL,
145  .sda = I2C0_SDA,
146  .scl_pullup = I2C0_SCL_PULLUP,
147  .sda_pullup = I2C0_SCL_PULLUP,
148  },
149 #endif
150 #if (SOC_I2C_NUM > 1) && defined(I2C1_SCL) && defined(I2C1_SDA) && defined(I2C1_SPEED)
151  {
152  .module = PERIPH_I2C1_MODULE,
153  .speed = I2C1_SPEED,
154  .scl = I2C1_SCL,
155  .sda = I2C1_SDA,
156  .scl_pullup = I2C1_SCL_PULLUP,
157  .sda_pullup = I2C1_SCL_PULLUP,
158  },
159 #endif
160 };
161 
170 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
171 
182 #ifdef PWM0_GPIOS
183 static const gpio_t pwm0_gpios[] = PWM0_GPIOS;
184 #endif
185 
189 #ifdef PWM1_GPIOS
190 static const gpio_t pwm1_gpios[] = PWM1_GPIOS;
191 #endif
192 
196 #ifdef PWM2_GPIOS
197 static const gpio_t pwm2_gpios[] = PWM2_GPIOS;
198 #endif
199 
203 #ifdef PWM3_GPIOS
204 static const gpio_t pwm3_gpios[] = PWM3_GPIOS;
205 #endif
206 
210 static const pwm_config_t pwm_config[] =
211 {
212 #ifdef PWM0_GPIOS
213  {
214  .module = PERIPH_LEDC_MODULE,
215  .group = LEDC_LOW_SPEED_MODE,
216  .timer = LEDC_TIMER_0,
217  .ch_numof = ARRAY_SIZE(pwm0_gpios),
218  .gpios = pwm0_gpios,
219  },
220 #endif
221 #ifdef PWM1_GPIOS
222  {
223  .module = PERIPH_LEDC_MODULE,
224 #ifdef SOC_LEDC_SUPPORT_HS_MODE
225  .group = LEDC_HIGH_SPEED_MODE,
226 #else
227  .group = LEDC_LOW_SPEED_MODE,
228 #endif
229  .timer = LEDC_TIMER_1,
230  .ch_numof = ARRAY_SIZE(pwm1_gpios),
231  .gpios = pwm1_gpios,
232  },
233 #endif
234 #ifdef PWM2_GPIOS
235  {
236  .module = PERIPH_LEDC_MODULE,
237  .group = LEDC_LOW_SPEED_MODE,
238  .timer = LEDC_TIMER_2,
239  .ch_numof = ARRAY_SIZE(pwm2_gpios),
240  .gpios = pwm2_gpios,
241  },
242 #endif
243 #ifdef PWM3_GPIOS
244  {
245  .module = PERIPH_LEDC_MODULE,
246 #ifdef SOC_LEDC_SUPPORT_HS_MODE
247  .group = LEDC_HIGH_SPEED_MODE,
248 #else
249  .group = LEDC_LOW_SPEED_MODE,
250 #endif
251  .timer = LEDC_TIMER_3,
252  .ch_numof = ARRAY_SIZE(pwm3_gpios),
253  .gpios = pwm3_gpios,
254  },
255 #endif
256 };
257 
265 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
266 
285 #ifndef HAVE_RMT_CHANNEL_CONFIG
287 #ifdef WS281X_PARAM_PIN
288  { 0, WS281X_PARAM_PIN },
289 #else
290  /* default for boards that don't define WS281X_PARAM_PIN */
291  { 0, GPIO0 },
292 #endif
293 };
294 #endif
295 
299 #define RMT_CH_NUMOF ARRAY_SIZE(rmt_channel_config)
300 
311 static const spi_conf_t spi_config[] = {
312 #if defined(SPI0_CTRL)
313  {
314  .ctrl = SPI0_CTRL,
315  .sck = SPI0_SCK,
316  .mosi = SPI0_MOSI,
317  .miso = SPI0_MISO,
318  .cs = SPI0_CS0,
319  },
320 #endif
321 #if defined(SPI1_CTRL) && (SOC_SPI_PERIPH_NUM > 2)
322  {
323  .ctrl = SPI1_CTRL,
324  .sck = SPI1_SCK,
325  .mosi = SPI1_MOSI,
326  .miso = SPI1_MISO,
327  .cs = SPI1_CS0,
328  },
329 #endif
330 };
331 
340 #define SPI_NUMOF ARRAY_SIZE(spi_config)
341 
342 #if IS_USED(MODULE_PERIPH_SPI)
343 static_assert(SPI_NUMOF != 0, "No SPI devices defined");
344 #endif
355 static const uart_conf_t uart_config[] = {
356  {
357  .txd = UART0_TXD,
358  .rxd = UART0_RXD,
359  },
360 #if (SOC_UART_NUM > 1) && defined(UART1_TXD) && defined(UART1_RXD)
361  {
362  .txd = UART1_TXD,
363  .rxd = UART1_RXD,
364  },
365 #endif
366 #if (SOC_UART_NUM > 2) && defined(UART2_TXD) && defined(UART2_RXD)
367  {
368  .txd = UART2_TXD,
369  .rxd = UART2_RXD,
370  },
371 #endif
372 };
373 
382 #define UART_NUMOF ARRAY_SIZE(uart_config)
385 #ifdef SOC_USB_OTG_SUPPORTED
391 #include "usbdev_esp32.h"
392 
397  {
398  .periph = USB_OTG_FS_PERIPH_BASE,
399  .type = DWC2_USB_OTG_FS,
401  }
402 };
403 
407 #define USBDEV_NUMOF ARRAY_SIZE(dwc2_usb_otg_fshs_config)
408 
410 #endif /* SOC_USB_OTG_SUPPORTED */
411 
412 #ifdef __cplusplus
413 } /* end extern "C" */
414 #endif
415 
416 #endif /* PERIPH_CONF_COMMON_H */
#define WS281X_PARAM_PIN
GPIO pin connected to the data pin.
Definition: board.h:58
#define static_assert(cond,...)
static_assert for c-version < c11
Definition: assert.h:154
#define I2C0_SPEED
I2C bus speed of I2C_DEV(0)
Definition: periph_conf.h:66
#define I2C0_SCL
SCL signal of I2C_DEV(0)
Definition: periph_conf.h:69
#define I2C0_SDA
SDA signal of I2C_DEV(0)
Definition: periph_conf.h:72
#define PWM1_GPIOS
PWM_DEV(1) is not used.
Definition: periph_conf.h:109
#define SPI1_MOSI
HSPI MOSI.
Definition: periph_conf.h:164
#define SPI1_SCK
HSPI SCK.
Definition: periph_conf.h:158
#define SPI1_MISO
HSPI MISO.
Definition: periph_conf.h:161
#define SPI1_CS0
HSPI CS0.
Definition: periph_conf.h:167
#define SPI1_CTRL
HSPI is used as SPI_DEV(1)
Definition: periph_conf.h:155
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition: container.h:83
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:282
@ UART0_RXD
UART0 RXD.
Definition: cc2538_gpio.h:280
@ UART0_TXD
UART0 TXD.
Definition: cc2538_gpio.h:251
@ UART1_TXD
UART1 TXD.
Definition: cc2538_gpio.h:253
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-S2 boards.
Common peripheral configurations for ESP32-S3 boards.
USB OTG configuration.
uintptr_t periph
USB peripheral base address.
I2C configuration structure.
Definition: periph_cpu.h:299
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:337
spi_ctrl_t ctrl
SPI controller used for the interface.
Definition: periph_cpu.h:864
UART device configuration.
Definition: periph_cpu.h:218
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.