Loading...
Searching...
No Matches
periph_cpu.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022 Gunar Schorcht
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
17
18#include <stdbool.h>
19#include <stdint.h>
20#include "sdkconfig.h"
21#include "hal/ledc_types.h"
22#include "hal/spi_types.h"
23#include "soc/ledc_struct.h"
24#include "soc/periph_defs.h"
25#include "soc/soc_caps.h"
26
27#include "modules.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
36#define STDIO_UART_DEV CONFIG_ESP_CONSOLE_UART_NUM
37
51#ifndef CONFIG_STDIO_USB_SERIAL_JTAG_TX_TIMEOUT_US
52# define CONFIG_STDIO_USB_SERIAL_JTAG_TX_TIMEOUT_US (50 * US_PER_MS)
53#endif
54
59#define PROVIDES_PM_SET_LOWEST
60#define PROVIDES_PM_RESTART
61#define PROVIDES_PM_OFF
62#define PROVIDES_PM_LAYERED_OFF
63
67#define PM_NUM_MODES (3U)
68
73#define ESP_PM_MODEM_SLEEP (2U)
74#define ESP_PM_LIGHT_SLEEP (1U)
75#define ESP_PM_DEEP_SLEEP (0U)
77
79
83#define CPUID_LEN (6U)
84
89
96#define HAVE_GPIO_T
97typedef unsigned int gpio_t;
99
104#define GPIO_UNDEF (0xffffffff)
106
111#define GPIO_PIN(x, y) ((x << 5) | y)
113
118#define PORT_GPIO (0)
120
125#define GPIO_PIN_NUMOF (SOC_GPIO_PIN_COUNT)
127
128#ifndef DOXYGEN
134#define HAVE_GPIO_FLANK_T
135typedef enum {
136 GPIO_NONE,
137 GPIO_RISING,
138 GPIO_FALLING,
139 GPIO_BOTH,
140 GPIO_LOW,
141 GPIO_HIGH
144
150#define HAVE_GPIO_MODE_T
151typedef enum {
152 GPIO_IN,
153 GPIO_IN_PD,
154 GPIO_IN_PU,
155 GPIO_OUT,
156 GPIO_OD,
157 GPIO_OD_PU,
158 GPIO_IN_OUT,
159 GPIO_IN_OD,
160 GPIO_IN_OD_PU
163
164/* BEGIN: GPIO LL overwrites */
165
166#if SOC_GPIO_PIN_COUNT > 32
167# define GPIO_PORT_NUMOF 2
168# define GPIO_PORT_0 0
169# define GPIO_PORT_1 1
170# define GPIO_PORT_0_PIN_NUMOF (32)
171# define GPIO_PORT_1_PIN_NUMOF (SOC_GPIO_PIN_COUNT - 32)
172# define GPIO_PORT_PIN_NUMOF(p) ((p == GPIO_PORT_0) ? GPIO_PORT_0_PIN_NUMOF \
173 : GPIO_PORT_1_PIN_NUMOF)
174#else
175# define GPIO_PORT_NUMOF 1
176# define GPIO_PORT_0 0
177# define GPIO_PORT_0_PIN_NUMOF (SOC_GPIO_PIN_COUNT)
178# define GPIO_PORT_PIN_NUMOF(p) ((p == GPIO_PORT_0) ? GPIO_PORT_0_PIN_NUMOF : 0)
179#endif
180
181#define HAVE_GPIO_PORT_T
182typedef uintptr_t gpio_port_t;
183
184#define HAVE_GPIO_SLEW_T
185typedef enum {
187 GPIO_SLEW_SLOW = 0,
188 GPIO_SLEW_FAST = 0,
191
192#define HAVE_GPIO_PULL_STRENGTH_T
193typedef enum {
195 GPIO_PULL_WEAK = 0,
199
200/*
201 * This include is placed here by intention to avoid type name conflicts.
202 * Having the macros HAVE_GPIO_* defined before including this file allows to
203 * use these macros in `hal/gpio_types.h` to decide whether to use the
204 * ESP-IDF types when compiling ESP-IDF modules or to use the RIOT types
205 * when compiling RIOT source code.
206 */
207#include "hal/gpio_types.h"
208
209#define HAVE_GPIO_PULL_T
210typedef gpio_pull_mode_t gpio_pull_t;
211#define GPIO_PULL_UP GPIO_PULLUP_ONLY
212#define GPIO_PULL_DOWN GPIO_PULLDOWN_ONLY
213#define GPIO_PULL_KEEP GPIO_PULLUP_PULLDOWN
214
218#define HAVE_GPIO_DRIVE_STRENGTH_T
219typedef enum {
221 GPIO_DRIVE_WEAK = 1,
225
226/*
227 * @brief Map former enumeration values the new enumeration values for compatibility.
228 */
229#define GPIO_DRIVE_5 GPIO_DRIVE_WEAKEST
230#define GPIO_DRIVE_10 GPIO_DRIVE_WEAK
231#define GPIO_DRIVE_20 GPIO_DRIVE_STRONG
232#define GPIO_DRIVE_30 GPIO_DRIVE_STRONGEST
233
234#define HAVE_GPIO_STATE_T
235typedef enum {
243
244#define HAVE_GPIO_CONF_T
245typedef union gpio_conf_esp32 gpio_conf_t;
246
247#endif /* ndef DOXYGEN */
248
290
291/* END: GPIO LL overwrites */
293
354
358#define ADC_NUMOF_MAX (SOC_ADC_CHANNEL_NUM(0) + SOC_ADC_CHANNEL_NUM(1))
359
361
397
401#if defined(SOC_DAC_SUPPORTED) || DOXYGEN
402# define DAC_NUMOF_MAX (SOC_DAC_PERIPH_NUM)
403#endif
404
406
452
453#ifndef DOXYGEN
460#define HAVE_I2C_SPEED_T
461typedef enum {
462 I2C_SPEED_LOW = 0,
469#endif /* ndef DOXYGEN */
470
474typedef struct {
475 uint8_t module;
477 gpio_t scl;
478 gpio_t sda;
481} i2c_conf_t;
482
486#define I2C_NUMOF_MAX (SOC_I2C_NUM)
487
488#define PERIPH_I2C_NEED_READ_REG
489#define PERIPH_I2C_NEED_READ_REGS
490#define PERIPH_I2C_NEED_WRITE_REG
491#define PERIPH_I2C_NEED_WRITE_REGS
493
568
583typedef struct {
584 uint8_t module;
585 ledc_mode_t group;
586 ledc_timer_t timer;
587 uint8_t ch_numof;
588 const gpio_t *gpios;
590
594#define PWM_NUMOF_MAX (4)
595
599#define PWM_CH_NUMOF_MAX (SOC_LEDC_CHANNEL_NUM)
600
602
615
623typedef struct {
624 uint8_t channel;
627
633#define RMT_CH_NUMOF_MAX (SOC_RMT_CHANNELS_PER_GROUP)
634
636
641
645#define RNG_DATA_REG_ADDR (WDEV_RND_REG)
647
652
660#define RTT_FREQUENCY (32768UL)
661
665#define RTT_MAX_VALUE (0xFFFFFFFFUL)
666
670#define RTT_MIN_OFFSET (1U)
671
673
698typedef enum {
699#if IS_USED(SOC_SDMMC_USE_GPIO_MATRIX) || DOXYGEN
701#endif
704
716typedef struct {
720#if IS_USED(SOC_SDMMC_USE_GPIO_MATRIX) || DOXYGEN
727#if IS_USED(MODULE_PERIPH_SMMC_8BIT) || DOXYGEN
732#endif /* IS_USED(MODULE_PERIPH_SMMC_8BIT) */
733#else /* IS_USED(SOC_SDMMC_USE_IOMUX) */
734 uint8_t bus_width;
735#endif
737
741#define SDMMC_CPU_DMA_REQUIREMENTS __attribute__((aligned(SDMMC_CPU_DMA_ALIGNMENT)))
742
746#define SDMMC_CPU_DMA_ALIGNMENT 4
747
749
824
825#ifndef DOXYGEN
830#define HAVE_SPI_CLK_T
831typedef enum {
832 SPI_CLK_100KHZ = 100000,
833 SPI_CLK_400KHZ = 400000,
834 SPI_CLK_1MHZ = 1000000,
835 SPI_CLK_5MHZ = 5000000,
836 SPI_CLK_10MHZ = 10000000
837} spi_clk_t;
839
844#define spi_pin_mosi(dev) spi_config[dev].mosi
845#define spi_pin_miso(dev) spi_config[dev].miso
846#define spi_pin_clk(dev) spi_config[dev].sck
848
849#endif /* !DOXYGEN */
850
854typedef spi_host_device_t spi_ctrl_t;
855
856/*
857 * In former ESP-IDF versions, SPI interfaces were identified by the alias
858 * names `FSPI`, `HSPI` and `VSPI`, which are sometimes also used in data
859 * sheets. These alias names have been declared obsolete in ESP-IDF. For
860 * source code compatibility reasons these alias names are defined here.
861 */
862#if defined(CPU_FAM_ESP32)
863# define HSPI SPI2_HOST
864# define VSPI SPI3_HOST
865#elif defined(CPU_FAM_ESP32S2)
866# define FSPI SPI2_HOST
867# define HSPI SPI3_HOST
868#else
869# define FSPI SPI2_HOST
870#endif
871
875typedef struct {
877 gpio_t sck;
878 gpio_t mosi;
879 gpio_t miso;
880 gpio_t cs;
881} spi_conf_t;
882
886#define SPI_NUMOF_MAX (SOC_SPI_PERIPH_NUM - 1)
887
888#define PERIPH_SPI_NEEDS_TRANSFER_BYTE
889#define PERIPH_SPI_NEEDS_TRANSFER_REG
890#define PERIPH_SPI_NEEDS_TRANSFER_REGS
892
917
918#ifndef MODULE_ESP_HW_COUNTER
925# define TIMER_NUMOF (SOC_TIMER_GROUP_TOTAL_TIMERS - 1)
926# define TIMER_CHANNEL_NUMOF (1)
927#endif
928
930#define TIMER_SYSTEM_GROUP 0 /* formerly TIMER_GROUP_0 */
932#define TIMER_SYSTEM_INDEX 0 /* formerly TIMER_0 */
934#define TIMER_SYSTEM_INT_SRC ETS_TG0_T0_LEVEL_INTR_SOURCE
935
937
941#define PERIPH_TIMER_PROVIDES_SET
942
984
988typedef struct {
989 gpio_t txd;
990 gpio_t rxd;
992
993#ifndef DOXYGEN
997typedef enum {
998 UART_STOP_BITS_1 = 0x1,
999 UART_STOP_BITS_1_5 = 0x2,
1000 UART_STOP_BITS_2 = 0x3,
1002
1003#define HAVE_UART_STOP_BITS_T
1004
1008#define UART_MODE_UNSUPPORTED 0xf0
1009
1013typedef enum {
1014 UART_PARITY_NONE = 0x0,
1015 UART_PARITY_EVEN = 0x2,
1016 UART_PARITY_ODD = 0x3,
1017 UART_PARITY_MARK = UART_MODE_UNSUPPORTED | 0,
1018 UART_PARITY_SPACE = UART_MODE_UNSUPPORTED | 1,
1020
1021#define UART_PARITY_DISABLE UART_PARITY_NONE
1022
1023#define HAVE_UART_PARITY_T
1024
1025#endif /* !DOXYGEN */
1026
1030#define UART_NUMOF_MAX (SOC_UART_NUM)
1032
1040#include "usbdev_synopsys_dwc2.h"
1041
1045#define USBDEV_NUMOF_MAX (SOC_USB_PERIPH_NUM)
1047
1048#ifdef __cplusplus
1049}
1050#endif
1051
1055#if defined(CPU_FAM_ESP32)
1056# include "periph_cpu_esp32.h"
1057#elif defined(CPU_FAM_ESP32C3)
1058# include "periph_cpu_esp32c3.h"
1059#elif defined(CPU_FAM_ESP32C6)
1060# include "periph_cpu_esp32c6.h"
1061#elif defined(CPU_FAM_ESP32H2)
1062# include "periph_cpu_esp32h2.h"
1063#elif defined(CPU_FAM_ESP32S2)
1064# include "periph_cpu_esp32s2.h"
1065#elif defined(CPU_FAM_ESP32S3)
1066# include "periph_cpu_esp32s3.h"
1067#else
1068# error "ESP32x family implementation missing"
1069#endif
1070
1071#ifdef MODULE_PERIPH_CAN
1072# include "can_esp.h"
1073#endif
gpio_flank_t
Definition periph_cpu.h:176
@ GPIO_OUT
select GPIO MASK as output
Definition periph_cpu.h:161
@ GPIO_IN
select GPIO MASK as input
Definition periph_cpu.h:160
i2c_speed_t
Definition periph_cpu.h:272
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition periph_cpu.h:274
@ I2C_SPEED_FAST_PLUS
fast plus mode: ~1000 kbit/s
Definition periph_cpu.h:276
@ I2C_SPEED_LOW
low speed mode: ~10 kbit/s
Definition periph_cpu.h:273
@ I2C_SPEED_HIGH
high speed mode: ~3400 kbit/s
Definition periph_cpu.h:278
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition periph_cpu.h:275
spi_clk_t
Definition periph_cpu.h:348
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition periph_cpu.h:353
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition periph_cpu.h:352
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition periph_cpu.h:350
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition periph_cpu.h:351
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition periph_cpu.h:349
SDK configuration used by ESP-IDF for all ESP32x SoC variants (families)
sdmmc_slot_t
SDIO/SDMMC slots.
Definition periph_cpu.h:698
@ SDMMC_SLOT_1
SD/MMC host controller slot 1.
Definition periph_cpu.h:702
@ SDMMC_SLOT_0
SD/MMC host controller slot 0 (not usable on ESP32 variant)
Definition periph_cpu.h:700
spi_ctrl_t
SPI controllers that can be used for peripheral interfaces.
Definition periph_cpu.h:267
gpio_mode_t
gpio_mode_t but with the addition of PIO pins
Definition gpio_conf.h:30
gpio_pull_t
Enumeration of pull resistor configurations.
Definition gpio_ll.h:254
gpio_pull_strength_t
Enumeration of pull resistor values.
Definition gpio_ll.h:272
gpio_state_t
Enumeration of GPIO states (direction)
Definition gpio_ll.h:162
gpio_slew_t
Enumeration of slew rate settings.
Definition gpio_ll.h:336
gpio_drive_strength_t
Enumeration of drive strength options.
Definition gpio_ll.h:303
typedef gpio_conf_t
GPIO pin configuration.
Definition gpio_ll.h:420
uintptr_t gpio_port_t
GPIO port type.
Definition gpio_ll.h:92
@ GPIO_PULL_WEAKEST
Use the weakest (highest Ohm value) resistor.
Definition gpio_ll.h:273
@ GPIO_PULL_WEAK
Use a weak pull resistor.
Definition gpio_ll.h:274
@ GPIO_PULL_STRONG
Use a strong pull resistor.
Definition gpio_ll.h:275
@ GPIO_PULL_STRONGEST
Use the strongest pull resistor.
Definition gpio_ll.h:276
@ GPIO_OUTPUT_OPEN_SOURCE
Use pin as output in open emitter configuration.
Definition gpio_ll.h:199
@ GPIO_USED_BY_PERIPHERAL
The GPIO pin is used by a peripheral.
Definition gpio_ll.h:218
@ GPIO_OUTPUT_OPEN_DRAIN
Use pin as output in open collector configuration.
Definition gpio_ll.h:186
@ GPIO_OUTPUT_PUSH_PULL
Use pin as output in push-pull configuration.
Definition gpio_ll.h:173
@ GPIO_DISCONNECT
Disconnect pin from all peripherals.
Definition gpio_ll.h:246
@ GPIO_INPUT
Use pin as input.
Definition gpio_ll.h:205
@ GPIO_SLEW_SLOWEST
let the output voltage level rise/fall as slow as possible
Definition gpio_ll.h:337
@ GPIO_SLEW_FAST
let the output voltage level rise/fall fast
Definition gpio_ll.h:340
@ GPIO_SLEW_SLOW
let the output voltage level rise/fall slowly
Definition gpio_ll.h:339
@ GPIO_SLEW_FASTEST
let the output voltage level rise/fall as fast as possible
Definition gpio_ll.h:341
@ GPIO_DRIVE_STRONG
Use a strong drive strength.
Definition gpio_ll.h:306
@ GPIO_DRIVE_WEAK
Use a weak drive strength.
Definition gpio_ll.h:305
@ GPIO_DRIVE_STRONGEST
Use the strongest drive strength.
Definition gpio_ll.h:307
@ GPIO_DRIVE_WEAKEST
Use the weakest drive strength.
Definition gpio_ll.h:304
unsigned int gpio_t
GPIO type identifier.
Definition periph_cpu.h:97
Common macros and compiler attributes/pragmas configuration.
ESP32 specific peripheral configuration.
ESP32-C3 specific peripheral configuration.
ESP32-C6 specific peripheral configuration.
ESP32-H2 specific peripheral configuration.
ESP32-S2 specific peripheral configuration.
ESP32-S3 specific peripheral configuration.
uart_parity_t
Definition of possible parity modes.
Definition periph_cpu.h:498
@ UART_PARITY_SPACE
space parity
Definition periph_cpu.h:503
@ UART_PARITY_NONE
no parity
Definition periph_cpu.h:499
@ UART_PARITY_EVEN
even parity
Definition periph_cpu.h:500
@ UART_PARITY_ODD
odd parity
Definition periph_cpu.h:501
@ UART_PARITY_MARK
mark parity
Definition periph_cpu.h:502
uart_stop_bits_t
Definition of possible stop bits lengths.
Definition periph_cpu.h:530
@ UART_STOP_BITS_2
2 stop bits
Definition periph_cpu.h:532
@ UART_STOP_BITS_1
1 stop bit
Definition periph_cpu.h:531
I2C configuration structure.
Definition periph_cpu.h:295
bool scl_pullup
Pullup enabled for SCL pin.
Definition periph_cpu.h:479
i2c_speed_t speed
Configured bus speed, actual speed may be lower but never higher.
Definition periph_cpu.h:300
bool sda_pullup
Pullup enabled for SDA pin.
Definition periph_cpu.h:480
gpio_t sda
GPIO used as SDA pin.
Definition periph_cpu.h:478
gpio_t scl
GPIO used as SCL pin.
Definition periph_cpu.h:477
uint8_t module
I2C module identifier.
Definition periph_cpu.h:475
PWM configuration structure type.
Definition periph_cpu.h:583
ledc_mode_t group
LEDC channel group used (low/high speed)
Definition periph_cpu.h:585
ledc_timer_t timer
LEDC timer used by this device.
Definition periph_cpu.h:586
uint8_t module
LEDC module identifier.
Definition periph_cpu.h:584
uint8_t ch_numof
Number of channels used by this device.
Definition periph_cpu.h:587
const gpio_t * gpios
GPIOs used as channels of this device.
Definition periph_cpu.h:588
RMT channel configuration.
Definition periph_cpu.h:623
uint8_t channel
channel index
Definition periph_cpu.h:624
gpio_t gpio
GPIO used as RMT channel.
Definition periph_cpu.h:625
SDMMC slot configuration.
Definition periph_cpu.h:716
gpio_t wp
Write Protect pin (must be GPIO_UNDEF if not connected)
Definition periph_cpu.h:719
gpio_t dat1
DAT[1] pin (GPIO_UNDEF if not connected)
Definition periph_cpu.h:724
gpio_t dat3
DAT[3] pin (GPIO_UNDEF if not connected)
Definition periph_cpu.h:726
gpio_t clk
CLK pin (must be defined)
Definition periph_cpu.h:721
gpio_t dat0
DAT[0] pin (must be defined)
Definition periph_cpu.h:723
gpio_t dat4
DAT[4] pin (GPIO_UNDEF if not connected)
Definition periph_cpu.h:728
gpio_t cmd
CMD pin (must be defined)
Definition periph_cpu.h:722
gpio_t dat6
DAT[6] pin (GPIO_UNDEF if not connected)
Definition periph_cpu.h:730
gpio_t dat7
DAT[7] pin (GPIO_UNDEF if not connected)
Definition periph_cpu.h:731
gpio_t dat2
DAT[2] pin (GPIO_UNDEF if not connected)
Definition periph_cpu.h:725
gpio_t dat5
DAT[5] pin (GPIO_UNDEF if not connected)
Definition periph_cpu.h:729
sdmmc_slot_t slot
SDMMC slot used [ SDMMC_SLOT_0 | SDMMC_SLOT_1].
Definition periph_cpu.h:717
gpio_t cd
Card Detect pin (must be GPIO_UNDEF if not connected)
Definition periph_cpu.h:718
SPI device configuration.
Definition periph_cpu.h:333
gpio_t mosi
GPIO used as MOSI pin.
Definition periph_cpu.h:878
spi_ctrl_t ctrl
SPI controller used for the interface.
Definition periph_cpu.h:876
gpio_t cs
GPIO used as CS0 pin.
Definition periph_cpu.h:880
gpio_t miso
GPIO used as MISO pin.
Definition periph_cpu.h:879
gpio_t sck
GPIO used as SCK pin.
Definition periph_cpu.h:877
UART device configuration.
Definition periph_cpu.h:214
gpio_t txd
GPIO used as TxD pin.
Definition periph_cpu.h:989
gpio_t rxd
GPIO used as RxD pin.
Definition periph_cpu.h:990
GPIO pin configuration for ESP32/ESP32Cx/ESP32Sx MCUs.
Definition periph_cpu.h:253
bool initial_value
Initial value of the output.
Definition periph_cpu.h:287
gpio_state_t state
State of the pin.
Definition periph_cpu.h:259
gpio_drive_strength_t drive_strength
Drive strength of the GPIO.
Definition periph_cpu.h:273
gpio_pull_t pull
Pull resistor configuration.
Definition periph_cpu.h:263
uint8_t bits
the raw bits
Definition periph_cpu.h:254
Low level USB FS/HS driver definitions for MCUs with Synopsys DWC2 IP core.