Skip to content
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

Merged
merged 5 commits into from
Jul 28, 2018

Conversation

wemos
Copy link
Contributor

@wemos wemos commented Jul 27, 2018

fix digitalPinToBitMask(), portOutputRegister(), portInputRegister() and portModeRegister() error when the pin is GPIO16.

@earlephilhower earlephilhower added this to the 2.4.2 milestone Jul 27, 2018
Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Collaborator

@earlephilhower earlephilhower left a 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.

#define digitalPinToPort(pin) (0)
#define digitalPinToBitMask(pin) (1UL << (pin))
#define _PORT_GPIO16 1
#define digitalPinToPort(pin) (pin==16)?(_PORT_GPIO16):(0)
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

#define digitalPinToPort(pin) (0)
#define digitalPinToBitMask(pin) (1UL << (pin))
#define _PORT_GPIO16 1
#define digitalPinToPort(pin) ((pin)==16)?(_PORT_GPIO16):(0)
Copy link
Collaborator

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.

Copy link
Collaborator

@earlephilhower earlephilhower left a 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.

@earlephilhower earlephilhower merged commit 7991938 into esp8266:master Jul 28, 2018
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