Rework modules handling to support ESP32-S2/S3 too.

This commit is contained in:
Johny Mattsson 2021-08-22 21:25:24 +10:00
parent e52e0a8e84
commit 3af14a367b
19 changed files with 151 additions and 155 deletions

View File

@ -9,7 +9,7 @@ jobs:
matrix:
lua_ver: ['5.1', '5.3']
numbers: ['default', 'alternate']
target: ['esp32', 'esp32c3']
target: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3']
runs-on: ubuntu-latest

View File

@ -1,4 +1,4 @@
if(NOT "${IDF_TARGET}" STREQUAL "esp32c3")
if(IDF_TARGET STREQUAL "esp32")
idf_component_register(
SRCS "CAN.c"

View File

@ -44,18 +44,22 @@
#include "rom/libc_stubs.h"
#include "rom/uart.h"
#if defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(syscall_table_ptr)
// The ESP32S2 libc_stubs.h is missing this compatibility def it seems
# define syscall_table_ptr syscall_table_ptr_pro
#endif
#define UART_INPUT_QUEUE_SZ 0x100
// These used to be available in soc/uart_register.h:
#define UART_GET_RXFIFO_RD_BYTE(i) GET_PERI_REG_BITS2(UART_FIFO_REG(i) , UART_RXFIFO_RD_BYTE_V, UART_RXFIFO_RD_BYTE_S)
#define UART_GET_RXFIFO_CNT(i) GET_PERI_REG_BITS2(UART_STATUS_REG(i) , UART_RXFIFO_CNT_V, UART_RXFIFO_CNT_S)
#define UART_SET_AUTOBAUD_EN(i,val) SET_PERI_REG_BITS(UART_AUTOBAUD_REG(i) ,UART_AUTOBAUD_EN_V,(val),UART_AUTOBAUD_EN_S)
typedef int (*_read_r_fn) (struct _reent *r, int fd, void *buf, int size);
static _read_r_fn _read_r_app;
#if !defined(CONFIG_IDF_TARGET_ESP32C3)
#if defined(CONFIG_IDF_TARGET_ESP32)
static _read_r_fn _read_r_pro;
#endif
@ -86,7 +90,7 @@ static int console_read_r (struct _reent *r, int fd, void *buf, int size, _read_
return -1;
}
#if !defined(CONFIG_IDF_TARGET_ESP32C3)
#if defined(CONFIG_IDF_TARGET_ESP32)
static int console_read_r_pro (struct _reent *r, int fd, void *buf, int size)
{
return console_read_r (r, fd, buf, size, _read_r_pro);
@ -154,11 +158,6 @@ void console_setup (const ConsoleSetup_t *cfg)
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
};
uart_param_config(CONSOLE_UART, &uart_conf);
#if !defined(CONFIG_IDF_TARGET_ESP32C3)
// TODO: Make this actually work
UART_SET_AUTOBAUD_EN(CONSOLE_UART, cfg->auto_baud);
#endif
}
@ -179,14 +178,15 @@ void console_init (const ConsoleSetup_t *cfg, task_handle_t tsk)
UART_FRM_ERR_INT_ENA_M);
// Register our console_read_r_xxx functions to support stdin input
#if defined(CONFIG_IDF_TARGET_ESP32C3)
_read_r_app = syscall_table_ptr->_read_r;
syscall_table_ptr->_read_r = console_read_r_app;
#else
#if defined(CONFIG_IDF_TARGET_ESP32)
// Only the original ESP32 uses per-cpu tables; the S2/S3/C3 do not
_read_r_app = syscall_table_ptr_app->_read_r;
_read_r_pro = syscall_table_ptr_pro->_read_r;
syscall_table_ptr_app->_read_r = console_read_r_app;
syscall_table_ptr_pro->_read_r = console_read_r_pro;
#else
_read_r_app = syscall_table_ptr->_read_r;
syscall_table_ptr->_read_r = console_read_r_app;
#endif
}

View File

