Loading...
Searching...
No Matches
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
9#pragma once
10
25
26#if defined(CPU_FAM_ESP32)
28#elif defined(CPU_FAM_ESP32C3)
30#elif defined(CPU_FAM_ESP32S2)
32#elif defined(CPU_FAM_ESP32S3)
34#else
35#error "ESP32x SoC family not supported"
36#endif
37
38/* include periph_cpu.h to make it visible in any case */
39#include "periph_cpu.h"
40#include "kernel_defines.h"
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
50
58#ifndef ADC_GPIOS
59#define ADC_GPIOS { }
60#endif
61
65static const gpio_t adc_channels[] = ADC_GPIOS;
66
75#define ADC_NUMOF ARRAY_SIZE(adc_channels)
77
82
90#ifndef DAC_GPIOS
91#define DAC_GPIOS { }
92#endif
93
97static const gpio_t dac_channels[] = DAC_GPIOS;
98
107#define DAC_NUMOF ARRAY_SIZE(dac_channels)
109
114
115#if defined(I2C0_SCL) && !defined(I2C0_SCL_PULLUP)
117#define I2C0_SCL_PULLUP true
118#endif
119
120#if defined(I2C0_SDA) && !defined(I2C0_SDA_PULLUP)
122#define I2C0_SDA_PULLUP true
123#endif
124
125#if (SOC_I2C_NUM > 1) && defined(I2C1_SCL) && !defined(I2C1_SCL_PULLUP)
127#define I2C1_SCL_PULLUP true
128#endif
129
130#if (SOC_I2C_NUM > 1) && defined(I2C1_SDA) && !defined(I2C1_SDA_PULLUP)
132#define I2C1_SDA_PULLUP true
133#endif
134
138static const i2c_conf_t i2c_config[] = {
139#if defined(I2C0_SCL) && defined(I2C0_SDA) && defined(I2C0_SPEED)
140 {
141 .module = PERIPH_I2C0_MODULE,
142 .speed = I2C0_SPEED,
143 .scl = I2C0_SCL,
144 .sda = I2C0_SDA,
145 .scl_pullup = I2C0_SCL_PULLUP,
146 .sda_pullup = I2C0_SCL_PULLUP,
147 },
148#endif
149#if (SOC_I2C_NUM > 1) && defined(I2C1_SCL) && defined(I2C1_SDA) && defined(I2C1_SPEED)
150 {
151 .module = PERIPH_I2C1_MODULE,
152 .speed = I2C1_SPEED,
153 .scl = I2C1_SCL,
154 .sda = I2C1_SDA,
155 .scl_pullup = I2C1_SCL_PULLUP,
156 .sda_pullup = I2C1_SCL_PULLUP,
157 },
158#endif
159};
160
169#define I2C_NUMOF ARRAY_SIZE(i2c_config)
170
172
177
181#ifdef PWM0_GPIOS
182static const gpio_t pwm0_gpios[] = PWM0_GPIOS;
183#endif
184
188#ifdef PWM1_GPIOS
189static const gpio_t pwm1_gpios[] = PWM1_GPIOS;
190#endif
191
195#ifdef PWM2_GPIOS
196static const gpio_t pwm2_gpios[] = PWM2_GPIOS;
197#endif
198
202#ifdef PWM3_GPIOS
203static const gpio_t pwm3_gpios[] = PWM3_GPIOS;
204#endif
205
209static const pwm_config_t pwm_config[] =
210{
211#ifdef PWM0_GPIOS
212 {
213 .module = PERIPH_LEDC_MODULE,
214 .group = LEDC_LOW_SPEED_MODE,
215 .timer = LEDC_TIMER_0,
216 .ch_numof = ARRAY_SIZE(pwm0_gpios),
217 .gpios = pwm0_gpios,
218 },
219#endif
220#ifdef PWM1_GPIOS
221 {
222 .module = PERIPH_LEDC_MODULE,
223#ifdef SOC_LEDC_SUPPORT_HS_MODE
224 .group = LEDC_HIGH_SPEED_MODE,
225#else
226 .group = LEDC_LOW_SPEED_MODE,
227#endif
228 .timer = LEDC_TIMER_1,
229 .ch_numof = ARRAY_SIZE(pwm1_gpios),
230 .gpios = pwm1_gpios,
231 },
232#endif
233#ifdef PWM2_GPIOS
234 {
235 .module = PERIPH_LEDC_MODULE,
236 .group = LEDC_LOW_SPEED_MODE,
237 .timer = LEDC_TIMER_2,
238 .ch_numof = ARRAY_SIZE(pwm2_gpios),
239 .gpios = pwm2_gpios,
240 },
241#endif
242#ifdef PWM3_GPIOS
243 {
244 .module = PERIPH_LEDC_MODULE,
245#ifdef SOC_LEDC_SUPPORT_HS_MODE
246 .group = LEDC_HIGH_SPEED_MODE,
247#else
248 .group = LEDC_LOW_SPEED_MODE,
249#endif
250 .timer = LEDC_TIMER_3,
251 .ch_numof = ARRAY_SIZE(pwm3_gpios),
252 .gpios = pwm3_gpios,
253 },
254#endif
255};
256
264#define PWM_NUMOF ARRAY_SIZE(pwm_config)
265
267
272
284#ifndef HAVE_RMT_CHANNEL_CONFIG
286#ifdef WS281X_PARAM_PIN
287 { 0, WS281X_PARAM_PIN },
288#else
289 /* default for boards that don't define WS281X_PARAM_PIN */
290 { 0, GPIO0 },
291#endif
292};
293#endif
294
298#define RMT_CH_NUMOF ARRAY_SIZE(rmt_channel_config)
299
301
306
310static const spi_conf_t spi_config[] = {
311#if defined(SPI0_CTRL)
312 {
313 .ctrl = SPI0_CTRL,
314 .sck = SPI0_SCK,
315 .mosi = SPI0_MOSI,
316 .miso = SPI0_MISO,
317 .cs = SPI0_CS0,
318 },
319#endif
320#if defined(SPI1_CTRL) && (SOC_SPI_PERIPH_NUM > 2)
321 {
322 .ctrl = SPI1_CTRL,
323 .sck = SPI1_SCK,
324 .mosi = SPI1_MOSI,
325 .miso = SPI1_MISO,
326 .cs = SPI1_CS0,
327 },
328#endif
329};
330
339#define SPI_NUMOF ARRAY_SIZE(spi_config)
340
341#if IS_USED(MODULE_PERIPH_SPI)
342static_assert(SPI_NUMOF != 0, "No SPI devices defined");
343#endif
345
350
354static const uart_conf_t uart_config[] = {
355 {
356 .txd = UART0_TXD,
357 .rxd = UART0_RXD,
358 },
359#if (SOC_UART_NUM > 1) && defined(UART1_TXD) && defined(UART1_RXD)
360 {
361 .txd = UART1_TXD,
362 .rxd = UART1_RXD,
363 },
364#endif
365#if (SOC_UART_NUM > 2) && defined(UART2_TXD) && defined(UART2_RXD)
366 {
367 .txd = UART2_TXD,
368 .rxd = UART2_RXD,
369 },
370#endif
371};
372
381#define UART_NUMOF ARRAY_SIZE(uart_config)
383
384#ifdef SOC_USB_OTG_SUPPORTED
389
390#include "usbdev_esp32.h"
391
396 {
397 .periph = USB_OTG_FS_PERIPH_BASE,
398 .type = DWC2_USB_OTG_FS,
400 }
401};
402
406#define USBDEV_NUMOF ARRAY_SIZE(dwc2_usb_otg_fshs_config)
407
409#endif /* SOC_USB_OTG_SUPPORTED */
410
411#ifdef __cplusplus
412} /* end extern "C" */
413#endif
414
#define WS281X_PARAM_PIN
GPIO pin connected to the data pin of the first LED.
Definition board.h:74
#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.
#define SPI1_MOSI
HSPI MOSI.
#define SPI1_SCK
HSPI SCK.
#define SPI1_MISO
HSPI MISO.
#define SPI1_CS0
HSPI CS0.
#define SPI1_CTRL
HSPI is used as SPI_DEV(1)
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition container.h:82
#define DAC_GPIOS
Declaration of GPIOs that can be used as DAC channels.
static const gpio_t dac_channels[]
Static array with declared DAC channels.
static const rmt_channel_config_t rmt_channel_config[]
RMT channel configuration.
#define ADC_GPIOS
Declaration of GPIOs that can be used as ADC channels.
#define SPI0_MOSI
HSPI / SPI_DEV(0) MOSI pin.
#define UART1_TXD
TxD pin of UART_DEV(1)
#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 UART1_RXD
RxD pin of UART_DEV(1)
#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.
#define SPI_NUMOF
Amount of SPI devices.
Common macros and compiler attributes/pragmas configuration.
Common declarations of ESP32 periphery for all ESP32 boards.
#define UART0_RXD
RxD of UART_DEV(0) used on all ESP32 boards.
#define UART0_TXD
TxD of UART_DEV(0) used on all ESP32 boards.
Common peripheral configurations for ESP32-C3 boards.
Common peripheral configurations for ESP32-S2 boards.
Common peripheral configurations for ESP32-S3 boards.
I2C configuration structure.
Definition periph_cpu.h:298
PWM configuration structure type.
Definition periph_cpu.h:572
RMT channel configuration.
Definition periph_cpu.h:612
SPI device configuration.
Definition periph_cpu.h:336
UART device configuration.
Definition periph_cpu.h:217
@ DWC2_USB_OTG_PHY_BUILTIN
on-chip FS PHY
@ DWC2_USB_OTG_FS
Full speed peripheral.