/***********************************************************************
 * Copyright (c)  2017 - 2022, Unicmicro Co.,Ltd .
 * All rights reserved.
 * Filename    : gpio.c
 * Description : gpio driver header file
 * Author(s)   : zhilan
 * version     : V1.0
 * Modify date : 2022-08-04
 ***********************************************************************/
#ifndef __GPIO_H__
#define __GPIO_H__

#include "um321xF.h"
									
//PIN Number                              
#define PIN0	                			(0)
#define PIN1	                			(1)
#define PIN2	                			(2)
#define PIN3	                			(3)
#define PIN4	                			(4)
#define PIN5	                			(5)
#define PIN6	                			(6)
#define PIN7	                			(7)
		
//ST		ATE
#define ENABLE	        					1
#define DISABLE		       					0
		
//LE		VEL
#define HIGH	        					1             //高电平
#define LOW		       						0             //低电平
		
//DI		R
#define GPIO_DIR_IN  	            		0             //引脚输入
#define GPIO_DIR_OUT  	            		1             //引脚输出
		
//电平/边沿中断触发模式
#define GPIO_IS_EDGE                		0             //边沿触发
#define GPIO_IS_LEVEL               		1             //电平触发
		
#define GPIO_IBE_SINGLE             		0             //单边沿触发
#define GPIO_IBE_DOUBLE             		1             //双边沿触发
		
#define GPIO_IEV_FALLEDGEORLOWLEVEL	        0             //下降沿触发
#define GPIO_IEV_RISEEDGEORHIGHLEVEL        1             //上升沿触发
		
//SYSCFG REG (PERI_CLKEN) GPIO 时钟选择(test)
#define GPIOA_CLKEN  	            		((uint32_t)0x1<<16)
#define GPIOB_CLKEN  	            		((uint32_t)0x1<<17)
#define GPIOC_CLKEN  	            		((uint32_t)0x1<<18)
#define GPIOD_CLKEN  	            		((uint32_t)0x1<<19)
#define GPIOE_CLKEN  	            		((uint32_t)0x1<<28)
#define GPIOF_CLKEN  	            		((uint32_t)0x1<<29)
#define GPIOG_CLKEN  	            		((uint32_t)0x1<<7)

//GPIO复位(test)
#define GPIOA_RESET  	            		((uint32_t)0x1<<16)
#define GPIOB_RESET  	            		((uint32_t)0x1<<17)
#define GPIOC_RESET  	            		((uint32_t)0x1<<18)
#define GPIOD_RESET  	            		((uint32_t)0x1<<19)
#define GPIOE_RESET  	            		((uint32_t)0x1<<28)
#define GPIOF_RESET  	            		((uint32_t)0x1<<29)
#define GPIOG_RESET  	            		((uint32_t)0x1<<7)


/************************************************************************
 * function   	: gpio_init
 * description	: gpio_init GPIO初始化函数
 * input 		: uint8_t port    GPIO端口类型 GPIOA,GPIOB,GPIOC....
 *				  uint8_t pin	  GPIO管脚   PIN0,PIN1,PIN2,PIN3,PIN4.....
				  uint8_t mulfunc GPIO引脚复用功能选择 0,1,2,3,4,5,6.....
 * return		: none
 ************************************************************************/
void gpio_init(uint8_t port, uint8_t pin,uint8_t mulfunc);

/************************************************************************
 * function   	: gpio_dir
 * description	: gpio_dir GPIO方向设置
 * input 		: uint8_t port    GPIO端口类型  GPIOA,GPIOB,GPIOC....
 *				  uint8_t pin	  GPIO管脚  PIN0,PIN1,PIN2,PIN3,PIN4.....
 *                uint8_t newstate   GPIO_DIR_OUT：输出  GPIO_DIR_IN：输入
 * return		: none
 ************************************************************************/
void gpio_dir(uint8_t port, uint8_t pin, uint8_t newstate);

/************************************************************************
 * function   	: gpio_in_enable
 * description	: gpio_in_enable GPIO输入使能设置
 * input 		: uint8_t port    GPIO端口类型  GPIOA,GPIOB,GPIOC....
 *				  uint8_t pin	  GPIO管脚  PIN0,PIN1,PIN2,PIN3,PIN4.....
 *                uint8_t newstate   1：使能  0：禁止
 * return		: none
 ************************************************************************/
void gpio_in_enable(uint8_t port, uint8_t pin, uint8_t newstate);

/************************************************************************
 * function   	: gpio_config_pu
 * description	: gpio_config_pu GPIO上拉使能设置
 * input 		: uint8_t port    GPIO端口类型 GPIOA,GPIOB,GPIOC....
 *				  uint8_t pin	  GPIO管脚  PIN0,PIN1,PIN2,PIN3......
 *                uint8_t newstate   1：使能 0：禁止
 * return		: none
 ************************************************************************/
