/***********************************************************************
 * Copyright (c)  2017 - 2020, Unicmicro Co.,Ltd .
 * All rights reserved.
 * Filename    : gpio.c
 * Description : gpio driver header file
 * Author(s)   : Chloe
 * version     : V1.0
 * Modify date : 2019-02-27
 ***********************************************************************/
#ifndef _GPIO_H_
#define _GPIO_H_

#include "um321xA.h"


//通用数字输入/出管脚--用于SYSCFG某些寄存器配置(PAD_PD PAD_OD PAD_PU)
#define PA0	                    			0
#define PA1	                    			1
#define PA2	                    			2
#define PA3	                    			3
#define PA4	                    			4
#define PA5	                    			5
#define PA6	                    			6

#define PB0	                    			8
#define PB1	                    			9
#define PB2	                    			10
#define PB3	                    			11
#define PB4	                    			12
#define PB5	                    			13
#define PB6	                    			14
#define PB7	                    			15

#define PC1	                    			17
#define PC2	                    			18
#define PC3	                    			19
#define PC4	                    			20
#define PC5	                    			21
#define PC6	                    			22

#define PD0	                    			24		
#define PD1	                    			25
#define PD2	                    			26
#define PD3	                    			27
#define PD4	                    			28
#define PD5	                    			29
#define PD6	                    			30
#define PD7	                    			31

#define PE0	                    			0		
#define PE1	                    			1
#define PE2	                    			2
#define PE3	                    			3
#define PE4	                    			4
#define PE5	                    			5	

//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
		
#define GPIO_RIS_RAW_IT	        			1
#define GPIO_RIS_NO_RAW_IT          		0
		
#define GPIO_MODE_SOFTWARE	        		0
#define GPIO_MODE_HARDWARE          		1
		
#define GPIO_DB_ENABLE	        			1
#define GPIO_DB_DISABLE		        		0

//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)

//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)
		
		
//GPIO复用功能(Px_SEL),x为A,B,C,D
/*******Px_SEL************/

#define PIN_SEL(x)  			            (4*x)

void gpio_init(uint8_t port, uint8_t pin);

void gpio_dir(uint8_t port, uint8_t pin, uint8_t newstate);

void gpio_in_enable(uint8_t port, uint8_t pin, uint8_t newstate);

void gpio_config_pu(uint8_t port, uint8_t pin, uint8_t newstate);

void gpio_config_pd(uint8_t port, uint8_t pin, uint8_t newstate);

void gpio_config_od(uint8_t port, uint8_t pin, uint8_t newstate);

uint8_t gpio_read_io(uint8_t port, uint8_t pin);

void gpio_write_io(uint8_t port, uint8_t pin, uint8_t newstate);
	
void gpio_setio(uint8_t port, uint8_t pin, uint8_t newstate);

void gpio_irq_init(uint8_t port, uint8_t pin, uint8_t newstate, void (*pfunc)(uint8_t pin));

void gpio_set_is(uint8_t port, uint8_t pin, uint8_t newstate);

void gpio_set_iev(uint8_t port, uint8_t pin, uint8_t newstate);

void gpio_set_ibe(uint8_t port, uint8_t pin, uint8_t newstate);

#endif

