Skip to content

Commit 3775e19

Browse files
yishai1999kartben
authored andcommitted
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 <[email protected]>
1 parent e5017da commit 3775e19

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

drivers/pwm/pwm_shell.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,29 @@ static int cmd_nsec(const struct shell *sh, size_t argc, char **argv)
126126
return 0;
127127
}
128128

129+
static bool device_is_pwm_and_ready(const struct device *dev)
130+
{
131+
return device_is_ready(dev) && DEVICE_API_IS(pwm, dev);
132+
}
133+
134+
static void device_name_get(size_t idx, struct shell_static_entry *entry)
135+
{
136+
const struct device *dev = shell_device_filter(idx, device_is_pwm_and_ready);
137+
138+
entry->syntax = (dev != NULL) ? dev->name : NULL;
139+
entry->handler = NULL;
140+
entry->help = NULL;
141+
entry->subcmd = NULL;
142+
}
143+
144+
SHELL_DYNAMIC_CMD_CREATE(dsub_device_name, device_name_get);
145+
129146
SHELL_STATIC_SUBCMD_SET_CREATE(pwm_cmds,
130-
SHELL_CMD_ARG(cycles, NULL, "<device> <channel> <period in cycles> "
147+
SHELL_CMD_ARG(cycles, &dsub_device_name, "<device> <channel> <period in cycles> "
131148
"<pulse width in cycles> [flags]", cmd_cycles, 5, 1),
132-
SHELL_CMD_ARG(usec, NULL, "<device> <channel> <period in usec> "
149+
SHELL_CMD_ARG(usec, &dsub_device_name, "<device> <channel> <period in usec> "
133150
"<pulse width in usec> [flags]", cmd_usec, 5, 1),
134-
SHELL_CMD_ARG(nsec, NULL, "<device> <channel> <period in nsec> "
151+
SHELL_CMD_ARG(nsec, &dsub_device_name, "<device> <channel> <period in nsec> "
135152
"<pulse width in nsec> [flags]", cmd_nsec, 5, 1),
136153
SHELL_SUBCMD_SET_END
137154
);

0 commit comments

Comments
 (0)