-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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] samples: reel_board: mesh_badge: Convert to the new GPIO API #22137
[topic-gpio] samples: reel_board: mesh_badge: Convert to the new GPIO API #22137
Conversation
Partially tested on the reel_board. @jhedberg could you please test it a bit more to make sure I haven't missed anything? |
All checks are passing now. checkpatch (informational only, not a failure)
Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages. |
22b8877
to
f0148fc
Compare
Use the flags included in the new GPIO API to describe the properties of LEDs and buttons in the device tree source files. Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
f0148fc
to
7fd50f8
Compare
gpio_init_callback(&button_cb, button_interrupt, BIT(DT_ALIAS_SW0_GPIOS_PIN)); | ||
gpio_add_callback(gpio, &button_cb); | ||
gpio_pin_interrupt_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN, | ||
GPIO_INT_EDGE_TO_ACTIVE); |
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.
It should be GPIO_INT_EDGE_BOTH
, see the definition of EDGE
, which is no longer needed BTW.
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.
Very well spotted. Fixed.
7fd50f8
to
6c83ce2
Compare
@jfischer-phytec-iot you might be interested to take a look as well |
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.
Only required change is handling an error return from gpio_pin_get()
, which can be treated as "not pressed". Others are commentary.
@@ -67,10 +65,14 @@ static struct { | |||
struct device *dev; | |||
const char *name; | |||
u32_t pin; |
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.
gpio_pin_t
would save some space.
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.
Indeed, changed.
{ .name = DT_ALIAS_LED0_GPIOS_CONTROLLER, .pin = DT_ALIAS_LED0_GPIOS_PIN, }, | ||
{ .name = DT_ALIAS_LED1_GPIOS_CONTROLLER, .pin = DT_ALIAS_LED1_GPIOS_PIN, }, | ||
{ .name = DT_ALIAS_LED2_GPIOS_CONTROLLER, .pin = DT_ALIAS_LED2_GPIOS_PIN, }, | ||
{ .name = DT_ALIAS_LED0_GPIOS_CONTROLLER, .pin = DT_ALIAS_LED0_GPIOS_PIN, |
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.
You could just do DT_ALIAS_LED0_GPIOS
which expands to the controller name, pin, and flags in a single initializer expression. Though without a pre-defined standard structure synchronized to generation of that expression it's technically more future-proof to spelling out each element.
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.
Oh, thanks for letting me know of this DT-generated macro. As you yourself mention, since this uses designated initializers I'd rather not change it at this point.
gpio_pin_read(gpio, DT_ALIAS_SW0_GPIOS_PIN, &val); | ||
|
||
return !val; | ||
return gpio_pin_get(gpio, DT_ALIAS_SW0_GPIOS_PIN); |
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.
Note gpio_pin_get
can return a negative value to indicate a failure to read a value. There's also an essential type error here. gpio_pin_get(...) > 0
would be better.
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.
Agreed, fixed.
Convert to the new GPIO API using logical levels, and remove the duplicate implementation of LED control that existed. Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
6c83ce2
to
77ad2e8
Compare
See commit messages.