From 0464bd364d9fbe0ca599e73459f629178d053a49 Mon Sep 17 00:00:00 2001 From: Mickael Gaillard Date: Sun, 26 Apr 2020 19:35:11 +0200 Subject: [PATCH 01/40] use builtin function for readBuffer Signed-off-by: Mickael Gaillard --- tasmota/xsns_27_apds9960.ino | 52 +++--------------------------------- 1 file changed, 3 insertions(+), 49 deletions(-) diff --git a/tasmota/xsns_27_apds9960.ino b/tasmota/xsns_27_apds9960.ino index e55deb276..1efef4680 100644 --- a/tasmota/xsns_27_apds9960.ino +++ b/tasmota/xsns_27_apds9960.ino @@ -333,53 +333,6 @@ uint8_t gesture_mode = 1; * Helper functions \******************************************************************************/ -/** - * @brief Writes a single byte to the I2C device (no register) - * - * @param[in] val the 1-byte value to write to the I2C device - * @return True if successful write operation. False otherwise. - */ -bool wireWriteByte(uint8_t val) { - Wire.beginTransmission(APDS9960_I2C_ADDR); - Wire.write(val); - if ( Wire.endTransmission() != 0 ) { - return false; - } - - return true; -} - -/** - * @brief Reads a block (array) of bytes from the I2C device and register - * - * @param[in] reg the register to read from - * @param[out] val pointer to the beginning of the data - * @param[in] len number of bytes to read - * @return Number of bytes read. -1 on read error. - */ -int8_t wireReadDataBlock(uint8_t reg, - uint8_t *val, - uint16_t len) { - unsigned char i = 0; - - /* Indicate which register we want to read from */ - if (!wireWriteByte(reg)) { - return -1; - } - - /* Read block data */ - Wire.requestFrom(APDS9960_I2C_ADDR, len); - while (Wire.available()) { - if (i >= len) { - return -1; - } - val[i] = Wire.read(); - i++; - } - - return i; -} - /** * Taken from the Adafruit-library * @brief Converts the raw R/G/B values to color temperature in degrees @@ -1494,8 +1447,9 @@ int16_t readGesture(void) { /* If there's stuff in the FIFO, read it into our data block */ if (fifo_level > 0) { - bytes_read = wireReadDataBlock(APDS9960_GFIFO_U, (uint8_t*)fifo_data, (fifo_level * 4)); - if (bytes_read == -1) { + bytes_read = (fifo_level * 4); + + if (I2cReadBuffer(APDS9960_I2C_ADDR, APDS9960_GFIFO_U, (uint8_t*)fifo_data, bytes_read)) { return APDS9960_ERROR; } From f8fabfe03502989d52a0b065a05e78be55edf82a Mon Sep 17 00:00:00 2001 From: Mickael Gaillard Date: Sun, 26 Apr 2020 19:44:25 +0200 Subject: [PATCH 02/40] Refactor code Signed-off-by: Mickael Gaillard --- tasmota/xsns_27_apds9960.ino | 140 ++++++++++++++++++++--------------- 1 file changed, 82 insertions(+), 58 deletions(-) diff --git a/tasmota/xsns_27_apds9960.ino b/tasmota/xsns_27_apds9960.ino index 1efef4680..141373801 100644 --- a/tasmota/xsns_27_apds9960.ino +++ b/tasmota/xsns_27_apds9960.ino @@ -33,12 +33,9 @@ * Source: Shawn Hymel (SparkFun Electronics) * Adaption for TASMOTA: Christian Baars * - * I2C Address: 0x39 + * I2C Address: 0x39 - standard address \*********************************************************************************************/ -#define XSNS_27 27 -#define XI2C_21 21 // See I2CDEVICES.md - // #if defined(USE_SHT) || defined(USE_VEML6070) || defined(USE_TSL2561) // #warning **** Turned off conflicting drivers SHT and VEML6070 **** // #ifdef USE_SHT @@ -51,6 +48,9 @@ // #undef USE_TSL2561 // possible address conflict on the I2C-bus // #endif // #endif +#define XSNS_27 27 +#define XI2C_21 21 // See I2CDEVICES.md + #define APDS9960_I2C_ADDR 0x39 @@ -61,7 +61,12 @@ #define APDS9930_CHIPID_1 0x12 // we will check, if someone got an incorrect sensor #define APDS9930_CHIPID_2 0x39 // there are case reports about "accidentially bought" 9930's -#define APDS9960_GESTURE // Enable Gesture feature(2k on flash) + +// TODO() : Move to my_user_config.h file +#define USE_APDS9960_GESTURE // Enable Gesture feature (+2k code) +#define USE_APDS9960_PROXIMITY // Enable Proximity feature (Not use) +#define USE_APDS9960_COLOR // Enable Color feature (Not use) + /* Gesture parameters */ #define GESTURE_THRESHOLD_OUT 10 @@ -71,36 +76,44 @@ #define APDS9960_LONG_RECOVERY 50 // long pause after sensor overload in loops #define APDS9960_MAX_GESTURE_CYCLES 50 // how many FIFO-reads are allowed to prevent crash -const char APDS9960_TAG[] = "APDS9960"; - -#ifdef USE_WEBSERVER -#ifdef APDS9960_GESTURE +// TODO() : Move to Translate file #define D_GESTURE "Gesture" - -const char HTTP_SNS_GESTURE[] PROGMEM = "{s}%s " D_GESTURE "{m}%s{e}"; - -#endif // APDS9960_GESTURE - #define D_COLOR_RED "Red" #define D_COLOR_GREEN "Green" #define D_COLOR_BLUE "Blue" #define D_CCT "CCT" #define D_PROXIMITY "Proximity" +#define D_UNIT_KELVIN "°K" + +/******************************************************************************\ + * constants +\******************************************************************************/ + +const char APDS9960_TAG[] PROGMEM = "APDS9960"; // Only one actualy + +#ifdef USE_WEBSERVER + +#ifdef USE_APDS9960_GESTURE + +const char HTTP_SNS_GESTURE[] PROGMEM = "{s}%s " D_GESTURE "{m}%s{e}"; + +#endif // USE_APDS9960_GESTURE + const char HTTP_SNS_COLOR_RED[] PROGMEM = "{s}%s " D_COLOR_RED "{m}%u{e}"; const char HTTP_SNS_COLOR_GREEN[] PROGMEM = "{s}%s " D_COLOR_GREEN "{m}%u{e}"; const char HTTP_SNS_COLOR_BLUE[] PROGMEM = "{s}%s " D_COLOR_BLUE "{m}%u{e}"; -const char HTTP_SNS_CCT[] PROGMEM = "{s}%s " D_CCT "{m}%u " "K" "{e}"; +const char HTTP_SNS_CCT[] PROGMEM = "{s}%s " D_CCT "{m}%u " D_UNIT_KELVIN "{e}"; const char HTTP_SNS_PROXIMITY[] PROGMEM = "{s}%s " D_PROXIMITY "{m}%u{e}"; #endif // USE_WEBSERVER -/*********************************************************************************************\ +/******************************************************************************\ * APDS9960 * * Programmer : APDS9960 Datasheet and Sparkfun -\*********************************************************************************************/ +\******************************************************************************/ /* Misc parameters */ #define FIFO_PAUSE_TIME 30 // Wait period (ms) between FIFO reads @@ -164,6 +177,7 @@ const char HTTP_SNS_PROXIMITY[] PROGMEM = "{s}%s " D_PROXIMITY "{m}%u{e}"; #define APDS9960_AIEN 0b00010000 #define APDS9960_PIEN 0b00100000 #define APDS9960_GEN 0b01000000 + #define APDS9960_GVALID 0b00000001 /* On/Off definitions */ @@ -220,6 +234,8 @@ const char HTTP_SNS_PROXIMITY[] PROGMEM = "{s}%s " D_PROXIMITY "{m}%u{e}"; #define GWTIME_30_8MS 6 #define GWTIME_39_2MS 7 + + /* Default values */ #define DEFAULT_ATIME 0xdb // 103ms = 0xdb = 219 #define DEFAULT_WTIME 246 // 27ms @@ -251,7 +267,8 @@ const char HTTP_SNS_PROXIMITY[] PROGMEM = "{s}%s " D_PROXIMITY "{m}%u{e}"; #define APDS9960_ERROR 0xFF -#ifdef APDS9960_GESTURE +#ifdef USE_APDS9960_GESTURE + /* Direction definitions */ const char GESTURE_UP[] PROGMEM = "Up"; const char GESTURE_DOWN[] PROGMEM = "Down"; @@ -302,7 +319,7 @@ typedef struct gesture_type { int16_t motion_ = DIR_NONE; } gesture_t; -#endif // APDS9960_GESTURE +#endif // USE_APDS9960_GESTURE typedef struct color_data_type { uint16_t a; // measured ambient @@ -310,23 +327,30 @@ typedef struct color_data_type { uint16_t g; // Green uint16_t b; // Blue uint8_t p; // proximity + uint16_t cct; // calculated color temperature uint16_t lux; // calculated illuminance - atm only from rgb } color_data_t; -/*Members*/ -#ifdef APDS9960_GESTURE +/******************************************************************************\ + * Globals +\******************************************************************************/ + +#ifdef USE_APDS9960_GESTURE + gesture_data_t gesture_data; gesture_t gesture; -#endif // APDS9960_GESTURE + +#endif // USE_APDS9960_GESTURE +char currentGesture[6]; + color_data_t color_data; volatile uint8_t recovery_loop_counter = 0; // count number of stateloops to switch the sensor off, if needed bool APDS9960_overload = false; -char currentGesture[6]; uint8_t APDS9960_aTime = DEFAULT_ATIME; -uint8_t APDS9960type = 0; +uint8_t APDS9960_type = 0; uint8_t gesture_mode = 1; /******************************************************************************\ @@ -365,9 +389,9 @@ void calculateColorTemperature(void) { return; } -/******************************************************************************* +/******************************************************************************\ * Getters and setters for register values - ******************************************************************************/ +\******************************************************************************/ /** * @brief Returns the lower threshold for proximity detection @@ -703,7 +727,7 @@ void setProxPhotoMask(uint8_t mask) { I2cWrite8(APDS9960_I2C_ADDR, APDS9960_CONFIG3, val); } -#ifdef APDS9960_GESTURE +#ifdef USE_APDS9960_GESTURE /** * @brief Gets the entry proximity threshold for gesture sensing @@ -908,7 +932,7 @@ void setGestureWaitTime(uint8_t time) { I2cWrite8(APDS9960_I2C_ADDR, APDS9960_GCONF2, val); } -#endif // APDS9960_GESTURE +#endif // USE_APDS9960_GESTURE /** * @brief Gets the low threshold for ambient light interrupts @@ -1224,7 +1248,7 @@ bool APDS9960_init(void) { I2cWrite8(APDS9960_I2C_ADDR, APDS9960_CONFIG3, DEFAULT_CONFIG3); /* Set default values for gesture sense registers */ -#ifdef APDS9960_GESTURE +#ifdef USE_APDS9960_GESTURE setGestureEnterThresh(DEFAULT_GPENTH); setGestureExitThresh(DEFAULT_GEXTH); @@ -1243,8 +1267,8 @@ bool APDS9960_init(void) { I2cWrite8(APDS9960_I2C_ADDR, APDS9960_GCONF3, DEFAULT_GCONF3); setGestureIntEnable(DEFAULT_GIEN); - -#endif // APDS9960_GESTURE + +#endif // USE_APDS9960_GESTURE disablePower(); // go to sleep @@ -1347,7 +1371,7 @@ void disableProximitySensor(void) { setMode(PROXIMITY, OFF); } -#ifdef APDS9960_GESTURE +#ifdef USE_APDS9960_GESTURE /** * @brief Starts the gesture recognition engine on the APDS-9960 * @@ -1496,7 +1520,7 @@ int16_t readGesture(void) { } } -#endif // APDS9960_GESTURE +#endif // USE_APDS9960_GESTURE /** * Turn the APDS-9960 on @@ -1534,7 +1558,7 @@ void readAllColorAndProximityData(void) { * High-level gesture controls \******************************************************************************/ -#ifdef APDS9960_GESTURE +#ifdef USE_APDS9960_GESTURE /** * @brief Resets all the parameters in the gesture data member @@ -1730,7 +1754,7 @@ void handleGesture(void) { } } -#endif // APDS9960_GESTURE +#endif // USE_APDS9960_GESTURE void APDS9960_adjustATime(void) { // not really used atm // readAllColorAndProximityData(); @@ -1764,7 +1788,7 @@ void APDS9960_adjustATime(void) { // not really used atm delay(20); } -#ifdef APDS9960_GESTURE +#ifdef USE_APDS9960_GESTURE void APDS9960_loop(void) { if (recovery_loop_counter > 0) { @@ -1794,31 +1818,31 @@ void APDS9960_loop(void) { } } -#endif // APDS9960_GESTURE +#endif // USE_APDS9960_GESTURE void APDS9960_detect(void) { - if (APDS9960type || I2cActive(APDS9960_I2C_ADDR)) { return; } + if (APDS9960_type || I2cActive(APDS9960_I2C_ADDR)) { return; } - APDS9960type = I2cRead8(APDS9960_I2C_ADDR, APDS9960_ID); + APDS9960_type = I2cRead8(APDS9960_I2C_ADDR, APDS9960_ID); #ifdef USE_DEBUG_DRIVER // Debug new chip - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DRV: %s Chip %X"), APDS9960_TAG, APDS9960type); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DRV: %s Chip %X"), APDS9960_TAG, APDS9960_type); #endif // USE_DEBUG_DRIVER - if (APDS9960type == APDS9960_CHIPID_1 || APDS9960type == APDS9960_CHIPID_2 || APDS9960type == APDS9960_CHIPID_3) { + if (APDS9960_type == APDS9960_CHIPID_1 || APDS9960_type == APDS9960_CHIPID_2 || APDS9960_type == APDS9960_CHIPID_3) { if (APDS9960_init()) { I2cSetActiveFound(APDS9960_I2C_ADDR, APDS9960_TAG); enableProximitySensor(); -#ifdef APDS9960_GESTURE +#ifdef USE_APDS9960_GESTURE enableGestureSensor(); -#endif // APDS9960_GESTURE +#endif // USE_APDS9960_GESTURE } else { - APDS9960type = 0; + APDS9960_type = 0; } } else { - APDS9960type = 0; + APDS9960_type = 0; } currentGesture[0] = '\0'; @@ -1829,7 +1853,7 @@ void APDS9960_detect(void) { \*********************************************************************************************/ void APDS9960_show(bool json) { - if (!APDS9960type) { return; } + if (!APDS9960_type) { return; } if (!gesture_mode && !APDS9960_overload) { uint16_t ambient; @@ -1843,7 +1867,7 @@ void APDS9960_show(bool json) { calculateColorTemperature(); // and calculate Lux if (json) { - ResponseAppend_P(PSTR(",\"%s\":{\"Red\":%u,\"Green\":%u,\"Blue\":%u,\"Ambient\":%u,\"CCT\":%u,\"Proximity\":%u}"), + ResponseAppend_P(PSTR(",\"%s\":{\"Red\":%u,\"Green\":%u,\"Blue\":%u,\"" D_JSON_ILLUMINANCE "\":%u,\"CCT\":%u,\"Proximity\":%u}"), APDS9960_TAG, color_data.r, color_data.g, @@ -1861,7 +1885,7 @@ void APDS9960_show(bool json) { WSContentSend_PD(HTTP_SNS_PROXIMITY, APDS9960_TAG, color_data.p); #endif // USE_WEBSERVER } -#ifdef APDS9960_GESTURE +#ifdef USE_APDS9960_GESTURE } else { if (currentGesture[0] != '\0') { if (json) { @@ -1873,7 +1897,7 @@ void APDS9960_show(bool json) { currentGesture[0] = '\0'; } } -#endif // APDS9960_GESTURE +#endif // USE_APDS9960_GESTURE } } @@ -1893,16 +1917,16 @@ bool APDS9960CommandSensor(void) { switch (XdrvMailbox.payload) { case 0: // Off -#ifdef APDS9960_GESTURE +#ifdef USE_APDS9960_GESTURE disableGestureSensor(); -#endif // APDS9960_GESTURE +#endif // USE_APDS9960_GESTURE gesture_mode = 0; enableLightSensor(); APDS9960_overload = false; // prevent unwanted re-enabling break; -#ifdef APDS9960_GESTURE +#ifdef USE_APDS9960_GESTURE case 1: // On with default gain of 4x - if (APDS9960type) { + if (APDS9960_type) { setGestureGain(DEFAULT_GGAIN); setProximityGain(DEFAULT_PGAIN); disableLightSensor(); @@ -1911,7 +1935,7 @@ bool APDS9960CommandSensor(void) { } break; case 2: // gain of 2x , needed for some models - if (APDS9960type) { + if (APDS9960_type) { setGestureGain(GGAIN_2X); setProximityGain(PGAIN_2X); disableLightSensor(); @@ -1919,7 +1943,7 @@ bool APDS9960CommandSensor(void) { gesture_mode = 1; } break; -#endif // APDS9960_GESTURE +#endif // USE_APDS9960_GESTURE default: int temp_aTime = (uint8_t)XdrvMailbox.payload; if (temp_aTime > 2 && temp_aTime < 256) { @@ -1946,13 +1970,13 @@ bool Xsns27(uint8_t function) { if (FUNC_INIT == function) { APDS9960_detect(); - } else if (APDS9960type) { + } else if (APDS9960_type) { switch (function) { -#ifdef APDS9960_GESTURE +#ifdef USE_APDS9960_GESTURE case FUNC_EVERY_50_MSECOND: APDS9960_loop(); break; -#endif // APDS9960_GESTURE +#endif // USE_APDS9960_GESTURE case FUNC_COMMAND_SENSOR: if (XSNS_27 == XdrvMailbox.index) { result = APDS9960CommandSensor(); From 0dc154c8e0b018cacdb6014334c9e4845cf45b75 Mon Sep 17 00:00:00 2001 From: Mickael Gaillard Date: Sun, 26 Apr 2020 19:51:20 +0200 Subject: [PATCH 03/40] Reduce footprint Signed-off-by: Mickael Gaillard --- tasmota/xsns_27_apds9960.ino | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tasmota/xsns_27_apds9960.ino b/tasmota/xsns_27_apds9960.ino index 141373801..4c557c28e 100644 --- a/tasmota/xsns_27_apds9960.ino +++ b/tasmota/xsns_27_apds9960.ino @@ -412,7 +412,7 @@ uint8_t getProxIntLowThresh(void) { * * @param[in] threshold the lower proximity threshold */ -void setProxIntLowThresh(uint8_t threshold) { +inline void setProxIntLowThresh(uint8_t threshold) { I2cWrite8(APDS9960_I2C_ADDR, APDS9960_PILT, threshold); } @@ -435,7 +435,7 @@ uint8_t getProxIntHighThresh(void) { * * @param[in] threshold the high proximity threshold */ -void setProxIntHighThresh(uint8_t threshold) { +inline void setProxIntHighThresh(uint8_t threshold) { I2cWrite8(APDS9960_I2C_ADDR, APDS9960_PIHT, threshold); } @@ -748,7 +748,7 @@ uint8_t getGestureEnterThresh(void) { * * @param[in] threshold proximity value needed to start gesture mode */ -void setGestureEnterThresh(uint8_t threshold) { +inline void setGestureEnterThresh(uint8_t threshold) { I2cWrite8(APDS9960_I2C_ADDR, APDS9960_GPENTH, threshold); } @@ -771,7 +771,7 @@ uint8_t getGestureExitThresh(void) { * * @param[in] threshold proximity value needed to end gesture mode */ -void setGestureExitThresh(uint8_t threshold) { +inline void setGestureExitThresh(uint8_t threshold) { I2cWrite8(APDS9960_I2C_ADDR, APDS9960_GEXTH, threshold); } @@ -1285,7 +1285,7 @@ bool APDS9960_init(void) { * * @return Contents of the ENABLE register. 0xFF if error. */ -uint8_t getMode(void) { +inline uint8_t getMode(void) { uint8_t enable_value; /* Read current ENABLE register */ @@ -1526,7 +1526,7 @@ int16_t readGesture(void) { * Turn the APDS-9960 on * */ -void enablePower(void) { +inline void enablePower(void) { setMode(POWER, ON); } @@ -1534,7 +1534,7 @@ void enablePower(void) { * Turn the APDS-9960 off * */ -void disablePower(void) { +inline void disablePower(void) { setMode(POWER, OFF); } @@ -1546,7 +1546,7 @@ void disablePower(void) { /** * @brief Reads the ARGB-Data and fills color_data */ -void readAllColorAndProximityData(void) { +inline void readAllColorAndProximityData(void) { if (I2cReadBuffer(APDS9960_I2C_ADDR, APDS9960_CDATAL, (uint8_t *) &color_data, (uint16_t)9)) { // not absolutely shure, if this is a correct way to do this, but it is very short // we fill the struct byte by byte From a417df17609a61e429ed0df289d9bc52043f9ed3 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <39969427+ascillato2@users.noreply.github.com> Date: Sun, 26 Apr 2020 20:49:46 -0300 Subject: [PATCH 04/40] Fix Humidity conversion on HDC1080 https://github.com/arendst/Tasmota/issues/8194#issuecomment-615749619 --- tasmota/xsns_65_hdc1080.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/xsns_65_hdc1080.ino b/tasmota/xsns_65_hdc1080.ino index 6e834ef90..5b3b159ba 100644 --- a/tasmota/xsns_65_hdc1080.ino +++ b/tasmota/xsns_65_hdc1080.ino @@ -62,7 +62,7 @@ #define HDC1080_CONV_TIME 15 // Assume 6.50 + 6.35 ms + x of conversion delay for this device #define HDC1080_TEMP_MULT 0.0025177 -#define HDC1080_RH_MULT 0.0025177 +#define HDC1080_RH_MULT 0.0015258 #define HDC1080_TEMP_OFFSET 40.0 const char* hdc_type_name = "HDC1080"; From 357e8d71b75f5a1f16bbfe0ca9b6b461f5568927 Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Mon, 27 Apr 2020 07:20:17 +0200 Subject: [PATCH 05/40] fix sml transmit timer --- tasmota/xsns_53_sml.ino | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tasmota/xsns_53_sml.ino b/tasmota/xsns_53_sml.ino index c5f2d3cc2..71b205e6e 100755 --- a/tasmota/xsns_53_sml.ino +++ b/tasmota/xsns_53_sml.ino @@ -2206,7 +2206,10 @@ void SML_Check_Send(void) { char *cp; for (uint32_t cnt=sml_desc_cnt; cnt=0 && script_meter_desc[cnt].txmem) { - if ((sml_100ms_cnt%script_meter_desc[cnt].tsecs)==0) { + //AddLog_P2(LOG_LEVEL_INFO, PSTR("100 ms>> %d - %s - %d"),sml_desc_cnt,script_meter_desc[cnt].txmem,script_meter_desc[cnt].tsecs); + if ((sml_100ms_cnt>=script_meter_desc[cnt].tsecs)) { + sml_100ms_cnt=0; + //AddLog_P2(LOG_LEVEL_INFO, PSTR("100 ms>> 2"),cp); if (script_meter_desc[cnt].max_index>1) { script_meter_desc[cnt].index++; if (script_meter_desc[cnt].index>=script_meter_desc[cnt].max_index) { From 5d9be9a4d04131364f0dda1965e183d93d31b9da Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 27 Apr 2020 10:35:38 +0200 Subject: [PATCH 06/40] Fix pin handling part 1 --- tasmota/support.ino | 6 +++--- tasmota/support_tasmota.ino | 6 +++--- tasmota/xdrv_24_buzzer.ino | 6 +++--- tasmota/xdrv_35_pwm_dimmer.ino | 2 +- tasmota/xnrg_01_hlw8012.ino | 2 +- tasmota/xnrg_04_mcp39f501.ino | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index ebcca3294..09b37d874 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1100,10 +1100,10 @@ void SetPin(uint32_t lpin, uint32_t gpio) { */ } -void DigitalWrite(uint32_t gpio_pin, uint32_t state) +void DigitalWrite(uint32_t gpio_pin, uint32_t index, uint32_t state) { - if (Pin(gpio_pin) < 99) { - digitalWrite(Pin(gpio_pin), state &1); + if (Pin(gpio_pin, index) < 99) { + digitalWrite(Pin(gpio_pin, index), state &1); } } diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 1d66b978c..85a3e1a04 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -166,7 +166,7 @@ void SetLatchingRelay(power_t lpower, uint32_t state) for (uint32_t i = 0; i < devices_present; i++) { uint32_t port = (i << 1) + ((latching_power >> i) &1); - DigitalWrite(GPIO_REL1 +port, bitRead(rel_inverted, port) ? !state : state); + DigitalWrite(GPIO_REL1, port, bitRead(rel_inverted, port) ? !state : state); } } @@ -228,7 +228,7 @@ void SetDevicePower(power_t rpower, uint32_t source) for (uint32_t i = 0; i < devices_present; i++) { power_t state = rpower &1; if (i < MAX_RELAYS) { - DigitalWrite(GPIO_REL1 +i, bitRead(rel_inverted, i) ? !state : state); + DigitalWrite(GPIO_REL1, i, bitRead(rel_inverted, i) ? !state : state); } rpower >>= 1; } @@ -351,7 +351,7 @@ void SetLedPowerIdx(uint32_t led, uint32_t state) } else { led_power &= (0xFF ^ mask); } - DigitalWrite(Pin(GPIO_LED1, led), bitRead(led_inverted, led) ? !state : state); + DigitalWrite(GPIO_LED1, led, bitRead(led_inverted, led) ? !state : state); } #ifdef USE_BUZZER if (led == 0) { diff --git a/tasmota/xdrv_24_buzzer.ino b/tasmota/xdrv_24_buzzer.ino index 45b570f85..7c522fa7e 100644 --- a/tasmota/xdrv_24_buzzer.ino +++ b/tasmota/xdrv_24_buzzer.ino @@ -41,7 +41,7 @@ struct BUZZER { void BuzzerOff(void) { - DigitalWrite(GPIO_BUZZER, Buzzer.inverted); // Buzzer Off + DigitalWrite(GPIO_BUZZER, 0, Buzzer.inverted); // Buzzer Off } //void BuzzerBeep(uint32_t count = 1, uint32_t on = 1, uint32_t off = 1, uint32_t tune = 0, uint32_t mode = 0); @@ -81,7 +81,7 @@ void BuzzerSetStateToLed(uint32_t state) { if (Buzzer.enable && (2 == Buzzer.mode)) { Buzzer.state = (state != 0); - DigitalWrite(GPIO_BUZZER, (Buzzer.inverted) ? !Buzzer.state : Buzzer.state); + DigitalWrite(GPIO_BUZZER, 0, (Buzzer.inverted) ? !Buzzer.state : Buzzer.state); } } @@ -140,7 +140,7 @@ void BuzzerEvery100mSec(void) Buzzer.duration = Buzzer.set[Buzzer.state]; } } - DigitalWrite(GPIO_BUZZER, (Buzzer.inverted) ? !Buzzer.state : Buzzer.state); + DigitalWrite(GPIO_BUZZER, 0, (Buzzer.inverted) ? !Buzzer.state : Buzzer.state); } else { Buzzer.enable = false; } diff --git a/tasmota/xdrv_35_pwm_dimmer.ino b/tasmota/xdrv_35_pwm_dimmer.ino index ac2ceaf55..429bc7421 100644 --- a/tasmota/xdrv_35_pwm_dimmer.ino +++ b/tasmota/xdrv_35_pwm_dimmer.ino @@ -165,7 +165,7 @@ void PWMDimmerSetPoweredOffLed(void) void PWMDimmerSetPower(void) { - DigitalWrite(GPIO_REL1, bitRead(rel_inverted, 0) ? !power : power); + DigitalWrite(GPIO_REL1, 0, bitRead(rel_inverted, 0) ? !power : power); PWMDimmerSetBrightnessLeds(0); PWMDimmerSetPoweredOffLed(); } diff --git a/tasmota/xnrg_01_hlw8012.ino b/tasmota/xnrg_01_hlw8012.ino index 4cbe111cd..04cd20847 100644 --- a/tasmota/xnrg_01_hlw8012.ino +++ b/tasmota/xnrg_01_hlw8012.ino @@ -143,7 +143,7 @@ void HlwEvery200ms(void) if (Hlw.cf1_timer >= 8) { Hlw.cf1_timer = 0; Hlw.select_ui_flag = (Hlw.select_ui_flag) ? false : true; - DigitalWrite(GPIO_NRG_SEL, Hlw.select_ui_flag); + DigitalWrite(GPIO_NRG_SEL, 0, Hlw.select_ui_flag); if (Hlw.cf1_pulse_counter) { cf1_pulse_length = Hlw.cf1_summed_pulse_length / Hlw.cf1_pulse_counter; diff --git a/tasmota/xnrg_04_mcp39f501.ino b/tasmota/xnrg_04_mcp39f501.ino index 92eec2013..3adbd0800 100644 --- a/tasmota/xnrg_04_mcp39f501.ino +++ b/tasmota/xnrg_04_mcp39f501.ino @@ -570,7 +570,7 @@ void McpSnsInit(void) } else { mcp_buffer = (char*)(malloc(MCP_BUFFER_SIZE)); } - DigitalWrite(GPIO_MCP39F5_RST, 1); // MCP enable + DigitalWrite(GPIO_MCP39F5_RST, 0, 1); // MCP enable } else { energy_flg = ENERGY_NONE; } From 24280bcdeac2d977f078dc16ae6a8a2a70d55a26 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 27 Apr 2020 11:54:23 +0200 Subject: [PATCH 07/40] Change pin handling part 2 --- tasmota/support.ino | 4 +++ tasmota/xdrv_10_scripter.ino | 6 +++-- tasmota/xdsp_02_ssd1306.ino | 4 +-- tasmota/xdsp_04_ili9341.ino | 8 +++--- tasmota/xdsp_05_epaper_29.ino | 12 ++++----- tasmota/xdsp_06_epaper_42.ino | 8 +++--- tasmota/xdsp_08_ILI9488.ino | 12 ++++----- tasmota/xdsp_09_SSD1351.ino | 8 +++--- tasmota/xdsp_10_RA8876.ino | 8 +++--- tasmota/xlgt_01_ws2812.ino | 4 +-- tasmota/xlgt_02_my92x1.ino | 6 ++--- tasmota/xlgt_03_sm16716.ino | 22 ++++++++-------- tasmota/xlgt_04_sm2135.ino | 6 ++--- tasmota/xlgt_05_sonoff_l1.ino | 2 +- tasmota/xlgt_06_electriq_moodl.ino | 2 +- tasmota/xnrg_01_hlw8012.ino | 40 ++++++++++++++++-------------- tasmota/xnrg_02_cse7766.ino | 10 +++++--- tasmota/xnrg_03_pzem004t.ino | 4 +-- tasmota/xnrg_04_mcp39f501.ino | 10 ++++---- tasmota/xnrg_05_pzem_ac.ino | 4 +-- tasmota/xnrg_06_pzem_dc.ino | 4 +-- tasmota/xnrg_07_ade7953.ino | 2 +- tasmota/xnrg_08_sdm120.ino | 4 +-- tasmota/xnrg_09_dds2382.ino | 4 +-- tasmota/xnrg_10_sdm630.ino | 4 +-- tasmota/xnrg_11_ddsu666.ino | 4 +-- tasmota/xnrg_12_solaxX1.ino | 6 ++--- tasmota/xnrg_13_fif_le01mr.ino | 4 +-- tasmota/xsns_01_counter.ino | 20 +++++++-------- 29 files changed, 122 insertions(+), 110 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 09b37d874..03bc8d9e9 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1073,6 +1073,10 @@ int ResponseJsonEndEnd(void) * GPIO Module and Template management \*********************************************************************************************/ +#ifndef ARDUINO_ESP8266_RELEASE_2_3_0 // Fix core 2.5.x ISR not in IRAM Exception +uint32_t Pin(uint32_t gpio, uint32_t index) ICACHE_RAM_ATTR; +#endif + uint32_t Pin(uint32_t gpio, uint32_t index = 0); uint32_t Pin(uint32_t gpio, uint32_t index) { //#ifdef ESP8266 diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 370686848..4f1c7428f 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -1573,7 +1573,8 @@ chknext: } if (!strncmp(vname,"pn[",3)) { GetNumericResult(vname+3,OPER_EQU,&fvar,0); - fvar=pin[(uint8_t)fvar]; +// fvar=pin[(uint8_t)fvar]; + fvar=Pin(fvar); // skip ] bracket len++; goto exit; @@ -1582,7 +1583,8 @@ chknext: GetNumericResult(vname+3,OPER_EQU,&fvar,0); uint8_t gpiopin=fvar; for (uint8_t i=0;ibegin(); #ifdef USE_DISPLAY_MODES1TO5 @@ -128,9 +128,9 @@ void Ili9341DisplayOnOff(uint8_t on) { // tft->showDisplay(on); // tft->invertDisplay(on); - if (pin[GPIO_BACKLIGHT] < 99) { - pinMode(pin[GPIO_BACKLIGHT], OUTPUT); - digitalWrite(pin[GPIO_BACKLIGHT], on); + if (Pin(GPIO_BACKLIGHT) < 99) { + pinMode(Pin(GPIO_BACKLIGHT), OUTPUT); + digitalWrite(Pin(GPIO_BACKLIGHT), on); } } diff --git a/tasmota/xdsp_05_epaper_29.ino b/tasmota/xdsp_05_epaper_29.ino index 946fc6343..c46a13229 100644 --- a/tasmota/xdsp_05_epaper_29.ino +++ b/tasmota/xdsp_05_epaper_29.ino @@ -67,13 +67,13 @@ void EpdInitDriver29() epd = new Epd(EPD_WIDTH,EPD_HEIGHT); // whiten display with full update, takes 3 seconds - if ((pin[GPIO_SPI_CS] < 99) && (pin[GPIO_SPI_CLK] < 99) && (pin[GPIO_SPI_MOSI] < 99)) { - epd->Begin(pin[GPIO_SPI_CS],pin[GPIO_SPI_MOSI],pin[GPIO_SPI_CLK]); - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("EPD: HardSPI CS %d, CLK %d, MOSI %d"),pin[GPIO_SPI_CS], pin[GPIO_SPI_CLK], pin[GPIO_SPI_MOSI]); + if ((Pin(GPIO_SPI_CS) < 99) && (Pin(GPIO_SPI_CLK) < 99) && (Pin(GPIO_SPI_MOSI) < 99)) { + epd->Begin(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK)); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("EPD: HardSPI CS %d, CLK %d, MOSI %d"),Pin(GPIO_SPI_CS), Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MOSI)); } - else if ((pin[GPIO_SSPI_CS] < 99) && (pin[GPIO_SSPI_SCLK] < 99) && (pin[GPIO_SSPI_MOSI] < 99)) { - epd->Begin(pin[GPIO_SSPI_CS],pin[GPIO_SSPI_MOSI],pin[GPIO_SSPI_SCLK]); - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("EPD: SoftSPI CS %d, CLK %d, MOSI %d"),pin[GPIO_SSPI_CS], pin[GPIO_SSPI_SCLK], pin[GPIO_SSPI_MOSI]); + else if ((Pin(GPIO_SSPI_CS) < 99) && (Pin(GPIO_SSPI_SCLK) < 99) && (Pin(GPIO_SSPI_MOSI) < 99)) { + epd->Begin(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK)); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("EPD: SoftSPI CS %d, CLK %d, MOSI %d"),Pin(GPIO_SSPI_CS), Pin(GPIO_SSPI_SCLK), Pin(GPIO_SSPI_MOSI)); } else { free(buffer); return; diff --git a/tasmota/xdsp_06_epaper_42.ino b/tasmota/xdsp_06_epaper_42.ino index 7a19ebb7f..b48f159bb 100644 --- a/tasmota/xdsp_06_epaper_42.ino +++ b/tasmota/xdsp_06_epaper_42.ino @@ -65,15 +65,15 @@ void EpdInitDriver42() epd42 = new Epd42(EPD_WIDTH42,EPD_HEIGHT42); #ifdef USE_SPI - if ((pin[GPIO_SSPI_CS]<99) && (pin[GPIO_SSPI_MOSI]<99) && (pin[GPIO_SSPI_SCLK]<99)) { - epd42->Begin(pin[GPIO_SSPI_CS],pin[GPIO_SSPI_MOSI],pin[GPIO_SSPI_SCLK]); + if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)) { + epd42->Begin(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK)); } else { free(buffer); return; } #else - if ((pin[GPIO_SPI_CS]<99) && (pin[GPIO_SPI_MOSI]<99) && (pin[GPIO_SPI_CLK]<99)) { - epd42->Begin(pin[GPIO_SPI_CS],pin[GPIO_SPI_MOSI],pin[GPIO_SPI_CLK]); + if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) { + epd42->Begin(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK)); } else { free(buffer); return; diff --git a/tasmota/xdsp_08_ILI9488.ino b/tasmota/xdsp_08_ILI9488.ino index 84a493fc6..eeb1328dc 100644 --- a/tasmota/xdsp_08_ILI9488.ino +++ b/tasmota/xdsp_08_ILI9488.ino @@ -80,16 +80,16 @@ void ILI9488_InitDriver() bg_color = ILI9488_BLACK; uint8_t bppin=BACKPLANE_PIN; - if (pin[GPIO_BACKLIGHT]<99) { - bppin=pin[GPIO_BACKLIGHT]; + if (Pin(GPIO_BACKLIGHT)<99) { + bppin=Pin(GPIO_BACKLIGHT); } // init renderer - if ((pin[GPIO_SSPI_CS]<99) && (pin[GPIO_SSPI_MOSI]<99) && (pin[GPIO_SSPI_SCLK]<99)){ - ili9488 = new ILI9488(pin[GPIO_SSPI_CS],pin[GPIO_SSPI_MOSI],pin[GPIO_SSPI_SCLK],bppin); + if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)){ + ili9488 = new ILI9488(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK),bppin); } else { - if ((pin[GPIO_SPI_CS]<99) && (pin[GPIO_SPI_MOSI]<99) && (pin[GPIO_SPI_CLK]<99)) { - ili9488 = new ILI9488(pin[GPIO_SPI_CS],pin[GPIO_SPI_MOSI],pin[GPIO_SPI_CLK],bppin); + if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) { + ili9488 = new ILI9488(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK),bppin); } else { return; } diff --git a/tasmota/xdsp_09_SSD1351.ino b/tasmota/xdsp_09_SSD1351.ino index be7138f65..978973c0d 100644 --- a/tasmota/xdsp_09_SSD1351.ino +++ b/tasmota/xdsp_09_SSD1351.ino @@ -60,11 +60,11 @@ void SSD1351_InitDriver() { bg_color = SSD1351_BLACK; // init renderer - if ((pin[GPIO_SSPI_CS]<99) && (pin[GPIO_SSPI_MOSI]<99) && (pin[GPIO_SSPI_SCLK]<99)){ - ssd1351 = new SSD1351(pin[GPIO_SSPI_CS],pin[GPIO_SSPI_MOSI],pin[GPIO_SSPI_SCLK]); + if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)){ + ssd1351 = new SSD1351(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK)); } else { - if ((pin[GPIO_SPI_CS]<99) && (pin[GPIO_SPI_MOSI]<99) && (pin[GPIO_SPI_CLK]<99)){ - ssd1351 = new SSD1351(pin[GPIO_SPI_CS],pin[GPIO_SPI_MOSI],pin[GPIO_SPI_CLK]); + if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) { + ssd1351 = new SSD1351(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK)); } else { return; } diff --git a/tasmota/xdsp_10_RA8876.ino b/tasmota/xdsp_10_RA8876.ino index 88f3ebad2..a91644f3e 100644 --- a/tasmota/xdsp_10_RA8876.ino +++ b/tasmota/xdsp_10_RA8876.ino @@ -72,11 +72,11 @@ void RA8876_InitDriver() bg_color = RA8876_BLACK; // init renderer, must use hardware spi - if ((pin[GPIO_SSPI_CS]<99) && (pin[GPIO_SSPI_MOSI]==13) && (pin[GPIO_SSPI_MISO]==12) && (pin[GPIO_SSPI_SCLK]==14)) { - ra8876 = new RA8876(pin[GPIO_SSPI_CS],pin[GPIO_SSPI_MOSI],pin[GPIO_SSPI_MISO],pin[GPIO_SSPI_SCLK],pin[GPIO_BACKLIGHT]); + if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)==13) && (Pin(GPIO_SSPI_MISO)==12) && (Pin(GPIO_SSPI_SCLK)==14)) { + ra8876 = new RA8876(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_MISO),Pin(GPIO_SSPI_SCLK),Pin(GPIO_BACKLIGHT)); } else { - if ((pin[GPIO_SPI_CS]<99) && (pin[GPIO_SPI_MOSI]==13) && (pin[GPIO_SPI_MISO]==12) && (pin[GPIO_SPI_CLK]==14)) { - ra8876 = new RA8876(pin[GPIO_SPI_CS],pin[GPIO_SPI_MOSI],pin[GPIO_SPI_MISO],pin[GPIO_SPI_CLK],pin[GPIO_BACKLIGHT]); + if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)==13) && (Pin(GPIO_SPI_MISO)==12) && (Pin(GPIO_SPI_CLK)==14)) { + ra8876 = new RA8876(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_MISO),Pin(GPIO_SPI_CLK),Pin(GPIO_BACKLIGHT)); } else { return; } diff --git a/tasmota/xlgt_01_ws2812.ino b/tasmota/xlgt_01_ws2812.ino index f6d332198..fe31f9779 100644 --- a/tasmota/xlgt_01_ws2812.ino +++ b/tasmota/xlgt_01_ws2812.ino @@ -449,10 +449,10 @@ void Ws2812ShowScheme(void) void Ws2812ModuleSelected(void) { - if (pin[GPIO_WS2812] < 99) { // RGB led + if (Pin(GPIO_WS2812) < 99) { // RGB led // For DMA, the Pin is ignored as it uses GPIO3 due to DMA hardware use. - strip = new NeoPixelBus(WS2812_MAX_LEDS, pin[GPIO_WS2812]); + strip = new NeoPixelBus(WS2812_MAX_LEDS, Pin(GPIO_WS2812)); strip->Begin(); Ws2812Clear(); diff --git a/tasmota/xlgt_02_my92x1.ino b/tasmota/xlgt_02_my92x1.ino index 69bccaf36..b129a80b0 100644 --- a/tasmota/xlgt_02_my92x1.ino +++ b/tasmota/xlgt_02_my92x1.ino @@ -115,9 +115,9 @@ bool My92x1SetChannels(void) void My92x1ModuleSelected(void) { - if ((pin[GPIO_DCKI] < 99) && (pin[GPIO_DI] < 99)) { - My92x1.pdi_pin = pin[GPIO_DI]; - My92x1.pdcki_pin = pin[GPIO_DCKI]; + if ((Pin(GPIO_DCKI) < 99) && (Pin(GPIO_DI) < 99)) { + My92x1.pdi_pin = Pin(GPIO_DI); + My92x1.pdcki_pin = Pin(GPIO_DCKI); pinMode(My92x1.pdi_pin, OUTPUT); pinMode(My92x1.pdcki_pin, OUTPUT); diff --git a/tasmota/xlgt_03_sm16716.ino b/tasmota/xlgt_03_sm16716.ino index 8332c80d1..5269749fa 100644 --- a/tasmota/xlgt_03_sm16716.ino +++ b/tasmota/xlgt_03_sm16716.ino @@ -100,9 +100,9 @@ void SM16716_Update(uint8_t duty_r, uint8_t duty_g, uint8_t duty_b) /* bool SM16716_ModuleSelected(void) { - Sm16716.pin_clk = pin[GPIO_SM16716_CLK]; - Sm16716.pin_dat = pin[GPIO_SM16716_DAT]; - Sm16716.pin_sel = pin[GPIO_SM16716_SEL]; + Sm16716.pin_clk = Pin(GPIO_SM16716_CLK); + Sm16716.pin_dat = Pin(GPIO_SM16716_DAT); + Sm16716.pin_sel = Pin(GPIO_SM16716_SEL); DEBUG_DRIVER_LOG(PSTR(D_LOG_SM16716 "ModuleSelected; clk_pin=%d, dat_pin=%d)"), Sm16716.pin_clk, Sm16716.pin_dat); return (Sm16716.pin_clk < 99) && (Sm16716.pin_dat < 99); } @@ -122,9 +122,9 @@ bool Sm16716SetChannels(void) /* // handle any PWM pins, skipping the first 3 values for sm16716 for (uint32_t i = 3; i < Light.subtype; i++) { - if (pin[GPIO_PWM1 +i-3] < 99) { + if (Pin(GPIO_PWM1, i-3) < 99) { //AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Cur_Col%d 10 bits %d, Pwm%d %d"), i, cur_col[i], i+1, curcol); - analogWrite(pin[GPIO_PWM1 +i-3], bitRead(pwm_inverted, i-3) ? Settings.pwm_range - cur_col_10bits[i] : cur_col_10bits[i]); + analogWrite(Pin(GPIO_PWM1, i-3), bitRead(pwm_inverted, i-3) ? Settings.pwm_range - cur_col_10bits[i] : cur_col_10bits[i]); } } */ @@ -138,17 +138,17 @@ bool Sm16716SetChannels(void) void Sm16716ModuleSelected(void) { - if ((pin[GPIO_SM16716_CLK] < 99) && (pin[GPIO_SM16716_DAT] < 99)) { - Sm16716.pin_clk = pin[GPIO_SM16716_CLK]; - Sm16716.pin_dat = pin[GPIO_SM16716_DAT]; - Sm16716.pin_sel = pin[GPIO_SM16716_SEL]; + if ((Pin(GPIO_SM16716_CLK) < 99) && (Pin(GPIO_SM16716_DAT) < 99)) { + Sm16716.pin_clk = Pin(GPIO_SM16716_CLK); + Sm16716.pin_dat = Pin(GPIO_SM16716_DAT); + Sm16716.pin_sel = Pin(GPIO_SM16716_SEL); /* // init PWM for (uint32_t i = 0; i < Light.subtype; i++) { Settings.pwm_value[i] = 0; // Disable direct PWM control - if (pin[GPIO_PWM1 +i] < 99) { - pinMode(pin[GPIO_PWM1 +i], OUTPUT); + if (Pin(GPIO_PWM1, i) < 99) { + pinMode(Pin(GPIO_PWM1, i), OUTPUT); } } */ diff --git a/tasmota/xlgt_04_sm2135.ino b/tasmota/xlgt_04_sm2135.ino index a77108dbb..2c0374123 100644 --- a/tasmota/xlgt_04_sm2135.ino +++ b/tasmota/xlgt_04_sm2135.ino @@ -134,9 +134,9 @@ bool Sm2135SetChannels(void) void Sm2135ModuleSelected(void) { - if ((pin[GPIO_SM2135_CLK] < 99) && (pin[GPIO_SM2135_DAT] < 99)) { - Sm2135.clk = pin[GPIO_SM2135_CLK]; - Sm2135.data = pin[GPIO_SM2135_DAT]; + if ((Pin(GPIO_SM2135_CLK) < 99) && (Pin(GPIO_SM2135_DAT) < 99)) { + Sm2135.clk = Pin(GPIO_SM2135_CLK); + Sm2135.data = Pin(GPIO_SM2135_DAT); pinMode(Sm2135.data, OUTPUT); digitalWrite(Sm2135.data, HIGH); diff --git a/tasmota/xlgt_05_sonoff_l1.ino b/tasmota/xlgt_05_sonoff_l1.ino index 3caf1b06d..1a32fa9ae 100644 --- a/tasmota/xlgt_05_sonoff_l1.ino +++ b/tasmota/xlgt_05_sonoff_l1.ino @@ -221,7 +221,7 @@ bool SnfL1SetChannels(void) void SnfL1ModuleSelected(void) { if (SONOFF_L1 == my_module_type) { - if ((pin[GPIO_RXD] < 99) && (pin[GPIO_TXD] < 99)) { + if ((Pin(GPIO_RXD) < 99) && (Pin(GPIO_TXD) < 99)) { SetSerial(19200, TS_SERIAL_8N1); light_type = LT_RGB; diff --git a/tasmota/xlgt_06_electriq_moodl.ino b/tasmota/xlgt_06_electriq_moodl.ino index 7e972f968..36a1e9e7a 100644 --- a/tasmota/xlgt_06_electriq_moodl.ino +++ b/tasmota/xlgt_06_electriq_moodl.ino @@ -70,7 +70,7 @@ bool ElectriqMoodLSetChannels(void) void ElectriqMoodLModuleSelected(void) { - if (pin[GPIO_ELECTRIQ_MOODL_TX] < 99) { + if (Pin(GPIO_ELECTRIQ_MOODL_TX) < 99) { SetSerial(9600, TS_SERIAL_8N1); light_type = LT_RGBW; light_flg = XLGT_06; diff --git a/tasmota/xnrg_01_hlw8012.ino b/tasmota/xnrg_01_hlw8012.ino index 04cd20847..6a106e985 100644 --- a/tasmota/xnrg_01_hlw8012.ino +++ b/tasmota/xnrg_01_hlw8012.ino @@ -138,7 +138,7 @@ void HlwEvery200ms(void) } } - if (pin[GPIO_NRG_CF1] < 99) { + if (Pin(GPIO_NRG_CF1) < 99) { Hlw.cf1_timer++; if (Hlw.cf1_timer >= 8) { Hlw.cf1_timer = 0; @@ -233,38 +233,42 @@ void HlwSnsInit(void) Hlw.current_ratio = HLW_IREF; } - if (pin[GPIO_NRG_SEL] < 99) { - pinMode(pin[GPIO_NRG_SEL], OUTPUT); - digitalWrite(pin[GPIO_NRG_SEL], Hlw.select_ui_flag); + if (Pin(GPIO_NRG_SEL) < 99) { + pinMode(Pin(GPIO_NRG_SEL), OUTPUT); + digitalWrite(Pin(GPIO_NRG_SEL), Hlw.select_ui_flag); } - if (pin[GPIO_NRG_CF1] < 99) { - pinMode(pin[GPIO_NRG_CF1], INPUT_PULLUP); - attachInterrupt(pin[GPIO_NRG_CF1], HlwCf1Interrupt, FALLING); + if (Pin(GPIO_NRG_CF1) < 99) { + pinMode(Pin(GPIO_NRG_CF1), INPUT_PULLUP); + attachInterrupt(Pin(GPIO_NRG_CF1), HlwCf1Interrupt, FALLING); } - pinMode(pin[GPIO_HLW_CF], INPUT_PULLUP); - attachInterrupt(pin[GPIO_HLW_CF], HlwCfInterrupt, FALLING); + pinMode(Pin(GPIO_HLW_CF), INPUT_PULLUP); + attachInterrupt(Pin(GPIO_HLW_CF), HlwCfInterrupt, FALLING); } void HlwDrvInit(void) { Hlw.model_type = 0; // HLW8012 - if (pin[GPIO_HJL_CF] < 99) { - pin[GPIO_HLW_CF] = pin[GPIO_HJL_CF]; - pin[GPIO_HJL_CF] = 99; + if (Pin(GPIO_HJL_CF) < 99) { +// pin[GPIO_HLW_CF] = pin[GPIO_HJL_CF]; +// pin[GPIO_HJL_CF] = 99; + SetPin(Pin(GPIO_HJL_CF), GPIO_HLW_CF); + SetPin(99, GPIO_HJL_CF); Hlw.model_type = 1; // HJL-01/BL0937 } - if (pin[GPIO_HLW_CF] < 99) { // HLW8012 or HJL-01 based device Power monitor + if (Pin(GPIO_HLW_CF) < 99) { // HLW8012 or HJL-01 based device Power monitor Hlw.ui_flag = true; // Voltage on high - if (pin[GPIO_NRG_SEL_INV] < 99) { - pin[GPIO_NRG_SEL] = pin[GPIO_NRG_SEL_INV]; - pin[GPIO_NRG_SEL_INV] = 99; + if (Pin(GPIO_NRG_SEL_INV) < 99) { +// pin[GPIO_NRG_SEL] = pin[GPIO_NRG_SEL_INV]; +// pin[GPIO_NRG_SEL_INV] = 99; + SetPin(Pin(GPIO_NRG_SEL_INV), GPIO_NRG_SEL); + SetPin(99, GPIO_NRG_SEL_INV); Hlw.ui_flag = false; // Voltage on low } - if (pin[GPIO_NRG_CF1] < 99) { // Voltage and/or Current monitor - if (99 == pin[GPIO_NRG_SEL]) { // Voltage and/or Current selector + if (Pin(GPIO_NRG_CF1) < 99) { // Voltage and/or Current monitor + if (99 == Pin(GPIO_NRG_SEL)) { // Voltage and/or Current selector Energy.current_available = false; // Assume Voltage } } else { diff --git a/tasmota/xnrg_02_cse7766.ino b/tasmota/xnrg_02_cse7766.ino index d7bb93665..13be8d7f9 100644 --- a/tasmota/xnrg_02_cse7766.ino +++ b/tasmota/xnrg_02_cse7766.ino @@ -23,6 +23,8 @@ * CSE7759 and CSE7766 - Energy (Sonoff S31 and Sonoff Pow R2) * HLW8032 - Energy (Blitzwolf SHP5) * + * Needs GPIO_CSE7766_RX only + * * Based on datasheet from http://www.chipsea.com/UploadFiles/2017/08/11144342F01B5662.pdf \*********************************************************************************************/ @@ -223,8 +225,8 @@ void CseEverySecond(void) void CseSnsInit(void) { // Software serial init needs to be done here as earlier (serial) interrupts may lead to Exceptions -// CseSerial = new TasmotaSerial(pin[GPIO_CSE7766_RX], pin[GPIO_CSE7766_TX], 1); - CseSerial = new TasmotaSerial(pin[GPIO_CSE7766_RX], -1, 1); +// CseSerial = new TasmotaSerial(Pin(GPIO_CSE7766_RX), Pin(GPIO_CSE7766_TX), 1); + CseSerial = new TasmotaSerial(Pin(GPIO_CSE7766_RX), -1, 1); if (CseSerial->begin(4800, 2)) { // Fake Software Serial 8E1 by using two stop bits if (CseSerial->hardwareSerial()) { SetSerial(4800, TS_SERIAL_8E1); @@ -243,8 +245,8 @@ void CseDrvInit(void) { Cse.rx_buffer = (uint8_t*)(malloc(CSE_BUFFER_SIZE)); if (Cse.rx_buffer != nullptr) { -// if ((pin[GPIO_CSE7766_RX] < 99) && (pin[GPIO_CSE7766_TX] < 99)) { - if (pin[GPIO_CSE7766_RX] < 99) { +// if ((Pin(GPIO_CSE7766_RX) < 99) && (Pin(GPIO_CSE7766_TX) < 99)) { + if (Pin(GPIO_CSE7766_RX) < 99) { energy_flg = XNRG_02; } } diff --git a/tasmota/xnrg_03_pzem004t.ino b/tasmota/xnrg_03_pzem004t.ino index 466298b0f..d61608aa6 100644 --- a/tasmota/xnrg_03_pzem004t.ino +++ b/tasmota/xnrg_03_pzem004t.ino @@ -241,7 +241,7 @@ void PzemEvery250ms(void) void PzemSnsInit(void) { // Software serial init needs to be done here as earlier (serial) interrupts may lead to Exceptions - PzemSerial = new TasmotaSerial(pin[GPIO_PZEM004_RX], pin[GPIO_PZEM0XX_TX], 1); + PzemSerial = new TasmotaSerial(Pin(GPIO_PZEM004_RX), Pin(GPIO_PZEM0XX_TX), 1); if (PzemSerial->begin(9600)) { if (PzemSerial->hardwareSerial()) { ClaimSerial(); @@ -256,7 +256,7 @@ void PzemSnsInit(void) void PzemDrvInit(void) { - if ((pin[GPIO_PZEM004_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) { // Any device with a Pzem004T + if ((Pin(GPIO_PZEM004_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) { // Any device with a Pzem004T energy_flg = XNRG_03; } } diff --git a/tasmota/xnrg_04_mcp39f501.ino b/tasmota/xnrg_04_mcp39f501.ino index 3adbd0800..3c1e97d09 100644 --- a/tasmota/xnrg_04_mcp39f501.ino +++ b/tasmota/xnrg_04_mcp39f501.ino @@ -562,7 +562,7 @@ void McpEverySecond(void) void McpSnsInit(void) { // Software serial init needs to be done here as earlier (serial) interrupts may lead to Exceptions - McpSerial = new TasmotaSerial(pin[GPIO_MCP39F5_RX], pin[GPIO_MCP39F5_TX], 1); + McpSerial = new TasmotaSerial(Pin(GPIO_MCP39F5_RX), Pin(GPIO_MCP39F5_TX), 1); if (McpSerial->begin(MCP_BAUDRATE)) { if (McpSerial->hardwareSerial()) { ClaimSerial(); @@ -578,10 +578,10 @@ void McpSnsInit(void) void McpDrvInit(void) { - if ((pin[GPIO_MCP39F5_RX] < 99) && (pin[GPIO_MCP39F5_TX] < 99)) { - if (pin[GPIO_MCP39F5_RST] < 99) { - pinMode(pin[GPIO_MCP39F5_RST], OUTPUT); - digitalWrite(pin[GPIO_MCP39F5_RST], 0); // MCP disable - Reset Delta Sigma ADC's + if ((Pin(GPIO_MCP39F5_RX) < 99) && (Pin(GPIO_MCP39F5_TX) < 99)) { + if (Pin(GPIO_MCP39F5_RST) < 99) { + pinMode(Pin(GPIO_MCP39F5_RST), OUTPUT); + digitalWrite(Pin(GPIO_MCP39F5_RST), 0); // MCP disable - Reset Delta Sigma ADC's } mcp_calibrate = 0; mcp_timeout = 2; // Initial wait diff --git a/tasmota/xnrg_05_pzem_ac.ino b/tasmota/xnrg_05_pzem_ac.ino index 86c4355aa..23b4bf9dd 100644 --- a/tasmota/xnrg_05_pzem_ac.ino +++ b/tasmota/xnrg_05_pzem_ac.ino @@ -117,7 +117,7 @@ void PzemAcEverySecond(void) void PzemAcSnsInit(void) { - PzemAcModbus = new TasmotaModbus(pin[GPIO_PZEM016_RX], pin[GPIO_PZEM0XX_TX]); + PzemAcModbus = new TasmotaModbus(Pin(GPIO_PZEM016_RX), Pin(GPIO_PZEM0XX_TX)); uint8_t result = PzemAcModbus->Begin(9600); if (result) { if (2 == result) { ClaimSerial(); } @@ -130,7 +130,7 @@ void PzemAcSnsInit(void) void PzemAcDrvInit(void) { - if ((pin[GPIO_PZEM016_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) { + if ((Pin(GPIO_PZEM016_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) { energy_flg = XNRG_05; } } diff --git a/tasmota/xnrg_06_pzem_dc.ino b/tasmota/xnrg_06_pzem_dc.ino index 961e4f854..5ac58a035 100644 --- a/tasmota/xnrg_06_pzem_dc.ino +++ b/tasmota/xnrg_06_pzem_dc.ino @@ -113,7 +113,7 @@ void PzemDcEverySecond(void) void PzemDcSnsInit(void) { - PzemDcModbus = new TasmotaModbus(pin[GPIO_PZEM017_RX], pin[GPIO_PZEM0XX_TX]); + PzemDcModbus = new TasmotaModbus(Pin(GPIO_PZEM017_RX), Pin(GPIO_PZEM0XX_TX)); uint8_t result = PzemDcModbus->Begin(9600, 2); // Uses two stop bits!! if (result) { if (2 == result) { ClaimSerial(); } @@ -127,7 +127,7 @@ void PzemDcSnsInit(void) void PzemDcDrvInit(void) { - if ((pin[GPIO_PZEM017_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) { + if ((Pin(GPIO_PZEM017_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) { energy_flg = XNRG_06; } } diff --git a/tasmota/xnrg_07_ade7953.ino b/tasmota/xnrg_07_ade7953.ino index 46f2ebd81..1792cc255 100644 --- a/tasmota/xnrg_07_ade7953.ino +++ b/tasmota/xnrg_07_ade7953.ino @@ -199,7 +199,7 @@ void Ade7953EnergyEverySecond(void) void Ade7953DrvInit(void) { - if (pin[GPIO_ADE7953_IRQ] < 99) { // Irq on GPIO16 is not supported... + if (Pin(GPIO_ADE7953_IRQ) < 99) { // Irq on GPIO16 is not supported... delay(100); // Need 100mS to init ADE7953 if (I2cSetDevice(ADE7953_ADDR)) { if (HLW_PREF_PULSE == Settings.energy_power_calibration) { diff --git a/tasmota/xnrg_08_sdm120.ino b/tasmota/xnrg_08_sdm120.ino index e41323a73..2083f348c 100644 --- a/tasmota/xnrg_08_sdm120.ino +++ b/tasmota/xnrg_08_sdm120.ino @@ -176,7 +176,7 @@ void SDM120Every250ms(void) void Sdm120SnsInit(void) { - Sdm120Modbus = new TasmotaModbus(pin[GPIO_SDM120_RX], pin[GPIO_SDM120_TX]); + Sdm120Modbus = new TasmotaModbus(Pin(GPIO_SDM120_RX), Pin(GPIO_SDM120_TX)); uint8_t result = Sdm120Modbus->Begin(SDM120_SPEED); if (result) { if (2 == result) { ClaimSerial(); } @@ -187,7 +187,7 @@ void Sdm120SnsInit(void) void Sdm120DrvInit(void) { - if ((pin[GPIO_SDM120_RX] < 99) && (pin[GPIO_SDM120_TX] < 99)) { + if ((Pin(GPIO_SDM120_RX) < 99) && (Pin(GPIO_SDM120_TX) < 99)) { energy_flg = XNRG_08; } } diff --git a/tasmota/xnrg_09_dds2382.ino b/tasmota/xnrg_09_dds2382.ino index aea1f03ea..a713ded1f 100644 --- a/tasmota/xnrg_09_dds2382.ino +++ b/tasmota/xnrg_09_dds2382.ino @@ -91,7 +91,7 @@ void Dds2382EverySecond(void) void Dds2382SnsInit(void) { - Dds2382Modbus = new TasmotaModbus(pin[GPIO_DDS2382_RX], pin[GPIO_DDS2382_TX]); + Dds2382Modbus = new TasmotaModbus(Pin(GPIO_DDS2382_RX), Pin(GPIO_DDS2382_TX)); uint8_t result = Dds2382Modbus->Begin(DDS2382_SPEED); if (result) { if (2 == result) { ClaimSerial(); } @@ -102,7 +102,7 @@ void Dds2382SnsInit(void) void Dds2382DrvInit(void) { - if ((pin[GPIO_DDS2382_RX] < 99) && (pin[GPIO_DDS2382_TX] < 99)) { + if ((Pin(GPIO_DDS2382_RX) < 99) && (Pin(GPIO_DDS2382_TX) < 99)) { energy_flg = XNRG_09; } } diff --git a/tasmota/xnrg_10_sdm630.ino b/tasmota/xnrg_10_sdm630.ino index 81b8bdcbf..f2c474204 100644 --- a/tasmota/xnrg_10_sdm630.ino +++ b/tasmota/xnrg_10_sdm630.ino @@ -174,7 +174,7 @@ void SDM630Every250ms(void) void Sdm630SnsInit(void) { - Sdm630Modbus = new TasmotaModbus(pin[GPIO_SDM630_RX], pin[GPIO_SDM630_TX]); + Sdm630Modbus = new TasmotaModbus(Pin(GPIO_SDM630_RX), Pin(GPIO_SDM630_TX)); uint8_t result = Sdm630Modbus->Begin(SDM630_SPEED); if (result) { if (2 == result) { ClaimSerial(); } @@ -186,7 +186,7 @@ void Sdm630SnsInit(void) void Sdm630DrvInit(void) { - if ((pin[GPIO_SDM630_RX] < 99) && (pin[GPIO_SDM630_TX] < 99)) { + if ((Pin(GPIO_SDM630_RX) < 99) && (Pin(GPIO_SDM630_TX) < 99)) { energy_flg = XNRG_10; } } diff --git a/tasmota/xnrg_11_ddsu666.ino b/tasmota/xnrg_11_ddsu666.ino index 6299f4f4a..864f8c987 100644 --- a/tasmota/xnrg_11_ddsu666.ino +++ b/tasmota/xnrg_11_ddsu666.ino @@ -133,7 +133,7 @@ void DDSU666Every250ms(void) void Ddsu666SnsInit(void) { - Ddsu666Modbus = new TasmotaModbus(pin[GPIO_DDSU666_RX], pin[GPIO_DDSU666_TX]); + Ddsu666Modbus = new TasmotaModbus(Pin(GPIO_DDSU666_RX), Pin(GPIO_DDSU666_TX)); uint8_t result = Ddsu666Modbus->Begin(DDSU666_SPEED); if (result) { if (2 == result) { ClaimSerial(); } @@ -144,7 +144,7 @@ void Ddsu666SnsInit(void) void Ddsu666DrvInit(void) { - if ((pin[GPIO_DDSU666_RX] < 99) && (pin[GPIO_DDSU666_TX] < 99)) { + if ((Pin(GPIO_DDSU666_RX) < 99) && (Pin(GPIO_DDSU666_TX) < 99)) { energy_flg = XNRG_11; } } diff --git a/tasmota/xnrg_12_solaxX1.ino b/tasmota/xnrg_12_solaxX1.ino index e9da3147d..c04ed8bca 100644 --- a/tasmota/xnrg_12_solaxX1.ino +++ b/tasmota/xnrg_12_solaxX1.ino @@ -406,10 +406,10 @@ void solaxX1250MSecond(void) // Every Second void solaxX1SnsInit(void) { AddLog_P(LOG_LEVEL_DEBUG, PSTR("SX1: Solax X1 Inverter Init")); - DEBUG_SENSOR_LOG(PSTR("SX1: RX pin: %d, TX pin: %d"), pin[GPIO_SOLAXX1_RX], pin[GPIO_SOLAXX1_TX]); + DEBUG_SENSOR_LOG(PSTR("SX1: RX pin: %d, TX pin: %d"), Pin(GPIO_SOLAXX1_RX), Pin(GPIO_SOLAXX1_TX)); protocolStatus.status = 0b00100000; // hasAddress - solaxX1Serial = new TasmotaSerial(pin[GPIO_SOLAXX1_RX], pin[GPIO_SOLAXX1_TX], 1); + solaxX1Serial = new TasmotaSerial(Pin(GPIO_SOLAXX1_RX), Pin(GPIO_SOLAXX1_TX), 1); if (solaxX1Serial->begin(SOLAXX1_SPEED)) { if (solaxX1Serial->hardwareSerial()) { ClaimSerial(); } } else { @@ -419,7 +419,7 @@ void solaxX1SnsInit(void) void solaxX1DrvInit(void) { - if ((pin[GPIO_SOLAXX1_RX] < 99) && (pin[GPIO_SOLAXX1_TX] < 99)) { + if ((Pin(GPIO_SOLAXX1_RX) < 99) && (Pin(GPIO_SOLAXX1_TX) < 99)) { energy_flg = XNRG_12; } } diff --git a/tasmota/xnrg_13_fif_le01mr.ino b/tasmota/xnrg_13_fif_le01mr.ino index 18f45065c..0fcac2658 100644 --- a/tasmota/xnrg_13_fif_le01mr.ino +++ b/tasmota/xnrg_13_fif_le01mr.ino @@ -213,7 +213,7 @@ void FifLEEvery250ms(void) void FifLESnsInit(void) { - FifLEModbus = new TasmotaModbus(pin[GPIO_LE01MR_RX], pin[GPIO_LE01MR_TX]); + FifLEModbus = new TasmotaModbus(Pin(GPIO_LE01MR_RX), Pin(GPIO_LE01MR_TX)); uint8_t result = FifLEModbus->Begin(LE01MR_SPEED); if (result) { if (2 == result) { ClaimSerial(); } @@ -224,7 +224,7 @@ void FifLESnsInit(void) void FifLEDrvInit(void) { - if ((pin[GPIO_LE01MR_RX] < 99) && (pin[GPIO_LE01MR_TX] < 99)) { + if ((Pin(GPIO_LE01MR_RX) < 99) && (Pin(GPIO_LE01MR_TX) < 99)) { energy_flg = XNRG_13; } } diff --git a/tasmota/xsns_01_counter.ino b/tasmota/xsns_01_counter.ino index 663d9413a..4e6db3eb7 100644 --- a/tasmota/xsns_01_counter.ino +++ b/tasmota/xsns_01_counter.ino @@ -59,7 +59,7 @@ void CounterUpdate(uint8_t index) if (Counter.pin_state) { // handle low and high debounce times when configured - if (digitalRead(pin[GPIO_CNTR1 +index]) == bitRead(Counter.pin_state, index)) { + if (digitalRead(Pin(GPIO_CNTR1, index)) == bitRead(Counter.pin_state, index)) { // new pin state to be ignored because debounce time was not met during last IRQ return; } @@ -127,15 +127,15 @@ void CounterInit(void) function counter_callbacks[] = { CounterUpdate1, CounterUpdate2, CounterUpdate3, CounterUpdate4 }; for (uint32_t i = 0; i < MAX_COUNTERS; i++) { - if (pin[GPIO_CNTR1 +i] < 99) { + if (Pin(GPIO_CNTR1, i) < 99) { Counter.any_counter = true; - pinMode(pin[GPIO_CNTR1 +i], bitRead(Counter.no_pullup, i) ? INPUT : INPUT_PULLUP); + pinMode(Pin(GPIO_CNTR1, i), bitRead(Counter.no_pullup, i) ? INPUT : INPUT_PULLUP); if ((0 == Settings.pulse_counter_debounce_low) && (0 == Settings.pulse_counter_debounce_high)) { Counter.pin_state = 0; - attachInterrupt(pin[GPIO_CNTR1 +i], counter_callbacks[i], FALLING); + attachInterrupt(Pin(GPIO_CNTR1, i), counter_callbacks[i], FALLING); } else { Counter.pin_state = 0x8f; - attachInterrupt(pin[GPIO_CNTR1 +i], counter_callbacks[i], CHANGE); + attachInterrupt(Pin(GPIO_CNTR1, i), counter_callbacks[i], CHANGE); } } } @@ -144,7 +144,7 @@ void CounterInit(void) void CounterEverySecond(void) { for (uint32_t i = 0; i < MAX_COUNTERS; i++) { - if (pin[GPIO_CNTR1 +i] < 99) { + if (Pin(GPIO_CNTR1, i) < 99) { if (bitRead(Settings.pulse_counter_type, i)) { uint32_t time = micros() - Counter.timer[i]; if (time > 4200000000) { // 70 minutes @@ -158,7 +158,7 @@ void CounterEverySecond(void) void CounterSaveState(void) { for (uint32_t i = 0; i < MAX_COUNTERS; i++) { - if (pin[GPIO_CNTR1 +i] < 99) { + if (Pin(GPIO_CNTR1, i) < 99) { Settings.pulse_counter[i] = RtcSettings.pulse_counter[i]; } } @@ -169,7 +169,7 @@ void CounterShow(bool json) bool header = false; uint8_t dsxflg = 0; for (uint32_t i = 0; i < MAX_COUNTERS; i++) { - if (pin[GPIO_CNTR1 +i] < 99) { + if (Pin(GPIO_CNTR1, i) < 99) { char counter[33]; if (bitRead(Settings.pulse_counter_type, i)) { dtostrfd((double)RtcSettings.pulse_counter[i] / 1000000, 6, counter); @@ -213,7 +213,7 @@ void CounterShow(bool json) void CmndCounter(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_COUNTERS)) { - if ((XdrvMailbox.data_len > 0) && (pin[GPIO_CNTR1 + XdrvMailbox.index -1] < 99)) { + if ((XdrvMailbox.data_len > 0) && (Pin(GPIO_CNTR1, XdrvMailbox.index -1) < 99)) { if ((XdrvMailbox.data[0] == '-') || (XdrvMailbox.data[0] == '+')) { RtcSettings.pulse_counter[XdrvMailbox.index -1] += XdrvMailbox.payload; Settings.pulse_counter[XdrvMailbox.index -1] += XdrvMailbox.payload; @@ -229,7 +229,7 @@ void CmndCounter(void) void CmndCounterType(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_COUNTERS)) { - if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1) && (pin[GPIO_CNTR1 + XdrvMailbox.index -1] < 99)) { + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1) && (Pin(GPIO_CNTR1, XdrvMailbox.index -1) < 99)) { bitWrite(Settings.pulse_counter_type, XdrvMailbox.index -1, XdrvMailbox.payload &1); RtcSettings.pulse_counter[XdrvMailbox.index -1] = 0; Settings.pulse_counter[XdrvMailbox.index -1] = 0; From c939077514c9efd51de274cf2168c58c45f78d5b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 27 Apr 2020 12:54:07 +0200 Subject: [PATCH 08/40] Change pin handling part 3 --- tasmota/support.ino | 7 ++++++- tasmota/support_button.ino | 4 ++-- tasmota/support_button_v2.ino | 6 +++--- tasmota/support_command.ino | 2 +- tasmota/support_rotary.ino | 2 +- tasmota/support_switch.ino | 6 +++--- tasmota/support_tasmota.ino | 32 +++++++++++++++--------------- tasmota/xdrv_04_light.ino | 10 +++++----- tasmota/xdrv_05_irremote.ino | 10 +++++----- tasmota/xdrv_05_irremote_full.ino | 10 +++++----- tasmota/xdrv_07_domoticz.ino | 2 +- tasmota/xdrv_08_serial_bridge.ino | 2 +- tasmota/xdrv_10_rules.ino | 4 ++-- tasmota/xdrv_12_home_assistant.ino | 4 ++-- tasmota/xdrv_14_mp3.ino | 2 +- tasmota/xdrv_16_tuyamcu.ino | 2 +- tasmota/xdrv_17_rcswitch.ino | 10 +++++----- tasmota/xdrv_23_zigbee_9_impl.ino | 2 +- tasmota/xdrv_24_buzzer.ino | 2 +- tasmota/xdrv_25_A4988_Stepper.ino | 4 ++-- tasmota/xdrv_26_ariluxrf.ino | 6 +++--- tasmota/xdrv_27_shutter.ino | 2 +- tasmota/xdrv_29_deepsleep.ino | 2 +- tasmota/xdrv_31_tasmota_slave.ino | 6 +++--- tasmota/xdrv_33_nrf24l01.ino | 2 +- tasmota/xdrv_35_pwm_dimmer.ino | 6 +++--- tasmota/xdsp_02_ssd1306.ino | 2 +- tasmota/xdsp_04_ili9341.ino | 2 +- tasmota/xdsp_05_epaper_29.ino | 4 ++-- tasmota/xdsp_06_epaper_42.ino | 4 ++-- tasmota/xdsp_08_ILI9488.ino | 6 +++--- tasmota/xdsp_09_SSD1351.ino | 4 ++-- tasmota/xdsp_10_RA8876.ino | 4 ++-- tasmota/xlgt_01_ws2812.ino | 2 +- tasmota/xlgt_02_my92x1.ino | 2 +- tasmota/xlgt_03_sm16716.ino | 6 +++--- tasmota/xlgt_04_sm2135.ino | 2 +- tasmota/xlgt_05_sonoff_l1.ino | 2 +- tasmota/xlgt_06_electriq_moodl.ino | 2 +- tasmota/xnrg_01_hlw8012.ino | 14 ++++++------- tasmota/xnrg_02_cse7766.ino | 4 ++-- tasmota/xnrg_03_pzem004t.ino | 2 +- tasmota/xnrg_04_mcp39f501.ino | 4 ++-- tasmota/xnrg_05_pzem_ac.ino | 2 +- tasmota/xnrg_06_pzem_dc.ino | 2 +- tasmota/xnrg_07_ade7953.ino | 2 +- tasmota/xnrg_08_sdm120.ino | 2 +- tasmota/xnrg_09_dds2382.ino | 2 +- tasmota/xnrg_10_sdm630.ino | 2 +- tasmota/xnrg_11_ddsu666.ino | 2 +- tasmota/xnrg_12_solaxX1.ino | 2 +- tasmota/xnrg_13_fif_le01mr.ino | 2 +- tasmota/xsns_01_counter.ino | 12 +++++------ tasmota/xsns_05_ds18x20.ino | 8 ++++---- tasmota/xsns_06_dht.ino | 4 ++-- tasmota/xsns_07_sht1x.ino | 4 ++-- tasmota/xsns_15_mhz19.ino | 4 ++-- tasmota/xsns_17_senseair.ino | 4 ++-- tasmota/xsns_18_pms5003.ino | 8 ++++---- tasmota/xsns_20_novasds.ino | 4 ++-- tasmota/xsns_22_sr04.ino | 10 +++++----- tasmota/xsns_28_tm1638.ino | 8 ++++---- 62 files changed, 151 insertions(+), 146 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 03bc8d9e9..10e34ada7 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1094,6 +1094,11 @@ uint32_t Pin(uint32_t gpio, uint32_t index) { */ } +boolean PinUsed(uint32_t gpio, uint32_t index = 0); +boolean PinUsed(uint32_t gpio, uint32_t index) { + return (Pin(gpio, index) < 99); +} + void SetPin(uint32_t lpin, uint32_t gpio) { //#ifdef ESP8266 pin[gpio] = lpin; @@ -1106,7 +1111,7 @@ void SetPin(uint32_t lpin, uint32_t gpio) { void DigitalWrite(uint32_t gpio_pin, uint32_t index, uint32_t state) { - if (Pin(gpio_pin, index) < 99) { + if (PinUsed(gpio_pin, index)) { digitalWrite(Pin(gpio_pin, index), state &1); } } diff --git a/tasmota/support_button.ino b/tasmota/support_button.ino index 59b90e39d..659a02348 100644 --- a/tasmota/support_button.ino +++ b/tasmota/support_button.ino @@ -60,7 +60,7 @@ void ButtonInit(void) { Button.present = 0; for (uint32_t i = 0; i < MAX_KEYS; i++) { - if (Pin(GPIO_KEY1, i) < 99) { + if (PinUsed(GPIO_KEY1, i)) { Button.present++; pinMode(Pin(GPIO_KEY1, i), bitRead(Button.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_KEY1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP)); } @@ -135,7 +135,7 @@ void ButtonHandler(void) } else #endif // ESP8266 - if (Pin(GPIO_KEY1, button_index) < 99) { + if (PinUsed(GPIO_KEY1, button_index)) { button_present = 1; button = (digitalRead(Pin(GPIO_KEY1, button_index)) != bitRead(Button.inverted_mask, button_index)); } diff --git a/tasmota/support_button_v2.ino b/tasmota/support_button_v2.ino index 3bb1f9153..4dc94cf13 100644 --- a/tasmota/support_button_v2.ino +++ b/tasmota/support_button_v2.ino @@ -60,7 +60,7 @@ void ButtonInit(void) { Button.present = 0; for (uint32_t i = 0; i < MAX_KEYS; i++) { - if (Pin(GPIO_KEY1, i) < 99) { + if (PinUsed(GPIO_KEY1, i)) { Button.present++; pinMode(Pin(GPIO_KEY1, i), bitRead(Button.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_KEY1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP)); } @@ -132,7 +132,7 @@ void ButtonHandler(void) } else #endif // ESP8266 - if (Pin(GPIO_KEY1, button_index) < 99) { + if (PinUsed(GPIO_KEY1, button_index)) { button_present = 1; button = (digitalRead(Pin(GPIO_KEY1, button_index)) != bitRead(Button.inverted_mask, button_index)); } @@ -266,7 +266,7 @@ void ButtonHandler(void) } else { SendKey(KEY_BUTTON, button_index +1, Button.press_counter[button_index] +9); // 2,3,4 and 5 press send just the key value (11,12,13 and 14) for rules if (0 == button_index) { // BUTTON1 can toggle up to 5 relays if present. If a relay is not present will send out the key value (2,11,12,13 and 14) for rules - if ((Button.press_counter[button_index] > 1 && Pin(GPIO_REL1, Button.press_counter[button_index]-1) < 99) && Button.press_counter[button_index] <= MAX_RELAY_BUTTON1) { + if ((Button.press_counter[button_index] > 1 && PinUsed(GPIO_REL1, Button.press_counter[button_index]-1)) && Button.press_counter[button_index] <= MAX_RELAY_BUTTON1) { ExecuteCommandPower(button_index + Button.press_counter[button_index], POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: Relay%d found on GPIO%d"), Button.press_counter[button_index], Pin(GPIO_REL1, Button.press_counter[button_index]-1)); } diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 2066ee56c..cc8bb92ae 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -1167,7 +1167,7 @@ void CmndTemplate(void) void CmndPwm(void) { if (pwm_present && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_PWMS)) { - if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= Settings.pwm_range) && (Pin(GPIO_PWM1, XdrvMailbox.index -1) < 99)) { + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= Settings.pwm_range) && PinUsed(GPIO_PWM1, XdrvMailbox.index -1)) { Settings.pwm_value[XdrvMailbox.index -1] = XdrvMailbox.payload; analogWrite(Pin(GPIO_PWM1, XdrvMailbox.index -1), bitRead(pwm_inverted, XdrvMailbox.index -1) ? Settings.pwm_range - XdrvMailbox.payload : XdrvMailbox.payload); } diff --git a/tasmota/support_rotary.ino b/tasmota/support_rotary.ino index f93b288c5..25c064a18 100644 --- a/tasmota/support_rotary.ino +++ b/tasmota/support_rotary.ino @@ -80,7 +80,7 @@ bool RotaryButtonPressed(void) void RotaryInit(void) { Rotary.present = 0; - if ((Pin(GPIO_ROT1A) < 99) && (Pin(GPIO_ROT1B) < 99)) { + if (PinUsed(GPIO_ROT1A) && PinUsed(GPIO_ROT1B)) { Rotary.present++; pinMode(Pin(GPIO_ROT1A), INPUT_PULLUP); pinMode(Pin(GPIO_ROT1B), INPUT_PULLUP); diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index 3fba37b3c..64837c74c 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -86,7 +86,7 @@ void SwitchProbe(void) uint8_t force_low = (Settings.switch_debounce % 50) &2; // 52, 102, 152 etc for (uint32_t i = 0; i < MAX_SWITCHES; i++) { - if (Pin(GPIO_SWT1, i) < 99) { + if (PinUsed(GPIO_SWT1, i)) { // Olimex user_switch2.c code to fix 50Hz induced pulses if (1 == digitalRead(Pin(GPIO_SWT1, i))) { @@ -127,7 +127,7 @@ void SwitchInit(void) Switch.present = 0; for (uint32_t i = 0; i < MAX_SWITCHES; i++) { Switch.last_state[i] = 1; // Init global to virtual switch state; - if (Pin(GPIO_SWT1, i) < 99) { + if (PinUsed(GPIO_SWT1, i)) { Switch.present++; pinMode(Pin(GPIO_SWT1, i), bitRead(Switch.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_SWT1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP)); Switch.last_state[i] = digitalRead(Pin(GPIO_SWT1, i)); // Set global now so doesn't change the saved power state on first switch check @@ -148,7 +148,7 @@ void SwitchHandler(uint8_t mode) uint16_t loops_per_second = 1000 / Settings.switch_debounce; for (uint32_t i = 0; i < MAX_SWITCHES; i++) { - if ((Pin(GPIO_SWT1, i) < 99) || (mode)) { + if (PinUsed(GPIO_SWT1, i) || (mode)) { uint8_t button = Switch.virtual_state[i]; uint8_t switchflag = POWER_TOGGLE +1; diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 85a3e1a04..1f2ad385c 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -325,7 +325,7 @@ void SetPowerOnState(void) // Issue #526 and #909 for (uint32_t i = 0; i < devices_present; i++) { if (!Settings.flag3.no_power_feedback) { // SetOption63 - Don't scan relay power state at restart - #5594 and #5663 - if ((i < MAX_RELAYS) && (Pin(GPIO_REL1, i) < 99)) { + if ((i < MAX_RELAYS) && PinUsed(GPIO_REL1, i)) { bitWrite(power, i, digitalRead(Pin(GPIO_REL1, i)) ^ bitRead(rel_inverted, i)); } } @@ -339,11 +339,11 @@ void SetPowerOnState(void) void SetLedPowerIdx(uint32_t led, uint32_t state) { if ((99 == Pin(GPIO_LEDLNK)) && (0 == led)) { // Legacy - LED1 is link led only if LED2 is present - if (Pin(GPIO_LED1, 1) < 99) { + if (PinUsed(GPIO_LED1, 1)) { led = 1; } } - if (Pin(GPIO_LED1, led) < 99) { + if (PinUsed(GPIO_LED1, led)) { uint32_t mask = 1 << led; if (state) { state = 1; @@ -608,7 +608,7 @@ void MqttShowPWMState(void) ResponseAppend_P(PSTR("\"" D_CMND_PWM "\":{")); bool first = true; for (uint32_t i = 0; i < MAX_PWMS; i++) { - if (Pin(GPIO_PWM1, i) < 99) { + if (PinUsed(GPIO_PWM1, i)) { ResponseAppend_P(PSTR("%s\"" D_CMND_PWM "%d\":%d"), first ? "" : ",", i+1, Settings.pwm_value[i]); first = false; } @@ -703,9 +703,9 @@ bool MqttShowSensor(void) int json_data_start = strlen(mqtt_data); for (uint32_t i = 0; i < MAX_SWITCHES; i++) { #ifdef USE_TM1638 - if ((Pin(GPIO_SWT1, i) < 99) || ((Pin(GPIO_TM16CLK) < 99) && (Pin(GPIO_TM16DIO) < 99) && (Pin(GPIO_TM16STB) < 99))) { + if (PinUsed(GPIO_SWT1, i) || (PinUsed(GPIO_TM16CLK) && PinUsed(GPIO_TM16DIO) && PinUsed(GPIO_TM16STB))) { #else - if (Pin(GPIO_SWT1, i) < 99) { + if (PinUsed(GPIO_SWT1, i)) { #endif // USE_TM1638 ResponseAppend_P(PSTR(",\"" D_JSON_SWITCH "%d\":\"%s\""), i +1, GetStateText(SwitchState(i))); } @@ -913,7 +913,7 @@ void Every250mSeconds(void) if (200 == blinks) blinks = 0; // Disable blink } } - if (Settings.ledstate &1 && (Pin(GPIO_LEDLNK) < 99 || !(blinks || restart_flag || ota_state_flag)) ) { + if (Settings.ledstate &1 && (PinUsed(GPIO_LEDLNK) || !(blinks || restart_flag || ota_state_flag)) ) { bool tstate = power & Settings.ledmask; #ifdef ESP8266 if ((SONOFF_TOUCH == my_module_type) || (SONOFF_T11 == my_module_type) || (SONOFF_T12 == my_module_type) || (SONOFF_T13 == my_module_type)) { @@ -1320,7 +1320,7 @@ void SerialInput(void) void ResetPwm(void) { for (uint32_t i = 0; i < MAX_PWMS; i++) { // Basic PWM control only - if (Pin(GPIO_PWM1, i) < 99) { + if (PinUsed(GPIO_PWM1, i)) { analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range : 0); // analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range - Settings.pwm_value[i] : Settings.pwm_value[i]); } @@ -1446,7 +1446,7 @@ void GpioInit(void) analogWriteFreq(Settings.pwm_frequency); // Default is 1000 (core_esp8266_wiring_pwm.c) #ifdef USE_SPI - spi_flg = ((((Pin(GPIO_SPI_CS) < 99) && (Pin(GPIO_SPI_CS) > 14)) || (Pin(GPIO_SPI_CS) < 12)) || (((Pin(GPIO_SPI_DC) < 99) && (Pin(GPIO_SPI_DC) > 14)) || (Pin(GPIO_SPI_DC) < 12))); + spi_flg = (((PinUsed(GPIO_SPI_CS) && (Pin(GPIO_SPI_CS) > 14)) || (Pin(GPIO_SPI_CS) < 12)) || ((PinUsed(GPIO_SPI_DC) && (Pin(GPIO_SPI_DC) > 14)) || (Pin(GPIO_SPI_DC) < 12))); if (spi_flg) { for (uint32_t i = 0; i < GPIO_MAX; i++) { if ((Pin(i) >= 12) && (Pin(i) <=14)) { SetPin(99, i); } @@ -1458,7 +1458,7 @@ void GpioInit(void) my_module.io[14] = GPIO_SPI_CLK; SetPin(14, GPIO_SPI_CLK); } - soft_spi_flg = ((Pin(GPIO_SSPI_CS) < 99) && (Pin(GPIO_SSPI_SCLK) < 99) && ((Pin(GPIO_SSPI_MOSI) < 99) || (Pin(GPIO_SSPI_MOSI) < 99))); + soft_spi_flg = (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_SCLK) && (PinUsed(GPIO_SSPI_MOSI) || PinUsed(GPIO_SSPI_MOSI))); #endif // USE_SPI // Set any non-used GPIO to INPUT - Related to resetPins() in support_legacy_cores.ino @@ -1474,7 +1474,7 @@ void GpioInit(void) } #ifdef USE_I2C - i2c_flg = ((Pin(GPIO_I2C_SCL) < 99) && (Pin(GPIO_I2C_SDA) < 99)); + i2c_flg = (PinUsed(GPIO_I2C_SCL) && PinUsed(GPIO_I2C_SDA)); if (i2c_flg) { Wire.begin(Pin(GPIO_I2C_SDA), Pin(GPIO_I2C_SCL)); } @@ -1506,7 +1506,7 @@ void GpioInit(void) #endif // ESP8266 for (uint32_t i = 0; i < MAX_PWMS; i++) { // Basic PWM control only - if (Pin(GPIO_PWM1, i) < 99) { + if (PinUsed(GPIO_PWM1, i)) { pinMode(Pin(GPIO_PWM1, i), OUTPUT); if (light_type) { // force PWM GPIOs to low or high mode, see #7165 @@ -1519,7 +1519,7 @@ void GpioInit(void) } for (uint32_t i = 0; i < MAX_RELAYS; i++) { - if (Pin(GPIO_REL1, i) < 99) { + if (PinUsed(GPIO_REL1, i)) { pinMode(Pin(GPIO_REL1, i), OUTPUT); devices_present++; #ifdef ESP8266 @@ -1532,7 +1532,7 @@ void GpioInit(void) } for (uint32_t i = 0; i < MAX_LEDS; i++) { - if (Pin(GPIO_LED1, i) < 99) { + if (PinUsed(GPIO_LED1, i)) { #ifdef USE_ARILUX_RF if ((3 == i) && (leds_present < 2) && (99 == Pin(GPIO_ARIRFSEL))) { SetPin(Pin(GPIO_LED4), GPIO_ARIRFSEL); // Legacy support where LED4 was Arilux RF enable @@ -1547,13 +1547,13 @@ void GpioInit(void) #endif } } - if (Pin(GPIO_LEDLNK) < 99) { + if (PinUsed(GPIO_LEDLNK)) { pinMode(Pin(GPIO_LEDLNK), OUTPUT); digitalWrite(Pin(GPIO_LEDLNK), ledlnk_inverted); } #ifdef USE_PWM_DIMMER - if (PWM_DIMMER == my_module_type && Pin(GPIO_REL1) < 99) { devices_present--; } + if (PWM_DIMMER == my_module_type && PinUsed(GPIO_REL1)) { devices_present--; } #endif // USE_PWM_DIMMER ButtonInit(); diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index 5e3afb9d6..9aaa9c9c0 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -1244,7 +1244,7 @@ bool LightModuleInit(void) if (Settings.flag.pwm_control) { // SetOption15 - Switch between commands PWM or COLOR/DIMMER/CT/CHANNEL for (uint32_t i = 0; i < MAX_PWMS; i++) { - if (Pin(GPIO_PWM1, i) < 99) { light_type++; } // Use Dimmer/Color control for all PWM as SetOption15 = 1 + if (PinUsed(GPIO_PWM1, i)) { light_type++; } // Use Dimmer/Color control for all PWM as SetOption15 = 1 } } @@ -1347,12 +1347,12 @@ void LightInit(void) if (light_type < LT_PWM6) { // PWM for (uint32_t i = 0; i < light_type; i++) { Settings.pwm_value[i] = 0; // Disable direct PWM control - if (Pin(GPIO_PWM1, i) < 99) { + if (PinUsed(GPIO_PWM1, i)) { pinMode(Pin(GPIO_PWM1, i), OUTPUT); } } - if (Pin(GPIO_ARIRFRCV) < 99) { - if (Pin(GPIO_ARIRFSEL) < 99) { + if (PinUsed(GPIO_ARIRFRCV)) { + if (PinUsed(GPIO_ARIRFSEL)) { pinMode(Pin(GPIO_ARIRFSEL), OUTPUT); digitalWrite(Pin(GPIO_ARIRFSEL), 1); // Turn off RF } @@ -2133,7 +2133,7 @@ void LightSetOutputs(const uint16_t *cur_col_10) { // now apply the actual PWM values, adjusted and remapped 10-bits range if (light_type < LT_PWM6) { // only for direct PWM lights, not for Tuya, Armtronix... for (uint32_t i = 0; i < (Light.subtype - Light.pwm_offset); i++) { - if (Pin(GPIO_PWM1, i) < 99) { + if (PinUsed(GPIO_PWM1, i)) { //AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Cur_Col%d 10 bits %d"), i, cur_col_10[i]); uint16_t cur_col = cur_col_10[i + Light.pwm_offset]; if (!isChannelCT(i)) { // if CT don't use pwm_min and pwm_max diff --git a/tasmota/xdrv_05_irremote.ino b/tasmota/xdrv_05_irremote.ino index 1a961a0f2..87a51de53 100644 --- a/tasmota/xdrv_05_irremote.ino +++ b/tasmota/xdrv_05_irremote.ino @@ -279,28 +279,28 @@ bool Xdrv05(uint8_t function) { bool result = false; - if ((Pin(GPIO_IRSEND) < 99) || (Pin(GPIO_IRRECV) < 99)) { + if (PinUsed(GPIO_IRSEND) || PinUsed(GPIO_IRRECV)) { switch (function) { case FUNC_PRE_INIT: - if (Pin(GPIO_IRSEND) < 99) { + if (PinUsed(GPIO_IRSEND)) { IrSendInit(); } #ifdef USE_IR_RECEIVE - if (Pin(GPIO_IRRECV) < 99) { + if (PinUsed(GPIO_IRRECV)) { IrReceiveInit(); } #endif // USE_IR_RECEIVE break; case FUNC_EVERY_50_MSECOND: #ifdef USE_IR_RECEIVE - if (Pin(GPIO_IRRECV) < 99) { + if (PinUsed(GPIO_IRRECV)) { IrReceiveCheck(); // check if there's anything on IR side } #endif // USE_IR_RECEIVE irsend_active = false; // re-enable IR reception break; case FUNC_COMMAND: - if (Pin(GPIO_IRSEND) < 99) { + if (PinUsed(GPIO_IRSEND)) { result = DecodeCommand(kIrRemoteCommands, IrRemoteCommand); } break; diff --git a/tasmota/xdrv_05_irremote_full.ino b/tasmota/xdrv_05_irremote_full.ino index 83ec56343..60e16b30d 100644 --- a/tasmota/xdrv_05_irremote_full.ino +++ b/tasmota/xdrv_05_irremote_full.ino @@ -635,24 +635,24 @@ bool Xdrv05(uint8_t function) { bool result = false; - if ((Pin(GPIO_IRSEND) < 99) || (Pin(GPIO_IRRECV) < 99)) { + if (PinUsed(GPIO_IRSEND) || PinUsed(GPIO_IRRECV)) { switch (function) { case FUNC_PRE_INIT: - if (Pin(GPIO_IRSEND) < 99) { + if (PinUsed(GPIO_IRSEND)) { IrSendInit(); } - if (Pin(GPIO_IRRECV) < 99) { + if (PinUsed(GPIO_IRRECV)) { IrReceiveInit(); } break; case FUNC_EVERY_50_MSECOND: - if (Pin(GPIO_IRRECV) < 99) { + if (PinUsed(GPIO_IRRECV)) { IrReceiveCheck(); // check if there's anything on IR side } irsend_active = false; // re-enable IR reception break; case FUNC_COMMAND: - if (Pin(GPIO_IRSEND) < 99) { + if (PinUsed(GPIO_IRSEND)) { result = DecodeCommand(kIrRemoteCommands, IrRemoteCommand); } break; diff --git a/tasmota/xdrv_07_domoticz.ino b/tasmota/xdrv_07_domoticz.ino index a5b284fc2..4face9bfb 100644 --- a/tasmota/xdrv_07_domoticz.ino +++ b/tasmota/xdrv_07_domoticz.ino @@ -576,7 +576,7 @@ void HandleDomoticzConfiguration(void) i +1, i, Settings.domoticz_relay_idx[i], i +1, i, Settings.domoticz_key_idx[i]); } - if (Pin(GPIO_SWT1, i) < 99) { + if (PinUsed(GPIO_SWT1, i)) { WSContentSend_P(HTTP_FORM_DOMOTICZ_SWITCH, i +1, i, Settings.domoticz_switch_idx[i]); } diff --git a/tasmota/xdrv_08_serial_bridge.ino b/tasmota/xdrv_08_serial_bridge.ino index 313cc9d6d..a3ae5ae32 100644 --- a/tasmota/xdrv_08_serial_bridge.ino +++ b/tasmota/xdrv_08_serial_bridge.ino @@ -87,7 +87,7 @@ void SerialBridgeInput(void) void SerialBridgeInit(void) { serial_bridge_active = false; - if ((Pin(GPIO_SBR_RX) < 99) && (Pin(GPIO_SBR_TX) < 99)) { + if (PinUsed(GPIO_SBR_RX) && PinUsed(GPIO_SBR_TX)) { SerialBridgeSerial = new TasmotaSerial(Pin(GPIO_SBR_RX), Pin(GPIO_SBR_TX)); if (SerialBridgeSerial->begin(Settings.sbaudrate * 300)) { // Baud rate is stored div 300 so it fits into 16 bits if (SerialBridgeSerial->hardwareSerial()) { diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index cfd633f38..fa5841564 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -580,9 +580,9 @@ void RulesEvery50ms(void) // Boot time SWITCHES Status for (uint32_t i = 0; i < MAX_SWITCHES; i++) { #ifdef USE_TM1638 - if ((Pin(GPIO_SWT1, i) < 99) || ((Pin(GPIO_TM16CLK) < 99) && (Pin(GPIO_TM16DIO) < 99) && (Pin(GPIO_TM16STB) < 99))) { + if (PinUsed(GPIO_SWT1, i) || (PinUsed(GPIO_TM16CLK) && PinUsed(GPIO_TM16DIO) && PinUsed(GPIO_TM16STB))) { #else - if (Pin(GPIO_SWT1, i) < 99) { + if (PinUsed(GPIO_SWT1, i)) { #endif // USE_TM1638 snprintf_P(json_event, sizeof(json_event), PSTR("{\"" D_JSON_SWITCH "%d\":{\"Boot\":%d}}"), i +1, (SwitchState(i))); RulesProcessEvent(json_event); diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index 30d17681c..2a95fa591 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -370,7 +370,7 @@ void HAssAnnounceSwitches(void) uint8_t hold = 0; uint8_t pir = 0; - if (Pin(GPIO_SWT1, switch_index) < 99) { switch_present = 1; } + if (PinUsed(GPIO_SWT1, switch_index)) { switch_present = 1; } if (KeyTopicActive(1) && strcmp(SettingsText(SET_MQTT_SWITCH_TOPIC), mqtt_topic)) // Enable Discovery for Switches only if Switchtopic is set to a custom name { @@ -451,7 +451,7 @@ void HAssAnnounceButtons(void) } else #endif { - if (Pin(GPIO_KEY1, button_index) < 99) { + if (PinUsed(GPIO_KEY1, button_index)) { button_present = 1; } } diff --git a/tasmota/xdrv_14_mp3.ino b/tasmota/xdrv_14_mp3.ino index 3bd722119..ed6beee63 100644 --- a/tasmota/xdrv_14_mp3.ino +++ b/tasmota/xdrv_14_mp3.ino @@ -232,7 +232,7 @@ bool Xdrv14(uint8_t function) { bool result = false; - if (Pin(GPIO_MP3_DFR562) < 99) { + if (PinUsed(GPIO_MP3_DFR562)) { switch (function) { case FUNC_PRE_INIT: MP3PlayerInit(); // init and start communication diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index 8b1bd73bd..bada16061 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -596,7 +596,7 @@ void TuyaNormalPowerModePacketProcess(void) bool TuyaModuleSelected(void) { - if (!(Pin(GPIO_TUYA_RX) < 99) || !(Pin(GPIO_TUYA_TX) < 99)) { // fallback to hardware-serial if not explicitly selected + 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; diff --git a/tasmota/xdrv_17_rcswitch.ino b/tasmota/xdrv_17_rcswitch.ino index 94323db1d..c5013828c 100644 --- a/tasmota/xdrv_17_rcswitch.ino +++ b/tasmota/xdrv_17_rcswitch.ino @@ -81,10 +81,10 @@ void RfReceiveCheck(void) void RfInit(void) { - if (Pin(GPIO_RFSEND) < 99) { + if (PinUsed(GPIO_RFSEND)) { mySwitch.enableTransmit(Pin(GPIO_RFSEND)); } - if (Pin(GPIO_RFRECV) < 99) { + if (PinUsed(GPIO_RFRECV)) { pinMode( Pin(GPIO_RFRECV), INPUT); mySwitch.enableReceive(Pin(GPIO_RFRECV)); } @@ -170,15 +170,15 @@ bool Xdrv17(uint8_t function) { bool result = false; - if ((Pin(GPIO_RFSEND) < 99) || (Pin(GPIO_RFRECV) < 99)) { + if (PinUsed(GPIO_RFSEND) || PinUsed(GPIO_RFRECV)) { switch (function) { case FUNC_EVERY_50_MSECOND: - if (Pin(GPIO_RFRECV) < 99) { + if (PinUsed(GPIO_RFRECV)) { RfReceiveCheck(); } break; case FUNC_COMMAND: - if (Pin(GPIO_RFSEND) < 99) { + if (PinUsed(GPIO_RFSEND)) { result = DecodeCommand(kRfSendCommands, RfSendCommand); } break; diff --git a/tasmota/xdrv_23_zigbee_9_impl.ino b/tasmota/xdrv_23_zigbee_9_impl.ino index e9024299a..983c76cf3 100644 --- a/tasmota/xdrv_23_zigbee_9_impl.ino +++ b/tasmota/xdrv_23_zigbee_9_impl.ino @@ -162,7 +162,7 @@ void ZigbeeInit(void) // AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem1 = %d"), ESP_getFreeHeap()); zigbee.active = false; - if ((Pin(GPIO_ZIGBEE_RX) < 99) && (Pin(GPIO_ZIGBEE_TX) < 99)) { + if (PinUsed(GPIO_ZIGBEE_RX) && PinUsed(GPIO_ZIGBEE_TX)) { AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_ZIGBEE "GPIOs Rx:%d Tx:%d"), Pin(GPIO_ZIGBEE_RX), Pin(GPIO_ZIGBEE_TX)); // if seriallog_level is 0, we allow GPIO 13/15 to switch to Hardware Serial ZigbeeSerial = new TasmotaSerial(Pin(GPIO_ZIGBEE_RX), Pin(GPIO_ZIGBEE_TX), seriallog_level ? 1 : 2, 0, 256); // set a receive buffer of 256 bytes diff --git a/tasmota/xdrv_24_buzzer.ino b/tasmota/xdrv_24_buzzer.ino index 7c522fa7e..f158f3cd9 100644 --- a/tasmota/xdrv_24_buzzer.ino +++ b/tasmota/xdrv_24_buzzer.ino @@ -111,7 +111,7 @@ bool BuzzerPinState(void) void BuzzerInit(void) { - if (Pin(GPIO_BUZZER) < 99) { + if (PinUsed(GPIO_BUZZER)) { pinMode(Pin(GPIO_BUZZER), OUTPUT); BuzzerOff(); } else { diff --git a/tasmota/xdrv_25_A4988_Stepper.ino b/tasmota/xdrv_25_A4988_Stepper.ino index bf75c413f..48f559314 100644 --- a/tasmota/xdrv_25_A4988_Stepper.ino +++ b/tasmota/xdrv_25_A4988_Stepper.ino @@ -93,7 +93,7 @@ void CmndDoTurn(void) { } void CmndSetMIS(void) { - if ((Pin(GPIO_A4988_MS1) < 99) && (Pin(GPIO_A4988_MS2) < 99) && (Pin(GPIO_A4988_MS3) < 99) && (XdrvMailbox.data_len > 0)) { + if (PinUsed(GPIO_A4988_MS1) && PinUsed(GPIO_A4988_MS2) && PinUsed(GPIO_A4988_MS3) && (XdrvMailbox.data_len > 0)) { short newMIS = strtoul(XdrvMailbox.data,nullptr,10); myA4988->setMIS(newMIS); ResponseCmndDone(); @@ -122,7 +122,7 @@ void CmndSetRPM(void) { bool Xdrv25(uint8_t function) { bool result = false; - if ((Pin(GPIO_A4988_DIR) < 99) && (Pin(GPIO_A4988_STP) < 99)) { + if (PinUsed(GPIO_A4988_DIR) && PinUsed(GPIO_A4988_STP)) { switch (function) { case FUNC_INIT: A4988Init(); diff --git a/tasmota/xdrv_26_ariluxrf.ino b/tasmota/xdrv_26_ariluxrf.ino index af3b80ebc..5027dfdcb 100644 --- a/tasmota/xdrv_26_ariluxrf.ino +++ b/tasmota/xdrv_26_ariluxrf.ino @@ -147,7 +147,7 @@ void AriluxRfHandler(void) void AriluxRfInit(void) { - if ((Pin(GPIO_ARIRFRCV) < 99) && (Pin(GPIO_ARIRFSEL) < 99)) { + if (PinUsed(GPIO_ARIRFRCV) && PinUsed(GPIO_ARIRFSEL)) { if (Settings.last_module != Settings.module) { Settings.rf_code[1][6] = 0; Settings.rf_code[1][7] = 0; @@ -162,7 +162,7 @@ void AriluxRfInit(void) void AriluxRfDisable(void) { - if ((Pin(GPIO_ARIRFRCV) < 99) && (Pin(GPIO_ARIRFSEL) < 99)) { + if (PinUsed(GPIO_ARIRFRCV) && PinUsed(GPIO_ARIRFSEL)) { detachInterrupt(Pin(GPIO_ARIRFRCV)); digitalWrite(Pin(GPIO_ARIRFSEL), 1); // Turn off RF } @@ -178,7 +178,7 @@ bool Xdrv26(uint8_t function) switch (function) { case FUNC_EVERY_50_MSECOND: - if (Pin(GPIO_ARIRFRCV) < 99) { AriluxRfHandler(); } + if (PinUsed(GPIO_ARIRFRCV)) { AriluxRfHandler(); } break; case FUNC_EVERY_SECOND: if (10 == uptime) { AriluxRfInit(); } // Needs rest before enabling RF interrupts diff --git a/tasmota/xdrv_27_shutter.ino b/tasmota/xdrv_27_shutter.ino index b2d0609ed..8e001abb9 100644 --- a/tasmota/xdrv_27_shutter.ino +++ b/tasmota/xdrv_27_shutter.ino @@ -201,7 +201,7 @@ void ShutterInit(void) } } else { Shutter.mode = SHT_OFF_ON__OPEN_CLOSE; - if ((Pin(GPIO_PWM1, i) < 99) && (Pin(GPIO_CNTR1, i) < 99)) { + if (PinUsed(GPIO_PWM1, i) && PinUsed(GPIO_CNTR1, i)) { Shutter.mode = SHT_OFF_ON__OPEN_CLOSE_STEPPER; Shutter.pwm_frequency[i] = 0; Shutter.accelerator[i] = 0; diff --git a/tasmota/xdrv_29_deepsleep.ino b/tasmota/xdrv_29_deepsleep.ino index c78a5fbbd..4ac0531db 100644 --- a/tasmota/xdrv_29_deepsleep.ino +++ b/tasmota/xdrv_29_deepsleep.ino @@ -54,7 +54,7 @@ bool DeepSleepEnabled(void) return false; // Disabled } - if (Pin(GPIO_DEEPSLEEP) < 99) { + if (PinUsed(GPIO_DEEPSLEEP)) { pinMode(Pin(GPIO_DEEPSLEEP), INPUT_PULLUP); return (digitalRead(Pin(GPIO_DEEPSLEEP))); // Disable DeepSleep if user holds pin GPIO_DEEPSLEEP low } diff --git a/tasmota/xdrv_31_tasmota_slave.ino b/tasmota/xdrv_31_tasmota_slave.ino index 52a43178a..37b98c897 100644 --- a/tasmota/xdrv_31_tasmota_slave.ino +++ b/tasmota/xdrv_31_tasmota_slave.ino @@ -437,15 +437,15 @@ void TasmotaSlave_Init(void) return; } if (!TSlave.SerialEnabled) { - if ((Pin(GPIO_TASMOTASLAVE_RXD) < 99) && (Pin(GPIO_TASMOTASLAVE_TXD) < 99) && - ((Pin(GPIO_TASMOTASLAVE_RST) < 99) || (Pin(GPIO_TASMOTASLAVE_RST_INV) < 99))) { + if (PinUsed(GPIO_TASMOTASLAVE_RXD) && PinUsed(GPIO_TASMOTASLAVE_TXD) && + (PinUsed(GPIO_TASMOTASLAVE_RST) || PinUsed(GPIO_TASMOTASLAVE_RST_INV))) { TasmotaSlave_Serial = new TasmotaSerial(Pin(GPIO_TASMOTASLAVE_RXD), Pin(GPIO_TASMOTASLAVE_TXD), 1, 0, 200); if (TasmotaSlave_Serial->begin(USE_TASMOTA_SLAVE_SERIAL_SPEED)) { if (TasmotaSlave_Serial->hardwareSerial()) { ClaimSerial(); } TasmotaSlave_Serial->setTimeout(50); - if (Pin(GPIO_TASMOTASLAVE_RST_INV) < 99) { + if (PinUsed(GPIO_TASMOTASLAVE_RST_INV)) { SetPin(Pin(GPIO_TASMOTASLAVE_RST_INV), GPIO_TASMOTASLAVE_RST); SetPin(99, GPIO_TASMOTASLAVE_RST_INV); TSlave.inverted = HIGH; diff --git a/tasmota/xdrv_33_nrf24l01.ino b/tasmota/xdrv_33_nrf24l01.ino index 3e7d8c63d..442bcb4db 100644 --- a/tasmota/xdrv_33_nrf24l01.ino +++ b/tasmota/xdrv_33_nrf24l01.ino @@ -73,7 +73,7 @@ bool NRF24initRadio() bool NRF24Detect(void) { - if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_DC)<99)){ + if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_DC)) { SPI.pins(SCK,MOSI,MISO,-1); if(NRF24initRadio()){ NRF24.chipType = 32; // SPACE diff --git a/tasmota/xdrv_35_pwm_dimmer.ino b/tasmota/xdrv_35_pwm_dimmer.ino index 429bc7421..fd7a9d86b 100644 --- a/tasmota/xdrv_35_pwm_dimmer.ino +++ b/tasmota/xdrv_35_pwm_dimmer.ino @@ -94,7 +94,7 @@ void PWMModulePreInit(void) PWMDimmerSetPoweredOffLed(); // The relay initializes to on. If the power is supposed to be off, turn the relay off. - if (!power && Pin(GPIO_REL1) < 99) digitalWrite(Pin(GPIO_REL1), bitRead(rel_inverted, 0) ? 1 : 0); + if (!power && PinUsed(GPIO_REL1)) digitalWrite(Pin(GPIO_REL1), bitRead(rel_inverted, 0) ? 1 : 0); #ifdef USE_PWM_DIMMER_REMOTE // If remote device mode is enabled, set the device group count to the number of buttons @@ -104,7 +104,7 @@ void PWMModulePreInit(void) device_group_count = 0; for (uint32_t button_index = 0; button_index < MAX_KEYS; button_index++) { - if (Pin(GPIO_KEY1, button_index) < 99) device_group_count++; + if (PinUsed(GPIO_KEY1, button_index)) device_group_count++; } remote_pwm_dimmer_count = device_group_count - 1; @@ -156,7 +156,7 @@ void PWMDimmerSetBrightnessLeds(int32_t operation) void PWMDimmerSetPoweredOffLed(void) { // Set the powered-off LED state. - if (Pin(GPIO_LEDLNK) < 99) { + if (PinUsed(GPIO_LEDLNK)) { bool power_off_led_on = !power && Settings.flag4.powered_off_led; if (ledlnk_inverted) power_off_led_on ^= 1; digitalWrite(Pin(GPIO_LEDLNK), power_off_led_on); diff --git a/tasmota/xdsp_02_ssd1306.ino b/tasmota/xdsp_02_ssd1306.ino index 64ee72794..24700b0af 100644 --- a/tasmota/xdsp_02_ssd1306.ino +++ b/tasmota/xdsp_02_ssd1306.ino @@ -71,7 +71,7 @@ void SSD1306InitDriver(void) } uint8_t reset_pin = -1; - if (Pin(GPIO_OLED_RESET) < 99) { + if (PinUsed(GPIO_OLED_RESET)) { reset_pin = Pin(GPIO_OLED_RESET); } diff --git a/tasmota/xdsp_04_ili9341.ino b/tasmota/xdsp_04_ili9341.ino index 85432de52..f755314c8 100644 --- a/tasmota/xdsp_04_ili9341.ino +++ b/tasmota/xdsp_04_ili9341.ino @@ -128,7 +128,7 @@ void Ili9341DisplayOnOff(uint8_t on) { // tft->showDisplay(on); // tft->invertDisplay(on); - if (Pin(GPIO_BACKLIGHT) < 99) { + if (PinUsed(GPIO_BACKLIGHT)) { pinMode(Pin(GPIO_BACKLIGHT), OUTPUT); digitalWrite(Pin(GPIO_BACKLIGHT), on); } diff --git a/tasmota/xdsp_05_epaper_29.ino b/tasmota/xdsp_05_epaper_29.ino index c46a13229..dc7397221 100644 --- a/tasmota/xdsp_05_epaper_29.ino +++ b/tasmota/xdsp_05_epaper_29.ino @@ -67,11 +67,11 @@ void EpdInitDriver29() epd = new Epd(EPD_WIDTH,EPD_HEIGHT); // whiten display with full update, takes 3 seconds - if ((Pin(GPIO_SPI_CS) < 99) && (Pin(GPIO_SPI_CLK) < 99) && (Pin(GPIO_SPI_MOSI) < 99)) { + if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_CLK) && PinUsed(GPIO_SPI_MOSI)) { epd->Begin(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK)); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("EPD: HardSPI CS %d, CLK %d, MOSI %d"),Pin(GPIO_SPI_CS), Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MOSI)); } - else if ((Pin(GPIO_SSPI_CS) < 99) && (Pin(GPIO_SSPI_SCLK) < 99) && (Pin(GPIO_SSPI_MOSI) < 99)) { + else if (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_SCLK) && PinUsed(GPIO_SSPI_MOSI)) { epd->Begin(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK)); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("EPD: SoftSPI CS %d, CLK %d, MOSI %d"),Pin(GPIO_SSPI_CS), Pin(GPIO_SSPI_SCLK), Pin(GPIO_SSPI_MOSI)); } else { diff --git a/tasmota/xdsp_06_epaper_42.ino b/tasmota/xdsp_06_epaper_42.ino index b48f159bb..fee42db6c 100644 --- a/tasmota/xdsp_06_epaper_42.ino +++ b/tasmota/xdsp_06_epaper_42.ino @@ -65,14 +65,14 @@ void EpdInitDriver42() epd42 = new Epd42(EPD_WIDTH42,EPD_HEIGHT42); #ifdef USE_SPI - if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)) { + if (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_MOSI) && PinUsed(GPIO_SSPI_SCLK)) { epd42->Begin(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK)); } else { free(buffer); return; } #else - if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) { + if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_MOSI) && PinUsed(GPIO_SPI_CLK)) { epd42->Begin(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK)); } else { free(buffer); diff --git a/tasmota/xdsp_08_ILI9488.ino b/tasmota/xdsp_08_ILI9488.ino index eeb1328dc..1dc877e18 100644 --- a/tasmota/xdsp_08_ILI9488.ino +++ b/tasmota/xdsp_08_ILI9488.ino @@ -80,15 +80,15 @@ void ILI9488_InitDriver() bg_color = ILI9488_BLACK; uint8_t bppin=BACKPLANE_PIN; - if (Pin(GPIO_BACKLIGHT)<99) { + if (PinUsed(GPIO_BACKLIGHT)) { bppin=Pin(GPIO_BACKLIGHT); } // init renderer - if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)){ + if (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_MOSI) && PinUsed(GPIO_SSPI_SCLK)) { ili9488 = new ILI9488(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK),bppin); } else { - if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) { + if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_MOSI) && PinUsed(GPIO_SPI_CLK)) { ili9488 = new ILI9488(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK),bppin); } else { return; diff --git a/tasmota/xdsp_09_SSD1351.ino b/tasmota/xdsp_09_SSD1351.ino index 978973c0d..5f3148be6 100644 --- a/tasmota/xdsp_09_SSD1351.ino +++ b/tasmota/xdsp_09_SSD1351.ino @@ -60,10 +60,10 @@ void SSD1351_InitDriver() { bg_color = SSD1351_BLACK; // init renderer - if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)){ + if (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_MOSI) && PinUsed(GPIO_SSPI_SCLK)){ ssd1351 = new SSD1351(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK)); } else { - if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) { + if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_MOSI) && PinUsed(GPIO_SPI_CLK)) { ssd1351 = new SSD1351(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK)); } else { return; diff --git a/tasmota/xdsp_10_RA8876.ino b/tasmota/xdsp_10_RA8876.ino index a91644f3e..9c86ff2d7 100644 --- a/tasmota/xdsp_10_RA8876.ino +++ b/tasmota/xdsp_10_RA8876.ino @@ -72,10 +72,10 @@ void RA8876_InitDriver() bg_color = RA8876_BLACK; // init renderer, must use hardware spi - if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)==13) && (Pin(GPIO_SSPI_MISO)==12) && (Pin(GPIO_SSPI_SCLK)==14)) { + if (PinUsed(GPIO_SSPI_CS) && (Pin(GPIO_SSPI_MOSI)==13) && (Pin(GPIO_SSPI_MISO)==12) && (Pin(GPIO_SSPI_SCLK)==14)) { ra8876 = new RA8876(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_MISO),Pin(GPIO_SSPI_SCLK),Pin(GPIO_BACKLIGHT)); } else { - if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)==13) && (Pin(GPIO_SPI_MISO)==12) && (Pin(GPIO_SPI_CLK)==14)) { + if (PinUsed(GPIO_SPI_CS) && (Pin(GPIO_SPI_MOSI)==13) && (Pin(GPIO_SPI_MISO)==12) && (Pin(GPIO_SPI_CLK)==14)) { ra8876 = new RA8876(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_MISO),Pin(GPIO_SPI_CLK),Pin(GPIO_BACKLIGHT)); } else { return; diff --git a/tasmota/xlgt_01_ws2812.ino b/tasmota/xlgt_01_ws2812.ino index fe31f9779..368567181 100644 --- a/tasmota/xlgt_01_ws2812.ino +++ b/tasmota/xlgt_01_ws2812.ino @@ -449,7 +449,7 @@ void Ws2812ShowScheme(void) void Ws2812ModuleSelected(void) { - if (Pin(GPIO_WS2812) < 99) { // RGB led + if (PinUsed(GPIO_WS2812)) { // RGB led // For DMA, the Pin is ignored as it uses GPIO3 due to DMA hardware use. strip = new NeoPixelBus(WS2812_MAX_LEDS, Pin(GPIO_WS2812)); diff --git a/tasmota/xlgt_02_my92x1.ino b/tasmota/xlgt_02_my92x1.ino index b129a80b0..6d12abf84 100644 --- a/tasmota/xlgt_02_my92x1.ino +++ b/tasmota/xlgt_02_my92x1.ino @@ -115,7 +115,7 @@ bool My92x1SetChannels(void) void My92x1ModuleSelected(void) { - if ((Pin(GPIO_DCKI) < 99) && (Pin(GPIO_DI) < 99)) { + if (PinUsed(GPIO_DCKI) && PinUsed(GPIO_DI)) { My92x1.pdi_pin = Pin(GPIO_DI); My92x1.pdcki_pin = Pin(GPIO_DCKI); diff --git a/tasmota/xlgt_03_sm16716.ino b/tasmota/xlgt_03_sm16716.ino index 5269749fa..314122a8b 100644 --- a/tasmota/xlgt_03_sm16716.ino +++ b/tasmota/xlgt_03_sm16716.ino @@ -122,7 +122,7 @@ bool Sm16716SetChannels(void) /* // handle any PWM pins, skipping the first 3 values for sm16716 for (uint32_t i = 3; i < Light.subtype; i++) { - if (Pin(GPIO_PWM1, i-3) < 99) { + if (PinUsed(GPIO_PWM1, i-3)) { //AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Cur_Col%d 10 bits %d, Pwm%d %d"), i, cur_col[i], i+1, curcol); analogWrite(Pin(GPIO_PWM1, i-3), bitRead(pwm_inverted, i-3) ? Settings.pwm_range - cur_col_10bits[i] : cur_col_10bits[i]); } @@ -138,7 +138,7 @@ bool Sm16716SetChannels(void) void Sm16716ModuleSelected(void) { - if ((Pin(GPIO_SM16716_CLK) < 99) && (Pin(GPIO_SM16716_DAT) < 99)) { + if (PinUsed(GPIO_SM16716_CLK) && PinUsed(GPIO_SM16716_DAT)) { Sm16716.pin_clk = Pin(GPIO_SM16716_CLK); Sm16716.pin_dat = Pin(GPIO_SM16716_DAT); Sm16716.pin_sel = Pin(GPIO_SM16716_SEL); @@ -147,7 +147,7 @@ void Sm16716ModuleSelected(void) // init PWM for (uint32_t i = 0; i < Light.subtype; i++) { Settings.pwm_value[i] = 0; // Disable direct PWM control - if (Pin(GPIO_PWM1, i) < 99) { + if (PinUsed(GPIO_PWM1, i)) { pinMode(Pin(GPIO_PWM1, i), OUTPUT); } } diff --git a/tasmota/xlgt_04_sm2135.ino b/tasmota/xlgt_04_sm2135.ino index 2c0374123..e262395a8 100644 --- a/tasmota/xlgt_04_sm2135.ino +++ b/tasmota/xlgt_04_sm2135.ino @@ -134,7 +134,7 @@ bool Sm2135SetChannels(void) void Sm2135ModuleSelected(void) { - if ((Pin(GPIO_SM2135_CLK) < 99) && (Pin(GPIO_SM2135_DAT) < 99)) { + if (PinUsed(GPIO_SM2135_CLK) && PinUsed(GPIO_SM2135_DAT)) { Sm2135.clk = Pin(GPIO_SM2135_CLK); Sm2135.data = Pin(GPIO_SM2135_DAT); diff --git a/tasmota/xlgt_05_sonoff_l1.ino b/tasmota/xlgt_05_sonoff_l1.ino index 1a32fa9ae..295330142 100644 --- a/tasmota/xlgt_05_sonoff_l1.ino +++ b/tasmota/xlgt_05_sonoff_l1.ino @@ -221,7 +221,7 @@ bool SnfL1SetChannels(void) void SnfL1ModuleSelected(void) { if (SONOFF_L1 == my_module_type) { - if ((Pin(GPIO_RXD) < 99) && (Pin(GPIO_TXD) < 99)) { + if (PinUsed(GPIO_RXD) && PinUsed(GPIO_TXD)) { SetSerial(19200, TS_SERIAL_8N1); light_type = LT_RGB; diff --git a/tasmota/xlgt_06_electriq_moodl.ino b/tasmota/xlgt_06_electriq_moodl.ino index 36a1e9e7a..57c493e64 100644 --- a/tasmota/xlgt_06_electriq_moodl.ino +++ b/tasmota/xlgt_06_electriq_moodl.ino @@ -70,7 +70,7 @@ bool ElectriqMoodLSetChannels(void) void ElectriqMoodLModuleSelected(void) { - if (Pin(GPIO_ELECTRIQ_MOODL_TX) < 99) { + if (PinUsed(GPIO_ELECTRIQ_MOODL_TX)) { SetSerial(9600, TS_SERIAL_8N1); light_type = LT_RGBW; light_flg = XLGT_06; diff --git a/tasmota/xnrg_01_hlw8012.ino b/tasmota/xnrg_01_hlw8012.ino index 6a106e985..9a054422e 100644 --- a/tasmota/xnrg_01_hlw8012.ino +++ b/tasmota/xnrg_01_hlw8012.ino @@ -138,7 +138,7 @@ void HlwEvery200ms(void) } } - if (Pin(GPIO_NRG_CF1) < 99) { + if (PinUsed(GPIO_NRG_CF1)) { Hlw.cf1_timer++; if (Hlw.cf1_timer >= 8) { Hlw.cf1_timer = 0; @@ -233,11 +233,11 @@ void HlwSnsInit(void) Hlw.current_ratio = HLW_IREF; } - if (Pin(GPIO_NRG_SEL) < 99) { + if (PinUsed(GPIO_NRG_SEL)) { pinMode(Pin(GPIO_NRG_SEL), OUTPUT); digitalWrite(Pin(GPIO_NRG_SEL), Hlw.select_ui_flag); } - if (Pin(GPIO_NRG_CF1) < 99) { + if (PinUsed(GPIO_NRG_CF1)) { pinMode(Pin(GPIO_NRG_CF1), INPUT_PULLUP); attachInterrupt(Pin(GPIO_NRG_CF1), HlwCf1Interrupt, FALLING); } @@ -248,7 +248,7 @@ void HlwSnsInit(void) void HlwDrvInit(void) { Hlw.model_type = 0; // HLW8012 - if (Pin(GPIO_HJL_CF) < 99) { + if (PinUsed(GPIO_HJL_CF)) { // pin[GPIO_HLW_CF] = pin[GPIO_HJL_CF]; // pin[GPIO_HJL_CF] = 99; SetPin(Pin(GPIO_HJL_CF), GPIO_HLW_CF); @@ -256,10 +256,10 @@ void HlwDrvInit(void) Hlw.model_type = 1; // HJL-01/BL0937 } - if (Pin(GPIO_HLW_CF) < 99) { // HLW8012 or HJL-01 based device Power monitor + if (PinUsed(GPIO_HLW_CF)) { // HLW8012 or HJL-01 based device Power monitor Hlw.ui_flag = true; // Voltage on high - if (Pin(GPIO_NRG_SEL_INV) < 99) { + if (PinUsed(GPIO_NRG_SEL_INV)) { // pin[GPIO_NRG_SEL] = pin[GPIO_NRG_SEL_INV]; // pin[GPIO_NRG_SEL_INV] = 99; SetPin(Pin(GPIO_NRG_SEL_INV), GPIO_NRG_SEL); @@ -267,7 +267,7 @@ void HlwDrvInit(void) Hlw.ui_flag = false; // Voltage on low } - if (Pin(GPIO_NRG_CF1) < 99) { // Voltage and/or Current monitor + if (PinUsed(GPIO_NRG_CF1)) { // Voltage and/or Current monitor if (99 == Pin(GPIO_NRG_SEL)) { // Voltage and/or Current selector Energy.current_available = false; // Assume Voltage } diff --git a/tasmota/xnrg_02_cse7766.ino b/tasmota/xnrg_02_cse7766.ino index 13be8d7f9..dae622845 100644 --- a/tasmota/xnrg_02_cse7766.ino +++ b/tasmota/xnrg_02_cse7766.ino @@ -245,8 +245,8 @@ void CseDrvInit(void) { Cse.rx_buffer = (uint8_t*)(malloc(CSE_BUFFER_SIZE)); if (Cse.rx_buffer != nullptr) { -// if ((Pin(GPIO_CSE7766_RX) < 99) && (Pin(GPIO_CSE7766_TX) < 99)) { - if (Pin(GPIO_CSE7766_RX) < 99) { +// if (PinUsed(GPIO_CSE7766_RX) && PinUsed(GPIO_CSE7766_TX)) { + if (PinUsed(GPIO_CSE7766_RX)) { energy_flg = XNRG_02; } } diff --git a/tasmota/xnrg_03_pzem004t.ino b/tasmota/xnrg_03_pzem004t.ino index d61608aa6..f06b34b0e 100644 --- a/tasmota/xnrg_03_pzem004t.ino +++ b/tasmota/xnrg_03_pzem004t.ino @@ -256,7 +256,7 @@ void PzemSnsInit(void) void PzemDrvInit(void) { - if ((Pin(GPIO_PZEM004_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) { // Any device with a Pzem004T + if (PinUsed(GPIO_PZEM004_RX) && PinUsed(GPIO_PZEM0XX_TX)) { // Any device with a Pzem004T energy_flg = XNRG_03; } } diff --git a/tasmota/xnrg_04_mcp39f501.ino b/tasmota/xnrg_04_mcp39f501.ino index 3c1e97d09..b3f8dbe6c 100644 --- a/tasmota/xnrg_04_mcp39f501.ino +++ b/tasmota/xnrg_04_mcp39f501.ino @@ -578,8 +578,8 @@ void McpSnsInit(void) void McpDrvInit(void) { - if ((Pin(GPIO_MCP39F5_RX) < 99) && (Pin(GPIO_MCP39F5_TX) < 99)) { - if (Pin(GPIO_MCP39F5_RST) < 99) { + if (PinUsed(GPIO_MCP39F5_RX) && PinUsed(GPIO_MCP39F5_TX)) { + if (PinUsed(GPIO_MCP39F5_RST)) { pinMode(Pin(GPIO_MCP39F5_RST), OUTPUT); digitalWrite(Pin(GPIO_MCP39F5_RST), 0); // MCP disable - Reset Delta Sigma ADC's } diff --git a/tasmota/xnrg_05_pzem_ac.ino b/tasmota/xnrg_05_pzem_ac.ino index 23b4bf9dd..bd656a874 100644 --- a/tasmota/xnrg_05_pzem_ac.ino +++ b/tasmota/xnrg_05_pzem_ac.ino @@ -130,7 +130,7 @@ void PzemAcSnsInit(void) void PzemAcDrvInit(void) { - if ((Pin(GPIO_PZEM016_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) { + if (PinUsed(GPIO_PZEM016_RX) && PinUsed(GPIO_PZEM0XX_TX)) { energy_flg = XNRG_05; } } diff --git a/tasmota/xnrg_06_pzem_dc.ino b/tasmota/xnrg_06_pzem_dc.ino index 5ac58a035..444861fb0 100644 --- a/tasmota/xnrg_06_pzem_dc.ino +++ b/tasmota/xnrg_06_pzem_dc.ino @@ -127,7 +127,7 @@ void PzemDcSnsInit(void) void PzemDcDrvInit(void) { - if ((Pin(GPIO_PZEM017_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) { + if (PinUsed(GPIO_PZEM017_RX) && PinUsed(GPIO_PZEM0XX_TX)) { energy_flg = XNRG_06; } } diff --git a/tasmota/xnrg_07_ade7953.ino b/tasmota/xnrg_07_ade7953.ino index 1792cc255..44bec2e59 100644 --- a/tasmota/xnrg_07_ade7953.ino +++ b/tasmota/xnrg_07_ade7953.ino @@ -199,7 +199,7 @@ void Ade7953EnergyEverySecond(void) void Ade7953DrvInit(void) { - if (Pin(GPIO_ADE7953_IRQ) < 99) { // Irq on GPIO16 is not supported... + if (PinUsed(GPIO_ADE7953_IRQ)) { // Irq on GPIO16 is not supported... delay(100); // Need 100mS to init ADE7953 if (I2cSetDevice(ADE7953_ADDR)) { if (HLW_PREF_PULSE == Settings.energy_power_calibration) { diff --git a/tasmota/xnrg_08_sdm120.ino b/tasmota/xnrg_08_sdm120.ino index 2083f348c..93af326f8 100644 --- a/tasmota/xnrg_08_sdm120.ino +++ b/tasmota/xnrg_08_sdm120.ino @@ -187,7 +187,7 @@ void Sdm120SnsInit(void) void Sdm120DrvInit(void) { - if ((Pin(GPIO_SDM120_RX) < 99) && (Pin(GPIO_SDM120_TX) < 99)) { + if (PinUsed(GPIO_SDM120_RX) && PinUsed(GPIO_SDM120_TX)) { energy_flg = XNRG_08; } } diff --git a/tasmota/xnrg_09_dds2382.ino b/tasmota/xnrg_09_dds2382.ino index a713ded1f..a516ea4a8 100644 --- a/tasmota/xnrg_09_dds2382.ino +++ b/tasmota/xnrg_09_dds2382.ino @@ -102,7 +102,7 @@ void Dds2382SnsInit(void) void Dds2382DrvInit(void) { - if ((Pin(GPIO_DDS2382_RX) < 99) && (Pin(GPIO_DDS2382_TX) < 99)) { + if (PinUsed(GPIO_DDS2382_RX) && PinUsed(GPIO_DDS2382_TX)) { energy_flg = XNRG_09; } } diff --git a/tasmota/xnrg_10_sdm630.ino b/tasmota/xnrg_10_sdm630.ino index f2c474204..4bfeecc96 100644 --- a/tasmota/xnrg_10_sdm630.ino +++ b/tasmota/xnrg_10_sdm630.ino @@ -186,7 +186,7 @@ void Sdm630SnsInit(void) void Sdm630DrvInit(void) { - if ((Pin(GPIO_SDM630_RX) < 99) && (Pin(GPIO_SDM630_TX) < 99)) { + if (PinUsed(GPIO_SDM630_RX) && PinUsed(GPIO_SDM630_TX)) { energy_flg = XNRG_10; } } diff --git a/tasmota/xnrg_11_ddsu666.ino b/tasmota/xnrg_11_ddsu666.ino index 864f8c987..87b585d84 100644 --- a/tasmota/xnrg_11_ddsu666.ino +++ b/tasmota/xnrg_11_ddsu666.ino @@ -144,7 +144,7 @@ void Ddsu666SnsInit(void) void Ddsu666DrvInit(void) { - if ((Pin(GPIO_DDSU666_RX) < 99) && (Pin(GPIO_DDSU666_TX) < 99)) { + if (PinUsed(GPIO_DDSU666_RX) && PinUsed(GPIO_DDSU666_TX)) { energy_flg = XNRG_11; } } diff --git a/tasmota/xnrg_12_solaxX1.ino b/tasmota/xnrg_12_solaxX1.ino index c04ed8bca..418a92acb 100644 --- a/tasmota/xnrg_12_solaxX1.ino +++ b/tasmota/xnrg_12_solaxX1.ino @@ -419,7 +419,7 @@ void solaxX1SnsInit(void) void solaxX1DrvInit(void) { - if ((Pin(GPIO_SOLAXX1_RX) < 99) && (Pin(GPIO_SOLAXX1_TX) < 99)) { + if (PinUsed(GPIO_SOLAXX1_RX) && PinUsed(GPIO_SOLAXX1_TX)) { energy_flg = XNRG_12; } } diff --git a/tasmota/xnrg_13_fif_le01mr.ino b/tasmota/xnrg_13_fif_le01mr.ino index 0fcac2658..71e77793a 100644 --- a/tasmota/xnrg_13_fif_le01mr.ino +++ b/tasmota/xnrg_13_fif_le01mr.ino @@ -224,7 +224,7 @@ void FifLESnsInit(void) void FifLEDrvInit(void) { - if ((Pin(GPIO_LE01MR_RX) < 99) && (Pin(GPIO_LE01MR_TX) < 99)) { + if (PinUsed(GPIO_LE01MR_RX) && PinUsed(GPIO_LE01MR_TX)) { energy_flg = XNRG_13; } } diff --git a/tasmota/xsns_01_counter.ino b/tasmota/xsns_01_counter.ino index 4e6db3eb7..fec5791f7 100644 --- a/tasmota/xsns_01_counter.ino +++ b/tasmota/xsns_01_counter.ino @@ -127,7 +127,7 @@ void CounterInit(void) function counter_callbacks[] = { CounterUpdate1, CounterUpdate2, CounterUpdate3, CounterUpdate4 }; for (uint32_t i = 0; i < MAX_COUNTERS; i++) { - if (Pin(GPIO_CNTR1, i) < 99) { + if (PinUsed(GPIO_CNTR1, i)) { Counter.any_counter = true; pinMode(Pin(GPIO_CNTR1, i), bitRead(Counter.no_pullup, i) ? INPUT : INPUT_PULLUP); if ((0 == Settings.pulse_counter_debounce_low) && (0 == Settings.pulse_counter_debounce_high)) { @@ -144,7 +144,7 @@ void CounterInit(void) void CounterEverySecond(void) { for (uint32_t i = 0; i < MAX_COUNTERS; i++) { - if (Pin(GPIO_CNTR1, i) < 99) { + if (PinUsed(GPIO_CNTR1, i)) { if (bitRead(Settings.pulse_counter_type, i)) { uint32_t time = micros() - Counter.timer[i]; if (time > 4200000000) { // 70 minutes @@ -158,7 +158,7 @@ void CounterEverySecond(void) void CounterSaveState(void) { for (uint32_t i = 0; i < MAX_COUNTERS; i++) { - if (Pin(GPIO_CNTR1, i) < 99) { + if (PinUsed(GPIO_CNTR1, i)) { Settings.pulse_counter[i] = RtcSettings.pulse_counter[i]; } } @@ -169,7 +169,7 @@ void CounterShow(bool json) bool header = false; uint8_t dsxflg = 0; for (uint32_t i = 0; i < MAX_COUNTERS; i++) { - if (Pin(GPIO_CNTR1, i) < 99) { + if (PinUsed(GPIO_CNTR1, i)) { char counter[33]; if (bitRead(Settings.pulse_counter_type, i)) { dtostrfd((double)RtcSettings.pulse_counter[i] / 1000000, 6, counter); @@ -213,7 +213,7 @@ void CounterShow(bool json) void CmndCounter(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_COUNTERS)) { - if ((XdrvMailbox.data_len > 0) && (Pin(GPIO_CNTR1, XdrvMailbox.index -1) < 99)) { + if ((XdrvMailbox.data_len > 0) && PinUsed(GPIO_CNTR1, XdrvMailbox.index -1)) { if ((XdrvMailbox.data[0] == '-') || (XdrvMailbox.data[0] == '+')) { RtcSettings.pulse_counter[XdrvMailbox.index -1] += XdrvMailbox.payload; Settings.pulse_counter[XdrvMailbox.index -1] += XdrvMailbox.payload; @@ -229,7 +229,7 @@ void CmndCounter(void) void CmndCounterType(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_COUNTERS)) { - if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1) && (Pin(GPIO_CNTR1, XdrvMailbox.index -1) < 99)) { + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1) && PinUsed(GPIO_CNTR1, XdrvMailbox.index -1)) { bitWrite(Settings.pulse_counter_type, XdrvMailbox.index -1, XdrvMailbox.payload &1); RtcSettings.pulse_counter[XdrvMailbox.index -1] = 0; Settings.pulse_counter[XdrvMailbox.index -1] = 0; diff --git a/tasmota/xsns_05_ds18x20.ino b/tasmota/xsns_05_ds18x20.ino index 046fb11c4..a762014c7 100644 --- a/tasmota/xsns_05_ds18x20.ino +++ b/tasmota/xsns_05_ds18x20.ino @@ -304,10 +304,10 @@ void Ds18x20Init(void) { uint64_t ids[DS18X20_MAX_SENSORS]; - ds18x20_pin = pin[GPIO_DSB]; + ds18x20_pin = Pin(GPIO_DSB); - if (pin[GPIO_DSB_OUT] < 99) { - ds18x20_pin_out = pin[GPIO_DSB_OUT]; + if (PinUsed(GPIO_DSB_OUT)) { + ds18x20_pin_out = Pin(GPIO_DSB_OUT); ds18x20_dual_mode = true; // Dual pins mode as used by Shelly pinMode(ds18x20_pin_out, OUTPUT); pinMode(ds18x20_pin, Settings.flag3.ds18x20_internal_pullup ? INPUT_PULLUP : INPUT); // SetOption74 - Enable internal pullup for single DS18x20 sensor @@ -518,7 +518,7 @@ bool Xsns05(uint8_t function) { bool result = false; - if (pin[GPIO_DSB] < 99) { + if (PinUsed(GPIO_DSB)) { switch (function) { case FUNC_INIT: Ds18x20Init(); diff --git a/tasmota/xsns_06_dht.ino b/tasmota/xsns_06_dht.ino index 2edc4abfa..46fb69fa5 100644 --- a/tasmota/xsns_06_dht.ino +++ b/tasmota/xsns_06_dht.ino @@ -204,8 +204,8 @@ bool DhtPinState() void DhtInit(void) { if (dht_sensors) { - if (pin[GPIO_DHT11_OUT] < 99) { - dht_pin_out = pin[GPIO_DHT11_OUT]; + if (PinUsed(GPIO_DHT11_OUT)) { + dht_pin_out = Pin(GPIO_DHT11_OUT); dht_dual_mode = true; // Dual pins mode as used by Shelly dht_sensors = 1; // We only support one sensor in pseudo mode pinMode(dht_pin_out, OUTPUT); diff --git a/tasmota/xsns_07_sht1x.ino b/tasmota/xsns_07_sht1x.ino index 735802ca2..e58c5553f 100644 --- a/tasmota/xsns_07_sht1x.ino +++ b/tasmota/xsns_07_sht1x.ino @@ -159,8 +159,8 @@ bool ShtRead(void) void ShtDetect(void) { - sht_sda_pin = pin[GPIO_I2C_SDA]; - sht_scl_pin = pin[GPIO_I2C_SCL]; + sht_sda_pin = Pin(GPIO_I2C_SDA); + sht_scl_pin = Pin(GPIO_I2C_SCL); if (ShtRead()) { sht_type = 1; AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_I2C D_SHT1X_FOUND)); diff --git a/tasmota/xsns_15_mhz19.ino b/tasmota/xsns_15_mhz19.ino index 633ca3f59..bc0ee8904 100644 --- a/tasmota/xsns_15_mhz19.ino +++ b/tasmota/xsns_15_mhz19.ino @@ -325,8 +325,8 @@ bool MhzCommandSensor(void) void MhzInit(void) { mhz_type = 0; - if ((pin[GPIO_MHZ_RXD] < 99) && (pin[GPIO_MHZ_TXD] < 99)) { - MhzSerial = new TasmotaSerial(pin[GPIO_MHZ_RXD], pin[GPIO_MHZ_TXD], 1); + if (PinUsed(GPIO_MHZ_RXD) && PinUsed(GPIO_MHZ_TXD)) { + MhzSerial = new TasmotaSerial(Pin(GPIO_MHZ_RXD), Pin(GPIO_MHZ_TXD), 1); if (MhzSerial->begin(9600)) { if (MhzSerial->hardwareSerial()) { ClaimSerial(); } mhz_type = 1; diff --git a/tasmota/xsns_17_senseair.ino b/tasmota/xsns_17_senseair.ino index 60614b4c7..90ba979bb 100644 --- a/tasmota/xsns_17_senseair.ino +++ b/tasmota/xsns_17_senseair.ino @@ -132,8 +132,8 @@ void Senseair250ms(void) // Every 250 mSec void SenseairInit(void) { senseair_type = 0; - if ((pin[GPIO_SAIR_RX] < 99) && (pin[GPIO_SAIR_TX] < 99)) { - SenseairModbus = new TasmotaModbus(pin[GPIO_SAIR_RX], pin[GPIO_SAIR_TX]); + if (PinUsed(GPIO_SAIR_RX) && PinUsed(GPIO_SAIR_TX)) { + SenseairModbus = new TasmotaModbus(Pin(GPIO_SAIR_RX), Pin(GPIO_SAIR_TX)); uint8_t result = SenseairModbus->Begin(SENSEAIR_MODBUS_SPEED); if (result) { if (2 == result) { ClaimSerial(); } diff --git a/tasmota/xsns_18_pms5003.ino b/tasmota/xsns_18_pms5003.ino index 525012f5a..dbac02936 100644 --- a/tasmota/xsns_18_pms5003.ino +++ b/tasmota/xsns_18_pms5003.ino @@ -171,7 +171,7 @@ bool PmsReadData(void) bool PmsCommandSensor(void) { - if ((pin[GPIO_PMS5003_TX] < 99) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32001)) { + if (PinUsed(GPIO_PMS5003_TX) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32001)) { if (XdrvMailbox.payload < MIN_INTERVAL_PERIOD) { // Set Active Mode if interval is less than 60 seconds Settings.pms_wake_interval = 0; @@ -239,12 +239,12 @@ void PmsSecond(void) // Every second void PmsInit(void) { Pms.type = 0; - if (pin[GPIO_PMS5003_RX] < 99) { - PmsSerial = new TasmotaSerial(pin[GPIO_PMS5003_RX], (pin[GPIO_PMS5003_TX] < 99) ? pin[GPIO_PMS5003_TX] : -1, 1); + if (PinUsed(GPIO_PMS5003_RX)) { + PmsSerial = new TasmotaSerial(Pin(GPIO_PMS5003_RX), (PinUsed(GPIO_PMS5003_TX)) ? Pin(GPIO_PMS5003_TX) : -1, 1); if (PmsSerial->begin(9600)) { if (PmsSerial->hardwareSerial()) { ClaimSerial(); } - if (99 == pin[GPIO_PMS5003_TX]) { // setting interval not supported if TX pin not connected + if (99 == Pin(GPIO_PMS5003_TX)) { // setting interval not supported if TX pin not connected Settings.pms_wake_interval = 0; Pms.ready = 1; } diff --git a/tasmota/xsns_20_novasds.ino b/tasmota/xsns_20_novasds.ino index 0b1580dde..ffaee14bc 100644 --- a/tasmota/xsns_20_novasds.ino +++ b/tasmota/xsns_20_novasds.ino @@ -202,8 +202,8 @@ bool NovaSdsCommandSensor(void) void NovaSdsInit(void) { novasds_type = 0; - if (pin[GPIO_SDS0X1_RX] < 99 && pin[GPIO_SDS0X1_TX] < 99) { - NovaSdsSerial = new TasmotaSerial(pin[GPIO_SDS0X1_RX], pin[GPIO_SDS0X1_TX], 1); + if (PinUsed(GPIO_SDS0X1_RX) && PinUsed(GPIO_SDS0X1_TX)) { + NovaSdsSerial = new TasmotaSerial(Pin(GPIO_SDS0X1_RX), Pin(GPIO_SDS0X1_TX), 1); if (NovaSdsSerial->begin(9600)) { if (NovaSdsSerial->hardwareSerial()) { ClaimSerial(); diff --git a/tasmota/xsns_22_sr04.ino b/tasmota/xsns_22_sr04.ino index dd8d87ab1..116729f66 100644 --- a/tasmota/xsns_22_sr04.ino +++ b/tasmota/xsns_22_sr04.ino @@ -40,10 +40,10 @@ TasmotaSerial* sonar_serial = nullptr; uint8_t Sr04TModeDetect(void) { sr04_type = 0; - if (99 == pin[GPIO_SR04_ECHO]) { return sr04_type; } + if (99 == Pin(GPIO_SR04_ECHO)) { return sr04_type; } - int sr04_echo_pin = pin[GPIO_SR04_ECHO]; - int sr04_trig_pin = (pin[GPIO_SR04_TRIG] < 99) ? pin[GPIO_SR04_TRIG] : pin[GPIO_SR04_ECHO]; // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only + int sr04_echo_pin = Pin(GPIO_SR04_ECHO); + int sr04_trig_pin = (PinUsed(GPIO_SR04_TRIG)) ? Pin(GPIO_SR04_TRIG) : Pin(GPIO_SR04_ECHO); // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only sonar_serial = new TasmotaSerial(sr04_echo_pin, sr04_trig_pin, 1); if (sonar_serial->begin(9600,1)) { @@ -62,7 +62,7 @@ uint8_t Sr04TModeDetect(void) delete sonar_serial; sonar_serial = nullptr; if (-1 == sr04_trig_pin) { - sr04_trig_pin = pin[GPIO_SR04_ECHO]; // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only + sr04_trig_pin = Pin(GPIO_SR04_ECHO); // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only } sonar = new NewPing(sr04_trig_pin, sr04_echo_pin, 300); } else { @@ -193,7 +193,7 @@ bool Xsns22(uint8_t function) if (sr04_type) { switch (function) { case FUNC_INIT: - result = (pin[GPIO_SR04_ECHO]<99); + result = (PinUsed(GPIO_SR04_ECHO)); break; case FUNC_EVERY_SECOND: Sr04TReading(); diff --git a/tasmota/xsns_28_tm1638.ino b/tasmota/xsns_28_tm1638.ino index da4de6999..9df220848 100644 --- a/tasmota/xsns_28_tm1638.ino +++ b/tasmota/xsns_28_tm1638.ino @@ -144,10 +144,10 @@ uint8_t Tm1638GetButtons(void) void TmInit(void) { tm1638_type = 0; - if ((pin[GPIO_TM16CLK] < 99) && (pin[GPIO_TM16DIO] < 99) && (pin[GPIO_TM16STB] < 99)) { - tm1638_clock_pin = pin[GPIO_TM16CLK]; - tm1638_data_pin = pin[GPIO_TM16DIO]; - tm1638_strobe_pin = pin[GPIO_TM16STB]; + if (PinUsed(GPIO_TM16CLK) && PinUsed(GPIO_TM16DIO) && PinUsed(GPIO_TM16STB)) { + tm1638_clock_pin = Pin(GPIO_TM16CLK); + tm1638_data_pin = Pin(GPIO_TM16DIO); + tm1638_strobe_pin = Pin(GPIO_TM16STB); pinMode(tm1638_data_pin, OUTPUT); pinMode(tm1638_clock_pin, OUTPUT); From 86f801c349f28cbd6f0b6ca7f1209ff1a01ad8a1 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 27 Apr 2020 16:47:29 +0200 Subject: [PATCH 09/40] Change pin handling part 4/4 --- tasmota/xdrv_10_scripter.ino | 2 +- tasmota/xnrg_01_hlw8012.ino | 4 --- tasmota/xsns_34_hx711.ino | 6 ++-- tasmota/xsns_35_tx20.ino | 20 ++++++------ tasmota/xsns_36_mgc3130.ino | 12 ++++---- tasmota/xsns_37_rfsensor.ino | 10 +++--- tasmota/xsns_38_az7798.ino | 4 +-- tasmota/xsns_39_max31855.ino | 24 +++++++-------- tasmota/xsns_40_pn532.ino | 4 +-- tasmota/xsns_43_hre.ino | 15 +++++---- tasmota/xsns_47_max31865.ino | 12 ++++---- tasmota/xsns_51_rdm6300.ino | 4 +-- tasmota/xsns_52_ibeacon.ino | 4 +-- tasmota/xsns_53_sml.ino | 5 +-- tasmota/xsns_56_hpma.ino | 4 +-- tasmota/xsns_60_GPS.ino | 4 +-- tasmota/xsns_61_MI_NRF24.ino | 60 ++++++++++++++++++------------------ tasmota/xsns_62_MI_HM10.ino | 4 +-- tasmota/xsns_64_hrxl.ino | 7 ++--- tasmota/xsns_67_as3935.ino | 10 +++--- 20 files changed, 105 insertions(+), 110 deletions(-) diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 4f1c7428f..614989ab4 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -1582,7 +1582,7 @@ chknext: if (!strncmp(vname,"pd[",3)) { GetNumericResult(vname+3,OPER_EQU,&fvar,0); uint8_t gpiopin=fvar; - for (uint8_t i=0;i 0; bitcount--) { - uint32_t dpin = (digitalRead(pin[GPIO_TX2X_TXD_BLACK])); + uint32_t dpin = (digitalRead(Pin(GPIO_TX2X_TXD_BLACK))); #ifdef USE_TX23_WIND_SENSOR dpin ^= 1; #endif // USE_TX23_WIND_SENSOR @@ -263,7 +263,7 @@ void TX2xStartRead(void) // 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]); + GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << Pin(GPIO_TX2X_TXD_BLACK)); } bool Tx2xAvailable(void) @@ -338,13 +338,13 @@ void Tx2xRead(void) // TX23 start transmission by pulling down TxD line for at minimum 500ms // so we pull TxD signal to low every 3 seconds tx23_stage = 0; - pinMode(pin[GPIO_TX2X_TXD_BLACK], OUTPUT); - digitalWrite(pin[GPIO_TX2X_TXD_BLACK], LOW); + pinMode(Pin(GPIO_TX2X_TXD_BLACK), OUTPUT); + digitalWrite(Pin(GPIO_TX2X_TXD_BLACK), LOW); } else if ((uptime % TX23_READ_INTERVAL)==1) { // after pulling down TxD: pull-up TxD every x+1 seconds // to trigger TX23 start transmission tx23_stage = 1; // first rising signal is invalid - pinMode(pin[GPIO_TX2X_TXD_BLACK], INPUT_PULLUP); + pinMode(Pin(GPIO_TX2X_TXD_BLACK), INPUT_PULLUP); } #endif // USE_TX23_WIND_SENSOR if (Tx2xAvailable()) { @@ -465,12 +465,12 @@ void Tx2xInit(void) #endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS #ifdef USE_TX23_WIND_SENSOR tx23_stage = 0; - pinMode(pin[GPIO_TX2X_TXD_BLACK], OUTPUT); - digitalWrite(pin[GPIO_TX2X_TXD_BLACK], LOW); + pinMode(Pin(GPIO_TX2X_TXD_BLACK), OUTPUT); + digitalWrite(Pin(GPIO_TX2X_TXD_BLACK), LOW); #else // USE_TX23_WIND_SENSOR - pinMode(pin[GPIO_TX2X_TXD_BLACK], INPUT); + pinMode(Pin(GPIO_TX2X_TXD_BLACK), INPUT); #endif // USE_TX23_WIND_SENSOR - attachInterrupt(pin[GPIO_TX2X_TXD_BLACK], TX2xStartRead, RISING); + attachInterrupt(Pin(GPIO_TX2X_TXD_BLACK), TX2xStartRead, RISING); } int32_t Tx2xNormalize(int32_t value) @@ -582,7 +582,7 @@ bool Xsns35(uint8_t function) { bool result = false; - if (pin[GPIO_TX2X_TXD_BLACK] < 99) { + if (PinUsed(GPIO_TX2X_TXD_BLACK)) { switch (function) { case FUNC_INIT: Tx2xInit(); diff --git a/tasmota/xsns_36_mgc3130.ino b/tasmota/xsns_36_mgc3130.ino index 4dd76155b..036ecf009 100644 --- a/tasmota/xsns_36_mgc3130.ino +++ b/tasmota/xsns_36_mgc3130.ino @@ -39,14 +39,11 @@ #define MGC3130_I2C_ADDR 0x42 -#define MGC3130_xfer pin[GPIO_MGC3130_XFER] -#define MGC3130_reset pin[GPIO_MGC3130_RESET] - - +uint8_t MGC3130_xfer = 0; +uint8_t MGC3130_reset = 0; bool MGC3130_type = false; char MGC3130stype[] = "MGC3130"; - #define MGC3130_SYSTEM_STATUS 0x15 #define MGC3130_REQUEST_MSG 0x06 #define MGC3130_FW_VERSION 0x83 @@ -478,6 +475,9 @@ void MGC3130_detect(void) { if (MGC3130_type || I2cActive(MGC3130_I2C_ADDR)) { return; } + MGC3130_xfer = Pin(GPIO_MGC3130_XFER); + MGC3130_reset = Pin(GPIO_MGC3130_RESET); + pinMode(MGC3130_xfer, INPUT_PULLUP); pinMode(MGC3130_reset, OUTPUT); digitalWrite(MGC3130_reset, LOW); @@ -588,7 +588,7 @@ bool Xsns36(uint8_t function) bool result = false; - if ((FUNC_INIT == function) && (pin[GPIO_MGC3130_XFER] < 99) && (pin[GPIO_MGC3130_RESET] < 99)) { + if ((FUNC_INIT == function) && PinUsed(GPIO_MGC3130_XFER) && PinUsed(GPIO_MGC3130_RESET)) { MGC3130_detect(); } else if (MGC3130_type) { diff --git a/tasmota/xsns_37_rfsensor.ino b/tasmota/xsns_37_rfsensor.ino index 87ce5c9d7..53945f2bb 100644 --- a/tasmota/xsns_37_rfsensor.ino +++ b/tasmota/xsns_37_rfsensor.ino @@ -607,9 +607,9 @@ void RfSnsInit(void) RfSnsInitAlectoV2(); #endif if (rfsns_any_sensor) { - rfsns_rf_bit = digitalPinToBitMask(pin[GPIO_RF_SENSOR]); - rfsns_rf_port = digitalPinToPort(pin[GPIO_RF_SENSOR]); - pinMode(pin[GPIO_RF_SENSOR], INPUT); + rfsns_rf_bit = digitalPinToBitMask(Pin(GPIO_RF_SENSOR)); + rfsns_rf_port = digitalPinToPort(Pin(GPIO_RF_SENSOR)); + pinMode(Pin(GPIO_RF_SENSOR), INPUT); } else { free(rfsns_raw_signal); rfsns_raw_signal = nullptr; @@ -654,14 +654,14 @@ bool Xsns37(uint8_t function) { bool result = false; - if ((pin[GPIO_RF_SENSOR] < 99) && (FUNC_INIT == function)) { + if (PinUsed(GPIO_RF_SENSOR) && (FUNC_INIT == function)) { RfSnsInit(); } else if (rfsns_raw_signal) { switch (function) { case FUNC_LOOP: if ((*portInputRegister(rfsns_rf_port) &rfsns_rf_bit) == rfsns_rf_bit) { - if (RfSnsFetchSignal(pin[GPIO_RF_SENSOR], HIGH)) { + if (RfSnsFetchSignal(Pin(GPIO_RF_SENSOR), HIGH)) { RfSnsAnalyzeRawSignal(); } } diff --git a/tasmota/xsns_38_az7798.ino b/tasmota/xsns_38_az7798.ino index b6b1dffbe..352f59389 100644 --- a/tasmota/xsns_38_az7798.ino +++ b/tasmota/xsns_38_az7798.ino @@ -267,8 +267,8 @@ void AzEverySecond(void) void AzInit(void) { az_type = 0; - if ((pin[GPIO_AZ_RXD] < 99) && (pin[GPIO_AZ_TXD] < 99)) { - AzSerial = new TasmotaSerial(pin[GPIO_AZ_RXD], pin[GPIO_AZ_TXD], 1); + if (PinUsed(GPIO_AZ_RXD) && PinUsed(GPIO_AZ_TXD)) { + AzSerial = new TasmotaSerial(Pin(GPIO_AZ_RXD), Pin(GPIO_AZ_TXD), 1); if (AzSerial->begin(9600)) { if (AzSerial->hardwareSerial()) { ClaimSerial(); } az_type = 1; diff --git a/tasmota/xsns_39_max31855.ino b/tasmota/xsns_39_max31855.ino index b4a430b54..c8cdfc7aa 100644 --- a/tasmota/xsns_39_max31855.ino +++ b/tasmota/xsns_39_max31855.ino @@ -34,13 +34,13 @@ void MAX31855_Init(void){ return; // Set GPIO modes for SW-SPI - pinMode(pin[GPIO_MAX31855CS], OUTPUT); - pinMode(pin[GPIO_MAX31855CLK], OUTPUT); - pinMode(pin[GPIO_MAX31855DO], INPUT); + pinMode(Pin(GPIO_MAX31855CS), OUTPUT); + pinMode(Pin(GPIO_MAX31855CLK), OUTPUT); + pinMode(Pin(GPIO_MAX31855DO), INPUT); // Chip not selected / Clock low - digitalWrite(pin[GPIO_MAX31855CS], HIGH); - digitalWrite(pin[GPIO_MAX31855CLK], LOW); + digitalWrite(Pin(GPIO_MAX31855CS), HIGH); + digitalWrite(Pin(GPIO_MAX31855CLK), LOW); initialized = true; } @@ -99,22 +99,22 @@ float MAX31855_GetReferenceTemperature(int32_t RawData){ int32_t MAX31855_ShiftIn(uint8_t Length){ int32_t dataIn = 0; - digitalWrite(pin[GPIO_MAX31855CS], LOW); // CS = LOW -> Start SPI communication + digitalWrite(Pin(GPIO_MAX31855CS), LOW); // CS = LOW -> Start SPI communication delayMicroseconds(1); // CS fall to output enable = max. 100ns for (uint32_t i = 0; i < Length; i++) { - digitalWrite(pin[GPIO_MAX31855CLK], LOW); + digitalWrite(Pin(GPIO_MAX31855CLK), LOW); delayMicroseconds(1); // CLK pulse width low = min. 100ns / CLK fall to output valid = max. 40ns dataIn <<= 1; - if(digitalRead(pin[GPIO_MAX31855DO])) + if(digitalRead(Pin(GPIO_MAX31855DO))) dataIn |= 1; - digitalWrite(pin[GPIO_MAX31855CLK], HIGH); + digitalWrite(Pin(GPIO_MAX31855CLK), HIGH); delayMicroseconds(1); // CLK pulse width high = min. 100ns } - digitalWrite(pin[GPIO_MAX31855CS], HIGH); // CS = HIGH -> End SPI communication - digitalWrite(pin[GPIO_MAX31855CLK], LOW); + digitalWrite(Pin(GPIO_MAX31855CS), HIGH); // CS = HIGH -> End SPI communication + digitalWrite(Pin(GPIO_MAX31855CLK), LOW); return dataIn; } @@ -151,7 +151,7 @@ void MAX31855_Show(bool Json){ bool Xsns39(uint8_t function) { bool result = false; - if((pin[GPIO_MAX31855CS] < 99) && (pin[GPIO_MAX31855CLK] < 99) && (pin[GPIO_MAX31855DO] < 99)){ + if(PinUsed(GPIO_MAX31855CS) && PinUsed(GPIO_MAX31855CLK) && PinUsed(GPIO_MAX31855DO)){ switch (function) { case FUNC_INIT: diff --git a/tasmota/xsns_40_pn532.ino b/tasmota/xsns_40_pn532.ino index b241eb320..15257abef 100644 --- a/tasmota/xsns_40_pn532.ino +++ b/tasmota/xsns_40_pn532.ino @@ -66,8 +66,8 @@ uint8_t pn532_newdata_len = 0; void PN532_Init(void) { - if ((pin[GPIO_PN532_RXD] < 99) && (pin[GPIO_PN532_TXD] < 99)) { - PN532_Serial = new TasmotaSerial(pin[GPIO_PN532_RXD], pin[GPIO_PN532_TXD], 1); + if (PinUsed(GPIO_PN532_RXD9) && PinUsed(GPIO_PN532_TXD)) { + PN532_Serial = new TasmotaSerial(Pin(GPIO_PN532_RXD), Pin(GPIO_PN532_TXD), 1); if (PN532_Serial->begin(115200)) { if (PN532_Serial->hardwareSerial()) { ClaimSerial(); } PN532_wakeup(); diff --git a/tasmota/xsns_43_hre.ino b/tasmota/xsns_43_hre.ino index fa03d0301..19fffe957 100644 --- a/tasmota/xsns_43_hre.ino +++ b/tasmota/xsns_43_hre.ino @@ -71,10 +71,10 @@ bool hre_good = false; // The settling times here were determined using a single unit hooked to a scope int hreReadBit() { - digitalWrite(pin[GPIO_HRE_CLOCK], HIGH); + digitalWrite(Pin(GPIO_HRE_CLOCK), HIGH); delay(1); - int bit = digitalRead(pin[GPIO_HRE_DATA]); - digitalWrite(pin[GPIO_HRE_CLOCK], LOW); + int bit = digitalRead(Pin(GPIO_HRE_DATA)); + digitalWrite(Pin(GPIO_HRE_CLOCK), LOW); delay(1); return bit; } @@ -110,12 +110,12 @@ void hreInit(void) hre_read_errors = 0; hre_good = false; - pinMode(pin[GPIO_HRE_CLOCK], OUTPUT); - pinMode(pin[GPIO_HRE_DATA], INPUT); + pinMode(Pin(GPIO_HRE_CLOCK), OUTPUT); + pinMode(Pin(GPIO_HRE_DATA), INPUT); // Note that the level shifter inverts this line and we want to leave it // high when not being read. - digitalWrite(pin[GPIO_HRE_CLOCK], LOW); + digitalWrite(Pin(GPIO_HRE_CLOCK), LOW); hre_state = hre_sync; } @@ -260,8 +260,7 @@ void hreShow(boolean json) bool Xsns43(byte function) { // If we don't have pins assigned give up quickly. - if (pin[GPIO_HRE_CLOCK] >= 99 || pin[GPIO_HRE_DATA] >= 99) - return false; + if (!PinUsed(GPIO_HRE_CLOCK) || !PinUsed(GPIO_HRE_DATA)) { return false; } switch (function) { diff --git a/tasmota/xsns_47_max31865.ino b/tasmota/xsns_47_max31865.ino index 3b8a11706..e29054392 100644 --- a/tasmota/xsns_47_max31865.ino +++ b/tasmota/xsns_47_max31865.ino @@ -51,10 +51,10 @@ void MAX31865_Init(void){ return; max31865.setPins( - pin[GPIO_SSPI_CS], - pin[GPIO_SSPI_MOSI], - pin[GPIO_SSPI_MISO], - pin[GPIO_SSPI_SCLK] + Pin(GPIO_SSPI_CS), + Pin(GPIO_SSPI_MOSI), + Pin(GPIO_SSPI_MISO), + Pin(GPIO_SSPI_SCLK) ); if(max31865.begin(PTD_WIRES)) @@ -110,8 +110,8 @@ void MAX31865_Show(bool Json){ bool Xsns47(uint8_t function) { bool result = false; - if((pin[GPIO_SSPI_MISO] < 99) && (pin[GPIO_SSPI_MOSI] < 99) && - (pin[GPIO_SSPI_SCLK] < 99) && (pin[GPIO_SSPI_CS] < 99)) { + if (PinUsed(GPIO_SSPI_MISO) && PinUsed(GPIO_SSPI_MOSI) && + PinUsed(GPIO_SSPI_SCLK) && PinUsed(GPIO_SSPI_CS)) { switch (function) { case FUNC_INIT: diff --git a/tasmota/xsns_51_rdm6300.ino b/tasmota/xsns_51_rdm6300.ino index 7fd8bc5b5..de2714cb2 100644 --- a/tasmota/xsns_51_rdm6300.ino +++ b/tasmota/xsns_51_rdm6300.ino @@ -36,8 +36,8 @@ uint8_t rdm_blcnt; TasmotaSerial *RDM6300_Serial = nullptr; void RDM6300_Init() { - if (pin[GPIO_RDM6300_RX] < 99) { - RDM6300_Serial = new TasmotaSerial(pin[GPIO_RDM6300_RX],-1,1); + if (PinUsed(GPIO_RDM6300_RX)) { + RDM6300_Serial = new TasmotaSerial(Pin(GPIO_RDM6300_RX),-1,1); if (RDM6300_Serial->begin(RDM6300_BAUDRATE)) { if (RDM6300_Serial->hardwareSerial()) { ClaimSerial(); diff --git a/tasmota/xsns_52_ibeacon.ino b/tasmota/xsns_52_ibeacon.ino index 97130df2a..88b040e76 100644 --- a/tasmota/xsns_52_ibeacon.ino +++ b/tasmota/xsns_52_ibeacon.ino @@ -95,8 +95,8 @@ void IBEACON_Init() { hm17_found=0; // actually doesnt work reliably with software serial - if ((pin[GPIO_IBEACON_RX] < 99) && (pin[GPIO_IBEACON_TX] < 99)) { - IBEACON_Serial = new TasmotaSerial(pin[GPIO_IBEACON_RX], pin[GPIO_IBEACON_TX],1); + if (PinUsed(GPIO_IBEACON_RX) && PinUsed(GPIO_IBEACON_TX)) { + IBEACON_Serial = new TasmotaSerial(Pin(GPIO_IBEACON_RX), Pin(GPIO_IBEACON_TX),1); if (IBEACON_Serial->begin(HM17_BAUDRATE)) { if (IBEACON_Serial->hardwareSerial()) { ClaimSerial(); diff --git a/tasmota/xsns_53_sml.ino b/tasmota/xsns_53_sml.ino index 71b205e6e..c61bfa20d 100755 --- a/tasmota/xsns_53_sml.ino +++ b/tasmota/xsns_53_sml.ino @@ -1831,8 +1831,9 @@ uint8_t *script_meter; #endif bool Gpio_used(uint8_t gpiopin) { - for (uint16_t i=0;ibegin(9600)) { diff --git a/tasmota/xsns_60_GPS.ino b/tasmota/xsns_60_GPS.ino index b789222fe..e7094887b 100644 --- a/tasmota/xsns_60_GPS.ino +++ b/tasmota/xsns_60_GPS.ino @@ -354,8 +354,8 @@ void UBXTriggerTele(void) void UBXDetect(void) { UBX.mode.init = 0; - if ((pin[GPIO_GPS_RX] < 99) && (pin[GPIO_GPS_TX] < 99)) { - UBXSerial = new TasmotaSerial(pin[GPIO_GPS_RX], pin[GPIO_GPS_TX], 1, 0, UBX_SERIAL_BUFFER_SIZE); // 64 byte buffer is NOT enough + if (PinUsed(GPIO_GPS_RX) && PinUsed(GPIO_GPS_TX)) { + UBXSerial = new TasmotaSerial(Pin(GPIO_GPS_RX), Pin(GPIO_GPS_TX), 1, 0, UBX_SERIAL_BUFFER_SIZE); // 64 byte buffer is NOT enough if (UBXSerial->begin(9600)) { DEBUG_SENSOR_LOG(PSTR("UBX: started serial")); if (UBXSerial->hardwareSerial()) { diff --git a/tasmota/xsns_61_MI_NRF24.ino b/tasmota/xsns_61_MI_NRF24.ino index d21f9e7e1..5dd82f3a5 100644 --- a/tasmota/xsns_61_MI_NRF24.ino +++ b/tasmota/xsns_61_MI_NRF24.ino @@ -27,10 +27,10 @@ 0.9.4.0 20200304 integrate - sensor types can be ignored (default for LYWSD03), add CGD1 (Alarm clock), correct PDU-types for LYWSD02 --- - 0.9.3.0 20200222 integrate - use now the correct id-word instead of MAC-OUI, + 0.9.3.0 20200222 integrate - use now the correct id-word instead of MAC-OUI, add CGG1 --- - 0.9.2.0 20200212 integrate - "backports" from MI-HM10, change reading pattern, + 0.9.2.0 20200212 integrate - "backports" from MI-HM10, change reading pattern, add missing PDU-types, renaming driver --- 0.9.1.0 20200117 integrate - Added support for the LYWSD02 @@ -176,7 +176,7 @@ struct { uint8_t packetMode; // 0 - normal BLE-advertisements, 1 - 6 "special" sensor packets uint8_t perPage = 4; uint8_t firstUsedPacketMode = 1; - + FIFO_t buffer; struct { @@ -232,16 +232,16 @@ static union{ /********************************************************************************************/ /** - * @brief - * + * @brief + * * @param _mode Packet mode 0-6 * @return true If no error occured - * @return false If NRF24L01 is not connected + * @return false If NRF24L01 is not connected */ bool MINRFinitBLE(uint8_t _mode) { if (MINRF.timer%1000 == 0){ // only re-init every 20 seconds - NRF24radio.begin(pin[GPIO_SPI_CS],pin[GPIO_SPI_DC]); + NRF24radio.begin(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_DC)); NRF24radio.setAutoAck(false); NRF24radio.setDataRate(RF24_1MBPS); NRF24radio.disableCRC(); @@ -264,7 +264,7 @@ bool MINRFinitBLE(uint8_t _mode) /** * @brief cycle through the channels 37-39, skip ignored channel - * + * */ void MINRFhopChannel() { @@ -405,19 +405,19 @@ bool MINRFhandleBeacon(scan_entry_t * entry, uint32_t offset); /** * @brief handle a generic BLE-packet in the scan process - * + * */ void MINRFhandleScan(void){ if(MINRFscanResult.size()>20 || MINRF.stopScan) { MINRF.activeScan=false; MINRFcomputefirstUsedPacketMode(); uint32_t i = 0; // pass counter as reference to lambda - MINRFscanResult.erase(std::remove_if(MINRFscanResult.begin(), + MINRFscanResult.erase(std::remove_if(MINRFscanResult.begin(), MINRFscanResult.end(), [&i](scan_entry_t e) { if(e.showedUp>2) AddLog_P2(LOG_LEVEL_INFO,PSTR("MINRF: Beacon %02u: %02X%02X%02X%02X%02X%02X Cid: %04X Svc: %04X UUID: %04X"),i,e.mac[0],e.mac[1],e.mac[2],e.mac[3],e.mac[4],e.mac[5],e.cid,e.svc,e.uuid); i++; - return ((e.showedUp < 3)); + return ((e.showedUp < 3)); }), MINRFscanResult.end()); MINRF.stopScan=false; @@ -447,7 +447,7 @@ void MINRFhandleScan(void){ /** * @brief start beacon mode, can co-exist with Mijia-sniffing - * + * * @param entry number of entry in scan list */ void MINRFstartBeacon(uint16_t entry){ @@ -459,7 +459,7 @@ void MINRFstartBeacon(uint16_t entry){ /** * @brief semi-generic BLE-ADV-parser - * + * * @param entry Entry of scan list * @param offset Depends on the reading mode: 0->regular BLE-ADV, 6->"cutted" BLE-ADV with MAC as PDU * @return true - when name, cid, uuid or svc is found with any value @@ -536,7 +536,7 @@ bool MINRFhandleBeacon(scan_entry_t * entry, uint32_t offset){ /** * @brief increase beacon timer every second and process the result - * + * */ void MINRFbeaconCounter(void){ if(MINRF.beacon.active) { @@ -550,7 +550,7 @@ void MINRFbeaconCounter(void){ /** * @brief compute "PDU" from MAC for each possible channel and store it globally - * + * */ void MINRFcomputeBeaconPDU(void){ for (uint32_t i = 0; i<3; i++){ @@ -570,7 +570,7 @@ void MINRFcomputeBeaconPDU(void){ /** * @brief reverse 6-byte-array, hard-coded size of 6 - * + * * @param _mac pass an uint_t[6] */ void MINRFreverseMAC(uint8_t _mac[]){ @@ -582,8 +582,8 @@ void MINRFreverseMAC(uint8_t _mac[]){ } /** - * @brief - * + * @brief + * * @param _string input string in format: AABBCCDDEEFF (upper case!) * @param _mac target byte array with fixed size of 6 */ @@ -594,7 +594,7 @@ void MINRFMACStringToBytes(char* _string, uint8_t _mac[]) { //uppercase uint8_t value = 0; if(c >= '0' && c <= '9') value = (c - '0'); - else if (c >= 'A' && c <= 'F') + else if (c >= 'A' && c <= 'F') value = (10 + (c - 'A')); _mac[(index/2)] += value << (((index + 1) % 2) * 4); index++; @@ -604,7 +604,7 @@ void MINRFMACStringToBytes(char* _string, uint8_t _mac[]) { //uppercase /** * @brief helper function, to avoid to start with an ignored sensor type - * + * */ void MINRFcomputefirstUsedPacketMode(void){ for (uint32_t i = 0; ilux=MINRF.buffer.miBeacon.lux & 0x00ffffff; DEBUG_SENSOR_LOG(PSTR("Mode 7: U24: %u Lux"), MINRF.buffer.miBeacon.lux & 0x00ffffff); - break; + break; case 0x08: _tempFloat =(float)MINRF.buffer.miBeacon.moist; if(_tempFloat<100){ @@ -881,7 +881,7 @@ void MINRFhandleCGD1Packet(void){ // no MiBeacon \*********************************************************************************************/ void MINRF_EVERY_50_MSECOND() { // Every 50mseconds - + if(MINRF.timer>6000){ // happens every 6000/20 = 300 seconds DEBUG_SENSOR_LOG(PSTR("MINRF: check for FAKE sensors")); MINRFpurgeFakeSensors(); @@ -890,7 +890,7 @@ void MINRF_EVERY_50_MSECOND() { // Every 50mseconds MINRF.timer++; if (!MINRFreceivePacket()){ - // DEBUG_SENSOR_LOG(PSTR("MINRF: nothing received")); + // DEBUG_SENSOR_LOG(PSTR("MINRF: nothing received")); } else { @@ -1057,7 +1057,7 @@ void MINRFShow(bool json) } ResponseAppend_P(PSTR(",\"%s-%02x%02x%02x\":{"),kMINRFSlaveType[MIBLEsensors[i].type-1],MIBLEsensors[i].serial[3],MIBLEsensors[i].serial[4],MIBLEsensors[i].serial[5]); if (MIBLEsensors[i].type==FLORA && !isnan(MIBLEsensors[i].temp)){ - char stemp[FLOATSZ]; + char stemp[FLOATSZ]; dtostrfd(MIBLEsensors[i].temp, Settings.flag2.temperature_resolution, stemp); ResponseAppend_P(PSTR("\"" D_JSON_TEMPERATURE "\":%s"), stemp); @@ -1074,7 +1074,7 @@ void MINRFShow(bool json) } ResponseJsonEnd(); } - if (MIBLEsensors[i].type>FLORA){ + if (MIBLEsensors[i].type>FLORA){ if(!isnan(MIBLEsensors[i].temp) && !isnan(MIBLEsensors[i].hum)){ ResponseAppendTHD(MIBLEsensors[i].temp,MIBLEsensors[i].hum); } @@ -1112,7 +1112,7 @@ void MINRFShow(bool json) continue; } WSContentSend_PD(HTTP_MINRF_HL); - WSContentSend_PD(HTTP_MINRF_MAC, kMINRFSlaveType[MIBLEsensors[i].type-1], D_MAC_ADDRESS, MIBLEsensors[i].serial[0], MIBLEsensors[i].serial[1],MIBLEsensors[i].serial[2],MIBLEsensors[i].serial[3],MIBLEsensors[i].serial[4],MIBLEsensors[i].serial[5]); + WSContentSend_PD(HTTP_MINRF_MAC, kMINRFSlaveType[MIBLEsensors[i].type-1], D_MAC_ADDRESS, MIBLEsensors[i].serial[0], MIBLEsensors[i].serial[1],MIBLEsensors[i].serial[2],MIBLEsensors[i].serial[3],MIBLEsensors[i].serial[4],MIBLEsensors[i].serial[5]); if (MIBLEsensors[i].type==FLORA){ if(!isnan(MIBLEsensors[i].temp)){ char temperature[FLOATSZ]; @@ -1139,7 +1139,7 @@ void MINRFShow(bool json) if(MINRF.beacon.active){ WSContentSend_PD(HTTP_MINRF_HL); WSContentSend_PD(HTTP_MINRF_HL); - WSContentSend_PD(HTTP_MINRF_MAC, F("Beacon"), D_MAC_ADDRESS, MINRF.beacon.mac[0], MINRF.beacon.mac[1],MINRF.beacon.mac[2],MINRF.beacon.mac[3],MINRF.beacon.mac[4],MINRF.beacon.mac[5]); + WSContentSend_PD(HTTP_MINRF_MAC, F("Beacon"), D_MAC_ADDRESS, MINRF.beacon.mac[0], MINRF.beacon.mac[1],MINRF.beacon.mac[2],MINRF.beacon.mac[3],MINRF.beacon.mac[4],MINRF.beacon.mac[5]); WSContentSend_PD(PSTR("{s}Beacon Time{m}%u seconds{e}"),MINRF.beacon.time); } if(counter>3) { diff --git a/tasmota/xsns_62_MI_HM10.ino b/tasmota/xsns_62_MI_HM10.ino index 01fa338e8..6655a0c87 100644 --- a/tasmota/xsns_62_MI_HM10.ino +++ b/tasmota/xsns_62_MI_HM10.ino @@ -403,7 +403,7 @@ uint32_t MIBLEgetSensorSlot(uint8_t (&_serial)[6], uint16_t _type){ void HM10SerialInit(void) { HM10.mode.init = false; HM10.serialSpeed = HM10_BAUDRATE; - HM10Serial = new TasmotaSerial(pin[GPIO_HM10_RX], pin[GPIO_HM10_TX], 1, 0, HM10_MAX_RX_BUF); + HM10Serial = new TasmotaSerial(Pin(GPIO_HM10_RX), Pin(GPIO_HM10_TX), 1, 0, HM10_MAX_RX_BUF); if (HM10Serial->begin(HM10.serialSpeed)) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s start serial communication fixed to 115200 baud"),D_CMND_HM10); if (HM10Serial->hardwareSerial()) { @@ -1257,7 +1257,7 @@ bool Xsns62(uint8_t function) { bool result = false; - if ((pin[GPIO_HM10_RX] < 99) && (pin[GPIO_HM10_TX] < 99)) { + if (PinUsed(GPIO_HM10_RX) && PinUsed(GPIO_HM10_TX)) { switch (function) { case FUNC_INIT: HM10SerialInit(); // init and start communication diff --git a/tasmota/xsns_64_hrxl.ino b/tasmota/xsns_64_hrxl.ino index a82134c94..389197e1a 100644 --- a/tasmota/xsns_64_hrxl.ino +++ b/tasmota/xsns_64_hrxl.ino @@ -41,9 +41,9 @@ bool hrxl_found = false; void HRXLInit(void) { hrxl_found = false; - if ((pin[GPIO_HRXL_RX] < 99)) + if (PinUsed(GPIO_HRXL_RX)) { - HRXLSerial = new TasmotaSerial(pin[GPIO_HRXL_RX], -1, 1); + HRXLSerial = new TasmotaSerial(Pin(GPIO_HRXL_RX), -1, 1); if (HRXLSerial->begin(9600)) { if (HRXLSerial->hardwareSerial()) @@ -100,8 +100,7 @@ void HRXLShow(bool json) bool Xsns64(uint8_t function) { - if (pin[GPIO_HRXL_RX] >= 99) - return false; + if (!PinUsed(GPIO_HRXL_RX)) { return false; } switch (function) { diff --git a/tasmota/xsns_67_as3935.ino b/tasmota/xsns_67_as3935.ino index 61042228f..27b97f9a2 100644 --- a/tasmota/xsns_67_as3935.ino +++ b/tasmota/xsns_67_as3935.ino @@ -401,9 +401,9 @@ void AS3935SetWdth(uint8_t wdth) { } bool AS3935AutoTune(){ - detachInterrupt(pin[GPIO_AS3935]); - bool result = AS3935AutoTuneCaps(pin[GPIO_AS3935]); - attachInterrupt(digitalPinToInterrupt(pin[GPIO_AS3935]), AS3935Isr, RISING); + detachInterrupt(Pin(GPIO_AS3935)); + bool result = AS3935AutoTuneCaps(Pin(GPIO_AS3935)); + attachInterrupt(digitalPinToInterrupt(Pin(GPIO_AS3935)), AS3935Isr, RISING); return result; } @@ -497,8 +497,8 @@ void AS3935Detect(void) { if (AS3935init()) { I2cSetActiveFound(AS3935_ADDR, D_NAME_AS3935); - pinMode(pin[GPIO_AS3935], INPUT); - attachInterrupt(digitalPinToInterrupt(pin[GPIO_AS3935]), AS3935Isr, RISING); + pinMode(Pin(GPIO_AS3935), INPUT); + attachInterrupt(digitalPinToInterrupt(Pin(GPIO_AS3935)), AS3935Isr, RISING); AS3935Setup(); as3935_active = 1; } From 1dda2ac6633e0118ed75927bcfb249e1bce21a95 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 27 Apr 2020 16:55:56 +0200 Subject: [PATCH 10/40] Fix pin handling part 4/4 --- tasmota/xsns_40_pn532.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/xsns_40_pn532.ino b/tasmota/xsns_40_pn532.ino index 15257abef..8218d0b35 100644 --- a/tasmota/xsns_40_pn532.ino +++ b/tasmota/xsns_40_pn532.ino @@ -66,7 +66,7 @@ uint8_t pn532_newdata_len = 0; void PN532_Init(void) { - if (PinUsed(GPIO_PN532_RXD9) && PinUsed(GPIO_PN532_TXD)) { + if (PinUsed(GPIO_PN532_RXD) && PinUsed(GPIO_PN532_TXD)) { PN532_Serial = new TasmotaSerial(Pin(GPIO_PN532_RXD), Pin(GPIO_PN532_TXD), 1); if (PN532_Serial->begin(115200)) { if (PN532_Serial->hardwareSerial()) { ClaimSerial(); } From ae4ec4325d05c1c926f79395cb91c3b625404d31 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 27 Apr 2020 17:16:52 +0200 Subject: [PATCH 11/40] Change pin handling part 5 --- tasmota/support_command.ino | 6 +++--- tasmota/support_tasmota.ino | 6 +++--- tasmota/xdrv_36_keeloq.ino | 2 +- tasmota/xnrg_01_hlw8012.ino | 6 +++--- tasmota/xsns_18_pms5003.ino | 2 +- tasmota/xsns_22_sr04.ino | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index cc8bb92ae..01c227f36 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -1694,7 +1694,7 @@ void CmndAltitude(void) void CmndLedPower(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_LEDS)) { - if (99 == Pin(GPIO_LEDLNK)) { XdrvMailbox.index = 1; } + if (!PinUsed(GPIO_LEDLNK)) { XdrvMailbox.index = 1; } if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 2)) { Settings.ledstate &= 8; // Disable power control uint32_t mask = 1 << (XdrvMailbox.index -1); // Led to control @@ -1713,14 +1713,14 @@ void CmndLedPower(void) break; } blinks = 0; - if (99 == Pin(GPIO_LEDLNK)) { + if (!PinUsed(GPIO_LEDLNK)) { SetLedPower(Settings.ledstate &8); } else { SetLedPowerIdx(XdrvMailbox.index -1, (led_power & mask)); } } bool state = bitRead(led_power, XdrvMailbox.index -1); - if (99 == Pin(GPIO_LEDLNK)) { + if (!PinUsed(GPIO_LEDLNK)) { state = bitRead(Settings.ledstate, 3); } ResponseCmndIdxChar(GetStateText(state)); diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 1f2ad385c..a6a293ae3 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -338,7 +338,7 @@ void SetPowerOnState(void) void SetLedPowerIdx(uint32_t led, uint32_t state) { - if ((99 == Pin(GPIO_LEDLNK)) && (0 == led)) { // Legacy - LED1 is link led only if LED2 is present + if (!PinUsed(GPIO_LEDLNK) && (0 == led)) { // Legacy - LED1 is link led only if LED2 is present if (PinUsed(GPIO_LED1, 1)) { led = 1; } @@ -362,7 +362,7 @@ void SetLedPowerIdx(uint32_t led, uint32_t state) void SetLedPower(uint32_t state) { - if (99 == Pin(GPIO_LEDLNK)) { // Legacy - Only use LED1 and/or LED2 + if (!PinUsed(GPIO_LEDLNK)) { // Legacy - Only use LED1 and/or LED2 SetLedPowerIdx(0, state); } else { power_t mask = 1; @@ -1534,7 +1534,7 @@ void GpioInit(void) for (uint32_t i = 0; i < MAX_LEDS; i++) { if (PinUsed(GPIO_LED1, i)) { #ifdef USE_ARILUX_RF - if ((3 == i) && (leds_present < 2) && (99 == Pin(GPIO_ARIRFSEL))) { + if ((3 == i) && (leds_present < 2) && !PinUsed(GPIO_ARIRFSEL)) { SetPin(Pin(GPIO_LED4), GPIO_ARIRFSEL); // Legacy support where LED4 was Arilux RF enable SetPin(99, GPIO_LED4); } else { diff --git a/tasmota/xdrv_36_keeloq.ino b/tasmota/xdrv_36_keeloq.ino index 75e3e6167..c271cf3f7 100644 --- a/tasmota/xdrv_36_keeloq.ino +++ b/tasmota/xdrv_36_keeloq.ino @@ -266,7 +266,7 @@ void KeeloqInit() \*********************************************************************************************/ bool Xdrv36(uint8_t function) { - if ((99 == Pin(GPIO_CC1101_GDO0)) || (99 == Pin(GPIO_CC1101_GDO2))) { return false; } + if (!PinUsed(GPIO_CC1101_GDO0) || !PinUsed(GPIO_CC1101_GDO2)) { return false; } bool result = false; diff --git a/tasmota/xnrg_01_hlw8012.ino b/tasmota/xnrg_01_hlw8012.ino index a1e67ecfc..12a10abb6 100644 --- a/tasmota/xnrg_01_hlw8012.ino +++ b/tasmota/xnrg_01_hlw8012.ino @@ -254,7 +254,7 @@ void HlwDrvInit(void) Hlw.model_type = 1; // HJL-01/BL0937 } - if (PinUsed(GPIO_HLW_CF)) { // HLW8012 or HJL-01 based device Power monitor + if (PinUsed(GPIO_HLW_CF)) { // HLW8012 or HJL-01 based device Power monitor Hlw.ui_flag = true; // Voltage on high if (PinUsed(GPIO_NRG_SEL_INV)) { @@ -263,8 +263,8 @@ void HlwDrvInit(void) Hlw.ui_flag = false; // Voltage on low } - if (PinUsed(GPIO_NRG_CF1)) { // Voltage and/or Current monitor - if (99 == Pin(GPIO_NRG_SEL)) { // Voltage and/or Current selector + if (PinUsed(GPIO_NRG_CF1)) { // Voltage and/or Current monitor + if (!PinUsed(GPIO_NRG_SEL)) { // Voltage and/or Current selector Energy.current_available = false; // Assume Voltage } } else { diff --git a/tasmota/xsns_18_pms5003.ino b/tasmota/xsns_18_pms5003.ino index dbac02936..d54527ddc 100644 --- a/tasmota/xsns_18_pms5003.ino +++ b/tasmota/xsns_18_pms5003.ino @@ -244,7 +244,7 @@ void PmsInit(void) if (PmsSerial->begin(9600)) { if (PmsSerial->hardwareSerial()) { ClaimSerial(); } - if (99 == Pin(GPIO_PMS5003_TX)) { // setting interval not supported if TX pin not connected + if (!PinUsed(GPIO_PMS5003_TX)) { // setting interval not supported if TX pin not connected Settings.pms_wake_interval = 0; Pms.ready = 1; } diff --git a/tasmota/xsns_22_sr04.ino b/tasmota/xsns_22_sr04.ino index 116729f66..187a67c3f 100644 --- a/tasmota/xsns_22_sr04.ino +++ b/tasmota/xsns_22_sr04.ino @@ -40,7 +40,7 @@ TasmotaSerial* sonar_serial = nullptr; uint8_t Sr04TModeDetect(void) { sr04_type = 0; - if (99 == Pin(GPIO_SR04_ECHO)) { return sr04_type; } + if (!PinUsed(GPIO_SR04_ECHO)) { return sr04_type; } int sr04_echo_pin = Pin(GPIO_SR04_ECHO); int sr04_trig_pin = (PinUsed(GPIO_SR04_TRIG)) ? Pin(GPIO_SR04_TRIG) : Pin(GPIO_SR04_ECHO); // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only From 3fef91d6ca7b666882bd81c69734755d099eec29 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 27 Apr 2020 17:28:05 +0200 Subject: [PATCH 12/40] Change pin handling part 6 --- tasmota/support.ino | 6 ++++++ tasmota/support_tasmota.ino | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 10e34ada7..0986a007e 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1109,6 +1109,12 @@ void SetPin(uint32_t lpin, uint32_t gpio) { */ } +void InitAllPins(void) { + for (uint32_t i = 0; i < ARRAY_SIZE(pin); i++) { + SetPin(99, i); + } +} + void DigitalWrite(uint32_t gpio_pin, uint32_t index, uint32_t state) { if (PinUsed(gpio_pin, index)) { diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index a6a293ae3..3db5ea2f7 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1383,9 +1383,7 @@ void GpioInit(void) my_adc0 = template_adc0; // Force Template override } - for (uint32_t i = 0; i < GPIO_MAX; i++) { - SetPin(99, i); - } + InitAllPins(); for (uint32_t i = 0; i < ARRAY_SIZE(my_module.io); i++) { uint32_t mpin = ValidPin(i, my_module.io[i]); From 4cd21644d69dfd53f4094a75bbce15679bf45282 Mon Sep 17 00:00:00 2001 From: kugelkopf123 <45996965+kugelkopf123@users.noreply.github.com> Date: Mon, 27 Apr 2020 20:44:26 +0200 Subject: [PATCH 13/40] Update xsns_02_analog.ino --- tasmota/xsns_02_analog.ino | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index 038da9fa5..41be46ff8 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -166,6 +166,8 @@ void AdcGetCurrentPower(uint8_t factor) uint16_t analog = 0; uint16_t analog_min = 1023; uint16_t analog_max = 0; + + if(Settings.adc_param1==0){ for (uint32_t i = 0; i < samples; i++) { analog = analogRead(A0); if (analog < analog_min) { @@ -176,8 +178,19 @@ void AdcGetCurrentPower(uint8_t factor) } delay(1); } - Adc.current = (float)(analog_max-analog_min) * ((float)(Settings.adc_param2) / 100000); + } + else{ + + analog = AdcRead(5); + if(analog>Settings.adc_param1){ + Adc.current = ((float)(analog) - (float)Settings.adc_param1) * ((float)(Settings.adc_param2) / 100000); + } + else{ + Adc.current = 0; + } + } + float power = Adc.current * (float)(Settings.adc_param3) / 10; uint32_t current_millis = millis(); Adc.energy = Adc.energy + ((power * (current_millis - Adc.previous_millis)) / 3600000000); @@ -357,7 +370,7 @@ void CmndAdcParam(void) Settings.adc_param3 = (int)(CharToFloat(subStr(sub_string, XdrvMailbox.data, ",", 4)) * 10000); } if (ADC0_CT_POWER == XdrvMailbox.payload) { - if ((Settings.adc_param1 & CT_FLAG_ENERGY_RESET) > 0) { + if ((Settings.adc_param1 == 1 & CT_FLAG_ENERGY_RESET) > 0) { Adc.energy = 0; Settings.adc_param1 ^= CT_FLAG_ENERGY_RESET; // Cancel energy reset flag } @@ -435,4 +448,4 @@ bool Xsns02(uint8_t function) return result; } -#endif // USE_ADC_VCC +#endif // USE_ADC_VCC \ No newline at end of file From b6e62bf71583124994e91d0c1ebb0bb746d14b6c Mon Sep 17 00:00:00 2001 From: Paul C Diem Date: Mon, 27 Apr 2020 22:26:32 -0500 Subject: [PATCH 14/40] Only advance to next palette color when fade is down --- tasmota/xdrv_04_light.ino | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index 9aaa9c9c0..971c0b2b2 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -1702,17 +1702,19 @@ void LightCycleColor(int8_t direction) #ifdef USE_LIGHT_PALETTE if (Light.palette_count) { - if (0 == direction) { - Light.wheel = random(Light.palette_count); - } - else { - Light.wheel += direction; - if (Light.wheel >= Light.palette_count) { - Light.wheel = 0; - if (direction < 0) Light.wheel = Light.palette_count - 1; + if (!Light.fade_running) { + if (0 == direction) { + Light.wheel = random(Light.palette_count); } + else { + Light.wheel += direction; + if (Light.wheel >= Light.palette_count) { + Light.wheel = 0; + if (direction < 0) Light.wheel = Light.palette_count - 1; + } + } + LightSetPaletteEntry(); } - LightSetPaletteEntry(); return; } #endif // USE_LIGHT_PALETTE From 966d3522ad830920a26dfa3bfcfe9db279d0b4d9 Mon Sep 17 00:00:00 2001 From: Paul C Diem Date: Tue, 28 Apr 2020 00:18:40 -0500 Subject: [PATCH 15/40] Rework DGR channel update --- tasmota/xdrv_04_light.ino | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index 971c0b2b2..345951696 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -2234,27 +2234,21 @@ void calcGammaBulbs(uint16_t cur_col_10[5]) { } #ifdef USE_DEVICE_GROUPS -void LightSendDeviceGroupStatus(bool force) +void LightSendDeviceGroupStatus(bool status) { - static uint8_t last_channels[LST_MAX]; - static uint8_t channels_sequence = 0; static uint8_t last_bri; - uint8_t bri = light_state.getBri(); - bool send_bri_update = (force || bri != last_bri); - + bool send_bri_update = (status || bri != last_bri); if (Light.subtype > LST_SINGLE && !Light.devgrp_no_channels_out) { - uint8_t channels[LST_MAX + 1]; - light_state.getChannels(channels); - if (force || memcmp(last_channels, channels, LST_MAX) -#ifdef USE_LIGHT_PALETTE - || (Settings.light_scheme && Light.palette_count) -#endif // USE_LIGHT_PALETTE - ) { - memcpy(last_channels, channels, LST_MAX); - channels[LST_MAX] = ++channels_sequence; - SendLocalDeviceGroupMessage((send_bri_update ? DGR_MSGTYP_PARTIAL_UPDATE : DGR_MSGTYP_UPDATE), DGR_ITEM_LIGHT_CHANNELS, channels); + static uint8_t channels[LST_MAX + 1] = { 0, 0, 0, 0, 0, 0 }; + if (status) { + light_state.getChannels(channels); } + else { + memcpy(channels, Light.new_color, LST_MAX); + channels[LST_MAX]++; + } + SendLocalDeviceGroupMessage((send_bri_update ? DGR_MSGTYP_PARTIAL_UPDATE : DGR_MSGTYP_UPDATE), DGR_ITEM_LIGHT_CHANNELS, channels); } if (send_bri_update) { last_bri = bri; From 4536746d032b35f80cb73649764f65cbf311ae2b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 28 Apr 2020 11:09:56 +0200 Subject: [PATCH 16/40] Update Changelog and Release notes --- RELEASENOTES.md | 3 ++- tasmota/CHANGELOG.md | 1 + tasmota/settings.h | 2 +- tasmota/xsns_02_analog.ino | 31 +++++++++++++++---------------- tools/decode-status.py | 6 +++--- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index d7e8d2bf1..62a21c61f 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -61,7 +61,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Change light scheme 2,3,4 cycle time speed from 24,48,72,... seconds to 4,6,12,24,36,48,... seconds (#8034) - Change remove floating point libs from IRAM - Change remove MQTT Info messages on restart for DeepSleep Wake (#8044) -- Change IRremoteESP8266 library updated to v2.7.5 +- Change IRremoteESP8266 library updated to v2.7.6 - Fix possible Relay toggle on (OTA) restart - Fix PWM flickering during wifi connection (#8046) - Fix Zigbee sending wrong Sat value with Hue emulation @@ -78,6 +78,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Add command ``SetOption73 1`` for button decoupling and send multi-press and hold MQTT messages by Federico Leoni (#8235) - Add command ``SetOption90 1`` to disable non-json MQTT messages (#8044) - Add command ``SetOption91 1`` to enable fading at startup / power on +- Add command ``SetOption92 1`` to set PWM Mode from regular PWM to ColorTemp control (Xiaomi Philips ...) - Add command ``Sensor10 0/1/2`` to control BH1750 resolution - 0 = High (default), 1 = High2, 2 = Low (#8016) - Add command ``Sensor10 31..254`` to control BH1750 measurement time which defaults to 69 (#8016) - Add command ``Sensor18 0..32000`` to control PMS5003 sensor interval to extend lifetime by Gene Ruebsamen (#8128) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 9d6b6c8e0..f3b36fcf5 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -12,6 +12,7 @@ - Fix Zigbee DimmerUp/DimmerDown malformed - Add config version tag - Add command ``SetOption73 1`` for button decoupling and send multi-press and hold MQTT messages by Federico Leoni (#8235) +- Add command ``SetOption92 1`` to set PWM Mode from regular PWM to ColorTemp control (Xiaomi Philips ...) - Add command ``SO`` as shortcut for command ``SetOption`` ### 8.2.0.3 20200329 diff --git a/tasmota/settings.h b/tasmota/settings.h index ae9243c70..ccf3e44ed 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -111,7 +111,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t zigbee_distinct_topics : 1; // bit 7 (v8.1.0.10) - SetOption89 - Distinct MQTT topics per device for Zigbee (#7835) uint32_t only_json_message : 1; // bit 8 (v8.2.0.3) - SetOption90 - Disable non-json MQTT response uint32_t fade_at_startup : 1; // bit 9 (v8.2.0.3) - SetOption91 - Enable light fading at start/power on - uint32_t pwm_ct_mode : 1; // bit 10 () - SetOption92 - Set PWM Mode from regular PWM to ColorTemp control (Xiaomi Philips ...) + uint32_t pwm_ct_mode : 1; // bit 10 (v8.2.0.4) - SetOption92 - Set PWM Mode from regular PWM to ColorTemp control (Xiaomi Philips ...) uint32_t spare11 : 1; uint32_t spare12 : 1; uint32_t spare13 : 1; diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index 41be46ff8..019eed86a 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -167,26 +167,25 @@ void AdcGetCurrentPower(uint8_t factor) uint16_t analog_min = 1023; uint16_t analog_max = 0; - if(Settings.adc_param1==0){ - for (uint32_t i = 0; i < samples; i++) { - analog = analogRead(A0); - if (analog < analog_min) { - analog_min = analog; + if (0 == Settings.adc_param1) { + for (uint32_t i = 0; i < samples; i++) { + analog = analogRead(A0); + if (analog < analog_min) { + analog_min = analog; + } + if (analog > analog_max) { + analog_max = analog; + } + delay(1); } - if (analog > analog_max) { - analog_max = analog; - } - delay(1); + Adc.current = (float)(analog_max-analog_min) * ((float)(Settings.adc_param2) / 100000); } - Adc.current = (float)(analog_max-analog_min) * ((float)(Settings.adc_param2) / 100000); - } - else{ - + else { analog = AdcRead(5); - if(analog>Settings.adc_param1){ + if (analog > Settings.adc_param1) { Adc.current = ((float)(analog) - (float)Settings.adc_param1) * ((float)(Settings.adc_param2) / 100000); } - else{ + else { Adc.current = 0; } } @@ -370,7 +369,7 @@ void CmndAdcParam(void) Settings.adc_param3 = (int)(CharToFloat(subStr(sub_string, XdrvMailbox.data, ",", 4)) * 10000); } if (ADC0_CT_POWER == XdrvMailbox.payload) { - if ((Settings.adc_param1 == 1 & CT_FLAG_ENERGY_RESET) > 0) { + if (((1 == Settings.adc_param1) & CT_FLAG_ENERGY_RESET) > 0) { Adc.energy = 0; Settings.adc_param1 ^= CT_FLAG_ENERGY_RESET; // Cancel energy reset flag } diff --git a/tools/decode-status.py b/tools/decode-status.py index 2450d1fb5..d2d7e2b83 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -126,7 +126,7 @@ a_setoption = [[ "Enable Weekend Energy Tariff", "Select different Modbus registers for Active Energy", "Enable hardware energy total counter as reference", - "Enable HTTP CORS", + "Detach buttons from relays and enable MQTT action state for multipress", "Enable internal pullup for single DS18x20 sensor", "GroupTopic replaces %topic% (0) or fixed topic cmnd/grouptopic (1)", "Enable incrementing bootcount when deepsleep is enabled", @@ -146,7 +146,7 @@ a_setoption = [[ "Distinct MQTT topics per device for Zigbee", "Disable non-json MQTT response", "Enable light fading at start/power on", - "","", + "Set PWM Mode from regular PWM to ColorTemp control","", "","","","", "","","","", "","","","", @@ -241,7 +241,7 @@ else: obj = json.load(fp) def StartDecode(): - print ("\n*** decode-status.py v20200411 by Theo Arends and Jacek Ziolkowski ***") + print ("\n*** decode-status.py v20200428 by Theo Arends and Jacek Ziolkowski ***") # print("Decoding\n{}".format(obj)) From 60e7a73b6066733c948993076df47f48cdecfaa8 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 28 Apr 2020 14:42:47 +0200 Subject: [PATCH 17/40] Switch from GPIO array to Pin array --- tasmota/support.ino | 16 +++++++++------- tasmota/support_tasmota.ino | 24 +++++++++++++++++------- tasmota/tasmota.ino | 6 +++++- tasmota/tasmota_globals.h | 2 ++ tasmota/xdrv_10_scripter.ino | 9 +++++++++ tasmota/xdrv_31_tasmota_slave.ino | 2 ++ tasmota/xnrg_01_hlw8012.ino | 4 ++++ tasmota/xsns_53_sml.ino | 6 ++++++ 8 files changed, 54 insertions(+), 15 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 0986a007e..1bcdb9015 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1079,11 +1079,14 @@ uint32_t Pin(uint32_t gpio, uint32_t index) ICACHE_RAM_ATTR; uint32_t Pin(uint32_t gpio, uint32_t index = 0); uint32_t Pin(uint32_t gpio, uint32_t index) { -//#ifdef ESP8266 +#ifdef LEGACY_GPIO_ARRAY return pin[gpio + index]; // Pin number configured for gpio or 99 if not used -/* #else - uint16_t real_gpio = (gpio << 5) + index; +//#ifdef ESP8266 + uint16_t real_gpio = gpio + index; +//#else +// uint16_t real_gpio = (gpio << 5) + index; +//endif for (uint32_t i = 0; i < ARRAY_SIZE(pin); i++) { if (pin[i] == real_gpio) { return i; // Pin number configured for gpio @@ -1091,7 +1094,6 @@ uint32_t Pin(uint32_t gpio, uint32_t index) { } return 99; // No pin used for gpio #endif -*/ } boolean PinUsed(uint32_t gpio, uint32_t index = 0); @@ -1100,20 +1102,20 @@ boolean PinUsed(uint32_t gpio, uint32_t index) { } void SetPin(uint32_t lpin, uint32_t gpio) { -//#ifdef ESP8266 +#ifdef LEGACY_GPIO_ARRAY pin[gpio] = lpin; -/* #else pin[lpin] = gpio; #endif -*/ } +#ifdef LEGACY_GPIO_ARRAY void InitAllPins(void) { for (uint32_t i = 0; i < ARRAY_SIZE(pin); i++) { SetPin(99, i); } } +#endif void DigitalWrite(uint32_t gpio_pin, uint32_t index, uint32_t state) { diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 3db5ea2f7..72137edab 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1383,13 +1383,15 @@ void GpioInit(void) my_adc0 = template_adc0; // Force Template override } +#ifdef LEGACY_GPIO_ARRAY InitAllPins(); +#endif for (uint32_t i = 0; i < ARRAY_SIZE(my_module.io); i++) { uint32_t mpin = ValidPin(i, my_module.io[i]); DEBUG_CORE_LOG(PSTR("INI: gpio pin %d, mpin %d"), i, mpin); - if (mpin) { + if (mpin) { // Above GPIO_NONE XdrvMailbox.index = mpin; XdrvMailbox.payload = i; @@ -1398,16 +1400,16 @@ void GpioInit(void) mpin -= (GPIO_SWT1_NP - GPIO_SWT1); } else if ((mpin >= GPIO_KEY1_NP) && (mpin < (GPIO_KEY1_NP + MAX_KEYS))) { - ButtonPullupFlag(mpin - GPIO_KEY1_NP); // 0 .. 3 + ButtonPullupFlag(mpin - GPIO_KEY1_NP); // 0 .. 3 mpin -= (GPIO_KEY1_NP - GPIO_KEY1); } else if ((mpin >= GPIO_KEY1_INV) && (mpin < (GPIO_KEY1_INV + MAX_KEYS))) { - ButtonInvertFlag(mpin - GPIO_KEY1_INV); // 0 .. 3 + ButtonInvertFlag(mpin - GPIO_KEY1_INV); // 0 .. 3 mpin -= (GPIO_KEY1_INV - GPIO_KEY1); } else if ((mpin >= GPIO_KEY1_INV_NP) && (mpin < (GPIO_KEY1_INV_NP + MAX_KEYS))) { - ButtonPullupFlag(mpin - GPIO_KEY1_INV_NP); // 0 .. 3 - ButtonInvertFlag(mpin - GPIO_KEY1_INV_NP); // 0 .. 3 + ButtonPullupFlag(mpin - GPIO_KEY1_INV_NP); // 0 .. 3 + ButtonInvertFlag(mpin - GPIO_KEY1_INV_NP); // 0 .. 3 mpin -= (GPIO_KEY1_INV_NP - GPIO_KEY1); } else if ((mpin >= GPIO_REL1_INV) && (mpin < (GPIO_REL1_INV + MAX_RELAYS))) { @@ -1433,9 +1435,13 @@ void GpioInit(void) mpin = XdrvMailbox.index; }; } - if (mpin) { SetPin(i, mpin); } + if (mpin) { SetPin(i, mpin); } // Anything above GPIO_NONE and below GPIO_SENSOR_END } +#ifndef LEGACY_GPIO_ARRAY + AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t*)pin, ARRAY_SIZE(pin)); +#endif + #ifdef ESP8266 if ((2 == Pin(GPIO_TXD)) || (H801 == my_module_type)) { Serial.set_tx(2); } #endif // ESP8266 @@ -1446,9 +1452,11 @@ void GpioInit(void) #ifdef USE_SPI spi_flg = (((PinUsed(GPIO_SPI_CS) && (Pin(GPIO_SPI_CS) > 14)) || (Pin(GPIO_SPI_CS) < 12)) || ((PinUsed(GPIO_SPI_DC) && (Pin(GPIO_SPI_DC) > 14)) || (Pin(GPIO_SPI_DC) < 12))); if (spi_flg) { +#ifdef LEGACY_GPIO_ARRAY for (uint32_t i = 0; i < GPIO_MAX; i++) { if ((Pin(i) >= 12) && (Pin(i) <=14)) { SetPin(99, i); } } +#endif my_module.io[12] = GPIO_SPI_MISO; SetPin(12, GPIO_SPI_MISO); my_module.io[13] = GPIO_SPI_MOSI; @@ -1456,7 +1464,7 @@ void GpioInit(void) my_module.io[14] = GPIO_SPI_CLK; SetPin(14, GPIO_SPI_CLK); } - soft_spi_flg = (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_SCLK) && (PinUsed(GPIO_SSPI_MOSI) || PinUsed(GPIO_SSPI_MOSI))); + soft_spi_flg = (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_SCLK) && (PinUsed(GPIO_SSPI_MOSI) || PinUsed(GPIO_SSPI_MISO))); #endif // USE_SPI // Set any non-used GPIO to INPUT - Related to resetPins() in support_legacy_cores.ino @@ -1534,7 +1542,9 @@ void GpioInit(void) #ifdef USE_ARILUX_RF if ((3 == i) && (leds_present < 2) && !PinUsed(GPIO_ARIRFSEL)) { SetPin(Pin(GPIO_LED4), GPIO_ARIRFSEL); // Legacy support where LED4 was Arilux RF enable +#ifdef LEGACY_GPIO_ARRAY SetPin(99, GPIO_LED4); +#endif } else { #endif pinMode(Pin(GPIO_LED1, i), OUTPUT); diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 69be1bbe5..4f84832ac 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -119,7 +119,7 @@ uint16_t blink_counter = 0; // Number of blink cycles uint16_t seriallog_timer = 0; // Timer to disable Seriallog uint16_t syslog_timer = 0; // Timer to re-enable syslog_level //#ifdef ESP32 -//uint16_t pin[MAX_GPIO_PIN]; // Possible pin configurations +//uint16_t pin[MAX_GPIO_PIN] = { 0 }; // Possible pin configurations //#endif int16_t save_data_counter; // Counter and flag for config save to Flash RulesBitfield rules_flag; // Rule state flags (16 bits) @@ -130,7 +130,11 @@ uint8_t latching_relay_pulse = 0; // Latching relay pulse timer uint8_t ssleep; // Current copy of Settings.sleep uint8_t blinkspeed = 1; // LED blink rate //#ifdef ESP8266 +#ifdef LEGACY_GPIO_ARRAY uint8_t pin[GPIO_MAX]; // Possible pin configurations +#else +uint8_t pin[MAX_GPIO_PIN] = { 0 }; // Possible pin configurations +#endif //#endif uint8_t active_device = 1; // Active device in ExecuteCommandPower uint8_t leds_present = 0; // Max number of LED supported diff --git a/tasmota/tasmota_globals.h b/tasmota/tasmota_globals.h index 9b72ba954..8881f8334 100644 --- a/tasmota/tasmota_globals.h +++ b/tasmota/tasmota_globals.h @@ -53,6 +53,8 @@ extern "C" void resetPins(); * Mandatory defines satisfying disabled defines \*********************************************************************************************/ +//#define LEGACY_GPIO_ARRAY + #ifndef MODULE #define MODULE SONOFF_BASIC // [Module] Select default model #endif diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 614989ab4..0c2ad48cf 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -1582,6 +1582,7 @@ chknext: if (!strncmp(vname,"pd[",3)) { GetNumericResult(vname+3,OPER_EQU,&fvar,0); uint8_t gpiopin=fvar; +#ifdef LEGACY_GPIO_ARRAY for (uint8_t i=0;i 0)) { + fvar = pin[gpiopin]; + // skip ] bracket + len++; + goto exit; + } +#endif fvar=999; goto exit; } diff --git a/tasmota/xdrv_31_tasmota_slave.ino b/tasmota/xdrv_31_tasmota_slave.ino index 37b98c897..370a3f6d6 100644 --- a/tasmota/xdrv_31_tasmota_slave.ino +++ b/tasmota/xdrv_31_tasmota_slave.ino @@ -447,7 +447,9 @@ void TasmotaSlave_Init(void) TasmotaSlave_Serial->setTimeout(50); if (PinUsed(GPIO_TASMOTASLAVE_RST_INV)) { SetPin(Pin(GPIO_TASMOTASLAVE_RST_INV), GPIO_TASMOTASLAVE_RST); +#ifdef LEGACY_GPIO_ARRAY SetPin(99, GPIO_TASMOTASLAVE_RST_INV); +#endif TSlave.inverted = HIGH; } pinMode(Pin(GPIO_TASMOTASLAVE_RST), OUTPUT); diff --git a/tasmota/xnrg_01_hlw8012.ino b/tasmota/xnrg_01_hlw8012.ino index 12a10abb6..7a3becf0a 100644 --- a/tasmota/xnrg_01_hlw8012.ino +++ b/tasmota/xnrg_01_hlw8012.ino @@ -250,7 +250,9 @@ void HlwDrvInit(void) Hlw.model_type = 0; // HLW8012 if (PinUsed(GPIO_HJL_CF)) { SetPin(Pin(GPIO_HJL_CF), GPIO_HLW_CF); +#ifdef LEGACY_GPIO_ARRAY SetPin(99, GPIO_HJL_CF); +#endif Hlw.model_type = 1; // HJL-01/BL0937 } @@ -259,7 +261,9 @@ 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); +#ifdef LEGACY_GPIO_ARRAY SetPin(99, GPIO_NRG_SEL_INV); +#endif Hlw.ui_flag = false; // Voltage on low } diff --git a/tasmota/xsns_53_sml.ino b/tasmota/xsns_53_sml.ino index c61bfa20d..632f64f50 100755 --- a/tasmota/xsns_53_sml.ino +++ b/tasmota/xsns_53_sml.ino @@ -1831,12 +1831,18 @@ uint8_t *script_meter; #endif bool Gpio_used(uint8_t gpiopin) { +#ifdef LEGACY_GPIO_ARRAY for (uint16_t i=0;i 0)) { + return true; + } +#endif return false; } From c24de18278222e970935c9ba8a268c2406a418b7 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 28 Apr 2020 18:27:07 +0200 Subject: [PATCH 18/40] Change ESP32 pin allocation part 1 --- tasmota/settings.h | 11 + tasmota/support.ino | 43 +- tasmota/tasmota.h | 6 - tasmota/tasmota.ino | 28 +- tasmota/tasmota_globals.h | 13 +- tasmota/tasmota_template.h | 25 +- tasmota/tasmota_template_ESP32.h | 731 ++++++++++++++++++++++++ tasmota/tasmota_template_ESP32_final.h | 742 +++++++++++++++++++++++++ 8 files changed, 1548 insertions(+), 51 deletions(-) create mode 100644 tasmota/tasmota_template_ESP32_final.h diff --git a/tasmota/settings.h b/tasmota/settings.h index ccf3e44ed..e5c9800fd 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -358,8 +358,17 @@ struct { SysBitfield3 flag3; // 3A0 uint8_t switchmode[MAX_SWITCHES]; // 3A4 (6.0.0b - moved from 0x4CA) +#ifdef ESP8266 char ex_friendlyname[4][33]; // 3AC char ex_switch_topic[33]; // 430 +#else // ESP32 +#ifdef FINAL_ESP32 + myio my_gp; // 3AC - 2 x 40 bytes (ESP32) + mytmplt user_template; // 3FC - 2 x 37 bytes (ESP32) + + uint8_t free_esp32_446[11]; // 446 +#endif +#endif // ESP8266 - ESP32 char serial_delimiter; // 451 uint8_t seriallog_level; // 452 @@ -406,10 +415,12 @@ struct { #ifdef ESP8266 char ex_mqtt_fulltopic[100]; // 558 #else // ESP32 +#ifndef FINAL_ESP32 myio my_gp; // 558 - 40 bytes (ESP32) mytmplt user_template; // 580 - 37 bytes (ESP32) uint8_t free_esp32_5a5[23]; // 5A5 +#endif #endif // ESP8266 - ESP32 SysBitfield2 flag2; // 5BC diff --git a/tasmota/support.ino b/tasmota/support.ino index 1bcdb9015..02d17af98 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1081,19 +1081,23 @@ uint32_t Pin(uint32_t gpio, uint32_t index = 0); uint32_t Pin(uint32_t gpio, uint32_t index) { #ifdef LEGACY_GPIO_ARRAY return pin[gpio + index]; // Pin number configured for gpio or 99 if not used -#else -//#ifdef ESP8266 +#else // No LEGACY_GPIO_ARRAY +#ifdef ESP8266 uint16_t real_gpio = gpio + index; -//#else -// uint16_t real_gpio = (gpio << 5) + index; -//endif +#else // ESP32 +#ifndef FINAL_ESP32 + uint16_t real_gpio = gpio + index; +#else // FINAL_ESP32 + uint16_t real_gpio = (gpio << 5) + index; +#endif // FINAL_ESP32 +#endif // ESP8266 - ESP32 for (uint32_t i = 0; i < ARRAY_SIZE(pin); i++) { if (pin[i] == real_gpio) { return i; // Pin number configured for gpio } } return 99; // No pin used for gpio -#endif +#endif // No LEGACY_GPIO_ARRAY } boolean PinUsed(uint32_t gpio, uint32_t index = 0); @@ -1164,13 +1168,18 @@ String ModuleName(void) void ModuleGpios(myio *gp) { -//#ifdef ESP8266 +#ifdef ESP8266 uint8_t *dest = (uint8_t *)gp; uint8_t src[ARRAY_SIZE(Settings.user_template.gp.io)]; -//#else -// uint16_t *dest = (uint16_t *)gp; -// uint16_t src[ARRAY_SIZE(Settings.user_template.gp.io)]; -//#endif +#else // ESP32 +#ifndef FINAL_ESP32 + uint8_t *dest = (uint8_t *)gp; + uint8_t src[ARRAY_SIZE(Settings.user_template.gp.io)]; +#else // FINAL_ESP32 + uint16_t *dest = (uint16_t *)gp; + uint16_t src[ARRAY_SIZE(Settings.user_template.gp.io)]; +#endif +#endif // ESP8266 - ESP32 memset(dest, GPIO_NONE, sizeof(myio)); if (USER_MODULE == Settings.module) { @@ -1275,11 +1284,15 @@ bool ValidAdc(void) return (ADC0_USER == template_adc0); } -//#ifdef ESP8266 +#ifdef ESP8266 bool GetUsedInModule(uint32_t val, uint8_t *arr) -//#else -//bool GetUsedInModule(uint32_t val, uint16_t *arr) -//#endif +#else // ESP32 +#ifndef FINAL_ESP32 +bool GetUsedInModule(uint32_t val, uint8_t *arr) +#else // FINAL_ESP32 +bool GetUsedInModule(uint32_t val, uint16_t *arr) +#endif // FINAL_ESP32 +#endif // ESP8266 - ESP32 { int offset = 0; diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index aae4df24c..a1a3cb473 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -41,14 +41,8 @@ * Power Type \*********************************************************************************************/ -//#ifdef ESP8266 typedef unsigned long power_t; // Power (Relay) type const uint32_t POWER_MASK = 0xffffffffUL; // Power (Relay) full mask -//#endif // ESP8266 -//#ifdef ESP32 -//typedef uint64_t power_t; // Power (Relay) type -//const uint64_t POWER_MASK = 0xffffffffffffffffull; // Power (Relay) full mask -//#endif // ESP32 /*********************************************************************************************\ * Constants diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 4f84832ac..8af7285ad 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -118,9 +118,13 @@ uint16_t tele_period = 9999; // Tele period timer uint16_t blink_counter = 0; // Number of blink cycles uint16_t seriallog_timer = 0; // Timer to disable Seriallog uint16_t syslog_timer = 0; // Timer to re-enable syslog_level -//#ifdef ESP32 -//uint16_t pin[MAX_GPIO_PIN] = { 0 }; // Possible pin configurations -//#endif + +#ifdef ESP32 +#ifdef FINAL_ESP32 +uint16_t pin[MAX_GPIO_PIN] = { 0 }; // Possible pin configurations +#endif // FINAL_ESP32 +#endif // ESP32 + int16_t save_data_counter; // Counter and flag for config save to Flash RulesBitfield rules_flag; // Rule state flags (16 bits) uint8_t mqtt_cmnd_blocked = 0; // Ignore flag for publish command @@ -129,13 +133,23 @@ uint8_t state_250mS = 0; // State 250msecond per second flag uint8_t latching_relay_pulse = 0; // Latching relay pulse timer uint8_t ssleep; // Current copy of Settings.sleep uint8_t blinkspeed = 1; // LED blink rate -//#ifdef ESP8266 + +#ifdef ESP8266 #ifdef LEGACY_GPIO_ARRAY uint8_t pin[GPIO_MAX]; // Possible pin configurations -#else +#else // No LEGACY_GPIO_ARRAY uint8_t pin[MAX_GPIO_PIN] = { 0 }; // Possible pin configurations -#endif -//#endif +#endif // LEGACY_GPIO_ARRAY +#else // ESP32 +#ifndef FINAL_ESP32 +#ifdef LEGACY_GPIO_ARRAY +uint8_t pin[GPIO_MAX]; // Possible pin configurations +#else // No LEGACY_GPIO_ARRAY +uint8_t pin[MAX_GPIO_PIN] = { 0 }; // Possible pin configurations +#endif // LEGACY_GPIO_ARRAY +#endif // No FINAL_ESP32 +#endif // ESP8266 - ESP32 + uint8_t active_device = 1; // Active device in ExecuteCommandPower uint8_t leds_present = 0; // Max number of LED supported uint8_t led_inverted = 0; // LED inverted flag (1 = (0 = On, 1 = Off)) diff --git a/tasmota/tasmota_globals.h b/tasmota/tasmota_globals.h index 8881f8334..178cf3c24 100644 --- a/tasmota/tasmota_globals.h +++ b/tasmota/tasmota_globals.h @@ -50,10 +50,19 @@ extern "C" void resetPins(); #include "tasmota_configurations.h" // Preconfigured configurations /*********************************************************************************************\ - * Mandatory defines satisfying disabled defines + * Theo transition defines - DO NOT TOUCH \*********************************************************************************************/ -//#define LEGACY_GPIO_ARRAY +//#define LEGACY_GPIO_ARRAY // Uncomment to use legacy GPIO array instead of new PIN array + +//#define FINAL_ESP32 // Uncomment for ESP32 16-bits PIN array +#ifdef FINAL_ESP32 +#undef LEGACY_GPIO_ARRAY +#endif + +/*********************************************************************************************\ + * Mandatory defines satisfying disabled defines +\*********************************************************************************************/ #ifndef MODULE #define MODULE SONOFF_BASIC // [Module] Select default model diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index ae95705c7..5f9c23b7c 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -20,6 +20,8 @@ #ifndef _TASMOTA_TEMPLATE_H_ #define _TASMOTA_TEMPLATE_H_ +#ifdef ESP8266 + // User selectable GPIO functionality // ATTENTION: Only add at the end of this list just before GPIO_SENSOR_END // Then add the same name(s) in a nice location in array kGpioNiceList @@ -699,31 +701,14 @@ const char kAdc0Names[] PROGMEM = /********************************************************************************************/ -#ifdef ESP8266 - #define MAX_GPIO_PIN 17 // Number of supported GPIO #define MIN_FLASH_PINS 4 // Number of flash chip pins unusable for configuration (GPIO6, 7, 8 and 11) +#define MAX_USER_PINS 13 // MAX_GPIO_PIN - MIN_FLASH_PINS #define ADC0_PIN 17 // Pin number of ADC0 #define WEMOS_MODULE 17 // Wemos module const char PINS_WEMOS[] PROGMEM = "D3TXD4RXD2D1flashcFLFLolD6D7D5D8D0A0"; -#else // ESP32 - -// esp32 has more pins -#define USER_MODULE 255 -#define MAX_GPIO_PIN 40 // Number of supported GPIO -#define MIN_FLASH_PINS 4 // Number of flash chip pins unusable for configuration (GPIO6, 7, 8 and 11) -#define ADC0_PIN 33 // Pin number of ADC0 -#define WEMOS_MODULE 0 // Wemos module - -// 0 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930313233343536373839 -const char PINS_WEMOS[] PROGMEM = "IOTXIORXIOIOflashcFLFLolIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOA6A7A0IoIoA3"; - -#endif // ESP8266 - -#define MAX_USER_PINS MAX_GPIO_PIN-MIN_FLASH_PINS - /********************************************************************************************/ typedef struct MYIO { @@ -758,10 +743,8 @@ typedef struct MYTMPLT { } mytmplt; /********************************************************************************************/ - -#ifdef ESP8266 - // Supported hardware modules + enum SupportedModules { SONOFF_BASIC, SONOFF_RF, SONOFF_SV, SONOFF_TH, SONOFF_DUAL, SONOFF_POW, SONOFF_4CH, SONOFF_S2X, SLAMPHER, SONOFF_TOUCH, SONOFF_LED, CH1, CH4, MOTOR, ELECTRODRAGON, EXS_RELAY, WION, WEMOS, SONOFF_DEV, H801, diff --git a/tasmota/tasmota_template_ESP32.h b/tasmota/tasmota_template_ESP32.h index 831532a59..4dfd9dd90 100644 --- a/tasmota/tasmota_template_ESP32.h +++ b/tasmota/tasmota_template_ESP32.h @@ -21,6 +21,7 @@ #define _TASMOTA_TEMPLATE_ESP32_H_ #ifdef ESP32 +#ifndef FINAL_ESP32 // Hardware has no ESP32 #undef USE_TUYA_DIMMER @@ -42,12 +43,738 @@ #undef USE_TUYA_MCU #undef USE_PS_16_DZ +// User selectable GPIO functionality +// ATTENTION: Only add at the end of this list just before GPIO_SENSOR_END +// Then add the same name(s) in a nice location in array kGpioNiceList +enum UserSelectablePins { + GPIO_NONE, // Not used + GPIO_DHT11, // DHT11 + GPIO_DHT22, // DHT21, DHT22, AM2301, AM2302, AM2321 + GPIO_SI7021, // iTead SI7021 + GPIO_DSB, // Single wire DS18B20 or DS18S20 + GPIO_I2C_SCL, // I2C SCL + GPIO_I2C_SDA, // I2C SDA + GPIO_WS2812, // WS2812 Led string + GPIO_IRSEND, // IR remote + GPIO_SWT1, // User connected external switches + GPIO_SWT2, + GPIO_SWT3, + GPIO_SWT4, + GPIO_SWT5, + GPIO_SWT6, + GPIO_SWT7, + GPIO_SWT8, + GPIO_KEY1, // Button usually connected to GPIO0 + GPIO_KEY2, + GPIO_KEY3, + GPIO_KEY4, + GPIO_REL1, // Relays + GPIO_REL2, + GPIO_REL3, + GPIO_REL4, + GPIO_REL5, + GPIO_REL6, + GPIO_REL7, + GPIO_REL8, + GPIO_REL1_INV, + GPIO_REL2_INV, + GPIO_REL3_INV, + GPIO_REL4_INV, + GPIO_REL5_INV, + GPIO_REL6_INV, + GPIO_REL7_INV, + GPIO_REL8_INV, + GPIO_PWM1, // RGB Red or C Cold White + GPIO_PWM2, // RGB Green or CW Warm White + GPIO_PWM3, // RGB Blue + GPIO_PWM4, // RGBW (Cold) White + GPIO_PWM5, // RGBCW Warm White + GPIO_CNTR1, + GPIO_CNTR2, + GPIO_CNTR3, + GPIO_CNTR4, + GPIO_PWM1_INV, // RGB Red or C Cold White + GPIO_PWM2_INV, // RGB Green or CW Warm White + GPIO_PWM3_INV, // RGB Blue + GPIO_PWM4_INV, // RGBW (Cold) White + GPIO_PWM5_INV, // RGBCW Warm White + GPIO_IRRECV, // IR receiver + GPIO_LED1, // Leds + GPIO_LED2, + GPIO_LED3, + GPIO_LED4, + GPIO_LED1_INV, + GPIO_LED2_INV, + GPIO_LED3_INV, + GPIO_LED4_INV, + GPIO_MHZ_TXD, // MH-Z19 Serial interface + GPIO_MHZ_RXD, // MH-Z19 Serial interface + GPIO_PZEM0XX_TX, // PZEM0XX Serial interface + GPIO_PZEM004_RX, // PZEM004T Serial interface + GPIO_SAIR_TX, // SenseAir Serial interface + GPIO_SAIR_RX, // SenseAir Serial interface + GPIO_SPI_CS, // SPI Chip Select + GPIO_SPI_DC, // SPI Data Direction + GPIO_BACKLIGHT, // Display backlight control + GPIO_PMS5003_RX, // Plantower PMS5003 Serial interface + GPIO_SDS0X1_RX, // Nova Fitness SDS011 Serial interface + GPIO_SBR_TX, // Serial Bridge Serial interface + GPIO_SBR_RX, // Serial Bridge Serial interface + GPIO_SR04_TRIG, // SR04 Trigger/TX pin + GPIO_SR04_ECHO, // SR04 Echo/RX pin + GPIO_SDM120_TX, // SDM120 Serial interface + GPIO_SDM120_RX, // SDM120 Serial interface + GPIO_SDM630_TX, // SDM630 Serial interface + GPIO_SDM630_RX, // SDM630 Serial interface + GPIO_TM16CLK, // TM1638 Clock + GPIO_TM16DIO, // TM1638 Data I/O + GPIO_TM16STB, // TM1638 Strobe + GPIO_SWT1_NP, // User connected external switches + GPIO_SWT2_NP, + GPIO_SWT3_NP, + GPIO_SWT4_NP, + GPIO_SWT5_NP, + GPIO_SWT6_NP, + GPIO_SWT7_NP, + GPIO_SWT8_NP, + GPIO_KEY1_NP, // Button usually connected to GPIO0 + GPIO_KEY2_NP, + GPIO_KEY3_NP, + GPIO_KEY4_NP, + GPIO_CNTR1_NP, + GPIO_CNTR2_NP, + GPIO_CNTR3_NP, + GPIO_CNTR4_NP, + GPIO_PZEM016_RX, // PZEM-014,016 Serial Modbus interface + GPIO_PZEM017_RX, // PZEM-003,017 Serial Modbus interface + GPIO_MP3_DFR562, // RB-DFR-562, DFPlayer Mini MP3 Player + GPIO_SDS0X1_TX, // Nova Fitness SDS011 Serial interface + GPIO_HX711_SCK, // HX711 Load Cell clock + GPIO_HX711_DAT, // HX711 Load Cell data + GPIO_TX2X_TXD_BLACK, // TX20/TX23 Transmission Pin + GPIO_RFSEND, // RF transmitter + GPIO_RFRECV, // RF receiver + GPIO_TUYA_TX, // Tuya Serial interface + GPIO_TUYA_RX, // Tuya Serial interface + GPIO_MGC3130_XFER, // MGC3130 Transfer + GPIO_MGC3130_RESET, // MGC3130 Reset + GPIO_SSPI_MISO, // Software SPI Master Input Slave Output + GPIO_SSPI_MOSI, // Software SPI Master Output Slave Input + GPIO_SSPI_SCLK, // Software SPI Serial Clock + GPIO_SSPI_CS, // Software SPI Chip Select + GPIO_SSPI_DC, // Software SPI Data or Command + GPIO_RF_SENSOR, // Rf receiver with sensor decoding + GPIO_AZ_TXD, // AZ-Instrument 7798 Serial interface + GPIO_AZ_RXD, // AZ-Instrument 7798 Serial interface + GPIO_MAX31855CS, // MAX31855 Serial interface + GPIO_MAX31855CLK, // MAX31855 Serial interface + GPIO_MAX31855DO, // MAX31855 Serial interface + GPIO_KEY1_INV, // Inverted buttons + GPIO_KEY2_INV, + GPIO_KEY3_INV, + GPIO_KEY4_INV, + GPIO_KEY1_INV_NP, // Inverted buttons without pull-up + GPIO_KEY2_INV_NP, + GPIO_KEY3_INV_NP, + GPIO_KEY4_INV_NP, + GPIO_NRG_SEL, // HLW8012/HLJ-01 Sel output (1 = Voltage) + GPIO_NRG_SEL_INV, // HLW8012/HLJ-01 Sel output (0 = Voltage) + GPIO_NRG_CF1, // HLW8012/HLJ-01 CF1 voltage / current + GPIO_HLW_CF, // HLW8012 CF power + GPIO_HJL_CF, // HJL-01/BL0937 CF power + GPIO_MCP39F5_TX, // MCP39F501 Serial interface (Shelly2) + GPIO_MCP39F5_RX, // MCP39F501 Serial interface (Shelly2) + GPIO_MCP39F5_RST, // MCP39F501 Reset (Shelly2) + GPIO_PN532_TXD, // PN532 NFC Serial Tx + GPIO_PN532_RXD, // PN532 NFC Serial Rx + GPIO_SM16716_CLK, // SM16716 CLOCK + GPIO_SM16716_DAT, // SM16716 DATA + GPIO_SM16716_SEL, // SM16716 SELECT + GPIO_DI, // my92x1 PWM input + GPIO_DCKI, // my92x1 CLK input + GPIO_CSE7766_TX, // CSE7766 Serial interface (S31 and Pow R2) - Not used anymore 20200121 + GPIO_CSE7766_RX, // CSE7766 Serial interface (S31 and Pow R2) + GPIO_ARIRFRCV, // AriLux RF Receive input + GPIO_TXD, // Serial interface + GPIO_RXD, // Serial interface + GPIO_ROT1A, // Rotary switch1 A Pin + GPIO_ROT1B, // Rotary switch1 B Pin + GPIO_ROT2A, // Rotary switch2 A Pin + GPIO_ROT2B, // Rotary switch2 B Pin + GPIO_HRE_CLOCK, // Clock/Power line for HR-E Water Meter + GPIO_HRE_DATA, // Data line for HR-E Water Meter + GPIO_ADE7953_IRQ, // ADE7953 IRQ + GPIO_LEDLNK, // Link led + GPIO_LEDLNK_INV, // Inverted link led + GPIO_ARIRFSEL, // Arilux RF Receive input selected + GPIO_BUZZER, // Buzzer + GPIO_BUZZER_INV, // Inverted buzzer + GPIO_OLED_RESET, // OLED Display Reset + GPIO_SOLAXX1_TX, // Solax Inverter tx pin + GPIO_SOLAXX1_RX, // Solax Inverter rx pin + GPIO_ZIGBEE_TX, // Zigbee Serial interface + GPIO_ZIGBEE_RX, // Zigbee Serial interface + GPIO_RDM6300_RX, // RDM6300 RX + GPIO_IBEACON_TX, // HM17 IBEACON TX + GPIO_IBEACON_RX, // HM17 IBEACON RX + GPIO_A4988_DIR, // A4988 direction pin + GPIO_A4988_STP, // A4988 step pin + GPIO_A4988_ENA, // A4988 enabled pin + GPIO_A4988_MS1, // A4988 microstep pin1 + GPIO_A4988_MS2, // A4988 microstep pin2 + GPIO_A4988_MS3, // A4988 microstep pin3 + GPIO_DDS2382_TX, // DDS2382 Serial interface + GPIO_DDS2382_RX, // DDS2382 Serial interface + GPIO_DDSU666_TX, // DDSU666 Serial interface + GPIO_DDSU666_RX, // DDSU666 Serial interface + GPIO_SM2135_CLK, // SM2135 Clk + GPIO_SM2135_DAT, // SM2135 Dat + GPIO_DEEPSLEEP, // Kill switch for deepsleep + GPIO_EXS_ENABLE, // EXS MCU Enable + GPIO_TASMOTASLAVE_TXD, // Slave TX + GPIO_TASMOTASLAVE_RXD, // Slave RX + GPIO_TASMOTASLAVE_RST, // Slave Reset Pin + GPIO_TASMOTASLAVE_RST_INV, // Slave Reset Inverted + GPIO_HPMA_RX, // Honeywell HPMA115S0 Serial interface + GPIO_HPMA_TX, // Honeywell HPMA115S0 Serial interface + GPIO_GPS_RX, // GPS serial interface + GPIO_GPS_TX, // GPS serial interface + GPIO_DSB_OUT, // Pseudo Single wire DS18B20 or DS18S20 + GPIO_DHT11_OUT, // Pseudo Single wire DHT11, DHT21, DHT22, AM2301, AM2302, AM2321 + GPIO_HM10_RX, // HM10-BLE-Mijia-bridge serial interface + GPIO_HM10_TX, // HM10-BLE-Mijia-bridge serial interface + GPIO_LE01MR_RX, // F&F LE-01MR energy meter + GPIO_LE01MR_TX, // F&F LE-01MR energy meter + GPIO_CC1101_GDO0, // CC1101 pin for RX + GPIO_CC1101_GDO2, // CC1101 pin for RX + GPIO_HRXL_RX, // Data from MaxBotix HRXL sonar range sensor + GPIO_ELECTRIQ_MOODL_TX, // ElectriQ iQ-wifiMOODL Serial TX + GPIO_AS3935, + GPIO_PMS5003_TX, // Plantower PMS5003 Serial interface + GPIO_SENSOR_END }; + +// Programmer selectable GPIO functionality +enum ProgramSelectablePins { + GPIO_FIX_START = 251, + GPIO_SPI_MISO, // SPI MISO library fixed pin GPIO12 + GPIO_SPI_MOSI, // SPI MOSI library fixed pin GPIO13 + GPIO_SPI_CLK, // SPI Clk library fixed pin GPIO14 + GPIO_USER, // User configurable needs to be 255 + GPIO_MAX }; + +// Text in webpage Module Parameters and commands GPIOS and GPIO +const char kSensorNames[] PROGMEM = + D_SENSOR_NONE "|" + D_SENSOR_DHT11 "|" D_SENSOR_AM2301 "|" D_SENSOR_SI7021 "|" + D_SENSOR_DS18X20 "|" + D_SENSOR_I2C_SCL "|" D_SENSOR_I2C_SDA "|" + D_SENSOR_WS2812 "|" + D_SENSOR_IRSEND "|" + D_SENSOR_SWITCH "1|" D_SENSOR_SWITCH "2|" D_SENSOR_SWITCH "3|" D_SENSOR_SWITCH "4|" D_SENSOR_SWITCH "5|" D_SENSOR_SWITCH "6|" D_SENSOR_SWITCH "7|" D_SENSOR_SWITCH "8|" + D_SENSOR_BUTTON "1|" D_SENSOR_BUTTON "2|" D_SENSOR_BUTTON "3|" D_SENSOR_BUTTON "4|" + D_SENSOR_RELAY "1|" D_SENSOR_RELAY "2|" D_SENSOR_RELAY "3|" D_SENSOR_RELAY "4|" D_SENSOR_RELAY "5|" D_SENSOR_RELAY "6|" D_SENSOR_RELAY "7|" D_SENSOR_RELAY "8|" + D_SENSOR_RELAY "1i|" D_SENSOR_RELAY "2i|" D_SENSOR_RELAY "3i|" D_SENSOR_RELAY "4i|" D_SENSOR_RELAY "5i|" D_SENSOR_RELAY "6i|" D_SENSOR_RELAY "7i|" D_SENSOR_RELAY "8i|" + D_SENSOR_PWM "1|" D_SENSOR_PWM "2|" D_SENSOR_PWM "3|" D_SENSOR_PWM "4|" D_SENSOR_PWM "5|" + D_SENSOR_COUNTER "1|" D_SENSOR_COUNTER "2|" D_SENSOR_COUNTER "3|" D_SENSOR_COUNTER "4|" + D_SENSOR_PWM "1i|" D_SENSOR_PWM "2i|" D_SENSOR_PWM "3i|" D_SENSOR_PWM "4i|" D_SENSOR_PWM "5i|" + D_SENSOR_IRRECV "|" + D_SENSOR_LED "1|" D_SENSOR_LED "2|" D_SENSOR_LED "3|" D_SENSOR_LED "4|" + D_SENSOR_LED "1i|" D_SENSOR_LED "2i|" D_SENSOR_LED "3i|" D_SENSOR_LED "4i|" + D_SENSOR_MHZ_TX "|" D_SENSOR_MHZ_RX "|" + D_SENSOR_PZEM0XX_TX "|" D_SENSOR_PZEM004_RX "|" + D_SENSOR_SAIR_TX "|" D_SENSOR_SAIR_RX "|" + D_SENSOR_SPI_CS "|" D_SENSOR_SPI_DC "|" D_SENSOR_BACKLIGHT "|" + D_SENSOR_PMS5003_RX "|" D_SENSOR_SDS0X1_RX "|" + D_SENSOR_SBR_TX "|" D_SENSOR_SBR_RX "|" + D_SENSOR_SR04_TRIG "|" D_SENSOR_SR04_ECHO "|" + D_SENSOR_SDM120_TX "|" D_SENSOR_SDM120_RX "|" + D_SENSOR_SDM630_TX "|" D_SENSOR_SDM630_RX "|" + D_SENSOR_TM1638_CLK "|" D_SENSOR_TM1638_DIO "|" D_SENSOR_TM1638_STB "|" + D_SENSOR_SWITCH "1n|" D_SENSOR_SWITCH "2n|" D_SENSOR_SWITCH "3n|" D_SENSOR_SWITCH "4n|" D_SENSOR_SWITCH "5n|" D_SENSOR_SWITCH "6n|" D_SENSOR_SWITCH "7n|" D_SENSOR_SWITCH "8n|" + D_SENSOR_BUTTON "1n|" D_SENSOR_BUTTON "2n|" D_SENSOR_BUTTON "3n|" D_SENSOR_BUTTON "4n|" + D_SENSOR_COUNTER "1n|" D_SENSOR_COUNTER "2n|" D_SENSOR_COUNTER "3n|" D_SENSOR_COUNTER "4n|" + D_SENSOR_PZEM016_RX "|" D_SENSOR_PZEM017_RX "|" + D_SENSOR_DFR562 "|" D_SENSOR_SDS0X1_TX "|" + D_SENSOR_HX711_SCK "|" D_SENSOR_HX711_DAT "|" + D_SENSOR_TX2X_TX "|" + D_SENSOR_RFSEND "|" D_SENSOR_RFRECV "|" + D_SENSOR_TUYA_TX "|" D_SENSOR_TUYA_RX "|" + D_SENSOR_MGC3130_XFER "|" D_SENSOR_MGC3130_RESET "|" + D_SENSOR_SSPI_MISO "|" D_SENSOR_SSPI_MOSI "|" D_SENSOR_SSPI_SCLK "|" D_SENSOR_SSPI_CS "|" D_SENSOR_SSPI_DC "|" + D_SENSOR_RF_SENSOR "|" + D_SENSOR_AZ_TX "|" D_SENSOR_AZ_RX "|" + D_SENSOR_MAX31855_CS "|" D_SENSOR_MAX31855_CLK "|" D_SENSOR_MAX31855_DO "|" + D_SENSOR_BUTTON "1i|" D_SENSOR_BUTTON "2i|" D_SENSOR_BUTTON "3i|" D_SENSOR_BUTTON "4i|" + D_SENSOR_BUTTON "1in|" D_SENSOR_BUTTON "2in|" D_SENSOR_BUTTON "3in|" D_SENSOR_BUTTON "4in|" + D_SENSOR_NRG_SEL "|" D_SENSOR_NRG_SEL "i|" D_SENSOR_NRG_CF1 "|" D_SENSOR_HLW_CF "|" D_SENSOR_HJL_CF "|" + D_SENSOR_MCP39F5_TX "|" D_SENSOR_MCP39F5_RX "|" D_SENSOR_MCP39F5_RST "|" + D_SENSOR_PN532_TX "|" D_SENSOR_PN532_RX "|" + D_SENSOR_SM16716_CLK "|" D_SENSOR_SM16716_DAT "|" D_SENSOR_SM16716_POWER "|" + D_SENSOR_MY92X1_DI "|" D_SENSOR_MY92X1_DCKI "|" + D_SENSOR_CSE7766_TX "|" D_SENSOR_CSE7766_RX "|" + D_SENSOR_ARIRFRCV "|" D_SENSOR_TXD "|" D_SENSOR_RXD "|" + D_SENSOR_ROTARY "1a|" D_SENSOR_ROTARY "1b|" D_SENSOR_ROTARY "2a|" D_SENSOR_ROTARY "2b|" + D_SENSOR_HRE_CLOCK "|" D_SENSOR_HRE_DATA "|" + D_SENSOR_ADE7953_IRQ "|" + D_SENSOR_LED_LINK "|" D_SENSOR_LED_LINK "i|" + D_SENSOR_ARIRFSEL "|" + D_SENSOR_BUZZER "|" D_SENSOR_BUZZER "i|" + D_SENSOR_OLED_RESET "|" + D_SENSOR_SOLAXX1_TX "|" D_SENSOR_SOLAXX1_RX "|" + D_SENSOR_ZIGBEE_TXD "|" D_SENSOR_ZIGBEE_RXD "|" + D_SENSOR_RDM6300_RX "|" + D_SENSOR_IBEACON_TX "|" D_SENSOR_IBEACON_RX "|" + D_SENSOR_A4988_DIR "|" D_SENSOR_A4988_STP "|" D_SENSOR_A4988_ENA "|" D_SENSOR_A4988_MS1 "|" D_SENSOR_A4988_MS2 "|" D_SENSOR_A4988_MS3 "|" + D_SENSOR_DDS2382_TX "|" D_SENSOR_DDS2382_RX "|" + D_SENSOR_DDSU666_TX "|" D_SENSOR_DDSU666_RX "|" + D_SENSOR_SM2135_CLK "|" D_SENSOR_SM2135_DAT "|" + D_SENSOR_DEEPSLEEP "|" D_SENSOR_EXS_ENABLE "|" + D_SENSOR_SLAVE_TX "|" D_SENSOR_SLAVE_RX "|" D_SENSOR_SLAVE_RESET "|" D_SENSOR_SLAVE_RESET "i|" + D_SENSOR_HPMA_RX "|" D_SENSOR_HPMA_TX "|" + D_SENSOR_GPS_RX "|" D_SENSOR_GPS_TX "|" + D_SENSOR_DS18X20 "o|" D_SENSOR_DHT11 "o|" + D_SENSOR_HM10_RX "|" D_SENSOR_HM10_TX "|" + D_SENSOR_LE01MR_RX "|" D_SENSOR_LE01MR_TX "|" + D_SENSOR_CC1101_GDO0 "|" D_SENSOR_CC1101_GDO2 "|" + D_SENSOR_HRXL_RX "|" + D_SENSOR_ELECTRIQ_MOODL "|" + D_SENSOR_AS3935 "|" D_SENSOR_PMS5003_TX + ; + +const char kSensorNamesFixed[] PROGMEM = + D_SENSOR_SPI_MISO "|" D_SENSOR_SPI_MOSI "|" D_SENSOR_SPI_CLK "|" + D_SENSOR_USER; + +const uint8_t kGpioNiceList[] PROGMEM = { + GPIO_NONE, // Not used + GPIO_KEY1, // Buttons + GPIO_KEY1_NP, + GPIO_KEY1_INV, + GPIO_KEY1_INV_NP, + GPIO_KEY2, + GPIO_KEY2_NP, + GPIO_KEY2_INV, + GPIO_KEY2_INV_NP, + GPIO_KEY3, + GPIO_KEY3_NP, + GPIO_KEY3_INV, + GPIO_KEY3_INV_NP, + GPIO_KEY4, + GPIO_KEY4_NP, + GPIO_KEY4_INV, + GPIO_KEY4_INV_NP, + GPIO_SWT1, // User connected external switches + GPIO_SWT1_NP, + GPIO_SWT2, + GPIO_SWT2_NP, + GPIO_SWT3, + GPIO_SWT3_NP, + GPIO_SWT4, + GPIO_SWT4_NP, + GPIO_SWT5, + GPIO_SWT5_NP, + GPIO_SWT6, + GPIO_SWT6_NP, + GPIO_SWT7, + GPIO_SWT7_NP, + GPIO_SWT8, + GPIO_SWT8_NP, + GPIO_REL1, // Relays + GPIO_REL1_INV, + GPIO_REL2, + GPIO_REL2_INV, + GPIO_REL3, + GPIO_REL3_INV, + GPIO_REL4, + GPIO_REL4_INV, + GPIO_REL5, + GPIO_REL5_INV, + GPIO_REL6, + GPIO_REL6_INV, + GPIO_REL7, + GPIO_REL7_INV, + GPIO_REL8, + GPIO_REL8_INV, + GPIO_LED1, // Leds + GPIO_LED1_INV, + GPIO_LED2, + GPIO_LED2_INV, + GPIO_LED3, + GPIO_LED3_INV, + GPIO_LED4, + GPIO_LED4_INV, + GPIO_LEDLNK, // Link led + GPIO_LEDLNK_INV, // Inverted link led + GPIO_PWM1, // RGB Red or C Cold White + GPIO_PWM1_INV, + GPIO_PWM2, // RGB Green or CW Warm White + GPIO_PWM2_INV, + GPIO_PWM3, // RGB Blue + GPIO_PWM3_INV, + GPIO_PWM4, // RGBW (Cold) White + GPIO_PWM4_INV, + GPIO_PWM5, // RGBCW Warm White + GPIO_PWM5_INV, +#ifdef USE_COUNTER + GPIO_CNTR1, // Counters + GPIO_CNTR1_NP, + GPIO_CNTR2, + GPIO_CNTR2_NP, + GPIO_CNTR3, + GPIO_CNTR3_NP, + GPIO_CNTR4, + GPIO_CNTR4_NP, +#endif +#ifdef USE_BUZZER + GPIO_BUZZER, // Buzzer + GPIO_BUZZER_INV, // Inverted buzzer +#endif + GPIO_TXD, // Serial interface + GPIO_RXD, // Serial interface +#ifdef USE_I2C + GPIO_I2C_SCL, // I2C SCL + GPIO_I2C_SDA, // I2C SDA +#endif +#ifdef USE_SPI + GPIO_SPI_CS, // SPI Chip Select + GPIO_SPI_DC, // SPI Data Direction + GPIO_SSPI_MISO, // Software SPI Master Input Slave Output + GPIO_SSPI_MOSI, // Software SPI Master Output Slave Input + GPIO_SSPI_SCLK, // Software SPI Serial Clock + GPIO_SSPI_CS, // Software SPI Chip Select + GPIO_SSPI_DC, // Software SPI Data or Command +#endif +#ifdef USE_DISPLAY + GPIO_BACKLIGHT, // Display backlight control + GPIO_OLED_RESET, // OLED Display Reset +#endif +#ifdef USE_DHT + GPIO_DHT11, // DHT11 + GPIO_DHT22, // DHT21, DHT22, AM2301, AM2302, AM2321 + GPIO_SI7021, // iTead SI7021 + GPIO_DHT11_OUT, // Pseudo Single wire DHT11, DHT21, DHT22, AM2301, AM2302, AM2321 +#endif +#ifdef USE_DS18x20 + GPIO_DSB, // Single wire DS18B20 or DS18S20 + GPIO_DSB_OUT, // Pseudo Single wire DS18B20 or DS18S20 +#endif + +// Light +#ifdef USE_LIGHT +#ifdef USE_WS2812 + GPIO_WS2812, // WS2812 Led string +#endif +#ifdef USE_ARILUX_RF + GPIO_ARIRFRCV, // AriLux RF Receive input + GPIO_ARIRFSEL, // Arilux RF Receive input selected +#endif +#ifdef USE_MY92X1 + GPIO_DI, // my92x1 PWM input + GPIO_DCKI, // my92x1 CLK input +#endif // USE_MY92X1 +#ifdef USE_SM16716 + GPIO_SM16716_CLK, // SM16716 CLOCK + GPIO_SM16716_DAT, // SM16716 DATA + GPIO_SM16716_SEL, // SM16716 SELECT +#endif // USE_SM16716 +#ifdef USE_SM2135 + GPIO_SM2135_CLK, // SM2135 CLOCK + GPIO_SM2135_DAT, // SM2135 DATA +#endif // USE_SM2135 +#ifdef USE_TUYA_MCU + GPIO_TUYA_TX, // Tuya Serial interface + GPIO_TUYA_RX, // Tuya Serial interface +#endif +#ifdef USE_EXS_DIMMER + GPIO_EXS_ENABLE, // EXS MCU Enable +#endif +#ifdef USE_ELECTRIQ_MOODL + GPIO_ELECTRIQ_MOODL_TX, +#endif +#endif // USE_LIGHT + +#if defined(USE_IR_REMOTE) || defined(USE_IR_REMOTE_FULL) + GPIO_IRSEND, // IR remote +#if defined(USE_IR_RECEIVE) || defined(USE_IR_REMOTE_FULL) + GPIO_IRRECV, // IR receiver +#endif +#endif + +#ifdef USE_RC_SWITCH + GPIO_RFSEND, // RF transmitter + GPIO_RFRECV, // RF receiver +#endif +#ifdef USE_RF_SENSOR + GPIO_RF_SENSOR, // Rf receiver with sensor decoding +#endif +#ifdef USE_SR04 + GPIO_SR04_TRIG, // SR04 Tri/TXgger pin + GPIO_SR04_ECHO, // SR04 Ech/RXo pin +#endif +#ifdef USE_TM1638 + GPIO_TM16CLK, // TM1638 Clock + GPIO_TM16DIO, // TM1638 Data I/O + GPIO_TM16STB, // TM1638 Strobe +#endif +#ifdef USE_HX711 + GPIO_HX711_SCK, // HX711 Load Cell clock + GPIO_HX711_DAT, // HX711 Load Cell data +#endif + +// Energy sensors +#ifdef USE_ENERGY_SENSOR +#ifdef USE_HLW8012 + GPIO_NRG_SEL, // HLW8012/HLJ-01 Sel output (1 = Voltage) + GPIO_NRG_SEL_INV, // HLW8012/HLJ-01 Sel output (0 = Voltage) + GPIO_NRG_CF1, // HLW8012/HLJ-01 CF1 voltage / current + GPIO_HLW_CF, // HLW8012 CF power + GPIO_HJL_CF, // HJL-01/BL0937 CF power +#endif +#if defined(USE_I2C) && defined(USE_ADE7953) + GPIO_ADE7953_IRQ, // ADE7953 IRQ +#endif +#ifdef USE_CSE7766 + GPIO_CSE7766_TX, // CSE7766 Serial interface (S31 and Pow R2) + GPIO_CSE7766_RX, // CSE7766 Serial interface (S31 and Pow R2) +#endif +#ifdef USE_MCP39F501 + GPIO_MCP39F5_TX, // MCP39F501 Serial interface (Shelly2) + GPIO_MCP39F5_RX, // MCP39F501 Serial interface (Shelly2) + GPIO_MCP39F5_RST, // MCP39F501 Reset (Shelly2) +#endif +#if defined(USE_PZEM004T) || defined(USE_PZEM_AC) || defined(USE_PZEM_DC) + GPIO_PZEM0XX_TX, // PZEM0XX Serial interface +#endif +#ifdef USE_PZEM004T + GPIO_PZEM004_RX, // PZEM004T Serial interface +#endif +#ifdef USE_PZEM_AC + GPIO_PZEM016_RX, // PZEM-014,016 Serial Modbus interface +#endif +#ifdef USE_PZEM_DC + GPIO_PZEM017_RX, // PZEM-003,017 Serial Modbus interface +#endif +#ifdef USE_SDM120 + GPIO_SDM120_TX, // SDM120 Serial interface + GPIO_SDM120_RX, // SDM120 Serial interface +#endif +#ifdef USE_SDM630 + GPIO_SDM630_TX, // SDM630 Serial interface + GPIO_SDM630_RX, // SDM630 Serial interface +#endif +#ifdef USE_DDS2382 + GPIO_DDS2382_TX, // DDS2382 Serial interface + GPIO_DDS2382_RX, // DDS2382 Serial interface +#endif +#ifdef USE_DDSU666 + GPIO_DDSU666_TX, // DDSU666 Serial interface + GPIO_DDSU666_RX, // DDSU666 Serial interface +#endif // USE_DDSU666 +#ifdef USE_SOLAX_X1 + GPIO_SOLAXX1_TX, // Solax Inverter tx pin + GPIO_SOLAXX1_RX, // Solax Inverter rx pin +#endif // USE_SOLAX_X1 +#ifdef USE_LE01MR + GPIO_LE01MR_RX, // F7F LE-01MR energy meter rx pin + GPIO_LE01MR_TX, // F7F LE-01MR energy meter tx pin +#endif // IFDEF:USE_LE01MR +#endif // USE_ENERGY_SENSOR + +// Serial +#ifdef USE_SERIAL_BRIDGE + GPIO_SBR_TX, // Serial Bridge Serial interface + GPIO_SBR_RX, // Serial Bridge Serial interface +#endif +#ifdef USE_ZIGBEE + GPIO_ZIGBEE_TX, // Zigbee Serial interface + GPIO_ZIGBEE_RX, // Zigbee Serial interface +#endif +#ifdef USE_MHZ19 + GPIO_MHZ_TXD, // MH-Z19 Serial interface + GPIO_MHZ_RXD, // MH-Z19 Serial interface +#endif +#ifdef USE_SENSEAIR + GPIO_SAIR_TX, // SenseAir Serial interface + GPIO_SAIR_RX, // SenseAir Serial interface +#endif +#ifdef USE_NOVA_SDS + GPIO_SDS0X1_TX, // Nova Fitness SDS011 Serial interface + GPIO_SDS0X1_RX, // Nova Fitness SDS011 Serial interface +#endif +#ifdef USE_HPMA + GPIO_HPMA_TX, // Honeywell HPMA115S0 Serial interface + GPIO_HPMA_RX, // Honeywell HPMA115S0 Serial interface +#endif +#ifdef USE_PMS5003 + GPIO_PMS5003_TX, // Plantower PMS5003 Serial interface + GPIO_PMS5003_RX, // Plantower PMS5003 Serial interface +#endif +#if defined(USE_TX20_WIND_SENSOR) || defined(USE_TX23_WIND_SENSOR) + GPIO_TX2X_TXD_BLACK, // TX20/TX23 Transmission Pin +#endif +#ifdef USE_MP3_PLAYER + GPIO_MP3_DFR562, // RB-DFR-562, DFPlayer Mini MP3 Player Serial interface +#endif +#ifdef USE_AZ7798 + GPIO_AZ_TXD, // AZ-Instrument 7798 CO2 datalogger Serial interface + GPIO_AZ_RXD, // AZ-Instrument 7798 CO2 datalogger Serial interface +#endif +#ifdef USE_PN532_HSU + GPIO_PN532_TXD, // PN532 HSU Tx + GPIO_PN532_RXD, // PN532 HSU Rx +#endif +#ifdef USE_TASMOTA_SLAVE + GPIO_TASMOTASLAVE_TXD, // Tasmota Slave TX + GPIO_TASMOTASLAVE_RXD, // Tasmota Slave RX + GPIO_TASMOTASLAVE_RST, // Tasmota Slave Reset + GPIO_TASMOTASLAVE_RST_INV, // Tasmota Slave Reset Inverted +#endif +#ifdef USE_RDM6300 + GPIO_RDM6300_RX, +#endif +#ifdef USE_IBEACON + GPIO_IBEACON_RX, + GPIO_IBEACON_TX, +#endif +#ifdef USE_GPS + GPIO_GPS_RX, // GPS serial interface + GPIO_GPS_TX, // GPS serial interface +#endif +#ifdef USE_HM10 + GPIO_HM10_RX, // GPS serial interface + GPIO_HM10_TX, // GPS serial interface +#endif + +#ifdef USE_MGC3130 + GPIO_MGC3130_XFER, + GPIO_MGC3130_RESET, +#endif +#ifdef USE_MAX31855 + GPIO_MAX31855CS, // MAX31855 Serial interface + GPIO_MAX31855CLK, // MAX31855 Serial interface + GPIO_MAX31855DO, // MAX31855 Serial interface +#endif +#ifdef ROTARY_V1 + GPIO_ROT1A, // Rotary switch1 A Pin + GPIO_ROT1B, // Rotary switch1 B Pin + GPIO_ROT2A, // Rotary switch2 A Pin + GPIO_ROT2B, // Rotary switch2 B Pin +#endif +#ifdef USE_HRE + GPIO_HRE_CLOCK, + GPIO_HRE_DATA, +#endif +#ifdef USE_A4988_STEPPER + GPIO_A4988_DIR, // A4988 direction pin + GPIO_A4988_STP, // A4988 step pin + // folowing are not mandatory + GPIO_A4988_ENA, // A4988 enabled pin + GPIO_A4988_MS1, // A4988 microstep pin1 + GPIO_A4988_MS2, // A4988 microstep pin2 + GPIO_A4988_MS3, // A4988 microstep pin3 +#endif +#ifdef USE_DEEPSLEEP + GPIO_DEEPSLEEP, +#endif +#ifdef USE_KEELOQ + GPIO_CC1101_GDO0, // CC1101 pin for RX + GPIO_CC1101_GDO2, // CC1101 pin for RX +#endif +#ifdef USE_HRXL + GPIO_HRXL_RX, +#endif +#ifdef USE_AS3935 + GPIO_AS3935, +#endif +}; + +/********************************************************************************************/ + +// User selectable ADC0 functionality +enum UserSelectableAdc0 { + ADC0_NONE, // Not used + ADC0_INPUT, // Analog input + ADC0_TEMP, // Thermistor + ADC0_LIGHT, // Light sensor + ADC0_BUTTON, // Button + ADC0_BUTTON_INV, + ADC0_RANGE, // Range + ADC0_CT_POWER, // Current +// ADC0_SWITCH, // Switch +// ADC0_SWITCH_INV, + ADC0_END }; + +// Programmer selectable ADC0 functionality +enum ProgramSelectableAdc0 { + ADC0_FIX_START = 14, + ADC0_USER, // User configurable needs to be 15 + ADC0_MAX }; + +// Text in webpage Module Parameters and commands ADC +const char kAdc0Names[] PROGMEM = + D_SENSOR_NONE "|" D_ANALOG_INPUT "|" + D_TEMPERATURE "|" D_LIGHT "|" + D_SENSOR_BUTTON "|" D_SENSOR_BUTTON "i|" + D_RANGE "|" + D_CT_POWER "|" +// D_SENSOR_SWITCH "|" D_SENSOR_SWITCH "i|" + ; + +/********************************************************************************************/ + +// esp32 has more pins +#define USER_MODULE 255 +#define MAX_GPIO_PIN 40 // Number of supported GPIO +#define MIN_FLASH_PINS 4 // Number of flash chip pins unusable for configuration (GPIO6, 7, 8 and 11) +#define MAX_USER_PINS 36 // MAX_GPIO_PIN - MIN_FLASH_PINS +#define ADC0_PIN 33 // Pin number of ADC0 +#define WEMOS_MODULE 0 // Wemos module + +// 0 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930313233343536373839 +const char PINS_WEMOS[] PROGMEM = "IOTXIORXIOIOflashcFLFLolIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOA6A7A0IoIoA3"; + +/********************************************************************************************/ + +typedef struct MYIO { + uint8_t io[MAX_GPIO_PIN]; +} myio; + +typedef struct MYCFGIO { + uint8_t io[MAX_GPIO_PIN - MIN_FLASH_PINS]; +} mycfgio; + +#define GPIO_FLAG_USED 0 // Currently two flags used + +#define GPIO_FLAG_SPARE04 16 +#define GPIO_FLAG_SPARE05 32 +#define GPIO_FLAG_SPARE06 64 +#define GPIO_FLAG_SPARE07 128 + +typedef union { + uint8_t data; + struct { + uint8_t adc0 : 4; // Allow ADC0 when define USE_ADC_VCC is disabled + uint8_t spare04 : 1; + uint8_t spare05 : 1; + uint8_t spare06 : 1; + uint8_t spare07 : 1; + }; +} gpio_flag; + +typedef struct MYTMPLT { + mycfgio gp; + gpio_flag flag; +} mytmplt; + /********************************************************************************************/ // Supported hardware modules + enum SupportedModules { WEMOS, ESP32_CAM_AITHINKER, MAXMODULE}; +#define USER_MODULE 255 + const char kModuleNames[] PROGMEM = "ESP32-DevKit|ESP32 Cam AiThinker"; @@ -102,6 +829,10 @@ const mytmplt kModules PROGMEM = 0 // Flag }; +#else // FINAL_ESP32 +#include "tasmota_template_ESP32_final.h" +#endif // FINAL_ESP32 + #endif // ESP32 #endif // _TASMOTA_TEMPLATE_ESP32_H_ diff --git a/tasmota/tasmota_template_ESP32_final.h b/tasmota/tasmota_template_ESP32_final.h new file mode 100644 index 000000000..e13dbec24 --- /dev/null +++ b/tasmota/tasmota_template_ESP32_final.h @@ -0,0 +1,742 @@ +/* + tasmota_template_ESP32_final.h - template settings for Tasmota + + Copyright (C) 2020 Theo Arends + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _TASMOTA_TEMPLATE_ESP32_FINAL_H_ +#define _TASMOTA_TEMPLATE_ESP32_FINAL_H_ + +#ifdef ESP32 + +// Hardware has no ESP32 +#undef USE_TUYA_DIMMER +#undef USE_PWM_DIMMER +#undef USE_EXS_DIMMER +#undef USE_ARMTRONIX_DIMMERS +#undef USE_SONOFF_RF +#undef USE_SONOFF_SC +#undef USE_SONOFF_IFAN +#undef USE_SONOFF_L1 +#undef USE_SONOFF_D1 +#undef USE_RF_FLASH + +// Not ported (yet) +#undef USE_DISCOVERY +#undef USE_ADC_VCC // Needs to be ported +#undef USE_DEEPSLEEP +#undef USE_MY92X1 +#undef USE_TUYA_MCU +#undef USE_PS_16_DZ + +enum UserSelectablePins { + GPIO_NONE, // Not used + GPIO_KEY1, // 4 x Button usually connected to GPIO0 + GPIO_KEY1_NP, + GPIO_KEY1_INV, + GPIO_KEY1_INV_NP, + GPIO_SWT1, // 8 x User connected external switches + GPIO_SWT1_NP, + GPIO_REL1, // 8 x Relays + GPIO_REL1_INV, + GPIO_LED1, // 4 x Leds + GPIO_LED1_INV, + GPIO_CNTR1, // 4 x Counter + GPIO_CNTR1_NP, + GPIO_PWM1, // 5 x PWM + GPIO_PWM1_INV, + GPIO_BUZZER, // Buzzer + GPIO_BUZZER_INV, // Inverted buzzer + GPIO_LEDLNK, // Link led + GPIO_LEDLNK_INV, // Inverted link led + GPIO_I2C_SCL, // I2C SCL + GPIO_I2C_SDA, // I2C SDA + GPIO_SPI_MISO, // SPI MISO + GPIO_SPI_MOSI, // SPI MOSI + GPIO_SPI_CLK, // SPI Clk + GPIO_SPI_CS, // SPI Chip Select + GPIO_SPI_DC, // SPI Data Direction + GPIO_SSPI_MISO, // Software SPI Master Input Slave Output + GPIO_SSPI_MOSI, // Software SPI Master Output Slave Input + GPIO_SSPI_SCLK, // Software SPI Serial Clock + GPIO_SSPI_CS, // Software SPI Chip Select + GPIO_SSPI_DC, // Software SPI Data or Command + GPIO_BACKLIGHT, // Display backlight control + GPIO_OLED_RESET, // OLED Display Reset + GPIO_IRSEND, // IR remote + GPIO_IRRECV, // IR receiver + GPIO_RFSEND, // RF transmitter + GPIO_RFRECV, // RF receiver + GPIO_DHT11, // DHT11 + GPIO_DHT22, // DHT21, DHT22, AM2301, AM2302, AM2321 + GPIO_SI7021, // iTead SI7021 + GPIO_DHT11_OUT, // Pseudo Single wire DHT11, DHT21, DHT22, AM2301, AM2302, AM2321 + GPIO_DSB, // Single wire DS18B20 or DS18S20 + GPIO_DSB_OUT, // Pseudo Single wire DS18B20 or DS18S20 + GPIO_WS2812, // WS2812 Led string + GPIO_MHZ_TXD, // MH-Z19 Serial interface + GPIO_MHZ_RXD, // MH-Z19 Serial interface + GPIO_PZEM0XX_TX, // PZEM0XX Serial interface + GPIO_PZEM004_RX, // PZEM004T Serial interface + GPIO_PZEM016_RX, // PZEM-014,016 Serial Modbus interface + GPIO_PZEM017_RX, // PZEM-003,017 Serial Modbus interface + GPIO_SAIR_TX, // SenseAir Serial interface + GPIO_SAIR_RX, // SenseAir Serial interface + GPIO_PMS5003_TX, // Plantower PMS5003 Serial interface + GPIO_PMS5003_RX, // Plantower PMS5003 Serial interface + GPIO_SDS0X1_TX, // Nova Fitness SDS011 Serial interface + GPIO_SDS0X1_RX, // Nova Fitness SDS011 Serial interface + GPIO_SBR_TX, // Serial Bridge Serial interface + GPIO_SBR_RX, // Serial Bridge Serial interface + GPIO_SR04_TRIG, // SR04 Trigger/TX pin + GPIO_SR04_ECHO, // SR04 Echo/RX pin + GPIO_SDM120_TX, // SDM120 Serial interface + GPIO_SDM120_RX, // SDM120 Serial interface + GPIO_SDM630_TX, // SDM630 Serial interface + GPIO_SDM630_RX, // SDM630 Serial interface + GPIO_TM16CLK, // TM1638 Clock + GPIO_TM16DIO, // TM1638 Data I/O + GPIO_TM16STB, // TM1638 Strobe + GPIO_MP3_DFR562, // RB-DFR-562, DFPlayer Mini MP3 Player + GPIO_HX711_SCK, // HX711 Load Cell clock + GPIO_HX711_DAT, // HX711 Load Cell data + GPIO_TX2X_TXD_BLACK, // TX20/TX23 Transmission Pin + GPIO_TUYA_TX, // Tuya Serial interface + GPIO_TUYA_RX, // Tuya Serial interface + GPIO_MGC3130_XFER, // MGC3130 Transfer + GPIO_MGC3130_RESET, // MGC3130 Reset + GPIO_RF_SENSOR, // Rf receiver with sensor decoding + GPIO_AZ_TXD, // AZ-Instrument 7798 Serial interface + GPIO_AZ_RXD, // AZ-Instrument 7798 Serial interface + GPIO_MAX31855CS, // MAX31855 Serial interface + GPIO_MAX31855CLK, // MAX31855 Serial interface + GPIO_MAX31855DO, // MAX31855 Serial interface + GPIO_NRG_SEL, // HLW8012/HLJ-01 Sel output (1 = Voltage) + GPIO_NRG_SEL_INV, // HLW8012/HLJ-01 Sel output (0 = Voltage) + GPIO_NRG_CF1, // HLW8012/HLJ-01 CF1 voltage / current + GPIO_HLW_CF, // HLW8012 CF power + GPIO_HJL_CF, // HJL-01/BL0937 CF power + GPIO_MCP39F5_TX, // MCP39F501 Serial interface (Shelly2) + GPIO_MCP39F5_RX, // MCP39F501 Serial interface (Shelly2) + GPIO_MCP39F5_RST, // MCP39F501 Reset (Shelly2) + GPIO_PN532_TXD, // PN532 NFC Serial Tx + GPIO_PN532_RXD, // PN532 NFC Serial Rx + GPIO_SM16716_CLK, // SM16716 CLOCK + GPIO_SM16716_DAT, // SM16716 DATA + GPIO_SM16716_SEL, // SM16716 SELECT + GPIO_DI, // my92x1 PWM input + GPIO_DCKI, // my92x1 CLK input + GPIO_CSE7766_TX, // CSE7766 Serial interface (S31 and Pow R2) - Not used anymore 20200121 + GPIO_CSE7766_RX, // CSE7766 Serial interface (S31 and Pow R2) + GPIO_ARIRFRCV, // AriLux RF Receive input + GPIO_TXD, // Serial interface + GPIO_RXD, // Serial interface + GPIO_ROT1A, // Rotary switch1 A Pin + GPIO_ROT1B, // Rotary switch1 B Pin + GPIO_ROT2A, // Rotary switch2 A Pin + GPIO_ROT2B, // Rotary switch2 B Pin + GPIO_HRE_CLOCK, // Clock/Power line for HR-E Water Meter + GPIO_HRE_DATA, // Data line for HR-E Water Meter + GPIO_ADE7953_IRQ, // ADE7953 IRQ + GPIO_ARIRFSEL, // Arilux RF Receive input selected + GPIO_SOLAXX1_TX, // Solax Inverter tx pin + GPIO_SOLAXX1_RX, // Solax Inverter rx pin + GPIO_ZIGBEE_TX, // Zigbee Serial interface + GPIO_ZIGBEE_RX, // Zigbee Serial interface + GPIO_RDM6300_RX, // RDM6300 RX + GPIO_IBEACON_TX, // HM17 IBEACON TX + GPIO_IBEACON_RX, // HM17 IBEACON RX + GPIO_A4988_DIR, // A4988 direction pin + GPIO_A4988_STP, // A4988 step pin + GPIO_A4988_ENA, // A4988 enabled pin + GPIO_A4988_MS1, // A4988 microstep pin1 + GPIO_A4988_MS2, // A4988 microstep pin2 + GPIO_A4988_MS3, // A4988 microstep pin3 + GPIO_DDS2382_TX, // DDS2382 Serial interface + GPIO_DDS2382_RX, // DDS2382 Serial interface + GPIO_DDSU666_TX, // DDSU666 Serial interface + GPIO_DDSU666_RX, // DDSU666 Serial interface + GPIO_SM2135_CLK, // SM2135 Clk + GPIO_SM2135_DAT, // SM2135 Dat + GPIO_DEEPSLEEP, // Kill switch for deepsleep + GPIO_EXS_ENABLE, // EXS MCU Enable + GPIO_TASMOTASLAVE_TXD, // Slave TX + GPIO_TASMOTASLAVE_RXD, // Slave RX + GPIO_TASMOTASLAVE_RST, // Slave Reset Pin + GPIO_TASMOTASLAVE_RST_INV, // Slave Reset Inverted + GPIO_HPMA_RX, // Honeywell HPMA115S0 Serial interface + GPIO_HPMA_TX, // Honeywell HPMA115S0 Serial interface + GPIO_GPS_RX, // GPS serial interface + GPIO_GPS_TX, // GPS serial interface + GPIO_HM10_RX, // HM10-BLE-Mijia-bridge serial interface + GPIO_HM10_TX, // HM10-BLE-Mijia-bridge serial interface + GPIO_LE01MR_RX, // F&F LE-01MR energy meter + GPIO_LE01MR_TX, // F&F LE-01MR energy meter + GPIO_CC1101_GDO0, // CC1101 pin for RX + GPIO_CC1101_GDO2, // CC1101 pin for RX + GPIO_HRXL_RX, // Data from MaxBotix HRXL sonar range sensor + GPIO_ELECTRIQ_MOODL_TX, // ElectriQ iQ-wifiMOODL Serial TX + GPIO_AS3935, +/* + ADC0_INPUT, // Analog input + ADC0_TEMP, // Thermistor + ADC0_LIGHT, // Light sensor + ADC0_BUTTON, // Button + ADC0_BUTTON_INV, + ADC0_RANGE, // Range + ADC0_CT_POWER, // Current +*/ + GPIO_SENSOR_END }; + +enum ProgramSelectablePins { +// GPIO_FIX_START = 254, + GPIO_FIX_START = 2046, + GPIO_USER, // User configurable needs to be 2047 + GPIO_MAX }; + +// Text in webpage Module Parameters and commands GPIOS and GPIO +const char kSensorNames[] PROGMEM = + D_SENSOR_NONE "|" + D_SENSOR_BUTTON "|" + D_SENSOR_BUTTON "n|" + D_SENSOR_BUTTON "i|" + D_SENSOR_BUTTON "in|" + D_SENSOR_SWITCH "|" + D_SENSOR_SWITCH "n|" + D_SENSOR_RELAY "|" + D_SENSOR_RELAY "i|" + D_SENSOR_LED "|" + D_SENSOR_LED "i|" + D_SENSOR_COUNTER "|" + D_SENSOR_COUNTER "n|" + D_SENSOR_PWM "|" + D_SENSOR_PWM "i|" + D_SENSOR_BUZZER "|" + D_SENSOR_BUZZER "i|" + D_SENSOR_LED_LINK "|" D_SENSOR_LED_LINK "i|" + D_SENSOR_I2C_SCL "|" D_SENSOR_I2C_SDA "|" + D_SENSOR_SPI_MISO "|" D_SENSOR_SPI_MOSI "|" D_SENSOR_SPI_CLK "|" D_SENSOR_SPI_CS "|" D_SENSOR_SPI_DC "|" + D_SENSOR_SSPI_MISO "|" D_SENSOR_SSPI_MOSI "|" D_SENSOR_SSPI_SCLK "|" D_SENSOR_SSPI_CS "|" D_SENSOR_SSPI_DC "|" + D_SENSOR_BACKLIGHT "|" D_SENSOR_OLED_RESET "|" + D_SENSOR_IRSEND "|" D_SENSOR_IRRECV "|" + D_SENSOR_RFSEND "|" D_SENSOR_RFRECV "|" + D_SENSOR_DHT11 "|" D_SENSOR_AM2301 "|" D_SENSOR_SI7021 "|" D_SENSOR_DHT11 "o|" + D_SENSOR_DS18X20 "|" D_SENSOR_DS18X20 "o|" + D_SENSOR_WS2812 "|" + D_SENSOR_MHZ_TX "|" D_SENSOR_MHZ_RX "|" + D_SENSOR_PZEM0XX_TX "|" D_SENSOR_PZEM004_RX "|" D_SENSOR_PZEM016_RX "|" D_SENSOR_PZEM017_RX "|" + D_SENSOR_SAIR_TX "|" D_SENSOR_SAIR_RX "|" + D_SENSOR_PMS5003_TX "|" D_SENSOR_PMS5003_RX "|" + D_SENSOR_SDS0X1_TX "|" D_SENSOR_SDS0X1_RX "|" + D_SENSOR_SBR_TX "|" D_SENSOR_SBR_RX "|" + D_SENSOR_SR04_TRIG "|" D_SENSOR_SR04_ECHO "|" + D_SENSOR_SDM120_TX "|" D_SENSOR_SDM120_RX "|" + D_SENSOR_SDM630_TX "|" D_SENSOR_SDM630_RX "|" + D_SENSOR_TM1638_CLK "|" D_SENSOR_TM1638_DIO "|" D_SENSOR_TM1638_STB "|" + D_SENSOR_DFR562 "|" + D_SENSOR_HX711_SCK "|" D_SENSOR_HX711_DAT "|" + D_SENSOR_TX2X_TX "|" + D_SENSOR_TUYA_TX "|" D_SENSOR_TUYA_RX "|" + D_SENSOR_MGC3130_XFER "|" D_SENSOR_MGC3130_RESET "|" + D_SENSOR_RF_SENSOR "|" + D_SENSOR_AZ_TX "|" D_SENSOR_AZ_RX "|" + D_SENSOR_MAX31855_CS "|" D_SENSOR_MAX31855_CLK "|" D_SENSOR_MAX31855_DO "|" + D_SENSOR_NRG_SEL "|" D_SENSOR_NRG_SEL "i|" D_SENSOR_NRG_CF1 "|" D_SENSOR_HLW_CF "|" D_SENSOR_HJL_CF "|" + D_SENSOR_MCP39F5_TX "|" D_SENSOR_MCP39F5_RX "|" D_SENSOR_MCP39F5_RST "|" + D_SENSOR_PN532_TX "|" D_SENSOR_PN532_RX "|" + D_SENSOR_SM16716_CLK "|" D_SENSOR_SM16716_DAT "|" D_SENSOR_SM16716_POWER "|" + D_SENSOR_MY92X1_DI "|" D_SENSOR_MY92X1_DCKI "|" + D_SENSOR_CSE7766_TX "|" D_SENSOR_CSE7766_RX "|" + D_SENSOR_ARIRFRCV "|" + D_SENSOR_TXD "|" D_SENSOR_RXD "|" + D_SENSOR_ROTARY "1a|" D_SENSOR_ROTARY "1b|" D_SENSOR_ROTARY "2a|" D_SENSOR_ROTARY "2b|" + D_SENSOR_HRE_CLOCK "|" D_SENSOR_HRE_DATA "|" + D_SENSOR_ADE7953_IRQ "|" + D_SENSOR_ARIRFSEL "|" + D_SENSOR_SOLAXX1_TX "|" D_SENSOR_SOLAXX1_RX "|" + D_SENSOR_ZIGBEE_TXD "|" D_SENSOR_ZIGBEE_RXD "|" + D_SENSOR_RDM6300_RX "|" + D_SENSOR_IBEACON_TX "|" D_SENSOR_IBEACON_RX "|" + D_SENSOR_A4988_DIR "|" D_SENSOR_A4988_STP "|" D_SENSOR_A4988_ENA "|" D_SENSOR_A4988_MS1 "|" D_SENSOR_A4988_MS2 "|" D_SENSOR_A4988_MS3 "|" + D_SENSOR_DDS2382_TX "|" D_SENSOR_DDS2382_RX "|" + D_SENSOR_DDSU666_TX "|" D_SENSOR_DDSU666_RX "|" + D_SENSOR_SM2135_CLK "|" D_SENSOR_SM2135_DAT "|" + D_SENSOR_DEEPSLEEP "|" D_SENSOR_EXS_ENABLE "|" + D_SENSOR_SLAVE_TX "|" D_SENSOR_SLAVE_RX "|" D_SENSOR_SLAVE_RESET "|" D_SENSOR_SLAVE_RESET "i|" + D_SENSOR_HPMA_RX "|" D_SENSOR_HPMA_TX "|" + D_SENSOR_GPS_RX "|" D_SENSOR_GPS_TX "|" + D_SENSOR_HM10_RX "|" D_SENSOR_HM10_TX "|" + D_SENSOR_LE01MR_RX "|" D_SENSOR_LE01MR_TX "|" + D_SENSOR_CC1101_GDO0 "|" D_SENSOR_CC1101_GDO2 "|" + D_SENSOR_HRXL_RX "|" + D_SENSOR_ELECTRIQ_MOODL "|" + D_SENSOR_AS3935 "|" +/* + D_ANALOG_INPUT "|" + D_TEMPERATURE "|" D_LIGHT "|" + D_SENSOR_BUTTON "|" D_SENSOR_BUTTON "i|" + D_RANGE "|" + D_CT_POWER "|" +*/ + ; + +const char kSensorNamesFixed[] PROGMEM = + D_SENSOR_USER; + +const uint16_t kGpioNiceList[] PROGMEM = { + GPIO_NONE, // Not used + GPIO_KEY1, // Buttons + GPIO_KEY1_NP, + GPIO_KEY1_INV, + GPIO_KEY1_INV_NP, + GPIO_SWT1, // User connected external switches + GPIO_SWT1_NP, + GPIO_REL1, // Relays + GPIO_REL1_INV, + GPIO_LED1, // Leds + GPIO_LED1_INV, +#ifdef USE_COUNTER + GPIO_CNTR1, // Counters + GPIO_CNTR1_NP, +#endif + GPIO_PWM1, // RGB Red or C Cold White + GPIO_PWM1_INV, +#ifdef USE_BUZZER + GPIO_BUZZER, // Buzzer + GPIO_BUZZER_INV, // Inverted buzzer +#endif + GPIO_LEDLNK, // Link led + GPIO_LEDLNK_INV, // Inverted link led +#ifdef USE_I2C + GPIO_I2C_SCL, // I2C SCL + GPIO_I2C_SDA, // I2C SDA +#endif +#ifdef USE_SPI + GPIO_SPI_MISO, // SPI MISO + GPIO_SPI_MOSI, // SPI MOSI + GPIO_SPI_CLK, // SPI Clk + GPIO_SPI_CS, // SPI Chip Select + GPIO_SPI_DC, // SPI Data Direction + GPIO_SSPI_MISO, // Software SPI Master Input Slave Output + GPIO_SSPI_MOSI, // Software SPI Master Output Slave Input + GPIO_SSPI_SCLK, // Software SPI Serial Clock + GPIO_SSPI_CS, // Software SPI Chip Select + GPIO_SSPI_DC, // Software SPI Data or Command +#endif +#ifdef USE_DISPLAY + GPIO_BACKLIGHT, // Display backlight control + GPIO_OLED_RESET, // OLED Display Reset +#endif + + GPIO_TXD, // Serial interface + GPIO_RXD, // Serial interface + +#ifdef USE_DHT + GPIO_DHT11, // DHT11 + GPIO_DHT22, // DHT21, DHT22, AM2301, AM2302, AM2321 + GPIO_SI7021, // iTead SI7021 + GPIO_DHT11_OUT, // Pseudo Single wire DHT11, DHT21, DHT22, AM2301, AM2302, AM2321 +#endif +#ifdef USE_DS18x20 + GPIO_DSB, // Single wire DS18B20 or DS18S20 + GPIO_DSB_OUT, // Pseudo Single wire DS18B20 or DS18S20 +#endif + +// Light +#ifdef USE_LIGHT +#ifdef USE_WS2812 + GPIO_WS2812, // WS2812 Led string +#endif +#ifdef USE_ARILUX_RF + GPIO_ARIRFRCV, // AriLux RF Receive input + GPIO_ARIRFSEL, // Arilux RF Receive input selected +#endif +#ifdef USE_MY92X1 + GPIO_DI, // my92x1 PWM input + GPIO_DCKI, // my92x1 CLK input +#endif // USE_MY92X1 +#ifdef USE_SM16716 + GPIO_SM16716_CLK, // SM16716 CLOCK + GPIO_SM16716_DAT, // SM16716 DATA + GPIO_SM16716_SEL, // SM16716 SELECT +#endif // USE_SM16716 +#ifdef USE_SM2135 + GPIO_SM2135_CLK, // SM2135 CLOCK + GPIO_SM2135_DAT, // SM2135 DATA +#endif // USE_SM2135 +#ifdef USE_TUYA_MCU + GPIO_TUYA_TX, // Tuya Serial interface + GPIO_TUYA_RX, // Tuya Serial interface +#endif +#ifdef USE_EXS_DIMMER + GPIO_EXS_ENABLE, // EXS MCU Enable +#endif +#ifdef USE_ELECTRIQ_MOODL + GPIO_ELECTRIQ_MOODL_TX, +#endif +#endif // USE_LIGHT + +#if defined(USE_IR_REMOTE) || defined(USE_IR_REMOTE_FULL) + GPIO_IRSEND, // IR remote +#if defined(USE_IR_RECEIVE) || defined(USE_IR_REMOTE_FULL) + GPIO_IRRECV, // IR receiver +#endif +#endif + +#ifdef USE_RC_SWITCH + GPIO_RFSEND, // RF transmitter + GPIO_RFRECV, // RF receiver +#endif +#ifdef USE_RF_SENSOR + GPIO_RF_SENSOR, // Rf receiver with sensor decoding +#endif +#ifdef USE_SR04 + GPIO_SR04_TRIG, // SR04 Tri/TXgger pin + GPIO_SR04_ECHO, // SR04 Ech/RXo pin +#endif +#ifdef USE_TM1638 + GPIO_TM16CLK, // TM1638 Clock + GPIO_TM16DIO, // TM1638 Data I/O + GPIO_TM16STB, // TM1638 Strobe +#endif +#ifdef USE_HX711 + GPIO_HX711_SCK, // HX711 Load Cell clock + GPIO_HX711_DAT, // HX711 Load Cell data +#endif + +// Energy sensors +#ifdef USE_ENERGY_SENSOR +#ifdef USE_HLW8012 + GPIO_NRG_SEL, // HLW8012/HLJ-01 Sel output (1 = Voltage) + GPIO_NRG_SEL_INV, // HLW8012/HLJ-01 Sel output (0 = Voltage) + GPIO_NRG_CF1, // HLW8012/HLJ-01 CF1 voltage / current + GPIO_HLW_CF, // HLW8012 CF power + GPIO_HJL_CF, // HJL-01/BL0937 CF power +#endif +#if defined(USE_I2C) && defined(USE_ADE7953) + GPIO_ADE7953_IRQ, // ADE7953 IRQ +#endif +#ifdef USE_CSE7766 + GPIO_CSE7766_TX, // CSE7766 Serial interface (S31 and Pow R2) + GPIO_CSE7766_RX, // CSE7766 Serial interface (S31 and Pow R2) +#endif +#ifdef USE_MCP39F501 + GPIO_MCP39F5_TX, // MCP39F501 Serial interface (Shelly2) + GPIO_MCP39F5_RX, // MCP39F501 Serial interface (Shelly2) + GPIO_MCP39F5_RST, // MCP39F501 Reset (Shelly2) +#endif +#if defined(USE_PZEM004T) || defined(USE_PZEM_AC) || defined(USE_PZEM_DC) + GPIO_PZEM0XX_TX, // PZEM0XX Serial interface +#endif +#ifdef USE_PZEM004T + GPIO_PZEM004_RX, // PZEM004T Serial interface +#endif +#ifdef USE_PZEM_AC + GPIO_PZEM016_RX, // PZEM-014,016 Serial Modbus interface +#endif +#ifdef USE_PZEM_DC + GPIO_PZEM017_RX, // PZEM-003,017 Serial Modbus interface +#endif +#ifdef USE_SDM120 + GPIO_SDM120_TX, // SDM120 Serial interface + GPIO_SDM120_RX, // SDM120 Serial interface +#endif +#ifdef USE_SDM630 + GPIO_SDM630_TX, // SDM630 Serial interface + GPIO_SDM630_RX, // SDM630 Serial interface +#endif +#ifdef USE_DDS2382 + GPIO_DDS2382_TX, // DDS2382 Serial interface + GPIO_DDS2382_RX, // DDS2382 Serial interface +#endif +#ifdef USE_DDSU666 + GPIO_DDSU666_TX, // DDSU666 Serial interface + GPIO_DDSU666_RX, // DDSU666 Serial interface +#endif // USE_DDSU666 +#ifdef USE_SOLAX_X1 + GPIO_SOLAXX1_TX, // Solax Inverter tx pin + GPIO_SOLAXX1_RX, // Solax Inverter rx pin +#endif // USE_SOLAX_X1 +#ifdef USE_LE01MR + GPIO_LE01MR_RX, // F7F LE-01MR energy meter rx pin + GPIO_LE01MR_TX, // F7F LE-01MR energy meter tx pin +#endif // IFDEF:USE_LE01MR +#endif // USE_ENERGY_SENSOR + +// Serial +#ifdef USE_SERIAL_BRIDGE + GPIO_SBR_TX, // Serial Bridge Serial interface + GPIO_SBR_RX, // Serial Bridge Serial interface +#endif +#ifdef USE_ZIGBEE + GPIO_ZIGBEE_TX, // Zigbee Serial interface + GPIO_ZIGBEE_RX, // Zigbee Serial interface +#endif +#ifdef USE_MHZ19 + GPIO_MHZ_TXD, // MH-Z19 Serial interface + GPIO_MHZ_RXD, // MH-Z19 Serial interface +#endif +#ifdef USE_SENSEAIR + GPIO_SAIR_TX, // SenseAir Serial interface + GPIO_SAIR_RX, // SenseAir Serial interface +#endif +#ifdef USE_NOVA_SDS + GPIO_SDS0X1_TX, // Nova Fitness SDS011 Serial interface + GPIO_SDS0X1_RX, // Nova Fitness SDS011 Serial interface +#endif +#ifdef USE_HPMA + GPIO_HPMA_TX, // Honeywell HPMA115S0 Serial interface + GPIO_HPMA_RX, // Honeywell HPMA115S0 Serial interface +#endif +#ifdef USE_PMS5003 + GPIO_PMS5003_TX, // Plantower PMS5003 Serial interface + GPIO_PMS5003_RX, // Plantower PMS5003 Serial interface +#endif +#if defined(USE_TX20_WIND_SENSOR) || defined(USE_TX23_WIND_SENSOR) + GPIO_TX2X_TXD_BLACK, // TX20/TX23 Transmission Pin +#endif +#ifdef USE_MP3_PLAYER + GPIO_MP3_DFR562, // RB-DFR-562, DFPlayer Mini MP3 Player Serial interface +#endif +#ifdef USE_AZ7798 + GPIO_AZ_TXD, // AZ-Instrument 7798 CO2 datalogger Serial interface + GPIO_AZ_RXD, // AZ-Instrument 7798 CO2 datalogger Serial interface +#endif +#ifdef USE_PN532_HSU + GPIO_PN532_TXD, // PN532 HSU Tx + GPIO_PN532_RXD, // PN532 HSU Rx +#endif +#ifdef USE_TASMOTA_SLAVE + GPIO_TASMOTASLAVE_TXD, // Tasmota Slave TX + GPIO_TASMOTASLAVE_RXD, // Tasmota Slave RX + GPIO_TASMOTASLAVE_RST, // Tasmota Slave Reset + GPIO_TASMOTASLAVE_RST_INV, // Tasmota Slave Reset Inverted +#endif +#ifdef USE_RDM6300 + GPIO_RDM6300_RX, +#endif +#ifdef USE_IBEACON + GPIO_IBEACON_RX, + GPIO_IBEACON_TX, +#endif +#ifdef USE_GPS + GPIO_GPS_RX, // GPS serial interface + GPIO_GPS_TX, // GPS serial interface +#endif +#ifdef USE_HM10 + GPIO_HM10_RX, // GPS serial interface + GPIO_HM10_TX, // GPS serial interface +#endif + +#ifdef USE_MGC3130 + GPIO_MGC3130_XFER, + GPIO_MGC3130_RESET, +#endif +#ifdef USE_MAX31855 + GPIO_MAX31855CS, // MAX31855 Serial interface + GPIO_MAX31855CLK, // MAX31855 Serial interface + GPIO_MAX31855DO, // MAX31855 Serial interface +#endif +#ifdef ROTARY_V1 + GPIO_ROT1A, // Rotary switch1 A Pin + GPIO_ROT1B, // Rotary switch1 B Pin + GPIO_ROT2A, // Rotary switch2 A Pin + GPIO_ROT2B, // Rotary switch2 B Pin +#endif +#ifdef USE_HRE + GPIO_HRE_CLOCK, + GPIO_HRE_DATA, +#endif +#ifdef USE_A4988_STEPPER + GPIO_A4988_DIR, // A4988 direction pin + GPIO_A4988_STP, // A4988 step pin + // folowing are not mandatory + GPIO_A4988_ENA, // A4988 enabled pin + GPIO_A4988_MS1, // A4988 microstep pin1 + GPIO_A4988_MS2, // A4988 microstep pin2 + GPIO_A4988_MS3, // A4988 microstep pin3 +#endif +#ifdef USE_DEEPSLEEP + GPIO_DEEPSLEEP, +#endif +#ifdef USE_KEELOQ + GPIO_CC1101_GDO0, // CC1101 pin for RX + GPIO_CC1101_GDO2, // CC1101 pin for RX +#endif +#ifdef USE_HRXL + GPIO_HRXL_RX, +#endif +#ifdef USE_AS3935 + GPIO_AS3935, +#endif +/* + ADC0_INPUT, // Analog input + ADC0_TEMP, // Thermistor + ADC0_LIGHT, // Light sensor + ADC0_BUTTON, // Button + ADC0_BUTTON_INV, + ADC0_RANGE, // Range + ADC0_CT_POWER, // Current +*/ +}; + +//******************************************************************************************** + +// User selectable ADC0 functionality +enum UserSelectableAdc0 { + ADC0_NONE, // Not used + ADC0_INPUT, // Analog input + ADC0_TEMP, // Thermistor + ADC0_LIGHT, // Light sensor + ADC0_BUTTON, // Button + ADC0_BUTTON_INV, + ADC0_RANGE, // Range + ADC0_CT_POWER, // Current +// ADC0_SWITCH, // Switch +// ADC0_SWITCH_INV, + ADC0_END }; + +// Programmer selectable ADC0 functionality +enum ProgramSelectableAdc0 { + ADC0_FIX_START = 14, + ADC0_USER, // User configurable needs to be 15 + ADC0_MAX }; + +// Text in webpage Module Parameters and commands ADC +const char kAdc0Names[] PROGMEM = + D_SENSOR_NONE "|" D_ANALOG_INPUT "|" + D_TEMPERATURE "|" D_LIGHT "|" + D_SENSOR_BUTTON "|" D_SENSOR_BUTTON "i|" + D_RANGE "|" + D_CT_POWER "|" +// D_SENSOR_SWITCH "|" D_SENSOR_SWITCH "i|" + ; + +//******************************************************************************************** + +#define MAX_GPIO_PIN 40 // Number of supported GPIO +#define MIN_FLASH_PINS 4 // Number of flash chip pins unusable for configuration (GPIO6, 7, 8 and 11) +#define MAX_USER_PINS 36 // MAX_GPIO_PIN - MIN_FLASH_PINS +#define ADC0_PIN 33 // Pin number of ADC0 +#define WEMOS_MODULE 0 // Wemos module + +// 0 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930313233343536373839 +const char PINS_WEMOS[] PROGMEM = "IOTXIORXIOIOflashcFLFLolIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOA6A7A0IoIoA3"; + +//******************************************************************************************** + +typedef struct MYIO { + uint16_t io[MAX_GPIO_PIN]; +} myio; // 40 * 2 = 80 bytes + +typedef struct MYCFGIO { + uint16_t io[MAX_USER_PINS]; +} mycfgio; // 36 * 2 = 72 bytes + +#define GPIO_FLAG_USED 0 // Currently no flags used + +typedef union { + uint16_t data; + struct { + uint16_t spare00 : 1; + uint16_t spare01 : 1; + uint16_t spare02 : 1; + uint16_t spare03 : 1; + uint16_t spare04 : 1; + uint16_t spare05 : 1; + uint16_t spare06 : 1; + uint16_t spare07 : 1; + uint16_t spare08 : 1; + uint16_t spare09 : 1; + uint16_t spare10 : 1; + uint16_t spare11 : 1; + uint16_t spare12 : 1; + uint16_t spare13 : 1; + uint16_t spare14 : 1; + uint16_t spare15 : 1; + }; +} gpio_flag; // 2 bytes + +typedef struct MYTMPLT { + mycfgio gp; // 72 bytes + gpio_flag flag; // 2 bytes +} mytmplt; // 74 bytes + +/********************************************************************************************/ +// Supported hardware modules +enum SupportedModules { + WEMOS, ESP32_CAM_AITHINKER, + MAXMODULE}; + +#define USER_MODULE 255 + +const char kModuleNames[] PROGMEM = + "ESP32-DevKit|ESP32 Cam AiThinker"; + +// Default module settings +const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = { + WEMOS, + ESP32_CAM_AITHINKER +}; + +const mytmplt kModules PROGMEM = +{ // WEMOS - Espressif ESP32-DevKitC - Any ESP32 device like WeMos and NodeMCU hardware (ESP32) + GPIO_USER << 5, // 0 (I)O GPIO0, ADC2_CH1, TOUCH1, RTC_GPIO11, CLK_OUT1, EMAC_TX_CLK + GPIO_USER << 5, // 1 IO TXD0 GPIO1, U0TXD, CLK_OUT3, EMAC_RXD2 + GPIO_USER << 5, // 2 IO GPIO2, ADC2_CH2, TOUCH2, RTC_GPIO12, HSPIWP, HS2_DATA0, SD_DATA0 + GPIO_USER << 5, // 3 IO RXD0 GPIO3, U0RXD, CLK_OUT2 + GPIO_USER << 5, // 4 IO GPIO4, ADC2_CH0, TOUCH0, RTC_GPIO10, HSPIHD, HS2_DATA1, SD_DATA1, EMAC_TX_ER + GPIO_USER << 5, // 5 IO GPIO5, VSPICS0, HS1_DATA6, EMAC_RX_CLK + // 6 IO GPIO6, Flash CLK + // 7 IO GPIO7, Flash D0 + // 8 IO GPIO8, Flash D1 + GPIO_USER << 5, // 9 IO GPIO9, Flash D2, U1RXD + GPIO_USER << 5, // 10 IO GPIO10, Flash D3, U1TXD + // 11 IO GPIO11, Flash CMD + GPIO_USER << 5, // 12 (I)O GPIO12, ADC2_CH5, TOUCH5, RTC_GPIO15, MTDI, HSPIQ, HS2_DATA2, SD_DATA2, EMAC_TXD3 (If driven High, flash voltage (VDD_SDIO) is 1.8V not default 3.3V. Has internal pull-down, so unconnected = Low = 3.3V. May prevent flashing and/or booting if 3.3V flash is connected and pulled high. See ESP32 datasheet for more details.) + GPIO_USER << 5, // 13 IO GPIO13, ADC2_CH4, TOUCH4, RTC_GPIO14, MTCK, HSPID, HS2_DATA3, SD_DATA3, EMAC_RX_ER + GPIO_USER << 5, // 14 IO GPIO14, ADC2_CH6, TOUCH6, RTC_GPIO16, MTMS, HSPICLK, HS2_CLK, SD_CLK, EMAC_TXD2 + GPIO_USER << 5, // 15 (I)O GPIO15, ADC2_CH3, TOUCH3, MTDO, HSPICS0, RTC_GPIO13, HS2_CMD, SD_CMD, EMAC_RXD3 (If driven Low, silences boot messages from normal boot. Has internal pull-up, so unconnected = High = normal output.) + GPIO_USER << 5, // 16 IO GPIO16, HS1_DATA4, U2RXD, EMAC_CLK_OUT + GPIO_USER << 5, // 17 IO GPIO17, HS1_DATA5, U2TXD, EMAC_CLK_OUT_180 + GPIO_USER << 5, // 18 IO GPIO18, VSPICLK, HS1_DATA7 + GPIO_USER << 5, // 19 IO GPIO19, VSPIQ, U0CTS, EMAC_TXD0 + 0, // 20 + GPIO_USER << 5, // 21 IO GPIO21, VSPIHD, EMAC_TX_EN + GPIO_USER << 5, // 22 IO LED GPIO22, VSPIWP, U0RTS, EMAC_TXD1 + GPIO_USER << 5, // 23 IO GPIO23, VSPID, HS1_STROBE + 0, // 24 + GPIO_USER << 5, // 25 IO GPIO25, DAC_1, ADC2_CH8, RTC_GPIO6, EMAC_RXD0 + GPIO_USER << 5, // 26 IO GPIO26, DAC_2, ADC2_CH9, RTC_GPIO7, EMAC_RXD1 + GPIO_USER << 5, // 27 IO GPIO27, ADC2_CH7, TOUCH7, RTC_GPIO17, EMAC_RX_DV + 0, // 28 + 0, // 29 + 0, // 30 + 0, // 31 + GPIO_USER << 5, // 32 IO GPIO32, XTAL_32K_P (32.768 kHz crystal oscillator input), ADC1_CH4, TOUCH9, RTC_GPIO9 + GPIO_USER << 5, // 33 IO GPIO33, XTAL_32K_N (32.768 kHz crystal oscillator output), ADC1_CH5, TOUCH8, RTC_GPIO8 + GPIO_USER << 5, // 34 I NO PULLUP GPIO34, ADC1_CH6, RTC_GPIO4 + GPIO_USER << 5, // 35 I NO PULLUP GPIO35, ADC1_CH7, RTC_GPIO5 + GPIO_USER << 5, // 36 I NO PULLUP GPIO36, SENSOR_VP, ADC_H, ADC1_CH0, RTC_GPIO0 + 0, // 37 NO PULLUP + 0, // 38 NO PULLUP + GPIO_USER << 5, // 39 I NO PULLUP GPIO39, SENSOR_VN, ADC1_CH3, ADC_H, RTC_GPIO3 + 0 // Flag +}; + +#endif // ESP32 + +#endif // _TASMOTA_TEMPLATE_ESP32_FINAL_H_ From d805803daa91be6eba1e8f13e1359735961e0f42 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 29 Apr 2020 14:01:02 +0200 Subject: [PATCH 19/40] Change pin array names Change pin array names to block unwanted use of direct access --- tasmota/support.ino | 12 ++++++------ tasmota/support_tasmota.ino | 2 +- tasmota/tasmota.ino | 10 +++++----- tasmota/xdrv_10_scripter.ino | 10 +++++----- tasmota/xsns_53_sml.ino | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 02d17af98..e90d01c85 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1080,7 +1080,7 @@ uint32_t Pin(uint32_t gpio, uint32_t index) ICACHE_RAM_ATTR; uint32_t Pin(uint32_t gpio, uint32_t index = 0); uint32_t Pin(uint32_t gpio, uint32_t index) { #ifdef LEGACY_GPIO_ARRAY - return pin[gpio + index]; // Pin number configured for gpio or 99 if not used + return pin_gpio[gpio + index]; // Pin number configured for gpio or 99 if not used #else // No LEGACY_GPIO_ARRAY #ifdef ESP8266 uint16_t real_gpio = gpio + index; @@ -1091,8 +1091,8 @@ uint32_t Pin(uint32_t gpio, uint32_t index) { uint16_t real_gpio = (gpio << 5) + index; #endif // FINAL_ESP32 #endif // ESP8266 - ESP32 - for (uint32_t i = 0; i < ARRAY_SIZE(pin); i++) { - if (pin[i] == real_gpio) { + for (uint32_t i = 0; i < ARRAY_SIZE(gpio_pin); i++) { + if (gpio_pin[i] == real_gpio) { return i; // Pin number configured for gpio } } @@ -1107,15 +1107,15 @@ boolean PinUsed(uint32_t gpio, uint32_t index) { void SetPin(uint32_t lpin, uint32_t gpio) { #ifdef LEGACY_GPIO_ARRAY - pin[gpio] = lpin; + pin_gpio[gpio] = lpin; #else - pin[lpin] = gpio; + gpio_pin[lpin] = gpio; #endif } #ifdef LEGACY_GPIO_ARRAY void InitAllPins(void) { - for (uint32_t i = 0; i < ARRAY_SIZE(pin); i++) { + for (uint32_t i = 0; i < ARRAY_SIZE(pin_gpio); i++) { SetPin(99, i); } } diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 72137edab..91fda344d 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1439,7 +1439,7 @@ void GpioInit(void) } #ifndef LEGACY_GPIO_ARRAY - AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t*)pin, ARRAY_SIZE(pin)); + AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t*)gpio_pin, ARRAY_SIZE(gpio_pin)); #endif #ifdef ESP8266 diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 8af7285ad..b552c55c6 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -121,7 +121,7 @@ uint16_t syslog_timer = 0; // Timer to re-enable syslog_level #ifdef ESP32 #ifdef FINAL_ESP32 -uint16_t pin[MAX_GPIO_PIN] = { 0 }; // Possible pin configurations +uint16_t gpio_pin[MAX_GPIO_PIN] = { 0 }; // GPIO functions indexed by pin number #endif // FINAL_ESP32 #endif // ESP32 @@ -136,16 +136,16 @@ uint8_t blinkspeed = 1; // LED blink rate #ifdef ESP8266 #ifdef LEGACY_GPIO_ARRAY -uint8_t pin[GPIO_MAX]; // Possible pin configurations +uint8_t pin_gpio[GPIO_MAX]; // Pin numbers indexed by GPIO function #else // No LEGACY_GPIO_ARRAY -uint8_t pin[MAX_GPIO_PIN] = { 0 }; // Possible pin configurations +uint8_t gpio_pin[MAX_GPIO_PIN] = { 0 }; // GPIO functions indexed by pin number #endif // LEGACY_GPIO_ARRAY #else // ESP32 #ifndef FINAL_ESP32 #ifdef LEGACY_GPIO_ARRAY -uint8_t pin[GPIO_MAX]; // Possible pin configurations +uint8_t pin_gpio[GPIO_MAX]; // Pin numbers indexed by GPIO function #else // No LEGACY_GPIO_ARRAY -uint8_t pin[MAX_GPIO_PIN] = { 0 }; // Possible pin configurations +uint8_t gpio_pin[MAX_GPIO_PIN] = { 0 }; // GPIO functions indexed by pin number #endif // LEGACY_GPIO_ARRAY #endif // No FINAL_ESP32 #endif // ESP8266 - ESP32 diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 0c2ad48cf..8078c7bce 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -1573,7 +1573,7 @@ chknext: } if (!strncmp(vname,"pn[",3)) { GetNumericResult(vname+3,OPER_EQU,&fvar,0); -// fvar=pin[(uint8_t)fvar]; +// fvar=pin_gpio[(uint8_t)fvar]; fvar=Pin(fvar); // skip ] bracket len++; @@ -1583,8 +1583,8 @@ chknext: GetNumericResult(vname+3,OPER_EQU,&fvar,0); uint8_t gpiopin=fvar; #ifdef LEGACY_GPIO_ARRAY - for (uint8_t i=0;i 0)) { - fvar = pin[gpiopin]; + if ((gpiopin < ARRAY_SIZE(gpio_pin)) && (gpio_pin[gpiopin] > 0)) { + fvar = gpio_pin[gpiopin]; // skip ] bracket len++; goto exit; diff --git a/tasmota/xsns_53_sml.ino b/tasmota/xsns_53_sml.ino index 632f64f50..efe3b89bc 100755 --- a/tasmota/xsns_53_sml.ino +++ b/tasmota/xsns_53_sml.ino @@ -1833,13 +1833,13 @@ uint8_t *script_meter; bool Gpio_used(uint8_t gpiopin) { #ifdef LEGACY_GPIO_ARRAY for (uint16_t i=0;i 0)) { + if ((gpiopin < ARRAY_SIZE(gpio_pin)) && (gpio_pin[gpiopin] > 0)) { return true; } #endif From 7dc7b631d46348fd902eaa5943281afc7c7b1983 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 29 Apr 2020 14:18:38 +0200 Subject: [PATCH 20/40] Fix ESP32 settings size Fix ESP32 settings size as regression from yesterday --- tasmota/settings.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index e5c9800fd..f4139a748 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -362,12 +362,15 @@ struct { char ex_friendlyname[4][33]; // 3AC char ex_switch_topic[33]; // 430 #else // ESP32 -#ifdef FINAL_ESP32 +#ifndef FINAL_ESP32 + char ex_friendlyname[4][33]; // 3AC + char ex_switch_topic[33]; // 430 +#else // FINAL_ESP32 myio my_gp; // 3AC - 2 x 40 bytes (ESP32) mytmplt user_template; // 3FC - 2 x 37 bytes (ESP32) uint8_t free_esp32_446[11]; // 446 -#endif +#endif // FINAL_ESP32 #endif // ESP8266 - ESP32 char serial_delimiter; // 451 @@ -420,7 +423,9 @@ struct { mytmplt user_template; // 580 - 37 bytes (ESP32) uint8_t free_esp32_5a5[23]; // 5A5 -#endif +#else // FINAL_ESP32 + char ex_mqtt_fulltopic[100]; // 558 +#endif // FINAL_ESP32 #endif // ESP8266 - ESP32 SysBitfield2 flag2; // 5BC From ef61668037ed8667ec438a874339d52f3632c14d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 29 Apr 2020 17:44:03 +0200 Subject: [PATCH 21/40] Change ESP32 pin allocation part 2 --- tasmota/support.ino | 25 +++++++- tasmota/support_command.ino | 56 ++++++++++++++--- tasmota/support_tasmota.ino | 58 +++++++++--------- tasmota/tasmota_globals.h | 14 ++++- tasmota/tasmota_template_ESP32_final.h | 84 +++++++++++++------------- tasmota/xdrv_01_webserver.ino | 36 ++++++++--- 6 files changed, 182 insertions(+), 91 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index e90d01c85..7523a65a3 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1256,7 +1256,7 @@ bool FlashPin(uint32_t pin) return (((pin > 5) && (pin < 9)) || (11 == pin)); } -uint8_t ValidPin(uint32_t pin, uint32_t gpio) +uint32_t ValidPin(uint32_t pin, uint32_t gpio) { if (FlashPin(pin)) { return GPIO_NONE; // Disable flash pins GPIO6, GPIO7, GPIO8 and GPIO11 @@ -1274,7 +1274,15 @@ uint8_t ValidPin(uint32_t pin, uint32_t gpio) bool ValidGPIO(uint32_t pin, uint32_t gpio) { +#ifdef ESP8266 return (GPIO_USER == ValidPin(pin, gpio)); // Only allow GPIO_USER pins +#else // ESP32 +#ifndef FINAL_ESP32 + return (GPIO_USER == ValidPin(pin, gpio)); // Only allow GPIO_USER pins +#else // FINAL_ESP32 + return (GPIO_USER == ValidPin(pin, gpio >> 5)); // Only allow GPIO_USER pins +#endif // FINAL_ESP32 +#endif // ESP8266 - ESP32 } bool ValidAdc(void) @@ -1362,7 +1370,7 @@ bool JsonTemplate(const char* dataBuf) #ifdef ESP8266 StaticJsonBuffer<400> jb; // 331 from https://arduinojson.org/v5/assistant/ #else - StaticJsonBuffer<800> jb; // 654 from https://arduinojson.org/v5/assistant/ + StaticJsonBuffer<999> jb; // 654 from https://arduinojson.org/v5/assistant/ #endif JsonObject& obj = jb.parseObject(dataBuf); if (!obj.success()) { return false; } @@ -1881,3 +1889,16 @@ void AddLogMissed(const char *sensor, uint32_t misses) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SNS: %s missed %d"), sensor, SENSOR_MAX_MISS - misses); } + +void AddLogBufferSize(uint32_t loglevel, uint8_t *buffer, uint32_t count, uint32_t size) { + snprintf_P(log_data, sizeof(log_data), PSTR("DMP:")); + for (uint32_t i = 0; i < count; i++) { + if (1 == size) { // uint8_t + snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, *(buffer)); + } else { // uint16_t + snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X%02X"), log_data, *(buffer +1), *(buffer)); + } + buffer += size; + } + AddLog(loglevel); +} diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 01c227f36..7bd3fcde5 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -1045,11 +1045,30 @@ void CmndGpio(void) if (XdrvMailbox.index < ARRAY_SIZE(Settings.my_gp.io)) { myio cmodule; ModuleGpios(&cmodule); - if (ValidGPIO(XdrvMailbox.index, cmodule.io[XdrvMailbox.index]) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < GPIO_SENSOR_END)) { + if (ValidGPIO(XdrvMailbox.index, cmodule.io[XdrvMailbox.index]) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < AGPIO(GPIO_SENSOR_END))) { bool present = false; - for (uint32_t i = 0; i < sizeof(kGpioNiceList); i++) { + for (uint32_t i = 0; i < ARRAY_SIZE(kGpioNiceList); i++) { +#ifdef ESP8266 uint32_t midx = pgm_read_byte(kGpioNiceList + i); - if (midx == XdrvMailbox.payload) { present = true; } + if (midx == XdrvMailbox.payload) { + present = true; + break; + } +#else // ESP32 +#ifndef FINAL_ESP32 + uint32_t midx = pgm_read_byte(kGpioNiceList + i); + if (midx == XdrvMailbox.payload) { + present = true; + break; + } +#else // FINAL_ESP32 + uint32_t midx = pgm_read_word(kGpioNiceList + i) << 5; + if (midx == (XdrvMailbox.payload & 0xFFE0)) { + present = true; + break; + } +#endif // FINAL_ESP32 +#endif // ESP8266 - ESP32 } if (present) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { @@ -1067,17 +1086,25 @@ void CmndGpio(void) if (ValidGPIO(i, cmodule.io[i]) || ((GPIO_USER == XdrvMailbox.payload) && !FlashPin(i))) { if (jsflg) { ResponseAppend_P(PSTR(",")); } jsflg = true; - uint8_t sensor_type = Settings.my_gp.io[i]; + uint32_t sensor_type = Settings.my_gp.io[i]; if (!ValidGPIO(i, cmodule.io[i])) { sensor_type = cmodule.io[i]; if (GPIO_USER == sensor_type) { // A user GPIO equals a not connected (=GPIO_NONE) GPIO here sensor_type = GPIO_NONE; } } - uint8_t sensor_name_idx = sensor_type; +#ifdef ESP8266 + uint32_t sensor_name_idx = sensor_type; +#else // ESP32 +#ifndef FINAL_ESP32 + uint32_t sensor_name_idx = sensor_type; +#else // FINAL_ESP32 + uint32_t sensor_name_idx = sensor_type >> 5; +#endif // FINAL_ESP32 +#endif // ESP8266 - ESP32 const char *sensor_names = kSensorNames; - if (sensor_type > GPIO_FIX_START) { - sensor_name_idx = sensor_type - GPIO_FIX_START -1; + if (sensor_name_idx > GPIO_FIX_START) { + sensor_name_idx = sensor_name_idx - GPIO_FIX_START -1; sensor_names = kSensorNamesFixed; } char stemp1[TOPSZ]; @@ -1099,8 +1126,19 @@ void CmndGpios(void) ModuleGpios(&cmodule); uint32_t lines = 1; bool jsflg = false; - for (uint32_t i = 0; i < sizeof(kGpioNiceList); i++) { + for (uint32_t i = 0; i < ARRAY_SIZE(kGpioNiceList); i++) { +#ifdef ESP8266 uint32_t midx = pgm_read_byte(kGpioNiceList + i); + uint32_t ridx = midx; +#else // ESP32 +#ifndef FINAL_ESP32 + uint32_t midx = pgm_read_byte(kGpioNiceList + i); + uint32_t ridx = midx; +#else // FINAL_ESP32 + uint32_t midx = pgm_read_word(kGpioNiceList + i); + uint32_t ridx = midx << 5; +#endif // FINAL_ESP32 +#endif // ESP8266 - ESP32 if ((XdrvMailbox.payload != 255) && GetUsedInModule(midx, cmodule.io)) { continue; } if (!jsflg) { Response_P(PSTR("{\"" D_CMND_GPIOS "%d\":{"), lines); @@ -1109,7 +1147,7 @@ void CmndGpios(void) } jsflg = true; char stemp1[TOPSZ]; - if ((ResponseAppend_P(PSTR("\"%d\":\"%s\""), midx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames)) > (LOGSZ - TOPSZ)) || (i == sizeof(kGpioNiceList) -1)) { + if ((ResponseAppend_P(PSTR("\"%d\":\"%s\""), ridx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames)) > (LOGSZ - TOPSZ)) || (i == ARRAY_SIZE(kGpioNiceList) -1)) { ResponseJsonEndEnd(); MqttPublishPrefixTopic_P(RESULT_OR_STAT, UpperCase(XdrvMailbox.command, XdrvMailbox.command)); jsflg = false; diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 91fda344d..c1f59cc95 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1353,21 +1353,21 @@ void GpioInit(void) } for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) { - if ((Settings.user_template.gp.io[i] >= GPIO_SENSOR_END) && (Settings.user_template.gp.io[i] < GPIO_USER)) { - Settings.user_template.gp.io[i] = GPIO_USER; // Fix not supported sensor ids in template + if ((Settings.user_template.gp.io[i] >= AGPIO(GPIO_SENSOR_END)) && (Settings.user_template.gp.io[i] < AGPIO(GPIO_USER))) { + Settings.user_template.gp.io[i] = AGPIO(GPIO_USER); // Fix not supported sensor ids in template } } myio def_gp; ModuleGpios(&def_gp); for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { - if ((Settings.my_gp.io[i] >= GPIO_SENSOR_END) && (Settings.my_gp.io[i] < GPIO_USER)) { + if ((Settings.my_gp.io[i] >= AGPIO(GPIO_SENSOR_END)) && (Settings.my_gp.io[i] < AGPIO(GPIO_USER))) { Settings.my_gp.io[i] = GPIO_NONE; // Fix not supported sensor ids in module } else if (Settings.my_gp.io[i] > GPIO_NONE) { my_module.io[i] = Settings.my_gp.io[i]; // Set User selected Module sensors } - if ((def_gp.io[i] > GPIO_NONE) && (def_gp.io[i] < GPIO_USER)) { + if ((def_gp.io[i] > GPIO_NONE) && (def_gp.io[i] < AGPIO(GPIO_USER))) { my_module.io[i] = def_gp.io[i]; // Force Template override } } @@ -1395,38 +1395,38 @@ void GpioInit(void) XdrvMailbox.index = mpin; XdrvMailbox.payload = i; - if ((mpin >= GPIO_SWT1_NP) && (mpin < (GPIO_SWT1_NP + MAX_SWITCHES))) { - SwitchPullupFlag(mpin - GPIO_SWT1_NP); - mpin -= (GPIO_SWT1_NP - GPIO_SWT1); + if ((mpin >= AGPIO(GPIO_SWT1_NP)) && (mpin < (AGPIO(GPIO_SWT1_NP) + MAX_SWITCHES))) { + SwitchPullupFlag(mpin - AGPIO(GPIO_SWT1_NP)); + mpin -= (AGPIO(GPIO_SWT1_NP) - AGPIO(GPIO_SWT1)); } - else if ((mpin >= GPIO_KEY1_NP) && (mpin < (GPIO_KEY1_NP + MAX_KEYS))) { - ButtonPullupFlag(mpin - GPIO_KEY1_NP); // 0 .. 3 - mpin -= (GPIO_KEY1_NP - GPIO_KEY1); + else if ((mpin >= AGPIO(GPIO_KEY1_NP)) && (mpin < (AGPIO(GPIO_KEY1_NP) + MAX_KEYS))) { + ButtonPullupFlag(mpin - AGPIO(GPIO_KEY1_NP)); // 0 .. 3 + mpin -= (AGPIO(GPIO_KEY1_NP) - AGPIO(GPIO_KEY1)); } - else if ((mpin >= GPIO_KEY1_INV) && (mpin < (GPIO_KEY1_INV + MAX_KEYS))) { - ButtonInvertFlag(mpin - GPIO_KEY1_INV); // 0 .. 3 - mpin -= (GPIO_KEY1_INV - GPIO_KEY1); + else if ((mpin >= AGPIO(GPIO_KEY1_INV)) && (mpin < (AGPIO(GPIO_KEY1_INV) + MAX_KEYS))) { + ButtonInvertFlag(mpin - AGPIO(GPIO_KEY1_INV)); // 0 .. 3 + mpin -= (AGPIO(GPIO_KEY1_INV) - AGPIO(GPIO_KEY1)); } - else if ((mpin >= GPIO_KEY1_INV_NP) && (mpin < (GPIO_KEY1_INV_NP + MAX_KEYS))) { - ButtonPullupFlag(mpin - GPIO_KEY1_INV_NP); // 0 .. 3 - ButtonInvertFlag(mpin - GPIO_KEY1_INV_NP); // 0 .. 3 - mpin -= (GPIO_KEY1_INV_NP - GPIO_KEY1); + else if ((mpin >= AGPIO(GPIO_KEY1_INV_NP)) && (mpin < (AGPIO(GPIO_KEY1_INV_NP) + MAX_KEYS))) { + ButtonPullupFlag(mpin - AGPIO(GPIO_KEY1_INV_NP)); // 0 .. 3 + ButtonInvertFlag(mpin - AGPIO(GPIO_KEY1_INV_NP)); // 0 .. 3 + mpin -= (AGPIO(GPIO_KEY1_INV_NP) - AGPIO(GPIO_KEY1)); } - else if ((mpin >= GPIO_REL1_INV) && (mpin < (GPIO_REL1_INV + MAX_RELAYS))) { - bitSet(rel_inverted, mpin - GPIO_REL1_INV); - mpin -= (GPIO_REL1_INV - GPIO_REL1); + else if ((mpin >= AGPIO(GPIO_REL1_INV)) && (mpin < (AGPIO(GPIO_REL1_INV) + MAX_RELAYS))) { + bitSet(rel_inverted, mpin - AGPIO(GPIO_REL1_INV)); + mpin -= (AGPIO(GPIO_REL1_INV) - AGPIO(GPIO_REL1)); } - else if ((mpin >= GPIO_LED1_INV) && (mpin < (GPIO_LED1_INV + MAX_LEDS))) { - bitSet(led_inverted, mpin - GPIO_LED1_INV); - mpin -= (GPIO_LED1_INV - GPIO_LED1); + else if ((mpin >= AGPIO(GPIO_LED1_INV)) && (mpin < (AGPIO(GPIO_LED1_INV) + MAX_LEDS))) { + bitSet(led_inverted, mpin - AGPIO(GPIO_LED1_INV)); + mpin -= (AGPIO(GPIO_LED1_INV) - AGPIO(GPIO_LED1)); } - else if (mpin == GPIO_LEDLNK_INV) { + else if (mpin == AGPIO(GPIO_LEDLNK_INV)) { ledlnk_inverted = 1; - mpin -= (GPIO_LEDLNK_INV - GPIO_LEDLNK); + mpin -= (AGPIO(GPIO_LEDLNK_INV) - AGPIO(GPIO_LEDLNK)); } - else if ((mpin >= GPIO_PWM1_INV) && (mpin < (GPIO_PWM1_INV + MAX_PWMS))) { - bitSet(pwm_inverted, mpin - GPIO_PWM1_INV); - mpin -= (GPIO_PWM1_INV - GPIO_PWM1); + else if ((mpin >= AGPIO(GPIO_PWM1_INV)) && (mpin < (AGPIO(GPIO_PWM1_INV) + MAX_PWMS))) { + bitSet(pwm_inverted, mpin - AGPIO(GPIO_PWM1_INV)); + mpin -= (AGPIO(GPIO_PWM1_INV) - AGPIO(GPIO_PWM1)); } else if (XdrvCall(FUNC_PIN_STATE)) { mpin = XdrvMailbox.index; @@ -1439,7 +1439,7 @@ void GpioInit(void) } #ifndef LEGACY_GPIO_ARRAY - AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t*)gpio_pin, ARRAY_SIZE(gpio_pin)); +// AddLogBufferSize(LOG_LEVEL_DEBUG, (uint8_t*)gpio_pin, ARRAY_SIZE(gpio_pin), sizeof(gpio_pin[0])); #endif #ifdef ESP8266 diff --git a/tasmota/tasmota_globals.h b/tasmota/tasmota_globals.h index 178cf3c24..1cff43fd8 100644 --- a/tasmota/tasmota_globals.h +++ b/tasmota/tasmota_globals.h @@ -53,9 +53,9 @@ extern "C" void resetPins(); * Theo transition defines - DO NOT TOUCH \*********************************************************************************************/ -//#define LEGACY_GPIO_ARRAY // Uncomment to use legacy GPIO array instead of new PIN array +//#define LEGACY_GPIO_ARRAY // Uncomment to use legacy GPIO array instead of new PIN array -//#define FINAL_ESP32 // Uncomment for ESP32 16-bits PIN array +//#define FINAL_ESP32 // Uncomment for ESP32 16-bits PIN array #ifdef FINAL_ESP32 #undef LEGACY_GPIO_ARRAY #endif @@ -333,6 +333,16 @@ const char kWebColors[] PROGMEM = #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #endif +#ifdef ESP8266 +#define AGPIO(x) (x) +#else // ESP32 +#ifndef FINAL_ESP32 +#define AGPIO(x) (x) +#else // FINAL_ESP32 +#define AGPIO(x) (x<<5) +#endif // FINAL_ESP32 +#endif // ESP8266 - ESP32 + #ifdef USE_DEVICE_GROUPS #define SendDeviceGroupMessage(DEVICE_INDEX, REQUEST_TYPE, ...) _SendDeviceGroupMessage(DEVICE_INDEX, REQUEST_TYPE, __VA_ARGS__, 0) #define SendLocalDeviceGroupMessage(REQUEST_TYPE, ...) _SendDeviceGroupMessage(0, REQUEST_TYPE, __VA_ARGS__, 0) diff --git a/tasmota/tasmota_template_ESP32_final.h b/tasmota/tasmota_template_ESP32_final.h index e13dbec24..b48897094 100644 --- a/tasmota/tasmota_template_ESP32_final.h +++ b/tasmota/tasmota_template_ESP32_final.h @@ -693,48 +693,48 @@ const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = { }; const mytmplt kModules PROGMEM = -{ // WEMOS - Espressif ESP32-DevKitC - Any ESP32 device like WeMos and NodeMCU hardware (ESP32) - GPIO_USER << 5, // 0 (I)O GPIO0, ADC2_CH1, TOUCH1, RTC_GPIO11, CLK_OUT1, EMAC_TX_CLK - GPIO_USER << 5, // 1 IO TXD0 GPIO1, U0TXD, CLK_OUT3, EMAC_RXD2 - GPIO_USER << 5, // 2 IO GPIO2, ADC2_CH2, TOUCH2, RTC_GPIO12, HSPIWP, HS2_DATA0, SD_DATA0 - GPIO_USER << 5, // 3 IO RXD0 GPIO3, U0RXD, CLK_OUT2 - GPIO_USER << 5, // 4 IO GPIO4, ADC2_CH0, TOUCH0, RTC_GPIO10, HSPIHD, HS2_DATA1, SD_DATA1, EMAC_TX_ER - GPIO_USER << 5, // 5 IO GPIO5, VSPICS0, HS1_DATA6, EMAC_RX_CLK - // 6 IO GPIO6, Flash CLK - // 7 IO GPIO7, Flash D0 - // 8 IO GPIO8, Flash D1 - GPIO_USER << 5, // 9 IO GPIO9, Flash D2, U1RXD - GPIO_USER << 5, // 10 IO GPIO10, Flash D3, U1TXD - // 11 IO GPIO11, Flash CMD - GPIO_USER << 5, // 12 (I)O GPIO12, ADC2_CH5, TOUCH5, RTC_GPIO15, MTDI, HSPIQ, HS2_DATA2, SD_DATA2, EMAC_TXD3 (If driven High, flash voltage (VDD_SDIO) is 1.8V not default 3.3V. Has internal pull-down, so unconnected = Low = 3.3V. May prevent flashing and/or booting if 3.3V flash is connected and pulled high. See ESP32 datasheet for more details.) - GPIO_USER << 5, // 13 IO GPIO13, ADC2_CH4, TOUCH4, RTC_GPIO14, MTCK, HSPID, HS2_DATA3, SD_DATA3, EMAC_RX_ER - GPIO_USER << 5, // 14 IO GPIO14, ADC2_CH6, TOUCH6, RTC_GPIO16, MTMS, HSPICLK, HS2_CLK, SD_CLK, EMAC_TXD2 - GPIO_USER << 5, // 15 (I)O GPIO15, ADC2_CH3, TOUCH3, MTDO, HSPICS0, RTC_GPIO13, HS2_CMD, SD_CMD, EMAC_RXD3 (If driven Low, silences boot messages from normal boot. Has internal pull-up, so unconnected = High = normal output.) - GPIO_USER << 5, // 16 IO GPIO16, HS1_DATA4, U2RXD, EMAC_CLK_OUT - GPIO_USER << 5, // 17 IO GPIO17, HS1_DATA5, U2TXD, EMAC_CLK_OUT_180 - GPIO_USER << 5, // 18 IO GPIO18, VSPICLK, HS1_DATA7 - GPIO_USER << 5, // 19 IO GPIO19, VSPIQ, U0CTS, EMAC_TXD0 - 0, // 20 - GPIO_USER << 5, // 21 IO GPIO21, VSPIHD, EMAC_TX_EN - GPIO_USER << 5, // 22 IO LED GPIO22, VSPIWP, U0RTS, EMAC_TXD1 - GPIO_USER << 5, // 23 IO GPIO23, VSPID, HS1_STROBE - 0, // 24 - GPIO_USER << 5, // 25 IO GPIO25, DAC_1, ADC2_CH8, RTC_GPIO6, EMAC_RXD0 - GPIO_USER << 5, // 26 IO GPIO26, DAC_2, ADC2_CH9, RTC_GPIO7, EMAC_RXD1 - GPIO_USER << 5, // 27 IO GPIO27, ADC2_CH7, TOUCH7, RTC_GPIO17, EMAC_RX_DV - 0, // 28 - 0, // 29 - 0, // 30 - 0, // 31 - GPIO_USER << 5, // 32 IO GPIO32, XTAL_32K_P (32.768 kHz crystal oscillator input), ADC1_CH4, TOUCH9, RTC_GPIO9 - GPIO_USER << 5, // 33 IO GPIO33, XTAL_32K_N (32.768 kHz crystal oscillator output), ADC1_CH5, TOUCH8, RTC_GPIO8 - GPIO_USER << 5, // 34 I NO PULLUP GPIO34, ADC1_CH6, RTC_GPIO4 - GPIO_USER << 5, // 35 I NO PULLUP GPIO35, ADC1_CH7, RTC_GPIO5 - GPIO_USER << 5, // 36 I NO PULLUP GPIO36, SENSOR_VP, ADC_H, ADC1_CH0, RTC_GPIO0 - 0, // 37 NO PULLUP - 0, // 38 NO PULLUP - GPIO_USER << 5, // 39 I NO PULLUP GPIO39, SENSOR_VN, ADC1_CH3, ADC_H, RTC_GPIO3 - 0 // Flag +{ // WEMOS - Espressif ESP32-DevKitC - Any ESP32 device like WeMos and NodeMCU hardware (ESP32) + AGPIO(GPIO_USER), // 0 (I)O GPIO0, ADC2_CH1, TOUCH1, RTC_GPIO11, CLK_OUT1, EMAC_TX_CLK + AGPIO(GPIO_USER), // 1 IO TXD0 GPIO1, U0TXD, CLK_OUT3, EMAC_RXD2 + AGPIO(GPIO_USER), // 2 IO GPIO2, ADC2_CH2, TOUCH2, RTC_GPIO12, HSPIWP, HS2_DATA0, SD_DATA0 + AGPIO(GPIO_USER), // 3 IO RXD0 GPIO3, U0RXD, CLK_OUT2 + AGPIO(GPIO_USER), // 4 IO GPIO4, ADC2_CH0, TOUCH0, RTC_GPIO10, HSPIHD, HS2_DATA1, SD_DATA1, EMAC_TX_ER + AGPIO(GPIO_USER), // 5 IO GPIO5, VSPICS0, HS1_DATA6, EMAC_RX_CLK + // 6 IO GPIO6, Flash CLK + // 7 IO GPIO7, Flash D0 + // 8 IO GPIO8, Flash D1 + AGPIO(GPIO_USER), // 9 IO GPIO9, Flash D2, U1RXD + AGPIO(GPIO_USER), // 10 IO GPIO10, Flash D3, U1TXD + // 11 IO GPIO11, Flash CMD + AGPIO(GPIO_USER), // 12 (I)O GPIO12, ADC2_CH5, TOUCH5, RTC_GPIO15, MTDI, HSPIQ, HS2_DATA2, SD_DATA2, EMAC_TXD3 (If driven High, flash voltage (VDD_SDIO) is 1.8V not default 3.3V. Has internal pull-down, so unconnected = Low = 3.3V. May prevent flashing and/or booting if 3.3V flash is connected and pulled high. See ESP32 datasheet for more details.) + AGPIO(GPIO_USER), // 13 IO GPIO13, ADC2_CH4, TOUCH4, RTC_GPIO14, MTCK, HSPID, HS2_DATA3, SD_DATA3, EMAC_RX_ER + AGPIO(GPIO_USER), // 14 IO GPIO14, ADC2_CH6, TOUCH6, RTC_GPIO16, MTMS, HSPICLK, HS2_CLK, SD_CLK, EMAC_TXD2 + AGPIO(GPIO_USER), // 15 (I)O GPIO15, ADC2_CH3, TOUCH3, MTDO, HSPICS0, RTC_GPIO13, HS2_CMD, SD_CMD, EMAC_RXD3 (If driven Low, silences boot messages from normal boot. Has internal pull-up, so unconnected = High = normal output.) + AGPIO(GPIO_USER), // 16 IO GPIO16, HS1_DATA4, U2RXD, EMAC_CLK_OUT + AGPIO(GPIO_USER), // 17 IO GPIO17, HS1_DATA5, U2TXD, EMAC_CLK_OUT_180 + AGPIO(GPIO_USER), // 18 IO GPIO18, VSPICLK, HS1_DATA7 + AGPIO(GPIO_USER), // 19 IO GPIO19, VSPIQ, U0CTS, EMAC_TXD0 + 0, // 20 + AGPIO(GPIO_USER), // 21 IO GPIO21, VSPIHD, EMAC_TX_EN + AGPIO(GPIO_USER), // 22 IO LED GPIO22, VSPIWP, U0RTS, EMAC_TXD1 + AGPIO(GPIO_USER), // 23 IO GPIO23, VSPID, HS1_STROBE + 0, // 24 + AGPIO(GPIO_USER), // 25 IO GPIO25, DAC_1, ADC2_CH8, RTC_GPIO6, EMAC_RXD0 + AGPIO(GPIO_USER), // 26 IO GPIO26, DAC_2, ADC2_CH9, RTC_GPIO7, EMAC_RXD1 + AGPIO(GPIO_USER), // 27 IO GPIO27, ADC2_CH7, TOUCH7, RTC_GPIO17, EMAC_RX_DV + 0, // 28 + 0, // 29 + 0, // 30 + 0, // 31 + AGPIO(GPIO_USER), // 32 IO GPIO32, XTAL_32K_P (32.768 kHz crystal oscillator input), ADC1_CH4, TOUCH9, RTC_GPIO9 + AGPIO(GPIO_USER), // 33 IO GPIO33, XTAL_32K_N (32.768 kHz crystal oscillator output), ADC1_CH5, TOUCH8, RTC_GPIO8 + AGPIO(GPIO_USER), // 34 I NO PULLUP GPIO34, ADC1_CH6, RTC_GPIO4 + AGPIO(GPIO_USER), // 35 I NO PULLUP GPIO35, ADC1_CH7, RTC_GPIO5 + AGPIO(GPIO_USER), // 36 I NO PULLUP GPIO36, SENSOR_VP, ADC_H, ADC1_CH0, RTC_GPIO0 + 0, // 37 NO PULLUP + 0, // 38 NO PULLUP + AGPIO(GPIO_USER), // 39 I NO PULLUP GPIO39, SENSOR_VN, ADC1_CH3, ADC_H, RTC_GPIO3 + 0 // Flag }; #endif // ESP32 diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 61f98e649..a4f43b6c6 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1429,12 +1429,23 @@ void HandleTemplateConfiguration(void) WSContentSend_P(HTTP_SCRIPT_MODULE_TEMPLATE); WSContentSend_P(HTTP_SCRIPT_TEMPLATE); - for (uint32_t i = 0; i < sizeof(kGpioNiceList); i++) { // GPIO: }2'0'>None (0)}3}2'17'>Button1 (17)}3... + for (uint32_t i = 0; i < ARRAY_SIZE(kGpioNiceList); i++) { // GPIO: }2'0'>None (0)}3}2'17'>Button1 (17)}3... if (1 == i) { - WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, GPIO_USER, D_SENSOR_USER, GPIO_USER); // }2'255'>User (255)}3 + WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, AGPIO(GPIO_USER), D_SENSOR_USER, AGPIO(GPIO_USER)); // }2'255'>User (255)}3 } +#ifdef ESP8266 uint32_t midx = pgm_read_byte(kGpioNiceList + i); - WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames), midx); + uint32_t ridx = midx; +#else // ESP32 +#ifndef FINAL_ESP32 + uint32_t midx = pgm_read_byte(kGpioNiceList + i); + uint32_t ridx = midx; +#else // FINAL_ESP32 + uint32_t midx = pgm_read_word(kGpioNiceList + i); + uint32_t ridx = midx << 5; +#endif // FINAL_ESP32 +#endif // ESP8266 - ESP32 + WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, ridx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames), ridx); } WSContentSend_P(HTTP_SCRIPT_TEMPLATE2); for (uint32_t i = 0; i < ADC0_END; i++) { // FLAG: }2'0'>None (0)}3}2'17'>Analog (17)}3... @@ -1492,7 +1503,7 @@ void TemplateSaveSettings(void) if (8 == i) { j = 12; } snprintf_P(webindex, sizeof(webindex), PSTR("g%d"), j); WebGetArg(webindex, tmp, sizeof(tmp)); // GPIO - uint8_t gpio = atoi(tmp); + uint32_t gpio = atoi(tmp); snprintf_P(svalue, sizeof(svalue), PSTR("%s%s%d"), svalue, (i>0)?",":"", gpio); j++; } @@ -1546,10 +1557,21 @@ void HandleModuleConfiguration(void) WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), vidx); } WSContentSend_P(PSTR("\";sk(%d,99);os=\""), Settings.module); - for (uint32_t i = 0; i < sizeof(kGpioNiceList); i++) { + for (uint32_t i = 0; i < ARRAY_SIZE(kGpioNiceList); i++) { +#ifdef ESP8266 midx = pgm_read_byte(kGpioNiceList + i); + uint32_t ridx = midx; +#else // ESP32 +#ifndef FINAL_ESP32 + midx = pgm_read_byte(kGpioNiceList + i); + uint32_t ridx = midx; +#else // FINAL_ESP32 + midx = pgm_read_word(kGpioNiceList + i); + uint32_t ridx = midx << 5; +#endif // FINAL_ESP32 +#endif // ESP8266 - ESP32 if (!GetUsedInModule(midx, cmodule.io)) { - WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames), midx); + WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, ridx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames), ridx); } } WSContentSend_P(PSTR("\";")); @@ -1616,7 +1638,7 @@ void ModuleSaveSettings(void) if (ValidGPIO(i, cmodule.io[i])) { snprintf_P(webindex, sizeof(webindex), PSTR("g%d"), i); WebGetArg(webindex, tmp, sizeof(tmp)); - uint8_t value = (!strlen(tmp)) ? 0 : atoi(tmp); + uint32_t value = (!strlen(tmp)) ? 0 : atoi(tmp); #ifdef ESP8266 Settings.my_gp.io[i] = value; #else // ESP32 From a83ea5290ee921850a937aa29655025db6edcf3d Mon Sep 17 00:00:00 2001 From: device111 <48546979+device111@users.noreply.github.com> Date: Wed, 29 Apr 2020 20:33:46 +0200 Subject: [PATCH 22/40] Fix http message time --- tasmota/xsns_67_as3935.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasmota/xsns_67_as3935.ino b/tasmota/xsns_67_as3935.ino index 27b97f9a2..59618c32a 100644 --- a/tasmota/xsns_67_as3935.ino +++ b/tasmota/xsns_67_as3935.ino @@ -548,14 +548,14 @@ void AS3935EverySecond() { as3935_sensor.mqtt_irq = 0; // start http times as3935_sensor.http_count_start = 1; + as3935_sensor.http_count = 0; as3935_sensor.icount++; // Int counter as3935_sensor.detected = false; } if (as3935_sensor.http_count_start) as3935_sensor.http_count++; // clear Http - if (as3935_sensor.http_count == as3935_sensor.http_timer) { - as3935_sensor.http_count = 0; + if (as3935_sensor.http_count > as3935_sensor.http_timer) { as3935_sensor.http_count_start = 0; as3935_sensor.http_intensity = 0; as3935_sensor.http_distance = 0; From e233c3830de638635a03a228d388b27473396de7 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Thu, 30 Apr 2020 14:38:32 +0200 Subject: [PATCH 23/40] Create CI_github.yml --- .github/workflows/CI_github.yml | 441 ++++++++++++++++++++++++++++++++ 1 file changed, 441 insertions(+) create mode 100644 .github/workflows/CI_github.yml diff --git a/.github/workflows/CI_github.yml b/.github/workflows/CI_github.yml new file mode 100644 index 000000000..685af3b24 --- /dev/null +++ b/.github/workflows/CI_github.yml @@ -0,0 +1,441 @@ +name: PlatformIO CI + +on: [push] + +jobs: + tasmota: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota + + tasmota-minimal: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-minimal + + tasmota-lite: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-lite + + tasmota-knx: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-knx + + tasmota-sensors: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-sensors + + + tasmota-display: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-display + + tasmota-ir: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-ir + + tasmota-BG: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-BG + + tasmota-BR: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-BR + + tasmota-CN: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-CN + + tasmota-CZ: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-CZ + + tasmota-DE: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-DE + + tasmota-ES: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-ES + + + tasmota-FR: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-FR + + tasmota-GR: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-GR + + tasmota-HE: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-HE + + tasmota-HU: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-HU + + tasmota-IT: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-IT + + tasmota-KO: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-KO + + tasmota-NL: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-NL + + tasmota-PL: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-PL + + tasmota-PT: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-PT + + tasmota-RO: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-RO + + tasmota-RU: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-RU + + tasmota-SE: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-SE + + tasmota-SK: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-SK + + tasmota-TR: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-TR + + tasmota-TW: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-TW + + tasmota-UK: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio upgrade --dev + platformio update + - name: Run PlatformIO + run: platformio run -e tasmota-UK From f6389c73852f5997df069df698e14d1a85a563b8 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Thu, 30 Apr 2020 14:41:43 +0200 Subject: [PATCH 24/40] CI on Push and Pull --- .github/workflows/CI_github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI_github.yml b/.github/workflows/CI_github.yml index 685af3b24..6fb55d608 100644 --- a/.github/workflows/CI_github.yml +++ b/.github/workflows/CI_github.yml @@ -1,6 +1,6 @@ name: PlatformIO CI -on: [push] +on: [push, pull_request] jobs: tasmota: From c0a05e9586762020a4945bfb9179758d6065ad26 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 30 Apr 2020 18:47:34 +0200 Subject: [PATCH 25/40] Change ESP32 pin allocation part 3 --- tasmota/support_command.ino | 25 ++- tasmota/tasmota_template_ESP32_final.h | 294 ++++++++++++------------- tasmota/xdrv_01_webserver.ino | 80 ++++++- 3 files changed, 239 insertions(+), 160 deletions(-) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 7bd3fcde5..a446fec30 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -1062,8 +1062,8 @@ void CmndGpio(void) break; } #else // FINAL_ESP32 - uint32_t midx = pgm_read_word(kGpioNiceList + i) << 5; - if (midx == (XdrvMailbox.payload & 0xFFE0)) { + uint32_t midx = pgm_read_word(kGpioNiceList + i); + if ((XdrvMailbox.payload >= (midx & 0xFFE0)) && (XdrvMailbox.payload < midx)) { present = true; break; } @@ -1083,16 +1083,17 @@ void CmndGpio(void) Response_P(PSTR("{")); bool jsflg = false; for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { - if (ValidGPIO(i, cmodule.io[i]) || ((GPIO_USER == XdrvMailbox.payload) && !FlashPin(i))) { + if (ValidGPIO(i, cmodule.io[i]) || ((AGPIO(GPIO_USER) == XdrvMailbox.payload) && !FlashPin(i))) { if (jsflg) { ResponseAppend_P(PSTR(",")); } jsflg = true; uint32_t sensor_type = Settings.my_gp.io[i]; if (!ValidGPIO(i, cmodule.io[i])) { sensor_type = cmodule.io[i]; - if (GPIO_USER == sensor_type) { // A user GPIO equals a not connected (=GPIO_NONE) GPIO here + if (AGPIO(GPIO_USER) == sensor_type) { // A user GPIO equals a not connected (=GPIO_NONE) GPIO here sensor_type = GPIO_NONE; } } + char sindex[4] = { 0 }; #ifdef ESP8266 uint32_t sensor_name_idx = sensor_type; #else // ESP32 @@ -1100,6 +1101,14 @@ void CmndGpio(void) uint32_t sensor_name_idx = sensor_type; #else // FINAL_ESP32 uint32_t sensor_name_idx = sensor_type >> 5; + uint32_t nice_list_search = sensor_type & 0xFFE0; + for (uint32_t j = 0; j < ARRAY_SIZE(kGpioNiceList); j++) { + uint32_t nls_idx = pgm_read_word(kGpioNiceList + j); + if (((nls_idx & 0xFFE0) == nice_list_search) && ((nls_idx & 0x001F) > 0)) { + snprintf_P(sindex, sizeof(sindex), PSTR("%d"), (sensor_type & 0x001F) +1); + break; + } + } #endif // FINAL_ESP32 #endif // ESP8266 - ESP32 const char *sensor_names = kSensorNames; @@ -1108,8 +1117,8 @@ void CmndGpio(void) sensor_names = kSensorNamesFixed; } char stemp1[TOPSZ]; - ResponseAppend_P(PSTR("\"" D_CMND_GPIO "%d\":{\"%d\":\"%s\"}"), - i, sensor_type, GetTextIndexed(stemp1, sizeof(stemp1), sensor_name_idx, sensor_names)); + ResponseAppend_P(PSTR("\"" D_CMND_GPIO "%d\":{\"%d\":\"%s%s\"}"), + i, sensor_type, GetTextIndexed(stemp1, sizeof(stemp1), sensor_name_idx, sensor_names), sindex); } } if (jsflg) { @@ -1135,8 +1144,8 @@ void CmndGpios(void) uint32_t midx = pgm_read_byte(kGpioNiceList + i); uint32_t ridx = midx; #else // FINAL_ESP32 - uint32_t midx = pgm_read_word(kGpioNiceList + i); - uint32_t ridx = midx << 5; + uint32_t ridx = pgm_read_word(kGpioNiceList + i) & 0xFFE0; + uint32_t midx = ridx >> 5; #endif // FINAL_ESP32 #endif // ESP8266 - ESP32 if ((XdrvMailbox.payload != 255) && GetUsedInModule(midx, cmodule.io)) { continue; } diff --git a/tasmota/tasmota_template_ESP32_final.h b/tasmota/tasmota_template_ESP32_final.h index b48897094..bd8063d33 100644 --- a/tasmota/tasmota_template_ESP32_final.h +++ b/tasmota/tasmota_template_ESP32_final.h @@ -297,290 +297,290 @@ const char kSensorNamesFixed[] PROGMEM = D_SENSOR_USER; const uint16_t kGpioNiceList[] PROGMEM = { - GPIO_NONE, // Not used - GPIO_KEY1, // Buttons - GPIO_KEY1_NP, - GPIO_KEY1_INV, - GPIO_KEY1_INV_NP, - GPIO_SWT1, // User connected external switches - GPIO_SWT1_NP, - GPIO_REL1, // Relays - GPIO_REL1_INV, - GPIO_LED1, // Leds - GPIO_LED1_INV, + GPIO_NONE, // Not used + AGPIO(GPIO_KEY1) + MAX_KEYS, // Buttons + AGPIO(GPIO_KEY1_NP) + MAX_KEYS, + AGPIO(GPIO_KEY1_INV) + MAX_KEYS, + AGPIO(GPIO_KEY1_INV_NP) + MAX_KEYS, + AGPIO(GPIO_SWT1) + MAX_SWITCHES, // User connected external switches + AGPIO(GPIO_SWT1_NP) + MAX_SWITCHES, + AGPIO(GPIO_REL1) + MAX_RELAYS, // Relays + AGPIO(GPIO_REL1_INV) + MAX_RELAYS, + AGPIO(GPIO_LED1) + MAX_LEDS, // Leds + AGPIO(GPIO_LED1_INV) + MAX_LEDS, #ifdef USE_COUNTER - GPIO_CNTR1, // Counters - GPIO_CNTR1_NP, + AGPIO(GPIO_CNTR1) + MAX_COUNTERS, // Counters + AGPIO(GPIO_CNTR1_NP) + MAX_COUNTERS, #endif - GPIO_PWM1, // RGB Red or C Cold White - GPIO_PWM1_INV, + AGPIO(GPIO_PWM1) + MAX_PWMS, // RGB Red or C Cold White + AGPIO(GPIO_PWM1_INV) + MAX_PWMS, #ifdef USE_BUZZER - GPIO_BUZZER, // Buzzer - GPIO_BUZZER_INV, // Inverted buzzer + AGPIO(GPIO_BUZZER), // Buzzer + AGPIO(GPIO_BUZZER_INV), // Inverted buzzer #endif - GPIO_LEDLNK, // Link led - GPIO_LEDLNK_INV, // Inverted link led + AGPIO(GPIO_LEDLNK), // Link led + AGPIO(GPIO_LEDLNK_INV), // Inverted link led #ifdef USE_I2C - GPIO_I2C_SCL, // I2C SCL - GPIO_I2C_SDA, // I2C SDA + AGPIO(GPIO_I2C_SCL), // I2C SCL + AGPIO(GPIO_I2C_SDA), // I2C SDA #endif #ifdef USE_SPI - GPIO_SPI_MISO, // SPI MISO - GPIO_SPI_MOSI, // SPI MOSI - GPIO_SPI_CLK, // SPI Clk - GPIO_SPI_CS, // SPI Chip Select - GPIO_SPI_DC, // SPI Data Direction - GPIO_SSPI_MISO, // Software SPI Master Input Slave Output - GPIO_SSPI_MOSI, // Software SPI Master Output Slave Input - GPIO_SSPI_SCLK, // Software SPI Serial Clock - GPIO_SSPI_CS, // Software SPI Chip Select - GPIO_SSPI_DC, // Software SPI Data or Command + AGPIO(GPIO_SPI_MISO), // SPI MISO + AGPIO(GPIO_SPI_MOSI), // SPI MOSI + AGPIO(GPIO_SPI_CLK), // SPI Clk + AGPIO(GPIO_SPI_CS), // SPI Chip Select + AGPIO(GPIO_SPI_DC), // SPI Data Direction + AGPIO(GPIO_SSPI_MISO), // Software SPI Master Input Slave Output + AGPIO(GPIO_SSPI_MOSI), // Software SPI Master Output Slave Input + AGPIO(GPIO_SSPI_SCLK), // Software SPI Serial Clock + AGPIO(GPIO_SSPI_CS), // Software SPI Chip Select + AGPIO(GPIO_SSPI_DC), // Software SPI Data or Command #endif #ifdef USE_DISPLAY - GPIO_BACKLIGHT, // Display backlight control - GPIO_OLED_RESET, // OLED Display Reset + AGPIO(GPIO_BACKLIGHT), // Display backlight control + AGPIO(GPIO_OLED_RESET), // OLED Display Reset #endif - GPIO_TXD, // Serial interface - GPIO_RXD, // Serial interface + AGPIO(GPIO_TXD), // Serial interface + AGPIO(GPIO_RXD), // Serial interface #ifdef USE_DHT - GPIO_DHT11, // DHT11 - GPIO_DHT22, // DHT21, DHT22, AM2301, AM2302, AM2321 - GPIO_SI7021, // iTead SI7021 - GPIO_DHT11_OUT, // Pseudo Single wire DHT11, DHT21, DHT22, AM2301, AM2302, AM2321 + AGPIO(GPIO_DHT11), // DHT11 + AGPIO(GPIO_DHT22), // DHT21, DHT22, AM2301, AM2302, AM2321 + AGPIO(GPIO_SI7021), // iTead SI7021 + AGPIO(GPIO_DHT11_OUT), // Pseudo Single wire DHT11, DHT21, DHT22, AM2301, AM2302, AM2321 #endif #ifdef USE_DS18x20 - GPIO_DSB, // Single wire DS18B20 or DS18S20 - GPIO_DSB_OUT, // Pseudo Single wire DS18B20 or DS18S20 + AGPIO(GPIO_DSB), // Single wire DS18B20 or DS18S20 + AGPIO(GPIO_DSB_OUT), // Pseudo Single wire DS18B20 or DS18S20 #endif // Light #ifdef USE_LIGHT #ifdef USE_WS2812 - GPIO_WS2812, // WS2812 Led string + AGPIO(GPIO_WS2812), // WS2812 Led string #endif #ifdef USE_ARILUX_RF - GPIO_ARIRFRCV, // AriLux RF Receive input - GPIO_ARIRFSEL, // Arilux RF Receive input selected + AGPIO(GPIO_ARIRFRCV), // AriLux RF Receive input + AGPIO(GPIO_ARIRFSEL), // Arilux RF Receive input selected #endif #ifdef USE_MY92X1 - GPIO_DI, // my92x1 PWM input - GPIO_DCKI, // my92x1 CLK input + AGPIO(GPIO_DI), // my92x1 PWM input + AGPIO(GPIO_DCKI), // my92x1 CLK input #endif // USE_MY92X1 #ifdef USE_SM16716 - GPIO_SM16716_CLK, // SM16716 CLOCK - GPIO_SM16716_DAT, // SM16716 DATA - GPIO_SM16716_SEL, // SM16716 SELECT + AGPIO(GPIO_SM16716_CLK), // SM16716 CLOCK + AGPIO(GPIO_SM16716_DAT), // SM16716 DATA + AGPIO(GPIO_SM16716_SEL), // SM16716 SELECT #endif // USE_SM16716 #ifdef USE_SM2135 - GPIO_SM2135_CLK, // SM2135 CLOCK - GPIO_SM2135_DAT, // SM2135 DATA + AGPIO(GPIO_SM2135_CLK), // SM2135 CLOCK + AGPIO(GPIO_SM2135_DAT), // SM2135 DATA #endif // USE_SM2135 #ifdef USE_TUYA_MCU - GPIO_TUYA_TX, // Tuya Serial interface - GPIO_TUYA_RX, // Tuya Serial interface + AGPIO(GPIO_TUYA_TX), // Tuya Serial interface + AGPIO(GPIO_TUYA_RX), // Tuya Serial interface #endif #ifdef USE_EXS_DIMMER - GPIO_EXS_ENABLE, // EXS MCU Enable + AGPIO(GPIO_EXS_ENABLE), // EXS MCU Enable #endif #ifdef USE_ELECTRIQ_MOODL - GPIO_ELECTRIQ_MOODL_TX, + AGPIO(GPIO_ELECTRIQ_MOODL_TX), #endif #endif // USE_LIGHT #if defined(USE_IR_REMOTE) || defined(USE_IR_REMOTE_FULL) - GPIO_IRSEND, // IR remote + AGPIO(GPIO_IRSEND), // IR remote #if defined(USE_IR_RECEIVE) || defined(USE_IR_REMOTE_FULL) - GPIO_IRRECV, // IR receiver + AGPIO(GPIO_IRRECV), // IR receiver #endif #endif #ifdef USE_RC_SWITCH - GPIO_RFSEND, // RF transmitter - GPIO_RFRECV, // RF receiver + AGPIO(GPIO_RFSEND), // RF transmitter + AGPIO(GPIO_RFRECV), // RF receiver #endif #ifdef USE_RF_SENSOR - GPIO_RF_SENSOR, // Rf receiver with sensor decoding + AGPIO(GPIO_RF_SENSOR), // Rf receiver with sensor decoding #endif #ifdef USE_SR04 - GPIO_SR04_TRIG, // SR04 Tri/TXgger pin - GPIO_SR04_ECHO, // SR04 Ech/RXo pin + AGPIO(GPIO_SR04_TRIG), // SR04 Tri/TXgger pin + AGPIO(GPIO_SR04_ECHO), // SR04 Ech/RXo pin #endif #ifdef USE_TM1638 - GPIO_TM16CLK, // TM1638 Clock - GPIO_TM16DIO, // TM1638 Data I/O - GPIO_TM16STB, // TM1638 Strobe + AGPIO(GPIO_TM16CLK), // TM1638 Clock + AGPIO(GPIO_TM16DIO), // TM1638 Data I/O + AGPIO(GPIO_TM16STB), // TM1638 Strobe #endif #ifdef USE_HX711 - GPIO_HX711_SCK, // HX711 Load Cell clock - GPIO_HX711_DAT, // HX711 Load Cell data + AGPIO(GPIO_HX711_SCK), // HX711 Load Cell clock + AGPIO(GPIO_HX711_DAT), // HX711 Load Cell data #endif // Energy sensors #ifdef USE_ENERGY_SENSOR #ifdef USE_HLW8012 - GPIO_NRG_SEL, // HLW8012/HLJ-01 Sel output (1 = Voltage) - GPIO_NRG_SEL_INV, // HLW8012/HLJ-01 Sel output (0 = Voltage) - GPIO_NRG_CF1, // HLW8012/HLJ-01 CF1 voltage / current - GPIO_HLW_CF, // HLW8012 CF power - GPIO_HJL_CF, // HJL-01/BL0937 CF power + AGPIO(GPIO_NRG_SEL), // HLW8012/HLJ-01 Sel output (1 = Voltage) + AGPIO(GPIO_NRG_SEL_INV), // HLW8012/HLJ-01 Sel output (0 = Voltage) + AGPIO(GPIO_NRG_CF1), // HLW8012/HLJ-01 CF1 voltage / current + AGPIO(GPIO_HLW_CF), // HLW8012 CF power + AGPIO(GPIO_HJL_CF), // HJL-01/BL0937 CF power #endif #if defined(USE_I2C) && defined(USE_ADE7953) - GPIO_ADE7953_IRQ, // ADE7953 IRQ + AGPIO(GPIO_ADE7953_IRQ), // ADE7953 IRQ #endif #ifdef USE_CSE7766 - GPIO_CSE7766_TX, // CSE7766 Serial interface (S31 and Pow R2) - GPIO_CSE7766_RX, // CSE7766 Serial interface (S31 and Pow R2) + AGPIO(GPIO_CSE7766_TX), // CSE7766 Serial interface (S31 and Pow R2) + AGPIO(GPIO_CSE7766_RX), // CSE7766 Serial interface (S31 and Pow R2) #endif #ifdef USE_MCP39F501 - GPIO_MCP39F5_TX, // MCP39F501 Serial interface (Shelly2) - GPIO_MCP39F5_RX, // MCP39F501 Serial interface (Shelly2) - GPIO_MCP39F5_RST, // MCP39F501 Reset (Shelly2) + AGPIO(GPIO_MCP39F5_TX), // MCP39F501 Serial interface (Shelly2) + AGPIO(GPIO_MCP39F5_RX), // MCP39F501 Serial interface (Shelly2) + AGPIO(GPIO_MCP39F5_RST), // MCP39F501 Reset (Shelly2) #endif #if defined(USE_PZEM004T) || defined(USE_PZEM_AC) || defined(USE_PZEM_DC) - GPIO_PZEM0XX_TX, // PZEM0XX Serial interface + AGPIO(GPIO_PZEM0XX_TX), // PZEM0XX Serial interface #endif #ifdef USE_PZEM004T - GPIO_PZEM004_RX, // PZEM004T Serial interface + AGPIO(GPIO_PZEM004_RX), // PZEM004T Serial interface #endif #ifdef USE_PZEM_AC - GPIO_PZEM016_RX, // PZEM-014,016 Serial Modbus interface + AGPIO(GPIO_PZEM016_RX), // PZEM-014,016 Serial Modbus interface #endif #ifdef USE_PZEM_DC - GPIO_PZEM017_RX, // PZEM-003,017 Serial Modbus interface + AGPIO(GPIO_PZEM017_RX), // PZEM-003,017 Serial Modbus interface #endif #ifdef USE_SDM120 - GPIO_SDM120_TX, // SDM120 Serial interface - GPIO_SDM120_RX, // SDM120 Serial interface + AGPIO(GPIO_SDM120_TX), // SDM120 Serial interface + AGPIO(GPIO_SDM120_RX), // SDM120 Serial interface #endif #ifdef USE_SDM630 - GPIO_SDM630_TX, // SDM630 Serial interface - GPIO_SDM630_RX, // SDM630 Serial interface + AGPIO(GPIO_SDM630_TX), // SDM630 Serial interface + AGPIO(GPIO_SDM630_RX), // SDM630 Serial interface #endif #ifdef USE_DDS2382 - GPIO_DDS2382_TX, // DDS2382 Serial interface - GPIO_DDS2382_RX, // DDS2382 Serial interface + AGPIO(GPIO_DDS2382_TX), // DDS2382 Serial interface + AGPIO(GPIO_DDS2382_RX), // DDS2382 Serial interface #endif #ifdef USE_DDSU666 - GPIO_DDSU666_TX, // DDSU666 Serial interface - GPIO_DDSU666_RX, // DDSU666 Serial interface + AGPIO(GPIO_DDSU666_TX), // DDSU666 Serial interface + AGPIO(GPIO_DDSU666_RX), // DDSU666 Serial interface #endif // USE_DDSU666 #ifdef USE_SOLAX_X1 - GPIO_SOLAXX1_TX, // Solax Inverter tx pin - GPIO_SOLAXX1_RX, // Solax Inverter rx pin + AGPIO(GPIO_SOLAXX1_TX), // Solax Inverter tx pin + AGPIO(GPIO_SOLAXX1_RX), // Solax Inverter rx pin #endif // USE_SOLAX_X1 #ifdef USE_LE01MR - GPIO_LE01MR_RX, // F7F LE-01MR energy meter rx pin - GPIO_LE01MR_TX, // F7F LE-01MR energy meter tx pin + AGPIO(GPIO_LE01MR_RX), // F7F LE-01MR energy meter rx pin + AGPIO(GPIO_LE01MR_TX), // F7F LE-01MR energy meter tx pin #endif // IFDEF:USE_LE01MR #endif // USE_ENERGY_SENSOR // Serial #ifdef USE_SERIAL_BRIDGE - GPIO_SBR_TX, // Serial Bridge Serial interface - GPIO_SBR_RX, // Serial Bridge Serial interface + AGPIO(GPIO_SBR_TX), // Serial Bridge Serial interface + AGPIO(GPIO_SBR_RX), // Serial Bridge Serial interface #endif #ifdef USE_ZIGBEE - GPIO_ZIGBEE_TX, // Zigbee Serial interface - GPIO_ZIGBEE_RX, // Zigbee Serial interface + AGPIO(GPIO_ZIGBEE_TX), // Zigbee Serial interface + AGPIO(GPIO_ZIGBEE_RX), // Zigbee Serial interface #endif #ifdef USE_MHZ19 - GPIO_MHZ_TXD, // MH-Z19 Serial interface - GPIO_MHZ_RXD, // MH-Z19 Serial interface + AGPIO(GPIO_MHZ_TXD), // MH-Z19 Serial interface + AGPIO(GPIO_MHZ_RXD), // MH-Z19 Serial interface #endif #ifdef USE_SENSEAIR - GPIO_SAIR_TX, // SenseAir Serial interface - GPIO_SAIR_RX, // SenseAir Serial interface + AGPIO(GPIO_SAIR_TX), // SenseAir Serial interface + AGPIO(GPIO_SAIR_RX), // SenseAir Serial interface #endif #ifdef USE_NOVA_SDS - GPIO_SDS0X1_TX, // Nova Fitness SDS011 Serial interface - GPIO_SDS0X1_RX, // Nova Fitness SDS011 Serial interface + AGPIO(GPIO_SDS0X1_TX), // Nova Fitness SDS011 Serial interface + AGPIO(GPIO_SDS0X1_RX), // Nova Fitness SDS011 Serial interface #endif #ifdef USE_HPMA - GPIO_HPMA_TX, // Honeywell HPMA115S0 Serial interface - GPIO_HPMA_RX, // Honeywell HPMA115S0 Serial interface + AGPIO(GPIO_HPMA_TX), // Honeywell HPMA115S0 Serial interface + AGPIO(GPIO_HPMA_RX), // Honeywell HPMA115S0 Serial interface #endif #ifdef USE_PMS5003 - GPIO_PMS5003_TX, // Plantower PMS5003 Serial interface - GPIO_PMS5003_RX, // Plantower PMS5003 Serial interface + AGPIO(GPIO_PMS5003_TX), // Plantower PMS5003 Serial interface + AGPIO(GPIO_PMS5003_RX), // Plantower PMS5003 Serial interface #endif #if defined(USE_TX20_WIND_SENSOR) || defined(USE_TX23_WIND_SENSOR) - GPIO_TX2X_TXD_BLACK, // TX20/TX23 Transmission Pin + AGPIO(GPIO_TX2X_TXD_BLACK), // TX20/TX23 Transmission Pin #endif #ifdef USE_MP3_PLAYER - GPIO_MP3_DFR562, // RB-DFR-562, DFPlayer Mini MP3 Player Serial interface + AGPIO(GPIO_MP3_DFR562), // RB-DFR-562, DFPlayer Mini MP3 Player Serial interface #endif #ifdef USE_AZ7798 - GPIO_AZ_TXD, // AZ-Instrument 7798 CO2 datalogger Serial interface - GPIO_AZ_RXD, // AZ-Instrument 7798 CO2 datalogger Serial interface + AGPIO(GPIO_AZ_TXD), // AZ-Instrument 7798 CO2 datalogger Serial interface + AGPIO(GPIO_AZ_RXD), // AZ-Instrument 7798 CO2 datalogger Serial interface #endif #ifdef USE_PN532_HSU - GPIO_PN532_TXD, // PN532 HSU Tx - GPIO_PN532_RXD, // PN532 HSU Rx + AGPIO(GPIO_PN532_TXD), // PN532 HSU Tx + AGPIO(GPIO_PN532_RXD), // PN532 HSU Rx #endif #ifdef USE_TASMOTA_SLAVE - GPIO_TASMOTASLAVE_TXD, // Tasmota Slave TX - GPIO_TASMOTASLAVE_RXD, // Tasmota Slave RX - GPIO_TASMOTASLAVE_RST, // Tasmota Slave Reset - GPIO_TASMOTASLAVE_RST_INV, // Tasmota Slave Reset Inverted + AGPIO(GPIO_TASMOTASLAVE_TXD), // Tasmota Slave TX + AGPIO(GPIO_TASMOTASLAVE_RXD), // Tasmota Slave RX + AGPIO(GPIO_TASMOTASLAVE_RST), // Tasmota Slave Reset + AGPIO(GPIO_TASMOTASLAVE_RST_INV), // Tasmota Slave Reset Inverted #endif #ifdef USE_RDM6300 - GPIO_RDM6300_RX, + AGPIO(GPIO_RDM6300_RX), #endif #ifdef USE_IBEACON - GPIO_IBEACON_RX, - GPIO_IBEACON_TX, + AGPIO(GPIO_IBEACON_RX), + AGPIO(GPIO_IBEACON_TX), #endif #ifdef USE_GPS - GPIO_GPS_RX, // GPS serial interface - GPIO_GPS_TX, // GPS serial interface + AGPIO(GPIO_GPS_RX), // GPS serial interface + AGPIO(GPIO_GPS_TX), // GPS serial interface #endif #ifdef USE_HM10 - GPIO_HM10_RX, // GPS serial interface - GPIO_HM10_TX, // GPS serial interface + AGPIO(GPIO_HM10_RX), // GPS serial interface + AGPIO(GPIO_HM10_TX), // GPS serial interface #endif #ifdef USE_MGC3130 - GPIO_MGC3130_XFER, - GPIO_MGC3130_RESET, + AGPIO(GPIO_MGC3130_XFER), + AGPIO(GPIO_MGC3130_RESET), #endif #ifdef USE_MAX31855 - GPIO_MAX31855CS, // MAX31855 Serial interface - GPIO_MAX31855CLK, // MAX31855 Serial interface - GPIO_MAX31855DO, // MAX31855 Serial interface + AGPIO(GPIO_MAX31855CS), // MAX31855 Serial interface + AGPIO(GPIO_MAX31855CLK), // MAX31855 Serial interface + AGPIO(GPIO_MAX31855DO), // MAX31855 Serial interface #endif #ifdef ROTARY_V1 - GPIO_ROT1A, // Rotary switch1 A Pin - GPIO_ROT1B, // Rotary switch1 B Pin - GPIO_ROT2A, // Rotary switch2 A Pin - GPIO_ROT2B, // Rotary switch2 B Pin + AGPIO(GPIO_ROT1A), // Rotary switch1 A Pin + AGPIO(GPIO_ROT1B), // Rotary switch1 B Pin + AGPIO(GPIO_ROT2A), // Rotary switch2 A Pin + AGPIO(GPIO_ROT2B), // Rotary switch2 B Pin #endif #ifdef USE_HRE - GPIO_HRE_CLOCK, - GPIO_HRE_DATA, + AGPIO(GPIO_HRE_CLOCK), + AGPIO(GPIO_HRE_DATA), #endif #ifdef USE_A4988_STEPPER - GPIO_A4988_DIR, // A4988 direction pin - GPIO_A4988_STP, // A4988 step pin + AGPIO(GPIO_A4988_DIR), // A4988 direction pin + AGPIO(GPIO_A4988_STP), // A4988 step pin // folowing are not mandatory - GPIO_A4988_ENA, // A4988 enabled pin - GPIO_A4988_MS1, // A4988 microstep pin1 - GPIO_A4988_MS2, // A4988 microstep pin2 - GPIO_A4988_MS3, // A4988 microstep pin3 + AGPIO(GPIO_A4988_ENA), // A4988 enabled pin + AGPIO(GPIO_A4988_MS1), // A4988 microstep pin1 + AGPIO(GPIO_A4988_MS2), // A4988 microstep pin2 + AGPIO(GPIO_A4988_MS3), // A4988 microstep pin3 #endif #ifdef USE_DEEPSLEEP - GPIO_DEEPSLEEP, + AGPIO(GPIO_DEEPSLEEP), #endif #ifdef USE_KEELOQ - GPIO_CC1101_GDO0, // CC1101 pin for RX - GPIO_CC1101_GDO2, // CC1101 pin for RX + AGPIO(GPIO_CC1101_GDO0), // CC1101 pin for RX + AGPIO(GPIO_CC1101_GDO2), // CC1101 pin for RX #endif #ifdef USE_HRXL - GPIO_HRXL_RX, + AGPIO(GPIO_HRXL_RX), #endif #ifdef USE_AS3935 - GPIO_AS3935, + AGPIO(GPIO_AS3935), #endif /* ADC0_INPUT, // Analog input diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index a4f43b6c6..beeaa31a3 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -231,12 +231,46 @@ const char HTTP_MODULE_TEMPLATE_REPLACE[] PROGMEM = "}2%d'>%s (%d}3"; // }2 and }3 are used in below os.replace const char HTTP_SCRIPT_MODULE_TEMPLATE[] PROGMEM = +#ifdef ESP8266 "var os;" "function sk(s,g){" // s = value, g = id and name "var o=os.replace(/}2/g,\"