/**
******************************************************************************************************************************************************************************************
*@file                       cpu_gpio.h
*@author         
*@data                       
*@version                    v1.0
*@par Copyright(c):
*
*@par History:
*     version:author,date,desc
*     v1.0   :create this file
*
*******************************************************************************************************************************************************************************************
*/
#ifndef _CPU_GPIO_H_
#define _CPU_GPIO_H_


#include <stdint.h>

typedef enum _irq_bank
{
	GPIO_Int0	=					(0),		//第一组GPIO外部中断
	GPIO_Int1	=					(1),		//第二组GPIO外部中断
	GPIO_Int2	=					(2),		//第三组GPIO外部中断
	GPIO_Int3	=					(3), 		//第四组GPIO外部中断     
}irq_bank;

typedef enum _gpio_irq_type
{
	GPIO_Int_Type_Disable		=	(0),		//GPIO外部中断  关闭沿触发
	GPIO_Int_Type_RisingEdge	=	(1),		//GPIO外部中断  上升沿触发
	GPIO_Int_Type_FallingEdge	=	(2),		//GPIO外部中断  下降沿触发
	GPIO_Int_Type_BothEdge	=	(3)    		//GPIO外部中断  双边沿触发
}gpio_irq_type;

//唤醒方式
typedef enum _gpio_wk_type
{
	WakeUpType_Disable			=	(0),		//GPIO外部中断  关闭中断
	WakeUpType_Immediately	=	(1),		//GPIO外部中断  立刻触发
	WakeUpType_32K_AntiShake	=   (2),  		//GPIO外部中断  滤波触发
}gpio_wk_type;


typedef enum _group_bank
{
	GPIO_BANK_A,					//GPIOA组
	GPIO_BANK_B,					//GPIOB组
	GPIO_BANK_C,					//GPIOC组
	GPIO_BANK_D,					//GPIOD组
	GPIO_BANK_MAX = GPIO_BANK_D,
}group_bank;


typedef enum
{ 
	GPIO_Remap_GPIO = 0x00,
	GPIO_Remap_UART0_RX = 0x01,
	GPIO_Remap_UART0_TX = 0x02,
	GPIO_Remap_UART0_CTSN = 0x03,
	GPIO_Remap_UART0_RTSN = 0x04,
	GPIO_Remap_UART1_RX = 0x05,
	GPIO_Remap_UART1_TX = 0x06,
	GPIO_Remap_UART1_CTSN = 0x07,
	GPIO_Remap_UART1_RTSN = 0x08,
	GPIO_Remap_SPI0_CSN = 0x09,
	GPIO_Remap_SPI0_CLK = 0x0a,
	GPIO_Remap_SPI0_MOSI = 0x0b,	
	GPIO_Remap_SPI0_MISO = 0x0c,
	GPIO_Remap_SPI1_CSN = 0x0d,
	GPIO_Remap_SPI1_CLK = 0x0e,
	GPIO_Remap_SPI1_MOSI = 0x0f,	
	GPIO_Remap_SPI1_MISO = 0x10,
	GPIO_Remap_I2C_SCL = 0x11,
	GPIO_Remap_I2C_SDA = 0x12,
	GPIO_Remap_PWM0 = 0x13,
	GPIO_Remap_PWM1 = 0x14,
	GPIO_Remap_QDEC_CHA = 0x15,
	GPIO_Remap_QDEC_CHB = 0x16,
	GPIO_Remap_QDEC_IDX = 0x17,
	GPIO_Remap_24RESERVED = 0x18,
	GPIO_Remap_25RESERVED = 0x19,
	GPIO_Remap_26RESERVED = 0x1a,
	GPIO_Remap_JTAC_TCLK = 0x1b,	
	GPIO_Remap_JTAC_TDO = 0x1c,
	GPIO_Remap_JTAC_TDI = 0x1d,
	GPIO_Remap_JATC_TMS = 0x1e,
	GPIO_Remap_JTAC_TRST = 0x1f,	
	GPIO_Remap_KPC_PIO0 = 0x20,
	GPIO_Remap_KPC_PIO1 = 0x21,
	GPIO_Remap_KPC_PIO2 = 0x22,
	GPIO_Remap_KPC_PIO3 = 0x23,
	GPIO_Remap_KPC_PIO4 = 0x24,
	GPIO_Remap_KPC_PIO5 = 0x25,
	GPIO_Remap_KPC_PIO6 = 0x26,
	GPIO_Remap_KPC_PIO7 = 0x27,
	GPIO_Remap_KPC_PIO8 = 0x28,
	GPIO_Remap_KPC_PIO9 = 0x29,
	GPIO_Remap_KPC_PIO10 = 0x2a,
	GPIO_Remap_KPC_PIO11 = 0x2b,	
	GPIO_Remap_KPC_PIO12 = 0x2c,
	GPIO_Remap_KPC_PIO13 = 0x2d,
	GPIO_Remap_KPC_PIO14 = 0x2e,
	GPIO_Remap_KPC_PIO15  = 0x2f,	
	GPIO_Remap_ADC		  = 0x30,
	GPIO_Remap_IRDA_RX 	  = 0x31,
	GPIO_Remap_IRDA_TX 	  = 0x32,
	GPIO_12M_CLOCK        = 0x33,
	GPIO_Remap_52RESERVED = 0x34,
	GPIO_Remap_53RESERVED = 0x35,
	GPIO_16M_OSC_RC_CLOCK = 0x36,
	GPIO_Remap_55RESERVED = 0x37,
	GPIO_Remap_56RESERVED = 0x38,
	GPIO_Remap_SYS_DBG	  = 0x39,
	GPIO_Remap_CLK32K	  = 0x3a,
	GPIO_Remap_MDM_CLK	  = 0x3b,	
	GPIO_Remap_BLE_DEG0   = 0x3c,
	GPIO_Remap_BLE_DEG1   = 0x3d,
	GPIO_Remap_BLE_DEG2   = 0x3e,
	GPIO_Remap_BLE_DEG3   = 0x3f,	
}gpio_remap_type;