@ -1,49 +0,0 @@
if(NOT "${IDF_TARGET}" STREQUAL "esp32c3")
# Globbing isn't recommended, but I dislike it less than having to edit
# this file whenever a new module source file springs into existence.
# Just remember to "idf.py reconfigure" (or do a clean build) to get
# cmake to pick up on the new (or removed) files.
file(
GLOB module_srcs
LIST_DIRECTORIES false
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
*.c
)
idf_component_register(
SRCS ${module_srcs}
PRIV_INCLUDE_DIRS "." "${CMAKE_CURRENT_BINARY_DIR}"
PRIV_REQUIRES
"base_nodemcu"
"driver"
"driver_can"
"sdmmc"
"esp_eth"
"lua"
"modules"
"platform"
"soc"
)
# Match up all the module source files with their corresponding Kconfig
# option in the form NODEMCU_CMODULE_<modname> and if enabled, add a
# "-u <modname>_module_selected1" option to force the linker to include
# the module. See components/core/include/module.h for further details on
# how this works.
set(modules_enabled)
foreach(module_src ${module_srcs})
string(REPLACE ".c" "" module_name ${module_src})
string(TOUPPER ${module_name} module_ucase)
set(mod_opt "CONFIG_NODEMCU_CMODULE_${module_ucase}")
if (${${mod_opt}})
list(APPEND modules_enabled ${module_ucase})
endif()
endforeach()
message("Including the following modules: ${modules_enabled}")
foreach(mod ${modules_enabled})
target_link_libraries(${COMPONENT_LIB} "-u ${mod}_module_selected1")
endforeach()
endif()

View File

@ -1,49 +0,0 @@
menu "NodeMCU modules (ESP32/ESP32-S specific)"
depends on IDF_TARGET != "ESP32C3"
config NODEMCU_CMODULE_CAN
bool "CAN module"
default "n"
help
Includes the can module.
config NODEMCU_CMODULE_DAC
bool "DAC module"
default "n"
help
Includes the dac module.
config NODEMCU_CMODULE_ETH
select ETH_USE_ESP32_EMAC
bool "Ethernet module"
default "n"
help
Includes the ethernet module.
config NODEMCU_CMODULE_I2S
bool "I2S module"
default "n"
help
Includes the I2S module.
config NODEMCU_CMODULE_PULSECNT
bool "Pulse counter module"
default "n"
help
Includes the pulse counter module to use ESP32's built-in pulse
counting hardware.
config NODEMCU_CMODULE_SDMMC
bool "SD-MMC module"
default "n"
help
Includes the sdmmc module.
config NODEMCU_CMODULE_TOUCH
bool "Touch module"
default "n"
help
Includes the touch module to use ESP32's built-in touch sensor
hardware.
endmenu

View File

