#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
{
    kGpioStatus_Low, 
    kGpioStatus_High,
    kGpioStatus_Err,
    kGpioStatus_End,    
}GpioStatus;

typedef enum
{
    kGpioMode_Input_Floating,   //浮空输入
	kGpioMode_Output_PP, 		//推挽输出 
    kGpioMode_Comm_Rx,			// 通信接收模式 复用推挽输出 
    kGpioMode_Comm_Tx = kGpioMode_Comm_Rx, //通信发送模式复用推挽输出 
    kGpioMode_Adc,
    kGpioMode_End,
}GpioMode;

typedef struct
{
    GpioMode   mode;
    GpioStatus init_st;
    uint32_t   io;  
	GpioPort   port_group;
	GpioPin    pin_idx;
}GpioArray;

kit_ret_e  drv_gpio_init(const GpioArray *array, uint16_t cnt);
GpioStatus drv_gpio_get_pin_status(uint16_t idx);
kit_ret_e  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);
kit_ret_e  drv_gpio_set_pin_mode(uint8_t io_idx, GpioMode mode);
#ifdef __cplusplus
}
#endif

#endif
