Skip to content
Closed
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
1 change: 1 addition & 0 deletions drivers/rtc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ config RTC_CALIBRATION
config RTC_SHELL
bool "RTC Shell commands"
depends on SHELL
imply DEVICE_DT_METADATA
help
RTC Shell commands

Expand Down
37 changes: 35 additions & 2 deletions drivers/rtc/rtc_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that was my point too

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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 default y if !SHELL_MINIMAL? Then it would be coupled with the SHELL subsystem, which makes more sense to me.

Copy link
Member

Choose a reason for hiding this comment

The 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)

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Yeah seen some first of those patches in the wild already 1c5c28b

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't adding default y if !SHELL_MINIMAL to CONFIG_DEVICE_DT_METADATA be kind of weird since CONFIG_DEVICE_DT_METADATA is under the kernel Kconfig? This would be the first mention of SHELL_MINIMAL outside of shell related Kconfigs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't adding default y if !SHELL_MINIMAL to CONFIG_DEVICE_DT_METADATA be kind of weird since CONFIG_DEVICE_DT_METADATA is under the kernel Kconfig? This would be the first mention of SHELL_MINIMAL outside of shell related Kconfigs

yup, sounds like we should instead have something like:

config SHELL_DEVICE_HELPERS
    bool "Shell device helpers"
    imply DEVICE_DT_METADATA
    default y if !SHELL_MINIMAL

Copy link
Contributor Author

@yishai1999 yishai1999 Dec 8, 2024

Choose a reason for hiding this comment

The 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]);
Expand Down Expand Up @@ -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]);
Expand Down
Loading