Skip to content

RTC and CAN shell completion #79251

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

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
41 changes: 38 additions & 3 deletions drivers/can/can_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,38 @@

LOG_MODULE_REGISTER(can_shell, CONFIG_CAN_LOG_LEVEL);

#define CAN_HDL_LIST_ENTRY(node_id) \
{ \
.dev = DEVICE_DT_GET(node_id), \
},

static struct can_hdl {
const struct device *dev;
} can_list[] = {
/* zephyr-keep-sorted-start */
DT_FOREACH_STATUS_OKAY(atmel_sam_can, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(atmel_sam0_can, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(espressif_esp32_twai, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(infineon_xmc4xxx_can_node, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(kvaser_pcican, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(microchip_mcp251xfd, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(microchip_mcp2515, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(nordic_nrf_can, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(nuvoton_numaker_canfd, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(nxp_flexcan, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(nxp_lpc_mcan, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(nxp_s32_canxl, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(renesas_rcar_can, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(st_stm32_bxcan, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(st_stm32_fdcan, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(st_stm32h7_fdcan, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(ti_tcan4x5x, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(zephyr_can_loopback, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(zephyr_fake_can, CAN_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(zephyr_native_linux_can, CAN_HDL_LIST_ENTRY)
/* zephyr-keep-sorted-stop */
};

struct can_shell_tx_event {
unsigned int frame_no;
int error;
Expand Down Expand Up @@ -996,11 +1028,14 @@ static int cmd_can_recover(const struct shell *sh, size_t argc, char **argv)

static void cmd_can_device_name(size_t idx, struct shell_static_entry *entry)
{
const struct device *dev = shell_device_lookup(idx, NULL);
if (idx >= ARRAY_SIZE(can_list)) {
entry->syntax = NULL;
return;
}

entry->syntax = (dev != NULL) ? dev->name : NULL;
entry->syntax = can_list[idx].dev->name;
entry->handler = NULL;
entry->help = NULL;
entry->help = "Device";
entry->subcmd = NULL;
}

Expand Down
37 changes: 34 additions & 3 deletions drivers/rtc/rtc_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,34 @@
#include <time.h>
#include <stdlib.h>

#define RTC_HDL_LIST_ENTRY(node_id) \
{ \
.dev = DEVICE_DT_GET(node_id), \
},

static struct rtc_hdl {
const struct device *dev;
} rtc_list[] = {
/* zephyr-keep-sorted-start */
DT_FOREACH_STATUS_OKAY(ambiq_am1805, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(ambiq_rtc, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(atmel_sam_rtc, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(infineon_xmc4xxx_rtc, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(maxim_ds1307, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(microcrystal_rv3028, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(microcrystal_rv_8263_c8, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(motorola_mc146818, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(nuvoton_numaker_rtc, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(nxp_pcf8523, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(nxp_pcf8563, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(raspberrypi_pico_rtc, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(renesas_smartbond_rtc, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(st_stm32_rtc, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(zephyr_fake_rtc, RTC_HDL_LIST_ENTRY)
DT_FOREACH_STATUS_OKAY(zephyr_rtc_emul, RTC_HDL_LIST_ENTRY)
/* zephyr-keep-sorted-stop */
};

/* Formats accepted when setting date and/or time */
static const char format_iso8601[] = "%FT%T";
static const char format_time[] = "%T"; /* hh:mm:ss */
Expand Down Expand Up @@ -219,11 +247,14 @@ static int cmd_get(const struct shell *sh, size_t argc, char **argv)

static void device_name_get(size_t idx, struct shell_static_entry *entry)
{
const struct device *dev = shell_device_lookup(idx, NULL);
if (idx >= ARRAY_SIZE(rtc_list)) {
entry->syntax = NULL;
return;
}

entry->syntax = (dev != NULL) ? dev->name : NULL;
entry->syntax = rtc_list[idx].dev->name;
entry->handler = NULL;
entry->help = NULL;
entry->help = "Device";
entry->subcmd = NULL;
}

Expand Down
Loading