Skip to content

Commit

Permalink
dac_shell: add device filtering
Browse files Browse the repository at this point in the history
Add shell device name filtering using DEVICE_API_IS.

Signed-off-by: Fabio Baltieri <[email protected]>
  • Loading branch information
fabiobaltieri committed Jan 17, 2025
1 parent 3a7a885 commit 0b2a270
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions drivers/dac/dac_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,31 @@ static int cmd_write_value(const struct shell *sh, size_t argc, char **argv)
return 0;
}

static bool device_is_dac(const struct device *dev)
{
return device_is_ready(dev) && DEVICE_API_IS(dac, dev);
}

static void device_name_get(size_t idx, struct shell_static_entry *entry)
{
const struct device *dev = shell_device_filter(idx, device_is_dac);

entry->syntax = (dev != NULL) ? dev->name : NULL;
entry->handler = NULL;
entry->help = NULL;
entry->subcmd = NULL;
}

SHELL_DYNAMIC_CMD_CREATE(dsub_device_name, device_name_get);

SHELL_STATIC_SUBCMD_SET_CREATE(dac_cmds,
SHELL_CMD_ARG(setup, NULL,
SHELL_CMD_ARG(setup, &dsub_device_name,
"Setup DAC channel\n"
"Usage: setup <device> <channel> <resolution> [-b] [-i]\n"
"-b Enable output buffer\n"
"-i Connect internally",
cmd_setup, 4, 2),
SHELL_CMD_ARG(write_value, NULL,
SHELL_CMD_ARG(write_value, &dsub_device_name,
"Write DAC value\n"
"Usage: write <device> <channel> <value>",
cmd_write_value, 4, 0),
Expand Down

0 comments on commit 0b2a270

Please sign in to comment.