-
Notifications
You must be signed in to change notification settings - Fork 30
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
Control digitalPin status using bits of a uint32_t #61
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I left you some minor logic error fixes and improvements.
But the more important question is: Why do you want this functionality? Because in a real microcontroller, a digitalWrite()
to a specific pin does not affect the value of the digitalRead()
on that pin. They are completely decoupled from each other. I'm not sure that EpoxyDuino should add a semantic coupling between those 2 functions that doesn't exist in real life.
cores/epoxy/Arduino.cpp
Outdated
void digitalWrite(uint8_t /*pin*/, uint8_t /*val*/) {} | ||
void digitalWrite(uint8_t pin, uint8_t val) { | ||
if( val == HIGH ){ | ||
arduinoPins |= ( 1LU << ( pin - 1 ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pin == 0 is a valid pin, so all the pin - 1
should be just pin
cores/epoxy/Arduino.cpp
Outdated
arduinoPins |= ( 1LU << ( pin - 1 ) ); | ||
} | ||
if( ( val == LOW ) && ( digitalRead( pin ) ) ){ | ||
arduinoPins ^= ( 1LU << ( pin - 1 ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be
arduinoPins &= ~(1LU << pin);
cores/epoxy/Arduino.cpp
Outdated
} | ||
|
||
int digitalRead(uint8_t pin) { | ||
return ( arduinoPins & ( 1LU << ( pin - 1 ) ) ) == ( 1LU << ( pin - 1 ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are testing for only a single bit, we can simplify this to:
return (arduinoPins & (1LU << pin) != 0;
This generates fewer machine instructions because it doesn't have to test against an extra argument.
Hello, |
I can see the convenience of being able to set the value returned by How about we create a new method, call it something like #if defined(EPOXY_DUINO)
digitalReadValue(xxx, yyy);
#endif But if the code is meant to run only on EpoxyDuino, then the conditional guard can be omitted. If this is agreeable to you, then I would like to make some commits to your branch to polish the PR for inclusion: fix bugs, add error checks, apply consistent coding style, add documentation, etc. |
Sure, I think this is a great idea! This is my first pull request, so maybe I will need some help in the process |
Normally the PR author (you) would make changes requested by the reviewer (me), and then do a |
I pushed 3 commits into your branch. Please take a quick look. If this is acceptable for you, I can merge this in this PR. |
that's great, is more than acceptable |
… instead of digitalWrite(); fix bugs (see bxparks#61)
… instead of digitalWrite(); fix bugs (see bxparks#61)
No description provided.