#ifndef _USER_GPIO_H_
#define _USER_GPIO_H_

#include "t_define.h"
#include "t_bk3231sf.h"

#define GPIO_PORT_0			0
#define GPIO_PORT_1			1		
#define GPIO_PORT_2			2
#define GPIO_PORT_3			3
#define GPIO_PORT_4			4

#define GPIO_PIN_0			0
#define GPIO_PIN_1			1		
#define GPIO_PIN_2			2
#define GPIO_PIN_3			3
#define GPIO_PIN_4			4
#define GPIO_PIN_5			5		
#define GPIO_PIN_6			6
#define GPIO_PIN_7			7

#define GPIO_GEN_CFG_0			BM_GPIO_MODE|BM_GPIO_IO_OUT_NOR|BM_GPIO_PULL_UP|BM_GPIO_PULL_DOWN	
#define GPIO_GEN_CFG_1      BM_GPIO_IO_IN 

#define GPIO_MODE_GPIO			(0x01ul<<BO_GPIO_MODE)
#define GPIO_MODE_SECOND		0x00
#define GPIO_MODE_HIGHZ		  (0x01ul<<BO_GPIO_MODE)

#define GPIO_IO_NONE				(0x01ul<<BO_GPIO_IO_OUT_NOR)
#define GPIO_IO_OUT					0x00
#define GPIO_IO_IN		  		(0x01ul<<BO_GPIO_IO_OUT_NOR)|(0x01ul<<BO_GPIO_IO_IN)

#define GPIO_PULL_NONE				0x00
#define GPIO_PULL_UP					(0x01ul<<BO_GPIO_PULL_UP)
#define GPIO_PULL_DOWM		  	(0x01ul<<BO_GPIO_PULL_DOWN)
#define GPIO_PULL_UPADOWM		  (0x01ul<<BO_GPIO_PULL_UP)|(0x01ul<<BO_GPIO_PULL_DOWN)

#define GPIO_INTERRUPT_EDGE_UP				0
#define GPIO_INTERRUPT_EDGE_DOWN			1

typedef void (*GPIO_INT_HANDLE_CB_PFN)(uint32);

void GpioGenCfg(uint8 port, uint8 bitoffset, uint32 mode, uint32 io, uint32 pull);
void GpioModeCfg(uint8 port, uint8 bitoffset, uint32 mode);
void GpioIoCfg(uint8 port, uint8 bitoffset, uint32 io);
void GpioPullCfg(uint8 port, uint8 bitoffset, uint32 pull);
void GpioSetOutNegate(uint8 port, uint8 bitoffset);
void GpioSetOut(uint8 port, uint8 bitoffset, uint32 out);
bool8 GpioGetIn(uint8 port, uint8 bitoffset);
void GpioIntCfg(uint8 port, uint8 bitoffset, uint32 interruptenable, uint32 trigedge);
void GpioIntEnCfg(uint8 port, uint8 bitoffset, uint32 interruptenable);
void GpioInTrigedgeCfg(uint8 port, uint8 bitoffset, uint32 trigedge);
void GpioDeepWakeupCfg(uint8 port, uint8 bitoffset, uint32 wakeupenable);
uint32 GpioGetInitSta(void);
void GpioClearInitSta(uint32 gpiointstate);
void GpioIntHandleCbCfg(GPIO_INT_HANDLE_CB_PFN cbpfn);
void GpioIntHandle(void);
void GpioIntHandleCb(uint32 gpiointstate);
void GpioInit(void);

#endif