-
Notifications
You must be signed in to change notification settings - Fork 8.3k
rtc: shell: support node labels and allow only rtc devices #82219
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,9 +146,37 @@ static char *strptime(const char *s, const char *format, struct tm *tm_time) | |
| } | ||
| } | ||
|
|
||
| /* Look up a device by some human-readable string identifier. We | ||
| * always search among device names. If the feature is available, we | ||
| * search by node label as well. | ||
| */ | ||
| static const struct device *get_rtc_device(char *id) | ||
| { | ||
| const struct device *dev; | ||
|
|
||
| dev = device_get_binding(id); | ||
| if (dev != NULL) { | ||
| return dev; | ||
| } | ||
|
|
||
| #ifdef CONFIG_DEVICE_DT_METADATA | ||
| dev = device_get_by_dt_nodelabel(id); | ||
| if (dev != NULL) { | ||
| return dev; | ||
| } | ||
| #endif /* CONFIG_DEVICE_DT_METADATA */ | ||
|
|
||
| return NULL; | ||
| } | ||
|
Comment on lines
+149
to
+170
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why don't we add a shell-level API to obtain a device pointer using either dev name/nodelabel id?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah that was my point too
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good! And then imply CONFIG_DEVICE_DT_METADATA in the shell Kconfig?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it stands, placed under a specific subsystem, it looks a bit off to me. We'd end up with the option auto enabling or not by default depending on some random combination of what subsystem are enabled, and what the corresponding contributors and maintainers decided. If you really want to make it more exposed to random users, how about changing it to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @henrikbrixandersen who IIRC cleaned up a bunch of SHELL options to solve a similar problems (incoherent defaults)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may even be able to extend the common API to autocomplete device names/nodelabels for a given device API type.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah seen some first of those patches in the wild already 1c5c28b
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't adding
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yup, sounds like we should instead have something like:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I opened a new PR (#82698) to add this. It would be great if you all could take a look. |
||
|
|
||
| static int cmd_set(const struct shell *sh, size_t argc, char **argv) | ||
| { | ||
| const struct device *dev = device_get_binding(argv[1]); | ||
| const struct device *dev = get_rtc_device(argv[1]); | ||
|
|
||
| if (dev == NULL) { | ||
| shell_error(sh, "unknown RTC device %s", argv[1]); | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| if (!device_is_ready(dev)) { | ||
| shell_error(sh, "device %s not ready", argv[1]); | ||
|
|
@@ -191,7 +219,12 @@ static int cmd_set(const struct shell *sh, size_t argc, char **argv) | |
|
|
||
| static int cmd_get(const struct shell *sh, size_t argc, char **argv) | ||
| { | ||
| const struct device *dev = device_get_binding(argv[1]); | ||
| const struct device *dev = get_rtc_device(argv[1]); | ||
|
|
||
| if (dev == NULL) { | ||
| shell_error(sh, "unknown RTC device %s", argv[1]); | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| if (!device_is_ready(dev)) { | ||
| shell_error(sh, "device %s not ready", argv[1]); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.