feat(refactor): Restructure project for improved modularity and clarity

This commit introduces a major refactoring of the project structure to align
with Zephyr's recommended multi-application and library organization.

Key changes include:
- Relocation of custom modules from 'software/modules/' to 'software/lib/'.
- Introduction of a central 'software/CMakeLists.txt' to manage application
  and library subdirectories.
- Creation of new Kconfig files for 'software/' and 'software/apps/slave_node/'
  to define project-wide and application-specific configurations.
- Removal of the 'gateway' and 'stm32g431_tests' applications.
- Removal of 'shell_modbus.c' and 'shell_system.c' from 'slave_node' application's
  direct source files, indicating a shift towards library-based shell commands.
- Updates to 'software/apps/slave_node/CMakeLists.txt', 'prj.conf', and
  'boards/bluepill_f103rb.conf' to reflect the new structure and dependencies.
This commit is contained in:
Eduard Iten 2025-07-03 16:58:43 +02:00
parent 3f0d5a76c6
commit 6c1ff0c4df
35 changed files with 80 additions and 74 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.associations": {
"fwu.h": "c"
}
}

6
lib/fwu/CMakeLists.txt Normal file
View File

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.20)
project(fwu)
target_sources(fwu PRIVATE src/fwu.c)
target_include_directories(fwu PUBLIC include)

View File

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.20)
project(modbus_server)
target_sources(modbus_server PRIVATE src/modbus_server.c)
target_include_directories(modbus_server PUBLIC include)

6
lib/valve/CMakeLists.txt Normal file
View File

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.20)
project(valve)
target_sources(valve PRIVATE src/valve.c)
target_include_directories(valve PUBLIC include)

View File

@ -1,8 +0,0 @@
cmake_minimum_required(VERSION 3.13.1)
project(software)
add_subdirectory(modules/modbus_server)
add_subdirectory(modules/valve)
add_subdirectory(modules/fwu)
add_subdirectory(apps/stm32g431_tests)

1
software/Kconfig Normal file
View File

@ -0,0 +1 @@
rsource "lib/Kconfig"

View File

@ -1,27 +1,8 @@
cmake_minimum_required(VERSION 3.20)
# Point BOARD_ROOT and DTS_ROOT to the 'software' directory, which contains 'boards'.
list(APPEND BOARD_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(slave_node)
list(APPEND KCONFIG_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../../modules/modbus_server/Kconfig)
list(APPEND KCONFIG_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../../modules/valve/Kconfig)
list(APPEND KCONFIG_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../../modules/fwu/Kconfig)
target_include_directories(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../modules/valve/include
${CMAKE_CURRENT_SOURCE_DIR}/../../modules/modbus_server/include
${CMAKE_CURRENT_SOURCE_DIR}/../../modules/fwu/include
)
# Add the source files from the app and the libraries
target_sources(app PRIVATE
src/main.c
src/shell_modbus.c
src/shell_system.c
${CMAKE_CURRENT_SOURCE_DIR}/../../modules/valve/src/valve.c
${CMAKE_CURRENT_SOURCE_DIR}/../../modules/modbus_server/src/modbus_server.c
${CMAKE_CURRENT_SOURCE_DIR}/../../modules/fwu/src/fwu.c
)
project(slave_node LANGUAGES C)
zephyr_include_directories(../../include)
add_subdirectory(../../lib lib)
target_sources(app PRIVATE src/main.c)

View File

@ -0,0 +1,2 @@
rsource "../../lib/Kconfig"
source "Kconfig.zephyr"

View File

@ -4,3 +4,4 @@ CONFIG_UART_CONSOLE=n
# Enable RTT console
CONFIG_RTT_CONSOLE=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_SHELL_BACKEND_RTT=y

View File

@ -4,7 +4,6 @@ CONFIG_LOG=y
# Enable Shell
CONFIG_SHELL=y
CONFIG_SHELL_BACKEND_RTT=y
CONFIG_REBOOT=y
# Enable Settings Subsystem

View File

@ -1,9 +1,9 @@
#include <zephyr/kernel.h>
#include <zephyr/settings/settings.h>
#include <zephyr/logging/log.h>
#include <modbus_server.h>
#include <valve.h>
#include <fwu.h>
#include <lib/modbus_server.h>
#include <lib/valve.h>
#include <lib/fwu.h>
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);

View File

