From b38a4d5d46e10f3af3cb77de4e20ddf26d77c756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Wed, 21 Jun 2023 17:02:48 +0200 Subject: [PATCH] [core] Add hardware peripheral availability defines --- cores/beken-7231n/base/lt_defs.h | 5 ++ cores/beken-7231t/base/lt_defs.h | 5 ++ cores/beken-7251/base/lt_defs.h | 5 ++ .../arduino/libraries/Serial/Serial.cpp | 4 +- cores/beken-72xx/arduino/src/lt_defs.h | 5 +- cores/beken-72xx/base/lt_defs.h | 15 ++-- cores/beken-72xx/base/lt_family.h | 6 +- .../arduino/libraries/api/Serial/Serial.h | 25 ------- cores/common/arduino/src/Arduino.h | 6 +- .../common/arduino/src/wiring/wiring_custom.h | 1 - cores/common/base/libretiny.h | 1 + cores/common/base/lt_pins.h | 69 +++++++++++++++++++ cores/realtek-amb/arduino/src/main.cpp | 2 +- cores/realtek-amb/base/lt_defs.h | 4 +- .../arduino/libraries/Serial/Serial.cpp | 6 +- cores/realtek-ambz/arduino/src/lt_defs.h | 3 +- cores/realtek-ambz/base/lt_defs.h | 4 +- cores/realtek-ambz/base/lt_family.h | 8 +-- .../arduino/libraries/Serial/Serial.cpp | 6 +- cores/realtek-ambz2/arduino/src/lt_defs.h | 5 +- cores/realtek-ambz2/base/lt_defs.h | 4 +- cores/realtek-ambz2/base/lt_family.h | 8 +-- docs/dev/config.md | 49 +++++++++---- 23 files changed, 166 insertions(+), 80 deletions(-) create mode 100644 cores/beken-7231n/base/lt_defs.h create mode 100644 cores/beken-7231t/base/lt_defs.h create mode 100644 cores/beken-7251/base/lt_defs.h create mode 100644 cores/common/base/lt_pins.h diff --git a/cores/beken-7231n/base/lt_defs.h b/cores/beken-7231n/base/lt_defs.h new file mode 100644 index 0000000..e099505 --- /dev/null +++ b/cores/beken-7231n/base/lt_defs.h @@ -0,0 +1,5 @@ +#pragma once + +#error "Don't include this file directly" + +#define LT_HW_BLE 1 diff --git a/cores/beken-7231t/base/lt_defs.h b/cores/beken-7231t/base/lt_defs.h new file mode 100644 index 0000000..e099505 --- /dev/null +++ b/cores/beken-7231t/base/lt_defs.h @@ -0,0 +1,5 @@ +#pragma once + +#error "Don't include this file directly" + +#define LT_HW_BLE 1 diff --git a/cores/beken-7251/base/lt_defs.h b/cores/beken-7251/base/lt_defs.h new file mode 100644 index 0000000..e099505 --- /dev/null +++ b/cores/beken-7251/base/lt_defs.h @@ -0,0 +1,5 @@ +#pragma once + +#error "Don't include this file directly" + +#define LT_HW_BLE 1 diff --git a/cores/beken-72xx/arduino/libraries/Serial/Serial.cpp b/cores/beken-72xx/arduino/libraries/Serial/Serial.cpp index bde481d..c4a071d 100644 --- a/cores/beken-72xx/arduino/libraries/Serial/Serial.cpp +++ b/cores/beken-72xx/arduino/libraries/Serial/Serial.cpp @@ -2,10 +2,10 @@ #include "SerialPrivate.h" -#if HAS_SERIAL1 +#if LT_HW_UART1 SerialClass Serial1(UART1_PORT); #endif -#if HAS_SERIAL2 +#if LT_HW_UART2 SerialClass Serial2(UART2_PORT); #endif diff --git a/cores/beken-72xx/arduino/src/lt_defs.h b/cores/beken-72xx/arduino/src/lt_defs.h index 6250f1c..3acbe64 100644 --- a/cores/beken-72xx/arduino/src/lt_defs.h +++ b/cores/beken-72xx/arduino/src/lt_defs.h @@ -2,7 +2,6 @@ #error "Don't include this file directly" -#define LT_ARD_HAS_WIFI 1 -#define LT_ARD_HAS_SERIAL 1 - +#define LT_ARD_HAS_WIFI 1 +#define LT_ARD_HAS_SERIAL 1 #define LT_ARD_MD5_HOSTAPD 1 diff --git a/cores/beken-72xx/base/lt_defs.h b/cores/beken-72xx/base/lt_defs.h index e80ef9d..3aac8ce 100644 --- a/cores/beken-72xx/base/lt_defs.h +++ b/cores/beken-72xx/base/lt_defs.h @@ -2,11 +2,16 @@ #error "Don't include this file directly" -#define LT_HAS_PRINTF 1 -#define LT_HAS_LWIP 1 -#define LT_HAS_LWIP2 1 -#define LT_HAS_FREERTOS 1 -#define LT_HAS_MBEDTLS 1 +#define LT_HAS_FLASH 1 +#define LT_HAS_FREERTOS 1 +#define LT_HAS_LWIP 1 +#define LT_HAS_LWIP2 1 +#define LT_HAS_MBEDTLS 1 +#define LT_HAS_OTA 1 +#define LT_HAS_PRINTF 1 +#define LT_HW_DEEP_SLEEP 1 +#define LT_HW_WATCHDOG 1 +#define LT_HW_WIFI 1 #define LT_HEAP_FUNC xPortGetFreeHeapSize #define LT_REALLOC_FUNC pvPortRealloc diff --git a/cores/beken-72xx/base/lt_family.h b/cores/beken-72xx/base/lt_family.h index fce1aa6..cf31399 100644 --- a/cores/beken-72xx/base/lt_family.h +++ b/cores/beken-72xx/base/lt_family.h @@ -2,13 +2,13 @@ #pragma once -#include LT_VARIANT_H +#include // Choose the main UART output port #ifndef LT_UART_DEFAULT_PORT -#if HAS_SERIAL2 +#if LT_HW_UART2 #define LT_UART_DEFAULT_PORT 2 -#elif HAS_SERIAL1 +#elif LT_HW_UART1 #define LT_UART_DEFAULT_PORT 1 #else #error "No serial port is available" diff --git a/cores/common/arduino/libraries/api/Serial/Serial.h b/cores/common/arduino/libraries/api/Serial/Serial.h index 232c48c..1b80b68 100644 --- a/cores/common/arduino/libraries/api/Serial/Serial.h +++ b/cores/common/arduino/libraries/api/Serial/Serial.h @@ -8,31 +8,6 @@ using namespace arduino; -#if HAS_SERIAL0 -#ifndef PIN_SERIAL0_RX -#define PIN_SERIAL0_RX PIN_INVALID -#endif -#ifndef PIN_SERIAL0_TX -#define PIN_SERIAL0_TX PIN_INVALID -#endif -#endif -#if HAS_SERIAL1 -#ifndef PIN_SERIAL1_RX -#define PIN_SERIAL1_RX PIN_INVALID -#endif -#ifndef PIN_SERIAL1_TX -#define PIN_SERIAL1_TX PIN_INVALID -#endif -#endif -#if HAS_SERIAL2 -#ifndef PIN_SERIAL2_RX -#define PIN_SERIAL2_RX PIN_INVALID -#endif -#ifndef PIN_SERIAL2_TX -#define PIN_SERIAL2_TX PIN_INVALID -#endif -#endif - class SerialClass : public HardwareSerial { private: uint32_t port; diff --git a/cores/common/arduino/src/Arduino.h b/cores/common/arduino/src/Arduino.h index cdda136..4688e28 100644 --- a/cores/common/arduino/src/Arduino.h +++ b/cores/common/arduino/src/Arduino.h @@ -44,13 +44,13 @@ using namespace arduino; #include #if HAS_SERIAL_CLASS -#if HAS_SERIAL0 +#if LT_HW_UART0 extern SerialClass Serial0; #endif -#if HAS_SERIAL1 +#if LT_HW_UART1 extern SerialClass Serial1; #endif -#if HAS_SERIAL2 +#if LT_HW_UART2 extern SerialClass Serial2; #endif #endif diff --git a/cores/common/arduino/src/wiring/wiring_custom.h b/cores/common/arduino/src/wiring/wiring_custom.h index befc254..7be9b6b 100644 --- a/cores/common/arduino/src/wiring/wiring_custom.h +++ b/cores/common/arduino/src/wiring/wiring_custom.h @@ -22,7 +22,6 @@ extern "C" { #define PIN_UART (1 << 11) #define PIN_MODE_ALL 0xFFFFFFFF -#define PIN_INVALID 255 typedef struct PinData_s PinData; diff --git a/cores/common/base/libretiny.h b/cores/common/base/libretiny.h index 22a133a..1d394e9 100644 --- a/cores/common/base/libretiny.h +++ b/cores/common/base/libretiny.h @@ -44,6 +44,7 @@ // APIs #include "lt_api.h" // main API function definitions #include "lt_logger.h" // UART logger utility +#include "lt_pins.h" // additional pin macros #include "lt_posix_api.h" // POSIX compat functions // printf silencing methods #include diff --git a/cores/common/base/lt_pins.h b/cores/common/base/lt_pins.h new file mode 100644 index 0000000..7e9f626 --- /dev/null +++ b/cores/common/base/lt_pins.h @@ -0,0 +1,69 @@ +/* Copyright (c) Kuba Szczodrzyński 2023-06-21. */ + +#include LT_VARIANT_H + +#define PIN_INVALID 255 + +#define LT_HW_UART0 HAS_SERIAL0 +#define LT_HW_UART1 HAS_SERIAL1 +#define LT_HW_UART2 HAS_SERIAL2 +#define LT_HW_I2C0 HAS_WIRE0 +#define LT_HW_I2C1 HAS_WIRE1 +#define LT_HW_I2C2 HAS_WIRE2 +#define LT_HW_SPI0 HAS_SPI0 +#define LT_HW_SPI1 HAS_SPI1 +#define LT_HW_SPI2 HAS_SPI2 + +#if LT_HW_UART0 +#ifndef PIN_SERIAL0_RX +#define PIN_SERIAL0_RX PIN_INVALID +#endif +#ifndef PIN_SERIAL0_TX +#define PIN_SERIAL0_TX PIN_INVALID +#endif +#endif + +#if LT_HW_UART1 +#ifndef PIN_SERIAL1_RX +#define PIN_SERIAL1_RX PIN_INVALID +#endif +#ifndef PIN_SERIAL1_TX +#define PIN_SERIAL1_TX PIN_INVALID +#endif +#endif + +#if LT_HW_UART2 +#ifndef PIN_SERIAL2_RX +#define PIN_SERIAL2_RX PIN_INVALID +#endif +#ifndef PIN_SERIAL2_TX +#define PIN_SERIAL2_TX PIN_INVALID +#endif +#endif + +#if LT_HW_I2C0 +#ifndef PIN_WIRE0_SDA +#define PIN_WIRE0_SDA PIN_INVALID +#endif +#ifndef PIN_WIRE0_SCL +#define PIN_WIRE0_SCL PIN_INVALID +#endif +#endif + +#if LT_HW_I2C1 +#ifndef PIN_WIRE1_SDA +#define PIN_WIRE1_SDA PIN_INVALID +#endif +#ifndef PIN_WIRE1_SCL +#define PIN_WIRE1_SCL PIN_INVALID +#endif +#endif + +#if LT_HW_I2C2 +#ifndef PIN_WIRE2_SDA +#define PIN_WIRE2_SDA PIN_INVALID +#endif +#ifndef PIN_WIRE2_SCL +#define PIN_WIRE2_SCL PIN_INVALID +#endif +#endif diff --git a/cores/realtek-amb/arduino/src/main.cpp b/cores/realtek-amb/arduino/src/main.cpp index 7db967f..4fcc21f 100644 --- a/cores/realtek-amb/arduino/src/main.cpp +++ b/cores/realtek-amb/arduino/src/main.cpp @@ -7,7 +7,7 @@ extern "C" { osThreadId main_tid = 0; -#if LT_AUTO_DOWNLOAD_REBOOT && LT_ARD_HAS_SERIAL && defined(PIN_SERIAL2_RX) && defined(PIN_SERIAL2_TX) +#if LT_AUTO_DOWNLOAD_REBOOT && LT_ARD_HAS_SERIAL && LT_HW_UART2 void lt_init_arduino() { // initialize auto-download-reboot parser Serial2.begin(115200); diff --git a/cores/realtek-amb/base/lt_defs.h b/cores/realtek-amb/base/lt_defs.h index e6250ff..1b387c6 100644 --- a/cores/realtek-amb/base/lt_defs.h +++ b/cores/realtek-amb/base/lt_defs.h @@ -2,7 +2,9 @@ #error "Don't include this file directly" -#define LT_HAS_PRINTF 1 +#define LT_HAS_FLASH 1 +#define LT_HW_WATCHDOG 1 +#define LT_HW_WIFI 1 #define LT_HEAP_FUNC xPortGetFreeHeapSize #define LT_REALLOC_FUNC pvPortReAlloc diff --git a/cores/realtek-ambz/arduino/libraries/Serial/Serial.cpp b/cores/realtek-ambz/arduino/libraries/Serial/Serial.cpp index f075d19..6f5d8e3 100644 --- a/cores/realtek-ambz/arduino/libraries/Serial/Serial.cpp +++ b/cores/realtek-ambz/arduino/libraries/Serial/Serial.cpp @@ -2,13 +2,13 @@ #include "SerialPrivate.h" -#if HAS_SERIAL0 +#if LT_HW_UART0 SerialClass Serial0(0, PIN_SERIAL0_RX, PIN_SERIAL0_TX); #endif -#if HAS_SERIAL1 +#if LT_HW_UART1 SerialClass Serial1(1, PIN_SERIAL1_RX, PIN_SERIAL1_TX); #endif -#if HAS_SERIAL2 +#if LT_HW_UART2 SerialClass Serial2(2, PIN_SERIAL2_RX, PIN_SERIAL2_TX); #endif diff --git a/cores/realtek-ambz/arduino/src/lt_defs.h b/cores/realtek-ambz/arduino/src/lt_defs.h index aff5c9b..39692e0 100644 --- a/cores/realtek-ambz/arduino/src/lt_defs.h +++ b/cores/realtek-ambz/arduino/src/lt_defs.h @@ -2,6 +2,5 @@ #error "Don't include this file directly" -#define LT_ARD_HAS_SERIAL 1 - +#define LT_ARD_HAS_SERIAL 1 #define LT_ARD_MD5_POLARSSL 1 diff --git a/cores/realtek-ambz/base/lt_defs.h b/cores/realtek-ambz/base/lt_defs.h index 0125e4b..a8f1344 100644 --- a/cores/realtek-ambz/base/lt_defs.h +++ b/cores/realtek-ambz/base/lt_defs.h @@ -2,7 +2,9 @@ #error "Don't include this file directly" +#define LT_HAS_FREERTOS 1 #define LT_HAS_LWIP 1 #define LT_HAS_LWIP2 1 -#define LT_HAS_FREERTOS 1 #define LT_HAS_MBEDTLS 1 +#define LT_HAS_OTA 1 +#define LT_HAS_PRINTF 1 diff --git a/cores/realtek-ambz/base/lt_family.h b/cores/realtek-ambz/base/lt_family.h index 3a25b48..205b9c8 100644 --- a/cores/realtek-ambz/base/lt_family.h +++ b/cores/realtek-ambz/base/lt_family.h @@ -2,15 +2,15 @@ #pragma once -#include LT_VARIANT_H +#include // Choose the main UART output port #ifndef LT_UART_DEFAULT_PORT -#if HAS_SERIAL2 +#if LT_HW_UART2 #define LT_UART_DEFAULT_PORT 2 -#elif HAS_SERIAL0 +#elif LT_HW_UART0 #define LT_UART_DEFAULT_PORT 0 -#elif HAS_SERIAL1 +#elif LT_HW_UART1 #define LT_UART_DEFAULT_PORT 1 #else #error "No serial port is available" diff --git a/cores/realtek-ambz2/arduino/libraries/Serial/Serial.cpp b/cores/realtek-ambz2/arduino/libraries/Serial/Serial.cpp index 709425a..9fb18d6 100644 --- a/cores/realtek-ambz2/arduino/libraries/Serial/Serial.cpp +++ b/cores/realtek-ambz2/arduino/libraries/Serial/Serial.cpp @@ -2,13 +2,13 @@ #include "SerialPrivate.h" -#if HAS_SERIAL0 +#if LT_HW_UART0 SerialClass Serial0(0, PIN_SERIAL0_RX, PIN_SERIAL0_TX); #endif -#if HAS_SERIAL1 +#if LT_HW_UART1 SerialClass Serial1(1, PIN_SERIAL1_RX, PIN_SERIAL1_TX); #endif -#if HAS_SERIAL2 +#if LT_HW_UART2 SerialClass Serial2(2, PIN_SERIAL2_RX, PIN_SERIAL2_TX); #endif diff --git a/cores/realtek-ambz2/arduino/src/lt_defs.h b/cores/realtek-ambz2/arduino/src/lt_defs.h index 72fc05a..f6cceb0 100644 --- a/cores/realtek-ambz2/arduino/src/lt_defs.h +++ b/cores/realtek-ambz2/arduino/src/lt_defs.h @@ -3,8 +3,7 @@ #error "Don't include this file directly" #define LT_ARD_HAS_SERIAL 1 -#define LT_ARD_HAS_WIFI 1 #define LT_ARD_HAS_SOFTSERIAL 0 +#define LT_ARD_HAS_WIFI 1 #define LT_ARD_HAS_WIRE 0 - -#define LT_ARD_MD5_MBEDTLS 1 +#define LT_ARD_MD5_MBEDTLS 1 diff --git a/cores/realtek-ambz2/base/lt_defs.h b/cores/realtek-ambz2/base/lt_defs.h index 0125e4b..4868572 100644 --- a/cores/realtek-ambz2/base/lt_defs.h +++ b/cores/realtek-ambz2/base/lt_defs.h @@ -2,7 +2,9 @@ #error "Don't include this file directly" +#define LT_HAS_FREERTOS 1 #define LT_HAS_LWIP 1 #define LT_HAS_LWIP2 1 -#define LT_HAS_FREERTOS 1 #define LT_HAS_MBEDTLS 1 +#define LT_HAS_PRINTF 1 +#define LT_HW_BLE 1 diff --git a/cores/realtek-ambz2/base/lt_family.h b/cores/realtek-ambz2/base/lt_family.h index d9c9f41..a574f6c 100644 --- a/cores/realtek-ambz2/base/lt_family.h +++ b/cores/realtek-ambz2/base/lt_family.h @@ -2,15 +2,15 @@ #pragma once -#include LT_VARIANT_H +#include // Choose the main UART output port #ifndef LT_UART_DEFAULT_PORT -#if HAS_SERIAL2 +#if LT_HW_UART2 #define LT_UART_DEFAULT_PORT 2 -#elif HAS_SERIAL0 +#elif LT_HW_UART0 #define LT_UART_DEFAULT_PORT 0 -#elif HAS_SERIAL1 +#elif LT_HW_UART1 #define LT_UART_DEFAULT_PORT 1 #else #error "No serial port is available" diff --git a/docs/dev/config.md b/docs/dev/config.md index 94950fb..1a976f3 100644 --- a/docs/dev/config.md +++ b/docs/dev/config.md @@ -70,7 +70,7 @@ build_flags = #### Per-module logging & debugging -The following options enable library-specific logging output. They are effective **for all loglevels** - i.e. disabling `LT_DEBUG_WIFI` will disable WiFi debug messages, as well as errors. +The following options enable library-specific logging output. They are effective **for all loglevels** - i.e. disabling `LT_DEBUG_WIFI` will disable WiFi debug messages, warnings, as well as errors. To see debug messages from i.e. OTA, loglevel must also be changed. @@ -119,24 +119,43 @@ Options for controlling default UART log output. - `LT_MICROS_HIGH_RES` (1) - count runtime microseconds using a high-resolution timer (if possible); disable if your application doesn't need `micros()` - `LT_AUTO_DOWNLOAD_REBOOT` (1) - automatically reboot into "download mode" after detecting a flashing protocol command; [read more](../flashing/tools/adr.md) -### Family feature config +### Family configuration !!! bug "Warning" These options are not meant for end-users. They're provided here as a reference for developers. **Do not set these options manually**. These options are selectively set by all families, as part of the build process. They are used for enabling LT core API parts, if the family has support for it. Files named `lt_defs.h`, containing these options, are read by the PlatformIO builders (note: they're never included by C code). -The `LT_ARD_*` options are only used with Arduino frameworks. +Checking for option value should be done with `#if` (not with `#ifdef`!) - if it's not defined, it will evaluate to 0. Otherwise, it will use the defined value, either 0 or 1. -The meaning of most flags is as follows: - -- `LT_HAS_FREERTOS` - FreeRTOS supported and used -- `LT_HAS_LWIP` - LwIP in SDK (any version) -- `LT_HAS_LWIP2` - LwIP v2.0.0 or newer -- `LT_HAS_MBEDTLS` - mbedTLS in SDK -- `LT_HAS_PRINTF` - printf library implemented -- `LT_ARD_HAS_SERIAL` - Serial class implemented, `Serial.h` available -- `LT_ARD_HAS_SOFTSERIAL` - SoftwareSerial library implemented, `SoftwareSerial.h` available -- `LT_ARD_HAS_WIFI` - WiFi library implemented, `WiFiData.h` available -- `LT_HEAP_FUNC` - function name used to get available heap size (for `LT_HEAP_I()`) -- `LT_REALLOC_FUNC` - function name used for `realloc()` call +- family-/chip-specific hardware peripherals + - `LT_HW_WIFI` - WiFi supported on the chip + - `LT_HW_BT` - Bluetooth Classic supported on the chip + - `LT_HW_BLE` - Bluetooth Low Energy supported on the chip + - `LT_HW_WATCHDOG` - watchdog available + - `LT_HW_DEEP_SLEEP` - deep sleep possible +- board-specific peripherals (note: defined in `lt_pins.h`, depending on available pin numbers) + - `LT_HW_UART#` - UART number # available on the board + - `LT_HW_I2C#` - I²C number # available on the board + - `LT_HW_SPI#` - SPI number # available on the board +- family software options (SDK features, LT implementation status) + - `LT_HAS_FREERTOS` - FreeRTOS supported and used + - `LT_HAS_LWIP` - LwIP in SDK (any version) + - `LT_HAS_LWIP2` - LwIP v2.0.0 or newer + - `LT_HAS_MBEDTLS` - mbedTLS in SDK + - `LT_HAS_PRINTF` - printf library implemented + - `LT_HAS_FLASH` - FAL flash port implemented + - `LT_HAS_OTA` - OTA implemented in base framework +- Arduino Core implementation status (only available and used along with Arduino framework) + - `LT_ARD_HAS_SERIAL` - Serial class implemented + - `LT_ARD_HAS_SOFTSERIAL` - SoftwareSerial library implemented + - `LT_ARD_HAS_WIFI` - WiFi library implemented + - `LT_ARD_HAS_WIRE` - Wire (I²C) library implemented + - `LT_ARD_HAS_SPI` - SPI library implemented + - `LT_ARD_MD5_POLARSSL` - use PolarSSL for MD5 library + - `LT_ARD_MD5_MBEDTLS` - use mbedTLS for MD5 library + - `LT_ARD_MD5_HOSTAPD` - use hostapd for MD5 library +- misc options + - `LT_HEAP_FUNC` - function name used to get available heap size (for `LT_HEAP_I()`) + - `LT_REALLOC_FUNC` - function name used for `realloc()` call + - `LT_REMALLOC` - use `malloc()` and `memcpy()` in `realloc()` call