File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,28 @@ typedef bool (*shell_device_filter_t)(const struct device *dev);
159159const struct device * shell_device_filter (size_t idx ,
160160 shell_device_filter_t filter );
161161
162+ /**
163+ * @brief Get a @ref device reference from its @ref device.name field or label.
164+ *
165+ * This function iterates through the devices on the system. If a device with
166+ * the given @p name field is found, and that device initialized successfully at
167+ * boot time, this function returns a pointer to the device.
168+ *
169+ * If no device has the given @p name, this function returns `NULL`.
170+ *
171+ * This function also returns NULL when a device is found, but it failed to
172+ * initialize successfully at boot time. (To troubleshoot this case, set a
173+ * breakpoint on your device driver's initialization function.)
174+ *
175+ * @param name device name to search for. A null pointer, or a pointer to an
176+ * empty string, will cause NULL to be returned.
177+ *
178+ * @return pointer to device structure with the given name; `NULL` if the device
179+ * is not found or if the device with that name's initialization function
180+ * failed.
181+ */
182+ const struct device * shell_device_get_binding (const char * name );
183+
162184/**
163185 * @brief Shell command handler prototype.
164186 *
Original file line number Diff line number Diff line change @@ -25,6 +25,11 @@ config SHELL_MINIMAL
2525 defaults which favor reduced flash or memory requirements over extra
2626 features.
2727
28+ config SHELL_DEVICE_HELPERS
29+ bool "Shell device helpers"
30+ imply DEVICE_DT_METADATA
31+ default y if !SHELL_MINIMAL
32+
2833config SHELL_THREAD_PRIORITY_OVERRIDE
2934 bool "Override default shell thread priority"
3035 help
Original file line number Diff line number Diff line change @@ -536,6 +536,17 @@ const struct device *shell_device_lookup(size_t idx,
536536 return shell_device_internal (idx , prefix , NULL );
537537}
538538
539+ const struct device * shell_device_get_binding (const char * name )
540+ {
541+ const struct device * dev = device_get_binding (name );
542+
543+ if (IS_ENABLED (CONFIG_DEVICE_DT_METADATA ) && dev == NULL ) {
544+ dev = device_get_by_dt_nodelabel (name );
545+ }
546+
547+ return dev ;
548+ }
549+
539550long shell_strtol (const char * str , int base , int * err )
540551{
541552 long val ;
You can’t perform that action at this time.
0 commit comments