-
Notifications
You must be signed in to change notification settings - Fork 8.2k
[TOPIC-GPIO] boards: nrf52840_pca10090: Convert to use the new GPIO API #20184
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
[TOPIC-GPIO] boards: nrf52840_pca10090: Convert to use the new GPIO API #20184
Conversation
Update the code configuring pins that control the routing of certain lines on the board, to take advantage of the introduced possibility of configuring a pin as output with specified initial state. Additionally, use `gpio_pin_get_raw` instead of `gpio_pin_get` for checking the reset pin state, to save a few bytes in flash. Signed-off-by: Andrzej Głąbek <[email protected]>
d3f490f to
7c9482e
Compare
| err = gpio_pin_configure(port, cfg[i].pin, GPIO_OUTPUT); | ||
| u32_t flag = (cfg[i].val ? GPIO_OUTPUT_LOW | ||
| : GPIO_OUTPUT_HIGH); | ||
| err = gpio_pin_configure(port, cfg[i].pin, flag); |
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.
So this new API will configure the pin as output and also set its state to low/high?
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.
Yes, that's what those flags do. Unfortunately there aren't OUTPUT_INIT_ACTIVE and OUTPUT_INIT_INACTIVE.
Since the pins are documented as being active low, and the new API supports operating on logical level, I think it would be more clear to have this be:
unsigned int flags = GPIO_ACTIVE_LOW;
if (cfg[i].pin) {
flags |= GPIO_OUTPUT_LOW;
} else {
flags |= GPIO_OUTPUT_HIGH;
}
err = gpio_pin_configure(port, cfg[i].pin, flags);
then...
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 the pins are documented as being active low
Well, in fact these pins are not documented as being active low. The DK documentation says only about the default destination and the optional destination, activated when a given pin is set as output and driven low or high, respectively. These pins are described as having active-low logic only in the comment before definitions of pins_on_p0 and pins_on_p1 tables (and I left that comment as it was, treating it as to be considered in the context of these tables only; should I change it?). They were also mentioned as being active low in the comment that I reworded, and I intentionally got rid of this "are active low" statement.
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.
OK then.
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 comment is still in the code, which is part of why I asked for the change:
* The switches have active-low logic, so when writing to the port we will
* need to invert the value to match the IS_ENABLED() logic.
However that's clear enough, so I'm ok with using the negative logic physical value.
| err = gpio_pin_configure(port, cfg[i].pin, GPIO_OUTPUT); | ||
| u32_t flag = (cfg[i].val ? GPIO_OUTPUT_LOW | ||
| : GPIO_OUTPUT_HIGH); | ||
| err = gpio_pin_configure(port, cfg[i].pin, flag); |
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.
Yes, that's what those flags do. Unfortunately there aren't OUTPUT_INIT_ACTIVE and OUTPUT_INIT_INACTIVE.
Since the pins are documented as being active low, and the new API supports operating on logical level, I think it would be more clear to have this be:
unsigned int flags = GPIO_ACTIVE_LOW;
if (cfg[i].pin) {
flags |= GPIO_OUTPUT_LOW;
} else {
flags |= GPIO_OUTPUT_HIGH;
}
err = gpio_pin_configure(port, cfg[i].pin, flags);
then...
| int val; | ||
|
|
||
| /* Wait until the pin is pulled low */ | ||
| do { |
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.
... here do:
/* Wait until pin becomes active */
while (gpio_pin_get(port, pin) == 0) {
}
Other boards might include pins that are active-high, and using the logic level rather than physical level would make the code more consistent.
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.
I now see the original comment about using _raw to save a few bytes of flash. I prefer clarity of using normal logic, but if I'm alone in that I won't insist.
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.
Other boards might include pins that are active-high, and using the logic level rather than physical level would make the code more consistent.
This reset pin here is in fact active high. And the above loop waits until it becomes inactive. As the accompanying comment says, this "lets the other side ensure that they are ready".
I'd prefer to left it as it is.
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.
Clearly I don't understand what this is doing well enough to assess it. We'll see if github allows me to remove my approval. edit: nope.
|
Thank you for cleaning this up. |
mnkp
left a comment
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.
@anangl Thanks! I overlooked this part when doing board conversion.
Update the code configuring pins that control the routing of certain
lines on the board, to take advantage of the introduced possibility
of configuring a pin as output with specified initial state.
Additionally, use
gpio_pin_get_rawinstead ofgpio_pin_getforchecking the reset pin state, to save a few bytes in flash.
Signed-off-by: Andrzej Głąbek [email protected]