feat: move configs into libs, add filesystem support
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 12s

This commit is contained in:
2026-02-10 18:14:43 +01:00
parent 1b8d3e17b8
commit 5e7a817e03
12 changed files with 171 additions and 29 deletions

View File

@@ -0,0 +1,5 @@
VERSION_MAJOR = 0
VERSION_MINOR = 0
PATCHLEVEL = 0
VERSION_TWEAK = 0
EXTRAVERSION =

View File

@@ -0,0 +1,5 @@
/ {
chosen {
nordic,pm-ext-flash = &mx25r64;
};
};

View File

@@ -0,0 +1,4 @@
littlefs_storage:
address: 0x0
size: 0x800000
region: external_flash

View File

@@ -20,32 +20,21 @@ CONFIG_NVS=y
CONFIG_SETTINGS=y
# Network and OpenThread
CONFIG_NETWORKING=y
CONFIG_NET_L2_OPENTHREAD=y
CONFIG_OPENTHREAD=y
CONFIG_OPENTHREAD_SHELL=y
CONFIG_OPENTHREAD_DEFAULT_TX_POWER=8
# CONFIG_NETWORKING=y
# CONFIG_NET_L2_OPENTHREAD=y
# CONFIG_OPENTHREAD=y
# CONFIG_OPENTHREAD_SHELL=y
# CONFIG_OPENTHREAD_DEFAULT_TX_POWER=8
# --- CoAP & UDP Features ---
CONFIG_OPENTHREAD_COAP=y
CONFIG_OPENTHREAD_MANUAL_START=y
# CONFIG_OPENTHREAD_COAP=y
# CONFIG_OPENTHREAD_MANUAL_START=y
# Bluetooth
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="Lasertag-Device"
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_L2CAP_TX_MTU=252
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_BUF_ACL_RX_SIZE=251
CONFIG_BT_ATT_PREPARE_COUNT=5
CONFIG_BT_LOG_LEVEL_WRN=y
# Enable Lasertag Shared Modules
CONFIG_LASERTAG_UTILS=y
CONFIG_THREAD_MGMT=y
CONFIG_LASERTAG_UTILS=n
CONFIG_THREAD_MGMT=n
CONFIG_OPENTHREAD_FTD=y
CONFIG_THREAD_MGMT_LOG_LEVEL_DBG=n
CONFIG_BLE_MGMT=y
CONFIG_BLE_MGMT_LOG_LEVEL_DBG=n
CONFIG_GAME_MGMT=y
CONFIG_BLE_MGMT=n
CONFIG_GAME_MGMT=y
CONFIG_FS_MGMT=y
CONFIG_FS_MGMT_LOG_LEVEL_DBG=y

View File

