diff --git a/tasmota/i18n.h b/tasmota/i18n.h index b3537b59c..194ff4bc6 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -322,10 +322,12 @@ #define D_CMND_HUMOFFSET "HumOffset" #define D_CMND_GLOBAL_TEMP "GlobalTemp" #define D_CMND_GLOBAL_HUM "GlobalHum" + #ifdef ESP32 #define D_CMND_TOUCH_CAL "TouchCal" #define D_CMND_TOUCH_THRES "TouchThres" #define D_CMND_TOUCH_NUM "TouchNum" +#define D_CMND_CPU_FREQUENCY "CpuFrequency" #endif //ESP32 // Commands xdrv_01_mqtt.ino diff --git a/tasmota/support.ino b/tasmota/support.ino index 87cd0ce5e..cdd1b3cd6 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1099,11 +1099,19 @@ uint32_t Pin(uint32_t gpio, uint32_t index) { return 99; // No pin used for gpio } -boolean PinUsed(uint32_t gpio, uint32_t index = 0); -boolean PinUsed(uint32_t gpio, uint32_t index) { +bool PinUsed(uint32_t gpio, uint32_t index = 0); +bool PinUsed(uint32_t gpio, uint32_t index) { return (Pin(gpio, index) < 99); } +uint32_t GetPin(uint32_t lpin) { + if (lpin < ARRAY_SIZE(gpio_pin)) { + return gpio_pin[lpin]; + } else { + return GPIO_NONE; + } +} + void SetPin(uint32_t lpin, uint32_t gpio) { gpio_pin[lpin] = gpio; } diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 565fd8fcd..76c5252a0 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -40,7 +40,7 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix #endif // USE_DEVICE_GROUPS D_CMND_SENSOR "|" D_CMND_DRIVER #ifdef ESP32 - "|" D_CMND_TOUCH_CAL "|" D_CMND_TOUCH_THRES "|" D_CMND_TOUCH_NUM + "|" D_CMND_TOUCH_CAL "|" D_CMND_TOUCH_THRES "|" D_CMND_TOUCH_NUM "|" D_CMND_CPU_FREQUENCY #endif //ESP32 ; @@ -67,7 +67,7 @@ void (* const TasmotaCommand[])(void) PROGMEM = { #endif // USE_DEVICE_GROUPS &CmndSensor, &CmndDriver #ifdef ESP32 - ,&CmndTouchCal, &CmndTouchThres, &CmndTouchNum + ,&CmndTouchCal, &CmndTouchThres, &CmndTouchNum, &CmndCpuFrequency #endif //ESP32 }; @@ -1977,6 +1977,14 @@ void CmndDriver(void) } #ifdef ESP32 + +void CmndCpuFrequency(void) { + if ((80 == XdrvMailbox.payload) || (160 == XdrvMailbox.payload) || (240 == XdrvMailbox.payload)) { + setCpuFrequencyMhz(XdrvMailbox.payload); + } + ResponseCmndNumber(getCpuFrequencyMhz()); +} + void CmndTouchCal(void) { if (XdrvMailbox.payload >= 0) { diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index ae32ea34b..68edd6a7a 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1591,6 +1591,7 @@ void GpioInit(void) SetPin(13, GPIO_SPI_MOSI); my_module.io[14] = GPIO_SPI_CLK; SetPin(14, GPIO_SPI_CLK); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SPI: Using GPIO12(MISO), GPIO13(MOSI) and GPIO14(CLK)")); } soft_spi_flg = (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_SCLK) && (PinUsed(GPIO_SSPI_MOSI) || PinUsed(GPIO_SSPI_MISO))); #endif // USE_SPI @@ -1598,7 +1599,55 @@ void GpioInit(void) analogWriteFreqRange(0, Settings.pwm_frequency, Settings.pwm_range); #ifdef USE_SPI - spi_flg = (PinUsed(GPIO_SPI_CLK) && (PinUsed(GPIO_SPI_MOSI) || PinUsed(GPIO_SPI_MISO))); + if (PinUsed(GPIO_SPI_CS) || PinUsed(GPIO_SPI_DC)) { + if ((15 == Pin(GPIO_SPI_CS)) && (!GetPin(12) && !GetPin(13) && !GetPin(14))) { // HSPI + my_module.io[12] = AGPIO(GPIO_SPI_MISO); + SetPin(12, AGPIO(GPIO_SPI_MISO)); + my_module.io[13] = AGPIO(GPIO_SPI_MOSI); + SetPin(13, AGPIO(GPIO_SPI_MOSI)); + my_module.io[14] = AGPIO(GPIO_SPI_CLK); + SetPin(14, AGPIO(GPIO_SPI_CLK)); + } + else if ((5 == Pin(GPIO_SPI_CS)) && (!GetPin(19) && !GetPin(23) && !GetPin(18))) { // VSPI + my_module.io[19] = AGPIO(GPIO_SPI_MISO); + SetPin(19, AGPIO(GPIO_SPI_MISO)); + my_module.io[23] = AGPIO(GPIO_SPI_MOSI); + SetPin(23, AGPIO(GPIO_SPI_MOSI)); + my_module.io[18] = AGPIO(GPIO_SPI_CLK); + SetPin(18, AGPIO(GPIO_SPI_CLK)); + } + else if ((12 == Pin(GPIO_SPI_MISO)) || (13 == Pin(GPIO_SPI_MOSI)) || (14 == Pin(GPIO_SPI_CLK))) { // HSPI + my_module.io[12] = AGPIO(GPIO_SPI_MISO); + SetPin(12, AGPIO(GPIO_SPI_MISO)); + my_module.io[13] = AGPIO(GPIO_SPI_MOSI); + SetPin(13, AGPIO(GPIO_SPI_MOSI)); + my_module.io[14] = AGPIO(GPIO_SPI_CLK); + SetPin(14, AGPIO(GPIO_SPI_CLK)); + } + else if ((19 == Pin(GPIO_SPI_MISO)) || (23 == Pin(GPIO_SPI_MOSI)) || (18 == Pin(GPIO_SPI_CLK))) { // VSPI + my_module.io[19] = AGPIO(GPIO_SPI_MISO); + SetPin(19, AGPIO(GPIO_SPI_MISO)); + my_module.io[23] = AGPIO(GPIO_SPI_MOSI); + SetPin(23, AGPIO(GPIO_SPI_MOSI)); + my_module.io[18] = AGPIO(GPIO_SPI_CLK); + SetPin(18, AGPIO(GPIO_SPI_CLK)); + } + spi_flg = (PinUsed(GPIO_SPI_CLK) && (PinUsed(GPIO_SPI_MOSI) || PinUsed(GPIO_SPI_MISO))); + if (spi_flg) { + if (PinUsed(GPIO_SPI_MOSI) && PinUsed(GPIO_SPI_MISO)) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SPI: Using GPIO%02d(MISO), GPIO%02d(MOSI) and GPIO%02d(CLK)"), + Pin(GPIO_SPI_MISO), Pin(GPIO_SPI_MOSI), Pin(GPIO_SPI_CLK)); + } + else if (PinUsed(GPIO_SPI_MOSI)) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SPI: Using GPIO%02d(MOSI) and GPIO%02d(CLK)"), + Pin(GPIO_SPI_MOSI), Pin(GPIO_SPI_CLK)); + } + else if (PinUsed(GPIO_SPI_MISO)) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SPI: Using GPIO%02d(MISO) and GPIO%02d(CLK)"), + Pin(GPIO_SPI_MISO), Pin(GPIO_SPI_CLK)); + } + } + } soft_spi_flg = (PinUsed(GPIO_SSPI_SCLK) && (PinUsed(GPIO_SSPI_MOSI) || PinUsed(GPIO_SSPI_MISO))); #endif // USE_SPI #endif // ESP8266 - ESP32 @@ -1682,7 +1731,7 @@ void GpioInit(void) if (PinUsed(GPIO_LED1, i)) { #ifdef USE_ARILUX_RF if ((3 == i) && (leds_present < 2) && !PinUsed(GPIO_ARIRFSEL)) { - SetPin(Pin(GPIO_LED1, i), GPIO_ARIRFSEL); // Legacy support where LED4 was Arilux RF enable + SetPin(Pin(GPIO_LED1, i), AGPIO(GPIO_ARIRFSEL)); // Legacy support where LED4 was Arilux RF enable } else { #endif pinMode(Pin(GPIO_LED1, i), OUTPUT); diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index 5c5b1a120..8b19e1259 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -570,15 +570,15 @@ void TuyaNormalPowerModePacketProcess(void) bool key1_set = false; bool led1_set = false; for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { - if (Settings.my_gp.io[i] == GPIO_LED1) led1_set = true; - else if (Settings.my_gp.io[i] == GPIO_KEY1) key1_set = true; + if (Settings.my_gp.io[i] == AGPIO(GPIO_LED1)) led1_set = true; + else if (Settings.my_gp.io[i] == AGPIO(GPIO_KEY1)) key1_set = true; } if (!Settings.my_gp.io[led1_gpio] && !led1_set) { - Settings.my_gp.io[led1_gpio] = GPIO_LED1; + Settings.my_gp.io[led1_gpio] = AGPIO(GPIO_LED1); restart_flag = 2; } if (!Settings.my_gp.io[key1_gpio] && !key1_set) { - Settings.my_gp.io[key1_gpio] = GPIO_KEY1; + Settings.my_gp.io[key1_gpio] = AGPIO(GPIO_KEY1); restart_flag = 2; } } @@ -597,10 +597,10 @@ void TuyaNormalPowerModePacketProcess(void) bool TuyaModuleSelected(void) { if (!PinUsed(GPIO_TUYA_RX) || !PinUsed(GPIO_TUYA_TX)) { // fallback to hardware-serial if not explicitly selected - SetPin(1, GPIO_TUYA_TX); - SetPin(3, GPIO_TUYA_RX); - Settings.my_gp.io[1] = GPIO_TUYA_TX; - Settings.my_gp.io[3] = GPIO_TUYA_RX; + SetPin(1, AGPIO(GPIO_TUYA_TX)); + SetPin(3, AGPIO(GPIO_TUYA_RX)); + Settings.my_gp.io[1] = AGPIO(GPIO_TUYA_TX); + Settings.my_gp.io[3] = AGPIO(GPIO_TUYA_RX); restart_flag = 2; } diff --git a/tasmota/xdrv_31_tasmota_client.ino b/tasmota/xdrv_31_tasmota_client.ino index 27e289373..1708df44f 100644 --- a/tasmota/xdrv_31_tasmota_client.ino +++ b/tasmota/xdrv_31_tasmota_client.ino @@ -427,7 +427,7 @@ void TasmotaClient_Init(void) { } TasmotaClient_Serial->setTimeout(100); // Theo 20200502 - increase from 50 if (PinUsed(GPIO_TASMOTACLIENT_RST_INV)) { - SetPin(Pin(GPIO_TASMOTACLIENT_RST_INV), GPIO_TASMOTACLIENT_RST); + SetPin(Pin(GPIO_TASMOTACLIENT_RST_INV), AGPIO(GPIO_TASMOTACLIENT_RST)); TClient.inverted = HIGH; } pinMode(Pin(GPIO_TASMOTACLIENT_RST), OUTPUT); diff --git a/tasmota/xnrg_01_hlw8012.ino b/tasmota/xnrg_01_hlw8012.ino index d0c17353a..3a0873dd1 100644 --- a/tasmota/xnrg_01_hlw8012.ino +++ b/tasmota/xnrg_01_hlw8012.ino @@ -249,7 +249,7 @@ void HlwDrvInit(void) { Hlw.model_type = 0; // HLW8012 if (PinUsed(GPIO_HJL_CF)) { - SetPin(Pin(GPIO_HJL_CF), GPIO_HLW_CF); + SetPin(Pin(GPIO_HJL_CF), AGPIO(GPIO_HLW_CF)); Hlw.model_type = 1; // HJL-01/BL0937 } @@ -257,7 +257,7 @@ void HlwDrvInit(void) Hlw.ui_flag = true; // Voltage on high if (PinUsed(GPIO_NRG_SEL_INV)) { - SetPin(Pin(GPIO_NRG_SEL_INV), GPIO_NRG_SEL); + SetPin(Pin(GPIO_NRG_SEL_INV), AGPIO(GPIO_NRG_SEL)); Hlw.ui_flag = false; // Voltage on low }