Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 pin checking macro contraints error #9505

Open
S5NC opened this issue Apr 14, 2024 · 1 comment
Open

ESP32 pin checking macro contraints error #9505

S5NC opened this issue Apr 14, 2024 · 1 comment
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@S5NC
Copy link

S5NC commented Apr 14, 2024

ESP32 pins_arduino.h definition, tested on ESP32-S3 Dev Module on Arduino IDE

The macro here checks if the pin are less than a number.

#define analogInputToDigitalPin(p)  (((p)<NUM_ANALOG_INPUTS)?(analogChannelToDigitalPin(p)):-1)
#define digitalPinToInterrupt(p)    ((((uint8_t)digitalPinToGPIONumber(p))<NUM_DIGITAL_PINS)?digitalPinToGPIONumber(p):NOT_AN_INTERRUPT)
#define digitalPinHasPWM(p)         (((uint8_t)digitalPinToGPIONumber(p))<NUM_DIGITAL_PINS)

If I pass 20, which is an ADC pin, into analogInputToDigitalPin(p) it would return -1 due to the first check as 20 is not less than NUM_ANALOG_INPUTS which is 20.
If I pass 19, which is an ADC pin, into analogInputToDigitalPin(p) it would return 20.

This is unlike digitalPinToInterrupt, which returns the same pin number.

There is also no check that the value is greater or equal to 0

These functions assume that all pins with the same type of functions are all sequentially located.

I don't see GPIO 20 referred to as pin 19 in this table
image

@S5NC S5NC added the Status: Awaiting triage Issue is waiting for triage label Apr 14, 2024
@S5NC
Copy link
Author

S5NC commented Apr 14, 2024

The check for a valid GPIO pin for the ESP32-S3, which means any GPIO pin, should be

#define digitalPinCheck(p) ((0 <= p <= 21 || 26 <= p <= 48) ? (p) : -1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

No branches or pull requests

1 participant