typedef enum
{
	GPIO_Mode_Input,						//悬浮输入
	RESERVED,								//保留
	GPIO_Mode_Input_Pull_Down_Resistor,	//下拉输入
	GPIO_Mode_Output,						//输出
}gpio_mode_type;


typedef enum _gpio_pin
{
	GPIOA_Pin0	=			(0x00),
	GPIOA_Pin1	=			(0x01),
	GPIOA_Pin2	=			(0x02),
	GPIOA_Pin3	=			(0x03),
	GPIOA_Pin4	=			(0x04),
	GPIOA_Pin5	=			(0x05),
	GPIOA_Pin6	=			(0x06),
	GPIOA_Pin7	=			(0x07),
	GPIOB_Pin0	=			(0x08),
	GPIOB_Pin1	=			(0x09),
	GPIOB_Pin2	=			(0x0A),
	GPIOB_Pin3	=			(0x0B),
	GPIOB_Pin4	=			(0x0C),
	GPIOB_Pin5	=			(0x0D),
	GPIOB_Pin6	=			(0x0E),
	GPIOB_Pin7	=			(0x0F),
	GPIOC_Pin0	=			(0x10),
	GPIOC_Pin1	=			(0x11),
	GPIOC_Pin2	=			(0x12),
	GPIOC_Pin3	=			(0x13),
	GPIOC_Pin4	=			(0x14),
	GPIOC_Pin5	=			(0x15),
	GPIOC_Pin6	=			(0x16),
	GPIOC_Pin7	=			(0x17),
	GPIOD_Pin0	=			(0x18),
	GPIOD_Pin1	=			(0x19),
	GPIOD_Pin2	=			(0x1A),
	GPIOD_Pin3	=			(0x1B),
	GPIOD_Pin4	=			(0x1C),
	GPIOD_Pin5	=			(0x1D),
	GPIOD_Pin6	=			(0x1E),
	GPIOD_Pin7	=			(0x1F),          
	GPIO_MAXS 	=			(0x1F),          
	GPIO_INVAILD 	=			(0xFF), 		 
}gpio_pin;



typedef struct
{
	uint32_t gpio_pinx;             /*!< Specifies the GPIO pins to be configured.
                                      This parameter can be any value of @ref GPIO_pins_define */	
	gpio_mode_type  gpio_mode;
	gpio_remap_type gpio_remap;
}GPIO_InitTypeDef;


extern void gpio_clear_it_pending(irq_bank gpio_intx);
extern uint32_t gpio_get_input(gpio_pin gpio_pinx);
extern uint32_t gpio_group_get_input(group_bank bank);
extern void gpio_group_init(group_bank bank,gpio_mode_type gpio_mode);
extern void gpio_group_reset(group_bank bank,int gpio_pins_map);
extern void gpio_group_sel_init(group_bank bank,uint32_t gpio_pins_map,gpio_mode_type gpio_mode);
extern void gpio_group_set(group_bank bank,uint32_t gpio_pins_map);
extern void gpio_init(gpio_pin gpio_pinx,gpio_mode_type gpio_mode);
extern void gpio_remap_config(gpio_pin gpio_pinx, gpio_remap_type gpio_remap);
extern void gpio_reset(gpio_pin gpio_pinx);
extern void gpio_set(gpio_pin gpio_pinx);
extern void gpio_set_irq_src_type(irq_bank gpio_intx,gpio_pin gpiox_pinx,gpio_irq_type gpio_int_type);
extern void gpio_set_output_level(gpio_pin gpio_pinx,uint32_t level);
extern void gpio_toggle(gpio_pin gpio_pinx);



#endif
