-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
fix digitalPinToBitMask(), portOutputRegister(), portInputRegister() … #4964
Conversation
…and portModeRegister() error when the pin is GPIO16.
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.
LGTM.
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.
Mybad on the LGTM. Needs parens for safety, ternaries are very low precedence and macros are always a pain when not bracketed.
cores/esp8266/Arduino.h
Outdated
#define digitalPinToPort(pin) (0) | ||
#define digitalPinToBitMask(pin) (1UL << (pin)) | ||
#define _PORT_GPIO16 1 | ||
#define digitalPinToPort(pin) (pin==16)?(_PORT_GPIO16):(0) |
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.
Sorry, I was just about to merge this but realized that all these macros have now lost their (
..)
parenthesis. In the rest of this header all macros are completely enclosed in parens. ex #define bit
and #define _min
. The port*Register(port) macros all had them as well.
Can we bracket these ternary operators with parens, just to avoid any weirdness later on if they're used in operations and simply assigned to a value?
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.
Sorry, I fix it now.
cores/esp8266/Arduino.h
Outdated
#define digitalPinToPort(pin) (0) | ||
#define digitalPinToBitMask(pin) (1UL << (pin)) | ||
#define _PORT_GPIO16 1 | ||
#define digitalPinToPort(pin) ((pin)==16)?(_PORT_GPIO16):(0) |
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.
@earlephilhower request to surround the entire ternary is not done. This should be as follows:
(((pin)==16)?(_PORT_GPIO16):(0))
Same is valid for all new defines below.
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.
Thanks for fixing this.
fix digitalPinToBitMask(), portOutputRegister(), portInputRegister() and portModeRegister() error when the pin is GPIO16.