feat: Integrate VND7050AJ driver and enhance gateway settings
This commit introduces the VND7050AJ driver as a new submodule and integrates it into the project. Key changes include: - Added as a git submodule. - Enhanced the gateway application () with LittleFS and the settings subsystem. - Implemented new shell commands (, , ) for managing custom settings. - Added functionality to compact the settings file. - Updated to include new library dependencies and log return code. - Adjusted include paths for in relevant files. Signed-off-by: Eduard Iten <eduard@iten.pro>
This commit is contained in:
@@ -1,28 +1,47 @@
|
||||
# Enable logging
|
||||
# -------------------
|
||||
# Logging and Console
|
||||
# -------------------
|
||||
CONFIG_LOG=y
|
||||
CONFIG_UART_CONSOLE=y
|
||||
|
||||
# Enable shell
|
||||
# -------------
|
||||
# Zephyr Shell
|
||||
# -------------
|
||||
CONFIG_SHELL=y
|
||||
CONFIG_KERNEL_SHELL=y
|
||||
CONFIG_REBOOT=y
|
||||
|
||||
# Enable MCUMGR
|
||||
# -------------------
|
||||
# MCUmgr OS Management
|
||||
# -------------------
|
||||
CONFIG_MCUMGR=y
|
||||
|
||||
# Enable MCUMGR OS management group only
|
||||
CONFIG_MCUMGR_GRP_OS=y
|
||||
|
||||
# Configure MCUMGR transport to UART
|
||||
CONFIG_MCUMGR_TRANSPORT_UART=y
|
||||
|
||||
# -------------------
|
||||
# MCUmgr Filesystem Group
|
||||
# -------------------
|
||||
CONFIG_MCUMGR_GRP_FS=y
|
||||
|
||||
# -------------------
|
||||
# LittleFS and Flash
|
||||
# -------------------
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_MAP=y
|
||||
|
||||
# -------------------
|
||||
# Settings Subsystem
|
||||
# -------------------
|
||||
CONFIG_SETTINGS=y
|
||||
CONFIG_SETTINGS_FILE=y
|
||||
CONFIG_SETTINGS_FILE_PATH="/lfs/settings.bin"
|
||||
|
||||
# -------------------
|
||||
# Dependencies
|
||||
# -------------------
|
||||
CONFIG_NET_BUF=y
|
||||
CONFIG_ZCBOR=y
|
||||
CONFIG_CRC=y
|
||||
CONFIG_BASE64=y
|
||||
|
||||
CONFIG_MCUMGR_GRP_IMG=y
|
||||
CONFIG_IMG_MANAGER=y
|
||||
CONFIG_MCUBOOT_IMG_MANAGER=y
|
||||
CONFIG_STREAM_FLASH=y
|
||||
@@ -1,11 +1,136 @@
|
||||
#include <zephyr/fs/fs.h>
|
||||
#include <zephyr/fs/littlefs.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/settings/settings.h>
|
||||
#include <zephyr/shell/shell.h>
|
||||
#include <app_version.h>
|
||||
#include <string.h>
|
||||
|
||||
LOG_MODULE_REGISTER(hello_world);
|
||||
|
||||
/* LittleFS mount configuration for 'storage_partition' partition */
|
||||
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(storage_partition);
|
||||
static struct fs_mount_t littlefs_mnt = {
|
||||
.type = FS_LITTLEFS,
|
||||
.mnt_point = "/lfs",
|
||||
.fs_data = &storage_partition, // default config macro
|
||||
.storage_dev = (void *)FIXED_PARTITION_ID(storage_partition),
|
||||
};
|
||||
|
||||
static char my_setting[32] = "default";
|
||||
|
||||
static int my_settings_set(const char *name, size_t len, settings_read_cb read_cb, void *cb_arg)
|
||||
{
|
||||
if (strcmp(name, "value") == 0) {
|
||||
if (len > sizeof(my_setting) - 1) {
|
||||
len = sizeof(my_setting) - 1;
|
||||
}
|
||||
if (read_cb(cb_arg, my_setting, len) == len) {
|
||||
my_setting[len] = '\0';
|
||||
return 0;
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
static int my_settings_export(int (*export_func)(const char *, const void *, size_t))
|
||||
{
|
||||
return export_func("my/setting/value", my_setting, strlen(my_setting));
|
||||
}
|
||||
|
||||
SETTINGS_STATIC_HANDLER_DEFINE(my, "my/setting", NULL, my_settings_set, NULL, my_settings_export);
|
||||
|
||||
static int cmd_my_get(const struct shell *shell, size_t argc, char **argv)
|
||||
{
|
||||
shell_print(shell, "my_setting = '%s'", my_setting);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_my_reset(const struct shell *shell, size_t argc, char **argv)
|
||||
{
|
||||
strcpy(my_setting, "default");
|
||||
settings_save();
|
||||
shell_print(shell, "my_setting reset to default");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Improved set command: join all arguments for whitespace support
|
||||
static int cmd_my_set(const struct shell *shell, size_t argc, char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
shell_error(shell, "Usage: my set <value>");
|
||||
return -EINVAL;
|
||||
}
|
||||
// Join all argv[1..] with spaces
|
||||
size_t i, pos = 0;
|
||||
my_setting[0] = '\0';
|
||||
for (i = 1; i < argc; ++i) {
|
||||
size_t left = sizeof(my_setting) - 1 - pos;
|
||||
if (left == 0)
|
||||
break;
|
||||
strncat(my_setting, argv[i], left);
|
||||
pos = strlen(my_setting);
|
||||
if (i < argc - 1 && left > 1) {
|
||||
strncat(my_setting, " ", left - 1);
|
||||
pos = strlen(my_setting);
|
||||
}
|
||||
}
|
||||
my_setting[sizeof(my_setting) - 1] = '\0';
|
||||
settings_save();
|
||||
shell_print(shell, "my_setting set to '%s'", my_setting);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(my_subcmds,
|
||||
SHELL_CMD(get, NULL, "Get my_setting", cmd_my_get),
|
||||
SHELL_CMD(set, NULL, "Set my_setting (supports spaces)", cmd_my_set),
|
||||
SHELL_CMD(reset, NULL, "Reset my_setting to default and compact settings file", cmd_my_reset),
|
||||
SHELL_SUBCMD_SET_END);
|
||||
|
||||
SHELL_CMD_REGISTER(my, &my_subcmds, "My settings commands", NULL);
|
||||
|
||||
static void compact_settings_file(void)
|
||||
{
|
||||
struct fs_file_t file;
|
||||
fs_file_t_init(&file);
|
||||
int rc = fs_open(&file, "/lfs/settings.bin", FS_O_WRITE | FS_O_CREATE | FS_O_TRUNC);
|
||||
if (rc == 0) {
|
||||
fs_close(&file);
|
||||
LOG_INF("Settings file compacted (truncated and recreated)");
|
||||
} else if (rc == -ENOENT) {
|
||||
LOG_INF("Settings file did not exist, created new");
|
||||
} else {
|
||||
LOG_ERR("Failed to compact settings file (%d)", rc);
|
||||
}
|
||||
settings_save();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int rc = fs_mount(&littlefs_mnt);
|
||||
if (rc < 0) {
|
||||
LOG_ERR("Error mounting LittleFS [%d]", rc);
|
||||
} else {
|
||||
LOG_INF("LittleFS mounted at /lfs");
|
||||
}
|
||||
|
||||
/* Initialize settings subsystem */
|
||||
settings_subsys_init();
|
||||
LOG_INF("Settings subsystem initialized");
|
||||
|
||||
/* Load settings from storage */
|
||||
rc = settings_load();
|
||||
if (rc == 0) {
|
||||
LOG_INF("Settings loaded: my_setting='%s'", my_setting);
|
||||
} else {
|
||||
LOG_ERR("Failed to load settings (%d)", rc);
|
||||
}
|
||||
|
||||
/* Compact settings file on each start */
|
||||
compact_settings_file();
|
||||
|
||||
LOG_INF("Hello World! Version: %s", APP_VERSION_EXTENDED_STRING);
|
||||
return 0;
|
||||
}
|
||||
@@ -6,7 +6,3 @@
|
||||
zephyr,code-partition = &slot0_partition;
|
||||
};
|
||||
};
|
||||
|
||||
&usb_serial {
|
||||
status = "okay";
|
||||
};
|
||||
Reference in New Issue
Block a user