drivers: hwinfo: Add shell command for device id
This commit adds support for device id shell command. Example: uart:~$ hwinfo devid Length: 12 ID: 0x1b0320d51485330313420 Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
This commit is contained in:
parent
62e55e5e4b
commit
7b1e9e9b34
4 changed files with 56 additions and 0 deletions
|
@ -3,3 +3,5 @@ zephyr_sources_ifdef(CONFIG_HWINFO hwinfo_weak_impl.c)
|
|||
|
||||
zephyr_sources_ifdef(CONFIG_HWINFO_STM32 hwinfo_stm32.c)
|
||||
zephyr_sources_ifdef(CONFIG_HWINFO_NRF hwinfo_nrf.c)
|
||||
|
||||
zephyr_sources_ifdef(CONFIG_HWINFO_SHELL hwinfo_shell.c)
|
||||
|
|
|
@ -13,6 +13,11 @@ menuconfig HWINFO
|
|||
|
||||
if HWINFO
|
||||
|
||||
config HWINFO_SHELL
|
||||
bool "Enable HWINFO Shell"
|
||||
help
|
||||
Enable hwinfo Shell for testing.
|
||||
|
||||
config HWINFO_STM32
|
||||
bool "STM32 hwinfo"
|
||||
default y
|
||||
|
|
47
drivers/hwinfo/hwinfo_shell.c
Normal file
47
drivers/hwinfo/hwinfo_shell.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Alexander Wachter
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <misc/printk.h>
|
||||
#include <shell/shell.h>
|
||||
#include <hwinfo.h>
|
||||
#include <zephyr/types.h>
|
||||
#include <logging/log.h>
|
||||
|
||||
static int cmd_get_device_id(const struct shell *shell, size_t argc, char **argv)
|
||||
{
|
||||
u8_t dev_id[16];
|
||||
ssize_t length;
|
||||
int i;
|
||||
|
||||
length = hwinfo_get_device_id(dev_id, sizeof(dev_id));
|
||||
|
||||
if (length == -ENOTSUP) {
|
||||
shell_error(shell, "Not supported by hardware");
|
||||
return -ENOTSUP;
|
||||
} else if (length < 0) {
|
||||
shell_error(shell, "Error: %d", length);
|
||||
return length;
|
||||
}
|
||||
|
||||
shell_fprintf(shell, SHELL_NORMAL, "Length: %d\n", length);
|
||||
shell_fprintf(shell, SHELL_NORMAL, "ID: 0x");
|
||||
|
||||
for (i = 0 ; i < length ; i++) {
|
||||
shell_fprintf(shell, SHELL_NORMAL, "%x", dev_id[i]);
|
||||
}
|
||||
|
||||
shell_fprintf(shell, SHELL_NORMAL, "\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHELL_CREATE_STATIC_SUBCMD_SET(sub_hwinfo) {
|
||||
/* Alphabetically sorted. */
|
||||
SHELL_CMD_ARG(devid, NULL, "Show device id", cmd_get_device_id, 1, 0),
|
||||
SHELL_SUBCMD_SET_END /* Array terminated. */
|
||||
};
|
||||
|
||||
SHELL_CMD_ARG_REGISTER(hwinfo, &sub_hwinfo, "HWINFO commands", NULL, 2, 0);
|
Loading…
Add table
Add a link
Reference in a new issue