Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev-esp32' into ble
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsg committed Jan 31, 2024
2 parents 55ab2fa + 3cc1d48 commit 8cafd55
Show file tree
Hide file tree
Showing 51 changed files with 326 additions and 643 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ components/*/.output/
tools/toolchains
.ccache
bin
version.txt
managed_components/
dependencies.lock

#ignore Eclipse project files
.cproject
Expand Down
14 changes: 9 additions & 5 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# .readthedocs.yaml
# Read the Docs configuration file
# Read the Docs configuration file for MkDocs projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"

mkdocs:
configuration: mkdocs.yml

# Optionally set the version of Python and requirements required to build your docs
# Optionally declare the Python requirements required to build your docs
python:
version: "3.7"
install:
- requirements: docs/requirements.txt
- requirements: docs/requirements.txt
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"
PRIV_REQUIRES "nvs_flash" "spiffs" "esp_netif" "driver"
LDFRAGMENTS "nodemcu.lf"
)
4 changes: 2 additions & 2 deletions components/base_nodemcu/user_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}


Expand Down
3 changes: 3 additions & 0 deletions components/driver_can/CAN.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <math.h>
Expand Down
1 change: 1 addition & 0 deletions components/driver_can/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ if(IDF_TARGET STREQUAL "esp32")
idf_component_register(
SRCS "CAN.c"
INCLUDE_DIRS "include"
PRIV_REQUIRES "driver" "esp_rom"
)

endif()
3 changes: 2 additions & 1 deletion components/driver_i2c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
idf_component_register(
SRCS "i2c_sw_master.c"
INCLUDE_DIRS "include"
REQUIRES "esp32"
REQUIRES "esp_rom"
PRIV_REQUIRES "driver"
)
4 changes: 2 additions & 2 deletions components/driver_i2c/include/driver/i2c_sw_master.h
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion components/lua/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 1 addition & 3 deletions components/lua/lua-5.1/lobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <limits.h>
#endif
const TValue luaO_nilobject_ = {LUA_TVALUE_NIL};
Expand Down
8 changes: 4 additions & 4 deletions components/lua/lua-5.3/lnodemcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand All @@ -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;
}
Expand Down
11 changes: 8 additions & 3 deletions components/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,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
Expand All @@ -82,20 +83,24 @@ idf_component_register(
"base_nodemcu"
"bt"
"driver_can"
"esp_eth"
"esp_http_client"
"fatfs"
"esp_http_server"
"esp_hw_support"
"fatfs"
"libsodium"
"lua"
"mbedtls"
"mqtt"
"platform"
"qrcodegen"
"sdmmc"
"spi_flash"
"sjson"
"soc"
"u8g2"
"ucg"
"vfs"
)

# Match up all the module source files with their corresponding Kconfig
Expand Down
6 changes: 3 additions & 3 deletions components/modules/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/modules/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
35 changes: 16 additions & 19 deletions components/modules/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,25 @@
#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);

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;

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),
Expand Down Expand Up @@ -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 );
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions components/modules/heaptrace.c
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
11 changes: 6 additions & 5 deletions components/modules/i2c_hw_master.c
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 8cafd55

Please sign in to comment.