@@ -1,18 +1,41 @@
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#ifdef CONFIG_LASERTAG_UTILS
#include <lasertag_utils.h>
#endif
#ifdef CONFIG_THREAD_MGMT
#include <thread_mgmt.h>
#endif
#ifdef CONFIG_BLE_MGMT
#include <ble_mgmt.h>
#endif
#ifdef CONFIG_FS_MGMT
#include <fs_mgmt.h>
#endif
LOG_MODULE_REGISTER(vest_app, CONFIG_LOG_DEFAULT_LEVEL);
int main(void)
{
int rc;
#ifdef CONFIG_LASERTAG_UTILS
/* Initialize shared project logic and NVS */
lasertag_utils_init();
#endif
#ifdef CONFIG_FS_MGMT
/* Initialize filesystem management */
rc = fs_mgmt_init();
if (rc) {
LOG_ERR("Filesystem management initialization failed (err %d)", rc);
return rc;
}
#endif
#ifdef CONFIG_BLE_MGMT
/* Initialize and start BLE management for provisioning */
int rc = ble_mgmt_init(LT_TYPE_VEST);
rc = ble_mgmt_init(LT_TYPE_VEST);
if (rc) {
LOG_ERR("BLE initialization failed (err %d)", rc);
return rc;
@@ -27,7 +50,9 @@ int main(void)
} else {
LOG_INF("BLE advertising started.");
}
#endif
#ifdef CONFIG_THREAD_MGMT
/* Initialize and start OpenThread stack */
rc = thread_mgmt_init();
if (rc) {
@@ -36,6 +61,7 @@ int main(void)
LOG_INF("Vest Application successfully started with Thread Mesh.");
return rc;
}
#endif
while (1) {
/* Main loop - handle high-level game logic here */

View File

@@ -4,4 +4,5 @@ add_subdirectory(ble_mgmt)
add_subdirectory(thread_mgmt)
add_subdirectory(lasertag_utils)
add_subdirectory(ir)
add_subdirectory(game_mgmt)
add_subdirectory(game_mgmt)
add_subdirectory(fs_mgmt)

View File

@@ -3,4 +3,5 @@ rsource "lasertag_utils/Kconfig"
rsource "thread_mgmt/Kconfig"
rsource "ble_mgmt/Kconfig"
rsource "ir/Kconfig"
rsource "game_mgmt/Kconfig"
rsource "game_mgmt/Kconfig"
rsource "fs_mgmt/Kconfig"

View File

@@ -1,6 +1,8 @@
menuconfig BLE_MGMT
bool "BLE Management"
depends on BT
select BT
select BT_PERIPHERAL
select BT_DEVICE_NAME_DYNAMIC
help
Library for BLE provisioning of the lasertag device.
@@ -9,9 +11,20 @@ if BLE_MGMT
module-str = ble_mgmt
source "subsys/logging/Kconfig.template.log_config"
config BLE_MGMT_CAN_BE_GAME_LEADER
config BLE_MGMT_CAN_BE_GAME_LEADER
bool "Can be game leader"
default n
help
Allow this device to take the game leader role in the lasertag game.
config BT_DEVICE_NAME
default "Lasertag Device"
config BT_L2CAP_TX_MTU
default 252
config BT_BUF_ACL_RX_SIZE
default 251
config BT_BUF_ACL_TX_SIZE
default 251
config BT_ATT_PREPARE_COUNT
default 5
endif

View File

@@ -2,4 +2,16 @@ if(CONFIG_FS_MGMT)
zephyr_library()
zephyr_sources(src/fs_mgmt.c)
zephyr_include_directories(include)
if(CONFIG_FILE_SYSTEM_LITTLEFS)
if(DEFINED ZEPHYR_LITTLEFS_MODULE_DIR)
zephyr_include_directories(${ZEPHYR_LITTLEFS_MODULE_DIR})
elseif(DEFINED WEST_TOPDIR)
zephyr_include_directories(${WEST_TOPDIR}/modules/fs/littlefs)
endif()
if(DEFINED ZEPHYR_BASE)
zephyr_include_directories(${ZEPHYR_BASE}/modules/littlefs)
endif()
endif()
endif()

View File

@@ -1,6 +1,7 @@
menuconfig FS_MGMT
bool "File System Management"
select FLASH
select FLASH_MAP
select FILE_SYSTEM
select FILE_SYSTEM_LITTLEFS
select FILE_SYSTEM_MKFS

View File

@@ -0,0 +1,7 @@
#ifndef FS_MGMT_H
#define FS_MGMT_H
int fs_mgmt_init(void);
#endif

View File

@@ -0,0 +1,78 @@
#include <zephyr/fs/fs.h>
#include <zephyr/fs/littlefs.h>
#include <zephyr/storage/flash_map.h>
#include <zephyr/logging/log.h>
#include <fs_mgmt.h>
LOG_MODULE_REGISTER(fs_mgmt, CONFIG_FS_MGMT_LOG_LEVEL);
#define STORAGE_PARTITION_ID FIXED_PARTITION_ID(littlefs_storage)
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(fs_storage_data);
static struct fs_mount_t fs_storage_mnt = {
.type = FS_LITTLEFS,
.fs_data = &fs_storage_data,
.storage_dev = (void *)STORAGE_PARTITION_ID,
.mnt_point = "/lfs",
};
int fs_mgmt_init(void)
{
int rc;
LOG_DBG("Initializing filesystem management module");
rc = fs_mount(&fs_storage_mnt);
if (rc)
{
LOG_ERR("Filesystem mount failed (err %d)", rc);
return rc;
}
else
{
struct fs_statvfs stat;
uint64_t total;
uint64_t free;
LOG_DBG("Filesystem mounted successfully at %s", fs_storage_mnt.mnt_point);
rc = fs_statvfs(fs_storage_mnt.mnt_point, &stat);
if (rc == 0)
{
total = (uint64_t)stat.f_blocks * (uint64_t)stat.f_frsize;
free = (uint64_t)stat.f_bfree * (uint64_t)stat.f_frsize;
uint64_t total_kb = total / 1024;
uint64_t free_kb = free / 1024;
uint64_t used_kb = total_kb - free_kb;
uint64_t used_pct_x10 = 0;
LOG_DBG("Filesystem total size/used/free size: %4llu/%4llu/%4llu KB",
(unsigned long long)total_kb,
(unsigned long long)used_kb,
(unsigned long long)free_kb);
if (total_kb > 0)
{
used_pct_x10 = (used_kb * 1000) / total_kb;
}
if (used_pct_x10 >= 900)
{
LOG_ERR("Filesystem used: %llu.%llu%%",
(unsigned long long)(used_pct_x10 / 10),
(unsigned long long)(used_pct_x10 % 10));
}
else if (used_pct_x10 >= 750)
{
LOG_WRN("Filesystem used: %llu.%llu%%",
(unsigned long long)(used_pct_x10 / 10),
(unsigned long long)(used_pct_x10 % 10));
}
else
{
LOG_DBG("Filesystem used: %llu.%llu%%",
(unsigned long long)(used_pct_x10 / 10),
(unsigned long long)(used_pct_x10 % 10));
}
}
else
{
LOG_WRN("Filesystem statvfs failed (err %d)", rc);
}
}
return 0;
}