准备驱动移植适配Rust

This commit is contained in:
冯佳
2026-01-29 15:08:30 +08:00
parent e879b18602
commit 1bdeca55ea
68 changed files with 4371 additions and 4392 deletions

View File

@ -0,0 +1,116 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : hal_stm32f4_eth.h
* @brief : STM32F4 specific Ethernet interface header file
******************************************************************************
*/
/* USER CODE END Header */
#ifndef HAL_STM32F4_ETH_H
#define HAL_STM32F4_ETH_H
#include "../../hal_eth.h"
#include "stm32f4xx_hal.h"
/**
* @brief STM32F4 Ethernet handle structure
*/
typedef struct {
ETH_HandleTypeDef heth; /*!< Ethernet handle */
uint8_t initialized; /*!< Initialization flag */
hal_eth_phy_addr_t phy_addr; /*!< PHY address */
uint32_t rx_packets; /*!< Received packets count */
uint32_t tx_packets; /*!< Transmitted packets count */
uint32_t rx_errors; /*!< Receive errors count */
uint32_t tx_errors; /*!< Transmit errors count */
} hal_stm32f4_eth_handle_t;
/**
* @brief Initialize STM32F4 Ethernet module
* @param config: Pointer to Ethernet configuration structure
* @retval HAL status code
*/
hal_ret_t hal_stm32f4_eth_init(const hal_eth_config_t* config);
/**
* @brief Deinitialize STM32F4 Ethernet module
* @param instance: Ethernet instance
* @retval HAL status code
*/
hal_ret_t hal_stm32f4_eth_deinit(hal_eth_instance_t instance);
/**
* @brief Get STM32F4 Ethernet status
* @param instance: Ethernet instance
* @param status: Pointer to Ethernet status structure
* @retval HAL status code
*/
hal_ret_t hal_stm32f4_eth_get_status(hal_eth_instance_t instance, hal_eth_status_t* status);
/**
* @brief Set STM32F4 Ethernet MAC address
* @param instance: Ethernet instance
* @param mac_addr: Pointer to MAC address structure
* @retval HAL status code
*/
hal_ret_t hal_stm32f4_eth_set_mac_addr(hal_eth_instance_t instance, const hal_eth_mac_addr_t* mac_addr);
/**
* @brief Get STM32F4 Ethernet MAC address
* @param instance: Ethernet instance
* @param mac_addr: Pointer to MAC address structure
* @retval HAL status code
*/
hal_ret_t hal_stm32f4_eth_get_mac_addr(hal_eth_instance_t instance, hal_eth_mac_addr_t* mac_addr);
/**
* @brief Check STM32F4 Ethernet link status
* @param instance: Ethernet instance
* @param link_up: Pointer to store link up status
* @retval HAL status code
*/
hal_ret_t hal_stm32f4_eth_check_link(hal_eth_instance_t instance, uint8_t* link_up);
/**
* @brief Reset STM32F4 Ethernet PHY
* @param instance: Ethernet instance
* @param phy_addr: PHY address
* @retval HAL status code
*/
hal_ret_t hal_stm32f4_eth_reset_phy(hal_eth_instance_t instance, hal_eth_phy_addr_t phy_addr);
/**
* @brief Read STM32F4 Ethernet PHY register
* @param instance: Ethernet instance
* @param phy_addr: PHY address
* @param reg_addr: Register address
* @param value: Pointer to store register value
* @retval HAL status code
*/
hal_ret_t hal_stm32f4_eth_read_phy_reg(hal_eth_instance_t instance, hal_eth_phy_addr_t phy_addr, uint16_t reg_addr, uint16_t* value);
/**
* @brief Write STM32F4 Ethernet PHY register
* @param instance: Ethernet instance
* @param phy_addr: PHY address
* @param reg_addr: Register address
* @param value: Register value
* @retval HAL status code
*/
hal_ret_t hal_stm32f4_eth_write_phy_reg(hal_eth_instance_t instance, hal_eth_phy_addr_t phy_addr, uint16_t reg_addr, uint16_t value);
/**
* @brief Configure STM32F4 Ethernet GPIO
* @retval HAL status code
*/
hal_ret_t hal_stm32f4_eth_gpio_config(void);
/**
* @brief Get STM32F4 Ethernet handle
* @param instance: Ethernet instance
* @retval Pointer to Ethernet handle structure
*/
hal_stm32f4_eth_handle_t* hal_stm32f4_eth_get_handle(hal_eth_instance_t instance);
#endif /* HAL_STM32F4_ETH_H */

160
HAL/Inc/hal_eth.h Normal file
View File

