Fix for Broken Arduino libraries due to implementaion of commonly used GPIO constants, issue #98 #99
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For your review, a potential fix for issue #98.
The changes add a new pinMode function that maps commonly used Arduino pin mode constants to internal methods using a pincfg structure and makes changes to existing defines to reflect this update.
Please Note:
In the implementation of the pinMode function I used a variable to assign the desired pin mode mapping and just called the internal function once. I did this instead of calling the function at each case (without the variable) because it seemed like it looked cleaner and may optimize better. However this assumes the am_hal_gpio_pincfg_t structure is safe to assign to a new variable (does not use pointers, etc). In this case the implementation is safe but future modifications could potentially break this if the = operator is not overloaded to account for it.
I could easily change it back to an alternate implementation that would be safer long term if you all are ok with the extra instances of functions calls in the generated code. I saw other instances in the code where assignment was being made between am_hal_gpio_pincfg_t variables so I assumed this was already factored into consideration.
In the implementation of the pinMode function when there is an invalid value passed in for the pin mode I just return and do nothing. There did not seem to be an error checking semantics in place for the original pinMode functions so it seemed safest just to do nothing.
I was trying to hold back my OCD and was pretty sparse in my comments using the existing level of detail as a guide. If a different level of detail is desired just let me know.