Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
19027: sys/fmt: optimize scn_u32_dec scn_u32_hex r=benpicco a=kfessel

### Contribution description

Improves the compilation result for `scn_u32_dec` `scn_u32_hex` especially on `cortex-m` reducing either stack usage and or code size.

This makes use of unsigned int overflow (slightly less better without doing that `hexn`).

See godbolt (original versions got an `o` attached, modified versions got `k`s) all functions are  marked `_S_` defined to `static`

by assigning the global at end the compiled function can be changed (`deco deck  hexo hexk hexkk hexn`)

this PR is `hexkk` and `deck` 

### Testing procedure

run unit-test/test-fmt

```
<RIOT>/tests/unittests$ make tests-fmt
<RIOT>/tests/unittests$ make term
```

### Issues/PRs references

[godbolt](https://godbolt.org/z/MzT1zh4q1)

19269: cpu/gd32v/periph_i2c: interrupt based driver r=benpicco a=gschorcht

### Contribution description

This PR provides an interrupt-driven version of the I2C low-level driver.

The existing I2C low-level driver for GDVF103 uses a busy-waiting approach where the status register is continuously polled while waiting for a certain status when sending or receiving. The MCU is thus occupied the whole time during a send or receive operation.

The driver provided with this PR uses an interrupt-driven approach. This is, while waiting for a certain status when sending or receiving, the calling thread is suspended and woken up by interrupts.

Since the I2C controller allows to receive up to two bytes before the application has to react, receiving a single byte, two bytes or more than two bytes needs a different handling for correct receiption. This requires a tricky implementation which distinguish a number of different case. There the driver requires 860 byte more ROM and 8 byte more RAM.

### Testing procedure

The driver should work with any I2C sensor/actuator. It was tested with
- `tests/driver_bmp180`
   <details>
  
   ```
    main(): This is RIOT! (Version: 2023.04-devel-355-g940c7-cpu/gd32v/periph_i2c_interrupt_driven)
    BMP180 test application
    
    +------------Initializing------------+
    Initialization successful
    
    +------------Calibration------------+
    AC1: 8448
    AC2: -1208
    AC3: -14907
    AC4: 33310
    AC5: 24774
    AC6: 19213
    B1: 6515
    B2: 49
    MB: -32768
    MC: -11786
    MD: 2958
    
    +--------Starting Measurements--------+
    Temperature [°C]: 22.0
    Pressure [hPa]: 1006.49
    Pressure at see level [hPa]: 1025.55
    Altitude [m]: 157
    
    +-------------------------------------+
    Temperature [°C]: 22.0
    Pressure [hPa]: 1006.56
    Pressure at see level [hPa]: 1025.58
    Altitude [m]: 157
    
    +-------------------------------------+
   ```
   
   </details>
- `tests/driver_ccs811`
   <details>
  
   ```
    main(): This is RIOT! (Version: 2023.04-devel-355-g940c7-cpu/gd32v/periph_i2c_interrupt_driven)
    CCS811 test application
    
    +------------Initializing------------+
    
    +--------Starting Measurements--------+
    TVOC [ppb]: 0
    eCO2 [ppm]: 0
    +-------------------------------------+
    TVOC [ppb]: 0
    eCO2 [ppm]: 0
    +-------------------------------------+
    TVOC [ppb]: 0
    eCO2 [ppm]: 0
    +-------------------------------------+
    TVOC [ppb]: 0
    eCO2 [ppm]: 400
    +-------------------------------------+
    TVOC [ppb]: 0
    eCO2 [ppm]: 400
    +-------------------------------------+
    TVOC [ppb]: 0
    eCO2 [ppm]: 400
    +-------------------------------------+
    TVOC [ppb]: 7
    eCO2 [ppm]: 446
    +-------------------------------------+
    TVOC [ppb]: 7
    eCO2 [ppm]: 446
    +-------------------------------------+
    TVOC [ppb]: 7
    eCO2 [ppm]: 446
    +-------------------------------------+
    TVOC [ppb]: 7
    eCO2 [ppm]: 446
    +-------------------------------------+
    ```
   
   </details>
- `tests/driver_sht3x`
   <details>
  
    ```
    main(): This is RIOT! (Version: 2023.04-devel-355-g940c7-cpu/gd32v/periph_i2c_interrupt_driven)
    SHT3X test application
    
    +------------Initializing------------+
    Initialization successful
    
    
    +--------Starting Measurements--------+
    Temperature [°C]: 21.46
    Relative Humidity [%]: 54.50
    +-------------------------------------+
    Temperature [°C]: 21.47
    Relative Humidity [%]: 54.53
    +-------------------------------------+
    Temperature [°C]: 21.46
    Relative Humidity [%]: 54.48
    +-------------------------------------+
    Temperature [°C]: 21.46
    Relative Humidity [%]: 54.47
    +-------------------------------------+
    ```
   
   </details>
- `tests/driver_l3gxxxx`
   <details>
  
    ```
    main(): This is RIOT! (Version: 2023.04-devel-375-g75547-cpu/gd32v/periph_i2c_interrupt_driven)
    L3GXXXX gyroscope driver test application
    
    Initializing L3GXXXX sensor
    [OK]
    
    gyro [dps] x:    +0, y:    -1, z:    -2
    gyro [dps] x:    +0, y:    +0, z:    +0
    gyro [dps] x:    +0, y:    +0, z:    +0
    gyro [dps] x:    +0, y:    +0, z:    +0
    gyro [dps] x:    +0, y:    +0, z:    +0
    gyro [dps] x:    +0, y:    +0, z:    +0
    gyro [dps] x:    -1, y:    +0, z:    +4
    gyro [dps] x:    +0, y:    +0, z:   -21
    gyro [dps] x:    +0, y:    +0, z:    +6
    gyro [dps] x:   -43, y:    +0, z:   -13
    gyro [dps] x:   -21, y:    -2, z:    +0
    gyro [dps] x:    +0, y:    +1, z:    +3
    gyro [dps] x:   +25, y:    +0, z:    +0
    ```
   
   </details>
- `tests/driver_hd44780` with `pcf8574a` I2C interface

### Issues/PRs references



19284: boards: support for the LILYGO TTGO T8 ESP32-S2 board r=benpicco a=gschorcht

### Contribution description

This PR provides the support for the LILYGO TTGO T8 ESP32-S2 board which has a OLED display (not yet supported) and a SD-Card slot on board.

The board is equipped with a USB-C connector that connects either to a USB-to-UART bridge or to the USB-OTG/JTAG interface of the ESP32-S2 via some DIP switches.

The PR includes a very small fix of printf format string in `tests/malloc`. I can split it off.

### Testing procedure

t.b.d.

### Issues/PRs references


19286: cpu/esp_common: use generic WIFI_SSID/WIFI_PASS defines r=benpicco a=benpicco



Co-authored-by: Karl Fessel <karl.fessel@ovgu.de>
Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
Co-authored-by: Benjamin Valentin <benpicco@beuth-hochschule.de>
  • Loading branch information
4 people authored Feb 17, 2023
5 parents 6f6727d + 18a783d + 3fd04b7 + 8e30600 + cebd768 commit 51eecf2
Show file tree
Hide file tree
Showing 31 changed files with 1,466 additions and 306 deletions.
61 changes: 61 additions & 0 deletions boards/esp32s2-lilygo-ttgo-t8/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 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 "esp32s2-lilygo-ttgo-t8" if BOARD_ESP32S2_LILYGO_TTGO_T8

config BOARD_ESP32S2_LILYGO_TTGO_T8
bool
default y
select BOARD_COMMON_ESP32S2
select CPU_MODEL_ESP32S2
select HAS_ARDUINO
select HAS_ESP_RTC_TIMER_32K if ESP32S2_LILYGO_TTGO_T8_32K_XTAL
select HAS_ESP_SPI_RAM
select HAS_HIGHLEVEL_STDIO if ESP32S2_LILYGO_TTGO_T8_USB
select HAS_PERIPH_ADC
select HAS_PERIPH_DAC
select HAS_PERIPH_I2C
select HAS_PERIPH_PWM
select HAS_PERIPH_SPI
select HAS_PERIPH_USBDEV
select HAS_SDCARD_SPI
select HAS_TINYUSB_DEVICE
select HAVE_MTD_SDCARD_DEFAULT
select HAVE_ST7735
select MODULE_FATFS_VFS if MODULE_VFS_DEFAULT
select MODULE_USBUS_CDC_ACM if MODULE_USBUS

menu "LILYGO TTGO T8 ESP32-S2 Board configurations"
depends on BOARD_ESP32S2_LILYGO_TTGO_T8

config ESP32S2_LILYGO_TTGO_T8_USB
bool "USB interface is used instead of USB-to-UART bridge"
help
The USB D-/D+ signals are connected via DIP switches either to the
USB-to-UART bridge (default) or to GPIO19/GPIO20 of the ESP32-S2.
To use the USB interface of the ESP32-S2, the USB D-/D+ signals
must be connected to GPIO19 and GPIO20 and this option has to be
enabled.

config ESP32S2_LILYGO_TTGO_T8_32K_XTAL
bool "32.768 kHz crystal is used"
default y
help
GPIO15 and GPIO16 of the ESP32-S2 are connected via DIP switches
either with the on-board 32.768 kHz crystal (default) or the
according pins at the extension headers. If the pins at the
extension headers are used instead, disable this option.

endmenu

choice STDIO_IMPLEMENTATION
default MODULE_STDIO_CDC_ACM if MODULE_USBUS
default MODULE_STDIO_TINYUSB_CDC_ACM if MODULE_TINYUSB_DEVICE
endchoice

source "$(RIOTBOARD)/common/esp32s2/Kconfig"
5 changes: 5 additions & 0 deletions boards/esp32s2-lilygo-ttgo-t8/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MODULE = board

DIRS = $(RIOTBOARD)/common/esp32s2

include $(RIOTBASE)/Makefile.base
19 changes: 19 additions & 0 deletions boards/esp32s2-lilygo-ttgo-t8/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ifneq (,$(filter esp32s2-lilygo-ttgo-t8-usb,$(USEMODULE)))
include $(RIOTBOARD)/common/makefiles/stdio_cdc_acm.dep.mk
endif

ifneq (,$(filter mtd,$(USEMODULE)))
USEMODULE += mtd_sdcard_default
endif

# default to using fatfs on SD card
ifneq (,$(filter vfs_default,$(USEMODULE)))
USEMODULE += fatfs_vfs
USEMODULE += mtd
endif

ifneq (,$(filter disp_dev,$(USEMODULE)))
USEMODULE += st7735
endif

include $(RIOTBOARD)/common/esp32s2/Makefile.dep
24 changes: 24 additions & 0 deletions boards/esp32s2-lilygo-ttgo-t8/Makefile.features
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# the board uses a ESP32-S2 with external 4MB QSPI Flash and external 8MB QSPI PSRAM
CPU_MODEL = esp32s2
FEATURES_PROVIDED += esp_spi_ram

# common board and CPU features
include $(RIOTBOARD)/common/esp32s2/Makefile.features

# peripherals provided by the board
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_dac
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_pwm
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_usbdev

# other features provided by the board
FEATURES_PROVIDED += arduino
FEATURES_PROVIDED += esp_rtc_timer_32k
FEATURES_PROVIDED += sdcard_spi
FEATURES_PROVIDED += tinyusb_device

ifneq (,$(filter esp32s2-lilygo-ttgo-t8-usb,$(USEMODULE)))
FEATURES_PROVIDED += highlevel_stdio
endif
7 changes: 7 additions & 0 deletions boards/esp32s2-lilygo-ttgo-t8/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PSEUDOMODULES += esp32s2-lilygo-ttgo-t8-usb

ifneq (,$(filter esp32s2-lilygo-ttgo-t8-usb,$(USEMODULE)))
PORT_LINUX ?= /dev/ttyACM0
endif

include $(RIOTBOARD)/common/esp32s2/Makefile.include
27 changes: 27 additions & 0 deletions boards/esp32s2-lilygo-ttgo-t8/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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_esp32s2_lilygo_ttgo_t8
* @{
*
* @file
* @brief Board initialization for the LILYGO TTGO T8 ESP32-S2 board
*
* @author Gunar Schorcht <gunar@schorcht.net>
*/

#include "board.h"
#include "periph/gpio.h"

void board_init(void)
{
if (IS_USED(MODULE_ST7735)) {
gpio_init(BACKLIGHT_PIN, GPIO_OUT);
}
}
179 changes: 179 additions & 0 deletions boards/esp32s2-lilygo-ttgo-t8/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/*
* 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.
*/

/**
* @defgroup boards_esp32s2_lilygo_ttgo_t8 LILYGO TTGO T8 ESP32-S2 Board
* @ingroup boards_esp32s2
* @brief Support for LILYGO TTGO T8 ESP32-S2 Board
* @author Gunar Schorcht <gunar@schorcht.net>

\section esp32s2_lilygo_ttgo_t8 LILYGO TTGO T8 ESP32-S2

## Table of Contents {#esp32s2_lilygo_ttgo_t8_toc}

1. [Overview](#esp32s2_lilygo_ttgo_t8_overview)
2. [Hardware](#esp32s2_lilygo_ttgo_t8_hardware)
1. [MCU](#esp32s2_lilygo_ttgo_t8_mcu)
2. [Board Configuration](#esp32s2_lilygo_ttgo_t8_board_configuration)
3. [Board Pinout](#esp32s2_lilygo_ttgo_t8_pinout)
3. [Flashing the Device](#esp32s2_lilygo_ttgo_t8_flashing)

## Overview {#esp32s2_lilygo_ttgo_t8_overview}

The Espressif LILYGO TTGO T8 ESP32-S2 is a ESP32-S2 board with an OLED Display
(not yet supported) and a TF Card slot.

\image html https://ae01.alicdn.com/kf/H8062f551fe7b4233809294d4a5b1d45d1.jpg "LILYGO TTGO T8 ESP32-S2" width=600px

The board has following main features:

Feature | Support
:--------------------|:-------
ESP32-S2 SoC | yes
4 MB Flash | yes
8 MB QSPI RAM | yes
SD Card slot | yes
32.768KHz Crystal | yes
OLED display ST77789 | no

[Back to table of contents](#esp32s2_lilygo_ttgo_t8_toc)

## Hardware {#esp32s2_lilygo_ttgo_t8_hardware}

This section describes

- the [MCU](#esp32s2_lilygo_ttgo_t8_mcu),
- the default [board configuration](#esp32s2_lilygo_ttgo_t8_board_configuration),
- [optional hardware configurations](#esp32s2_lilygo_ttgo_t8_optional_hardware),
- the [board pinout](#esp32s2_lilygo_ttgo_t8_pinout).

[Back to table of contents](#esp32s2_lilygo_ttgo_t8_toc)

### MCU {#esp32s2_lilygo_ttgo_t8_mcu}

Most features of the board are provided by the ESP32-S2 SoC. For detailed
information about the ESP32-S2 SoC variant (family) and ESP32x SoCs,
see section \ref esp32_mcu_esp32 "ESP32 SoC Series".

[Back to table of contents](#esp32s2_lilygo_ttgo_t8_toc)

### Board Configuration {#esp32s2_lilygo_ttgo_t8_board_configuration}

The LILYGO TTGO T8 ESP32-S2 board uses the `SPI_DEV(0)` (FSPI) for the
OLED Display. The GPIOs of `SPI_DEV(0)` are therefore not broken out.
SPI_DEV(1) is used for the SD Card slot. These GPIOs are broken out and
can also be used by other devices.

The LILYGO TTGO T8 ESP32-S2 has a USB-to-UART bridge on board. The USB D-/D+
signals of the USB-C connector are connected via DIP switches either to this
USB-to-UART bridge (default) or to GPIO19/GPIO20 of the ESP32-S2. To use the
USB-OTG interface of the ESP32-S2, the USB D-/D+ signals must be connected to
GPIO19 and GPIO20, see section \ref esp32s2_lilygo_ttgo_t8_pinout "Pinout".
If the USB-to-UART bridge is used, module `stdio_cdc_acm` or module
`stdio_tinyusb_cdc_acm` can be enabled to use the USB interface also for the
console.

The LILYGO TTGO T8 ESP32-S2 has a 32.768 kHz crystal on the board, which is
connected to GPIO15 and GPIO16 via DIP switches (default). The crystal can
be switched off via the DIP switches so that GPIO15 and GPIO16 become available
at the headers, see section \ref esp32s2_lilygo_ttgo_t8_pinout "Pinout".

The following table shows the default board configuration, which is sorted
according to the defined functionality of GPIOs. This configuration can be
overridden by \ref esp32_application_specific_configurations
"application-specific configurations".

<center>
Function | GPIOs | Remarks | Configuration
:---------------|:-------|:--------|:----------------------------------
BUTTON0 | GPIO0 | | |
ADC_LINE(n) | GPIO1 ... GPIO9 | | \ref esp32_adc_channels "ADC Channels"
DAC_LINE(n) | GPIO17, GPIO18 | | \ref esp32_dac_channels "DAC Channels"
GPIO38 | GPIO38 | OLED RESET (not broken out) | |
I2C_DEV(0) SCL | GPIO7 | | \ref esp32_i2c_interfaces "I2C Interfaces"
I2C_DEV(0) SDA | GPIO8 | | \ref esp32_i2c_interfaces "I2C Interfaces"
PWM_DEV(0) | GPIO39, GPIO40, GPIO41, GPIO42 | - | \ref esp32_pwm_channels "PWM Channels"
PWM_DEV(1) | GPIO15, GPIO16 | if module `esp_rtc_timer_32k` is not used | \ref esp32_pwm_channels "PWM Channels"
SPI_DEV(0) CLK | GPIO36 | OLED CLK (not broken out) | |
SPI_DEV(0) MISO | GPIO37 | OLED MISO (not broken out) | |
SPI_DEV(0) MOSI | GPIO35 | OLED MOSI (not broken out) | |
SPI_DEV(0) CS0 | GPIO34 | OLED CS0 (not broken out) | |
SPI_DEV(1) CLK | GPIO12 | SD Card CLK | \ref esp32_spi_interfaces "SPI Interfaces"
SPI_DEV(1) MISO | GPIO37 | SD Card MISO | \ref esp32_spi_interfaces "SPI Interfaces"
SPI_DEV(1) MOSI | GPIO35 | SD Card MOSI | \ref esp32_spi_interfaces "SPI Interfaces"
SPI_DEV(1) CS0 | GPIO34 | SD Card CS | \ref esp32_spi_interfaces "SPI Interfaces"
UART_DEV(0) TxD | GPIO43 | Console | \ref esp32_uart_interfaces "UART interfaces"
UART_DEV(0) RxD | GPIO44 | Console | \ref esp32_uart_interfaces "UART interfaces"
USB D- | GPIO19 | if USB-to-UART bridge is not used | |
USB D+ | GPIO20 | if USB-to-UART bridge is not used | |
</center>
\n

For detailed information about the peripheral configurations of ESP32-S2
boards, see section \ref esp32_peripherals "Common Peripherals".

[Back to table of contents](#esp32s2_lilygo_ttgo_t8_toc)

### Board Pinout {#esp32s2_lilygo_ttgo_t8_pinout}

The following figure shows the pinout as configured by the board
definition.

@image html https://ae01.alicdn.com/kf/H4a77f8684c144384a165d7a89476c602q.jpg "LILYGO TTGO T8 ESP32-S2 Pinout" width=900px

The corresponding board schematics can be found [here]
(https://github.com/Xinyuan-LilyGO/LilyGo-T-Display-S2/raw/master/schematic/ESP32_S2-Display.pdf)

[Back to table of contents](#esp32s2_lilygo_ttgo_t8_toc)

## Flashing the Device {#esp32s2_lilygo_ttgo_t8_flashing}

Flashing RIOT is quite easy. The board has an USB-C connector which is either
connected to the USB-to-UART bridge (default) with a built-in reset/boot/flash
logic or to the USB signals of the ESP32-S2 SoC. The flash method depends on
the configuration of the DIP switches,
see section \ref esp32s2_lilygo_ttgo_t8_pinout "Pinout".

### USB-C connector is connected to the USB-to-UART bridge (default)

Just connect the board to your host computer and type using the programming
port:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BOARD=esp32s2-liligo-ttgo-t8 make flash ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For detailed information about ESP32-S2 as well as configuring and compiling
RIOT for ESP32-S2 boards, see \ref esp32_riot.

### USB-C connector is connected to the USB signals of the ESP32-S2 SoC

In this configuration the integrated USB-to-JTAG bridge can be used to flash
the board. The USB-to-JTAG bridge is automatically activated in the download
mode of the bootloader, provided that the eFuses `JTAG_SEL_ENABLE` and
`DIS_USB_JTAG` are not burned (see also section
\ref esp32_jtag_interface_esp32s2 "JTAG Interface" strapping pin GPIO3).

For this purpose, connect the board to your host computer and enter the
following command using the programming port:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
USEMODULE=esp32s2-lilygo-ttgo-t8-usb BOARD=esp32s2-liligo-ttgo-t8 make flash ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If RIOT is already on the device, it should automatically reset the device
and enter the bootloader download mode. If

- RIOT is not already on the device or
- automatic reset does not work or
- the device is stuck in some other mode,

the download mode has to be forced before by pressing the Reset (RST) button
while holding the BOOT (BOT) button.

[Back to table of contents](#esp32s2_lilygo_ttgo_t8_toc)
*/
38 changes: 38 additions & 0 deletions boards/esp32s2-lilygo-ttgo-t8/include/arduino_board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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_esp32s2_lilygo_ttgo_t8
* @{
*
* @file
* @brief Board specific configuration for the Arduino API
*
* @author Gunar Schorcht <gunar@schorcht.net>
*/

#ifndef ARDUINO_BOARD_H
#define ARDUINO_BOARD_H

#include "arduino_board_common.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief The on-board LED is not available
*/
#define ARDUINO_LED (0)

#ifdef __cplusplus
}
#endif

#endif /* ARDUINO_BOARD_H */
/** @} */
Loading

0 comments on commit 51eecf2

Please sign in to comment.