Skip to content

Commit

Permalink
Prepare for Arduino v3 / esp-idf v5 (#19264)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hadinger authored Aug 5, 2023
1 parent ab9a519 commit 5c8c7cd
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- Zigbee decode Aqara 0000/FF01 attribute 03 as Temperature (#19210)
- Berry bytes `get` and `set` work for 3 bytes values (#19225)
- Matter support for fabric_filtered request (for Google compatibility) (#19249)
- Prepare for Arduino v3 / esp-idf v5

### Breaking Changed

Expand Down
12 changes: 0 additions & 12 deletions lib/libesp32/ESP32-to-ESP8266-compat/src/ESP32Wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,6 @@ void WiFiClass32::scrubDNS(void) {
} else {
dns_setserver(i, IP4_ADDR_ANY);
}
#else // USE_IPV6
uint32_t ip_dns = ip_addr_get_ip4_u32(dns_getserver(i));
// Step 1. save valid values from DNS
if (has_v4 && (uint32_t)ip_dns != 0) {
ip_addr_set_ip4_u32_val(dns_save4[i], ip_dns);
}
// Step 2. scrub addresses not supported
if (!has_v4) {
ip_addr_set_ip4_u32_val(dns_save4[i], 0L);
}
// Step 3. restore saved value
dns_setserver(i, &dns_save4[i]);
#endif // USE_IPV6
}
// AddLog(LOG_LEVEL_DEBUG, "IP>: DNS: from(%s %s) to (%s %s) has4/6:%i-%i", dns_entry0.c_str(), dns_entry1.c_str(), IPAddress(dns_getserver(0)).toString().c_str(), IPAddress(dns_getserver(1)).toString().c_str(), has_v4, has_v6);
Expand Down
7 changes: 6 additions & 1 deletion lib/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#ifdef ESP32

#include "Arduino.h"
#include "esp_idf_version.h"
#include "esp8266toEsp32.h"
#include "driver/ledc.h"

Expand All @@ -33,7 +34,11 @@ enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_D
#else
#define LEDC_DEFAULT_CLK LEDC_AUTO_CLK
#endif
#define LEDC_MAX_BIT_WIDTH SOC_LEDC_TIMER_BIT_WIDE_NUM
#if (ESP_IDF_VERSION_MAJOR >= 5)
#define LEDC_MAX_BIT_WIDTH SOC_LEDC_TIMER_BIT_WIDTH
#else
#define LEDC_MAX_BIT_WIDTH SOC_LEDC_TIMER_BIT_WIDE_NUM
#endif

// define our limits to ease any change from esp-idf
#define MAX_TIMERS LEDC_TIMER_MAX // 4 timers for all ESP32 variants
Expand Down
3 changes: 3 additions & 0 deletions tasmota/tasmota_support/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ bool RtcRebootValid(void) {

extern "C" {
#include "spi_flash.h"
#if ESP_IDF_VERSION_MAJOR >= 5
#include "spi_flash_mmap.h"
#endif
}

#ifdef ESP8266
Expand Down
5 changes: 4 additions & 1 deletion tasmota/tasmota_support/support_crash_recorder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ void CrashDumpClear(void)
// esp_err_t IRAM_ATTR esp_backtrace_print(int depth)

#include "freertos/xtensa_api.h"
#if ESP_IDF_VERSION_MAJOR >= 4
#if ESP_IDF_VERSION_MAJOR >= 5
#include "esp_debug_helpers.h"
#include "esp_cpu_utils.h"
#elif ESP_IDF_VERSION_MAJOR >= 4
#include "esp_debug_helpers.h"
#else // IDF 3.x
#include "esp_panic.h"
Expand Down
15 changes: 14 additions & 1 deletion tasmota/tasmota_support/support_esp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ String GetCodeCores(void) {

// See libraries\ESP32\examples\ResetReason.ino
#if ESP_IDF_VERSION_MAJOR > 3 // IDF 4+
#include "esp_chip_info.h"
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/rtc.h"
#elif CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2
Expand Down Expand Up @@ -393,7 +394,12 @@ void NvsInfo(void) {

// See Esp.cpp
#include "Esp.h"
#include "esp_spi_flash.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
#include <memory>
#include <soc/soc.h>
#include <soc/efuse_reg.h>
Expand Down Expand Up @@ -423,6 +429,9 @@ extern "C" {
#include "rom/spi_flash.h"
#define ESP_FLASH_IMAGE_BASE 0x1000
#endif
#if ESP_IDF_VERSION_MAJOR >= 5
#include "bootloader_common.h"
#endif

uint32_t EspProgramSize(const char *label) {
const esp_partition_t *part = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, label);
Expand Down Expand Up @@ -874,8 +883,12 @@ typedef struct {
pkg_version += ((word3 >> 2) & 0x1) << 3
return pkg_version
*/
#if (ESP_IDF_VERSION_MAJOR >= 5)
uint32_t pkg_version = bootloader_common_get_chip_ver_pkg();
#else
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
uint32_t pkg_version = chip_ver & 0x7;
#endif

// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("HDW: ESP32 Model %d, Revision %d, Core %d, Package %d"), chip_info.model, chip_revision, chip_info.cores, chip_ver);

Expand Down
2 changes: 2 additions & 0 deletions tasmota/tasmota_support/support_tasmota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,8 @@ void TasConsoleInput(void) {
//
// This patched version of pinMode forces a full GPIO reset before setting new mode
//
#include "driver/gpio.h"

extern "C" void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode);

extern "C" void ARDUINO_ISR_ATTR pinMode(uint8_t pin, uint8_t mode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,23 @@ public:
state = AsyncTCPState::INPROGRESS; // reset state
}

#ifdef USE_IPV6
if (ip.type() == IPv6) {
struct sockaddr_in6 *tmpaddr = (struct sockaddr_in6 *)&serveraddr;
sockfd = socket(AF_INET6, SOCK_STREAM, 0);
tmpaddr->sin6_family = AF_INET6;
memcpy(tmpaddr->sin6_addr.un.u8_addr, &ip[0], 16);
tmpaddr->sin6_port = htons(port);
} else {
#endif
struct sockaddr_in *tmpaddr = (struct sockaddr_in *)&serveraddr;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
tmpaddr->sin_family = AF_INET;
tmpaddr->sin_addr.s_addr = ip;
tmpaddr->sin_port = htons(port);
#ifdef USE_IPV6
}
#endif
if (sockfd < 0) {
AddLog(LOG_LEVEL_DEBUG, "BRY: Error: socket: %d", errno);
return 0;
Expand Down Expand Up @@ -312,7 +316,7 @@ public:
local_addr = IPAddress((uint32_t)(s->sin_addr.s_addr));
// return IPAddress((uint32_t)(s->sin_addr.s_addr));
}

#ifdef USE_IPV6
// IPv6, but it might be IPv4 mapped address
if (((struct sockaddr*)&local_address)->sa_family == AF_INET6) {
struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *)&local_address;
Expand All @@ -325,6 +329,7 @@ public:
// return IPAddress(IPv6, (uint8_t*)(saddr6->sin6_addr.s6_addr));
}
}
#endif // USE_IPV6
}
}

Expand Down
8 changes: 4 additions & 4 deletions tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ void checkBeTop(void) {
* Use PSRAM if available
\*********************************************************************************************/
extern "C" {
void *berry_malloc(uint32_t size);
void *berry_malloc(size_t size);
void *berry_realloc(void *ptr, size_t size);
#ifdef USE_BERRY_PSRAM
void *berry_malloc(uint32_t size) {
void *berry_malloc(size_t size) {
return special_malloc(size);
}
void *berry_realloc(void *ptr, size_t size) {
Expand All @@ -77,7 +77,7 @@ extern "C" {
return special_calloc(num, size);
}
#else
void *berry_malloc(uint32_t size) {
void *berry_malloc(size_t size) {
return malloc(size);
}
void *berry_realloc(void *ptr, size_t size) {
Expand All @@ -89,7 +89,7 @@ extern "C" {
#endif // USE_BERRY_PSRAM


void *berry_malloc32(uint32_t size) {
void *berry_malloc32(size_t size) {
#ifdef USE_BERRY_IRAM
return special_malloc32(size);
#else
Expand Down
2 changes: 2 additions & 0 deletions tasmota/tasmota_xsns_sensor/xsns_02_analog.ino
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ void AdcInit(void) {

if (Adcs.present) {
#ifdef ESP32
#if ESP_IDF_VERSION_MAJOR < 5
analogSetClockDiv(1); // Default 1
#endif
#if CONFIG_IDF_TARGET_ESP32
analogSetWidth(ANALOG_RESOLUTION); // Default 12 bits (0 - 4095)
#endif // CONFIG_IDF_TARGET_ESP32
Expand Down
12 changes: 6 additions & 6 deletions tasmota/tasmota_xsns_sensor/xsns_127_esp32_sensors.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#define XSNS_127 127

#if CONFIG_IDF_TARGET_ESP32
#if CONFIG_IDF_TARGET_ESP32 && (ESP_IDF_VERSION_MAJOR < 5) // Hall sensor is no more supported in esp-idf 5

#define HALLEFFECT_SAMPLE_COUNT 32 // 32 takes about 12 mS at 80MHz CPU frequency

Expand All @@ -51,7 +51,7 @@ void Esp32SensorInit(void) {
}
}

#endif // CONFIG_IDF_TARGET_ESP32
#endif // CONFIG_IDF_TARGET_ESP32 && (ESP_IDF_VERSION_MAJOR < 5)

void Esp32SensorShow(bool json) {
bool json_end = false;
Expand Down Expand Up @@ -84,7 +84,7 @@ void Esp32SensorShow(bool json) {
}
}

#if CONFIG_IDF_TARGET_ESP32
#if CONFIG_IDF_TARGET_ESP32 && (ESP_IDF_VERSION_MAJOR < 5) // Hall sensor is no more supported in esp-idf 5
if (HEData.present) {
int value = 0;
for (uint32_t i = 0; i < HALLEFFECT_SAMPLE_COUNT; i++) {
Expand Down Expand Up @@ -115,7 +115,7 @@ void Esp32SensorShow(bool json) {
#endif // USE_WEBSERVER
}
}
#endif // CONFIG_IDF_TARGET_ESP32
#endif // CONFIG_IDF_TARGET_ESP32 && (ESP_IDF_VERSION_MAJOR < 5)

if (json_end) {
ResponseJsonEnd();
Expand All @@ -138,11 +138,11 @@ bool Xsns127(uint32_t function) {
Esp32SensorShow(0);
break;
#endif // USE_WEBSERVER
#if CONFIG_IDF_TARGET_ESP32
#if CONFIG_IDF_TARGET_ESP32 && (ESP_IDF_VERSION_MAJOR < 5) // Hall sensor is no more supported in esp-idf 5
case FUNC_INIT:
Esp32SensorInit();
break;
#endif // CONFIG_IDF_TARGET_ESP32
#endif // CONFIG_IDF_TARGET_ESP32 && (ESP_IDF_VERSION_MAJOR < 5)
}
return result;
}
Expand Down

0 comments on commit 5c8c7cd

Please sign in to comment.