void gpio_config_pu(uint8_t port, uint8_t pin, uint8_t newstate);

/************************************************************************
 * function   	: gpio_config_pd
 * description	: gpio_config_pd GPIO下拉使能设置
 * input 		: uint8_t port    GPIO端口类型 GPIOA,GPIOB,GPIOC....
 *				  uint8_t pin	  GPIO管脚   PIN0,PIN1,PIN2,PIN3......
 *                uint8_t newstate   1：使能  0：禁止
 * return		: none
 ************************************************************************/
void gpio_config_pd(uint8_t port, uint8_t pin, uint8_t newstate);

/************************************************************************
 * function   	: gpio_config_od
 * description	: gpio_config_od GPIO开漏使能设置
 * input 		: uint8_t port    GPIO端口类型 GPIOA,GPIOB,GPIOC....
 *				  uint8_t pin	  GPIO管脚    PIN0,PIN1,PIN2,PIN3......
 *                uint8_t newstate   1：使能  0：禁止
 * return		: none
 ************************************************************************/
void gpio_config_od(uint8_t port, uint8_t pin, uint8_t newstate);

/************************************************************************
 * function   	: gpio_read_io
 * description	: gpio_read_io GPIO输入电平获取
 * input 		: uint8_t port    GPIO端口类型 GPIOA,GPIOB,GPIOC....
 *				  uint8_t pin	  GPIO管脚 PIN0,PIN1,PIN2,PIN3......
 * return		: 管脚电平状态
 ************************************************************************/
uint8_t gpio_read_io(uint8_t port, uint8_t pin);

/************************************************************************
 * function   	: gpio_write_io
 * description	: gpio_write_io   GPIO输出电平
 * input 		: uint8_t port    GPIO端口类型  GPIOA,GPIOB,GPIOC....
 *				  uint8_t pin	  GPIO管脚 PIN0,PIN1,PIN2,PIN3......
 *				  uint8_t newstate  1：高电平  0：低电平
 * return		: none
 ************************************************************************/
void gpio_write_io(uint8_t port, uint8_t pin, uint8_t newstate);

/************************************************************************
 * function   	: gpio_setio
 * description	: gpio_setio GPIO电平设置
 * input 		: uint8_t port    GPIO端口类型 GPIOA,GPIOB,GPIOC....
 *				  uint8_t pin	  GPIO管脚 PIN0,PIN1,PIN2,PIN3......
 *                uint8_t newstate   1：高电平  0：低电平
 * return		: none
 ************************************************************************/
void gpio_setio(uint8_t port, uint8_t pin, uint8_t newstate);

/************************************************************************
 * function   	: gpio_irq_init
 * description	: gpio_irq_init GPIO中断初始化
 * input 		: uint8_t port    GPIO端口类型  GPIOA,GPIOB,GPIOC....
 *				  uint8_t pin	  GPIO管脚 PIN0,PIN1,PIN2,PIN3......
 *                uint8_t newstate   1：使能中断  0：禁止中断
 * return		: none
 ************************************************************************/
void gpio_irq_init(uint8_t port, uint8_t pin, uint8_t irq_enable, void (*pfunc)(uint8_t val_ris));

/************************************************************************
 * function   	: gpio_set_is
 * description	: gpio_set_is GPIO中断触发类型设置
 * input 		: uint8_t port    GPIO端口类型  GPIOA,GPIOB,GPIOC....
 *				  uint8_t pin	  GPIO管脚  PIN0,PIN1,PIN2,PIN3......
 *                uint8_t newstate   1：电平触发 0：边沿触发
 * return		: none
 ************************************************************************/
void gpio_set_is(uint8_t port, uint8_t pin, uint8_t newstate);

/************************************************************************
 * function   	: gpio_set_iev
 * description	: gpio_set_iev GPIO中断触发极性设置
 * input 		: uint8_t port    GPIO端口类型  GPIOA,GPIOB,GPIOC....
 *				  uint8_t pin	  GPIO管脚  PIN0,PIN1,PIN2,PIN3......
 *                uint8_t newstate   1：上升沿/高电平触发 
                                     0：下降沿/低电平触发
 * return		: none
 ************************************************************************/
void gpio_set_iev(uint8_t port, uint8_t pin, uint8_t newstate);

/************************************************************************
 * function   	: gpio_set_ibe
 * description	: gpio_set_ibe GPIO单双边沿触发
 * input 		: uint8_t port    GPIO端口类型  GPIOA,GPIOB,GPIOC....
 *				  uint8_t pin	  GPIO管脚  PIN0,PIN1,PIN2,PIN3......
 *                uint8_t newstate   1：双边沿触发 0：单边沿触发
 * return		: none
 ************************************************************************/
void gpio_set_ibe(uint8_t port, uint8_t pin, uint8_t newstate);

#endif

