准备驱动移植适配Rust
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_board.h
|
||||
* @brief : Board support package board abstraction header file
|
||||
* @brief : 板级支持包板级抽象头文件
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -18,9 +18,11 @@
|
||||
#include "hal_i2c.h"
|
||||
#include "hal_can.h"
|
||||
#include "hal_adc.h"
|
||||
#include "hal_eth.h"
|
||||
#include "bsp_eth.h"
|
||||
|
||||
/**
|
||||
* @brief BSP configuration version
|
||||
* @brief BSP 配置版本
|
||||
*/
|
||||
#define BSP_CONFIG_VERSION_MAJOR 1
|
||||
#define BSP_CONFIG_VERSION_MINOR 0
|
||||
@ -28,49 +30,49 @@
|
||||
#define BSP_CONFIG_VERSION (BSP_CONFIG_VERSION_MAJOR << 16 | BSP_CONFIG_VERSION_MINOR << 8 | BSP_CONFIG_VERSION_PATCH)
|
||||
|
||||
/**
|
||||
* @brief Board LED configuration structure
|
||||
* @brief 板级 LED 配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< LED enable flag */
|
||||
hal_gpio_port_t port; /*!< LED GPIO port */
|
||||
hal_gpio_pin_t pin; /*!< LED GPIO pin */
|
||||
hal_gpio_mode_t mode; /*!< LED GPIO mode */
|
||||
hal_gpio_speed_t speed; /*!< LED GPIO speed */
|
||||
hal_gpio_pull_t pull; /*!< LED GPIO pull configuration */
|
||||
uint8_t enable; /*!< LED 使能标志 */
|
||||
hal_gpio_port_t port; /*!< LED GPIO 端口 */
|
||||
hal_gpio_pin_t pin; /*!< LED GPIO 引脚 */
|
||||
hal_gpio_mode_t mode; /*!< LED GPIO 模式 */
|
||||
hal_gpio_speed_t speed; /*!< LED GPIO 速度 */
|
||||
hal_gpio_pull_t pull; /*!< LED GPIO 上拉配置 */
|
||||
} bsp_led_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board LEDs configuration structure
|
||||
* @brief 板级 LEDs 配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< LEDs enable flag */
|
||||
uint8_t count; /*!< Number of LEDs */
|
||||
const bsp_led_config_t* leds; /*!< Pointer to LEDs configuration array */
|
||||
uint8_t enable; /*!< LEDs 使能标志 */
|
||||
uint8_t count; /*!< LED 数量 */
|
||||
const bsp_led_config_t* leds; /*!< 指向 LEDs 配置数组的指针 */
|
||||
} bsp_leds_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board button configuration structure
|
||||
* @brief 板级按键配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
hal_gpio_port_t port; /*!< Button GPIO port */
|
||||
hal_gpio_pin_t pin; /*!< Button GPIO pin */
|
||||
hal_gpio_mode_t mode; /*!< Button GPIO mode */
|
||||
hal_gpio_speed_t speed; /*!< Button GPIO speed */
|
||||
hal_gpio_pull_t pull; /*!< Button GPIO pull configuration */
|
||||
uint8_t active_high; /*!< Button active high flag */
|
||||
hal_gpio_port_t port; /*!< 按键 GPIO 端口 */
|
||||
hal_gpio_pin_t pin; /*!< 按键 GPIO 引脚 */
|
||||
hal_gpio_mode_t mode; /*!< 按键 GPIO 模式 */
|
||||
hal_gpio_speed_t speed; /*!< 按键 GPIO 速度 */
|
||||
hal_gpio_pull_t pull; /*!< 按键 GPIO 上拉配置 */
|
||||
uint8_t active_high; /*!< 按键高电平有效标志 */
|
||||
} bsp_button_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board buttons configuration structure
|
||||
* @brief 板级按键组配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< Buttons enable flag */
|
||||
uint8_t count; /*!< Number of buttons */
|
||||
const bsp_button_config_t* buttons; /*!< Pointer to buttons configuration array */
|
||||
uint8_t enable; /*!< 按键使能标志 */
|
||||
uint8_t count; /*!< 按键数量 */
|
||||
const bsp_button_config_t* buttons; /*!< 指向按键配置数组的指针 */
|
||||
} bsp_buttons_config_t;
|
||||
|
||||
/**
|
||||
* @brief UART instance identifier definitions
|
||||
* @brief UART 实例标识符定义
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_UART_INSTANCE_1 = 0,
|
||||
@ -83,251 +85,258 @@ typedef enum {
|
||||
} bsp_uart_instance_t;
|
||||
|
||||
/**
|
||||
* @brief Board UART configuration structure
|
||||
* @brief 板级 UART 配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< UART enable flag */
|
||||
bsp_uart_instance_t instance; /*!< UART instance */
|
||||
uint32_t baudrate; /*!< UART baudrate */
|
||||
hal_uart_parity_t parity; /*!< UART parity */
|
||||
hal_uart_stopbits_t stopbits; /*!< UART stop bits */
|
||||
hal_uart_databits_t databits; /*!< UART data bits */
|
||||
hal_gpio_port_t tx_port; /*!< UART TX port */
|
||||
hal_gpio_pin_t tx_pin; /*!< UART TX pin */
|
||||
hal_gpio_port_t rx_port; /*!< UART RX port */
|
||||
hal_gpio_pin_t rx_pin; /*!< UART RX pin */
|
||||
uint8_t enable; /*!< UART 使能标志 */
|
||||
bsp_uart_instance_t instance; /*!< UART 实例 */
|
||||
uint32_t baudrate; /*!< UART 波特率 */
|
||||
hal_uart_parity_t parity; /*!< UART 校验位 */
|
||||
hal_uart_stopbits_t stopbits; /*!< UART 停止位 */
|
||||
hal_uart_databits_t databits; /*!< UART 数据位 */
|
||||
hal_gpio_port_t tx_port; /*!< UART TX 端口 */
|
||||
hal_gpio_pin_t tx_pin; /*!< UART TX 引脚 */
|
||||
hal_gpio_port_t rx_port; /*!< UART RX 端口 */
|
||||
hal_gpio_pin_t rx_pin; /*!< UART RX 引脚 */
|
||||
} bsp_uart_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board SPI configuration structure
|
||||
* @brief 板级 SPI 配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< SPI enable flag */
|
||||
hal_spi_instance_t instance; /*!< SPI instance */
|
||||
hal_spi_mode_t mode; /*!< SPI mode */
|
||||
uint32_t baudrate; /*!< SPI baudrate */
|
||||
hal_spi_polarity_t polarity; /*!< SPI clock polarity */
|
||||
hal_spi_phase_t phase; /*!< SPI clock phase */
|
||||
hal_spi_databits_t databits; /*!< SPI data bits */
|
||||
hal_gpio_port_t sck_port; /*!< SPI SCK port */
|
||||
hal_gpio_pin_t sck_pin; /*!< SPI SCK pin */
|
||||
hal_gpio_port_t miso_port; /*!< SPI MISO port */
|
||||
hal_gpio_pin_t miso_pin; /*!< SPI MISO pin */
|
||||
hal_gpio_port_t mosi_port; /*!< SPI MOSI port */
|
||||
hal_gpio_pin_t mosi_pin; /*!< SPI MOSI pin */
|
||||
uint8_t enable; /*!< SPI 使能标志 */
|
||||
hal_spi_instance_t instance; /*!< SPI 实例 */
|
||||
hal_spi_mode_t mode; /*!< SPI 模式 */
|
||||
uint32_t baudrate; /*!< SPI 波特率 */
|
||||
hal_spi_polarity_t polarity; /*!< SPI 时钟极性 */
|
||||
hal_spi_phase_t phase; /*!< SPI 时钟相位 */
|
||||
hal_spi_databits_t databits; /*!< SPI 数据位 */
|
||||
hal_gpio_port_t sck_port; /*!< SPI SCK 端口 */
|
||||
hal_gpio_pin_t sck_pin; /*!< SPI SCK 引脚 */
|
||||
hal_gpio_port_t miso_port; /*!< SPI MISO 端口 */
|
||||
hal_gpio_pin_t miso_pin; /*!< SPI MISO 引脚 */
|
||||
hal_gpio_port_t mosi_port; /*!< SPI MOSI 端口 */
|
||||
hal_gpio_pin_t mosi_pin; /*!< SPI MOSI 引脚 */
|
||||
} bsp_spi_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board I2C configuration structure
|
||||
* @brief 板级 I2C 配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< I2C enable flag */
|
||||
hal_i2c_instance_t instance; /*!< I2C instance */
|
||||
hal_i2c_speed_t speed; /*!< I2C speed */
|
||||
hal_i2c_address_mode_t address_mode; /*!< I2C address mode */
|
||||
hal_i2c_dutycycle_t dutycycle; /*!< I2C duty cycle */
|
||||
uint16_t own_address1; /*!< I2C own address 1 */
|
||||
hal_gpio_port_t scl_port; /*!< I2C SCL port */
|
||||
hal_gpio_pin_t scl_pin; /*!< I2C SCL pin */
|
||||
hal_gpio_port_t sda_port; /*!< I2C SDA port */
|
||||
hal_gpio_pin_t sda_pin; /*!< I2C SDA pin */
|
||||
uint8_t enable; /*!< I2C 使能标志 */
|
||||
hal_i2c_instance_t instance; /*!< I2C 实例 */
|
||||
hal_i2c_speed_t speed; /*!< I2C 速度 */
|
||||
hal_i2c_address_mode_t address_mode; /*!< I2C 地址模式 */
|
||||
hal_i2c_dutycycle_t dutycycle; /*!< I2C 占空比 */
|
||||
uint16_t own_address1; /*!< I2C 自身地址 1 */
|
||||
hal_gpio_port_t scl_port; /*!< I2C SCL 端口 */
|
||||
hal_gpio_pin_t scl_pin; /*!< I2C SCL 引脚 */
|
||||
hal_gpio_port_t sda_port; /*!< I2C SDA 端口 */
|
||||
hal_gpio_pin_t sda_pin; /*!< I2C SDA 引脚 */
|
||||
} bsp_i2c_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board CAN configuration structure
|
||||
* @brief 板级 CAN 配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< CAN enable flag */
|
||||
hal_can_instance_t instance; /*!< CAN instance */
|
||||
hal_can_mode_t mode; /*!< CAN mode */
|
||||
uint32_t prescaler; /*!< CAN prescaler */
|
||||
uint8_t sync_jump_width; /*!< CAN sync jump width */
|
||||
uint8_t time_segment1; /*!< CAN time segment 1 */
|
||||
uint8_t time_segment2; /*!< CAN time segment 2 */
|
||||
hal_gpio_port_t rx_port; /*!< CAN RX port */
|
||||
hal_gpio_pin_t rx_pin; /*!< CAN RX pin */
|
||||
hal_gpio_port_t tx_port; /*!< CAN TX port */
|
||||
hal_gpio_pin_t tx_pin; /*!< CAN TX pin */
|
||||
uint8_t enable; /*!< CAN 使能标志 */
|
||||
hal_can_instance_t instance; /*!< CAN 实例 */
|
||||
hal_can_mode_t mode; /*!< CAN 模式 */
|
||||
uint32_t prescaler; /*!< CAN 预分频器 */
|
||||
uint8_t sync_jump_width; /*!< CAN 同步跳转宽度 */
|
||||
uint8_t time_segment1; /*!< CAN 时间段 1 */
|
||||
uint8_t time_segment2; /*!< CAN 时间段 2 */
|
||||
hal_gpio_port_t rx_port; /*!< CAN RX 端口 */
|
||||
hal_gpio_pin_t rx_pin; /*!< CAN RX 引脚 */
|
||||
hal_gpio_port_t tx_port; /*!< CAN TX 端口 */
|
||||
hal_gpio_pin_t tx_pin; /*!< CAN TX 引脚 */
|
||||
} bsp_can_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board ADC channel configuration structure
|
||||
* @brief 板级 ADC 通道配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< ADC channel enable flag */
|
||||
hal_adc_channel_t channel; /*!< ADC channel */
|
||||
hal_adc_sampletime_t sampletime; /*!< ADC sample time */
|
||||
uint8_t rank; /*!< ADC channel rank */
|
||||
uint8_t enable; /*!< ADC 通道使能标志 */
|
||||
hal_adc_channel_t channel; /*!< ADC 通道 */
|
||||
hal_adc_sampletime_t sampletime; /*!< ADC 采样时间 */
|
||||
uint8_t rank; /*!< ADC 通道优先级 */
|
||||
} bsp_adc_channel_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board ADC configuration structure
|
||||
* @brief 板级 ADC 配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< ADC enable flag */
|
||||
hal_adc_instance_t instance; /*!< ADC instance */
|
||||
hal_adc_resolution_t resolution; /*!< ADC resolution */
|
||||
uint8_t scan_conversion_mode; /*!< ADC scan conversion mode */
|
||||
uint8_t continuous_conversion_mode; /*!< ADC continuous conversion mode */
|
||||
uint8_t channel_count; /*!< Number of ADC channels */
|
||||
const bsp_adc_channel_config_t* channels; /*!< Pointer to ADC channels configuration array */
|
||||
uint8_t enable; /*!< ADC 使能标志 */
|
||||
hal_adc_instance_t instance; /*!< ADC 实例 */
|
||||
hal_adc_resolution_t resolution; /*!< ADC 分辨率 */
|
||||
uint8_t scan_conversion_mode; /*!< ADC 扫描转换模式 */
|
||||
uint8_t continuous_conversion_mode; /*!< ADC 连续转换模式 */
|
||||
uint8_t channel_count; /*!< ADC 通道数量 */
|
||||
const bsp_adc_channel_config_t* channels; /*!< 指向 ADC 通道配置数组的指针 */
|
||||
} bsp_adc_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board W25QXX configuration structure
|
||||
* @brief 板级 W25QXX 配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< W25QXX enable flag */
|
||||
hal_gpio_port_t cs_port; /*!< W25QXX CS port */
|
||||
hal_gpio_pin_t cs_pin; /*!< W25QXX CS pin */
|
||||
uint8_t spi_instance; /*!< SPI instance used by W25QXX */
|
||||
uint8_t enable; /*!< W25QXX 使能标志 */
|
||||
hal_gpio_port_t cs_port; /*!< W25QXX CS 端口 */
|
||||
hal_gpio_pin_t cs_pin; /*!< W25QXX CS 引脚 */
|
||||
uint8_t spi_instance; /*!< W25QXX 使用的 SPI 实例 */
|
||||
} bsp_w25qxx_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board peripheral initialization function type
|
||||
* @brief 板级外设初始化函数类型
|
||||
*/
|
||||
typedef hal_ret_t (*bsp_periph_init_func_t)(const void* config);
|
||||
|
||||
/**
|
||||
* @brief Board ID structure
|
||||
* @brief 板级 ID 结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t vendor_id; /*!< Board vendor ID */
|
||||
uint16_t product_id; /*!< Board product ID */
|
||||
uint32_t serial_number; /*!< Board serial number */
|
||||
uint16_t vendor_id; /*!< 板级厂商 ID */
|
||||
uint16_t product_id; /*!< 板级产品 ID */
|
||||
uint32_t serial_number; /*!< 板级序列号 */
|
||||
} bsp_board_id_t;
|
||||
|
||||
/**
|
||||
* @brief Board feature flags
|
||||
* @brief 板级特性标志
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_BOARD_FEATURE_LED = (1 << 0), /*!< Board has LED support */
|
||||
BSP_BOARD_FEATURE_BUTTON = (1 << 1), /*!< Board has button support */
|
||||
BSP_BOARD_FEATURE_UART = (1 << 2), /*!< Board has UART support */
|
||||
BSP_BOARD_FEATURE_SPI = (1 << 3), /*!< Board has SPI support */
|
||||
BSP_BOARD_FEATURE_I2C = (1 << 4), /*!< Board has I2C support */
|
||||
BSP_BOARD_FEATURE_CAN = (1 << 5), /*!< Board has CAN support */
|
||||
BSP_BOARD_FEATURE_ADC = (1 << 6), /*!< Board has ADC support */
|
||||
BSP_BOARD_FEATURE_DAC = (1 << 7), /*!< Board has DAC support */
|
||||
BSP_BOARD_FEATURE_TIMER = (1 << 8), /*!< Board has TIMER support */
|
||||
BSP_BOARD_FEATURE_RTC = (1 << 9), /*!< Board has RTC support */
|
||||
BSP_BOARD_FEATURE_W25QXX = (1 << 10), /*!< Board has W25QXX support */
|
||||
BSP_BOARD_FEATURE_DMA = (1 << 11), /*!< Board has DMA support */
|
||||
BSP_BOARD_FEATURE_ETH = (1 << 12), /*!< Board has ETH support */
|
||||
BSP_BOARD_FEATURE_USB = (1 << 13), /*!< Board has USB support */
|
||||
BSP_BOARD_FEATURE_SDIO = (1 << 14), /*!< Board has SDIO support */
|
||||
BSP_BOARD_FEATURE_FSMC = (1 << 15), /*!< Board has FSMC support */
|
||||
BSP_BOARD_FEATURE_LED = (1 << 0), /*!< 板级支持 LED */
|
||||
BSP_BOARD_FEATURE_BUTTON = (1 << 1), /*!< 板级支持按键 */
|
||||
BSP_BOARD_FEATURE_UART = (1 << 2), /*!< 板级支持 UART */
|
||||
BSP_BOARD_FEATURE_SPI = (1 << 3), /*!< 板级支持 SPI */
|
||||
BSP_BOARD_FEATURE_I2C = (1 << 4), /*!< 板级支持 I2C */
|
||||
BSP_BOARD_FEATURE_CAN = (1 << 5), /*!< 板级支持 CAN */
|
||||
BSP_BOARD_FEATURE_ADC = (1 << 6), /*!< 板级支持 ADC */
|
||||
BSP_BOARD_FEATURE_DAC = (1 << 7), /*!< 板级支持 DAC */
|
||||
BSP_BOARD_FEATURE_TIMER = (1 << 8), /*!< 板级支持 TIMER */
|
||||
BSP_BOARD_FEATURE_RTC = (1 << 9), /*!< 板级支持 RTC */
|
||||
BSP_BOARD_FEATURE_W25QXX = (1 << 10), /*!< 板级支持 W25QXX */
|
||||
BSP_BOARD_FEATURE_DMA = (1 << 11), /*!< 板级支持 DMA */
|
||||
BSP_BOARD_FEATURE_ETH = (1 << 12), /*!< 板级支持 ETH */
|
||||
BSP_BOARD_FEATURE_USB = (1 << 13), /*!< 板级支持 USB */
|
||||
BSP_BOARD_FEATURE_SDIO = (1 << 14), /*!< 板级支持 SDIO */
|
||||
BSP_BOARD_FEATURE_FSMC = (1 << 15), /*!< 板级支持 FSMC */
|
||||
} bsp_board_feature_t;
|
||||
|
||||
/**
|
||||
* @brief Board hardware information structure
|
||||
* @brief 板级硬件信息结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t clock_speed; /*!< Board clock speed */
|
||||
uint32_t flash_size; /*!< Flash size in bytes */
|
||||
uint32_t ram_size; /*!< RAM size in bytes */
|
||||
uint32_t eeprom_size; /*!< EEPROM size in bytes */
|
||||
uint32_t sram_size; /*!< SRAM size in bytes */
|
||||
uint8_t cpu_core; /*!< CPU core type */
|
||||
uint8_t cpu_bits; /*!< CPU bits (32 or 64) */
|
||||
uint32_t clock_speed; /*!< 板级时钟速度 */
|
||||
uint32_t flash_size; /*!< Flash 大小(字节) */
|
||||
uint32_t ram_size; /*!< RAM 大小(字节) */
|
||||
uint32_t eeprom_size; /*!< EEPROM 大小(字节) */
|
||||
uint32_t sram_size; /*!< SRAM 大小(字节) */
|
||||
uint8_t cpu_core; /*!< CPU 核心类型 */
|
||||
uint8_t cpu_bits; /*!< CPU 位数(32 或 64) */
|
||||
} bsp_board_hw_info_t;
|
||||
|
||||
/**
|
||||
* @brief Board peripheral configuration structure
|
||||
* @brief 板级外设配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
/* UART configurations */
|
||||
uint8_t uart_count; /*!< Number of UARTs */
|
||||
const bsp_uart_config_t* uarts; /*!< Pointer to UARTs configuration array */
|
||||
/* UART 配置 */
|
||||
uint8_t uart_count; /*!< UART 数量 */
|
||||
const bsp_uart_config_t* uarts; /*!< 指向 UART 配置数组的指针 */
|
||||
|
||||
/* SPI configurations */
|
||||
uint8_t spi_count; /*!< Number of SPIs */
|
||||
const bsp_spi_config_t* spis; /*!< Pointer to SPIs configuration array */
|
||||
/* SPI 配置 */
|
||||
uint8_t spi_count; /*!< SPI 数量 */
|
||||
const bsp_spi_config_t* spis; /*!< 指向 SPI 配置数组的指针 */
|
||||
|
||||
/* I2C configurations */
|
||||
uint8_t i2c_count; /*!< Number of I2Cs */
|
||||
const bsp_i2c_config_t* i2cs; /*!< Pointer to I2Cs configuration array */
|
||||
/* I2C 配置 */
|
||||
uint8_t i2c_count; /*!< I2C 数量 */
|
||||
const bsp_i2c_config_t* i2cs; /*!< 指向 I2C 配置数组的指针 */
|
||||
|
||||
/* CAN configurations */
|
||||
uint8_t can_count; /*!< Number of CANs */
|
||||
const bsp_can_config_t* cans; /*!< Pointer to CANs configuration array */
|
||||
/* CAN 配置 */
|
||||
uint8_t can_count; /*!< CAN 数量 */
|
||||
const bsp_can_config_t* cans; /*!< 指向 CAN 配置数组的指针 */
|
||||
|
||||
/* ADC configurations */
|
||||
uint8_t adc_count; /*!< Number of ADCs */
|
||||
const bsp_adc_config_t* adcs; /*!< Pointer to ADCs configuration array */
|
||||
/* ADC 配置 */
|
||||
uint8_t adc_count; /*!< ADC 数量 */
|
||||
const bsp_adc_config_t* adcs; /*!< 指向 ADC 配置数组的指针 */
|
||||
} bsp_board_periph_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board initialization function pointers structure
|
||||
* @brief 板级以太网配置结构体
|
||||
*/
|
||||
// bsp_eth_config_t 在 bsp_eth.h 中定义
|
||||
|
||||
/**
|
||||
* @brief 板级初始化函数指针结构体
|
||||
*/
|
||||
typedef struct {
|
||||
bsp_periph_init_func_t led_init; /*!< LED initialization function */
|
||||
bsp_periph_init_func_t button_init; /*!< Button initialization function */
|
||||
bsp_periph_init_func_t uart_init; /*!< UART initialization function */
|
||||
bsp_periph_init_func_t spi_init; /*!< SPI initialization function */
|
||||
bsp_periph_init_func_t i2c_init; /*!< I2C initialization function */
|
||||
bsp_periph_init_func_t can_init; /*!< CAN initialization function */
|
||||
bsp_periph_init_func_t adc_init; /*!< ADC initialization function */
|
||||
bsp_periph_init_func_t w25qxx_init; /*!< W25QXX initialization function */
|
||||
bsp_periph_init_func_t led_init; /*!< LED 初始化函数 */
|
||||
bsp_periph_init_func_t button_init; /*!< 按键初始化函数 */
|
||||
bsp_periph_init_func_t uart_init; /*!< UART 初始化函数 */
|
||||
bsp_periph_init_func_t spi_init; /*!< SPI 初始化函数 */
|
||||
bsp_periph_init_func_t i2c_init; /*!< I2C 初始化函数 */
|
||||
bsp_periph_init_func_t can_init; /*!< CAN 初始化函数 */
|
||||
bsp_periph_init_func_t adc_init; /*!< ADC 初始化函数 */
|
||||
bsp_periph_init_func_t w25qxx_init; /*!< W25QXX 初始化函数 */
|
||||
bsp_periph_init_func_t eth_init; /*!< 以太网初始化函数 */
|
||||
} bsp_board_init_funcs_t;
|
||||
|
||||
/**
|
||||
* @brief Board configuration structure
|
||||
* @brief 板级配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t version; /*!< Configuration version */
|
||||
const char* name; /*!< Board name */
|
||||
const char* description; /*!< Board description */
|
||||
bsp_board_id_t id; /*!< Board ID information */
|
||||
uint32_t version; /*!< 配置版本 */
|
||||
const char* name; /*!< 板级名称 */
|
||||
const char* description; /*!< 板级描述 */
|
||||
bsp_board_id_t id; /*!< 板级 ID 信息 */
|
||||
|
||||
/* Board features */
|
||||
uint32_t features; /*!< Board feature flags */
|
||||
/* 板级特性 */
|
||||
uint32_t features; /*!< 板级特性标志 */
|
||||
|
||||
/* Hardware information */
|
||||
bsp_board_hw_info_t hw_info; /*!< Hardware information */
|
||||
/* 硬件信息 */
|
||||
bsp_board_hw_info_t hw_info; /*!< 硬件信息 */
|
||||
|
||||
/* Peripheral configurations */
|
||||
bsp_leds_config_t leds; /*!< LEDs configuration */
|
||||
bsp_buttons_config_t buttons; /*!< Buttons configuration */
|
||||
bsp_w25qxx_config_t w25qxx; /*!< W25QXX configuration */
|
||||
/* 外设配置 */
|
||||
bsp_leds_config_t leds; /*!< LEDs 配置 */
|
||||
bsp_buttons_config_t buttons; /*!< 按键配置 */
|
||||
bsp_w25qxx_config_t w25qxx; /*!< W25QXX 配置 */
|
||||
bsp_eth_config_t eth; /*!< 以太网配置 */
|
||||
|
||||
/* Peripheral arrays */
|
||||
bsp_board_periph_config_t periphs; /*!< Peripheral configurations */
|
||||
/* 外设数组 */
|
||||
bsp_board_periph_config_t periphs; /*!< 外设配置 */
|
||||
|
||||
/* Initialization functions */
|
||||
bsp_board_init_funcs_t init_funcs; /*!< Initialization function pointers */
|
||||
/* 初始化函数 */
|
||||
bsp_board_init_funcs_t init_funcs; /*!< 初始化函数指针 */
|
||||
|
||||
/* Additional board-specific configuration */
|
||||
void* custom_config; /*!< Custom board configuration pointer */
|
||||
size_t custom_config_size; /*!< Custom board configuration size */
|
||||
/* 板级特定配置 */
|
||||
void* custom_config; /*!< 自定义板级配置指针 */
|
||||
size_t custom_config_size; /*!< 自定义板级配置大小 */
|
||||
|
||||
/* Board revision information */
|
||||
uint8_t major_rev; /*!< Major revision */
|
||||
uint8_t minor_rev; /*!< Minor revision */
|
||||
uint8_t patch_rev; /*!< Patch revision */
|
||||
const char* revision_desc; /*!< Revision description */
|
||||
/* 板级版本信息 */
|
||||
uint8_t major_rev; /*!< 主版本 */
|
||||
uint8_t minor_rev; /*!< 次版本 */
|
||||
uint8_t patch_rev; /*!< 补丁版本 */
|
||||
const char* revision_desc; /*!< 版本描述 */
|
||||
} bsp_board_config_t;
|
||||
|
||||
/**
|
||||
* @brief STM32F407VET6 board configuration extern declaration
|
||||
* @brief STM32F407VET6 板级配置外部声明
|
||||
*/
|
||||
extern const bsp_board_config_t stm32f407vet6_board_config;
|
||||
|
||||
/**
|
||||
* @brief Board hardware initialization
|
||||
* @retval HAL status code
|
||||
* @brief 板级硬件初始化
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_board_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get board name
|
||||
* @retval Board name string
|
||||
* @brief 获取板级名称
|
||||
* @retval 板级名称字符串
|
||||
*/
|
||||
const char* bsp_board_get_name(void);
|
||||
|
||||
/**
|
||||
* @brief Get board configuration
|
||||
* @retval Pointer to board configuration structure
|
||||
* @brief 获取板级配置
|
||||
* @retval 指向板级配置结构体的指针
|
||||
*/
|
||||
const bsp_board_config_t* bsp_board_get_config(void);
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_board_manager.h
|
||||
* @brief : Board support package manager header file
|
||||
* @brief : 板级支持包管理器头文件
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -15,48 +15,48 @@
|
||||
#include "bsp_board.h"
|
||||
|
||||
/**
|
||||
* @brief Get number of supported boards
|
||||
* @retval Number of supported boards
|
||||
* @brief 获取支持的板卡数量
|
||||
* @retval 支持的板卡数量
|
||||
*/
|
||||
uint8_t bsp_board_get_count(void);
|
||||
|
||||
/**
|
||||
* @brief Get board configuration by index
|
||||
* @param index: Board configuration index
|
||||
* @retval Pointer to board configuration structure, NULL if invalid index
|
||||
* @brief 通过索引获取板卡配置
|
||||
* @param index: 板卡配置索引
|
||||
* @retval 指向板卡配置结构体的指针,无效索引返回 NULL
|
||||
*/
|
||||
const bsp_board_config_t* bsp_board_get_by_index(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief Get board configuration by name
|
||||
* @param name: Board name string
|
||||
* @retval Pointer to board configuration structure, NULL if not found
|
||||
* @brief 通过名称获取板卡配置
|
||||
* @param name: 板卡名称字符串
|
||||
* @retval 指向板卡配置结构体的指针,未找到返回 NULL
|
||||
*/
|
||||
const bsp_board_config_t* bsp_board_get_by_name(const char* name);
|
||||
|
||||
/**
|
||||
* @brief Set current board configuration by index
|
||||
* @param index: Board configuration index
|
||||
* @retval HAL status code
|
||||
* @brief 通过索引设置当前板卡配置
|
||||
* @param index: 板卡配置索引
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_board_set_by_index(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief Set current board configuration by name
|
||||
* @param name: Board name string
|
||||
* @retval HAL status code
|
||||
* @brief 通过名称设置当前板卡配置
|
||||
* @param name: 板卡名称字符串
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_board_set_by_name(const char* name);
|
||||
|
||||
/**
|
||||
* @brief Get current board configuration
|
||||
* @retval Pointer to current board configuration structure
|
||||
* @brief 获取当前板卡配置
|
||||
* @retval 指向当前板卡配置结构体的指针
|
||||
*/
|
||||
const bsp_board_config_t* bsp_board_get_config(void);
|
||||
|
||||
/**
|
||||
* @brief Get current board index
|
||||
* @retval Current board index
|
||||
* @brief 获取当前板卡索引
|
||||
* @retval 当前板卡索引
|
||||
*/
|
||||
uint8_t bsp_board_get_current_index(void);
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_config.h
|
||||
* @brief : Board support package configuration file header
|
||||
* @brief : 板级支持包配置文件头文件
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -16,7 +16,7 @@
|
||||
#include "hal.h"
|
||||
|
||||
/**
|
||||
* @brief BSP configuration file format definitions
|
||||
* @brief BSP 配置文件格式定义
|
||||
*/
|
||||
#define BSP_CONFIG_FILE_VERSION "1.0.0"
|
||||
#define BSP_CONFIG_MAX_LINE_LENGTH 256
|
||||
@ -25,7 +25,7 @@
|
||||
#define BSP_CONFIG_MAX_VALUE_LENGTH 128
|
||||
|
||||
/**
|
||||
* @brief BSP configuration section type
|
||||
* @brief BSP 配置节类型
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_CONFIG_SECTION_NONE = 0,
|
||||
@ -36,7 +36,7 @@ typedef enum {
|
||||
} bsp_config_section_t;
|
||||
|
||||
/**
|
||||
* @brief BSP configuration entry
|
||||
* @brief BSP 配置条目
|
||||
*/
|
||||
typedef struct {
|
||||
const char* section;
|
||||
@ -45,7 +45,7 @@ typedef struct {
|
||||
} bsp_config_entry_t;
|
||||
|
||||
/**
|
||||
* @brief BSP configuration parser context
|
||||
* @brief BSP 配置解析器上下文
|
||||
*/
|
||||
typedef struct {
|
||||
FILE* file;
|
||||
@ -56,7 +56,7 @@ typedef struct {
|
||||
} bsp_config_parser_t;
|
||||
|
||||
/**
|
||||
* @brief BSP configuration file operations
|
||||
* @brief BSP 配置文件操作
|
||||
*/
|
||||
typedef struct {
|
||||
hal_ret_t (*open)(const char* filename, bsp_config_parser_t* parser);
|
||||
@ -69,115 +69,115 @@ typedef struct {
|
||||
} bsp_config_ops_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize BSP configuration system
|
||||
* @retval HAL status code
|
||||
* @brief 初始化 BSP 配置系统
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_init(void);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize BSP configuration system
|
||||
* @retval HAL status code
|
||||
* @brief 反初始化 BSP 配置系统
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Load BSP configuration from file
|
||||
* @param filename: Configuration file name
|
||||
* @retval HAL status code
|
||||
* @brief 从文件加载 BSP 配置
|
||||
* @param filename: 配置文件名称
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_load(const char* filename);
|
||||
|
||||
/**
|
||||
* @brief Save BSP configuration to file
|
||||
* @param filename: Configuration file name
|
||||
* @retval HAL status code
|
||||
* @brief 保存 BSP 配置到文件
|
||||
* @param filename: 配置文件名称
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
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
|
||||
* @brief 获取配置值
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 存储值的指针
|
||||
* @param max_length: 值缓冲区的最大长度
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
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
|
||||
* @brief 设置配置值
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 配置值
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
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
|
||||
* @brief 获取配置值作为整数
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 存储整数值的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
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
|
||||
* @brief 设置配置值作为整数
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 整数值
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
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
|
||||
* @brief 获取配置值作为无符号整数
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 存储无符号整数值的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
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
|
||||
* @brief 设置配置值作为无符号整数
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 无符号整数值
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
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
|
||||
* @brief 获取配置值作为布尔值
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 存储布尔值的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
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
|
||||
* @brief 设置配置值作为布尔值
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 布尔值
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
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
|
||||
* @brief 从配置解析 BSP 模块
|
||||
* @param config: 指向要填充的 BSP 板卡配置结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
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
|
||||
* @brief 从配置文件初始化 BSP
|
||||
* @param filename: 配置文件名称
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_init_from_config(const char* filename);
|
||||
|
||||
|
||||
169
BSP/Inc/bsp_eth.h
Normal file
169
BSP/Inc/bsp_eth.h
Normal file
@ -0,0 +1,169 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_eth.h
|
||||
* @brief : 板级支持包以太网(LAN8720)驱动头文件
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef BSP_ETH_H
|
||||
#define BSP_ETH_H
|
||||
|
||||
#include "hal.h"
|
||||
#include "hal_eth.h"
|
||||
|
||||
/**
|
||||
* @brief LAN8720 PHY 地址定义
|
||||
*/
|
||||
#define LAN8720_PHY_ADDR 0x00
|
||||
|
||||
/**
|
||||
* @brief LAN8720 PHY 寄存器定义
|
||||
*/
|
||||
#define LAN8720_REG_BSR 0x01 /*!< 基本状态寄存器 */
|
||||
#define LAN8720_REG_BCR 0x00 /*!< 基本控制寄存器 */
|
||||
#define LAN8720_REG_PID1 0x02 /*!< PHY 标识符 1 */
|
||||
#define LAN8720_REG_PID2 0x03 /*!< PHY 标识符 2 */
|
||||
#define LAN8720_REG_ANAR 0x04 /*!< 自动协商通告寄存器 */
|
||||
#define LAN8720_REG_ANLPAR 0x05 /*!< 自动协商链路伙伴能力寄存器 */
|
||||
#define LAN8720_REG_ANER 0x06 /*!< 自动协商扩展寄存器 */
|
||||
#define LAN8720_REG_DR 0x0E /*!< 设备修订寄存器 */
|
||||
#define LAN8720_REG_CR 0x10 /*!< 控制寄存器 */
|
||||
#define LAN8720_REG_SR 0x11 /*!< 状态寄存器 */
|
||||
|
||||
/**
|
||||
* @brief LAN8720 BSR 寄存器位定义
|
||||
*/
|
||||
#define LAN8720_BSR_LINK_STATUS (1 << 2) /*!< 链路状态位 */
|
||||
#define LAN8720_BSR_AUTO_NEG_COMPLETE (1 << 5) /*!< 自动协商完成 */
|
||||
#define LAN8720_BSR_100BASE_T4 (1 << 11) /*!< 支持 100BASE-T4 */
|
||||
#define LAN8720_BSR_100BASE_TX_FD (1 << 12) /*!< 支持 100BASE-TX 全双工 */
|
||||
#define LAN8720_BSR_100BASE_TX_HD (1 << 13) /*!< 支持 100BASE-TX 半双工 */
|
||||
#define LAN8720_BSR_10BASE_T_FD (1 << 14) /*!< 支持 10BASE-T 全双工 */
|
||||
#define LAN8720_BSR_10BASE_T_HD (1 << 15) /*!< 支持 10BASE-T 半双工 */
|
||||
|
||||
/**
|
||||
* @brief LAN8720 BCR 寄存器位定义
|
||||
*/
|
||||
#define LAN8720_BCR_RESET (1 << 15) /*!< 软件复位 */
|
||||
#define LAN8720_BCR_AUTO_NEG_EN (1 << 12) /*!< 自动协商使能 */
|
||||
#define LAN8720_BCR_SPEED_SELECT (1 << 13) /*!< 速度选择 (1=100Mbps, 0=10Mbps) */
|
||||
#define LAN8720_BCR_DUPLEX_MODE (1 << 8) /*!< 双工模式 (1=全双工, 0=半双工) */
|
||||
#define LAN8720_BCR_RESTART_AN (1 << 9) /*!< 重启自动协商 */
|
||||
|
||||
/**
|
||||
* @brief LAN8720 PHY 标识符
|
||||
*/
|
||||
#define LAN8720_PID1_VALUE 0x0007
|
||||
#define LAN8720_PID2_VALUE 0xC0F0
|
||||
|
||||
/**
|
||||
* @brief 以太网配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< 以太网使能标志 */
|
||||
hal_eth_instance_t instance; /*!< 以太网实例 */
|
||||
hal_eth_mode_t mode; /*!< 以太网模式 */
|
||||
hal_eth_speed_t speed; /*!< 以太网速度 */
|
||||
hal_eth_phy_addr_t phy_addr; /*!< PHY 地址 */
|
||||
hal_eth_mac_addr_t mac_addr; /*!< MAC 地址 */
|
||||
uint8_t auto_negotiation; /*!< 自动协商使能标志 */
|
||||
uint8_t interrupt_enable; /*!< 中断使能标志 */
|
||||
} bsp_eth_config_t;
|
||||
|
||||
/**
|
||||
* @brief 以太网状态结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t link_up; /*!< 链路状态 */
|
||||
uint8_t duplex; /*!< 双工模式 (0: 半双工, 1: 全双工) */
|
||||
uint32_t speed; /*!< 速度 (Mbps) */
|
||||
uint32_t rx_packets; /*!< 接收数据包计数 */
|
||||
uint32_t tx_packets; /*!< 发送数据包计数 */
|
||||
uint32_t rx_errors; /*!< 接收错误计数 */
|
||||
uint32_t tx_errors; /*!< 发送错误计数 */
|
||||
uint16_t phy_id1; /*!< PHY 标识符 1 */
|
||||
uint16_t phy_id2; /*!< PHY 标识符 2 */
|
||||
} bsp_eth_status_t;
|
||||
|
||||
/**
|
||||
* @brief 初始化以太网(LAN8720)模块
|
||||
* @param config: 指向以太网配置结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_eth_init(const bsp_eth_config_t* config);
|
||||
|
||||
/**
|
||||
* @brief 反初始化以太网(LAN8720)模块
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_eth_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief 获取以太网(LAN8720)状态
|
||||
* @param status: 指向以太网状态结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_eth_get_status(bsp_eth_status_t* status);
|
||||
|
||||
/**
|
||||
* @brief 设置以太网 MAC 地址
|
||||
* @param mac_addr: 指向 MAC 地址结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_eth_set_mac_addr(const hal_eth_mac_addr_t* mac_addr);
|
||||
|
||||
/**
|
||||
* @brief 获取以太网 MAC 地址
|
||||
* @param mac_addr: 指向 MAC 地址结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_eth_get_mac_addr(hal_eth_mac_addr_t* mac_addr);
|
||||
|
||||
/**
|
||||
* @brief 检查以太网链路状态
|
||||
* @param link_up: 存储链路状态的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_eth_check_link(uint8_t* link_up);
|
||||
|
||||
/**
|
||||
* @brief 复位以太网 PHY(LAN8720)
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_eth_reset_phy(void);
|
||||
|
||||
/**
|
||||
* @brief 读取 LAN8720 PHY 寄存器
|
||||
* @param reg_addr: 寄存器地址
|
||||
* @param value: 存储寄存器值的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_eth_read_phy_reg(uint16_t reg_addr, uint16_t* value);
|
||||
|
||||
/**
|
||||
* @brief 写入 LAN8720 PHY 寄存器
|
||||
* @param reg_addr: 寄存器地址
|
||||
* @param value: 寄存器值
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_eth_write_phy_reg(uint16_t reg_addr, uint16_t value);
|
||||
|
||||
/**
|
||||
* @brief 检测 LAN8720 PHY 存在
|
||||
* @param detected: 存储检测结果的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_eth_detect_phy(uint8_t* detected);
|
||||
|
||||
/**
|
||||
* @brief 配置 LAN8720 PHY
|
||||
* @param mode: 以太网模式
|
||||
* @param speed: 以太网速度
|
||||
* @param auto_neg: 自动协商使能
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_eth_configure_phy(hal_eth_mode_t mode, hal_eth_speed_t speed, uint8_t auto_neg);
|
||||
|
||||
#endif /* BSP_ETH_H */
|
||||
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_init.h
|
||||
* @brief : Board support package initialization header file
|
||||
* @brief : 板级支持包初始化头文件
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -13,26 +13,26 @@
|
||||
#include "bsp_board.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize board support package
|
||||
* @retval HAL status code
|
||||
* @brief 初始化板级支持包
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_init(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize board GPIO
|
||||
* @retval HAL status code
|
||||
* @brief 初始化板级 GPIO
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_gpio_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get board name
|
||||
* @retval Board name string
|
||||
* @brief 获取板级名称
|
||||
* @retval 板级名称字符串
|
||||
*/
|
||||
const char* bsp_get_board_name(void);
|
||||
|
||||
/**
|
||||
* @brief Get current board configuration
|
||||
* @retval Pointer to board configuration structure
|
||||
* @brief 获取当前板级配置
|
||||
* @retval 指向板级配置结构体的指针
|
||||
*/
|
||||
const bsp_board_config_t* bsp_get_board_config(void);
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_key.h
|
||||
* @brief : Board support package key driver header file
|
||||
* @brief : 板级支持包按键驱动头文件
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -13,7 +13,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Key ID definitions
|
||||
* @brief 按键 ID 定义
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_KEY_ID_KEY0 = 0,
|
||||
@ -23,7 +23,7 @@ typedef enum {
|
||||
} bsp_key_id_t;
|
||||
|
||||
/**
|
||||
* @brief Key state definitions
|
||||
* @brief 按键状态定义
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_KEY_STATE_RELEASED = 0,
|
||||
@ -31,80 +31,80 @@ typedef enum {
|
||||
} bsp_key_state_t;
|
||||
|
||||
/**
|
||||
* @brief Key event definitions
|
||||
* @brief 按键事件定义
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_KEY_EVENT_NONE = 0,
|
||||
BSP_KEY_EVENT_PRESSED, /* Key pressed event */
|
||||
BSP_KEY_EVENT_RELEASED, /* Key released event */
|
||||
BSP_KEY_EVENT_LONG_PRESSED, /* Key long pressed event */
|
||||
BSP_KEY_EVENT_REPEAT, /* Key repeat event */
|
||||
BSP_KEY_EVENT_SHORT_PRESSED /* Key short pressed event */
|
||||
BSP_KEY_EVENT_PRESSED, /* 按键按下事件 */
|
||||
BSP_KEY_EVENT_RELEASED, /* 按键释放事件 */
|
||||
BSP_KEY_EVENT_LONG_PRESSED, /* 按键长按事件 */
|
||||
BSP_KEY_EVENT_REPEAT, /* 按键重复事件 */
|
||||
BSP_KEY_EVENT_SHORT_PRESSED /* 按键短按事件 */
|
||||
} bsp_key_event_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize all keys
|
||||
* @brief 初始化所有按键
|
||||
*/
|
||||
void bsp_key_init(void);
|
||||
|
||||
/**
|
||||
* @brief Update key state (call this function periodically, e.g. every 10ms)
|
||||
* @brief 更新按键状态(定期调用此函数,例如每 10ms)
|
||||
*/
|
||||
void bsp_key_update(void);
|
||||
|
||||
/**
|
||||
* @brief Read debounced key state
|
||||
* @param key_id: Key ID
|
||||
* @retval Key state
|
||||
* @brief 读取去抖后的按键状态
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 按键状态
|
||||
*/
|
||||
bsp_key_state_t bsp_key_read(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check if key is pressed
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if pressed, 0 otherwise
|
||||
* @brief 检查按键是否按下
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 按下返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_is_pressed(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check if key is released
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if released, 0 otherwise
|
||||
* @brief 检查按键是否释放
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 释放返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_is_released(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check for key press event (edge detection)
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key was pressed, 0 otherwise
|
||||
* @brief 检查按键按下事件(边沿检测)
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 按键按下返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_get_press_event(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check for key release event (edge detection)
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key was released, 0 otherwise
|
||||
* @brief 检查按键释放事件(边沿检测)
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 按键释放返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_get_release_event(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check for key long pressed event
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key was long pressed, 0 otherwise
|
||||
* @brief 检查按键长按事件
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 按键长按返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_get_long_press_event(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check for key repeat event
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key repeat event occurred, 0 otherwise
|
||||
* @brief 检查按键重复事件
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 按键重复事件发生返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_get_repeat_event(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check for key short pressed event
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key was short pressed, 0 otherwise
|
||||
* @brief 检查按键短按事件
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 按键短按返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_get_short_press_event(bsp_key_id_t key_id);
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_module.h
|
||||
* @brief : Board support package module management header file
|
||||
* @brief : 板级支持包模块管理头文件
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -13,7 +13,7 @@
|
||||
#include "hal.h"
|
||||
|
||||
/**
|
||||
* @brief BSP module type definitions
|
||||
* @brief BSP 模块类型定义
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_MODULE_TYPE_LED = 0,
|
||||
@ -31,7 +31,7 @@ typedef enum {
|
||||
} bsp_module_type_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module state definitions
|
||||
* @brief BSP 模块状态定义
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_MODULE_STATE_UNINIT = 0,
|
||||
@ -42,7 +42,7 @@ typedef enum {
|
||||
} bsp_module_state_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module priority definitions
|
||||
* @brief BSP 模块优先级定义
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_MODULE_PRIORITY_HIGHEST = 0,
|
||||
@ -53,36 +53,36 @@ typedef enum {
|
||||
} bsp_module_priority_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module configuration structure
|
||||
* @brief BSP 模块配置结构体
|
||||
*/
|
||||
typedef struct bsp_module_config {
|
||||
bsp_module_type_t type; /*!< Module type */
|
||||
const char* name; /*!< Module name */
|
||||
bsp_module_priority_t priority; /*!< Module priority */
|
||||
uint32_t version; /*!< Module version */
|
||||
uint8_t instance; /*!< Module instance */
|
||||
uint8_t enable; /*!< Module enable flag */
|
||||
void* config_data; /*!< Module configuration data */
|
||||
size_t config_size; /*!< Module configuration size */
|
||||
uint32_t dependencies; /*!< Module dependencies bitmask */
|
||||
bsp_module_type_t type; /*!< 模块类型 */
|
||||
const char* name; /*!< 模块名称 */
|
||||
bsp_module_priority_t priority; /*!< 模块优先级 */
|
||||
uint32_t version; /*!< 模块版本 */
|
||||
uint8_t instance; /*!< 模块实例 */
|
||||
uint8_t enable; /*!< 模块使能标志 */
|
||||
void* config_data; /*!< 模块配置数据 */
|
||||
size_t config_size; /*!< 模块配置大小 */
|
||||
uint32_t dependencies; /*!< 模块依赖位掩码 */
|
||||
} bsp_module_config_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module operations structure
|
||||
* @brief BSP 模块操作结构体
|
||||
*/
|
||||
typedef struct {
|
||||
hal_ret_t (*init)(void* config); /*!< Module initialization function */
|
||||
hal_ret_t (*deinit)(void); /*!< Module deinitialization function */
|
||||
hal_ret_t (*configure)(void* config); /*!< Module configuration function */
|
||||
hal_ret_t (*start)(void); /*!< Module start function */
|
||||
hal_ret_t (*stop)(void); /*!< Module stop function */
|
||||
hal_ret_t (*reset)(void); /*!< Module reset function */
|
||||
bsp_module_state_t (*get_state)(void); /*!< Module get state function */
|
||||
hal_ret_t (*control)(uint32_t cmd, void* param); /*!< Module control function */
|
||||
hal_ret_t (*init)(void* config); /*!< 模块初始化函数 */
|
||||
hal_ret_t (*deinit)(void); /*!< 模块反初始化函数 */
|
||||
hal_ret_t (*configure)(void* config); /*!< 模块配置函数 */
|
||||
hal_ret_t (*start)(void); /*!< 模块启动函数 */
|
||||
hal_ret_t (*stop)(void); /*!< 模块停止函数 */
|
||||
hal_ret_t (*reset)(void); /*!< 模块复位函数 */
|
||||
bsp_module_state_t (*get_state)(void); /*!< 模块获取状态函数 */
|
||||
hal_ret_t (*control)(uint32_t cmd, void* param); /*!< 模块控制函数 */
|
||||
} bsp_module_ops_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module version structure
|
||||
* @brief BSP 模块版本结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t major;
|
||||
@ -91,42 +91,42 @@ typedef struct {
|
||||
} bsp_module_version_t;
|
||||
|
||||
/**
|
||||
* @brief Forward declaration of bsp_module_t
|
||||
* @brief bsp_module_t 的前向声明
|
||||
*/
|
||||
typedef struct bsp_module bsp_module_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module event callback type
|
||||
* @brief BSP 模块事件回调类型
|
||||
*/
|
||||
typedef hal_ret_t (*bsp_module_event_callback_t)(const bsp_module_t* sender, uint32_t event, void* data);
|
||||
|
||||
/**
|
||||
* @brief BSP module structure
|
||||
* @brief BSP 模块结构体
|
||||
*/
|
||||
typedef struct bsp_module {
|
||||
bsp_module_config_t config; /*!< Module configuration */
|
||||
bsp_module_ops_t ops; /*!< Module operations */
|
||||
bsp_module_state_t state; /*!< Module state */
|
||||
bsp_module_version_t version; /*!< Module version */
|
||||
struct bsp_module* next; /*!< Pointer to next module in the list */
|
||||
struct bsp_module* prev; /*!< Pointer to previous module in the list */
|
||||
void* private_data; /*!< Module private data */
|
||||
bsp_module_event_callback_t event_callback; /*!< Event callback */
|
||||
bsp_module_config_t config; /*!< 模块配置 */
|
||||
bsp_module_ops_t ops; /*!< 模块操作 */
|
||||
bsp_module_state_t state; /*!< 模块状态 */
|
||||
bsp_module_version_t version; /*!< 模块版本 */
|
||||
struct bsp_module* next; /*!< 链表中下一个模块的指针 */
|
||||
struct bsp_module* prev; /*!< 链表中上一个模块的指针 */
|
||||
void* private_data; /*!< 模块私有数据 */
|
||||
bsp_module_event_callback_t event_callback; /*!< 事件回调 */
|
||||
} bsp_module_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module event definitions
|
||||
* @brief BSP 模块事件定义
|
||||
*/
|
||||
#define BSP_MODULE_EVENT_INIT (1 << 0) /*!< Module initialized */
|
||||
#define BSP_MODULE_EVENT_DEINIT (1 << 1) /*!< Module deinitialized */
|
||||
#define BSP_MODULE_EVENT_START (1 << 2) /*!< Module started */
|
||||
#define BSP_MODULE_EVENT_STOP (1 << 3) /*!< Module stopped */
|
||||
#define BSP_MODULE_EVENT_ERROR (1 << 4) /*!< Module error */
|
||||
#define BSP_MODULE_EVENT_CONFIG (1 << 5) /*!< Module configured */
|
||||
#define BSP_MODULE_EVENT_CUSTOM (1 << 8) /*!< Custom module event base */
|
||||
#define BSP_MODULE_EVENT_INIT (1 << 0) /*!< 模块已初始化 */
|
||||
#define BSP_MODULE_EVENT_DEINIT (1 << 1) /*!< 模块已反初始化 */
|
||||
#define BSP_MODULE_EVENT_START (1 << 2) /*!< 模块已启动 */
|
||||
#define BSP_MODULE_EVENT_STOP (1 << 3) /*!< 模块已停止 */
|
||||
#define BSP_MODULE_EVENT_ERROR (1 << 4) /*!< 模块错误 */
|
||||
#define BSP_MODULE_EVENT_CONFIG (1 << 5) /*!< 模块已配置 */
|
||||
#define BSP_MODULE_EVENT_CUSTOM (1 << 8) /*!< 自定义模块事件基础 */
|
||||
|
||||
/**
|
||||
* @brief BSP module auto-registration macros
|
||||
* @brief BSP 模块自动注册宏
|
||||
*/
|
||||
#define BSP_MODULE_REGISTER(module) \
|
||||
static const bsp_module_config_t __bsp_module_##module##_config = { \
|
||||
@ -173,228 +173,228 @@ typedef struct bsp_module {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BSP module manager structure
|
||||
* @brief BSP 模块管理器结构体
|
||||
*/
|
||||
typedef struct {
|
||||
bsp_module_t* modules[BSP_MODULE_TYPE_MAX]; /*!< Modules by type */
|
||||
bsp_module_t* module_list; /*!< Linked list of all modules */
|
||||
uint32_t module_count; /*!< Total number of modules */
|
||||
bsp_module_t* modules[BSP_MODULE_TYPE_MAX]; /*!< 按类型存储的模块 */
|
||||
bsp_module_t* module_list; /*!< 所有模块的链表 */
|
||||
uint32_t module_count; /*!< 模块总数 */
|
||||
} bsp_module_manager_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize BSP module manager
|
||||
* @retval HAL status code
|
||||
* @brief 初始化 BSP 模块管理器
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_manager_init(void);
|
||||
|
||||
/**
|
||||
* @brief Register a BSP module
|
||||
* @param module: Pointer to module structure
|
||||
* @retval HAL status code
|
||||
* @brief 注册一个 BSP 模块
|
||||
* @param module: 指向模块结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_register(bsp_module_t* module);
|
||||
|
||||
/**
|
||||
* @brief Unregister a BSP module
|
||||
* @param module: Pointer to module structure
|
||||
* @retval HAL status code
|
||||
* @brief 注销一个 BSP 模块
|
||||
* @param module: 指向模块结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_unregister(bsp_module_t* module);
|
||||
|
||||
/**
|
||||
* @brief Initialize all registered BSP modules
|
||||
* @retval HAL status code
|
||||
* @brief 初始化所有注册的 BSP 模块
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_init_all(void);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize all registered BSP modules
|
||||
* @retval HAL status code
|
||||
* @brief 反初始化所有注册的 BSP 模块
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_deinit_all(void);
|
||||
|
||||
/**
|
||||
* @brief Start all registered BSP modules
|
||||
* @retval HAL status code
|
||||
* @brief 启动所有注册的 BSP 模块
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_start_all(void);
|
||||
|
||||
/**
|
||||
* @brief Stop all registered BSP modules
|
||||
* @retval HAL status code
|
||||
* @brief 停止所有注册的 BSP 模块
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_stop_all(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @retval HAL status code
|
||||
* @brief 初始化指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_init(bsp_module_type_t type, uint8_t instance);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @retval HAL status code
|
||||
* @brief 反初始化指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_deinit(bsp_module_type_t type, uint8_t instance);
|
||||
|
||||
/**
|
||||
* @brief Configure a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param config: Module configuration data
|
||||
* @param size: Module configuration size
|
||||
* @retval HAL status code
|
||||
* @brief 配置指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param config: 模块配置数据
|
||||
* @param size: 模块配置大小
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_configure(bsp_module_type_t type, uint8_t instance, void* config, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Start a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @retval HAL status code
|
||||
* @brief 启动指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_start(bsp_module_type_t type, uint8_t instance);
|
||||
|
||||
/**
|
||||
* @brief Stop a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @retval HAL status code
|
||||
* @brief 停止指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_stop(bsp_module_type_t type, uint8_t instance);
|
||||
|
||||
/**
|
||||
* @brief Reset a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @retval HAL status code
|
||||
* @brief 复位指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_reset(bsp_module_type_t type, uint8_t instance);
|
||||
|
||||
/**
|
||||
* @brief Get state of a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param state: Pointer to store module state
|
||||
* @retval HAL status code
|
||||
* @brief 获取指定 BSP 模块的状态
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param state: 存储模块状态的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_get_state(bsp_module_type_t type, uint8_t instance, bsp_module_state_t* state);
|
||||
|
||||
/**
|
||||
* @brief Control a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param cmd: Control command
|
||||
* @param param: Control parameter
|
||||
* @retval HAL status code
|
||||
* @brief 控制指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param cmd: 控制命令
|
||||
* @param param: 控制参数
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_control(bsp_module_type_t type, uint8_t instance, uint32_t cmd, void* param);
|
||||
|
||||
/**
|
||||
* @brief Get a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @retval Pointer to module structure, or NULL if not found
|
||||
* @brief 获取指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @retval 指向模块结构体的指针,未找到返回 NULL
|
||||
*/
|
||||
bsp_module_t* bsp_module_get(bsp_module_type_t type, uint8_t instance);
|
||||
|
||||
/**
|
||||
* @brief Get all modules of a specific type
|
||||
* @param type: Module type
|
||||
* @retval Pointer to module list, or NULL if no modules found
|
||||
* @brief 获取指定类型的所有模块
|
||||
* @param type: 模块类型
|
||||
* @retval 指向模块列表的指针,未找到模块返回 NULL
|
||||
*/
|
||||
bsp_module_t* bsp_module_get_by_type(bsp_module_type_t type);
|
||||
|
||||
/**
|
||||
* @brief Get module by name
|
||||
* @param name: Module name
|
||||
* @retval Pointer to module structure, or NULL if not found
|
||||
* @brief 通过名称获取模块
|
||||
* @param name: 模块名称
|
||||
* @retval 指向模块结构体的指针,未找到返回 NULL
|
||||
*/
|
||||
bsp_module_t* bsp_module_get_by_name(const char* name);
|
||||
|
||||
/**
|
||||
* @brief Get total number of registered modules
|
||||
* @retval Number of registered modules
|
||||
* @brief 获取注册模块的总数
|
||||
* @retval 注册模块的数量
|
||||
*/
|
||||
uint32_t bsp_module_get_count(void);
|
||||
|
||||
/**
|
||||
* @brief Check if all dependencies of a module are satisfied
|
||||
* @param module: Pointer to module structure
|
||||
* @retval HAL status code
|
||||
* @brief 检查模块的所有依赖是否满足
|
||||
* @param module: 指向模块结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_check_dependencies(const bsp_module_t* module);
|
||||
|
||||
/**
|
||||
* @brief Get module manager instance
|
||||
* @retval Pointer to module manager structure
|
||||
* @brief 获取模块管理器实例
|
||||
* @retval 指向模块管理器结构体的指针
|
||||
*/
|
||||
bsp_module_manager_t* bsp_module_get_manager(void);
|
||||
|
||||
/**
|
||||
* @brief Register a module event callback
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param callback: Event callback function
|
||||
* @retval HAL status code
|
||||
* @brief 注册模块事件回调
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param callback: 事件回调函数
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_register_event_callback(bsp_module_type_t type, uint8_t instance, bsp_module_event_callback_t callback);
|
||||
|
||||
/**
|
||||
* @brief Trigger a module event
|
||||
* @param module: Pointer to module structure
|
||||
* @param event: Event to trigger
|
||||
* @param data: Event data
|
||||
* @retval HAL status code
|
||||
* @brief 触发模块事件
|
||||
* @param module: 指向模块结构体的指针
|
||||
* @param event: 要触发的事件
|
||||
* @param data: 事件数据
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_trigger_event(const bsp_module_t* module, uint32_t event, void* data);
|
||||
|
||||
/**
|
||||
* @brief Find modules by priority range
|
||||
* @param min_priority: Minimum priority
|
||||
* @param max_priority: Maximum priority
|
||||
* @param count: Pointer to store number of modules found
|
||||
* @retval Pointer to array of module pointers, or NULL if no modules found
|
||||
* @brief 按优先级范围查找模块
|
||||
* @param min_priority: 最低优先级
|
||||
* @param max_priority: 最高优先级
|
||||
* @param count: 存储找到的模块数量的指针
|
||||
* @retval 指向模块指针数组的指针,未找到模块返回 NULL
|
||||
*/
|
||||
bsp_module_t** bsp_module_find_by_priority_range(bsp_module_priority_t min_priority, bsp_module_priority_t max_priority, uint32_t* count);
|
||||
|
||||
/**
|
||||
* @brief Set module enable/disable state
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param enable: Enable flag
|
||||
* @retval HAL status code
|
||||
* @brief 设置模块使能/禁用状态
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param enable: 使能标志
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_set_enable(bsp_module_type_t type, uint8_t instance, uint8_t enable);
|
||||
|
||||
/**
|
||||
* @brief Check if module is enabled
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param enable: Pointer to store enable state
|
||||
* @retval HAL status code
|
||||
* @brief 检查模块是否启用
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param enable: 存储使能状态的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_is_enabled(bsp_module_type_t type, uint8_t instance, uint8_t* enable);
|
||||
|
||||
/**
|
||||
* @brief Set module priority
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param priority: New priority
|
||||
* @retval HAL status code
|
||||
* @brief 设置模块优先级
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param priority: 新优先级
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_set_priority(bsp_module_type_t type, uint8_t instance, bsp_module_priority_t priority);
|
||||
|
||||
/**
|
||||
* @brief Get module priority
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param priority: Pointer to store priority
|
||||
* @retval HAL return code
|
||||
* @brief 获取模块优先级
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param priority: 存储优先级的指针
|
||||
* @retval HAL 返回码
|
||||
*/
|
||||
hal_ret_t bsp_module_get_priority(bsp_module_type_t type, uint8_t instance, bsp_module_priority_t* priority);
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_w25qxx.h
|
||||
* @brief : BSP layer for W25QXX flash memory
|
||||
* @brief : W25QXX 闪存芯片的 BSP 层头文件
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -15,71 +15,71 @@
|
||||
#include "hal_gpio.h"
|
||||
|
||||
/**
|
||||
* @brief W25QXX chip select pin configuration
|
||||
* @brief W25QXX 芯片选择引脚配置
|
||||
*/
|
||||
#define W25QXX_CS_PORT HAL_GPIO_PORT_B
|
||||
#define W25QXX_CS_PIN HAL_GPIO_PIN_0
|
||||
|
||||
/**
|
||||
* @brief W25QXX SPI instance
|
||||
* @brief W25QXX SPI 实例
|
||||
*/
|
||||
#define W25QXX_SPI_INSTANCE HAL_SPI_INSTANCE_1
|
||||
|
||||
/**
|
||||
* @brief Initialize W25QXX flash memory
|
||||
* @retval true if initialization is successful, false otherwise
|
||||
* @brief 初始化 W25QXX 闪存芯片
|
||||
* @retval 初始化成功返回 true,失败返回 false
|
||||
*/
|
||||
bool bsp_w25qxx_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get W25QXX device information
|
||||
* @param info Pointer to device information structure to fill
|
||||
* @retval true if successful, false otherwise
|
||||
* @brief 获取 W25QXX 设备信息
|
||||
* @param info 指向设备信息结构体的指针
|
||||
* @retval 成功返回 true,失败返回 false
|
||||
*/
|
||||
bool bsp_w25qxx_get_device_info(w25qxx_device_info_t *info);
|
||||
|
||||
/**
|
||||
* @brief Read data from W25QXX flash memory
|
||||
* @param address Starting address to read from
|
||||
* @param data Pointer to data buffer to store read data
|
||||
* @param size Size of data to read
|
||||
* @retval true if read is successful, false otherwise
|
||||
* @brief 从 W25QXX 闪存芯片读取数据
|
||||
* @param address 起始读取地址
|
||||
* @param data 存储读取数据的缓冲区指针
|
||||
* @param size 要读取的数据大小
|
||||
* @retval 读取成功返回 true,失败返回 false
|
||||
*/
|
||||
bool bsp_w25qxx_read(uint32_t address, uint8_t *data, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Write data to W25QXX flash memory
|
||||
* @param address Starting address to write to
|
||||
* @param data Pointer to data buffer to write
|
||||
* @param size Size of data to write
|
||||
* @retval true if write is successful, false otherwise
|
||||
* @brief 向 W25QXX 闪存芯片写入数据
|
||||
* @param address 起始写入地址
|
||||
* @param data 要写入的数据缓冲区指针
|
||||
* @param size 要写入的数据大小
|
||||
* @retval 写入成功返回 true,失败返回 false
|
||||
*/
|
||||
bool bsp_w25qxx_write(uint32_t address, const uint8_t *data, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Erase 4KB block
|
||||
* @param address Address within the block to erase
|
||||
* @retval true if erase is successful, false otherwise
|
||||
* @brief 擦除 4KB 块
|
||||
* @param address 块内的地址
|
||||
* @retval 擦除成功返回 true,失败返回 false
|
||||
*/
|
||||
bool bsp_w25qxx_erase_block_4kb(uint32_t address);
|
||||
|
||||
/**
|
||||
* @brief Erase 32KB block
|
||||
* @param address Address within the block to erase
|
||||
* @retval true if erase is successful, false otherwise
|
||||
* @brief 擦除 32KB 块
|
||||
* @param address 块内的地址
|
||||
* @retval 擦除成功返回 true,失败返回 false
|
||||
*/
|
||||
bool bsp_w25qxx_erase_block_32kb(uint32_t address);
|
||||
|
||||
/**
|
||||
* @brief Erase 64KB block
|
||||
* @param address Address within the block to erase
|
||||
* @retval true if erase is successful, false otherwise
|
||||
* @brief 擦除 64KB 块
|
||||
* @param address 块内的地址
|
||||
* @retval 擦除成功返回 true,失败返回 false
|
||||
*/
|
||||
bool bsp_w25qxx_erase_block_64kb(uint32_t address);
|
||||
|
||||
/**
|
||||
* @brief Erase entire chip
|
||||
* @retval true if erase is successful, false otherwise
|
||||
* @brief 擦除整个芯片
|
||||
* @retval 擦除成功返回 true,失败返回 false
|
||||
*/
|
||||
bool bsp_w25qxx_erase_chip(void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user