/**************************** (C) COPYRIGHT 2015 Fortiortech shenzhen *****************************
* File Name          : FU68xx_GPIO.h
* Author             : Billy Long Fortiortech  Market Dept
* Version            : V1.0
* Date               : 01/07/2015
* Description        : This file contains all the common data types used for
*                      Motor Control.
***************************************************************************************************
* All Rights Reserved
**************************************************************************************************/ 

/* Define to prevent recursive inclusion --------------------------------------------------------*/
#ifndef __FU68xx_GPIO_H_
#define __FU68xx_GPIO_H_

/* Includes -------------------------------------------------------------------------------------*/
#include <absacc.h>

/* Base Config Define ---------------------------------------------------------------------------*/
#define SET(reg,bit)					(reg |= (1<<bit))
#define CLR(reg,bit)					(reg &= ~(1<<bit))
#define SetBit(reg,bit,val)		val?(reg |= (1<<bit)):(reg &= ~(1<<bit))
#define GetBit(reg,bit)				(reg & (1<<bit))
#define SetReg(reg,val)	 			(reg = val)

/*GPIO端口位号定义-------------------------------------------------------------------------------*/
#define	P07			7
#define	P06			6
#define	P05			5
#define	P04			4
#define	P03			3
#define	P02			2
#define	P01			1
#define	P00			0

#define	P17			7
#define	P16			6
#define	P15			5
#define	P14			4
#define	P13			3
#define	P12			2
#define	P11			1
#define	P10			0

#define	P27			7
#define	P26			6
#define	P25			5
#define	P24			4
#define	P23			3
#define	P22			2
#define	P21			1
#define	P20			0

#define	P37			7
#define	P36			6
#define	P35			5
#define	P34			4
#define	P33			3
#define	P32			2
#define	P31			1
#define	P30			0

#define P42			2
#define P41			1
#define P40			0


/* Register Define ------------------------------------------------------------------------------*/
sfr P0_OE = 0xfc;														// P0输出使能寄存器
sfr P1_OE = 0xfd;														// P1输出使能寄存器
sfr P2_OE = 0xfe;														// P2输出使能寄存器
sfr P3_OE = 0xff;														// P3输出使能寄存器

sfr P1IE = 0xd1;														// P1中断使能寄存器
sfr P1IF = 0xd2;														// P1中断标志寄存器
sfr P2IE = 0xd3;														// P2中断使能寄存器
sfr P2IF = 0xd4;														// P2中断标志寄存器

#define P0_PU XBYTE[0x4053]                 // P0输出使能寄存器
#define P1_PU XBYTE[0x4054]									// P1输出使能寄存器
#define P2_PU XBYTE[0x4055]									// P2输出使能寄存器
#define P3_PU XBYTE[0x4056]									// P3输出使能寄存器

#define P1_AN XBYTE[0x4050]									// P1模拟使能寄存器
#define HBMODE    3
#define ODE1			1
#define ODE0			0

#define P2_AN XBYTE[0x4051]									// P2模拟使能寄存器
#define P3_AN XBYTE[0x4052]									// P3模拟使能寄存器

#define DRV_CTL XBYTE[0x404d]								// 驱动输出选择/使能寄存器
#define OCS1			3
#define OCS0			2
#define PRDRVEN		1
#define DRVOE			0

#define PH_SEL XBYTE[0x404c]								// 管脚复用功能选择寄存器
#define UT1EN			6
#define UT0EN			5
#define T4SEL			4
#define T3SEL			3
#define T2SEL			2
#define T5SEL			1
#define T0CH4SEL	0

sfr DRV_OUT = 0xf8;													// 驱动输出空闲状态寄存器
sbit MOE   = DRV_OUT^7;
sbit OIS4  = DRV_OUT^6;
sbit OISWL = DRV_OUT^5;
sbit OISWH = DRV_OUT^4;
sbit OISVL = DRV_OUT^3;
sbit OISVH = DRV_OUT^2;
sbit OISUL = DRV_OUT^1;
sbit OISUH = DRV_OUT^0;


sfr P0 = 0x80;															// P0端口寄存器
sbit GP07 = P0^7;
sbit GP06 = P0^6;
sbit GP05 = P0^5;
sbit GP04 = P0^4;
sbit GP03 = P0^3;
sbit GP02 = P0^2;
sbit GP01 = P0^1;
sbit GP00 = P0^0;

sfr P1 = 0x90;															// P1端口寄存器
sbit GP17 = P1^7;
sbit GP16 = P1^6;
sbit GP15 = P1^5;
sbit GP14 = P1^4;
sbit GP13 = P1^3;
sbit GP12 = P1^2;
sbit GP11 = P1^1;
sbit GP10 = P1^0;

sfr P2 = 0xa0;															// P2端口寄存器
sbit GP27 = P2^7;
sbit GP26 = P2^6;
sbit GP25 = P2^5;
sbit GP24 = P2^4;
sbit GP23 = P2^3;
sbit GP22 = P2^2;
sbit GP21 = P2^1;
sbit GP20	= P2^0;

sfr P3 = 0xb0;															// P3端口寄存器
sbit GP37 = P3^7;
sbit GP36 = P3^6;
sbit GP35 = P3^5;
sbit GP34 = P3^4;
sbit GP33 = P3^3;
sbit GP32 = P3^2;
sbit GP31 = P3^1;
sbit GP30 = P3^0;


#endif