@ -0,0 +1,5 @@
add_subdirectory_ifdef(CONFIG_LIB_FWU fwu)
add_subdirectory_ifdef(CONFIG_LIB_MODBUS_SERVER modbus_server)
add_subdirectory_ifdef(CONFIG_LIB_VALVE valve)
add_subdirectory_ifdef(CONFIG_SHELL_SYSTEM shell_system)
add_subdirectory_ifdef(CONFIG_SHELL_MODBUS shell_modbus)

8
software/lib/Kconfig Normal file
View File

@ -0,0 +1,8 @@
menu "Irrigation system software libraries"
rsource "fwu/Kconfig"
rsource "modbus_server/Kconfig"
rsource "valve/Kconfig"
rsource "shell_system/Kconfig"
rsource "shell_modbus/Kconfig"
endmenu

View File

@ -0,0 +1 @@
zephyr_library_sources(fwu.c)

View File

@ -1,5 +1,5 @@
config FWU
config LIB_FWU
bool "Enable Firmware Update Library"
default y
help
Enable the Firmware Update module.
Enable the Firmware Update Library.

View File

@ -1,8 +1,8 @@
#include "fwu.h"
#include <zephyr/kernel.h>
#include <zephyr/sys/crc.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/logging/log.h>
#include <lib/fwu.h>
LOG_MODULE_REGISTER(fwu, LOG_LEVEL_INF);

View File

@ -0,0 +1 @@
zephyr_library_sources(modbus_server.c)

View File

@ -0,0 +1,5 @@
config LIB_MODBUS_SERVER
bool "Enable Modbus Server Library"
default y
help
Enable the Modbus Server Library.

View File

@ -5,9 +5,9 @@
#include <zephyr/logging/log.h>
#include <zephyr/settings/settings.h>
#include <zephyr/sys/reboot.h>
#include "modbus_server.h"
#include "valve.h"
#include "fwu.h"
#include <lib/modbus_server.h>
#include <lib/valve.h>
#include <lib/fwu.h>
#include <zephyr/usb/usb_device.h>
@ -135,7 +135,7 @@ static int input_reg_rd(uint16_t addr, uint16_t *reg)
*reg = (0 << 8) | 0;
break;
case REG_INPUT_FIRMWARE_VERSION_PATCH:
*reg = 1;
*reg = 2;
break;
default:
*reg = 0;

View File

@ -0,0 +1 @@
zephyr_library_sources(shell_modbus.c)

View File

@ -0,0 +1,5 @@
config SHELL_MODBUS
bool "Enable Shell Modbus"
default y
help
Enable the modnbus shell commands.

View File

@ -1,7 +1,7 @@
#include <zephyr/shell/shell.h>
#include <stdlib.h>
#include <modbus_server.h>
#include <valve.h>
#include <lib/modbus_server.h>
#include <lib/valve.h>
static int cmd_modbus_set_baud(const struct shell *sh, size_t argc, char **argv)
{

View File

@ -0,0 +1 @@
zephyr_library_sources(shell_system.c)

View File

@ -0,0 +1,5 @@
config SHELL_SYSTEM
bool "Enable Shell System"
default y
help
Enable the system commands.

View File

@ -0,0 +1 @@
zephyr_library_sources(valve.c)

View File

@ -1,5 +1,5 @@
config VALVE
config LIB_VALVE
bool "Enable Valve Library"
default y
help
Enable the Valve module.
Enable the Valve Library.

View File

@ -1,7 +1,7 @@
#include "valve.h"
#include <zephyr/kernel.h>
#include <zephyr/settings/settings.h>
#include <zephyr/logging/log.h>
#include <lib/valve.h>
LOG_MODULE_REGISTER(valve, LOG_LEVEL_INF);

View File

@ -1,7 +0,0 @@
cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(fwu)
target_sources(app PRIVATE src/fwu.c)
target_include_directories(app PUBLIC include)

View File

@ -1,7 +0,0 @@
cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(modbus_server)
target_sources(app PRIVATE src/modbus_server.c)
target_include_directories(app PUBLIC include)

View File

@ -1,5 +0,0 @@
config MODBUS_SERVER
bool "Enable Modbus Server Library"
default y
help
Enable the Modbus Server module.

View File

@ -1,7 +0,0 @@
cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(valve)
target_sources(app PRIVATE src/valve.c)
target_include_directories(app PUBLIC include)