Skip to content

Commit

Permalink
drivers: stepper: shell: Use shell_device_filter
Browse files Browse the repository at this point in the history
Use the shell_device_filter utils method and leverage the new api classing
to only suggest stepper devices via tab-complete within the shell.

(cherry picked from commit fc25679)

Original-Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
GitOrigin-RevId: fc25679
Cr-Build-Id: 8727359303490889121
Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8727359303490889121
Copybot-Job-Name: zephyr-main-copybot-downstream
Change-Id: Ic23bb4a2a0eb7ce2b53962c02137c6c4e2ca0b20
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/6128081
Commit-Queue: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Bot-Commit: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
  • Loading branch information
Fabian Blatz authored and Chromeos LUCI committed Dec 28, 2024
1 parent 245e435 commit 56279aa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions drivers/stepper/stepper_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ static void print_callback(const struct device *dev, const enum stepper_event ev
}
}

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

static const struct stepper_direction_map stepper_direction_map[] = {
STEPPER_DIRECTION_MAP_ENTRY("positive", STEPPER_DIRECTION_POSITIVE),
STEPPER_DIRECTION_MAP_ENTRY("negative", STEPPER_DIRECTION_NEGATIVE),
Expand Down Expand Up @@ -114,7 +119,7 @@ SHELL_DYNAMIC_CMD_CREATE(dsub_stepper_microstep, cmd_stepper_microstep);

static void cmd_pos_stepper_motor_name(size_t idx, struct shell_static_entry *entry)
{
const struct device *dev = shell_device_lookup(idx, NULL);
const struct device *dev = shell_device_filter(idx, stepper_device_check);

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

static void cmd_pos_stepper_motor_name_dir(size_t idx, struct shell_static_entry *entry)
{
const struct device *dev = shell_device_lookup(idx, NULL);
const struct device *dev = shell_device_filter(idx, stepper_device_check);

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

static void cmd_pos_stepper_motor_name_microstep(size_t idx, struct shell_static_entry *entry)
{
const struct device *dev = shell_device_lookup(idx, NULL);
const struct device *dev = shell_device_filter(idx, stepper_device_check);

if (dev != NULL) {
entry->syntax = dev->name;
Expand Down

0 comments on commit 56279aa

Please sign in to comment.