Skip to content

Commit 8d3db86

Browse files
gWaceykoffes
authored andcommitted
applications: Ensure button names are printed in a standard manner
Assign the button names dependent on the GPIO pin, so as to match the button correctly to it's name across multiple boards. Signed-off-by: Graham Wacey <[email protected]>
1 parent 17d21fe commit 8d3db86

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

applications/nrf5340_audio/src/modules/button_assignments.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@
2929
#define BUTTON_VOLUME_DOWN DT_GPIO_PIN(DT_ALIAS(sw0), gpios)
3030
#else
3131
#define BUTTON_VOLUME_DOWN BUTTON_NOT_ASSIGNED
32-
3332
#endif
3433

3534
#if DT_NODE_EXISTS(DT_ALIAS(sw1))
3635
#define BUTTON_VOLUME_UP DT_GPIO_PIN(DT_ALIAS(sw1), gpios)
3736
#else
3837
#define BUTTON_VOLUME_UP BUTTON_NOT_ASSIGNED
39-
4038
#endif
4139

4240
#if DT_NODE_EXISTS(DT_ALIAS(sw2))

applications/nrf5340_audio/src/modules/button_handler.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,19 @@ static bool debounce_is_ongoing;
5050
#pragma error("No buttons node found")
5151
#endif
5252

53+
#define BUTTON_NAME(b) \
54+
((b) == BUTTON_VOLUME_DOWN ? "BUTTON_VOLUME_DOWN" \
55+
: (b) == BUTTON_VOLUME_UP ? "BUTTON_VOLUME_UP" \
56+
: (b) == BUTTON_PLAY_PAUSE ? "BUTTON_PLAY_PAUSE" \
57+
: (b) == BUTTON_4 ? "BUTTON_4" \
58+
: (b) == BUTTON_5 ? "BUTTON_5" \
59+
: NULL)
60+
5361
#define BUTTON_GPIO(button_node_id) \
5462
{ \
55-
.name = STRINGIFY(BUTTON_##button_node_id), \
56-
.gpio = GPIO_DT_SPEC_GET(button_node_id, gpios), \
57-
},
63+
.name = BUTTON_NAME(DT_GPIO_PIN(button_node_id, gpios)), \
64+
.gpio = GPIO_DT_SPEC_GET(button_node_id, gpios), \
65+
},
5866

5967
static struct btn_cfg_data btn_config_data[] = {DT_FOREACH_CHILD(BUTTON, BUTTON_GPIO)};
6068

0 commit comments

Comments
 (0)