diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 9a0528c9e..b84ce4265 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -345,7 +345,7 @@ #define D_CMND_TOUCH_THRES "TouchThres" #define D_CMND_TOUCH_NUM "TouchNum" #define D_CMND_CPU_FREQUENCY "CpuFrequency" -#endif //ESP32 +#endif // ESP32 // Commands xdrv_01_mqtt.ino #define D_CMND_MQTTLOG "MqttLog" diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 2d95b9b22..1b24e6eac 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -54,10 +54,11 @@ #ifdef ESP8266 #define FALLBACK_MODULE SONOFF_BASIC // [Module2] Select default module on fast reboot where USER_MODULE is user template //#define USER_TEMPLATE "{\"NAME\":\"Generic\",\"GPIO\":[255,255,255,255,255,255,255,255,255,255,255,255,255],\"FLAG\":15,\"BASE\":18}" // [Template] Set JSON template -#else // ESP32 +#endif // ESP8266 +#ifdef ESP32 #define FALLBACK_MODULE WEMOS // [Module2] Select default module on fast reboot where USER_MODULE is user template //#define USER_TEMPLATE "{\"NAME\":\"ESP32-DevKit\",\"GPIO\":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,1,1,1,1,1,0,0,1],\"FLAG\":0,\"BASE\":1}" // [Template] Set JSON template -#endif +#endif // ESP32 #define SAVE_DATA 1 // [SaveData] Save changed parameters to Flash (0 = disable, 1 - 3600 seconds) #define SAVE_STATE true // [SetOption0] Save changed power state to Flash (false = disable, true = enable) @@ -92,9 +93,10 @@ // -- Ota ----------------------------------------- #ifdef ESP8266 #define OTA_URL "http://ota.tasmota.com/tasmota/release/tasmota.bin.gz" // [OtaUrl] -#else // ESP32 +#endif // ESP8266 +#ifdef ESP32 #define OTA_URL "http://ota.tasmota.com/tasmota32/release/tasmota.bin" // [OtaUrl] -#endif +#endif // ESP32 #define OTA_COMPATIBILITY false // [SetOption78] Disable OTA compatibility check // -- MQTT ---------------------------------------- @@ -825,7 +827,7 @@ #define USE_MI_ESP32 // Add support for ESP32 as a BLE-bridge (+9k2 mem, +292k flash) //#define USE_WEBCAM // Add support for webcam -#endif +#endif // ESP32 /*********************************************************************************************\ * Debug features diff --git a/tasmota/sendemail.h b/tasmota/sendemail.h index 7b168b498..5c75ae260 100644 --- a/tasmota/sendemail.h +++ b/tasmota/sendemail.h @@ -10,9 +10,10 @@ #ifdef ESP8266 #include "WiFiClientSecureLightBearSSL.h" -#else +#endif // ESP8266 +#ifdef ESP32 #include -#endif +#endif // ESP32 class SendEmail { @@ -27,9 +28,10 @@ class SendEmail #ifdef ESP8266 // use bear ssl BearSSL::WiFiClientSecure_light *client; -#else +#endif // ESP8266 +#ifdef ESP32 WiFiClient *client; -#endif +#endif // ESP32 String readClient(); void a3_to_a4(unsigned char * a4, unsigned char * a3); diff --git a/tasmota/sendemail.ino b/tasmota/sendemail.ino index 9480ede7b..467646487 100644 --- a/tasmota/sendemail.ino +++ b/tasmota/sendemail.ino @@ -185,12 +185,13 @@ WiFiClient *g_client; SendEmail::SendEmail(const String& host, const int port, const String& user, const String& passwd, const int timeout, const int auth_used) : host(host), port(port), user(user), passwd(passwd), timeout(timeout), ssl(ssl), auth_used(auth_used), client(new BearSSL::WiFiClientSecure_light(1024,1024)) { } -#else +#endif // ESP8266 +#ifdef ESP32 WiFiClient *g_client; SendEmail::SendEmail(const String& host, const int port, const String& user, const String& passwd, const int timeout, const int auth_used) : host(host), port(port), user(user), passwd(passwd), timeout(timeout), ssl(ssl), auth_used(auth_used), client(new WiFiClientSecure()) { } -#endif +#endif // ESP32 String SendEmail::readClient() { delay(0); diff --git a/tasmota/settings.h b/tasmota/settings.h index 44a6947a4..7273e48db 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -444,7 +444,8 @@ struct { uint8_t free_esp8266_41A[55]; // 41A -#else // ESP32 +#endif // ESP8266 +#ifdef ESP32 uint8_t eth_type; // 446 uint8_t eth_clk_mode; // 447 @@ -452,7 +453,7 @@ struct { WebCamCfg webcam_config; // 44C uint8_t eth_address; // 450 -#endif // ESP8266 - ESP32 +#endif // ESP32 char serial_delimiter; // 451 uint8_t seriallog_level; // 452 uint8_t sleep; // 453 @@ -464,11 +465,12 @@ struct { #ifdef ESP8266 myio8 ex_my_gp8; // 484 17 bytes (ESP8266) - Free since 9.0.0.1 -#else // ESP32 +#endif // ESP8266 +#ifdef ESP32 uint8_t free_esp32_484[17]; // 484 -#endif // ESP8266 - ESP32 +#endif // ESP32 uint8_t ex_my_adc0; // 495 Free since 9.0.0.1 @@ -525,11 +527,12 @@ struct { #ifdef ESP8266 mytmplt8285 ex_user_template8; // 72F 14 bytes (ESP8266) - Free since 9.0.0.1 -#else // ESP32 +#endif // ESP8266 +#ifdef ESP32 uint8_t free_esp32_72f[14]; // 72F -#endif // ESP8266 - ESP32 +#endif // ESP32 uint8_t novasds_startingoffset; // 73D uint8_t web_color[18][3]; // 73E @@ -638,7 +641,7 @@ struct { uint8_t shd_leading_edge; // F5B uint16_t shd_warmup_brightness; // F5C uint8_t shd_warmup_time; // F5E - + uint8_t free_f5e[84]; // F5E - Decrement if adding new Setting variables just above and below // Only 32 bit boundary variables below @@ -669,7 +672,7 @@ typedef struct { TRtcReboot RtcReboot; #ifdef ESP32 RTC_NOINIT_ATTR TRtcReboot RtcDataReboot; -#endif +#endif // ESP32 typedef struct { uint16_t valid; // 290 (RTC memory offset 100) @@ -691,7 +694,7 @@ typedef struct { TRtcSettings RtcSettings; #ifdef ESP32 RTC_NOINIT_ATTR TRtcSettings RtcDataSettings; -#endif +#endif // ESP32 struct TIME_T { uint8_t second; diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 18711b5fc..a226cc181 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -42,9 +42,10 @@ void RtcSettingsSave(void) RtcSettings.valid = RTC_MEM_VALID; #ifdef ESP8266 ESP.rtcUserMemoryWrite(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); -#else +#endif // ESP8266 +#ifdef ESP32 RtcDataSettings = RtcSettings; -#endif +#endif // ESP32 rtc_settings_crc = GetRtcSettingsCrc(); } } @@ -53,9 +54,10 @@ void RtcSettingsLoad(void) { #ifdef ESP8266 ESP.rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); // 0x290 -#else +#endif // ESP8266 +#ifdef ESP32 RtcSettings = RtcDataSettings; -#endif +#endif // ESP32 if (RtcSettings.valid != RTC_MEM_VALID) { memset(&RtcSettings, 0, sizeof(RtcSettings)); RtcSettings.valid = RTC_MEM_VALID; @@ -97,9 +99,10 @@ void RtcRebootSave(void) RtcReboot.valid = RTC_MEM_VALID; #ifdef ESP8266 ESP.rtcUserMemoryWrite(100 - sizeof(RtcReboot), (uint32_t*)&RtcReboot, sizeof(RtcReboot)); -#else +#endif // ESP8266 +#ifdef ESP32 RtcDataReboot = RtcReboot; -#endif +#endif // ESP32 rtc_reboot_crc = GetRtcRebootCrc(); } } @@ -114,9 +117,10 @@ void RtcRebootLoad(void) { #ifdef ESP8266 ESP.rtcUserMemoryRead(100 - sizeof(RtcReboot), (uint32_t*)&RtcReboot, sizeof(RtcReboot)); // 0x280 -#else +#endif // ESP8266 +#ifdef ESP32 RtcReboot = RtcDataReboot; -#endif +#endif // ESP32 if (RtcReboot.valid != RTC_MEM_VALID) { memset(&RtcReboot, 0, sizeof(RtcReboot)); RtcReboot.valid = RTC_MEM_VALID; @@ -316,7 +320,8 @@ void UpdateQuickPowerCycle(bool update) { AddLog_P(LOG_LEVEL_INFO, PSTR("QPC: Reset")); } } -#else // ESP32 +#endif // ESP8266 +#ifdef ESP32 uint32_t pc_register; QPCRead(&pc_register, sizeof(pc_register)); if (update && ((pc_register & 0xFFFFFFF0) == 0xFFA55AF0)) { @@ -337,7 +342,7 @@ void UpdateQuickPowerCycle(bool update) { QPCWrite(&pc_register, sizeof(pc_register)); AddLog_P(LOG_LEVEL_INFO, PSTR("QPC: Reset")); } -#endif // ESP8266 or ESP32 +#endif // ESP32 #endif // FIRMWARE_MINIMAL } @@ -511,10 +516,11 @@ void SettingsSave(uint8_t rotate) } } AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_CONFIG D_SAVED_TO_FLASH_AT " %X, " D_COUNT " %d, " D_BYTES " %d"), settings_location, Settings.save_flag, sizeof(Settings)); -#else // ESP32 +#endif // ESP8266 +#ifdef ESP32 SettingsWrite(&Settings, sizeof(Settings)); AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_CONFIG "Saved, " D_COUNT " %d, " D_BYTES " %d"), Settings.save_flag, sizeof(Settings)); -#endif // ESP8266 +#endif // ESP32 settings_crc32 = Settings.cfg_crc32; } @@ -547,10 +553,11 @@ void SettingsLoad(void) { ESP.flashRead(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(Settings)); AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG D_LOADED_FROM_FLASH_AT " %X, " D_COUNT " %lu"), settings_location, Settings.save_flag); } -#else // ESP32 +#endif // ESP8266 +#ifdef ESP32 SettingsRead(&Settings, sizeof(Settings)); AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG "Loaded, " D_COUNT " %lu"), Settings.save_flag); -#endif // ESP8266 - ESP32 +#endif // ESP32 #ifndef FIRMWARE_MINIMAL if ((0 == settings_location) || (Settings.cfg_holder != (uint16_t)CFG_HOLDER)) { // Init defaults if cfg_holder differs from user settings in my_user_config.h @@ -755,7 +762,7 @@ void SettingsDefaultSet2(void) Settings.eth_type = ETH_TYPE; Settings.eth_clk_mode = ETH_CLKMODE; Settings.eth_address = ETH_ADDR; -#endif +#endif // ESP32 // Wifi flag4.network_wifi |= 1; diff --git a/tasmota/support_button.ino b/tasmota/support_button.ino index ba9d0425a..749509b69 100644 --- a/tasmota/support_button.ino +++ b/tasmota/support_button.ino @@ -27,7 +27,7 @@ #ifdef ESP32 #define TOUCH_PIN_THRESHOLD 12 // Smaller value will treated as button press #define TOUCH_HIT_THRESHOLD 3 // successful hits to filter out noise -#endif // ESP32 +#endif // ESP32 const char kMultiPress[] PROGMEM = "|SINGLE|DOUBLE|TRIPLE|QUAD|PENTA|"; @@ -47,7 +47,7 @@ struct BUTTON { #ifdef ESP32 uint8_t touch_mask = 0; // Touch flag (1 = inverted) uint8_t touch_hits[MAX_KEYS] = { 0 }; // Hits in a row to filter out noise -#endif // ESP32 +#endif // ESP32 uint8_t present = 0; // Number of buttons found flag } Button; @@ -57,7 +57,7 @@ struct TOUCH_BUTTON { uint8_t hit_threshold = TOUCH_HIT_THRESHOLD; uint8_t calibration = 0; // Bitfield } TOUCH_BUTTON; -#endif // ESP32 +#endif // ESP32 /********************************************************************************************/ @@ -73,7 +73,7 @@ void ButtonInvertFlag(uint32_t button_bit) { void ButtonTouchFlag(uint32_t button_bit) { bitSet(Button.touch_mask, button_bit); } -#endif // ESP32 +#endif // ESP32 void ButtonInit(void) { Button.present = 0; @@ -87,9 +87,10 @@ void ButtonInit(void) { Button.present++; #ifdef ESP8266 pinMode(Pin(GPIO_KEY1, i), bitRead(Button.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_KEY1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP)); -#else // ESP32 +#endif // ESP8266 +#ifdef ESP32 pinMode(Pin(GPIO_KEY1, i), bitRead(Button.no_pullup_mask, i) ? INPUT : INPUT_PULLUP); -#endif +#endif // ESP32 } #ifdef USE_ADC else if (PinUsed(GPIO_ADC_BUTTON, i) || PinUsed(GPIO_ADC_BUTTON_INV, i)) { diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 502eb9788..4b9e21839 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -41,7 +41,7 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix D_CMND_SENSOR "|" D_CMND_DRIVER #ifdef ESP32 "|Info|" D_CMND_TOUCH_CAL "|" D_CMND_TOUCH_THRES "|" D_CMND_TOUCH_NUM "|" D_CMND_CPU_FREQUENCY "|" D_CMND_WIFI -#endif //ESP32 +#endif // ESP32 ; void (* const TasmotaCommand[])(void) PROGMEM = { @@ -68,7 +68,7 @@ void (* const TasmotaCommand[])(void) PROGMEM = { &CmndSensor, &CmndDriver #ifdef ESP32 , &CmndInfo, &CmndTouchCal, &CmndTouchThres, &CmndTouchNum, &CmndCpuFrequency, &CmndWifi -#endif //ESP32 +#endif // ESP32 }; const char kWifiConfig[] PROGMEM = @@ -268,7 +268,7 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) } } } -#else //USE_SCRIPT_SUB_COMMAND +#else // USE_SCRIPT_SUB_COMMAND if (!DecodeCommand(kTasmotaCommands, TasmotaCommand)) { if (!XdrvCall(FUNC_COMMAND)) { if (!XsnsCall(FUNC_COMMAND)) { @@ -276,7 +276,7 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) } } } -#endif //USE_SCRIPT_SUB_COMMAND +#endif // USE_SCRIPT_SUB_COMMAND } @@ -483,20 +483,20 @@ void CmndStatus(void) Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS4_MEMORY "\":{\"" D_JSON_PROGRAMSIZE "\":%d,\"" D_JSON_FREEMEMORY "\":%d,\"" D_JSON_HEAPSIZE "\":%d,\"" #ifdef ESP32 D_JSON_PSRMAXMEMORY "\":%d,\"" D_JSON_PSRFREEMEMORY "\":%d,\"" -#endif +#endif // ESP32 D_JSON_PROGRAMFLASHSIZE "\":%d,\"" D_JSON_FLASHSIZE "\":%d" #ifdef ESP8266 ",\"" D_JSON_FLASHCHIPID "\":\"%06X\"" -#endif +#endif // ESP8266 ",\"FlashFrequency\":%d,\"" D_JSON_FLASHMODE "\":%d"), ESP_getSketchSize()/1024, ESP.getFreeSketchSpace()/1024, ESP_getFreeHeap()/1024, #ifdef ESP32 ESP.getPsramSize()/1024, ESP.getFreePsram()/1024, -#endif +#endif // ESP32 ESP.getFlashChipSize()/1024, ESP.getFlashChipRealSize()/1024 #ifdef ESP8266 , ESP.getFlashChipId() -#endif +#endif // ESP8266 , ESP.getFlashChipSpeed()/1000000, ESP.getFlashChipMode()); ResponseAppendFeatures(); XsnsDriverState(); @@ -2122,4 +2122,4 @@ void CmndTouchNum(void) } -#endif //ESP32 +#endif // ESP32 diff --git a/tasmota/support_eeprom.ino b/tasmota/support_eeprom.ino index 009026e56..467459354 100644 --- a/tasmota/support_eeprom.ino +++ b/tasmota/support_eeprom.ino @@ -51,21 +51,7 @@ uint32_t eeprom_init(uint32_t size) { #else // USE_24C256 -#ifdef ESP32 - -// esp32 uses eeprom section -uint32_t eeprom_init(uint32_t size) { - return EEPROM.begin(size); -} -void eeprom_writeBytes(uint32_t addr, uint32_t len, uint8_t *buff) { - EEPROM.writeBytes(addr, buff, len); - EEPROM.commit(); -} -void eeprom_readBytes(uint32_t addr, uint32_t len, uint8_t *buff) { - EEPROM.readBytes(addr, buff, len); -} - -#else +#ifdef ESP8266 // esp8266 uses eeprom section uint32_t eeprom_init(uint32_t size) { EEPROM.begin(size); @@ -83,7 +69,20 @@ void eeprom_readBytes(uint32_t adr, uint32_t len, uint8_t *buf) { *buf++ = EEPROM.read(adr++); } } +#endif // ESP8266 +#ifdef ESP32 +// esp32 uses eeprom section +uint32_t eeprom_init(uint32_t size) { + return EEPROM.begin(size); +} +void eeprom_writeBytes(uint32_t addr, uint32_t len, uint8_t *buff) { + EEPROM.writeBytes(addr, buff, len); + EEPROM.commit(); +} +void eeprom_readBytes(uint32_t addr, uint32_t len, uint8_t *buff) { + EEPROM.readBytes(addr, buff, len); +} +#endif // ESP32 -#endif -#endif // USE_24C256 -#endif // USE_EEPROM +#endif // USE_24C256 +#endif // USE_EEPROM diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index 84755b54d..5e10796ea 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -201,9 +201,10 @@ void SwitchInit(void) { Switch.present++; #ifdef ESP8266 pinMode(Pin(GPIO_SWT1, i), bitRead(Switch.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_SWT1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP)); -#else // ESP32 +#endif // ESP8266 +#ifdef ESP32 pinMode(Pin(GPIO_SWT1, i), bitRead(Switch.no_pullup_mask, i) ? INPUT : INPUT_PULLUP); -#endif +#endif // ESP32 if (ac_detect) { Switch.state[i] = 0x80 + 2 * AC_PERIOD; Switch.last_state[i] = 0; // Will set later in the debouncing code diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index c402e00b2..f8e88d17b 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1194,13 +1194,14 @@ void Every250mSeconds(void) #ifdef ESP8266 StartWebserver(Settings.webserver, WiFi.localIP()); -#else // ESP32 +#endif // ESP8266 +#ifdef ESP32 #ifdef USE_ETHERNET StartWebserver(Settings.webserver, (EthernetLocalIP()) ? EthernetLocalIP() : WiFi.localIP()); #else StartWebserver(Settings.webserver, WiFi.localIP()); #endif -#endif +#endif // ESP32 #ifdef USE_DISCOVERY #ifdef WEBSERVER_ADVERTISE @@ -1605,7 +1606,8 @@ void GpioInit(void) AddLog_P(LOG_LEVEL_DEBUG, PSTR("SPI: Using GPIO12(MISO), GPIO13(MOSI) and GPIO14(CLK)")); } #endif // USE_SPI -#else // ESP32 +#endif // ESP8266 +#ifdef ESP32 #ifdef USE_SPI if (PinUsed(GPIO_SPI_CS) || PinUsed(GPIO_SPI_DC)) { if ((15 == Pin(GPIO_SPI_CS)) && (!GetPin(12) && !GetPin(13) && !GetPin(14))) { // HSPI @@ -1657,7 +1659,7 @@ void GpioInit(void) } } #endif // USE_SPI -#endif // ESP8266 - ESP32 +#endif // ESP32 TasmotaGlobal.soft_spi_enabled = (PinUsed(GPIO_SSPI_SCLK) && (PinUsed(GPIO_SSPI_MOSI) || PinUsed(GPIO_SSPI_MISO))); for (uint32_t i = 0; i < ARRAY_SIZE(TasmotaGlobal.my_module.io); i++) { @@ -1719,9 +1721,10 @@ void GpioInit(void) if (PinUsed(GPIO_PWM1, i)) { #ifdef ESP8266 pinMode(Pin(GPIO_PWM1, i), OUTPUT); -#else // ESP32 +#endif // ESP8266 +#ifdef ESP32 analogAttach(Pin(GPIO_PWM1, i), i); -#endif +#endif // ESP32 if (TasmotaGlobal.light_type) { // force PWM GPIOs to low or high mode, see #7165 analogWrite(Pin(GPIO_PWM1, i), bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings.pwm_range : 0);