@ -1,14 +1,68 @@
# Globbing isn't recommended, but I dislike it less than having to edit
# this file whenever a new module source file springs into existence.
# Just remember to "idf.py reconfigure" (or do a clean build) to get
# cmake to pick up on the new (or removed) files.
file(
GLOB module_srcs
LIST_DIRECTORIES false
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
*.c
# Modules common to all chips
set(module_srcs
"adc.c"
"bit.c"
"bthci.c"
"common.c"
"crypto.c"
"dht.c"
"encoder.c"
"file.c"
"gpio.c"
"http.c"
"i2c.c"
"i2c_hw_master.c"
"i2c_hw_slave.c"
"ledc.c"
"mqtt.c"
"net.c"
"node.c"
"otaupgrade.c"
"ow.c"
"pipe.c"
"qrcodegen.c"
"sigma_delta.c"
"sjson.c"
"sodium.c"
"spi.c"
"spi_master.c"
"struct.c"
"time.c"
"tmr.c"
"u8g2.c"
"uart.c"
"ucg.c"
"wifi.c"
"wifi_ap.c"
"wifi_common.c"
"wifi_sta.c"
"ws2812.c"
)
# Chip specific modules, per module.
# List source files for each applicable chip.
if(IDF_TARGET STREQUAL "esp32")
list(APPEND module_srcs
"can.c"
"dac.c"
"eth.c"
"i2s.c"
"pulsecnt.c"
"sdmmc.c"
"touch.c"
)
elseif(IDF_TARGET STREQUAL "esp32s2")
list(APPEND module_srcs
"dac.c"
)
elseif(IDF_TARGET STREQUAL "esp32s3")
list(APPEND module_srcs
)
elseif(IDF_TARGET STREQUAL "esp32c3")
list(APPEND module_srcs
)
endif()
idf_component_register(
SRCS ${module_srcs}
INCLUDE_DIRS "." "${CMAKE_CURRENT_BINARY_DIR}"

View File

@ -21,12 +21,26 @@ menu "NodeMCU modules"
help
Includes the simple BlueTooth HCI module.
config NODEMCU_CMODULE_CAN
depends on CONFIG_IDF_TARGET_ESP32
bool "CAN module"
default "n"
help
Includes the can module.
config NODEMCU_CMODULE_CRYPTO
bool "Crypto module"
default "n"
help
Includes the crypto module.
config NODEMCU_CMODULE_DAC
depends on IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2
bool "DAC module"
default "n"
help
Includes the dac module.
config NODEMCU_CMODULE_DHT
bool "DHT11/21/22/AM2301/AM2302 module"
default "n"
@ -40,6 +54,14 @@ menu "NodeMCU modules"
Includes the encoder module. This provides hex and base64 encoding
and decoding functionality.
config NODEMCU_CMODULE_ETH
depends on IDF_TARGET_ESP32
select ETH_USE_ESP32_EMAC
bool "Ethernet module"
default "n"
help
Includes the ethernet module.
config NODEMCU_CMODULE_FILE
bool "File module"
default "y"
@ -64,6 +86,13 @@ menu "NodeMCU modules"
help
Includes the I2C module (recommended).
config NODEMCU_CMODULE_I2S
depends on IDF_TARGET_ESP32
bool "I2S module"
default "n"
help
Includes the I2S module.
config NODEMCU_CMODULE_LEDC
bool "LEDC module"
default "n"
@ -108,6 +137,14 @@ menu "NodeMCU modules"
help
Includes the pipe module (required by our Lua VM).
config NODEMCU_CMODULE_PULSECNT
depends on IDF_TARGET_ESP32
bool "Pulse counter module"
default "n"
help
Includes the pulse counter module to use ESP32's built-in pulse
counting hardware.
config NODEMCU_CMODULE_QRCODEGEN
bool "QR Code Generator module"
default "n"
@ -115,6 +152,13 @@ menu "NodeMCU modules"
Includes the QR Code Generator from
https://www.nayuki.io/page/qr-code-generator-library
config NODEMCU_CMODULE_SDMMC
depends on IDF_TARGET_ESP32
bool "SD-MMC module"
default "n"
help
Includes the sdmmc module.
config NODEMCU_CMODULE_SIGMA_DELTA
bool "Sigma-Delta module"
default "n"
@ -153,6 +197,14 @@ menu "NodeMCU modules"
help
Includes the timer module (recommended).
config NODEMCU_CMODULE_TOUCH
depends on IDF_TARGET_ESP32
bool "Touch module"
default "n"
help
Includes the touch module to use ESP32's built-in touch sensor
hardware.
config NODEMCU_CMODULE_U8G2
bool "U8G2 module"
default "n"

View File

@ -4,6 +4,7 @@
#include "lmem.h"
#include "driver/i2c.h"
#include "soc/i2c_reg.h"
#include "hal/i2c_ll.h"
#include "i2c_common.h"
@ -219,7 +220,7 @@ int li2c_hw_master_setup( lua_State *L, unsigned id, unsigned sda, unsigned scl,
int timeoutcycles;
i2c_lua_checkerr( L, i2c_get_timeout( port, &timeoutcycles) );
timeoutcycles = timeoutcycles * stretchfactor;
luaL_argcheck( L, timeoutcycles * stretchfactor <= I2C_TIME_OUT_REG_V, 5, "excessive stretch factor" );
luaL_argcheck( L, timeoutcycles * stretchfactor <= I2C_LL_MAX_TIMEOUT, 5, "excessive stretch factor" );
i2c_lua_checkerr( L, i2c_set_timeout( port, timeoutcycles) );
i2c_lua_checkerr( L, i2c_driver_install( port, cfg.mode, 0, 0, 0 ));

View File

@ -56,7 +56,7 @@ static int node_bootreason( lua_State *L)
// 21: EXT_CPU_RESET = 14, /**<14, for APP CPU, reseted by PRO CPU*/
// 22: RTCWDT_BROWN_OUT_RESET = 15, /**<15, Reset when the vdd voltage is not stable*/
// 23: RTCWDT_RTC_RESET = 16 /**<16, RTC Watch dog reset digital core and rtc module*/`
#if defined(CONFIG_IDF_TARGET_ESP32C3)
#if !defined(CONFIG_IDF_TARGET_ESP32)
# define SW_CPU_RESET RTC_SW_CPU_RESET
# define SW_RESET RTC_SW_SYS_RESET
#endif
@ -67,24 +67,32 @@ static int node_bootreason( lua_State *L)
case SW_RESET:
rawinfo = 2; break;
case NO_MEAN:
#if !defined(CONFIG_IDF_TARGET_ESP32C3)
#if defined(CONFIG_IDF_TARGET_ESP32)
case EXT_CPU_RESET:
#endif
case DEEPSLEEP_RESET:
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32C3)
case SDIO_RESET:
#endif
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
case GLITCH_RTC_RESET:
#endif
#if defined(CONFIG_IDF_TARGET_ESP32S3)
case EFUSE_RESET:
#endif
case TG0WDT_SYS_RESET:
case TG1WDT_SYS_RESET:
case INTRUSION_RESET:
case RTCWDT_BROWN_OUT_RESET:
case RTCWDT_RTC_RESET:
rawinfo = 3; break;
#if defined(CONFIG_IDF_TARGET_ESP32C3)
#if defined(CONFIG_IDF_TARGET_ESP32)
case OWDT_RESET:
case TGWDT_CPU_RESET:
#else
case TG0WDT_CPU_RESET:
case TG1WDT_CPU_RESET:
case SUPER_WDT_RESET:
#else
case OWDT_RESET:
case TGWDT_CPU_RESET:
#endif
case RTCWDT_CPU_RESET:
case RTCWDT_SYS_RESET:
@ -99,7 +107,7 @@ static int node_bootreason( lua_State *L)
return 2;
}
#if !defined(CONFIG_IDF_TARGET_ESP32C3)
#if defined(CONFIG_IDF_TARGET_ESP32)
// Lua: node.chipid()
static int node_chipid( lua_State *L )
{
@ -783,7 +791,7 @@ LROT_END(node_wakeup, NULL, 0)
LROT_BEGIN(node, NULL, 0)
LROT_FUNCENTRY( bootreason, node_bootreason )
#if !defined(CONFIG_IDF_TARGET_ESP32C3)
#if defined(CONFIG_IDF_TARGET_ESP32)
LROT_FUNCENTRY( chipid, node_chipid )
#endif
LROT_FUNCENTRY( compile, node_compile )

View File

@ -61,19 +61,6 @@ menu "NodeMCU platform config"
default 1843200 if NODEMCU_CONSOLE_BIT_RATE_1843200
default 3683400 if NODEMCU_CONSOLE_BIT_RATE_3683400
config NODEMCU_CONSOLE_BIT_RATE_AUTO
bool "UART console auto-baud detection"
default "y"
help
Enables auto-baud detection for the UART console.
By typing a few characters into the console shortly after boot,
NodeMCU can automatically detect your terminal settings and
adjust accordingly.
If you are doing advanced things with the console, you may want
to disable this feature.
config NODEMCU_NODE_DEBUG
bool "Enable NODE_DBG() output"
default "n"

View File

@ -501,15 +501,7 @@ int platform_adc_channel_exists( uint8_t adc, uint8_t channel ) {
uint8_t platform_adc_set_width( uint8_t adc, int bits ) {
(void)adc;
#if defined(CONFIG_IDF_TARGET_ESP32C3)
if (bits != SOC_ADC_MAX_BITWIDTH)
return 0;
bits = SOC_ADC_MAX_BITWIDTH;
#else
bits = bits - 9;
if (bits < ADC_WIDTH_9Bit || bits > ADC_WIDTH_12Bit)
return 0;
#endif
if (ESP_OK != adc1_config_width( bits ))
return 0;
@ -530,7 +522,7 @@ int platform_adc_read( uint8_t adc, uint8_t channel ) {
}
int platform_adc_read_hall_sensor( ) {
#if !defined(CONFIG_IDF_TARGET_ESP32C3)
#if defined(CONFIG_IDF_TARGET_ESP32)
int value = hall_sensor_read( );
return value;
#else

View File

@ -104,10 +104,10 @@ static void ws2812_isr(void *arg)
RMT.int_clr.val = BIT(channel+24);
ws2812_chain_t *chain = &(ws2812_chains[channel]);
#if defined(CONFIG_IDF_TARGET_ESP32C3)
uint32_t data_sub_len = RMT.tx_lim[channel].limit/8;
#else
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2)
uint32_t data_sub_len = RMT.tx_lim_ch[channel].limit/8;
#else
uint32_t data_sub_len = RMT.tx_lim[channel].limit/8;
#endif
if (chain->len >= data_sub_len) {