Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
matrix:
lua_ver: ['5.1', '5.3']
numbers: ['default', 'alternate']
target: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32c6', 'esp32h2']
target: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32c5', 'esp32c6', 'esp32h2']

runs-on: ubuntu-20.04
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4
Expand All @@ -31,7 +31,10 @@ jobs:
shell: bash
- name: Prepare default sdkconfig
run: |
# Compose sdkconfig manually rather than overwrite checked in files
cp sdkconfig.defaults sdkconfig
[ -e "sdkconfig.defaults.${{ matrix.target }}" ] && cat "sdkconfig.defaults.${{ matrix.target }}" >> sdkconfig || true
[ -e "sdkconfig.ci.${{ matrix.target }}" ] && cat "sdkconfig.ci.${{ matrix.target }}" >> sdkconfig || true
shell: bash
- name: Update config for Lua 5.1
if: ${{ matrix.lua_ver == '5.1' }}
Expand All @@ -54,6 +57,10 @@ jobs:
echo CONFIG_LUA_NUMBER_INT64=y >> sdkconfig
echo CONFIG_LUA_NUMBER_DOUBLE=y >> sdkconfig
shell: bash
- name: Show resulting sdkconfig
shell: bash
run: |
cat sdkconfig
- name: Build firmware
run: |
make IDF_TARGET=${{ matrix.target }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
sdk/
cache/
user_config.h
server-ca.crt
sdkconfig
sdkconfig.old*
Expand All @@ -13,6 +12,7 @@ bin
version.txt
managed_components/
dependencies.lock
.idf_tools_installed

#ignore Eclipse project files
.cproject
Expand Down
2 changes: 1 addition & 1 deletion components/base_nodemcu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ idf_component_register(
SRCS "ip_fmt.c" "user_main.c"
INCLUDE_DIRS "include"
REQUIRES "lua"
PRIV_REQUIRES "nvs_flash" "spiffs" "esp_netif" "driver" "vfs"
PRIV_REQUIRES "driver" "esp_netif" "esp_vfs_console" "nvs_flash" "vfs" "spiffs"
LDFRAGMENTS "nodemcu.lf"
)
41 changes: 11 additions & 30 deletions components/base_nodemcu/user_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
#include "sdkconfig.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_spiffs.h"
#include "esp_netif.h"
#include "esp_vfs_dev.h"
#include "esp_vfs_cdcacm.h"
#include "esp_vfs_usb_serial_jtag.h"
#include "driver/uart_vfs.h"
#include "driver/usb_serial_jtag.h"
#include "nvs_flash.h"

#include "task/task.h"
Expand All @@ -24,6 +28,10 @@
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"

#ifndef CONFIG_NODEMCU_AUTO_FORMAT_ON_BOOT
# define CONFIG_NODEMCU_AUTO_FORMAT_ON_BOOT 0
#endif


// We don't get argument size data from the esp_event dispatch, so it's
// not possible to copy and forward events from the default event queue
Expand Down Expand Up @@ -94,42 +102,15 @@ static void start_lua ()

static void nodemcu_init(void)
{
NODE_ERR("\n");
// Initialize platform first for lua modules.
if( platform_init() != PLATFORM_OK )
{
// This should never happen
NODE_DBG("Can not init platform for modules.\n");
return;
}
const char *label = CONFIG_NODEMCU_DEFAULT_SPIFFS_LABEL;

esp_vfs_spiffs_conf_t spiffs_cfg = {
.base_path = "",
.partition_label = (label && label[0]) ? label : NULL,
.max_files = CONFIG_NODEMCU_MAX_OPEN_FILES,
.format_if_mount_failed = true,
};
const char *reason = NULL;
switch(esp_vfs_spiffs_register(&spiffs_cfg))
{
case ESP_OK: break;
case ESP_ERR_NO_MEM:
reason = "out of memory";
break;
case ESP_ERR_INVALID_STATE:
reason = "already mounted, or encrypted";
break;
case ESP_ERR_NOT_FOUND:
reason = "no SPIFFS partition found";
break;
case ESP_FAIL:
reason = "failed to mount or format partition";
break;
default:
reason = "unknown";
break;
}
const char *reason =
platform_remount_default_fs(CONFIG_NODEMCU_AUTO_FORMAT_ON_BOOT);
if (reason)
printf("Failed to mount SPIFFS partition: %s\n", reason);
}
Expand Down
14 changes: 13 additions & 1 deletion components/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Modules common to all chips
set(extra_requires
)
set(wifi_modules
"espnow.c"
"wifi.c"
Expand Down Expand Up @@ -64,6 +66,9 @@ if(IDF_TARGET STREQUAL "esp32")
"touch.c"
${wifi_modules}
)
list(APPEND extra_requires
"driver_can"
)
elseif(IDF_TARGET STREQUAL "esp32s2")
list(APPEND module_srcs
"dac.c"
Expand All @@ -81,6 +86,12 @@ elseif(IDF_TARGET STREQUAL "esp32c3")
list(APPEND module_srcs
${wifi_modules}
)
elseif(IDF_TARGET STREQUAL "esp32c5")
list(APPEND module_srcs
"i2s.c"
"pulsecnt.c"
${wifi_modules}
)
elseif(IDF_TARGET STREQUAL "esp32c6")
list(APPEND module_srcs
"dac.c"
Expand All @@ -99,11 +110,11 @@ idf_component_register(
"app_update"
"base_nodemcu"
"bt"
"driver_can"
"esp_eth"
"esp_http_client"
"esp_http_server"
"esp_hw_support"
"esp_vfs_console"
"fatfs"
"libsodium"
"lua"
Expand All @@ -118,6 +129,7 @@ idf_component_register(
"u8g2"
"ucg"
"vfs"
${extra_requires}
)

# Match up all the module source files with their corresponding Kconfig
Expand Down
12 changes: 12 additions & 0 deletions components/modules/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,18 @@ menu "NodeMCU modules"
help
Includes the WiFi module (recommended).

config NODEMCU_CMODULE_WIFI_STARTUP_DELAY
depends on NODEMCU_CMODULE_WIFI
depends on ESP_CONSOLE_USB_CDC
int "WiFi start-up delay (ms)"
default 500
help
For some unknown reason there is an issue with allowing the
WiFi stack to initialise immediately when using a USB CDC
console (at least on the ESP32-S2). The workaround is to
delay the initialisation sequence by enough that whatever
else is needing to run gets to run first.

config NODEMCU_CMODULE_WS2812
bool "WS2812 module"
default "n"
Expand Down
14 changes: 8 additions & 6 deletions components/modules/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include "esp_vfs_dev.h"
#include "esp_vfs_cdcacm.h"
#include "esp_vfs_usb_serial_jtag.h"
#include "driver/uart_vfs.h"
#include "driver/usb_serial_jtag.h"
#include "driver/usb_serial_jtag_vfs.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

Expand Down Expand Up @@ -111,9 +113,9 @@ static void console_init(void)
#if CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM
/* Based on console/advanced example */

esp_vfs_dev_uart_port_set_rx_line_endings(
uart_vfs_dev_port_set_rx_line_endings(
CONFIG_ESP_CONSOLE_UART_NUM, RX_LINE_ENDINGS_CFG);
esp_vfs_dev_uart_port_set_tx_line_endings(
uart_vfs_dev_port_set_tx_line_endings(
CONFIG_ESP_CONSOLE_UART_NUM, TX_LINE_ENDINGS_CFG);

/* Configure UART. Note that REF_TICK is used so that the baud rate remains
Expand All @@ -135,20 +137,20 @@ static void console_init(void)
uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config);

/* Tell VFS to use UART driver */
esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
uart_vfs_dev_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);

#elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
/* Based on @pjsg's work */

esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(RX_LINE_ENDINGS_CFG);
esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(TX_LINE_ENDINGS_CFG);
usb_serial_jtag_vfs_set_rx_line_endings(RX_LINE_ENDINGS_CFG);
usb_serial_jtag_vfs_set_tx_line_endings(TX_LINE_ENDINGS_CFG);

usb_serial_jtag_driver_config_t usb_serial_jtag_config =
USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT();
/* Install USB-SERIAL-JTAG driver for interrupt-driven reads and write */
usb_serial_jtag_driver_install(&usb_serial_jtag_config);

esp_vfs_usb_serial_jtag_use_driver();
usb_serial_jtag_vfs_use_driver();
#elif CONFIG_ESP_CONSOLE_USB_CDC
/* Based on console/advanced_usb_cdc */

Expand Down
4 changes: 2 additions & 2 deletions components/modules/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ static int leth_init( lua_State *L )

eth_esp32_emac_config_t emac_cfg = ETH_ESP32_EMAC_DEFAULT_CONFIG();

emac_cfg.smi_mdc_gpio_num =
emac_cfg.smi_gpio.mdc_num =
opt_checkint_range( L, "mdc", -1, GPIO_NUM_0, GPIO_NUM_MAX-1 );
emac_cfg.smi_mdio_gpio_num =
emac_cfg.smi_gpio.mdio_num =
opt_checkint_range( L, "mdio", -1, GPIO_NUM_0, GPIO_NUM_MAX-1 );

eth_mac_config_t mac_cfg = ETH_MAC_DEFAULT_CONFIG();
Expand Down
5 changes: 5 additions & 0 deletions components/modules/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ static int file_format( lua_State* L )
else{
NODE_ERR( "format done.\n" );
}

const char *err = platform_remount_default_fs(false);
if (err)
return luaL_error(L, err);

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion components/modules/heaptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static int lht_init(lua_State *L)

heap_trace_stop();
free(buffer);
buffer = calloc(sizeof(heap_trace_record_t), records);
buffer = calloc(records, sizeof(heap_trace_record_t));
if (!buffer)
return luaL_error(L, "out of memory");

Expand Down
14 changes: 14 additions & 0 deletions components/modules/i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,13 @@ static int node_i2s_start( lua_State *L )
pin_config.data_out_num = opt_checkint(L, "data_out_pin", I2S_PIN_NO_CHANGE);
pin_config.data_in_num = opt_checkint(L, "data_in_pin", I2S_PIN_NO_CHANGE);
//
#ifdef SOC_I2S_SUPPORTS_DAC
i2s_dac_mode_t dac_mode = opt_checkint_range(L, "dac_mode", I2S_DAC_CHANNEL_DISABLE, 0, I2S_DAC_CHANNEL_MAX-1);
#endif
//
#ifdef SOC_I2S_SUPPORTS_ADC
adc1_channel_t adc1_channel = opt_checkint_range(L, "adc1_channel", ADC1_CHANNEL_MAX, ADC1_CHANNEL_0, ADC1_CHANNEL_MAX);
#endif

// handle optional callback functions TX and RX
lua_settop( L, top );
Expand All @@ -183,14 +187,18 @@ static int node_i2s_start( lua_State *L )
if (err != ESP_OK)
luaL_error( L, "i2s can not start" );

#ifdef SOC_I2S_SUPPORTS_DAC
if (dac_mode != I2S_DAC_CHANNEL_DISABLE) {
if (i2s_set_dac_mode( dac_mode ) != ESP_OK)
luaL_error( L, "error setting dac mode" );
}
#endif
#ifdef SOC_I2S_SUPPORTS_ADC
if (adc1_channel != ADC1_CHANNEL_MAX) {
if (i2s_set_adc_mode( ADC_UNIT_1, adc1_channel ) != ESP_OK)
luaL_error( L, "error setting adc1 mode" );
}
#endif

if (i2s_set_pin(i2s_id, &pin_config) != ESP_OK)
luaL_error( L, "error setting pins" );
Expand Down Expand Up @@ -331,14 +339,20 @@ LROT_BEGIN(i2s, NULL, 0)
LROT_NUMENTRY( MODE_SLAVE, I2S_MODE_SLAVE )
LROT_NUMENTRY( MODE_TX, I2S_MODE_TX )
LROT_NUMENTRY( MODE_RX, I2S_MODE_RX )
#ifdef SOC_I2S_SUPPORTS_DAC
LROT_NUMENTRY( MODE_DAC_BUILT_IN, I2S_MODE_DAC_BUILT_IN )
#endif
#ifdef SOC_I2S_SUPPORTS_ADC
LROT_NUMENTRY( MODE_ADC_BUILT_IN, I2S_MODE_ADC_BUILT_IN )
#endif
LROT_NUMENTRY( MODE_PDM, I2S_MODE_PDM )

#ifdef SOC_I2S_SUPPORTS_DAC
LROT_NUMENTRY( DAC_CHANNEL_DISABLE, I2S_DAC_CHANNEL_DISABLE )
LROT_NUMENTRY( DAC_CHANNEL_RIGHT, I2S_DAC_CHANNEL_RIGHT_EN )
LROT_NUMENTRY( DAC_CHANNEL_LEFT, I2S_DAC_CHANNEL_LEFT_EN )
LROT_NUMENTRY( DAC_CHANNEL_BOTH, I2S_DAC_CHANNEL_BOTH_EN )
#endif
LROT_END(i2s, NULL, 0)

int luaopen_i2s( lua_State *L ) {
Expand Down
17 changes: 10 additions & 7 deletions components/modules/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,19 @@ static int node_bootreason( lua_State *L)
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32C6)
case SDIO_RESET:
#endif
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32H2)
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3)
case GLITCH_RTC_RESET:
#endif
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2)
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2) || defined(CONFIG_IDF_TARGET_ESP32C5)
case EFUSE_RESET:
#endif
#if defined(CONFIG_IDF_TARGET_ESP32C6)
#if defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32C5)
case JTAG_RESET:
#endif
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2)
#if defined(CONFIG_IDF_TARGET_ESP32H2)
case JTAG_CPU_RESET:
#endif
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2) || defined(CONFIG_IDF_TARGET_ESP32C5)
case USB_UART_CHIP_RESET:
case USB_JTAG_CHIP_RESET:
#endif
Expand All @@ -131,7 +134,7 @@ static int node_bootreason( lua_State *L)
#endif
case TG0WDT_SYS_RESET:
case TG1WDT_SYS_RESET:
#if !defined(CONFIG_IDF_TARGET_ESP32C6)
#if !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32C5) && !defined(CONFIG_IDF_TARGET_ESP32H2)
case INTRUSION_RESET:
#endif
case RTCWDT_BROWN_OUT_RESET:
Expand Down Expand Up @@ -281,7 +284,7 @@ static int node_sleep (lua_State *L)
esp_sleep_enable_timer_wakeup(usecs);
}

#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2)
#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32C5)
// touch option: boolean
if (opt_checkbool(L, "touch", false)) {
int err = esp_sleep_enable_touchpad_wakeup();
Expand Down Expand Up @@ -354,7 +357,7 @@ static int node_dsleep (lua_State *L)
}
}

#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2)
#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32C5)
bool pull = opt_checkbool(L, "pull", false);
if (opt_get(L, "isolate", LUA_TTABLE)) {
for (int i = 1; ; i++) {
Expand Down
Loading