Change pin array names

Change pin array names to block unwanted use of direct access
This commit is contained in:
Theo Arends 2020-04-29 14:01:02 +02:00
parent c24de18278
commit d805803daa
5 changed files with 19 additions and 19 deletions

View File

@ -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);
}
}

View File

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

View File

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

View File

@ -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<GPIO_SENSOR_END;i++) { // Theo/Gemu: This needs to change when pin[] becomes real pin array
// if (pin[i]==gpiopin) {
for (uint8_t i=0;i<GPIO_SENSOR_END;i++) {
// if (pin_gpio[i]==gpiopin) {
if (Pin(i)==gpiopin) {
fvar=i;
// skip ] bracket
@ -1593,8 +1593,8 @@ chknext:
}
}
#else
if ((gpiopin < ARRAY_SIZE(pin)) && (pin[gpiopin] > 0)) {
fvar = pin[gpiopin];
if ((gpiopin < ARRAY_SIZE(gpio_pin)) && (gpio_pin[gpiopin] > 0)) {
fvar = gpio_pin[gpiopin];
// skip ] bracket
len++;
goto exit;

View File

@ -1833,13 +1833,13 @@ uint8_t *script_meter;
bool Gpio_used(uint8_t gpiopin) {
#ifdef LEGACY_GPIO_ARRAY
for (uint16_t i=0;i<GPIO_SENSOR_END;i++) { // Theo/Gemu: This needs to change when pin[] has becomes real pin array
// if (pin[i]==gpiopin) {
// if (pin_gpio[i]==gpiopin) {
if (Pin(i)==gpiopin) {
return true;
}
}
#else
if ((gpiopin < ARRAY_SIZE(pin)) && (pin[gpiopin] > 0)) {
if ((gpiopin < ARRAY_SIZE(gpio_pin)) && (gpio_pin[gpiopin] > 0)) {
return true;
}
#endif