Skip to content

Commit ef2fde8

Browse files
bjarki-andreasenfabiobaltieri
authored andcommitted
comparator: shell: filter device lookup using DEVICE_API macros
Filter for comparator devices when looking them up in dynamic shell commands. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent 957ece8 commit ef2fde8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/comparator/comparator_shell.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ static int cmd_trigger_is_pending(const struct shell *sh, size_t argc, char **ar
216216
return 0;
217217
}
218218

219+
static bool device_is_comp_and_ready(const struct device *dev)
220+
{
221+
return device_is_ready(dev) && DEVICE_API_IS(comparator, dev);
222+
}
223+
219224
static void dsub_set_trigger_lookup_1(size_t idx, struct shell_static_entry *entry)
220225
{
221226
entry->syntax = (idx < ARRAY_SIZE(trigger_lookup)) ? trigger_lookup[idx] : NULL;
@@ -228,7 +233,7 @@ SHELL_DYNAMIC_CMD_CREATE(dsub_set_trigger_1, dsub_set_trigger_lookup_1);
228233

229234
static void dsub_set_trigger_lookup_0(size_t idx, struct shell_static_entry *entry)
230235
{
231-
const struct device *dev = shell_device_lookup(idx, NULL);
236+
const struct device *dev = shell_device_filter(idx, device_is_comp_and_ready);
232237

233238
entry->syntax = dev != NULL ? dev->name : NULL;
234239
entry->handler = NULL;
@@ -240,7 +245,7 @@ SHELL_DYNAMIC_CMD_CREATE(dsub_set_trigger_0, dsub_set_trigger_lookup_0);
240245

241246
static void dsub_device_lookup_0(size_t idx, struct shell_static_entry *entry)
242247
{
243-
const struct device *dev = shell_device_lookup(idx, NULL);
248+
const struct device *dev = shell_device_filter(idx, device_is_comp_and_ready);
244249

245250
entry->syntax = (dev != NULL) ? dev->name : NULL;
246251
entry->handler = NULL;

0 commit comments

Comments
 (0)