diff --git a/.gitignore b/.gitignore index b004739ba4..e161118dd3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ components/*/.output/ tools/toolchains .ccache bin +version.txt +managed_components/ +dependencies.lock #ignore Eclipse project files .cproject diff --git a/components/base_nodemcu/CMakeLists.txt b/components/base_nodemcu/CMakeLists.txt index 7207263780..50114b1ff2 100644 --- a/components/base_nodemcu/CMakeLists.txt +++ b/components/base_nodemcu/CMakeLists.txt @@ -2,6 +2,6 @@ idf_component_register( SRCS "ip_fmt.c" "user_main.c" INCLUDE_DIRS "include" REQUIRES "lua" - PRIV_REQUIRES "nvs_flash" "spiffs" + PRIV_REQUIRES "nvs_flash" "spiffs" "esp_netif" "driver" LDFRAGMENTS "nodemcu.lf" ) diff --git a/components/base_nodemcu/user_main.c b/components/base_nodemcu/user_main.c index adb8832fdf..2e8bca562a 100644 --- a/components/base_nodemcu/user_main.c +++ b/components/base_nodemcu/user_main.c @@ -17,8 +17,8 @@ #include "esp_system.h" #include "esp_event.h" #include "esp_spiffs.h" +#include "esp_netif.h" #include "nvs_flash.h" -#include "flash_api.h" #include "task/task.h" #include "sections.h" @@ -64,7 +64,7 @@ static void relay_default_loop_events( if (task_post_medium(relayed_event_task, (intptr_t)&event)) xSemaphoreTake(relayed_event_handled, portMAX_DELAY); else - printf("ERROR: failed to forward esp event %s/%d", base, id); + printf("ERROR: failed to forward esp event %s/%ld", base, id); } diff --git a/components/driver_can/CAN.c b/components/driver_can/CAN.c index ddd6b61910..d3ca24bae2 100644 --- a/components/driver_can/CAN.c +++ b/components/driver_can/CAN.c @@ -32,6 +32,9 @@ #include "freertos/FreeRTOS.h" #include "freertos/queue.h" +#include "soc/gpio_sig_map.h" +#include "rom/gpio.h" + #include "esp_intr_alloc.h" #include "soc/dport_reg.h" #include diff --git a/components/driver_can/CMakeLists.txt b/components/driver_can/CMakeLists.txt index 44bde7b96e..35ffaee3eb 100644 --- a/components/driver_can/CMakeLists.txt +++ b/components/driver_can/CMakeLists.txt @@ -3,6 +3,7 @@ if(IDF_TARGET STREQUAL "esp32") idf_component_register( SRCS "CAN.c" INCLUDE_DIRS "include" + PRIV_REQUIRES "driver" "esp_rom" ) endif() diff --git a/components/driver_i2c/CMakeLists.txt b/components/driver_i2c/CMakeLists.txt index 99b838826d..64ae54bd35 100644 --- a/components/driver_i2c/CMakeLists.txt +++ b/components/driver_i2c/CMakeLists.txt @@ -1,5 +1,6 @@ idf_component_register( SRCS "i2c_sw_master.c" INCLUDE_DIRS "include" - REQUIRES "esp32" + REQUIRES "esp_rom" + PRIV_REQUIRES "driver" ) diff --git a/components/driver_i2c/include/driver/i2c_sw_master.h b/components/driver_i2c/include/driver/i2c_sw_master.h index ac8b8d30e6..5cb6d8018f 100644 --- a/components/driver_i2c/include/driver/i2c_sw_master.h +++ b/components/driver_i2c/include/driver/i2c_sw_master.h @@ -1,14 +1,14 @@ #ifndef __I2C_SW_MASTER_H__ #define __I2C_SW_MASTER_H__ -#include "rom/ets_sys.h" +#include "esp_rom_sys.h" #define I2C_NUM_MAX 1 void i2c_sw_master_gpio_init(uint8_t sda, uint8_t scl); void i2c_sw_master_init(void); -#define i2c_sw_master_wait ets_delay_us +#define i2c_sw_master_wait esp_rom_delay_us void i2c_sw_master_stop(void); void i2c_sw_master_start(void); void i2c_sw_master_setAck(uint8_t level); diff --git a/components/lua/Kconfig b/components/lua/Kconfig index f41170ef6d..695101a530 100644 --- a/components/lua/Kconfig +++ b/components/lua/Kconfig @@ -2,7 +2,7 @@ menu "Lua configuration" choice LUA_VERSION prompt "Lua version" - default LUA_VERSION_51 + default LUA_VERSION_53 help The version of Lua interpreter to use. diff --git a/components/lua/lua-5.1/lobject.c b/components/lua/lua-5.1/lobject.c index 39512b8c65..2a0b053049 100644 --- a/components/lua/lua-5.1/lobject.c +++ b/components/lua/lua-5.1/lobject.c @@ -20,9 +20,7 @@ #include "lstate.h" #include "lstring.h" #include "lvm.h" -#ifndef LUA_CROSS_COMPILER -#include "flash_api.h" -#else +#ifdef LUA_CROSS_COMPILER #include #endif const TValue luaO_nilobject_ = {LUA_TVALUE_NIL}; diff --git a/components/lua/lua-5.3/lnodemcu.c b/components/lua/lua-5.3/lnodemcu.c index f9cba0f567..7eb70fcd56 100644 --- a/components/lua/lua-5.3/lnodemcu.c +++ b/components/lua/lua-5.3/lnodemcu.c @@ -177,7 +177,7 @@ static void platform_flash_erase_sector(lu_int32 i) { lockFlashWrite(); } -static void platform_s_flash_write(const void *from, lu_int32 to, lu_int32 len) { +static void platform_flash_write(const void *from, lu_int32 to, lu_int32 len) { lua_assert(to >= LFSbase && to + len < LFSbase + LFS_SIZE); /* DEBUG */ unlockFlashWrite(); memcpy(byteptr(LFSregion) + (to-LFSbase), from, len); @@ -449,7 +449,7 @@ static const char *readF (lua_State *L, void *ud, size_t *size) { static void eraseLFS(LFSflashState *F) { lu_int32 i; #ifdef LUA_USE_ESP - printf("\nErasing LFS from flash addr 0x%06x", F->addrPhys); + printf("\nErasing LFS from flash addr 0x%06lx", F->addrPhys); #endif unlockFlashWrite(); for (i = 0; i < F->size; i += FLASH_PAGE_SIZE) { @@ -464,7 +464,7 @@ static void eraseLFS(LFSflashState *F) { platform_flash_erase_sector(s); } #ifdef LUA_USE_ESP - printf(" to 0x%06x\n", F->addrPhys + F->size-1); + printf(" to 0x%06lx\n", F->addrPhys + F->size-1); #endif flush_icache(F); lockFlashWrite(); @@ -483,7 +483,7 @@ LUAI_FUNC void luaN_flushFlash(void *vF) { lu_int32 size = F->oNdx * WORDSIZE; lua_assert(start + size < F->addrPhys + F->size); /* is write in bounds? */ //printf("Flush Buf: %6x (%u)\n", F->oNdx, size); //DEBUG - platform_s_flash_write(F->oBuff, start, size); + platform_flash_write(F->oBuff, start, size); F->oChunkNdx += F->oNdx; F->oNdx = 0; } diff --git a/components/modules/CMakeLists.txt b/components/modules/CMakeLists.txt index 80455ef9d5..c5e77a2a0e 100644 --- a/components/modules/CMakeLists.txt +++ b/components/modules/CMakeLists.txt @@ -59,13 +59,14 @@ if(IDF_TARGET STREQUAL "esp32") elseif(IDF_TARGET STREQUAL "esp32s2") list(APPEND module_srcs "dac.c" - "rmt.c" "pulsecnt.c" + "rmt.c" ) elseif(IDF_TARGET STREQUAL "esp32s3") list(APPEND module_srcs - "rmt.c" "pulsecnt.c" + "rmt.c" + "sdmmc.c" ) elseif(IDF_TARGET STREQUAL "esp32c3") list(APPEND module_srcs @@ -81,9 +82,11 @@ idf_component_register( "base_nodemcu" "bt" "driver_can" + "esp_eth" "esp_http_client" - "fatfs" "esp_http_server" + "esp_hw_support" + "fatfs" "libsodium" "lua" "mbedtls" @@ -91,10 +94,12 @@ idf_component_register( "platform" "qrcodegen" "sdmmc" + "spi_flash" "sjson" "soc" "u8g2" "ucg" + "vfs" ) # Match up all the module source files with their corresponding Kconfig diff --git a/components/modules/adc.c b/components/modules/adc.c index 86af249cad..33f334a9fc 100644 --- a/components/modules/adc.c +++ b/components/modules/adc.c @@ -54,9 +54,9 @@ static int adc_read( lua_State *L ) // Lua: read_hall_sensor( ) static int read_hall_sensor( lua_State *L ) { - int sample = platform_adc_read_hall_sensor( ); - lua_pushinteger( L, ( lua_Integer ) sample ); - return 1; + const char *msg = "ADC hall sensor no longer supported in IDF, sorry"; + platform_print_deprecation_note("msg", "IDFv5"); + return luaL_error(L, msg); } // Module function map diff --git a/components/modules/can.c b/components/modules/can.c index 6f748057b7..3816baface 100644 --- a/components/modules/can.c +++ b/components/modules/can.c @@ -29,7 +29,7 @@ CAN_device_t CAN_cfg = { static task_handle_t can_data_task_id; static int can_on_received = LUA_NOREF; -static xTaskHandle xCanTaskHandle = NULL; +static TaskHandle_t xCanTaskHandle = NULL; // LUA static void can_data_task( task_param_t param, task_prio_t prio ) { diff --git a/components/modules/eth.c b/components/modules/eth.c index 7ccefad567..7aaed53f9a 100644 --- a/components/modules/eth.c +++ b/components/modules/eth.c @@ -14,6 +14,7 @@ #include "esp_eth.h" #include "esp_eth_phy.h" #include "driver/gpio.h" +#include "esp_mac.h" typedef esp_eth_phy_t *(*new_eth_phy_fn)(const eth_phy_config_t *config); @@ -21,9 +22,8 @@ typedef esp_eth_phy_t *(*new_eth_phy_fn)(const eth_phy_config_t *config); typedef enum { ETH_PHY_DP83848, ETH_PHY_IP101, - ETH_PHY_KSZ8041, - ETH_PHY_KSZ8081, - ETH_PHY_LAN8720, + ETH_PHY_KSZ80XX, + ETH_PHY_LAN87XX, ETH_PHY_RTL8201, ETH_PHY_MAX } eth_phy_t; @@ -31,9 +31,8 @@ typedef enum { static const new_eth_phy_fn new_eth_phy[] = { [ETH_PHY_DP83848] = esp_eth_phy_new_dp83848, [ETH_PHY_IP101] = esp_eth_phy_new_ip101, - [ETH_PHY_KSZ8041] = esp_eth_phy_new_ksz8041, - [ETH_PHY_KSZ8081] = esp_eth_phy_new_ksz8081, - [ETH_PHY_LAN8720] = esp_eth_phy_new_lan8720, + [ETH_PHY_KSZ80XX] = esp_eth_phy_new_ksz80xx, + [ETH_PHY_LAN87XX] = esp_eth_phy_new_lan87xx, [ETH_PHY_RTL8201] = esp_eth_phy_new_rtl8201, }; _Static_assert(sizeof(new_eth_phy) == (sizeof(new_eth_phy[0]) * ETH_PHY_MAX), @@ -273,13 +272,15 @@ static int leth_init( lua_State *L ) // temporarily copy option table to top of stack for opt_ functions lua_pushvalue( L, stack ); - eth_mac_config_t mac_cfg = ETH_MAC_DEFAULT_CONFIG(); + eth_esp32_emac_config_t emac_cfg = ETH_ESP32_EMAC_DEFAULT_CONFIG(); - mac_cfg.smi_mdc_gpio_num = + emac_cfg.smi_mdc_gpio_num = opt_checkint_range( L, "mdc", -1, GPIO_NUM_0, GPIO_NUM_MAX-1 ); - mac_cfg.smi_mdio_gpio_num = + emac_cfg.smi_mdio_gpio_num = opt_checkint_range( L, "mdio", -1, GPIO_NUM_0, GPIO_NUM_MAX-1 ); + eth_mac_config_t mac_cfg = ETH_MAC_DEFAULT_CONFIG(); + eth_phy_config_t phy_cfg = ETH_PHY_DEFAULT_CONFIG(); phy_cfg.phy_addr = opt_checkint_range( L, "addr", -1, -1, 31 ); @@ -290,7 +291,7 @@ static int leth_init( lua_State *L ) lua_settop( L, top ); - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_cfg); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&emac_cfg, &mac_cfg); esp_eth_phy_t *phy = new_eth_phy[phy_type](&phy_cfg); esp_eth_config_t eth_cfg = ETH_DEFAULT_CONFIG(mac, phy); @@ -302,10 +303,6 @@ static int leth_init( lua_State *L ) esp_netif_config_t netif_cfg = ESP_NETIF_DEFAULT_ETH(); esp_netif_t *new_eth = esp_netif_new(&netif_cfg); - err = esp_eth_set_default_handlers(new_eth); - if (err != ESP_OK) - goto cleanup_netif; - void *glue = esp_eth_new_netif_glue(eth_handle); err = esp_netif_attach(new_eth, glue); if (err != ESP_OK) @@ -320,8 +317,6 @@ static int leth_init( lua_State *L ) cleanup_glue: esp_eth_del_netif_glue(glue); - -cleanup_netif: esp_netif_destroy(new_eth); cleanup_mac_phy: @@ -354,9 +349,11 @@ LROT_BEGIN(eth, NULL, 0) LROT_NUMENTRY( PHY_DP83848, ETH_PHY_DP83848 ) LROT_NUMENTRY( PHY_IP101, ETH_PHY_IP101 ) - LROT_NUMENTRY( PHY_KSZ8041, ETH_PHY_KSZ8041 ) - LROT_NUMENTRY( PHY_KSZ8081, ETH_PHY_KSZ8081 ) - LROT_NUMENTRY( PHY_LAN8720, ETH_PHY_LAN8720 ) + LROT_NUMENTRY( PHY_KSZ80XX, ETH_PHY_KSZ80XX ) + LROT_NUMENTRY( PHY_KSZ8041, ETH_PHY_KSZ80XX ) // deprecated in favour of 80XX + LROT_NUMENTRY( PHY_KSZ8081, ETH_PHY_KSZ80XX ) // deprecated in favour of 80XX + LROT_NUMENTRY( PHY_LAN87XX, ETH_PHY_LAN87XX ) + LROT_NUMENTRY( PHY_LAN8720, ETH_PHY_LAN87XX ) // deprecated in favour of 87XX LROT_NUMENTRY( PHY_RTL8201, ETH_PHY_RTL8201 ) LROT_END(eth, NULL, 0) diff --git a/components/modules/heaptrace.c b/components/modules/heaptrace.c index 8a5966f427..d8f023eef3 100644 --- a/components/modules/heaptrace.c +++ b/components/modules/heaptrace.c @@ -1,7 +1,10 @@ #include "module.h" #include "lauxlib.h" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcpp" #include "esp_heap_trace.h" +#pragma GCC diagnostic pop static heap_trace_record_t *buffer = NULL; diff --git a/components/modules/i2c_hw_master.c b/components/modules/i2c_hw_master.c index f07092923d..e4055fc4ee 100644 --- a/components/modules/i2c_hw_master.c +++ b/components/modules/i2c_hw_master.c @@ -1,10 +1,11 @@ - #include "module.h" #include "lauxlib.h" #include "lmem.h" +#include "platform.h" #include "driver/i2c.h" #include "soc/i2c_reg.h" #include "hal/i2c_ll.h" +#include "rom/gpio.h" #include "i2c_common.h" @@ -73,7 +74,7 @@ static void vTransferTask( void *pvParameters ) xQueueReceive( xQueue, job, portMAX_DELAY ); job->err = i2c_master_cmd_begin( job->port, job->cmd, - job->to_ms > 0 ? job->to_ms / portTICK_RATE_MS : portMAX_DELAY ); + job->to_ms > 0 ? job->to_ms / portTICK_PERIOD_MS : portMAX_DELAY ); task_post_medium( i2c_transfer_task_id, (task_param_t)job ); } @@ -202,11 +203,11 @@ int li2c_hw_master_setup( lua_State *L, unsigned id, unsigned sda, unsigned scl, memset( &cfg, 0, sizeof( cfg ) ); cfg.mode = I2C_MODE_MASTER; - luaL_argcheck( L, GPIO_IS_VALID_OUTPUT_GPIO(sda), 2, "invalid sda pin" ); + luaL_argcheck( L, platform_gpio_output_exists(sda), 2, "invalid sda pin" ); cfg.sda_io_num = sda; cfg.sda_pullup_en = GPIO_PULLUP_ENABLE; - luaL_argcheck( L, GPIO_IS_VALID_OUTPUT_GPIO(scl), 3, "invalid scl pin" ); + luaL_argcheck( L, platform_gpio_output_exists(scl), 3, "invalid scl pin" ); cfg.scl_io_num = scl; cfg.scl_pullup_en = GPIO_PULLUP_ENABLE; @@ -357,7 +358,7 @@ int li2c_hw_master_transfer( lua_State *L ) // note that i2c_master_cmd_begin() implements mutual exclusive access // if it is currently in progress from the transfer task, it will block here until esp_err_t err = i2c_master_cmd_begin( job->port, job->cmd, - job->to_ms > 0 ? job->to_ms / portTICK_RATE_MS : portMAX_DELAY ); + job->to_ms > 0 ? job->to_ms / portTICK_PERIOD_MS : portMAX_DELAY ); switch (err) { case ESP_OK: diff --git a/components/modules/i2s.c b/components/modules/i2s.c index 88fab401de..cd213c57d0 100644 --- a/components/modules/i2s.c +++ b/components/modules/i2s.c @@ -30,11 +30,11 @@ typedef struct { typedef struct { struct { - xTaskHandle taskHandle; + TaskHandle_t taskHandle; QueueHandle_t queue; } tx; struct { - xTaskHandle taskHandle; + TaskHandle_t taskHandle; QueueHandle_t queue; } rx; int cb; @@ -152,8 +152,8 @@ static int node_i2s_start( lua_State *L ) // i2s_config.channel_format = opt_checkint(L, "channel", I2S_CHANNEL_FMT_RIGHT_LEFT); i2s_config.communication_format = opt_checkint(L, "format", I2S_COMM_FORMAT_STAND_I2S); - i2s_config.dma_buf_count = opt_checkint_range(L, "buffer_count", 2, 2, 128); - i2s_config.dma_buf_len = opt_checkint_range(L, "buffer_len", i2s_config.sample_rate / 100, 8, 1024); + i2s_config.dma_desc_num = opt_checkint_range(L, "buffer_count", 2, 2, 128); + i2s_config.dma_frame_num = opt_checkint_range(L, "buffer_len", i2s_config.sample_rate / 100, 8, 1024); i2s_config.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1; // pin_config.bck_io_num = opt_checkint(L, "bck_pin", I2S_PIN_NO_CHANGE); @@ -176,9 +176,9 @@ static int node_i2s_start( lua_State *L ) esp_err_t err; if (i2s_config.mode & I2S_MODE_RX) { - err = i2s_driver_install(i2s_id, &i2s_config, i2s_config.dma_buf_count, &is->rx.queue); + err = i2s_driver_install(i2s_id, &i2s_config, i2s_config.dma_desc_num, &is->rx.queue); } else { - err = i2s_driver_install(i2s_id, &i2s_config, i2s_config.dma_buf_count, NULL); + err = i2s_driver_install(i2s_id, &i2s_config, i2s_config.dma_desc_num, NULL); } if (err != ESP_OK) luaL_error( L, "i2s can not start" ); @@ -265,7 +265,7 @@ static int node_i2s_read( lua_State *L ) int wait_ms = luaL_optint(L, 3, 0); char * data = luaM_malloc( L, bytes ); size_t read; - if (i2s_read(i2s_id, data, bytes, &read, wait_ms / portTICK_RATE_MS) != ESP_OK) + if (i2s_read(i2s_id, data, bytes, &read, wait_ms / portTICK_PERIOD_MS) != ESP_OK) return luaL_error( L, "I2S driver error" ); lua_pushlstring(L, data, read); diff --git a/components/modules/idf_component.yml b/components/modules/idf_component.yml new file mode 100644 index 0000000000..ae9c530179 --- /dev/null +++ b/components/modules/idf_component.yml @@ -0,0 +1,7 @@ +## IDF Component Manager Manifest File +dependencies: + ## Required IDF version + idf: + version: ">=5.0.0" + # Component dependencies + libsodium: "~1.0.20" diff --git a/components/modules/mqtt.c b/components/modules/mqtt.c index ecc8aca49d..3c4909aa8f 100644 --- a/components/modules/mqtt.c +++ b/components/modules/mqtt.c @@ -50,6 +50,13 @@ typedef struct { }; } mqtt_context_t; + +typedef struct { + mqtt_context_t *ctx; + esp_mqtt_event_t event; +} event_info_t; + + // event_handler_t is the function signature for all events typedef void (*event_handler_t)(lua_State* L, mqtt_context_t* mqtt_context, esp_mqtt_event_handle_t event); @@ -64,10 +71,12 @@ task_handle_t event_handler_task_id = 0; // event_clone makes a copy of the mqtt event received so we can pass it on // and the mqtt library can discard it. -static esp_mqtt_event_handle_t event_clone(esp_mqtt_event_handle_t ev) { +static event_info_t *event_clone(esp_mqtt_event_handle_t ev, mqtt_context_t *ctx) { // allocate memory for the copy - esp_mqtt_event_handle_t ev1 = (esp_mqtt_event_handle_t)malloc(sizeof(esp_mqtt_event_t)); + event_info_t *clone = (event_info_t *)malloc(sizeof(event_info_t)); ESP_LOGD(TAG, "event_clone(): event %p, event id %d, msg %d", ev, ev->event_id, ev->msg_id); + clone->ctx = ctx; + esp_mqtt_event_handle_t ev1 = &clone->event; // make a shallow copy: *ev1 = *ev; @@ -95,11 +104,12 @@ static esp_mqtt_event_handle_t event_clone(esp_mqtt_event_handle_t ev) { ev1->topic = NULL; } } - return ev1; + return clone; } // event_free deallocates all the memory associated with a cloned event -static void event_free(esp_mqtt_event_handle_t ev) { +static void event_free(event_info_t *clone) { + esp_mqtt_event_handle_t ev = &clone->event; if (ev->data != NULL) { ESP_LOGD(TAG, "event_free():free: event %p, msg %d, data %p", ev, ev->msg_id, ev->data); free(ev->data); @@ -108,7 +118,7 @@ static void event_free(esp_mqtt_event_handle_t ev) { ESP_LOGD(TAG, "event_free():free: event %p, msg %d, topic %p", ev, ev->msg_id, ev->topic); free(ev->topic); } - free(ev); + free(clone); } // event_connected is run when the mqtt client connected @@ -235,10 +245,9 @@ static void event_data_received(lua_State* L, mqtt_context_t* mqtt_context, esp_ // event_task_handler takes a nodemcu task message and dispatches it to the appropriate event_xxx callback above. static void event_task_handler(task_param_t param, task_prio_t prio) { // extract the event data out of the task param - esp_mqtt_event_handle_t event = (esp_mqtt_event_handle_t)param; - - // recover the mqtt context from the event user_context field: - mqtt_context_t* mqtt_context = (mqtt_context_t*)event->user_context; + event_info_t *info = (event_info_t *)param; + esp_mqtt_event_handle_t event = &info->event; + mqtt_context_t* mqtt_context = info->ctx; // Check if this event is about an object that is in the process of garbage collection: if (!luaX_valid_ref(mqtt_context->self)) { @@ -290,14 +299,17 @@ static void event_task_handler(task_param_t param, task_prio_t prio) { lua_settop(L, top); // leave the stack as it was task_handler_end: - event_free(event); // free the event copy memory + event_free(info); // free the cloned event info } // mqtt_event_handler receives all events from the esp mqtt library and converts them // to a task message -static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event) { - task_post_medium(event_handler_task_id, (task_param_t)event_clone(event)); - return ESP_OK; +static void mqtt_event_handler(void *handler_arg, esp_event_base_t base, int32_t event_id, void *event_data) { + (void)base; + (void)event_id; + event_info_t *clone = event_clone(event_data, handler_arg); + if (!task_post_medium(event_handler_task_id, (task_param_t)clone)) + event_free(clone); } // Lua: on() @@ -330,7 +342,15 @@ static int mqtt_connect(lua_State* L) { memset(&config, 0, sizeof(esp_mqtt_client_config_t)); // process function parameters populating the mqtt config structure - config.host = luaL_checkstring(L, 2); + const char *host = luaL_checkstring(L, 2); + bool is_mqtt_uri = strncmp(host, "mqtt://", 7) == 0; + bool is_mqtts_uri = strncmp(host, "mqtts://", 8) == 0; + bool is_ws_uri = strncmp(host, "ws://", 5) == 0; + bool is_wss_uri = strncmp(host, "wss://", 6) == 0; + if (is_mqtt_uri || is_mqtts_uri || is_ws_uri || is_wss_uri) + config.broker.address.uri = host; + else + config.broker.address.hostname = host; // set defaults: int secure = 0; @@ -340,14 +360,20 @@ static int mqtt_connect(lua_State* L) { const char * cert_pem = NULL; const char * client_cert_pem = NULL; const char * client_key_pem = NULL; - + size_t cert_pem_len = 0; + size_t client_cert_pem_len = 0; + size_t client_key_pem_len = 0; if (lua_isnumber(L, n)) { + if (is_mqtt_uri || is_mqtts_uri) + return luaL_error(L, "port arg must be nil if giving full uri"); port = luaL_checknumber(L, n); n++; } if (lua_isnumber(L, n)) { + if (is_mqtt_uri || is_mqtts_uri) + return luaL_error(L, "secure on/off determined by uri"); secure = !!luaL_checkinteger(L, n); n++; @@ -355,19 +381,19 @@ static int mqtt_connect(lua_State* L) { if (lua_istable(L, n)) { secure = true; lua_getfield(L, n, "ca_cert"); - if ((cert_pem = luaL_optstring(L, -1, NULL)) != NULL) { + if ((cert_pem = luaL_optlstring(L, -1, NULL, &cert_pem_len)) != NULL) { luaX_set_ref(L, -1, &mqtt_context->cert_pem); } lua_pop(L, 1); // lua_getfield(L, n, "client_cert"); - if ((client_cert_pem = luaL_optstring(L, -1, NULL)) != NULL) { + if ((client_cert_pem = luaL_optlstring(L, -1, NULL, &client_cert_pem_len)) != NULL) { luaX_set_ref(L, -1, &mqtt_context->client_cert_pem); } lua_pop(L, 1); // lua_getfield(L, n, "client_key"); - if ((client_key_pem = luaL_optstring(L, -1, NULL)) != NULL) { + if ((client_key_pem = luaL_optlstring(L, -1, NULL, &client_key_pem_len)) != NULL) { luaX_set_ref(L, -1, &mqtt_context->client_key_pem); } lua_pop(L, 1); @@ -393,24 +419,26 @@ static int mqtt_connect(lua_State* L) { ESP_LOGD(TAG, "connect: mqtt_context*: %p", mqtt_context); - config.user_context = mqtt_context; // store a pointer to our context in the mqtt client user context field - // this will be useful to identify to which instance events belong to - config.event_handle = mqtt_event_handler; // set the function that will be called by the mqtt client everytime something - // happens - - config.client_id = mqtt_context->client_id; - config.lwt_msg = mqtt_context->lwt_msg; - config.lwt_topic = mqtt_context->lwt_topic; - config.username = mqtt_context->username; - config.password = mqtt_context->password; - config.keepalive = mqtt_context->keepalive; - config.disable_clean_session = mqtt_context->disable_clean_session; - config.port = port; - config.disable_auto_reconnect = (reconnect == 0); - config.transport = secure ? MQTT_TRANSPORT_OVER_SSL : MQTT_TRANSPORT_OVER_TCP; - config.cert_pem = cert_pem; - config.client_cert_pem = client_cert_pem; - config.client_key_pem = client_key_pem; + if (config.broker.address.uri != NULL) + { + config.broker.address.port = port; + config.broker.address.transport = + secure ? MQTT_TRANSPORT_OVER_SSL : MQTT_TRANSPORT_OVER_TCP; + } + config.broker.verification.certificate = cert_pem; + config.broker.verification.certificate_len = cert_pem_len; + config.credentials.authentication.certificate = client_cert_pem; + config.credentials.authentication.certificate_len = client_cert_pem_len; + config.credentials.authentication.key = client_key_pem; + config.credentials.authentication.key_len = client_key_pem_len; + config.credentials.authentication.password = mqtt_context->password; + config.credentials.client_id = mqtt_context->client_id; + config.credentials.username = mqtt_context->username; + config.network.disable_auto_reconnect = (reconnect == 0); + config.session.disable_clean_session = mqtt_context->disable_clean_session; + config.session.keepalive = mqtt_context->keepalive; + config.session.last_will.msg = mqtt_context->lwt_msg; + config.session.last_will.topic = mqtt_context->lwt_topic; // create a mqtt client instance mqtt_context->client = esp_mqtt_client_init(&config); @@ -419,6 +447,10 @@ static int mqtt_connect(lua_State* L) { return 0; } + // register the event handler with mqtt_context as the handler arg + esp_mqtt_client_register_event( + mqtt_context->client, ESP_EVENT_ANY_ID, mqtt_event_handler, mqtt_context); + // actually start the mqtt client and connect esp_err_t err = esp_mqtt_client_start(mqtt_context->client); if (err != ESP_OK) { diff --git a/components/modules/node.c b/components/modules/node.c index af25ccd38f..b16c67f04c 100644 --- a/components/modules/node.c +++ b/components/modules/node.c @@ -5,6 +5,7 @@ #include "platform.h" #include "task/task.h" #include "esp_system.h" +#include "esp_timer.h" #include "esp_log.h" #include "esp_sleep.h" #include "driver/rtc_io.h" diff --git a/components/modules/otaupgrade.c b/components/modules/otaupgrade.c index 2444ebcf76..3c206f2f34 100644 --- a/components/modules/otaupgrade.c +++ b/components/modules/otaupgrade.c @@ -37,6 +37,7 @@ #include "esp_system.h" #include "esp_ota_ops.h" #include "esp_partition.h" +#include "spi_flash_mmap.h" static esp_ota_handle_t ota_handle; static const esp_partition_t *next; diff --git a/components/modules/pulsecnt.c b/components/modules/pulsecnt.c index 4f4df34bbb..62030e61e2 100644 --- a/components/modules/pulsecnt.c +++ b/components/modules/pulsecnt.c @@ -114,7 +114,7 @@ static void pulsecnt_task(task_param_t param, task_prio_t prio) (void)prio; // we bit packed the unit number and status into 1 int in the IRAM interrupt so need to unpack here - uint32_t unit = (uint32_t)param & 0xffu; + uint8_t unit = (uint8_t)param & 0xffu; int status = ((uint32_t)param >> 8); // int16_t cur_count, evt_count = 0; @@ -217,7 +217,7 @@ static void pulsecnt_task(task_param_t param, task_prio_t prio) // lua_pushinteger (L, status); luaL_pcallx (L, 6, 0); } else { - if (pc->is_debug) ESP_LOGI("pulsecnt", "Could not find cb for unit %d with ptr %d", unit, pc->cb_ref); + if (pc->is_debug) ESP_LOGI("pulsecnt", "Could not find cb for unit %d with ptr %ld", unit, pc->cb_ref); } } @@ -599,7 +599,7 @@ static int pulsecnt_create( lua_State *L ) { pc->is_debug = true; } - if (pc->is_debug) ESP_LOGI("pulsecnt", "Created obj for unit %d with callback ref of %d", pc->unit, pc->cb_ref ); + if (pc->is_debug) ESP_LOGI("pulsecnt", "Created obj for unit %d with callback ref of %ld", pc->unit, pc->cb_ref ); return 1; } diff --git a/components/modules/sdmmc.c b/components/modules/sdmmc.c index e4cd94cba8..d800ba14eb 100644 --- a/components/modules/sdmmc.c +++ b/components/modules/sdmmc.c @@ -13,6 +13,7 @@ #include "driver/sdspi_host.h" #include "common.h" +#include "platform.h" // We're limiting ourselves to the number of FAT volumes configured. #define NUM_CARDS FF_VOLUMES @@ -20,8 +21,12 @@ sdmmc_card_t *lsdmmc_card[NUM_CARDS]; // local definition for SDSPI host #define LSDMMC_HOST_SDSPI 100 +#ifdef CONFIG_IDF_TARGET_ESP32 #define LSDMMC_HOST_HSPI (LSDMMC_HOST_SDSPI + HSPI_HOST) #define LSDMMC_HOST_VSPI (LSDMMC_HOST_SDSPI + VSPI_HOST) +#endif +#define LSDMMC_HOST_SPI2 (LSDMMC_HOST_SDSPI + SPI2_HOST) +#define LSDMMC_HOST_SPI3 (LSDMMC_HOST_SDSPI + SPI3_HOST) typedef struct { sdmmc_card_t *card; @@ -31,25 +36,21 @@ typedef struct { } lsdmmc_ud_t; -static void choose_partition(uint8_t pdrv, uint8_t part) +static bool is_field_present(lua_State *L, int idx, const char *field) { - // Update the volume->partition mapping in FatFS - for (unsigned i = 0; i < FF_VOLUMES; ++i) - { - if (VolToPart[i].pd == pdrv) - VolToPart[i].pt = part; - } + lua_getfield(L, idx, field); + bool present = !lua_isnoneornil(L, -1); + lua_pop(L, 1); + return present; } -static esp_err_t sdmmc_mount_fat(lsdmmc_ud_t *ud, const char *base_path, uint8_t partition) +static esp_err_t sdmmc_mount_fat(lsdmmc_ud_t *ud, const char *base_path) { esp_err_t err = ff_diskio_get_drive(&ud->pdrv); if (err != ESP_OK) return err; - choose_partition(ud->pdrv, partition); - ff_diskio_register_sdmmc(ud->pdrv, ud->card); char drv[3] = { (char)('0' + ud->pdrv), ':', 0 }; @@ -73,7 +74,6 @@ static esp_err_t sdmmc_mount_fat(lsdmmc_ud_t *ud, const char *base_path, uint8_t ud->fs = NULL; } esp_vfs_fat_unregister_path(base_path); - choose_partition(ud->pdrv, 0); ff_diskio_unregister(ud->pdrv); return err; @@ -101,7 +101,10 @@ static int lsdmmc_init( lua_State *L ) int slot = luaL_checkint( L, ++stack ); luaL_argcheck( L, slot == SDMMC_HOST_SLOT_0 || slot == SDMMC_HOST_SLOT_1 || - slot == LSDMMC_HOST_HSPI || slot == LSDMMC_HOST_VSPI, +#ifdef CONFIG_IDF_TARGET_ESP32 + slot == LSDMMC_HOST_HSPI || slot == LSDMMC_HOST_VSPI || +#endif + slot == LSDMMC_HOST_SPI2 || slot == LSDMMC_HOST_SPI3, stack, "invalid slot" ); bool is_sdspi = false; @@ -115,10 +118,7 @@ static int lsdmmc_init( lua_State *L ) int wp_pin = SDMMC_SLOT_NO_WP; int freq_khz = SDMMC_FREQ_DEFAULT; int width = SDMMC_HOST_FLAG_1BIT; - // additional entries for SDSPI configuration - int sck_pin = -1; - int mosi_pin = -1; - int miso_pin = -1; + // additional cs for SDSPI configuration int cs_pin = -1; if (lua_type( L, ++stack ) == LUA_TTABLE) { @@ -131,9 +131,12 @@ static int lsdmmc_init( lua_State *L ) // mandatory entries for SDSPI configuration if (is_sdspi) { - sck_pin = opt_checkint_range( L, "sck_pin", -1, 0, GPIO_NUM_MAX ); - mosi_pin = opt_checkint_range( L, "mosi_pin", -1, 0, GPIO_NUM_MAX ); - miso_pin = opt_checkint_range( L, "miso_pin", -1, 0, GPIO_NUM_MAX ); + if (is_field_present(L, -1, "sck_pin") || + is_field_present(L, -1, "mosi_pin") || + is_field_present(L, -1, "miso_pin")) + { + platform_print_deprecation_note("SCK/MOSI/MISO ignored; please configure via spimaster instead", "IDFv5"); + } cs_pin = opt_checkint_range( L, "cs_pin", -1, 0, GPIO_NUM_MAX ); } @@ -166,16 +169,16 @@ static int lsdmmc_init( lua_State *L ) } if (res == ESP_OK || res == ESP_ERR_INVALID_STATE) { + sdmmc_host_t sdspi_host_config = SDSPI_HOST_DEFAULT(); + sdmmc_host_t sdmmc_host_config = SDMMC_HOST_DEFAULT(); + if (is_sdspi) { // configure SDSPI slot - sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT(); - slot_config.gpio_miso = miso_pin; - slot_config.gpio_mosi = mosi_pin; - slot_config.gpio_sck = sck_pin; - slot_config.gpio_cs = cs_pin; - slot_config.gpio_cd = cd_pin; - slot_config.gpio_wp = wp_pin; - res = sdspi_host_init_slot( slot, &slot_config ); + sdspi_device_config_t dev_config = SDSPI_DEVICE_CONFIG_DEFAULT(); + dev_config.gpio_cs = cs_pin; + dev_config.gpio_cd = cd_pin; + dev_config.gpio_wp = wp_pin; + res = sdspi_host_init_device(&dev_config, &sdspi_host_config.slot); } else { // configure SDMMC slot sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); @@ -184,10 +187,7 @@ static int lsdmmc_init( lua_State *L ) res = sdmmc_host_init_slot( slot, &slot_config ); } if (res == ESP_OK) { - // initialize card - sdmmc_host_t sdspi_host_config = SDSPI_HOST_DEFAULT(); - sdmmc_host_t sdmmc_host_config = SDMMC_HOST_DEFAULT(); sdmmc_host_t *host_config = is_sdspi ? &sdspi_host_config : &sdmmc_host_config; host_config->slot = slot; host_config->flags &= ~SDMMC_HOST_FLAG_8BIT; @@ -352,13 +352,21 @@ static int lsdmmc_mount( lua_State *L ) (void)card; const char *ldrv = luaL_checkstring(L, 2); - int part = luaL_optint(L, 3, 0); + if (!lua_isnoneornil(L, 3)) + { + // Warn that this feature isn't around + platform_print_deprecation_note( + "partition selection not supported", "IDFv5"); + // ...and error if used to select something we can no longer do + if (luaL_optint(L, 3, 0) > 1) + return luaL_error(L, "only first partition supported since IDFv5"); + } lua_settop(L, 2); if (ud->fs == NULL) { - esp_err_t err = sdmmc_mount_fat(ud, ldrv, part); + esp_err_t err = sdmmc_mount_fat(ud, ldrv); if (err == ESP_OK) { // We need this when we unmount @@ -408,8 +416,12 @@ LROT_BEGIN(sdmmc, NULL, 0) LROT_FUNCENTRY( init, lsdmmc_init ) LROT_NUMENTRY( HS1, SDMMC_HOST_SLOT_0 ) LROT_NUMENTRY( HS2, SDMMC_HOST_SLOT_1 ) +#ifdef CONFIG_IDF_TARGET_ESP32 LROT_NUMENTRY( HSPI, LSDMMC_HOST_HSPI ) LROT_NUMENTRY( VSPI, LSDMMC_HOST_VSPI ) +#endif + LROT_NUMENTRY( SPI2, LSDMMC_HOST_SPI2 ) + LROT_NUMENTRY( SPI3, LSDMMC_HOST_SPI3 ) LROT_NUMENTRY( W1BIT, SDMMC_HOST_FLAG_1BIT ) LROT_NUMENTRY( W4BIT, SDMMC_HOST_FLAG_1BIT | SDMMC_HOST_FLAG_4BIT ) diff --git a/components/modules/touch.c b/components/modules/touch.c index a1d2137b68..e8bb2abdfc 100644 --- a/components/modules/touch.c +++ b/components/modules/touch.c @@ -190,7 +190,7 @@ static int touch_create( lua_State *L ) { tp->is_intr = opt_checkbool(L, "intrInitAtStart", true); tp->thresTrigger = opt_checkint_range(L, "thresTrigger", TOUCH_TRIGGER_BELOW, TOUCH_TRIGGER_BELOW, TOUCH_TRIGGER_MAX); - if (tp->is_debug) ESP_LOGI(TAG, "isDebug: %d, filterMs: %d, lvolt: %d, hvolt: %d, atten: %d, slope: %d, intrInitAtStart: %d, thresTrigger: %d", + if (tp->is_debug) ESP_LOGI(TAG, "isDebug: %d, filterMs: %lu, lvolt: %d, hvolt: %d, atten: %d, slope: %d, intrInitAtStart: %d, thresTrigger: %d", tp->is_debug, tp->filterMs, tp->lvolt, tp->hvolt, tp->atten, tp->slope, tp->is_intr, tp->thresTrigger); // get the field pad. this can be passed in as int or table of ints. pad = 0 || {0,1,2,3,4,5,6,7,8,9} @@ -277,7 +277,7 @@ static int touch_create( lua_State *L ) { // Initialize and start a software filter to detect slight change of capacitance. if (tp->filterMs > 0) { touch_pad_filter_start(tp->filterMs); - if (tp->is_debug) ESP_LOGI(TAG, "Set filter period to %d ms", tp->filterMs ); + if (tp->is_debug) ESP_LOGI(TAG, "Set filter period to %lu ms", tp->filterMs ); } // Register touch interrupt ISR @@ -320,7 +320,7 @@ static int touch_create( lua_State *L ) { // prevent false triggering when detecting slight change of capacitance. Need to call // touch_pad_filter_start before all touch filter APIs if (tp->filterMs > 0) { - if (tp->is_debug) ESP_LOGI(TAG, "You provided a filter so turning on filter mode. filterMs: %d", tp->filterMs); + if (tp->is_debug) ESP_LOGI(TAG, "You provided a filter so turning on filter mode. filterMs: %lu", tp->filterMs); esp_err_t err = touch_pad_filter_start(tp->filterMs); if (err == ESP_ERR_INVALID_ARG) { ESP_LOGI(TAG, "Filter start parameter error"); diff --git a/components/platform/CMakeLists.txt b/components/platform/CMakeLists.txt index 1e7148e897..955f8dbb49 100644 --- a/components/platform/CMakeLists.txt +++ b/components/platform/CMakeLists.txt @@ -1,8 +1,27 @@ idf_component_register( - SRCS "dht.c" "flash_api.c" "onewire.c" "platform.c" - "platform_flash.c" "platform_partition.c" "platform_rmt.c" - "u8x8_nodemcu_hal.c" "ucg_nodemcu_hal.c" "wdt.c" "ws2812.c" + SRCS + "dht.c" + "onewire.c" + "platform.c" + "platform_flash.c" + "platform_partition.c" + "platform_rmt.c" + "u8x8_nodemcu_hal.c" + "ucg_nodemcu_hal.c" + "wdt.c" + "ws2812.c" INCLUDE_DIRS "include" - REQUIRES "spiffs" "u8g2" "ucg" "driver_i2c" "task" - PRIV_REQUIRES "bootloader_support" "lua" "esp32" + REQUIRES + "driver" + "driver_i2c" + "spi_flash" + "spiffs" + "task" + "u8g2" + "ucg" + PRIV_REQUIRES + "bootloader_support" + "esp_rom" + "lua" + "soc" ) diff --git a/components/platform/flash_api.c b/components/platform/flash_api.c deleted file mode 100644 index 9b6383a42a..0000000000 --- a/components/platform/flash_api.c +++ /dev/null @@ -1,179 +0,0 @@ -/****************************************************************************** - * Flash api for NodeMCU - * NodeMCU Team - * 2014-12-31 -*******************************************************************************/ -#include "flash_api.h" -#include -#include -#include -#include "rom/spi_flash.h" -#include "platform_wdt.h" -#include "esp_image_format.h" -#include "esp_flash_partitions.h" - -#define FLASH_HDR_ADDR 0x1000 - -static inline esp_image_header_t flash_load_rom_header (void) -{ - esp_image_header_t hdr; - if (ESP_OK != - spi_flash_read (FLASH_HDR_ADDR, (uint32_t *)&hdr, sizeof (hdr))) - { - NODE_ERR("Failed to load flash header block!\n"); - abort(); - } - return hdr; -} - -#define IRAM_SECTION __attribute__((section(".iram1"))) -static void IRAM_SECTION update_flash_chip_size (uint32_t sz) -{ - esp_rom_spiflash_config_param ( - g_rom_flashchip.device_id, - sz, - g_rom_flashchip.block_size, - g_rom_flashchip.sector_size, - g_rom_flashchip.page_size, - g_rom_flashchip.status_mask); -} - -static uint32_t __attribute__((section(".iram1"))) flash_detect_size_byte(void) -{ -#define DETECT_SZ 32 - uint32_t detected_size = FLASH_SIZE_1MBYTE; - uint8_t data_orig[DETECT_SZ] PLATFORM_ALIGNMENT = {0}; - uint8_t data_new[DETECT_SZ] PLATFORM_ALIGNMENT = {0}; - // Ensure we read something which isn't just 0xff... - const uint32_t offs = ESP_PARTITION_TABLE_OFFSET; - // Detect read failure or wrap-around on flash read to find end of flash - if (ESP_OK == spi_flash_read (offs, (uint32_t *)data_orig, DETECT_SZ)) - { - update_flash_chip_size (FLASH_SIZE_16MBYTE); - while ((detected_size < FLASH_SIZE_16MBYTE) && - (ESP_OK == spi_flash_read ( - detected_size + offs, (uint32_t *)data_new, DETECT_SZ)) && - (0 != memcmp(data_orig, data_new, DETECT_SZ))) - { - detected_size *= 2; - } - - update_flash_chip_size (detected_size); - }; - return detected_size; -#undef FLASH_BUFFER_SIZE_DETECT -} - -uint32_t flash_safe_get_size_byte(void) -{ - static uint32_t flash_size = 0; - if (flash_size == 0) - { - flash_size = flash_detect_size_byte(); - } - return flash_size; -} - - -uint16_t flash_safe_get_sec_num(void) -{ - return (flash_safe_get_size_byte() / (SPI_FLASH_SEC_SIZE)); -} - -uint32_t flash_rom_get_size_byte(void) -{ - static uint32_t flash_size = 0; - if (flash_size == 0) - { - switch (flash_load_rom_header ().spi_size) - { - default: // Unknown flash size, fall back mode. - case ESP_IMAGE_FLASH_SIZE_1MB: flash_size = FLASH_SIZE_1MBYTE; break; - case ESP_IMAGE_FLASH_SIZE_2MB: flash_size = FLASH_SIZE_2MBYTE; break; - case ESP_IMAGE_FLASH_SIZE_4MB: flash_size = FLASH_SIZE_4MBYTE; break; - case ESP_IMAGE_FLASH_SIZE_8MB: flash_size = FLASH_SIZE_8MBYTE; break; - case ESP_IMAGE_FLASH_SIZE_16MB: flash_size = FLASH_SIZE_16MBYTE; break; - } - } - return flash_size; -} - -static bool flash_rom_set_size_type(uint8_t size_code) -{ - // Dangerous, here are dinosaur infested!!!!! - // Reboot required!!! - // If you don't know what you're doing, your nodemcu may turn into stone ... - NODE_DBG("\nBEGIN SET FLASH HEADER\n"); - esp_image_header_t *hdr = (esp_image_header_t *)malloc (SPI_FLASH_SEC_SIZE); - if (!hdr) - return false; - - if (ESP_OK == spi_flash_read (FLASH_HDR_ADDR, (uint32_t *)hdr, SPI_FLASH_SEC_SIZE)) - { - hdr->spi_size = size_code; - if (ESP_OK == spi_flash_erase_sector (FLASH_HDR_ADDR / SPI_FLASH_SEC_SIZE)) - { - NODE_DBG("\nERASE SUCCESS\n"); - } - if (ESP_OK == spi_flash_write(FLASH_HDR_ADDR, (uint32_t *)hdr, SPI_FLASH_SEC_SIZE)) - { - NODE_DBG("\nWRITE SUCCESS, %u\n", size_code); - } - } - free (hdr); - NODE_DBG("\nEND SET FLASH HEADER\n"); - return true; -} - - -bool flash_rom_set_size_byte(uint32_t size) -{ - // Dangerous, here are dinosaur infested!!!!! - // Reboot required!!! - bool ok = true; - uint8_t size_code = 0; - switch (size) - { - case FLASH_SIZE_1MBYTE: size_code = ESP_IMAGE_FLASH_SIZE_1MB; break; - case FLASH_SIZE_2MBYTE: size_code = ESP_IMAGE_FLASH_SIZE_2MB; break; - case FLASH_SIZE_4MBYTE: size_code = ESP_IMAGE_FLASH_SIZE_4MB; break; - case FLASH_SIZE_8MBYTE: size_code = ESP_IMAGE_FLASH_SIZE_8MB; break; - case FLASH_SIZE_16MBYTE: size_code = ESP_IMAGE_FLASH_SIZE_16MB; break; - default: ok = false; break; - } - if (ok) - ok = flash_rom_set_size_type (size_code); - return ok; -} - - -uint16_t flash_rom_get_sec_num(void) -{ - return ( flash_rom_get_size_byte() / (SPI_FLASH_SEC_SIZE) ); -} - - -uint8_t flash_rom_get_mode(void) -{ - return flash_load_rom_header ().spi_mode; -} - - -uint32_t flash_rom_get_speed(void) -{ - switch (flash_load_rom_header ().spi_speed) - { - case ESP_IMAGE_SPI_SPEED_40M: return 40000000; - case ESP_IMAGE_SPI_SPEED_26M: return 26700000; // TODO: verify 26.7MHz - case ESP_IMAGE_SPI_SPEED_20M: return 20000000; - case ESP_IMAGE_SPI_SPEED_80M: return 80000000; - default: break; - } - return 0; -} - -esp_err_t flash_erase(size_t sector) -{ - platform_wdt_feed(); - return spi_flash_erase_sector(sector); -} diff --git a/components/platform/include/cpu_esp32.h b/components/platform/include/cpu_esp32.h index f8ae6968d7..6a8fe104f2 100644 --- a/components/platform/include/cpu_esp32.h +++ b/components/platform/include/cpu_esp32.h @@ -2,7 +2,7 @@ #define _CPU_ESP32_H_ #include "sdkconfig.h" -#include "esp_spi_flash.h" +#include "spi_flash_mmap.h" #define NUM_UART SOC_UART_NUM @@ -10,12 +10,4 @@ #define INTERNAL_FLASH_WRITE_UNIT_SIZE 4 #define INTERNAL_FLASH_READ_UNIT_SIZE 4 -#define FLASH_SEC_NUM (flash_safe_get_sec_num()) - -// Determine whether an address is in the flash-cache range -static inline bool is_cache_flash_addr (uint32_t addr) -{ - return addr >= 0x3F400000 && addr < 0x3FC00000; -} - #endif diff --git a/components/platform/include/flash_api.h b/components/platform/include/flash_api.h deleted file mode 100644 index fb703d4487..0000000000 --- a/components/platform/include/flash_api.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __FLASH_API_H__ -#define __FLASH_API_H__ -#include "platform.h" -#include "esp_spi_flash.h" - -uint32_t flash_safe_get_size_byte(void); -uint16_t flash_safe_get_sec_num(void); - -uint32_t flash_rom_get_size_byte(void); - bool flash_rom_set_size_byte(uint32_t); -uint16_t flash_rom_get_sec_num(void); - uint8_t flash_rom_get_mode(void); -uint32_t flash_rom_get_speed(void); - -#define FLASH_SIZE_1MBYTE ( 1 * 1024 * 1024) -#define FLASH_SIZE_2MBYTE ( 2 * 1024 * 1024) -#define FLASH_SIZE_4MBYTE ( 4 * 1024 * 1024) -#define FLASH_SIZE_8MBYTE ( 8 * 1024 * 1024) -#define FLASH_SIZE_16MBYTE (16 * 1024 * 1024) - -#define flash_write spi_flash_write -esp_err_t flash_erase(size_t sector); -#define flash_read spi_flash_read - -#endif // __FLASH_API_H__ diff --git a/components/platform/include/platform.h b/components/platform/include/platform.h index 786e9ab5b0..5c0929a4e1 100644 --- a/components/platform/include/platform.h +++ b/components/platform/include/platform.h @@ -90,7 +90,7 @@ typedef struct { typedef struct { QueueHandle_t queue; - xTaskHandle taskHandle; + TaskHandle_t taskHandle; int receive_rf; int error_rf; char *line_buffer; @@ -137,7 +137,6 @@ int platform_adc_channel_exists( uint8_t adc, uint8_t channel ); uint8_t platform_adc_set_width( uint8_t adc, int bits ); uint8_t platform_adc_setup( uint8_t adc, uint8_t channel, uint8_t attn ); int platform_adc_read( uint8_t adc, uint8_t channel ); -int platform_adc_read_hall_sensor( ); enum { PLATFORM_ADC_ATTEN_0db = 0, PLATFORM_ADC_ATTEN_2_5db = 1, @@ -220,9 +219,6 @@ int platform_ws2812_send( void ); uint32_t platform_flash_get_sector_of_address( uint32_t addr ); uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size ); uint32_t platform_flash_read( void *to, uint32_t fromaddr, uint32_t size ); -uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t size ); -uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size ); -uint32_t platform_flash_get_num_sectors(void); int platform_flash_erase_sector( uint32_t sector_id ); diff --git a/components/platform/onewire.c b/components/platform/onewire.c index 4bc455f61e..4d5888e5db 100644 --- a/components/platform/onewire.c +++ b/components/platform/onewire.c @@ -63,6 +63,8 @@ sample code bearing this copyright. #include "driver/rmt.h" #include "driver/gpio.h" +#include "rom/gpio.h" // for gpio_matrix_out() +#include "soc/gpio_periph.h" #include "esp_log.h" #define TRUE (1==1) @@ -108,7 +110,7 @@ static const uint8_t owDefaultPower = 0; static int onewire_rmt_init( uint8_t gpio_num ) { - if(!GPIO_IS_VALID_GPIO(gpio_num)) { + if(!platform_gpio_exists(gpio_num)) { return PLATFORM_ERR; } @@ -187,7 +189,7 @@ static void onewire_flush_rmt_rx_buf( void ) // check rmt TX&RX channel assignment and eventually attach them to the requested pin static int onewire_rmt_attach_pin( uint8_t gpio_num ) { - if(!GPIO_IS_VALID_GPIO(gpio_num)) { + if(!platform_gpio_exists(gpio_num)) { return PLATFORM_ERR; } diff --git a/components/platform/platform.c b/components/platform/platform.c index 5fc404d438..ea759c34ef 100644 --- a/components/platform/platform.c +++ b/components/platform/platform.c @@ -5,7 +5,9 @@ #include "soc/uart_reg.h" #include #include -#include +#include "freertos/FreeRTOS.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" #include "lua.h" #include "rom/uart.h" #include "esp_log.h" @@ -22,8 +24,24 @@ int platform_init (void) // ***************************************************************************** // GPIO subsection -int platform_gpio_exists( unsigned gpio ) { return GPIO_IS_VALID_GPIO(gpio); } -int platform_gpio_output_exists( unsigned gpio ) { return GPIO_IS_VALID_OUTPUT_GPIO(gpio); } +int platform_gpio_exists(unsigned gpio) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" + // Suppress ">= is always true" due to unsigned type here + return GPIO_IS_VALID_GPIO(gpio); +#pragma GCC diagnostic pop +} + + +int platform_gpio_output_exists(unsigned gpio) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" + // Suppress ">= is always true" due to unsigned type here + return GPIO_IS_VALID_OUTPUT_GPIO(gpio); +#pragma GCC diagnostic pop +} // **************************************************************************** @@ -136,7 +154,7 @@ static void task_uart( void *pvParameters ){ uart_event_t event; for(;;) { - if(xQueueReceive(uart_status[id].queue, (void * )&event, (portTickType)portMAX_DELAY)) { + if(xQueueReceive(uart_status[id].queue, (void * )&event, (TickType_t)portMAX_DELAY)) { switch(event.type) { case UART_DATA: { // Attempt to coalesce received bytes to reduce risk of overrunning @@ -222,6 +240,7 @@ uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int pari .baud_rate = baud, .flow_ctrl = flow_control, .rx_flow_ctrl_thresh = UART_FIFO_LEN - 16, + .source_clk = UART_SCLK_DEFAULT, }; switch (databits) @@ -523,14 +542,6 @@ int platform_adc_read( uint8_t adc, uint8_t channel ) { return value; } -int platform_adc_read_hall_sensor( ) { -#if defined(CONFIG_IDF_TARGET_ESP32) - int value = hall_sensor_read( ); - return value; -#else - return -1; -#endif -} // ***************************************************************************** // I2C platform interface diff --git a/components/platform/platform_flash.c b/components/platform/platform_flash.c index d6e00b367f..acabdccd63 100644 --- a/components/platform/platform_flash.c +++ b/components/platform/platform_flash.c @@ -1,5 +1,6 @@ #include "platform.h" -#include "flash_api.h" +#include "platform_wdt.h" +#include "esp_flash.h" #include #include #include @@ -21,183 +22,43 @@ static uint32_t flashh_find_sector( uint32_t address, uint32_t *pstart, uint32_t return sect_id; } + uint32_t platform_flash_get_sector_of_address( uint32_t addr ) { return flashh_find_sector( addr, NULL, NULL ); } -uint32_t platform_flash_get_num_sectors(void) -{ - return flash_safe_get_sec_num (); -} uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size ) { -#ifndef INTERNAL_FLASH_WRITE_UNIT_SIZE - return platform_s_flash_write( from, toaddr, size ); -#else // #ifindef INTERNAL_FLASH_WRITE_UNIT_SIZE - uint32_t temp, rest, ssize = size; - unsigned i; - char tmpdata[ INTERNAL_FLASH_WRITE_UNIT_SIZE ]; - const uint8_t *pfrom = ( const uint8_t* )from; - const uint32_t blksize = INTERNAL_FLASH_WRITE_UNIT_SIZE; - const uint32_t blkmask = INTERNAL_FLASH_WRITE_UNIT_SIZE - 1; - - // Align the start - if( toaddr & blkmask ) - { - rest = toaddr & blkmask; - temp = toaddr & ~blkmask; // this is the actual aligned address - // memcpy( tmpdata, ( const void* )temp, blksize ); - platform_s_flash_read( tmpdata, temp, blksize ); - for( i = rest; size && ( i < blksize ); i ++, size --, pfrom ++ ) - tmpdata[ i ] = *pfrom; - platform_s_flash_write( tmpdata, temp, blksize ); - if( size == 0 ) - return ssize; - toaddr = temp + blksize; - } - // The start address is now a multiple of blksize - // Compute how many bytes we can write as multiples of blksize - rest = size & blkmask; - temp = size & ~blkmask; - // Program the blocks now - if( temp ) - { - platform_s_flash_write( pfrom, toaddr, temp ); - toaddr += temp; - pfrom += temp; - } - // And the final part of a block if needed - if( rest ) - { - // memcpy( tmpdata, ( const void* )toaddr, blksize ); - platform_s_flash_read( tmpdata, toaddr, blksize ); - for( i = 0; size && ( i < rest ); i ++, size --, pfrom ++ ) - tmpdata[ i ] = *pfrom; - platform_s_flash_write( tmpdata, toaddr, blksize ); - } - return ssize; -#endif // #ifndef INTERNAL_FLASH_WRITE_UNIT_SIZE -} - -uint32_t platform_flash_read( void *to, uint32_t fromaddr, uint32_t size ) -{ -#ifndef INTERNAL_FLASH_READ_UNIT_SIZE - return platform_s_flash_read( to, fromaddr, size ); -#else // #ifindef INTERNAL_FLASH_READ_UNIT_SIZE - uint32_t temp, rest, ssize = size; - unsigned i; - char tmpdata[ INTERNAL_FLASH_READ_UNIT_SIZE ] __attribute__ ((aligned(INTERNAL_FLASH_READ_UNIT_SIZE))); - uint8_t *pto = ( uint8_t* )to; - const uint32_t blksize = INTERNAL_FLASH_READ_UNIT_SIZE; - const uint32_t blkmask = INTERNAL_FLASH_READ_UNIT_SIZE - 1; - - // Align the start - if( fromaddr & blkmask ) - { - rest = fromaddr & blkmask; - temp = fromaddr & ~blkmask; // this is the actual aligned address - platform_s_flash_read( tmpdata, temp, blksize ); - for( i = rest; size && ( i < blksize ); i ++, size --, pto ++ ) - *pto = tmpdata[ i ]; - - if( size == 0 ) - return ssize; - fromaddr = temp + blksize; - } - // The start address is now a multiple of blksize - // Compute how many bytes we can read as multiples of blksize - rest = size & blkmask; - temp = size & ~blkmask; - // Program the blocks now - if( temp ) - { - platform_s_flash_read( pto, fromaddr, temp ); - fromaddr += temp; - pto += temp; - } - // And the final part of a block if needed - if( rest ) - { - platform_s_flash_read( tmpdata, fromaddr, blksize ); - for( i = 0; size && ( i < rest ); i ++, size --, pto ++ ) - *pto = tmpdata[ i ]; - } - return ssize; -#endif // #ifndef INTERNAL_FLASH_READ_UNIT_SIZE -} - - -/* - * Assumptions: - * > toaddr is INTERNAL_FLASH_WRITE_UNIT_SIZE aligned - * > size is a multiple of INTERNAL_FLASH_WRITE_UNIT_SIZE - */ -uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t size ) -{ - esp_err_t r; - const uint32_t blkmask = INTERNAL_FLASH_WRITE_UNIT_SIZE - 1; - uint32_t *apbuf = NULL; - uint32_t fromaddr = (uint32_t)from; - if( (fromaddr & blkmask ) || is_cache_flash_addr(fromaddr)) { - apbuf = (uint32_t *)malloc(size); - if(!apbuf) - return 0; - memcpy(apbuf, from, size); - } - r = flash_write(toaddr, apbuf?(uint32_t *)apbuf:(uint32_t *)from, size); - if(apbuf) - free(apbuf); - if(ESP_OK == r) - return size; - else{ - NODE_ERR( "ERROR in flash_write: r=%d at %08X\n", ( int )r, ( unsigned )toaddr); + esp_err_t err = esp_flash_write(NULL, from, toaddr, size); + if (err != ESP_OK) return 0; - } + else + return size; } -/* - * Assumptions: - * > fromaddr is INTERNAL_FLASH_READ_UNIT_SIZE aligned - * > size is a multiple of INTERNAL_FLASH_READ_UNIT_SIZE - */ -uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size ) +uint32_t platform_flash_read( void *to, uint32_t fromaddr, uint32_t size ) { - if (size==0) + esp_err_t err = esp_flash_write(NULL, to, fromaddr, size); + if (err != ESP_OK) return 0; - - esp_err_t r; - - const uint32_t blkmask = (INTERNAL_FLASH_READ_UNIT_SIZE - 1); - if( ((uint32_t)to) & blkmask ) - { - uint32_t size2=size-INTERNAL_FLASH_READ_UNIT_SIZE; - uint32_t* to2=(uint32_t*)((((uint32_t)to)&(~blkmask))+INTERNAL_FLASH_READ_UNIT_SIZE); - r = flash_read(fromaddr, to2, size2); - if(ESP_OK == r) - { - memmove(to,to2,size2); - char back[ INTERNAL_FLASH_READ_UNIT_SIZE ] __attribute__ ((aligned(INTERNAL_FLASH_READ_UNIT_SIZE))); - r=flash_read(fromaddr+size2,(uint32_t*)back,INTERNAL_FLASH_READ_UNIT_SIZE); - memcpy((uint8_t*)to+size2,back,INTERNAL_FLASH_READ_UNIT_SIZE); - } - } else - r = flash_read(fromaddr, (uint32_t *)to, size); - - if(ESP_OK == r) return size; - else{ - NODE_ERR( "ERROR in flash_read: r=%d at %08X sz %x\n", ( int )r, ( unsigned )fromaddr, size); - return 0; - } } int platform_flash_erase_sector( uint32_t sector_id ) { - return flash_erase( sector_id ) == ESP_OK ? PLATFORM_OK : PLATFORM_ERR; + platform_wdt_feed(); + + uint32_t addr = sector_id * INTERNAL_FLASH_SECTOR_SIZE; + esp_err_t err = + esp_flash_erase_region(NULL, addr, INTERNAL_FLASH_SECTOR_SIZE); + if (err == ESP_OK) + return PLATFORM_OK; + else + return PLATFORM_ERR; } diff --git a/components/platform/platform_partition.c b/components/platform/platform_partition.c index 46cedca618..78fc2effef 100644 --- a/components/platform/platform_partition.c +++ b/components/platform/platform_partition.c @@ -36,7 +36,7 @@ #include #include #include "esp_flash_partitions.h" -#include "esp_spi_flash.h" +#include "esp_flash.h" static inline bool possible_idx (uint8_t idx) { @@ -50,8 +50,12 @@ bool platform_partition_info (uint8_t idx, platform_partition_t *info) return false; esp_partition_info_t pi; - esp_err_t err = spi_flash_read ( - ESP_PARTITION_TABLE_OFFSET + idx * sizeof(pi), (uint32_t *)&pi, sizeof (pi)); + esp_err_t err = esp_flash_read( + NULL, + (uint32_t *)&pi, + ESP_PARTITION_TABLE_OFFSET + idx * sizeof(pi), + sizeof (pi)); + if (err != ESP_OK) return false; @@ -66,42 +70,3 @@ bool platform_partition_info (uint8_t idx, platform_partition_t *info) return true; } - - -bool platform_partition_add (const platform_partition_t *info) -{ - esp_partition_info_t *part_table = - (esp_partition_info_t *)malloc(SPI_FLASH_SEC_SIZE); - if (!part_table) - return false; - esp_err_t err = spi_flash_read ( - ESP_PARTITION_TABLE_OFFSET, (uint32_t *)part_table, SPI_FLASH_SEC_SIZE); - if (err != ESP_OK) - goto out; - - uint8_t idx = 0; - for (; possible_idx (idx); ++idx) - if (part_table[idx].magic != ESP_PARTITION_MAGIC) - break; - - if (possible_idx (idx)) - { - esp_partition_info_t *slot = &part_table[idx]; - slot->magic = ESP_PARTITION_MAGIC; - slot->type = info->type; - slot->subtype = info->subtype; - slot->pos.offset = info->offs; - slot->pos.size = info->size; - memcpy (slot->label, info->label, sizeof (slot->label)); - slot->flags = 0; - err = spi_flash_erase_sector ( - ESP_PARTITION_TABLE_OFFSET / SPI_FLASH_SEC_SIZE); - if (err == ESP_OK) - err = spi_flash_write ( - ESP_PARTITION_TABLE_OFFSET, (uint32_t *)part_table, SPI_FLASH_SEC_SIZE); - } - -out: - free (part_table); - return err == ESP_OK; -} diff --git a/components/platform/platform_rmt.c b/components/platform/platform_rmt.c index 1c5682208c..45560fa9af 100644 --- a/components/platform/platform_rmt.c +++ b/components/platform/platform_rmt.c @@ -1,4 +1,3 @@ - #include #include "platform_rmt.h" diff --git a/components/platform/u8x8_nodemcu_hal.c b/components/platform/u8x8_nodemcu_hal.c index e66b947740..2b51750d92 100644 --- a/components/platform/u8x8_nodemcu_hal.c +++ b/components/platform/u8x8_nodemcu_hal.c @@ -3,7 +3,7 @@ #include "driver/gpio.h" #include "driver/i2c.h" #include "driver/spi_master.h" -#include "rom/ets_sys.h" +#include "esp_rom_sys.h" #include "esp_heap_caps.h" #include @@ -38,27 +38,27 @@ uint8_t u8x8_gpio_and_delay_nodemcu(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, break; case U8X8_MSG_DELAY_NANO: // delay arg_int * 1 nano second - ets_delay_us( 1 ); + esp_rom_delay_us( 1 ); break; case U8X8_MSG_DELAY_100NANO: // delay arg_int * 100 nano seconds temp = arg_int * 100; temp /= 1000; - ets_delay_us( temp > 0 ? temp : 1 ); + esp_rom_delay_us( temp > 0 ? temp : 1 ); break; case U8X8_MSG_DELAY_10MICRO: // delay arg_int * 10 micro seconds - ets_delay_us( arg_int * 10 ); + esp_rom_delay_us( arg_int * 10 ); break; case U8X8_MSG_DELAY_MILLI: // delay arg_int * 1 milli second - ets_delay_us( arg_int * 1000 ); + esp_rom_delay_us( arg_int * 1000 ); break; case U8X8_MSG_DELAY_I2C: // arg_int is the I2C speed in 100KHz, e.g. 4 = 400 KHz temp = 5000 / arg_int; // arg_int=1: delay by 5us, arg_int = 4: delay by 1.25us temp /= 1000; - ets_delay_us( temp > 0 ? temp : 1 ); + esp_rom_delay_us( temp > 0 ? temp : 1 ); break; case U8X8_MSG_GPIO_D0: // D0 or SPI clock pin: Output level in arg_int diff --git a/components/platform/ucg_nodemcu_hal.c b/components/platform/ucg_nodemcu_hal.c index 5cbded354b..b8b407c365 100644 --- a/components/platform/ucg_nodemcu_hal.c +++ b/components/platform/ucg_nodemcu_hal.c @@ -87,7 +87,7 @@ int16_t ucg_com_nodemcu_hw_spi(ucg_t *ucg, int16_t msg, uint16_t arg, uint8_t *d break; case UCG_COM_MSG_DELAY: - ets_delay_us(arg); + esp_rom_delay_us(arg); break; case UCG_COM_MSG_CHANGE_RESET_LINE: diff --git a/components/platform/wdt.c b/components/platform/wdt.c index c815268ebf..4603011ba5 100644 --- a/components/platform/wdt.c +++ b/components/platform/wdt.c @@ -7,23 +7,20 @@ #include "platform.h" #include "esp_task_wdt.h" +int platform_wdt_feed( void ) +{ #ifdef CONFIG_TASK_WDT -static uint32_t task_wdt_timeout = CONFIG_TASK_WDT_TIMEOUT_S; - -static bool task_wdt_panic = + esp_task_wdt_config_t cfg = { + .timeout_ms = CONFIG_TASK_WDT_TIMEOUT_S * 1000, + .idle_core_mask = (uint32_t)-1, + .trigger_panic = #ifdef CONFIG_TASK_WDT_PANIC - true; + true, #else -false; -#endif - + false, #endif - - -int platform_wdt_feed( void ) -{ -#ifdef CONFIG_TASK_WDT - return esp_task_wdt_init(task_wdt_timeout, task_wdt_panic) == ESP_OK ? PLATFORM_OK : PLATFORM_ERR; + }; + return esp_task_wdt_init(&cfg) == ESP_OK ? PLATFORM_OK : PLATFORM_ERR; #else return PLATFORM_OK; #endif diff --git a/components/platform/ws2812.c b/components/platform/ws2812.c index 4a4aace2a5..d00510cb01 100644 --- a/components/platform/ws2812.c +++ b/components/platform/ws2812.c @@ -30,6 +30,8 @@ #include "driver/gpio.h" #include "esp_log.h" #include "soc/periph_defs.h" +#include "rom/gpio.h" // for gpio_matrix_out() +#include "soc/gpio_periph.h" #undef WS2812_DEBUG diff --git a/components/rtos_dbg/rtos_dbg.c b/components/rtos_dbg/rtos_dbg.c index 4ca8f66685..50aed4cbc4 100644 --- a/components/rtos_dbg/rtos_dbg.c +++ b/components/rtos_dbg/rtos_dbg.c @@ -13,7 +13,7 @@ extern struct { void rtos_dbg_task_print (const char *file, uint32_t line) { - printf(">>dbg: %s:%d in RTOS task \"%s\": prio %d\n", + printf(">>dbg: %s:%lu in RTOS task \"%s\": prio %u\n", file, line, pxCurrentTCB->pcTaskName, @@ -30,6 +30,6 @@ void rtos_dbg_stack_print (const char *file, uint32_t line) for (;p < pxCurrentTCB->pxTopOfStack && *p == fill; ++p) ++nwords; - printf(">>dbg: %s:%d in RTOS task \"%s\": %u stack untouched\n", + printf(">>dbg: %s:%lu in RTOS task \"%s\": %lu stack untouched\n", file, line, pxCurrentTCB->pcTaskName, nwords * 4); } diff --git a/components/task/task.c b/components/task/task.c index 0de0caab0a..12c0f77bc5 100644 --- a/components/task/task.c +++ b/components/task/task.c @@ -29,11 +29,11 @@ typedef struct /* * Private arrays to hold the 3 event task queues and the dispatch callbacks */ -static xQueueHandle task_Q[TASK_PRIORITY_COUNT]; +static QueueHandle_t task_Q[TASK_PRIORITY_COUNT]; /* Rather than using a QueueSet (which requires queues to be empty when created) * we use a binary semaphore to unblock the pump whenever something is posted */ -static xSemaphoreHandle pending; +static SemaphoreHandle_t pending; static task_callback_t *task_func; static int task_count; diff --git a/docs/modules/adc.md b/docs/modules/adc.md index 152e44e569..c719999c5c 100644 --- a/docs/modules/adc.md +++ b/docs/modules/adc.md @@ -60,22 +60,3 @@ the sampled value (number) ```lua val = adc.read(adc.ADC1, 0) ``` - -## adc.read_hall_sensor() - -Read Hall sensor (GPIO36, GPIO39). We recommend using 12-bits width on ADC1. - -#### Syntax -`adc.read_hall_sensor()` - -#### Parameters -none - -#### Returns -the sampled value (number) - -#### Example -```lua -val = adc.read_hall_sensor() -``` - diff --git a/docs/modules/eth.md b/docs/modules/eth.md index 3802586c7f..1512af199f 100644 --- a/docs/modules/eth.md +++ b/docs/modules/eth.md @@ -8,8 +8,10 @@ The eth module provides access to the ethernet PHY chip configuration. Your board must contain one of the PHY chips that are supported by ESP-IDF: - IP101 -- LAN8720 -- TLK110 +- RTL8201 +- LAN8720 (possibly others in the LAN87xx family) +- DP83848 +- KSZ8001 / KSZ8021 / KSZ8031 / KSZ8041 / KSZ8051 / KSZ8061 / KSZ8081 / KSZ8091 ## eth.get_mac() Get MAC address. @@ -67,9 +69,11 @@ eth.init(cfg) - `phy` PHY chip model, one of - `PHY_DP83848` - `PHY_IP101` - - `PHY_KSZ8041` - - `PHY_KSZ8081` - - `PHY_LAN8720` + - `PHY_KSZ80XX` + - `PHY_KSZ8041` (deprecated, use `PHY_KSZ80XX` instead) + - `PHY_KSZ8081` (deprecated, use `PHY_KSZ80XX` instead) + - `PHY_LAN87XX` + - `PHY_LAN8720` (deprecated, use `PHY_LAN87XX` instead) - `PHY_RTL8201` - `power` power enable pin, optional diff --git a/docs/modules/sdmmc.md b/docs/modules/sdmmc.md index 89e7728ab3..d6005998bf 100644 --- a/docs/modules/sdmmc.md +++ b/docs/modules/sdmmc.md @@ -77,7 +77,7 @@ Initialize the SDMMC and probe the attached SD card. - `sdmmc.W8BIT`, not supported yet #### Parameters SD SPI Mode -- `slot` SD SPI slot, one of `sdmmc.HSPI` or `sdmmc.VSPI` +- `slot` SD SPI slot, one of `sdmmc.SPI2` or `sdmmc.SPI3` (on ESP32 the names`sdmmc.HSPI` or `sdmmc.VSPI` are still available, but deprecated) - `cfg` mandatory table containing slot configuration: - `sck_pin` SPI SCK pin, mandatory - `mosi_pin`, SPI MOSI pin, mandatory @@ -128,12 +128,10 @@ Table containing the card's OCR, CID, CSD, SCR, and RCA with elements: Mount filesystem on SD card. #### Syntax -`card:mount(ldrv[, partition])` +`card:mount(ldrv)` #### Parameters - `ldrv` name of logical drive, "/SD0", "/SD1", etc. -- `partition` the partition number, default is 0, meaning the first available - FAT partition. #### Returns `true` if successful, `false` otherwise diff --git a/sdk/esp32-esp-idf b/sdk/esp32-esp-idf index 3572900934..5181de8ac5 160000 --- a/sdk/esp32-esp-idf +++ b/sdk/esp32-esp-idf @@ -1 +1 @@ -Subproject commit 357290093430e41e7e3338227a61ef5162f2deed +Subproject commit 5181de8ac5ec5e18f04f634da8ce173b7ef5ab73