Skip to content

Commit 3d24b8b

Browse files
fabiobaltiericarlescufi
authored andcommitted
gpio: shell: use the first nodelabel when available
Use the first nodelabel rather than the node name when available for shell completion as well as "gpio info". This label is always set gpio nodes as that's what's used for references by device nodes, there may be some case where a node has multiple labels for some reason but for a human I reckon it still makes more sense to suggest a label rather than the address. This means that the commands would use, for example "gpioa" rather than "gpio@58020000". Fall back to the normal node name if there's no label set or if dt metadata is not enabled. Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
1 parent 70efa2b commit 3d24b8b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

drivers/gpio/gpio_shell.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,14 +472,28 @@ static int cmd_gpio_blink(const struct shell *sh, size_t argc, char **argv)
472472
return 0;
473473
}
474474

475+
static const char *gpio_device_name(const struct device *dev)
476+
{
477+
#ifdef CONFIG_DEVICE_DT_METADATA
478+
const struct device_dt_nodelabels *nl = device_get_dt_nodelabels(dev);
479+
480+
if (nl != NULL && nl->num_nodelabels > 0) {
481+
return nl->nodelabels[0];
482+
}
483+
#endif
484+
return dev->name;
485+
}
486+
475487
static void device_name_get(size_t idx, struct shell_static_entry *entry)
476488
{
489+
const struct device *dev = gpio_list[idx].dev;
490+
477491
if (idx >= ARRAY_SIZE(gpio_list)) {
478492
entry->syntax = NULL;
479493
return;
480494
}
481495

482-
entry->syntax = gpio_list[idx].dev->name;
496+
entry->syntax = gpio_device_name(dev);
483497
entry->handler = NULL;
484498
entry->help = "Device";
485499
entry->subcmd = gpio_list[idx].subcmd;
@@ -597,7 +611,7 @@ static void pin_ordered(const struct pin_info *info, void *user_data)
597611
shell_print(data->sh, " %-12s %-8c %-16s %2u",
598612
data->next.line_name,
599613
data->next.reserved ? '*' : ' ',
600-
data->next.dev->name,
614+
gpio_device_name(data->next.dev),
601615
data->next.pin);
602616

603617
data->prev = data->next;

0 commit comments

Comments
 (0)