Skip to content

Fix for Broken Arduino libraries due to implementaion of commonly used GPIO constants, issue #98 #99

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

Merged
merged 2 commits into from
Dec 23, 2019

Conversation

frinkahedron
Copy link
Contributor

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:

  1. 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.

  2. 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.

  3. 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.

@jgromes
Copy link

jgromes commented Dec 22, 2019

Hi, any chance this could be added? The pin mode issue really does break a lot of Arduino libraries (including mine :P).

It's a shame Arduino core has no specific pin state type, but I'm afraid that design decision has been made way too long ago to do anything about it now...

@oclyke oclyke self-requested a review December 23, 2019 17:08
@oclyke
Copy link
Contributor

oclyke commented Dec 23, 2019

I apologize - I had some WIP response that must have gotten lost.

  1. I agree with you judgement since it is already done that way in other locations in the core. We will just have to cross the bridge whenever (if ever) the implementation of the HAL changes.

  2. Agreed

  3. Thanks - with this project we've generally wanted to try a concept of only the comments that are necessary to explain a general concept with details from commits serving as additional resources. So what you've done is perfect!

Thanks for helping make the core better!

@oclyke oclyke merged commit d50bdcf into sparkfun:master Dec 23, 2019
@jgromes
Copy link

jgromes commented Dec 23, 2019

@oclyke Perfect! Any chance we could get a release to update the boards manager? Thanks, and have a great Christmas!

@oclyke
Copy link
Contributor

oclyke commented Dec 23, 2019

@jgromes Yes you may! I'm also including some addtl. improvements to the SVL bootloader. Speed and reliability are both increased thanks to Nate Seidle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants