Open S5NC opened 5 months ago
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)
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 thanNUM_ANALOG_INPUTS
which is 20. If I pass 19, which is an ADC pin, intoanalogInputToDigitalPin(p)
it would return 20.
Maybe you are using the function wrongly - on esp32, analogInputToDigitalPin(p)
is meant to convert "ADC channels" to GPIO pin numbers.
ESP32-S3 has 2 ADC units with 10 channels, i.e.
I think the macro works correctly with your examples.
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 thanNUM_ANALOG_INPUTS
which is 20. If I pass 19, which is an ADC pin, intoanalogInputToDigitalPin(p)
it would return 20.Maybe you are using the function wrongly - on esp32,
analogInputToDigitalPin(p)
is meant to convert "ADC channels" to GPIO pin numbers.ESP32-S3 has 2 ADC units with 10 channels, i.e.
* ADC1: channel 0...9 * ADC2: channel 10..19
I think the macro works correctly with your examples.
* channel 20 => not existing => -1 * channel 19 => ADC2_9 => gpio 20
You are right, I thought an analog input meant an analog-capable pin but it refers to the analog channel.
What do you think about digitalPinCheck
?
ESP32
pins_arduino.h
definition, tested on ESP32-S3 Dev Module on Arduino IDEThe macro here checks if the pin are less than a number.
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 thanNUM_ANALOG_INPUTS
which is 20. If I pass 19, which is an ADC pin, intoanalogInputToDigitalPin(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