Remove non IDF5 code

This commit is contained in:
Theo Arends 2024-05-15 16:45:42 +02:00
parent 1d7f3e8f07
commit ac06195907
10 changed files with 23 additions and 118 deletions

View File

@ -189,9 +189,9 @@ bool RtcRebootValid(void) {
extern "C" { extern "C" {
#include "spi_flash.h" #include "spi_flash.h"
#if ESP_IDF_VERSION_MAJOR >= 5 #ifdef ESP32
#include "spi_flash_mmap.h" #include "spi_flash_mmap.h"
#endif #endif // ESP32
} }
#ifdef ESP8266 #ifdef ESP8266

View File

@ -27,14 +27,10 @@ bool I2cBegin(int sda, int scl, uint32_t frequency) {
Wire.begin(sda, scl); Wire.begin(sda, scl);
#endif #endif
#ifdef ESP32 #ifdef ESP32
#if ESP_IDF_VERSION_MAJOR > 3 // Core 2.x uses a different I2C library
static bool reinit = false; static bool reinit = false;
if (reinit) { Wire.end(); } if (reinit) { Wire.end(); }
#endif // ESP_IDF_VERSION_MAJOR > 3
result = Wire.begin(sda, scl, frequency); result = Wire.begin(sda, scl, frequency);
#if ESP_IDF_VERSION_MAJOR > 3 // Core 2.x uses a different I2C library
reinit = result; reinit = result;
#endif // ESP_IDF_VERSION_MAJOR > 3
#endif #endif
// AddLog(LOG_LEVEL_DEBUG, PSTR("I2C: Bus1 %d"), result); // AddLog(LOG_LEVEL_DEBUG, PSTR("I2C: Bus1 %d"), result);
return result; return result;

View File

@ -2674,11 +2674,9 @@ void CmndWifi(void) {
break; break;
} }
#ifdef ESP32 #ifdef ESP32
#if ESP_IDF_VERSION_MAJOR >= 5
case 6: // Wifi 6 = BGNAX case 6: // Wifi 6 = BGNAX
option = 4; option = 4;
#endif // ESP_IDF_VERSION_MAJOR #endif // ESP32
#endif // ESP32/ESP8266
case 4: // Wifi 4 = BGN case 4: // Wifi 4 = BGN
case 3: // Wifi 3 = BG case 3: // Wifi 3 = BG
case 2: // Wifi 2 = B case 2: // Wifi 2 = B

View File

@ -162,14 +162,8 @@ void CrashDumpClear(void)
// esp_err_t IRAM_ATTR esp_backtrace_print(int depth) // esp_err_t IRAM_ATTR esp_backtrace_print(int depth)
#include "freertos/xtensa_api.h" #include "freertos/xtensa_api.h"
#if ESP_IDF_VERSION_MAJOR >= 5
#include "esp_debug_helpers.h" #include "esp_debug_helpers.h"
#include "esp_cpu_utils.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"
#endif
extern "C" { extern "C" {
// esp-idf 3.x // esp-idf 3.x
void __real_panicHandler(XtExcFrame *frame); void __real_panicHandler(XtExcFrame *frame);

View File

@ -577,12 +577,8 @@ uint32_t ESP_getMaxAllocPsram(void) {
} }
extern "C" { extern "C" {
#if ESP_IDF_VERSION_MAJOR >= 5
// bool IRAM_ATTR __attribute__((pure)) esp_psram_is_initialized(void) // bool IRAM_ATTR __attribute__((pure)) esp_psram_is_initialized(void)
bool 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()`. // this function is a replacement for `psramFound()`.
@ -748,11 +744,7 @@ typedef struct {
bool rev3 = (chip_revision >= 300); bool rev3 = (chip_revision >= 300);
// bool single_core = (1 == ESP.getChipCores()); // bool single_core = (1 == ESP.getChipCores());
bool single_core = (1 == chip_info.cores); bool single_core = (1 == chip_info.cores);
uint32_t pkg_version = bootloader_common_get_chip_ver_pkg();
uint32_t pkg_version = 0;
#if (ESP_IDF_VERSION_MAJOR >= 5)
pkg_version = bootloader_common_get_chip_ver_pkg();
#endif
switch (chip_model) { switch (chip_model) {
case 0: case 0:
@ -931,11 +923,7 @@ String GetDeviceHardwareRevision(void) {
esp_chip_info_t chip_info; esp_chip_info_t chip_info;
esp_chip_info(&chip_info); esp_chip_info(&chip_info);
#if ESP_IDF_VERSION_MAJOR >= 5
uint32_t chip_revision = chip_info.revision; // 16-bit chip revision number (in format MXX; where M - wafer major version, XX - wafer minor version) uint32_t chip_revision = chip_info.revision; // 16-bit chip revision number (in format MXX; where M - wafer major version, XX - wafer minor version)
#else
uint32_t chip_revision = chip_info.full_revision; // 16-bit chip revision number (in format MXX; where M - wafer major version, XX - wafer minor version)
#endif
char revision[16]; char revision[16];
snprintf_P(revision, sizeof(revision), PSTR(" v%d.%d"), chip_revision / 100, chip_revision % 100); snprintf_P(revision, sizeof(revision), PSTR(" v%d.%d"), chip_revision / 100, chip_revision % 100);
result += revision; // ESP32-C3 v0.3 result += revision; // ESP32-C3 v0.3

View File

@ -42,9 +42,9 @@ const uint8_t WIFI_RETRY_OFFSET_SEC = WIFI_RETRY_SECONDS; // seconds
#include <ESP8266WiFi.h> // Wifi, MQTT, Ota, WifiManager #include <ESP8266WiFi.h> // Wifi, MQTT, Ota, WifiManager
#include "lwip/dns.h" #include "lwip/dns.h"
#if ESP_IDF_VERSION_MAJOR >= 5 #ifdef ESP32
#include "esp_netif.h" #include "esp_netif.h"
#endif #endif // ESP32
int WifiGetRssiAsQuality(int rssi) { int WifiGetRssiAsQuality(int rssi) {
int quality = 0; int quality = 0;

View File

@ -31,16 +31,16 @@ struct MY92X1 {
uint8_t model = 0; uint8_t model = 0;
} My92x1; } My92x1;
#if ESP_IDF_VERSION_MAJOR >= 5 #ifdef ESP32
#include "rom/ets_sys.h" #include "rom/ets_sys.h"
#ifndef os_delay_us #ifndef os_delay_us
#define os_delay_us ets_delay_us #define os_delay_us ets_delay_us
#endif //os_delay_us #endif //os_delay_us
#else #else // ESP8266
extern "C" { extern "C" {
void os_delay_us(unsigned int); void os_delay_us(unsigned int);
} }
#endif #endif // ESP8266
void LightDiPulse(uint8_t times) void LightDiPulse(uint8_t times)
{ {

View File

@ -27,10 +27,8 @@
#define XSNS_02 2 #define XSNS_02 2
#ifdef ESP32 #ifdef ESP32
#if ESP_IDF_VERSION_MAJOR >= 5
#include "esp32-hal-adc.h" #include "esp32-hal-adc.h"
#endif #endif
#endif
#ifdef ESP8266 #ifdef ESP8266
#define ANALOG_RESOLUTION 10 // 12 = 4095, 11 = 2047, 10 = 1023 #define ANALOG_RESOLUTION 10 // 12 = 4095, 11 = 2047, 10 = 1023
@ -179,16 +177,13 @@ struct {
int indexOfPointer = -1; int indexOfPointer = -1;
} Adc[MAX_ADCS]; } Adc[MAX_ADCS];
bool adcAttachPin(uint8_t pin) {
#ifdef ESP8266 #ifdef ESP8266
bool adcAttachPin(uint8_t pin) {
return (ADC0_PIN == pin); return (ADC0_PIN == pin);
#else // ESP32
return true;
#endif // ESP32
} }
#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) { void AdcSaveSettings(uint32_t idx) {
char parameters[32]; char parameters[32];
@ -310,9 +305,6 @@ void AdcInit(void) {
if (Adcs.present) { if (Adcs.present) {
#ifdef ESP32 #ifdef ESP32
#if ESP_IDF_VERSION_MAJOR < 5
analogSetClockDiv(1); // Default 1
#endif
#if CONFIG_IDF_TARGET_ESP32 #if CONFIG_IDF_TARGET_ESP32
analogSetWidth(ANALOG_RESOLUTION); // Default 12 bits (0 - 4095) analogSetWidth(ANALOG_RESOLUTION); // Default 12 bits (0 - 4095)
#endif // CONFIG_IDF_TARGET_ESP32 #endif // CONFIG_IDF_TARGET_ESP32

View File

@ -1,5 +1,5 @@
/* /*
xsns_127_esp32_sensors.ino - ESP32 Temperature and Hall Effect sensor for Tasmota xsns_127_esp32_sensors.ino - ESP32 Temperature sensor for Tasmota
Copyright (C) 2021 Theo Arends Copyright (C) 2021 Theo Arends
@ -20,39 +20,14 @@
#ifdef ESP32 #ifdef ESP32
#ifdef USE_ESP32_SENSORS #ifdef USE_ESP32_SENSORS
/*********************************************************************************************\ /*********************************************************************************************\
* ESP32 CPU Temperature and optional Hall Effect sensor * ESP32 CPU Temperature sensor
* *
* To allow for not updating the global temperature by the ESP32 temperature sensor this * To allow for not updating the global temperature by the ESP32 temperature sensor this
* driver needs to be the highest numbered driver (currently 127) * driver needs to be the highest numbered driver (currently 127)
*
* ESP32 internal Hall Effect sensor connected to both GPIO36 and GPIO39
* To enable set
* GPIO36 as HallEffect 1
* GPIO39 as HallEffect 2
\*********************************************************************************************/ \*********************************************************************************************/
#define XSNS_127 127 #define XSNS_127 127
#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
struct {
bool present = false;
} HEData;
void Esp32SensorInit(void) {
if (PinUsed(GPIO_HALLEFFECT) && PinUsed(GPIO_HALLEFFECT, 1)) {
if (((36 == Pin(GPIO_HALLEFFECT)) && (39 == Pin(GPIO_HALLEFFECT, 1))) ||
((39 == Pin(GPIO_HALLEFFECT)) && (36 == Pin(GPIO_HALLEFFECT, 1)))) {
HEData.present = true;
hallRead();
}
}
}
#endif // CONFIG_IDF_TARGET_ESP32 && (ESP_IDF_VERSION_MAJOR < 5)
void Esp32SensorShow(bool json) { void Esp32SensorShow(bool json) {
bool json_end = false; bool json_end = false;
@ -84,39 +59,6 @@ void Esp32SensorShow(bool json) {
} }
} }
#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++) {
value += hallRead();
}
value /= HALLEFFECT_SAMPLE_COUNT;
if (json) {
if (!json_end) {
ResponseAppend_P(PSTR(",\"ESP32\":{"));
} else {
ResponseAppend_P(PSTR(","));
}
ResponseAppend_P(PSTR("\"" D_JSON_HALLEFFECT "\":%d"), value);
json_end = true;
#ifdef USE_DOMOTICZ
// Instead of below code use a rule like 'on tele-esp32#halleffect do dzsend1 9988,%value% endon'
// where 9988 is the domoticz sensor Idx
// if (0 == TasmotaGlobal.tele_period) {
// DomoticzSensor(DZ_COUNT, value);
// }
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {
WSContentSend_P(HTTP_SNS_HALL_EFFECT, "ESP32", value);
#endif // USE_WEBSERVER
}
}
#endif // CONFIG_IDF_TARGET_ESP32 && (ESP_IDF_VERSION_MAJOR < 5)
if (json_end) { if (json_end) {
ResponseJsonEnd(); ResponseJsonEnd();
} }
@ -138,11 +80,6 @@ bool Xsns127(uint32_t function) {
Esp32SensorShow(0); Esp32SensorShow(0);
break; break;
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
#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 && (ESP_IDF_VERSION_MAJOR < 5)
} }
return result; return result;
} }

View File

@ -152,9 +152,9 @@ void ChirpResetAll(void) {
/********************************************************************************************/ /********************************************************************************************/
void ChirpClockSet() { // set I2C for this slow sensor void ChirpClockSet() { // set I2C for this slow sensor
#if ESP_IDF_VERSION_MAJOR < 5 // setClockStretchLimit was removed #ifdef ESP8266
Wire.setClockStretchLimit(4000); Wire.setClockStretchLimit(4000);
#endif #endif // ESP8266
Wire.setClock(50000); Wire.setClock(50000);
} }