-
Notifications
You must be signed in to change notification settings - Fork 13.3k
digitalWrite cleanup and more compliant with behavior on AVR #530
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
Conversation
I rewrote digitalWrite because the existing version was breaking functionality as compared to how it behaves on the AVR,. specifically, I could not use digitalWrite for a library that works fine on the AVR. Instead I had to resort to fiddling with GPOC and GPOS and bit masks, but this rewrite made all of that unnecessary, for whatever reason, it just works better. This version borrows a little from the AVR library in the sense that the same logic is applied to determine whether a pin should be high or low as the AVR version, and yes, it does appear to make a difference.
The diff appears to miss an
|
Could you please point to the library which caused issues? As far as I can tell, the difference between old and new code is that if someone calls digitalWrite with an even non-zero value argument (like 2 or 4), old code would interpret that as 0, hence output would be low, and in new version we will go into else branch and set output high. Arduino documentation doesn't specify what should happen when digitalWrite is passed value which is not LOW or HIGH, so i think the library you had trouble with makes some assumptions and passes some other integers into digitalWrite. |
If that is the case, the fix should be as simple as removing this line: val &= 0x01; |
Ugh, I don't know how that happened.
I'm sorry, I somehow managed to paste a broken function in, I could have sworn it was complete when I copied it from one file to another. I've corrected it. |
Could you please also try the original version with this line removed: |
I'm happy to report that you're correct, sorry if I got a little overzealous. I've altered my pull request to reflect this, thanks. |
I rewrote digitalWrite because the existing version was breaking
functionality as compared to how it behaves on the AVR.
Specifically, I could not use digitalWrite for a library that works fine on the AVR.
Instead I had to resort to fiddling with GPOC and GPOS and bit masks,
but this rewrite made all of that unnecessary, for whatever reason it
just works better.
This version borrows a little from the AVR library in the sense that the
same logic is applied to determine whether a pin should be high or low
as the AVR version, and yes, it does appear to make a difference, at least as far as my testing on hardware has shown.