进一步迭代优化统一管理

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

@ -9,11 +9,13 @@
#include "hal.h"
#include "hal_gpio.h"
#include <stddef.h>
/**
* @brief Initialize GPIO hardware
* @retval HAL status code
*/
void hal_gpio_init(void) {
hal_ret_t hal_gpio_init(void) {
/* Call architecture specific GPIO initialization */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
hal_stm32f1_gpio_init();
@ -25,14 +27,21 @@ void hal_gpio_init(void) {
hal_stm32l4_gpio_init();
#else
#error "Unsupported HAL architecture"
return HAL_RET_ERROR;
#endif
return HAL_RET_OK;
}
/**
* @brief Configure GPIO pin
* @param config: GPIO configuration structure
* @retval HAL status code
*/
void hal_gpio_configure_pin(const hal_gpio_config_t *config) {
hal_ret_t hal_gpio_configure_pin(const hal_gpio_config_t *config) {
if (config == NULL) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific GPIO configuration */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
hal_stm32f1_gpio_configure_pin(config);
@ -44,7 +53,9 @@ void hal_gpio_configure_pin(const hal_gpio_config_t *config) {
hal_stm32l4_gpio_configure_pin(config);
#else
#error "Unsupported HAL architecture"
return HAL_RET_ERROR;
#endif
return HAL_RET_OK;
}
/**
@ -52,8 +63,14 @@ void hal_gpio_configure_pin(const hal_gpio_config_t *config) {
* @param port: GPIO port
* @param pin: GPIO pin
* @param state: GPIO pin state
* @retval HAL status code
*/
void hal_gpio_write_pin(hal_gpio_port_t port, hal_gpio_pin_t pin, hal_gpio_pin_state_t state) {
hal_ret_t hal_gpio_write_pin(hal_gpio_port_t port, hal_gpio_pin_t pin, hal_gpio_pin_state_t state) {
/* Validate parameters */
if (port >= HAL_GPIO_PORT_K + 1 || pin >= HAL_GPIO_PIN_ALL) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific GPIO write implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
hal_stm32f1_gpio_write_pin(port, pin, state);
@ -65,15 +82,23 @@ void hal_gpio_write_pin(hal_gpio_port_t port, hal_gpio_pin_t pin, hal_gpio_pin_s
hal_stm32l4_gpio_write_pin(port, pin, state);
#else
#error "Unsupported HAL architecture"
return HAL_RET_ERROR;
#endif
return HAL_RET_OK;
}
/**
* @brief Toggle GPIO pin state
* @param port: GPIO port
* @param pin: GPIO pin
* @retval HAL status code
*/
void hal_gpio_toggle_pin(hal_gpio_port_t port, hal_gpio_pin_t pin) {
hal_ret_t hal_gpio_toggle_pin(hal_gpio_port_t port, hal_gpio_pin_t pin) {
/* Validate parameters */
if (port >= HAL_GPIO_PORT_K + 1 || pin >= HAL_GPIO_PIN_ALL) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific GPIO toggle implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
hal_stm32f1_gpio_toggle_pin(port, pin);
@ -85,7 +110,9 @@ void hal_gpio_toggle_pin(hal_gpio_port_t port, hal_gpio_pin_t pin) {
hal_stm32l4_gpio_toggle_pin(port, pin);
#else
#error "Unsupported HAL architecture"
return HAL_RET_ERROR;
#endif
return HAL_RET_OK;
}
/**