@ -0,0 +1,160 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : hal_eth.h
* @brief : Hardware Abstraction Layer Ethernet interface header file
******************************************************************************
*/
/* USER CODE END Header */
#ifndef HAL_ETH_H
#define HAL_ETH_H
#include "hal.h"
/**
* @brief Ethernet instance definitions
*/
typedef enum {
HAL_ETH_INSTANCE_1 = 0, /*!< Ethernet instance 1 */
HAL_ETH_INSTANCE_MAX
} hal_eth_instance_t;
/**
* @brief Ethernet mode definitions
*/
typedef enum {
HAL_ETH_MODE_HALFDUPLEX = 0, /*!< Half duplex mode */
HAL_ETH_MODE_FULLDUPLEX, /*!< Full duplex mode */
HAL_ETH_MODE_MAX
} hal_eth_mode_t;
/**
* @brief Ethernet speed definitions
*/
typedef enum {
HAL_ETH_SPEED_10MBPS = 0, /*!< 10 Mbps speed */
HAL_ETH_SPEED_100MBPS, /*!< 100 Mbps speed */
HAL_ETH_SPEED_MAX
} hal_eth_speed_t;
/**
* @brief Ethernet PHY address definitions
*/
typedef uint8_t hal_eth_phy_addr_t;
/**
* @brief Ethernet MAC address structure
*/
typedef struct {
uint8_t byte[6]; /*!< MAC address bytes */
} hal_eth_mac_addr_t;
/**
* @brief Ethernet configuration structure
*/
typedef struct {
uint8_t enable; /*!< Ethernet enable flag */
hal_eth_instance_t instance; /*!< Ethernet instance */
hal_eth_mode_t mode; /*!< Ethernet mode */
hal_eth_speed_t speed; /*!< Ethernet speed */
hal_eth_phy_addr_t phy_addr; /*!< PHY address */
hal_eth_mac_addr_t mac_addr; /*!< MAC address */
uint8_t auto_negotiation; /*!< Auto negotiation enable flag */
uint8_t interrupt_enable; /*!< Interrupt enable flag */
} hal_eth_config_t;
/**
* @brief Ethernet status structure
*/
typedef struct {
uint8_t link_up; /*!< Link up status */
uint8_t duplex; /*!< Duplex mode (0: half, 1: full) */
uint32_t speed; /*!< Speed in Mbps */
uint32_t rx_packets; /*!< Received packets count */
uint32_t tx_packets; /*!< Transmitted packets count */
uint32_t rx_errors; /*!< Receive errors count */
uint32_t tx_errors; /*!< Transmit errors count */
} hal_eth_status_t;
/**
* @brief Initialize Ethernet module
* @param config: Pointer to Ethernet configuration structure
* @retval HAL status code
*/
hal_ret_t hal_eth_init(const hal_eth_config_t* config);
/**
* @brief Deinitialize Ethernet module
* @param instance: Ethernet instance
* @retval HAL status code
*/
hal_ret_t hal_eth_deinit(hal_eth_instance_t instance);
/**
* @brief Get Ethernet status
* @param instance: Ethernet instance
* @param status: Pointer to Ethernet status structure
* @retval HAL status code
*/
hal_ret_t hal_eth_get_status(hal_eth_instance_t instance, hal_eth_status_t* status);
/**
* @brief Set Ethernet MAC address
* @param instance: Ethernet instance
* @param mac_addr: Pointer to MAC address structure
* @retval HAL status code
*/
hal_ret_t hal_eth_set_mac_addr(hal_eth_instance_t instance, const hal_eth_mac_addr_t* mac_addr);
/**
* @brief Get Ethernet MAC address
* @param instance: Ethernet instance
* @param mac_addr: Pointer to MAC address structure
* @retval HAL status code
*/
hal_ret_t hal_eth_get_mac_addr(hal_eth_instance_t instance, hal_eth_mac_addr_t* mac_addr);
/**
* @brief Check Ethernet link status
* @param instance: Ethernet instance
* @param link_up: Pointer to store link up status
* @retval HAL status code
*/
hal_ret_t hal_eth_check_link(hal_eth_instance_t instance, uint8_t* link_up);
/**
* @brief Reset Ethernet PHY
* @param instance: Ethernet instance
* @param phy_addr: PHY address
* @retval HAL status code
*/
hal_ret_t hal_eth_reset_phy(hal_eth_instance_t instance, hal_eth_phy_addr_t phy_addr);
/**
* @brief Read PHY register
* @param instance: Ethernet instance
* @param phy_addr: PHY address
* @param reg_addr: Register address
* @param value: Pointer to store register value
* @retval HAL status code
*/
hal_ret_t hal_eth_read_phy_reg(hal_eth_instance_t instance, hal_eth_phy_addr_t phy_addr, uint16_t reg_addr, uint16_t* value);
/**
* @brief Write PHY register
* @param instance: Ethernet instance
* @param phy_addr: PHY address
* @param reg_addr: Register address
* @param value: Register value
* @retval HAL status code
*/
hal_ret_t hal_eth_write_phy_reg(hal_eth_instance_t instance, hal_eth_phy_addr_t phy_addr, uint16_t reg_addr, uint16_t value);
/**
* @brief Get default Ethernet configuration
* @return Pointer to default Ethernet configuration
*/
const hal_eth_config_t* hal_eth_get_default_config(void);
#endif /* HAL_ETH_H */