-
-
Notifications
You must be signed in to change notification settings - Fork 212
pinMode does not accept NC / unused pin #693
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
Comments
Hi @MarcelRobitaille , thanks for reporting this. In fact, there's no specific reason why |
As a rule of thumb, we should protect the most used APIs from misusage, even at the cost of slowing them down due to the additional check. |
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 beNC
. 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:There is also a version with
PinName
, but most arduino libraries useuint8_t
or something like that for their pin numbers, notPinName
.This definition of
pinMode
looks up the GPIO object inside ofg_APinDescription
without doing any checks that the pin is in range.The equivalent definitions of
digitalRead
anddigitalWrite
check if the pin is in range before doing anything, butpinMode
does not.I think
pinMode
should have the exact same guard asdigitalRead
anddigitalWrite
. I can open a PR for this. Is there anything I am missing as to why this is implemented this way?The text was updated successfully, but these errors were encountered: