From dd877972bed558d31f9aa49397849308d2d181e4 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 21 Aug 2023 17:10:06 +0200 Subject: [PATCH] Phase 1 support C2/C6 --- .../xdrv_52_3_berry_gpio.ino | 48 +++++++++++++++++-- .../xdrv_52_3_berry_wire.ino | 2 +- tasmota/tasmota_xdrv_driver/xdrv_54_lvgl.ino | 4 +- .../tasmota_xdrv_driver/xdrv_79_esp32_ble.ino | 2 +- .../xdrv_85_esp32_ble_eq3_trv.ino | 2 +- tasmota/tasmota_xlgt_light/xlgt_02_my92x1.ino | 7 +++ .../tasmota_xnrg_energy/xnrg_23_ade7880.ino | 2 +- .../tasmota_xsns_sensor/xsns_01_counter.ino | 3 +- tasmota/tasmota_xsns_sensor/xsns_35_tx20.ino | 5 +- tasmota/tasmota_xsns_sensor/xsns_48_chirp.ino | 2 + .../xsns_52_esp32_ibeacon_ble.ino | 2 +- .../tasmota_xsns_sensor/xsns_62_esp32_mi.ino | 10 ++-- .../xsns_62_esp32_mi_ble.ino | 2 +- .../tasmota_xsns_sensor/xsns_67_as3935.ino | 4 +- tasmota/tasmota_xsns_sensor/xsns_74_lmt01.ino | 12 ++--- 15 files changed, 78 insertions(+), 29 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_gpio.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_gpio.ino index 3b616895e..a8815f798 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_gpio.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_gpio.ino @@ -24,8 +24,12 @@ #include "esp8266toEsp32.h" #if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) +#if ESP_IDF_VERSION_MAJOR >= 5 +#include +#else #include #endif +#endif /*********************************************************************************************\ * Native functions mapped to Berry functions * @@ -60,8 +64,17 @@ extern "C" { // DAC #if defined(CONFIG_IDF_TARGET_ESP32) if (25 == pin || 26 == pin) { +#if ESP_IDF_VERSION_MAJOR >= 5 + dac_oneshot_handle_t channel_handle; + const dac_channel_t channel = (25 == pin) ? DAC_CHAN_0 : DAC_CHAN_1; + dac_oneshot_config_t channel_cfg = { + .chan_id = channel, + }; + esp_err_t err = dac_oneshot_new_channel(&channel_cfg, &channel_handle); +#else dac_channel_t channel = (25 == pin) ? DAC_CHANNEL_1 : DAC_CHANNEL_2; esp_err_t err = dac_output_enable(channel); +#endif if (err) { be_raisef(vm, "value_error", "Error: dac_output_enable(%i) -> %i", channel, err); } @@ -70,8 +83,17 @@ extern "C" { } #elif defined(CONFIG_IDF_TARGET_ESP32S2) if (17 == pin || 18 == pin) { +#if ESP_IDF_VERSION_MAJOR >= 5 + dac_oneshot_handle_t channel_handle; + const dac_channel_t channel = (17 == pin) ? DAC_CHAN_0 : DAC_CHAN_1; + dac_oneshot_config_t channel_cfg = { + .chan_id = channel, + }; + esp_err_t err = dac_oneshot_new_channel(&channel_cfg, &channel_handle); +#else dac_channel_t channel = (17 == pin) ? DAC_CHANNEL_1 : DAC_CHANNEL_2; esp_err_t err = dac_output_enable(channel); +#endif if (err) { be_raisef(vm, "value_error", "Error: dac_output_enable(%i) -> %i", channel, err); } @@ -129,8 +151,18 @@ extern "C" { uint32_t dac_value = changeUIntScale(mV, 0, 3300, 0, 255); // convert from 0..3300 ms to 0..255 #if defined(CONFIG_IDF_TARGET_ESP32) if (25 == pin || 26 == pin) { +#if ESP_IDF_VERSION_MAJOR >= 5 + dac_oneshot_handle_t channel_handle; + const dac_channel_t channel = (25 == pin) ? DAC_CHAN_0 : DAC_CHAN_1; + dac_oneshot_config_t channel_cfg = { + .chan_id = channel, + }; + esp_err_t err = dac_oneshot_new_channel(&channel_cfg, &channel_handle); +#else dac_channel_t channel = (25 == pin) ? DAC_CHANNEL_1 : DAC_CHANNEL_2; - esp_err_t err = dac_output_voltage(channel, dac_value); +// esp_err_t err = dac_output_voltage(channel, dac_value); + esp_err_t err = dac_output_enable(channel); +#endif if (err) { be_raisef(vm, "internal_error", "Error: esp_err_tdac_output_voltage(%i, %i) -> %i", channel, dac_value, err); } @@ -139,16 +171,24 @@ extern "C" { } #elif defined(CONFIG_IDF_TARGET_ESP32S2) if (17 == pin || 18 == pin) { +#if ESP_IDF_VERSION_MAJOR >= 5 + dac_oneshot_handle_t channel_handle; + const dac_channel_t channel = (17 == pin) ? DAC_CHAN_0 : DAC_CHAN_1; + dac_oneshot_config_t channel_cfg = { + .chan_id = channel, + }; + esp_err_t err = dac_oneshot_new_channel(&channel_cfg, &channel_handle); +#else dac_channel_t channel = (17 == pin) ? DAC_CHANNEL_1 : DAC_CHANNEL_2; - esp_err_t err = dac_output_voltage(channel, dac_value); +// esp_err_t err = dac_output_voltage(channel, dac_value); + esp_err_t err = dac_output_enable(channel); +#endif if (err) { be_raisef(vm, "internal_error", "Error: esp_err_tdac_output_voltage(%i, %i) -> %i", channel, dac_value, err); } } else { be_raise(vm, "value_error", "DAC only supported on GPIO17-18"); } -#elif defined(CONFIG_IDF_TARGET_ESP32C3) - be_raise(vm, "value_error", "DAC unsupported in this chip"); #else be_raise(vm, "value_error", "DAC unsupported in this chip"); #endif diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_wire.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_wire.ino index c78f30960..1518ce518 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_wire.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_wire.ino @@ -96,7 +96,7 @@ extern "C" { TwoWire & myWire = getWire(vm); if (top == 2 && be_isint(vm, 2)) { // only 1 argument of type string accepted int32_t address = be_toint(vm, 2); - myWire.beginTransmission(address); + myWire.beginTransmission((int)address); be_return(vm); // Return } be_raise(vm, kTypeError, nullptr); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_54_lvgl.ino b/tasmota/tasmota_xdrv_driver/xdrv_54_lvgl.ino index 26fa7bbcb..58293139b 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_54_lvgl.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_54_lvgl.ino @@ -382,8 +382,8 @@ void start_lvgl(const char * uconfig) { // By default set the display color to black and opacity to 100% lv_disp_set_bg_color(NULL, lv_color_from_uint32(USE_LVGL_BG_DEFAULT)); lv_disp_set_bg_opa(NULL, LV_OPA_COVER); - lv_obj_set_style_bg_color(lv_scr_act(), lv_color_from_uint32(USE_LVGL_BG_DEFAULT), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_bg_opa(lv_scr_act(), LV_OPA_COVER, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_color(lv_scr_act(), lv_color_from_uint32(USE_LVGL_BG_DEFAULT), static_cast(LV_PART_MAIN) | static_cast(LV_STATE_DEFAULT)); + lv_obj_set_style_bg_opa(lv_scr_act(), LV_OPA_COVER, static_cast(LV_PART_MAIN) | static_cast(LV_STATE_DEFAULT)); #if LV_USE_LOG lv_log_register_print_cb(lvbe_debug); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_79_esp32_ble.ino b/tasmota/tasmota_xdrv_driver/xdrv_79_esp32_ble.ino index 6f9089e1f..6a2e01cc7 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_79_esp32_ble.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_79_esp32_ble.ino @@ -32,7 +32,7 @@ #endif #ifdef ESP32 // ESP32 family only. Use define USE_HM10 for ESP8266 support -#if defined CONFIG_IDF_TARGET_ESP32 || defined CONFIG_IDF_TARGET_ESP32C3 || defined CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 #ifdef USE_BLE_ESP32 /* diff --git a/tasmota/tasmota_xdrv_driver/xdrv_85_esp32_ble_eq3_trv.ino b/tasmota/tasmota_xdrv_driver/xdrv_85_esp32_ble_eq3_trv.ino index 860eb0038..3e170c2c3 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_85_esp32_ble_eq3_trv.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_85_esp32_ble_eq3_trv.ino @@ -132,7 +132,7 @@ print("".join(pin)) #define USE_EQ3_ESP32 #endif -#if defined CONFIG_IDF_TARGET_ESP32 || defined CONFIG_IDF_TARGET_ESP32C3 || defined CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 #ifdef USE_EQ3_ESP32 #ifdef ESP32 // ESP32 only. Use define USE_HM10 for ESP8266 support #ifdef USE_BLE_ESP32 diff --git a/tasmota/tasmota_xlgt_light/xlgt_02_my92x1.ino b/tasmota/tasmota_xlgt_light/xlgt_02_my92x1.ino index ec72df8d8..9120f9397 100644 --- a/tasmota/tasmota_xlgt_light/xlgt_02_my92x1.ino +++ b/tasmota/tasmota_xlgt_light/xlgt_02_my92x1.ino @@ -31,9 +31,16 @@ struct MY92X1 { uint8_t model = 0; } My92x1; +#if ESP_IDF_VERSION_MAJOR >= 5 +#include "rom/ets_sys.h" +#ifndef os_delay_us +#define os_delay_us ets_delay_us +#endif //os_delay_us +#else extern "C" { void os_delay_us(unsigned int); } +#endif void LightDiPulse(uint8_t times) { diff --git a/tasmota/tasmota_xnrg_energy/xnrg_23_ade7880.ino b/tasmota/tasmota_xnrg_energy/xnrg_23_ade7880.ino index 08fb4a11f..ea6989994 100644 --- a/tasmota/tasmota_xnrg_energy/xnrg_23_ade7880.ino +++ b/tasmota/tasmota_xnrg_energy/xnrg_23_ade7880.ino @@ -545,7 +545,7 @@ void Ade7880Service0(void) { Ade7880.irq0_state = 0; } -void IRAM_ATTR Ade7880Isr0(void) { +static void IRAM_ATTR Ade7880Isr0(void) { // Poll sequence if (!Ade7880.irq0_state) { Ade7880.irq0_state = 1; diff --git a/tasmota/tasmota_xsns_sensor/xsns_01_counter.ino b/tasmota/tasmota_xsns_sensor/xsns_01_counter.ino index ba31983db..183fbb62c 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_01_counter.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_01_counter.ino @@ -47,7 +47,8 @@ struct COUNTER { } Counter; -void IRAM_ATTR CounterIsrArg(void *arg) { +void IRAM_ATTR CounterIsrArg(void *arg); +void CounterIsrArg(void *arg) { uint32_t index = *static_cast(arg); uint32_t time = micros(); diff --git a/tasmota/tasmota_xsns_sensor/xsns_35_tx20.ino b/tasmota/tasmota_xsns_sensor/xsns_35_tx20.ino index a128f2fe3..e1c012971 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_35_tx20.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_35_tx20.ino @@ -165,8 +165,7 @@ uint32_t tx2x_last_available = 0; uint32_t tx23_stage = 0; #endif // USE_TX23_WIND_SENSOR -void IRAM_ATTR TX2xStartRead(void) -{ +static void IRAM_ATTR TX2xStartRead(void) { /** * La Crosse TX20 Anemometer datagram every 2 seconds * 0-0 11011 0011 111010101111 0101 1100 000101010000 0-0 - Received pin data at 1200 uSec per bit @@ -279,9 +278,11 @@ void IRAM_ATTR TX2xStartRead(void) } #endif // USE_TX23_WIND_SENSOR +#ifdef ESP8266 // Must clear this bit in the interrupt register, // it gets set even when interrupts are disabled GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << Pin(GPIO_TX2X_TXD_BLACK)); +#endif } bool Tx2xAvailable(void) diff --git a/tasmota/tasmota_xsns_sensor/xsns_48_chirp.ino b/tasmota/tasmota_xsns_sensor/xsns_48_chirp.ino index 1782a59df..f7a47e8d4 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_48_chirp.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_48_chirp.ino @@ -152,7 +152,9 @@ void ChirpResetAll(void) { /********************************************************************************************/ void ChirpClockSet() { // set I2C for this slow sensor +#if ESP_IDF_VERSION_MAJOR < 5 // setClockStretchLimit was removed Wire.setClockStretchLimit(4000); +#endif Wire.setClock(50000); } diff --git a/tasmota/tasmota_xsns_sensor/xsns_52_esp32_ibeacon_ble.ino b/tasmota/tasmota_xsns_sensor/xsns_52_esp32_ibeacon_ble.ino index 9a96ea794..2e886af91 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_52_esp32_ibeacon_ble.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_52_esp32_ibeacon_ble.ino @@ -52,7 +52,7 @@ // for testing of BLE_ESP32, we remove xsns_52_ibeacon.ino completely, and instead add this modified xsns_52_ibeacon_BLE_ESP32.ino // in the future this may be more fine-grained, e.g. to allow hm17 for this, and BLE-ESP32 for other -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 #ifdef USE_BLE_ESP32 #define XSNS_52 52 diff --git a/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi.ino b/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi.ino index 7a8964c4d..47c68c8cc 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi.ino @@ -50,7 +50,7 @@ */ #ifndef USE_BLE_ESP32 #ifdef ESP32 // ESP32 only. Use define USE_HM10 for ESP8266 support -#if defined CONFIG_IDF_TARGET_ESP32 || defined CONFIG_IDF_TARGET_ESP32C3 || defined CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 #ifdef USE_MI_ESP32 @@ -697,9 +697,7 @@ void MI32PreInit(void) { void MI32Init(void) { if (MI32.mode.init) { return; } - if (TasmotaGlobal.global_state.wifi_down && TasmotaGlobal.global_state.eth_down) { - if (!(WIFI_MANAGER == Wifi.config_type || WIFI_MANAGER_RESET_ONLY == Wifi.config_type)) return; - } + if (TasmotaGlobal.global_state.wifi_down && TasmotaGlobal.global_state.eth_down) { return; } if (!TasmotaGlobal.global_state.wifi_down) { TasmotaGlobal.wifi_stay_asleep = true; @@ -1294,7 +1292,7 @@ bool MI32StartConnectionTask(){ } void MI32ConnectionTask(void *pvParameters){ -#if !defined(CONFIG_IDF_TARGET_ESP32C3) //needs more testing ... +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) //needs more testing ... // NimBLEDevice::setOwnAddrType(BLE_OWN_ADDR_RANDOM,false); //seems to be important for i.e. xbox controller, hopefully not breaking other things // NimBLEDevice::setSecurityAuth(true, true, true); #endif //CONFIG_IDF_TARGET_ESP32C3 @@ -2671,4 +2669,4 @@ bool Xsns62(uint32_t function) #endif // USE_MI_ESP32 #endif // CONFIG_IDF_TARGET_ESP32 or CONFIG_IDF_TARGET_ESP32C3 #endif // ESP32 -#endif // USE_BLE_ESP32 +#endif // USE_BLE_ESP32 \ No newline at end of file diff --git a/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi_ble.ino b/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi_ble.ino index 6f5a9d124..56dcd8e16 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi_ble.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi_ble.ino @@ -71,7 +71,7 @@ #ifdef USE_BLE_ESP32 #ifdef ESP32 // ESP32 family only. Use define USE_HM10 for ESP8266 support -#if defined CONFIG_IDF_TARGET_ESP32 || defined CONFIG_IDF_TARGET_ESP32C3|| defined CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 #ifdef USE_MI_ESP32 diff --git a/tasmota/tasmota_xsns_sensor/xsns_67_as3935.ino b/tasmota/tasmota_xsns_sensor/xsns_67_as3935.ino index 2ae4d49a9..ae0f68c74 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_67_as3935.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_67_as3935.ino @@ -150,7 +150,7 @@ struct { volatile uint32_t pulse = 0; } as3935_sensor; -void IRAM_ATTR AS3935Isr(void) { +static void IRAM_ATTR AS3935Isr(void) { as3935_sensor.detected = true; as3935_sensor.icount++; } @@ -176,7 +176,7 @@ void AS3935WriteRegister(uint8_t reg, uint8_t mask, uint8_t shift, uint8_t data) /********************************************************************************************/ // Autotune Caps -void IRAM_ATTR AS3935CountFreq(void) { +static void IRAM_ATTR AS3935CountFreq(void) { if (as3935_sensor.dispLCO) as3935_sensor.pulse++; } diff --git a/tasmota/tasmota_xsns_sensor/xsns_74_lmt01.ino b/tasmota/tasmota_xsns_sensor/xsns_74_lmt01.ino index edfa00d3b..daf02a1bc 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_74_lmt01.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_74_lmt01.ino @@ -32,6 +32,12 @@ bool lmt01_initialized = false; float lmt01_temperature = NAN; +volatile int lmt01_pulseCount = 0; + +static void IRAM_ATTR LMT01_countPulse(void) { + lmt01_pulseCount++; +} + void LMT01_Init(void) { if (PinUsed(GPIO_LMT01)) { pinMode(Pin(GPIO_LMT01), INPUT); @@ -40,12 +46,6 @@ void LMT01_Init(void) { } } -volatile int lmt01_pulseCount = 0; - -void IRAM_ATTR LMT01_countPulse(void) { - lmt01_pulseCount++; -} - void LMT01_GetTemperature(void) { int pulses = 0; pulses = LMT01_getPulses();