Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add few shell filters #84179

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions drivers/comparator/comparator_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ static int cmd_trigger_is_pending(const struct shell *sh, size_t argc, char **ar
return 0;
}

static bool device_is_comp_and_ready(const struct device *dev)
static bool device_is_comp(const struct device *dev)
{
return device_is_ready(dev) && DEVICE_API_IS(comparator, dev);
return DEVICE_API_IS(comparator, dev);
}

static void dsub_set_trigger_lookup_1(size_t idx, struct shell_static_entry *entry)
Expand All @@ -233,7 +233,7 @@ SHELL_DYNAMIC_CMD_CREATE(dsub_set_trigger_1, dsub_set_trigger_lookup_1);

static void dsub_set_trigger_lookup_0(size_t idx, struct shell_static_entry *entry)
{
const struct device *dev = shell_device_filter(idx, device_is_comp_and_ready);
const struct device *dev = shell_device_filter(idx, device_is_comp);

entry->syntax = dev != NULL ? dev->name : NULL;
entry->handler = NULL;
Expand All @@ -245,7 +245,7 @@ SHELL_DYNAMIC_CMD_CREATE(dsub_set_trigger_0, dsub_set_trigger_lookup_0);

static void dsub_device_lookup_0(size_t idx, struct shell_static_entry *entry)
{
const struct device *dev = shell_device_filter(idx, device_is_comp_and_ready);
const struct device *dev = shell_device_filter(idx, device_is_comp);

entry->syntax = (dev != NULL) ? dev->name : NULL;
entry->handler = NULL;
Expand Down
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_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
7 changes: 6 additions & 1 deletion drivers/i2c/i2c_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,14 @@ static int cmd_i2c_speed(const struct shell *shell_ctx, size_t argc, char **argv
return 0;
}

static bool device_is_i2c(const struct device *dev)
{
return DEVICE_API_IS(i2c, dev);
}

static void device_name_get(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, device_is_i2c);

entry->syntax = (dev != NULL) ? dev->name : NULL;
entry->handler = NULL;
Expand Down
6 changes: 3 additions & 3 deletions drivers/led/led_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@ cmd_write_channels(const struct shell *sh, size_t argc, char **argv)
return err;
}

static bool device_is_led_and_ready(const struct device *dev)
static bool device_is_led(const struct device *dev)
{
return device_is_ready(dev) && DEVICE_API_IS(led, dev);
return DEVICE_API_IS(led, dev);
}

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

entry->syntax = (dev != NULL) ? dev->name : NULL;
entry->handler = NULL;
Expand Down
6 changes: 3 additions & 3 deletions drivers/pwm/pwm_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ 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)
static bool device_is_pwm(const struct device *dev)
{
return device_is_ready(dev) && DEVICE_API_IS(pwm, dev);
return 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);
const struct device *dev = shell_device_filter(idx, device_is_pwm);

entry->syntax = (dev != NULL) ? dev->name : NULL;
entry->handler = NULL;
Expand Down
7 changes: 6 additions & 1 deletion drivers/regulator/regulator_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,14 @@ static int cmd_shipmode(const struct shell *sh, size_t argc, char **argv)
return 0;
}

static bool device_is_regulator(const struct device *dev)
{
return DEVICE_API_IS(regulator, dev);
}

static void device_name_get(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, device_is_regulator);

entry->syntax = (dev != NULL) ? dev->name : NULL;
entry->handler = NULL;
Expand Down
2 changes: 1 addition & 1 deletion drivers/stepper/stepper_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ 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);
return DEVICE_API_IS(stepper, dev);
}

static const struct stepper_direction_map stepper_direction_map[] = {
Expand Down
Loading