#ifndef __SN32F770_SWI2C_H
#define __SN32F770_SWI2C_H


/*_____ I N C L U D E S ____________________________________________________*/
#include "SWI2C_User.h"

/*_____ D E F I N I T I O N S ______________________________________________*/
#define	BIT_0		(0x01 << 0)
#define	BIT_1		(0x01 << 1)
#define	BIT_2		(0x01 << 2)
#define	BIT_3		(0x01 << 3)
#define	BIT_4		(0x01 << 4)
#define	BIT_5		(0x01 << 5)
#define	BIT_6		(0x01 << 6)
#define	BIT_7		(0x01 << 7)


#define	SLAVE_ACK		0x00
#define	SLAVE_NAK		0x01


extern	void Mn_SWI2C_Init(void);
extern	void Mn_SWI2C_Control(void);
extern	void Mn_SWI2C_Release(void);
extern	void Mn_SWI2C_Start(void);
extern	void Mn_SWI2C_Stop(void);
extern	void Mn_SWI2C_SendByte(uint8_t bDataFIFO);
extern	uint8_t Mn_SWI2C_ReceiveByte(void);
extern	void Mn_SWI2C_WriteAck(void);
extern	void Mn_SWI2C_ReadAck(void);
extern	void Mn_SWI2C_ReadNak(void);
extern	uint8_t I2C_Write(uint16_t eeprom_adr, uint8_t write_num);
extern	uint8_t I2C_Read(uint16_t eeprom_adr, uint8_t read_num);
extern	__asm	void	Mn_SWI2C_SendByte_Asm(uint8_t	DataFIFO);
extern	__asm	void	Mn_SWI2C_ReceiveByte_Asm (uint8_t	*DataFIFO);

extern	uint8_t bI2C_TxFIFO[I2C_TX_FIFO_LENGTH];
extern	uint8_t bI2C_RxFIFO[I2C_RX_FIFO_LENGTH];


/*_____ M A C R O S ________________________________________________________*/


#if	(__I2C_SDA_PORT == 0)
	#define	__I2C_SDA_OUTPUT_MODE  	SN_GPIO0->MODE|=(0x01<<__I2C_SDA_BIT);
	#define __I2C_SDA_INPUT_MODE  	SN_GPIO0->MODE&=~(0x01<<__I2C_SDA_BIT);
	#define __I2C_SDA_FLOATING_MASK SN_GPIO0->CFG&=~(0x03<<(__I2C_SDA_BIT<<1));
	#define __I2C_SDA_FLOATING 			SN_GPIO0->CFG|=(0x02<<(__I2C_SDA_BIT<<1));
	#define __I2C_SDA_OUTPUT_H 	 		SN_GPIO0->BSET =(0x01<<__I2C_SDA_BIT);
	#define __I2C_SDA_OUTPUT_L  		SN_GPIO0->BCLR =(0x01<<__I2C_SDA_BIT);
	#define	__I2C_SDA_DATA					((SN_GPIO0->DATA)&(0x01<<__I2C_SDA_BIT))==(0x01<<__I2C_SDA_BIT)
#elif	(__I2C_SDA_PORT == 1)
	#define	__I2C_SDA_OUTPUT_MODE  	SN_GPIO1->MODE|=(0x01<<__I2C_SDA_BIT);
	#define __I2C_SDA_INPUT_MODE  	SN_GPIO1->MODE&=~(0x01<<__I2C_SDA_BIT);
	#define __I2C_SDA_FLOATING_MASK SN_GPIO1->CFG&=~(0x03<<(__I2C_SDA_BIT<<1));
	#define __I2C_SDA_FLOATING 			SN_GPIO1->CFG|=(0x02<<(__I2C_SDA_BIT<<1));
	#define __I2C_SDA_OUTPUT_H 	 		SN_GPIO1->BSET =(0x01<<__I2C_SDA_BIT);
	#define __I2C_SDA_OUTPUT_L  		SN_GPIO1->BCLR =(0x01<<__I2C_SDA_BIT);
	#define	__I2C_SDA_DATA					((SN_GPIO1->DATA)&(0x01<<__I2C_SDA_BIT))==(0x01<<__I2C_SDA_BIT)
