From 79fc49cc761a6f3a7dc2d609fb5122fe67db12fb Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Thu, 30 Mar 2023 18:40:53 +0200 Subject: [PATCH] boards/esp32c3-wemos-mini: add support for Wemos ESP32-C3 mini --- boards/esp32c3-wemos-mini/Kconfig | 51 +++++ boards/esp32c3-wemos-mini/Makefile | 5 + boards/esp32c3-wemos-mini/Makefile.dep | 10 + boards/esp32c3-wemos-mini/Makefile.features | 15 ++ boards/esp32c3-wemos-mini/Makefile.include | 6 + boards/esp32c3-wemos-mini/doc.txt | 191 +++++++++++++++++ .../esp32c3-wemos-mini.config | 1 + .../include/arduino_board.h | 42 ++++ .../include/arduino_pinmap.h | 77 +++++++ boards/esp32c3-wemos-mini/include/board.h | 98 +++++++++ .../esp32c3-wemos-mini/include/gpio_params.h | 53 +++++ .../esp32c3-wemos-mini/include/periph_conf.h | 192 ++++++++++++++++++ 12 files changed, 741 insertions(+) create mode 100644 boards/esp32c3-wemos-mini/Kconfig create mode 100644 boards/esp32c3-wemos-mini/Makefile create mode 100644 boards/esp32c3-wemos-mini/Makefile.dep create mode 100644 boards/esp32c3-wemos-mini/Makefile.features create mode 100644 boards/esp32c3-wemos-mini/Makefile.include create mode 100644 boards/esp32c3-wemos-mini/doc.txt create mode 100644 boards/esp32c3-wemos-mini/esp32c3-wemos-mini.config create mode 100644 boards/esp32c3-wemos-mini/include/arduino_board.h create mode 100644 boards/esp32c3-wemos-mini/include/arduino_pinmap.h create mode 100644 boards/esp32c3-wemos-mini/include/board.h create mode 100644 boards/esp32c3-wemos-mini/include/gpio_params.h create mode 100644 boards/esp32c3-wemos-mini/include/periph_conf.h diff --git a/boards/esp32c3-wemos-mini/Kconfig b/boards/esp32c3-wemos-mini/Kconfig new file mode 100644 index 000000000000..aedd829f561f --- /dev/null +++ b/boards/esp32c3-wemos-mini/Kconfig @@ -0,0 +1,51 @@ +# Copyright (c) 2020 HAW Hamburg +# 2022 Gunar Schorcht +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +config BOARD + default "esp32c3-wemos-mini" if BOARD_ESP32C3_WEMOS_MINI + +config BOARD_ESP32C3_WEMOS_MINI + bool + default y + select BOARD_COMMON_ESP32C3 + select CPU_MODEL_ESP32C3_FH4 + # select HAS_ARDUINO + select HAS_ESP_JTAG + select HAS_PERIPH_ADC + select HAS_PERIPH_I2C + select HAS_PERIPH_PWM + select HAS_PERIPH_SPI + select MODULE_ESP32C3_WEMOS_MINI_V1_0_0 if BOARD_VERSION_ESP32C3_WEMOS_MINI_V1_0_0 + select MODULE_ESP32C3_WEMOS_MINI_V2_1_0 if BOARD_VERSION_ESP32C3_WEMOS_MINI_V2_1_0 + + choice + bool "Wemos ESP32-C3 mini board version" + default BOARD_VERSION_ESP32C3_WEMOS_MINI_V2_1_0 + config BOARD_VERSION_ESP32C3_WEMOS_MINI_V1_0_0 + bool "Version 1.0.0" + config BOARD_VERSION_ESP32C3_WEMOS_MINI_V2_1_0 + bool "Version 2.1.0" + help + There are different versions on the market which differ in the pin + layout for ADC channels and the SPI interface. In addition, + version 2.1.0 has an RGB LED connected to GPIO7 instead of an LED. + Select your version for correct peripheral configuration. If your + board has a RGB LED, it is version 2.1.0 or newer, otherwise it is + version 1.0.0 + endchoice + +config MODULE_ESP32C3_WEMOS_MINI_V1_0_0 + bool + help + Indicates that Wemos ESP32-C3 mini board version v1.0.0 is used. + +config MODULE_ESP32C3_WEMOS_MINI_V2_1_0 + bool + help + Indicates that Wemos ESP32-C3 mini board version v2.1.0 is used. + +source "$(RIOTBOARD)/common/esp32c3/Kconfig" diff --git a/boards/esp32c3-wemos-mini/Makefile b/boards/esp32c3-wemos-mini/Makefile new file mode 100644 index 000000000000..13fe94b28b78 --- /dev/null +++ b/boards/esp32c3-wemos-mini/Makefile @@ -0,0 +1,5 @@ +MODULE = board + +DIRS = $(RIOTBOARD)/common/esp32c3 + +include $(RIOTBASE)/Makefile.base diff --git a/boards/esp32c3-wemos-mini/Makefile.dep b/boards/esp32c3-wemos-mini/Makefile.dep new file mode 100644 index 000000000000..063d72f638d5 --- /dev/null +++ b/boards/esp32c3-wemos-mini/Makefile.dep @@ -0,0 +1,10 @@ +ifeq (,$(filter stdio_% slipdev_stdio,$(USEMODULE))) + USEMODULE += stdio_usb_serial_jtag +endif + +ifeq (,$(filter esp32c3_wemos_mini_v%,$(USEMODULE))) + # use Wemos ESP32-C3 min version V2.1.0 by default + USEMODULE += esp32c3_wemos_mini_v2_1_0 +endif + +include $(RIOTBOARD)/common/esp32c3/Makefile.dep diff --git a/boards/esp32c3-wemos-mini/Makefile.features b/boards/esp32c3-wemos-mini/Makefile.features new file mode 100644 index 000000000000..69bfcf330bf3 --- /dev/null +++ b/boards/esp32c3-wemos-mini/Makefile.features @@ -0,0 +1,15 @@ +CPU_MODEL = esp32c3_fh4 + +# common board and CPU features +include $(RIOTBOARD)/common/esp32c3/Makefile.features + +# additional features provided by the board +FEATURES_PROVIDED += periph_adc +FEATURES_PROVIDED += periph_i2c +FEATURES_PROVIDED += periph_pwm +FEATURES_PROVIDED += periph_spi + +# unique features provided by the board +FEATURES_PROVIDED += esp_jtag + +#FEATURES_PROVIDED += arduino diff --git a/boards/esp32c3-wemos-mini/Makefile.include b/boards/esp32c3-wemos-mini/Makefile.include new file mode 100644 index 000000000000..96ebc9535c21 --- /dev/null +++ b/boards/esp32c3-wemos-mini/Makefile.include @@ -0,0 +1,6 @@ +PORT_LINUX ?= /dev/ttyACM0 + +PSEUDOMODULES += esp32c3_wemos_mini_v1_0_0 +PSEUDOMODULES += esp32c3_wemos_mini_v2_1_0 + +include $(RIOTBOARD)/common/esp32c3/Makefile.include diff --git a/boards/esp32c3-wemos-mini/doc.txt b/boards/esp32c3-wemos-mini/doc.txt new file mode 100644 index 000000000000..9ff07075da9b --- /dev/null +++ b/boards/esp32c3-wemos-mini/doc.txt @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2023 Gunar Schorcht + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup boards_esp32c3_wemos_mini Wemos ESP32-C3 mini + * @ingroup boards_esp32c3 + * @brief Support for generic ESP32-C3 boards + * @author Gunar Schorcht + +\section esp32c3_wemos_mini Wemos ESP32-C3 mini + +## Table of Contents {#esp32c3_wemos_mini_toc} + +1. [Overview](#esp32c3_wemos_mini_overview) +2. [Hardware](#esp32c3_wemos_mini_hardware) + 1. [MCU](#esp32c3_wemos_mini_mcu) + 2. [Board Configuration](#esp32c3_wemos_mini_board_configuration) + 3. [Board Pinout](#esp32c3_wemos_mini_pinout) +3. [Flashing the Device](#esp32c3_wemos_mini_flashing) + +## Overview {#esp32c3_wemos_mini_overview} + +The Wemos ESP32-C3 mini board is an interesting development kit as it uses +in the stackable Wemos LOLIN D1 Mini format. Thus, all [shields for Wemos D1 mini] +(https://docs.wemos.cc/en/latest/d1_mini_shield/index.html) for ESP8266 +can also be used with ESP32-C3. Examples for such shields are: + +- Micro SD-Card Shield +- MRF24J40 IEEE 802.15.4 radio Shield +- Button Shield +- RGB LED Shield +- OLED Display Shield +- ... + +This makes it possible to create different hardware configurations without +the need for a soldering iron or a breadboard. + +@image html "https://www.wemos.cc/en/latest/_images/c3_mini_v2.1.0_1_16x16.jpg" "Wemos ESP32-C3 mini board" width=250px + +This stackable platform was tested in an RIOT application with: + +- MRF24J40 IEEE 802.15.4 radio Shield (contact gunar@schorcht.net for more information) +- [BMP180 Pressure Sensor Shield] + +This application is a good example how easy it is with this board to create +different hardware applications. + +@image html "https://gitlab.com/gschorcht/RIOT.wiki-Images/raw/master/esp32/Wemos_ESP32-C3_mini_application.jpg" "RIOT application with MRF24J40 Radio and a BMP180 Pressure Sensor" width=450px + +[Back to table of contents](#esp32c3_wemos_mini_toc) + +## Hardware {#esp32c3_wemos_mini_hardware} + +This section describes + +- the [MCU](#esp32c3_wemos_mini_mcu), +- the default [board configuration](#esp32c3_wemos_mini_board_configuration), +- the [board pinout](#esp32c3_wemos_mini_pinout). + +[Back to table of contents](#esp32c3_wemos_mini_toc) + +### MCU {#esp32c3_wemos_mini_mcu} + +Most features of the board are provided by the ESP32-C3 SoC. For detailed +information about the ESP32-C3 variant (family) and ESP32x SoCs, +see section \ref esp32_mcu_esp32 "ESP32 SoC Series". + +[Back to table of contents](#esp32c3_wemos_mini_toc) + +### Board Configuration {#esp32c3_wemos_mini_board_configuration} + +The Wemos ESP32-C3 mini board has no special hardware on board with the +exception of a single pin RGB-LED. + +There are two board versions available on the market with a different pinout +of the ADC channels and the SPI interface. Which version is used is +determined by activating a pseudo module for the corresponding version: + +- v1.0.0, module `esp32c3_wemos_mini_v1_0_0` +- v2.1.0, module `esp32c3_wemos_mini_v2_1_0` (default) + +To specify which board version is used, simply add the variable +definition `USEMODULE=...` to the make command line, for example: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +USEMODULE=esp32c3_wemos_mini_v1_0_0 BOARD=esp32c3-wemos-min make ... +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +If the board version is not specified, version v2.1.0 is used by default. + +Almost all GPIOs are broken out and can be used for different peripherals: + +- 6 x ADC channels at maximum +- 1 x SPI +- 1 x I2C +- 1 x UART +- 2 x PWM channels + +However, since the number of GPIOs of the ESP32-C3 SoC is very limited, some +GPIOs are used in multiple peripheral configurations but can only be used for +one peripheral at a time. For example, GPIO4 is used in the ADC channel +configuration and in the MOSI signal configuration for SPI_DEV(0). This is +possible because GPIOs are only used for a specific peripheral interface when +either + +- the corresponding peripheral module is used, e.g. `periph_spi` or +- the corresponding init function is called, e.g. `adc_init` + +That is, the purpose for which a GPIO is used depends on which module +or function is used first. For example, if module `periph_spi` is not used, +the GPIOs listed in SPI configuration can be used for other purposes, that is, +GPIO4 can be used as ADC channel. + +The following table shows the default board configuration depending on used +board version, which is sorted according to the defined functionality of GPIOs. +This configuration can be overridden by \ref esp32_application_specific_configurations +"application-specific configurations". + +
+Function | v1.0.0 | v2.1.0 | Remarks | Configuration +:---------------|:-------|:-------|:--------|:--------------------- +BUTTON0 | GPIO9 | GPIO9 | | | +ADC | GPIO0 ... GPIO5 | GPIO0 ... GPIO5 | | see \ref esp32_adc_channels "ADC Channels" +I2C_DEV(0):SCL | GPIO10 | GPIO10 | | \ref esp32_i2c_interfaces "I2C Interfaces" +I2C_DEV(0):SDA | GPIO8 | GPIO8 | | \ref esp32_i2c_interfaces "I2C Interfaces" +LED0 | GPIO7 | - | | | +PWM_DEV(0) | GPIO1, GPIO6, GPIO7 | GPIO2, GPIO6 | | \ref esp32_pwm_channels "PWM Channels" +RGB-LED | - | GPIO7 | supported by driver module `ws281x` | | +SPI_DEV(0):CLK | GPIO2 | GPIO1 | SPI2_HOST (FSPI) is used | \ref esp32_spi_interfaces "SPI Interfaces" +SPI_DEV(0):MISO | GPIO3 | GPIO0 | SPI2_HOST (FSPI) is used | \ref esp32_spi_interfaces "SPI Interfaces" +SPI_DEV(0):MOSI | GPIO4 | GPIO4 | SPI2_HOST (FSPI) is used | \ref esp32_spi_interfaces "SPI Interfaces" +SPI_DEV(0):CS0 | GPIO5 | GPIO5 | SPI2_HOST (FSPI) is used | \ref esp32_spi_interfaces "SPI Interfaces" +UART_DEV(0):TxD | GPIO21 | GPIO21 | Console (configuration is fixed) | \ref esp32_uart_interfaces "UART interfaces" +UART_DEV(0):RxD | GPIO20 | GPIO20 | Console (configuration is fixed) | \ref esp32_uart_interfaces "UART interfaces" +
+\n +@note The configuration of ADC channels contains all ESP32-C3 GPIOs that could + be used as ADC channels. + +For detailed information about the peripheral configurations of ESP32-C3 +boards, see section \ref esp32_peripherals "Common Peripherals". + +[Back to table of contents](#esp32c3_wemos_mini_toc) + +### Board Pinout {#esp32c3_wemos_mini_pinout} + +The following figures show the pinouts as configured by default board +definition. + +@image html https://gitlab.com/gschorcht/RIOT.wiki-Images/-/raw/master/esp32/Wesos_ESP32-C3_mini_pinout.png "Wemos EPS32-C3 mini Pinout" + +The corresponding board schematics can be found: + +- [Wemos ESP32-C3 mini v1.0.0](https://www.wemos.cc/en/latest/_static/files/sch_c3_mini_v1.0.0.pdf) +- [Wemos ESP32-C3 mini v2.1.0](https://www.wemos.cc/en/latest/_static/files/sch_c3_mini_v2.1.0.pdf) + +[Back to table of contents](#esp32c3_wemos_mini_toc) + +## Flashing the Device {#esp32c3_wemos_mini_flashing} + +The USB-C connector of the board is directly connected to the USB Serial/JTAG +interface of the ESP32-C3 SoC. It can be used to program the board and to debug +the application. Just connect the board to your host computer and use the +following command: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +make flash BOARD=esp32c3-devkit ... +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The make system will resets the board to restart the board into download mode. +In some special cases this reset does not work so that the programmer cannot +connect to the board and the flashing is aborted with a timeout: +``` +Serial port /dev/ttyACM0 +Connecting... +... +serial.serialutil.SerialTimeoutException: Write timeout +``` +In this case, restart the board manually in download mode by pressing and +releasing the RESET button while holding down the BOOT button. + +After flashing the board, it will still be in download mode. You have to press +the reset button (RST) to start your application. + +For detailed information about ESP32-C3 as well as configuring and compiling +RIOT for ESP32-C3 boards, see \ref esp32_riot. + +[Back to table of contents](#esp32c3_wemos_mini_toc) + */ diff --git a/boards/esp32c3-wemos-mini/esp32c3-wemos-mini.config b/boards/esp32c3-wemos-mini/esp32c3-wemos-mini.config new file mode 100644 index 000000000000..0ebba57f03ef --- /dev/null +++ b/boards/esp32c3-wemos-mini/esp32c3-wemos-mini.config @@ -0,0 +1 @@ +CONFIG_MODULE_STDIO_USB_SERIAL_JTAG=y diff --git a/boards/esp32c3-wemos-mini/include/arduino_board.h b/boards/esp32c3-wemos-mini/include/arduino_board.h new file mode 100644 index 000000000000..5e5e5f6fe03f --- /dev/null +++ b/boards/esp32c3-wemos-mini/include/arduino_board.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2022 Gunar Schorcht + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_esp32c3_wemos_mini + * @{ + * + * @file + * @brief Board specific configuration for the Arduino API + * + * @author Gunar Schorcht + */ + +#ifndef ARDUINO_BOARD_H +#define ARDUINO_BOARD_H + +#include "arduino_board_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The on-board LED (not available on board version 2.1.0) + */ +#ifdef MODULE_ESP32C3_WEMOS_MINI_V1_0_0 +#define ARDUINO_LED (5) +#else /* MODULE_ESP32C3_WEMOS_MINI_V2_1_0 */ +#define ARDUINO_LED (0) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* ARDUINO_BOARD_H */ +/** @} */ diff --git a/boards/esp32c3-wemos-mini/include/arduino_pinmap.h b/boards/esp32c3-wemos-mini/include/arduino_pinmap.h new file mode 100644 index 000000000000..ff3fc69967f6 --- /dev/null +++ b/boards/esp32c3-wemos-mini/include/arduino_pinmap.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2022 Gunar Schorcht + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_esp32c3_wemos_mini + * @{ + * + * @file + * @brief Mapping from MCU pins to Arduino pins + * + * @author Gunar Schorcht + */ + +#ifndef ARDUINO_PINMAP_H +#define ARDUINO_PINMAP_H + +#include "periph/gpio.h" +#include "periph/adc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name Mapping of MCU pins to Arduino pins + * @{ + */ +#define ARDUINO_PIN_0 GPIO20 /**< Arduino Uno pin 0 (RxD) */ +#define ARDUINO_PIN_1 GPIO21 /**< Arduino Uno pin 1 (TxD) */ +#define ARDUINO_PIN_2 GPIO9 /**< Arduino Uno pin 2 */ +#define ARDUINO_PIN_3 GPIO6 /**< Arduino Uno pin 3 (PWM) */ +#define ARDUINO_PIN_4 GPIO_UNDEF /**< Arduino Uno pin 4 */ + +#ifdef MODULE_ESP32C3_WEMOS_MINI_V1_0_0 +#define ARDUINO_PIN_5 GPIO7 /**< Arduino Uno pin 5 (PWM) */ +#define ARDUINO_PIN_6 GPIO1 /**< Arduino Uno pin 6 (PWM) */ +#define ARDUINO_PIN_7 GPIO0 /**< Arduino Uno pin 7 */ +#else /* MODULE_ESP32C3_WEMOS_MINI_V2_1_0 */ +#define ARDUINO_PIN_5 GPIO_UNDEF /**< Arduino Uno pin 5 (PWM) */ +#define ARDUINO_PIN_6 GPIO2 /**< Arduino Uno pin 6 (PWM) */ +#define ARDUINO_PIN_7 GPIO3 /**< Arduino Uno pin 7 */ +#endif + +#define ARDUINO_PIN_8 GPIO_UNDEF /**< Arduino Uno pin 8 */ +#define ARDUINO_PIN_9 GPIO_UNDEF /**< Arduino Uno pin 9 (PWM) */ + +#ifdef MODULE_ESP32C3_WEMOS_MINI_V1_0_0 +#define ARDUINO_PIN_10 GPIO5 /**< Arduino Uno pin 10 (CS0 / PWM) */ +#define ARDUINO_PIN_11 GPIO4 /**< Arduino Uno pin 11 (MOSI / PWM) */ +#define ARDUINO_PIN_12 GPIO3 /**< Arduino Uno pin 12 (MISO) */ +#define ARDUINO_PIN_13 GPIO2 /**< Arduino Uno pin 13 (SCK) */ +#else /* MODULE_ESP32C3_WEMOS_MINI_V2_1_0 */ +#define ARDUINO_PIN_10 GPIO5 /**< Arduino Uno pin 10 (CS0 / PWM) */ +#define ARDUINO_PIN_11 GPIO4 /**< Arduino Uno pin 11 (MOSI / PWM) */ +#define ARDUINO_PIN_12 GPIO0 /**< Arduino Uno pin 12 (MISO) */ +#define ARDUINO_PIN_13 GPIO1 /**< Arduino Uno pin 13 (SCK) */ +#endif + +#define ARDUINO_PIN_A0 GPIO0 /**< Arduino Uno pin A0 */ +#define ARDUINO_PIN_A1 GPIO1 /**< Arduino Uno pin A1 */ +#define ARDUINO_PIN_A2 GPIO2 /**< Arduino Uno pin A2 */ +#define ARDUINO_PIN_A3 GPIO3 /**< Arduino Uno pin A3 */ +#define ARDUINO_PIN_A4 GPIO4 /**< Arduino Uno pin A4 (SDA) */ +#define ARDUINO_PIN_A5 GPIO5 /**< Arduino Uno pin A5 (SCL) */ +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* ARDUINO_PINMAP_H */ +/** @} */ diff --git a/boards/esp32c3-wemos-mini/include/board.h b/boards/esp32c3-wemos-mini/include/board.h new file mode 100644 index 000000000000..ae0794ac8b09 --- /dev/null +++ b/boards/esp32c3-wemos-mini/include/board.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2023 Gunar Schorcht + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_esp32c3_wemos_mini + * @brief Board definitions for the Wemos ESP32-C3 mini board + * @{ + * + * @file + * @author Gunar Schorcht + */ + +#ifndef BOARD_H +#define BOARD_H + +#include + +/** + * @name Button pin definitions + * @{ + */ + +/** + * @brief Default button GPIO pin definition + * + * The Wemos ESP32-C3 mini board has a BOOT button connected to GPIO9, which can + * be used as button during normal operation. Since the GPIO9 pin is pulled up, + * the button signal is inverted, i.e., pressing the button will give a + * low signal. + */ +#define BTN0_PIN GPIO9 + +/** + * @brief Default button GPIO mode definition + * + * Since the GPIO of the button is pulled up with an external resistor, the + * mode for the GPIO pin has to be GPIO_IN. + */ +#define BTN0_MODE GPIO_IN_PU + +/** + * @brief Default interrupt flank definition for the button GPIO + */ +#ifndef BTN0_INT_FLANK +#define BTN0_INT_FLANK GPIO_FALLING +#endif + +/** + * @brief Definition for compatibility with previous versions + */ +#define BUTTON0_PIN BTN0_PIN + +/** @} */ + +/** + * @name LED (on-board) configuration + * + * LED configuration depends on Wemos ESP32-C3 mini board version: + * + * - v1.0.0 has one LED connected to GPIO7. + * - v2.1.0 has one 24-bit RGB-LED WS2812B connected to GPIO7. + * @{ + */ +#ifdef MODULE_ESP32C3_WEMOS_MINI_V1_0_0 + +#define LED0_PIN GPIO7 /**< GPIO7 is used as LED Pin */ +#define LED0_ACTIVE (1) /**< LED is HIGH active */ + +#else /* MODULE_ESP32C3_WEMOS_MINI_V2_1_0 */ + +#ifndef WS281X_PARAM_PIN +#define WS281X_PARAM_PIN (GPIO7) /**< GPIO pin connected to the data pin */ +#endif +#ifndef WS281X_PARAM_NUMOF +#define WS281X_PARAM_NUMOF (1U) /**< Number of LEDs chained */ +#endif + +#endif +/** @} */ + +/* include common board definitions as last step */ +#include "board_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} /* end extern "C" */ +#endif + +#endif /* BOARD_H */ +/** @} */ diff --git a/boards/esp32c3-wemos-mini/include/gpio_params.h b/boards/esp32c3-wemos-mini/include/gpio_params.h new file mode 100644 index 000000000000..da8bdf0c49d3 --- /dev/null +++ b/boards/esp32c3-wemos-mini/include/gpio_params.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2023 Gunar Schorcht + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +#ifndef GPIO_PARAMS_H +#define GPIO_PARAMS_H + +/** + * @ingroup boards_esp32c3_wemos_mini + * @brief Board specific configuration of direct mapped GPIOs + * @file + * @author Gunar Schorcht + * @{ + */ + +#include "board.h" +#include "saul/periph.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief LED and Button configuration + */ +static const saul_gpio_params_t saul_gpio_params[] = +{ + { + .name = "BOOT", + .pin = BTN0_PIN, + .mode = BTN0_MODE, + .flags = SAUL_GPIO_INVERTED + }, +#ifdef LED0_PIN + { + .name = "LED0", + .pin = LED0_PIN, + .mode = GPIO_OUT, + .flags = SAUL_GPIO_INIT_CLEAR + }, +#endif +}; + +#ifdef __cplusplus +} +#endif + +#endif /* GPIO_PARAMS_H */ +/** @} */ diff --git a/boards/esp32c3-wemos-mini/include/periph_conf.h b/boards/esp32c3-wemos-mini/include/periph_conf.h new file mode 100644 index 000000000000..931583dddfb3 --- /dev/null +++ b/boards/esp32c3-wemos-mini/include/periph_conf.h @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2023 Gunar Schorcht + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_esp32c3_wemos_mini + * @brief Peripheral configurations for the Wemos ESP32-C3 mini board + * @{ + * + * For detailed information about the peripheral configuration for ESP32-C3 + * boards, see section \ref esp32_peripherals "Common Peripherals". + * + * There are two board versions available on the market with a different pinout + * of the ADC channels and the SPI interface. Which version is used is + * determined by activating a pseudo module for the corresponding version: + * + * - v1.0.0, module `esp32c3_wemos_mini_v1_0_0` + * - v2.1.0, module `esp32c3_wemos_mini_v2_1_0` (default) + * + * To specify which board version is used, simply add the variable + * definition `USEMODULE=...` to the make command line, for example: + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * USEMODULE=esp32c3_wemos_mini_v1_0_0 BOARD=esp32c3-wemos-min make ... + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * If the board version is not specified, version v2.1.0 is used by default. + * + * @note + * Most definitions can be overridden by an \ref esp32_application_specific_configurations + * "application-specific board configuration" if necessary. + * + * @file + * @author Gunar Schorcht + */ + +#ifndef PERIPH_CONF_H +#define PERIPH_CONF_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name ADC and DAC channel configuration + * @{ + */ +/** + * @brief Declaration of GPIOs that can be used as ADC channels + * + * For generic boards, all ADC pins that have broken out are declared as ADC + * channels. + * + * @note As long as the GPIOs listed in ADC_GPIOS are not initialized as ADC + * channels with the `adc_init` function, they can be used for other + * purposes. + */ +#ifndef ADC_GPIOS +#define ADC_GPIOS { GPIO0, GPIO1, GPIO2, GPIO3, GPIO4, GPIO5 } +#endif +/** @} */ + +/** + * @name I2C configuration + * + * For generic boards, only one I2C interface I2C_DEV(0) is defined. + * + * The GPIOs listed in the configuration are only initialized as I2C signals + * when module `periph_i2c` is used. Otherwise they are not allocated and + * can be used for other purposes. + * + * @{ + */ +#ifndef I2C0_SPEED +#define I2C0_SPEED I2C_SPEED_FAST /**< I2C bus speed of I2C_DEV(0) */ +#endif +#ifndef I2C0_SCL +#define I2C0_SCL GPIO10 /**< SCL signal of I2C_DEV(0) */ +#endif +#ifndef I2C0_SDA +#define I2C0_SDA GPIO8 /**< SDA signal of I2C_DEV(0) */ +#endif +/** @} */ + +/** + * @name PWM channel configuration + * + * For generic boards, two PWM devices are configured. These devices + * contain all GPIOs that are not defined as I2C, SPI or UART for this board. + * Generally, all outputs pins could be used as PWM channels. + * + * @note As long as the according PWM device is not initialized with + * the `pwm_init`, the GPIOs declared for this device can be used + * for other purposes. + * + * @{ + */ + +/** + * @brief Declaration of the channels for device PWM_DEV(0), + * at maximum PWM_CHANNEL_NUM_DEV_MAX. + */ +#ifndef PWM0_GPIOS +#ifdef MODULE_ESP32C3_WEMOS_MINI_V1_0_0 +#define PWM0_GPIOS { GPIO1, GPIO6, GPIO7 } +#else /* MODULE_ESP32C3_WEMOS_MINI_V2_1_0 */ +#define PWM0_GPIOS { GPIO2, GPIO6 } +#endif +#endif + +/** @} */ + +/** + * @name SPI configuration + * + * @note + * - For compatibility with [Wemos D1 mini shields] + * (https://www.wemos.cc/en/latest/d1_mini_shield/index.html), FSPI signals + * do not use direct I/O (IOMUX pin functions) but are routed through the + * GPIO matrix as required for D1 mini shields. This limits the SPI clock + * speed to 26 MHz instead of 80 MHz SPI clock speed. + * - The GPIOs listed in the configuration are not initialized as SPI + * signals until the corresponding SPI interface is used for the first time + * by either calling the `spi_init_cs` function or the `spi_acquire` + * function. That is, they are not allocated as SPI signals before and can + * be used for other purposes as long as the SPI interface is not used. + * + * @{ + */ +#ifdef MODULE_ESP32C3_WEMOS_MINI_V1_0_0 +#ifndef SPI0_CTRL +#define SPI0_CTRL FSPI /**< FSPI is used as SPI_DEV(0) */ +#endif +#ifndef SPI0_SCK +#define SPI0_SCK GPIO2 /**< FSPI SCK signal routed to GPIO2 in GPIO matrix */ +#endif +#ifndef SPI0_MISO +#define SPI0_MISO GPIO3 /**< FSPI SCK signal routed to GPIO3 in GPIO matrix */ +#endif +#ifndef SPI0_MOSI +#define SPI0_MOSI GPIO4 /**< FSPI SCK signal routed to GPIO4 in GPIO matrix */ +#endif +#ifndef SPI0_CS0 +#define SPI0_CS0 GPIO5 /**< CS pin controlled in software */ +#endif +#else /* MODULE_ESP32C3_WEMOS_MINI_V2_1_0 */ +#ifndef SPI0_CTRL +#define SPI0_CTRL FSPI /**< FSPI is used as SPI_DEV(0) */ +#endif +#ifndef SPI0_SCK +#define SPI0_SCK GPIO1 /**< FSPI SCK signal routed to GPIO2 in GPIO matrix */ +#endif +#ifndef SPI0_MISO +#define SPI0_MISO GPIO0 /**< FSPI SCK signal routed to GPIO3 in GPIO matrix */ +#endif +#ifndef SPI0_MOSI +#define SPI0_MOSI GPIO4 /**< FSPI SCK signal routed to GPIO4 in GPIO matrix */ +#endif +#ifndef SPI0_CS0 +#define SPI0_CS0 GPIO5 /**< CS pin controlled in software */ +#endif +#endif +/** @} */ + +/** + * @name UART configuration + * + * ESP32-C3 provides 2 UART interfaces at maximum: + * + * UART_DEV(0) uses fixed standard configuration.
+ * UART_DEV(1) is not used.
+ * + * @{ + */ +#define UART0_TXD GPIO21 /**< direct I/O pin for UART_DEV(0) TxD, can't be changed */ +#define UART0_RXD GPIO20 /**< direct I/O pin for UART_DEV(0) RxD, can't be changed */ + +/** @} */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif + +/* include common peripheral definitions as last step */ +#include "periph_conf_common.h" + +#endif /* PERIPH_CONF_H */ +/** @} */