Skip to content

Commit fc25679

Browse files
faxe1008kartben
authored andcommitted
drivers: stepper: shell: Use shell_device_filter
Use the shell_device_filter utils method and leverage the new api classing to only suggest stepper devices via tab-complete within the shell. Signed-off-by: Fabian Blatz <[email protected]>
1 parent 02fa47f commit fc25679

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/stepper/stepper_shell.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ static void print_callback(const struct device *dev, const enum stepper_event ev
6767
}
6868
}
6969

70+
static bool stepper_device_check(const struct device *dev)
71+
{
72+
return DEVICE_API_IS(stepper, dev) && device_is_ready(dev);
73+
}
74+
7075
static const struct stepper_direction_map stepper_direction_map[] = {
7176
STEPPER_DIRECTION_MAP_ENTRY("positive", STEPPER_DIRECTION_POSITIVE),
7277
STEPPER_DIRECTION_MAP_ENTRY("negative", STEPPER_DIRECTION_NEGATIVE),
@@ -114,7 +119,7 @@ SHELL_DYNAMIC_CMD_CREATE(dsub_stepper_microstep, cmd_stepper_microstep);
114119

115120
static void cmd_pos_stepper_motor_name(size_t idx, struct shell_static_entry *entry)
116121
{
117-
const struct device *dev = shell_device_lookup(idx, NULL);
122+
const struct device *dev = shell_device_filter(idx, stepper_device_check);
118123

119124
entry->syntax = (dev != NULL) ? dev->name : NULL;
120125
entry->handler = NULL;
@@ -126,7 +131,7 @@ SHELL_DYNAMIC_CMD_CREATE(dsub_pos_stepper_motor_name, cmd_pos_stepper_motor_name
126131

127132
static void cmd_pos_stepper_motor_name_dir(size_t idx, struct shell_static_entry *entry)
128133
{
129-
const struct device *dev = shell_device_lookup(idx, NULL);
134+
const struct device *dev = shell_device_filter(idx, stepper_device_check);
130135

131136
if (dev != NULL) {
132137
entry->syntax = dev->name;
@@ -142,7 +147,7 @@ SHELL_DYNAMIC_CMD_CREATE(dsub_pos_stepper_motor_name_dir, cmd_pos_stepper_motor_
142147

143148
static void cmd_pos_stepper_motor_name_microstep(size_t idx, struct shell_static_entry *entry)
144149
{
145-
const struct device *dev = shell_device_lookup(idx, NULL);
150+
const struct device *dev = shell_device_filter(idx, stepper_device_check);
146151

147152
if (dev != NULL) {
148153
entry->syntax = dev->name;

0 commit comments

Comments
 (0)