bs_bcu_app/drv/drv_stm32f4xx/drv_gpio.h

86 lines
1.7 KiB
C
Raw Normal View History

2024-11-07 17:24:19 +08:00
#ifndef _DRV_GPIO_H_
#define _DRV_GPIO_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "kit_macro.h"
#define GPIO_GET_PIN(io) ((uint8_t)((io) >> 16))
#define GPIO_GET_PORT(io) ((uint8_t)((io) >> 24))
#define GPIO_GET_PIN_BIT(io) ((uint16_t)(io))
#define GPIO_PORT_PIN(port, pin) (((port) << 24) + ((pin) << 16) + (1 << (pin)))
typedef enum
{
kGpioPort_A = 0,
kGpioPort_B,
kGpioPort_C,
kGpioPort_D,
kGpioPort_E,
kGpioPort_F,
kGpioPort_G,
kGpioPort_End,
}GpioPort;
typedef enum
{
kGpioPin_0 = 0,
kGpioPin_1,
kGpioPin_2,
kGpioPin_3,
kGpioPin_4,
kGpioPin_5,
kGpioPin_6,
kGpioPin_7,
kGpioPin_8,
kGpioPin_9,
kGpioPin_10,
kGpioPin_11,
kGpioPin_12,
kGpioPin_13,
kGpioPin_14,
kGpioPin_15,
}GpioPin;
typedef enum
{
kGpioMode_Input, //浮空输入
kGpioMode_Output, //推挽输出 50MHz
kGpioMode_CommRx,
kGpioMode_CommTx = kGpioMode_CommRx, //复用推挽输出 50MHz
kGpioMode_Adc,
kGpioMode_End,
}GpioMode;
typedef enum
{
kGpioStatus_Low,
kGpioStatus_High,
kGpioStatus_Err,
kGpioStatus_End,
}GpioStatus;
typedef struct
{
GpioMode mode;
GpioStatus init_st;
uint32_t io;
}GpioArray;
KitResult drv_gpio_init(const GpioArray *array, uint16_t cnt);
GpioStatus drv_gpio_get_pin_status(uint16_t idx);
KitResult drv_gpio_set_pin_status(uint16_t idx, GpioStatus status);
uint32_t drv_gpio_get_actual_io(uint16_t idx);
void drv_gpio_set_af(uint8_t port, uint8_t pin, uint8_t af);
KitResult drv_gpio_set_pin_mode(uint8_t io_idx, GpioMode mode);
#ifdef __cplusplus
}
#endif
#endif