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] 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