mirror of
https://gitee.com/dlmu-cone/bf_original_balance_chassis
synced 2026-07-24 03:27:45 +08:00
添加bsp gpio的支持
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#include "bsp_gpio.h"
|
||||
#include "memory.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
static uint8_t idx;
|
||||
static GPIOInstance* gpio_instance[GPIO_MX_DEVICE_NUM] = {NULL};
|
||||
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
GPIOInstance *GPIORegister(GPIO_Init_Config_s *GPIO_config)
|
||||
{
|
||||
GPIOInstance *ins=(GPIOInstance*)malloc(sizeof(GPIOInstance));
|
||||
memset(ins,0,sizeof(GPIOInstance));
|
||||
|
||||
ins->GPIOx=GPIO_config->GPIOx;
|
||||
ins->GPIO_Pin=GPIO_config->GPIO_Pin;
|
||||
ins->id=GPIO_config->id;
|
||||
ins->gpio_model_callback=GPIO_config->gpio_model_callback;
|
||||
|
||||
gpio_instance[idx++]=ins;
|
||||
return ins;
|
||||
}
|
||||
|
||||
// ----------------- GPIO API -----------------
|
||||
// 都是对HAL的形式上的封装,后续考虑增加GPIO state变量,可以直接读取state
|
||||
|
||||
void GPIOToggel(GPIOInstance *_instance)
|
||||
{
|
||||
HAL_GPIO_TogglePin(_instance->GPIOx,_instance->GPIO_Pin);
|
||||
}
|
||||
|
||||
void GPIOSet(GPIOInstance *_instance)
|
||||
{
|
||||
HAL_GPIO_WritePin(_instance->GPIOx,_instance->GPIO_Pin,GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
void GPIOReset(GPIOInstance *_instance)
|
||||
{
|
||||
HAL_GPIO_WritePin(_instance->GPIOx,_instance->GPIO_Pin,GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
GPIO_PinState GPIORead(GPIOInstance *_instance)
|
||||
{
|
||||
return HAL_GPIO_ReadPin(_instance->GPIOx,_instance->GPIO_Pin);
|
||||
}
|
||||
|
||||
@@ -1,2 +1,38 @@
|
||||
#include "gpio.h"
|
||||
#include "stdint.h"
|
||||
|
||||
#define GPIO_MX_DEVICE_NUM 10
|
||||
|
||||
/**
|
||||
* @brief GPIO实例结构体定义
|
||||
*
|
||||
*/
|
||||
typedef struct tmpgpio
|
||||
{
|
||||
GPIO_TypeDef *GPIOx;
|
||||
uint16_t GPIO_Pin;
|
||||
void* id;
|
||||
void (*gpio_model_callback)(struct tmpgpio*); // 随便取个名字当临时声明
|
||||
} GPIOInstance;
|
||||
|
||||
/**
|
||||
* @brief GPIO初始化配置结构体定义
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
GPIO_TypeDef *GPIOx;
|
||||
uint16_t GPIO_Pin;
|
||||
void* id;
|
||||
void (*gpio_model_callback)(GPIOInstance*);
|
||||
} GPIO_Init_Config_s;
|
||||
|
||||
GPIOInstance* GPIORegister(GPIO_Init_Config_s* GPIO_config);
|
||||
|
||||
void GPIOToggel(GPIOInstance* _instance);
|
||||
|
||||
void GPIOSet(GPIOInstance* _instance);
|
||||
|
||||
void GPIOReset(GPIOInstance* _instance);
|
||||
|
||||
GPIO_PinState GPIORead(GPIOInstance* _instance);
|
||||
Reference in New Issue
Block a user