Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for Arduino v3 / esp-idf v5 2nd batch #19265

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ TasmotaSerial *tms_obj_list[16];
#ifdef ESP32

#include "driver/uart.h"
#include "driver/gpio.h"
#include "esp_rom_gpio.h"

static uint32_t tasmota_serial_uart_bitmap = 0; // Assigned UARTs

Expand Down Expand Up @@ -466,6 +468,7 @@ size_t TasmotaSerial::write(uint8_t b) {
return size;
}

#ifdef ESP8266
void IRAM_ATTR TasmotaSerial::rxRead(void) {
if (!m_nwmode) {
uint32_t start = ESP.getCycleCount();
Expand Down Expand Up @@ -586,3 +589,4 @@ void IRAM_ATTR TasmotaSerial::rxRead(void) {
}
}
}
#endif // ESP8266
2 changes: 1 addition & 1 deletion lib/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ uint8_t ledcReadResolution(uint8_t chan);
// was not yet attached.
//
// Returns: hardware channel number, or -1 if it failed
int analogAttach(uint32_t pin, bool output_invert = false); // returns the ledc channel, or -1 if failed. This is implicitly called by analogWrite if the channel was not already allocated
int32_t analogAttach(uint32_t pin, bool output_invert = false); // returns the ledc channel, or -1 if failed. This is implicitly called by analogWrite if the channel was not already allocated

// change both freq and range
// `0`: set to global value
Expand Down
20 changes: 10 additions & 10 deletions lib/libesp32/berry_mapping/src/be_cb_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_D
* We allow 4 parameters, or 3 if method (first arg is `self`)
* This could be extended if needed
\*********************************************************************************************/
typedef int32_t (*berry_callback_t)(int32_t v0, int32_t v1, int32_t v2, int32_t v3);
static int32_t call_berry_cb(int32_t num, int32_t v0, int32_t v1, int32_t v2, int32_t v3);
typedef int (*berry_callback_t)(int v0, int v1, int v2, int v3);
static int call_berry_cb(int num, int v0, int v1, int v2, int v3);