#else
	#define	__I2C_SDA_OUTPUT_MODE  	SN_GPIO2->MODE|=(0x01<<__I2C_SDA_BIT);
	#define __I2C_SDA_INPUT_MODE  	SN_GPIO2->MODE&=~(0x01<<__I2C_SDA_BIT);
	#define __I2C_SDA_FLOATING_MASK SN_GPIO2->CFG&=~(0x03<<(__I2C_SDA_BIT<<1));
	#define __I2C_SDA_FLOATING 			SN_GPIO2->CFG|=(0x02<<(__I2C_SDA_BIT<<1));
	#define __I2C_SDA_OUTPUT_H 	 		SN_GPIO2->BSET =(0x01<<__I2C_SDA_BIT);
	#define __I2C_SDA_OUTPUT_L  		SN_GPIO2->BCLR =(0x01<<__I2C_SDA_BIT);
	#define	__I2C_SDA_DATA					((SN_GPIO2->DATA)&(0x01<<__I2C_SDA_BIT))==(0x01<<__I2C_SDA_BIT)
#endif


#if	(__I2C_SCL_PORT == 0)
	#define	__I2C_SCL_OUTPUT_MODE  	SN_GPIO0->MODE|=(0x01<<__I2C_SCL_BIT);
	#define	__I2C_SCL_INPUT_MODE		SN_GPIO0->MODE&=~(0x01<<__I2C_SCL_BIT);
	#define __I2C_SCL_FLOATING_MASK SN_GPIO0->CFG&=~(0x03<<(__I2C_SCL_BIT<<1));
	#define __I2C_SCL_FLOATING 			SN_GPIO0->CFG|=(0x02<<(__I2C_SCL_BIT<<1));
	#define __I2C_SCL_OUTPUT_H 	 		SN_GPIO0->BSET =(0x01<<__I2C_SCL_BIT);
	#define __I2C_SCL_OUTPUT_L  		SN_GPIO0->BCLR =(0x01<<__I2C_SCL_BIT);
	#define	__I2C_SCL_DATA					((SN_GPIO0->DATA)&(0x01<<__I2C_SCL_BIT))==(0x01<<__I2C_SCL_BIT)
#elif	(__I2C_SCL_PORT == 1)
	#define	__I2C_SCL_OUTPUT_MODE  	SN_GPIO1->MODE|=(0x01<<__I2C_SCL_BIT);
	#define	__I2C_SCL_INPUT_MODE		SN_GPIO1->MODE&=~(0x01<<__I2C_SCL_BIT);
	#define __I2C_SCL_FLOATING_MASK SN_GPIO1->CFG&=~(0x03<<(__I2C_SCL_BIT<<1));
	#define __I2C_SCL_FLOATING 			SN_GPIO1->CFG|=(0x02<<(__I2C_SCL_BIT<<1));
	#define __I2C_SCL_OUTPUT_H 	 		SN_GPIO1->BSET =(0x01<<__I2C_SCL_BIT);
	#define __I2C_SCL_OUTPUT_L  		SN_GPIO1->BCLR =(0x01<<__I2C_SCL_BIT);
	#define	__I2C_SCL_DATA					((SN_GPIO1->DATA)&(0x01<<__I2C_SCL_BIT))==(0x01<<__I2C_SCL_BIT)
#else
	#define	__I2C_SCL_OUTPUT_MODE  	SN_GPIO2->MODE|=(0x01<<__I2C_SCL_BIT);
	#define	__I2C_SCL_INPUT_MODE		SN_GPIO2->MODE&=~(0x01<<__I2C_SCL_BIT);
	#define __I2C_SCL_FLOATING_MASK SN_GPIO2->CFG&=~(0x03<<(__I2C_SCL_BIT<<1));
	#define __I2C_SCL_FLOATING 			SN_GPIO2->CFG|=(0x02<<(__I2C_SCL_BIT<<1));
	#define __I2C_SCL_OUTPUT_H 	 		SN_GPIO2->BSET =(0x01<<__I2C_SCL_BIT);
	#define __I2C_SCL_OUTPUT_L  		SN_GPIO2->BCLR =(0x01<<__I2C_SCL_BIT);
	#define	__I2C_SCL_DATA					((SN_GPIO2->DATA)&(0x01<<__I2C_SCL_BIT))==(0x01<<__I2C_SCL_BIT)
#endif

	
	#define	__I2C_TIME_OUT					255
	
/*_____ D E C L A R A T I O N S ____________________________________________*/

#endif	/*__SN32F770_SWI2C_H*/

