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

This commit is contained in:
s-hadinger 2023-08-05 20:34:24 +02:00 committed by GitHub
parent e52c6105c6
commit 0b3d6fd146
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 86 additions and 18 deletions

View File

@ -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
@ -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();
@ -586,3 +589,4 @@ void IRAM_ATTR TasmotaSerial::rxRead(void) {
}
}
}
#endif // ESP8266

View File

@ -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

View File

@ -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);
@ -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),
@ -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);
@ -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 */
@ -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)) {
@ -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)) {
@ -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) {
@ -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

View File

@ -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);
@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);
@ -415,6 +416,7 @@ void setup(void) {
gpio_reset_pin(GPIO_NUM_17);
}
}
#endif
#endif // CONFIG_IDF_TARGET_ESP32
#endif // ESP32

View File

@ -30,7 +30,7 @@ void CmndWDT(void)
{
volatile uint32_t dummy = 0;
while (1) {
dummy++;
dummy = dummy + 1;
}
}

View File

@ -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)
@ -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;
@ -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()`.
@ -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
}

View File

@ -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;
@ -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
}
/*********************************************************************************************\
@ -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
@ -91,6 +103,7 @@ extern "C" {
be_pushbytes(vm, buf.get(), length);
be_return(vm);
}
#endif
be_raise(vm, kTypeError, nullptr);
}
@ -98,6 +111,7 @@ extern "C" {
// 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 */
@ -126,6 +140,7 @@ extern "C" {
}
}
}
#endif
be_raise(vm, kTypeError, nullptr);
}
@ -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);
@ -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);
}

View File

@ -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;
@ -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;
}
@ -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);
@ -650,6 +653,7 @@ extern "C" {
be_pushint(vm, written);
be_return(vm); /* return code */
}
#endif
be_raise(vm, kTypeError, nullptr);
}
}

View File

@ -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
@ -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

View File

@ -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
@ -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];