进一步迭代优化统一管理

This commit is contained in:
冯佳
2026-01-23 14:35:51 +08:00
parent 988cc7ad4a
commit 075e8299cf
36 changed files with 6146 additions and 1590 deletions

View File

@ -2,7 +2,7 @@
/**
******************************************************************************
* @file : bsp_config.h
* @brief : Board support package configuration file
* @brief : Board support package configuration file header
******************************************************************************
*/
/* USER CODE END Header */
@ -10,42 +10,175 @@
#ifndef BSP_CONFIG_H
#define BSP_CONFIG_H
#include "hal_gpio.h"
#include "hal_uart.h"
#include <stdio.h>
#include "bsp_module.h"
#include "bsp_board.h"
#include "hal.h"
/**
* @brief Board name definition
* @brief BSP configuration file format definitions
*/
#define BOARD_NAME "STM32F407VET6"
#define BSP_CONFIG_FILE_VERSION "1.0.0"
#define BSP_CONFIG_MAX_LINE_LENGTH 256
#define BSP_CONFIG_MAX_SECTION_NAME_LENGTH 32
#define BSP_CONFIG_MAX_KEY_NAME_LENGTH 32
#define BSP_CONFIG_MAX_VALUE_LENGTH 128
/**
* @brief LED hardware configuration
* @brief BSP configuration section type
*/
#define BSP_LED_PORT HAL_GPIO_PORT_A
#define BSP_LED_PIN HAL_GPIO_PIN_6
typedef enum {
BSP_CONFIG_SECTION_NONE = 0,
BSP_CONFIG_SECTION_BOARD,
BSP_CONFIG_SECTION_MODULE,
BSP_CONFIG_SECTION_PERIPH,
BSP_CONFIG_SECTION_MAX
} bsp_config_section_t;
/**
* @brief Button hardware configuration
* @brief BSP configuration entry
*/
/* KEY0 - PE4, active low */
#define BSP_KEY0_PORT HAL_GPIO_PORT_E
#define BSP_KEY0_PIN HAL_GPIO_PIN_4
/* KEY1 - PE3, active low */
#define BSP_KEY1_PORT HAL_GPIO_PORT_E
#define BSP_KEY1_PIN HAL_GPIO_PIN_3
/* WK_UP - PA0, active high */
#define BSP_WKUP_PORT HAL_GPIO_PORT_A
#define BSP_WKUP_PIN HAL_GPIO_PIN_0
typedef struct {
const char* section;
const char* key;
const char* value;
} bsp_config_entry_t;
/**
* @brief UART hardware configuration
* @brief BSP configuration parser context
*/
#define BSP_UART_INSTANCE BSP_UART_INSTANCE_1
#define BSP_UART_BAUDRATE 115200
#define BSP_UART_PARITY HAL_UART_PARITY_NONE
#define BSP_UART_STOPBITS HAL_UART_STOPBITS_1
#define BSP_UART_DATABITS HAL_UART_DATABITS_8
typedef struct {
FILE* file;
char current_section[BSP_CONFIG_MAX_SECTION_NAME_LENGTH];
char buffer[BSP_CONFIG_MAX_LINE_LENGTH];
uint32_t line_number;
uint8_t initialized;
} bsp_config_parser_t;
/**
* @brief BSP configuration file operations
*/
typedef struct {
hal_ret_t (*open)(const char* filename, bsp_config_parser_t* parser);
hal_ret_t (*close)(bsp_config_parser_t* parser);
hal_ret_t (*read_entry)(bsp_config_parser_t* parser, bsp_config_entry_t* entry);
hal_ret_t (*parse_int)(const char* value, int* result);
hal_ret_t (*parse_uint)(const char* value, uint32_t* result);
hal_ret_t (*parse_bool)(const char* value, uint8_t* result);
hal_ret_t (*parse_string)(const char* value, char* result, size_t max_length);
} bsp_config_ops_t;
/**
* @brief Initialize BSP configuration system
* @retval HAL status code
*/
hal_ret_t bsp_config_init(void);
/**
* @brief Deinitialize BSP configuration system
* @retval HAL status code
*/
hal_ret_t bsp_config_deinit(void);
/**
* @brief Load BSP configuration from file
* @param filename: Configuration file name
* @retval HAL status code
*/
hal_ret_t bsp_config_load(const char* filename);
/**
* @brief Save BSP configuration to file
* @param filename: Configuration file name
* @retval HAL status code
*/
hal_ret_t bsp_config_save(const char* filename);
/**
* @brief Get configuration value
* @param section: Configuration section name
* @param key: Configuration key name
* @param value: Pointer to store value
* @param max_length: Maximum length of value buffer
* @retval HAL status code
*/
hal_ret_t bsp_config_get_value(const char* section, const char* key, char* value, size_t max_length);
/**
* @brief Set configuration value
* @param section: Configuration section name
* @param key: Configuration key name
* @param value: Configuration value
* @retval HAL status code
*/
hal_ret_t bsp_config_set_value(const char* section, const char* key, const char* value);
/**
* @brief Get configuration value as integer
* @param section: Configuration section name
* @param key: Configuration key name
* @param value: Pointer to store integer value
* @retval HAL status code
*/
hal_ret_t bsp_config_get_int(const char* section, const char* key, int* value);
/**
* @brief Set configuration value as integer
* @param section: Configuration section name
* @param key: Configuration key name
* @param value: Integer value
* @retval HAL status code
*/
hal_ret_t bsp_config_set_int(const char* section, const char* key, int value);
/**
* @brief Get configuration value as unsigned integer
* @param section: Configuration section name
* @param key: Configuration key name
* @param value: Pointer to store unsigned integer value
* @retval HAL status code
*/
hal_ret_t bsp_config_get_uint(const char* section, const char* key, uint32_t* value);
/**
* @brief Set configuration value as unsigned integer
* @param section: Configuration section name
* @param key: Configuration key name
* @param value: Unsigned integer value
* @retval HAL status code
*/
hal_ret_t bsp_config_set_uint(const char* section, const char* key, uint32_t value);
/**
* @brief Get configuration value as boolean
* @param section: Configuration section name
* @param key: Configuration key name
* @param value: Pointer to store boolean value
* @retval HAL status code
*/
hal_ret_t bsp_config_get_bool(const char* section, const char* key, uint8_t* value);
/**
* @brief Set configuration value as boolean
* @param section: Configuration section name
* @param key: Configuration key name
* @param value: Boolean value
* @retval HAL status code
*/
hal_ret_t bsp_config_set_bool(const char* section, const char* key, uint8_t value);
/**
* @brief Parse BSP modules from configuration
* @param config: Pointer to BSP board configuration structure to fill
* @retval HAL status code
*/
hal_ret_t bsp_config_parse_modules(bsp_board_config_t* config);
/**
* @brief Initialize BSP from configuration file
* @param filename: Configuration file name
* @retval HAL status code
*/
hal_ret_t bsp_init_from_config(const char* filename);
#endif /* BSP_CONFIG_H */