#define BERRY_CB(n) int32_t berry_cb_##n(int32_t v0, int32_t v1, int32_t v2, int32_t v3) { return call_berry_cb(n, v0, v1, v2, v3); }
#define BERRY_CB(n) int berry_cb_##n(int v0, int v1, int v2, int v3) { return call_berry_cb(n, v0, v1, v2, v3); }
// list the callbacks
BERRY_CB(0);
BERRY_CB(1);
Expand Down Expand Up @@ -85,7 +85,7 @@ typedef struct be_callback_handler_list_t {

static be_callback_hook be_cb_hooks[BE_MAX_CB] = {0};

static int32_t be_cb_gen_cb(bvm *vm);
static int be_cb_gen_cb(bvm *vm);
static be_callback_handler_list_t be_callback_default_gen_cb = {
NULL,
be_const_func(&be_cb_gen_cb),
Expand All @@ -102,7 +102,7 @@ static be_callback_handler_list_t *be_callback_handler_list_head = &be_callback_
*
* arg1: function (or closure)
\*********************************************************************************************/
static int32_t be_cb_add_handler(bvm *vm) {
static int be_cb_add_handler(bvm *vm) {
int32_t top = be_top(vm);
if (top >= 1 && be_isfunction(vm, 1)) {
bvalue *v = be_indexof(vm, 1);
Expand All @@ -129,7 +129,7 @@ static int32_t be_cb_add_handler(bvm *vm) {
*
* No args
\*********************************************************************************************/
static int32_t be_cb_list_handlers(bvm *vm) {
static int be_cb_list_handlers(bvm *vm) {
be_newobject(vm, "list");
for (be_callback_handler_list_t *elt = be_callback_handler_list_head; elt != NULL; elt = elt->next) {
if (elt->vm == vm) { /* on purpose don't show the default handler, just pretend it's not there since it's default */
Expand All @@ -153,7 +153,7 @@ static int32_t be_cb_list_handlers(bvm *vm) {
* arg2: type name for callback (optional)
* argN: any other callback specific arguments (unlimited number, passed as-is)
\*********************************************************************************************/
static int32_t be_cb_make_cb(bvm *vm) {
static int be_cb_make_cb(bvm *vm) {
int32_t argc = be_top(vm);
if (argc >= 1 && be_isfunction(vm, 1)) {

Expand Down Expand Up @@ -187,7 +187,7 @@ static int32_t be_cb_make_cb(bvm *vm) {
*
* arg1: function (or closure)
\*********************************************************************************************/
static int32_t be_cb_gen_cb(bvm *vm) {
static int be_cb_gen_cb(bvm *vm) {
int32_t top = be_top(vm);
// tasmota_log_C(LOG_LEVEL_DEBUG, "BRY: gen_cb() called");
if (top >= 1 && be_isfunction(vm, 1)) {
Expand Down Expand Up @@ -217,7 +217,7 @@ static int32_t be_cb_gen_cb(bvm *vm) {
* `get_cb_list`: Return the list of callbacks for this vm
*
\*********************************************************************************************/
static int32_t be_cb_get_cb_list(bvm *vm) {
static int be_cb_get_cb_list(bvm *vm) {
be_newobject(vm, "list");
for (uint32_t i=0; i < BE_MAX_CB; i++) {
if (be_cb_hooks[i].vm) {
Expand All @@ -242,7 +242,7 @@ static int32_t be_cb_get_cb_list(bvm *vm) {
* We allow 4 parameters, or 3 if method (first arg is `self`)
* This could be extended if needed
\*********************************************************************************************/
static int32_t call_berry_cb(int32_t num, int32_t v0, int32_t v1, int32_t v2, int32_t v3) {
static int call_berry_cb(int num, int v0, int v1, int v2, int v3) {
// call berry cb dispatcher
int32_t ret = 0;
// retrieve vm and function
Expand Down
6 changes: 6 additions & 0 deletions lib/libesp32/berry_matter/src/be_matter_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static uint8_t ip_bytes[16] = {};
extern "C" const void* matter_get_ip_bytes(const char* ip_str, size_t* ret_len) {
IPAddress ip;
if (ip.fromString(ip_str)) {
#ifdef USE_IPV6
if (ip.isV4()) {
uint32_t ip_32 = ip;
memcpy(ip_bytes, &ip_32, 4);
Expand All @@ -39,6 +40,11 @@ extern "C" const void* matter_get_ip_bytes(const char* ip_str, size_t* ret_len)
memcpy(ip_bytes, ip.raw6(), 16);
*ret_len = 16;
}
#else
uint32_t ip_32 = ip;
memcpy(ip_bytes, &ip_32, 4);
*ret_len = 4;
#endif
return ip_bytes;
} else {
*ret_len = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/libesp32/berry_matter/src/be_matter_qrcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

// `matter.QRCode.encode_str(content:string) -> map`
//
int32_t qr_encode_str(bvm *vm) {
int qr_encode_str(bvm *vm) {
int32_t argc = be_top(vm);
if (argc >= 1 && be_isstring(vm, 1)) {
const char * data_str = be_tostring(vm, 1);
Expand Down
8 changes: 7 additions & 1 deletion lib/libesp32/berry_tasmota/include/be_ctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ typedef struct be_ctypes_classes_t {
const be_ctypes_class_t * classes;
} be_ctypes_classes_t;

BE_EXPORT_VARIABLE const bclass be_class_ctypes_bytes;
#ifdef __cplusplus
extern "C" {
#endif
extern const bclass be_class_ctypes_bytes;
#ifdef __cplusplus
}
#endif

static void ctypes_register_class(bvm *vm, const bclass * ctypes_class) {
be_pushntvclass(vm, ctypes_class);
Expand Down
2 changes: 2 additions & 0 deletions tasmota/tasmota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ void setup(void) {

#ifdef CONFIG_IDF_TARGET_ESP32
// restore GPIO16/17 if no PSRAM is found
#if ESP_IDF_VERSION_MAJOR < 5 // TODO for esp-idf 5
if (!FoundPSRAM()) {
// test if the CPU is not pico
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
Expand All @@ -415,6 +416,7 @@ void setup(void) {
gpio_reset_pin(GPIO_NUM_17);
}
}
#endif
#endif // CONFIG_IDF_TARGET_ESP32
#endif // ESP32

Expand Down
2 changes: 1 addition & 1 deletion tasmota/tasmota_support/support_crash_recorder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void CmndWDT(void)
{
volatile uint32_t dummy = 0;
while (1) {
dummy++;
dummy = dummy + 1;
}
}

Expand Down
18 changes: 15 additions & 3 deletions tasmota/tasmota_support/support_esp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ String GetCodeCores(void) {

#ifdef ESP32

#include "bootloader_flash.h"
#include "soc/soc.h"
#include "soc/spi_reg.h"
// ESP32_ARCH contains the name of the architecture (used by autoconf)
Expand Down Expand Up @@ -256,6 +255,10 @@ String GetCodeCores(void) {
#include "rom/rtc.h"
#endif

#if ESP_IDF_VERSION_MAJOR >= 5
#include "esp_chip_info.h"
#endif

// Set the Stacksize for Arduino core. Default is 8192, some builds may need a bigger one
size_t getArduinoLoopTaskStackSize(void) {
return SET_ESP32_STACK_SIZE;
Expand Down Expand Up @@ -724,7 +727,12 @@ uint8_t* FlashDirectAccess(void) {
}

extern "C" {
bool esp_spiram_is_initialized(void);
#if ESP_IDF_VERSION_MAJOR >= 5
// bool IRAM_ATTR __attribute__((pure)) esp_psram_is_initialized(void)
bool esp_psram_is_initialized(void);
#else
bool esp_spiram_is_initialized(void);
#endif
}

// this function is a replacement for `psramFound()`.
Expand All @@ -734,7 +742,11 @@ bool FoundPSRAM(void) {
#if CONFIG_IDF_TARGET_ESP32C3
return psramFound();
#else
return psramFound() && esp_spiram_is_initialized();
#if ESP_IDF_VERSION_MAJOR >= 5
return psramFound() && esp_psram_is_initialized();
#else
return psramFound() && esp_spiram_is_initialized();
#endif
#endif
}

Expand Down
19 changes: 18 additions & 1 deletion tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_flash.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@
#ifdef USE_BERRY

#include <berry.h>
#include "esp_spi_flash.h"

#include "esp_idf_version.h"
#if ESP_IDF_VERSION_MAJOR >= 5
// esp_spi_flash.h is deprecated, please use spi_flash_mmap.h instead
#include "spi_flash_mmap.h"
#else
#include "esp_spi_flash.h"
#endif

size_t FlashWriteSubSector(uint32_t address_start, const uint8_t *data, size_t size) {
#if ESP_IDF_VERSION_MAJOR < 5
uint32_t addr = address_start;
size_t size_left = size;
size_t current_offset = 0;
Expand Down Expand Up @@ -59,6 +67,9 @@ size_t FlashWriteSubSector(uint32_t address_start, const uint8_t *data, size_t s
}

return current_offset;
#else
// TODO ESPIDF 5
#endif
}

/*********************************************************************************************\
Expand All @@ -73,6 +84,7 @@ extern "C" {
// If length is not specified, it is full block 4KB
int32_t p_flash_read(struct bvm *vm);
int32_t p_flash_read(struct bvm *vm) {
#if ESP_IDF_VERSION_MAJOR < 5
int32_t argc = be_top(vm); // Get the number of arguments
if (argc >= 1 && be_isint(vm, 1) &&
(argc < 2 || be_isint(vm, 2)) ) { // optional second argument must be int
Expand All @@ -91,13 +103,15 @@ extern "C" {
be_pushbytes(vm, buf.get(), length);
be_return(vm);
}
#endif
be_raise(vm, kTypeError, nullptr);
}

// Berry: `flash.write(address:int, content:bytes() [, no_erase:bool]) -> nil`
// if `no_erase` is true, just call spi_flash_write
int32_t p_flash_write(struct bvm *vm);
int32_t p_flash_write(struct bvm *vm) {
#if ESP_IDF_VERSION_MAJOR < 5
int32_t argc = be_top(vm); // Get the number of arguments
if (argc >= 2 && be_isint(vm, 1) && be_isinstance(vm, 2)) {
be_getglobal(vm, "bytes"); /* get the bytes class */ /* TODO eventually replace with be_getbuiltin */
Expand Down Expand Up @@ -126,6 +140,7 @@ extern "C" {
}
}
}
#endif
be_raise(vm, kTypeError, nullptr);
}

Expand All @@ -134,6 +149,7 @@ extern "C" {
// Address and length must be 4KB aligned
int32_t p_flash_erase(struct bvm *vm);
int32_t p_flash_erase(struct bvm *vm) {
#if ESP_IDF_VERSION_MAJOR < 5
int32_t argc = be_top(vm); // Get the number of arguments
if (argc >= 2 && be_isint(vm, 1) && be_isint(vm, 2)) {
int32_t address = be_toint(vm, 1);
Expand All @@ -147,6 +163,7 @@ extern "C" {
esp_err_t ret = spi_flash_erase_range(address, length);
be_return_nil(vm);
}
#endif
be_raise(vm, kTypeError, nullptr);
}

Expand Down
4 changes: 4 additions & 0 deletions tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_webclient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ public:
size_t write(const uint8_t *buffer, size_t size) override {
// AddLog(LOG_LEVEL_INFO, "FLASH: addr=%p hex=%*_H size=%i", addr_start + offset, 32, buffer, size);
if (size > 0) {
#if ESP_IDF_VERSION_MAJOR < 5 // TODO later
esp_err_t ret = spi_flash_write(addr_start + offset, buffer, size);
if (ret != ESP_OK) { return 0; } // error
offset += size;
Expand All @@ -590,6 +591,7 @@ public:
if (((offset - size) / STREAM_FLASH_PROGRESS_THRESHOLD) != (offset / STREAM_FLASH_PROGRESS_THRESHOLD)) {
AddLog(LOG_LEVEL_DEBUG, D_LOG_UPLOAD "Progress %d kB", offset / 1024);
}
#endif
}
return size;
}
Expand All @@ -611,6 +613,7 @@ protected:
extern "C" {
int32_t wc_writeflash(struct bvm *vm);
int32_t wc_writeflash(struct bvm *vm) {
#if ESP_IDF_VERSION_MAJOR < 5
int32_t argc = be_top(vm);
if (argc >= 2 && be_isint(vm, 2)) {
HTTPClientLight * cl = wc_getclient(vm);
Expand Down Expand Up @@ -650,6 +653,7 @@ extern "C" {
be_pushint(vm, written);
be_return(vm); /* return code */
}
#endif
be_raise(vm, kTypeError, nullptr);
}
}
Expand Down
6 changes: 6 additions & 0 deletions tasmota/tasmota_xdrv_driver/xdrv_68_zerocrossDimmer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

#define XDRV_68 68


#if !defined(ESP32) || (ESP_IDF_VERSION_MAJOR < 5) // temporarily disable for IDF 5.0

static const uint8_t TRIGGER_PERIOD = 75;

#define ZCDIMMERSET_SHOW 1
Expand Down Expand Up @@ -298,4 +301,7 @@ bool Xdrv68(uint32_t function)
}
return result;
}

#endif // !enabled(ESP32) || (ESP_IDF_VERSION_MAJOR < 5)

#endif // USE_AC_ZERO_CROSS_DIMMER
11 changes: 11 additions & 0 deletions tasmota/tasmota_xsns_sensor/xsns_02_analog.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@

#define XSNS_02 2

#ifdef ESP32
#if ESP_IDF_VERSION_MAJOR >= 5
#include "esp32-hal-adc.h"
#endif
#endif

#ifdef ESP8266
#define ANALOG_RESOLUTION 10 // 12 = 4095, 11 = 2047, 10 = 1023
#define ANALOG_RANGE 1023 // 4095 = 12, 2047 = 11, 1023 = 10
Expand Down Expand Up @@ -176,6 +182,11 @@ bool adcAttachPin(uint8_t pin) {
return (ADC0_PIN == pin);
}
#endif
#if defined(ESP32) && (ESP_IDF_VERSION_MAJOR >= 5)
bool adcAttachPin(uint8_t pin) {
return true; // TODO - no more needed?
}
#endif

void AdcSaveSettings(uint32_t idx) {
char parameters[32];
Expand Down