pwm: shell: filter device lookup using DEVICE_API macros

Filter for PWM devices when looking them up in dynamic shell commands.

Signed-off-by: Yishai Jaffe <yishai1999@gmail.com>
This commit is contained in:
Yishai Jaffe 2024-12-01 17:59:08 +02:00 committed by Benjamin Cabé
parent e5017da2b0
commit 3775e197e6

View File

@ -126,12 +126,29 @@ static int cmd_nsec(const struct shell *sh, size_t argc, char **argv)
return 0;
}
static bool device_is_pwm_and_ready(const struct device *dev)
{
return device_is_ready(dev) && DEVICE_API_IS(pwm, dev);
}
static void device_name_get(size_t idx, struct shell_static_entry *entry)
{
const struct device *dev = shell_device_filter(idx, device_is_pwm_and_ready);
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(pwm_cmds,
SHELL_CMD_ARG(cycles, NULL, "<device> <channel> <period in cycles> "
SHELL_CMD_ARG(cycles, &dsub_device_name, "<device> <channel> <period in cycles> "
"<pulse width in cycles> [flags]", cmd_cycles, 5, 1),
SHELL_CMD_ARG(usec, NULL, "<device> <channel> <period in usec> "
SHELL_CMD_ARG(usec, &dsub_device_name, "<device> <channel> <period in usec> "
"<pulse width in usec> [flags]", cmd_usec, 5, 1),
SHELL_CMD_ARG(nsec, NULL, "<device> <channel> <period in nsec> "
SHELL_CMD_ARG(nsec, &dsub_device_name, "<device> <channel> <period in nsec> "
"<pulse width in nsec> [flags]", cmd_nsec, 5, 1),
SHELL_SUBCMD_SET_END
);