-
-
Notifications
You must be signed in to change notification settings - Fork 217
Description
Normally, if a library takes a pin that is not used, I would pass in -1 as the pin number. The equivalent in Mbed would be NC. However, this -1 crashes the MCU with the mbed core. (I'm not sure if crashes is the right term. My Portenta H7 is not responding and the red LED is blinking).
The reason is that libraries made for arduino use pinMode with this signature:
void pinMode(pin_size_t pin, PinMode mode)There is also a version with PinName, but most arduino libraries use uint8_t or something like that for their pin numbers, not PinName.
This definition of pinMode looks up the GPIO object inside of g_APinDescription without doing any checks that the pin is in range.
The equivalent definitions of digitalRead and digitalWrite check if the pin is in range before doing anything, but pinMode does not.
if (pin >= PINS_COUNT) {
return LOW;
} I think pinMode should have the exact same guard as digitalRead and digitalWrite. I can open a PR for this. Is there anything I am missing as to why this is implemented this way?