#ifndef __CT_I2C_H_
#define __CT_I2C_H_

#include "stm32f4xx.h"
//#include "GPIO_Config.h"

///////////////////////////////////////////////////////////////
//位带操作,实现51类似的GPIO控制功能
//具体实现思想,参考<<CM3权威指南>>第五章(87页~92页).
//IO口操作宏定义
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 
#define MEM_ADDR(addr)  *((volatile unsigned long  *)(addr)) 
#define BIT_ADDR(addr, bitnum)   MEM_ADDR(BITBAND(addr, bitnum)) 

//IO操作函数	   
#define SET_SDA()     GPIO_SetBits(CT_SDA_GPIO_PORT,CT_SDA_GPIO_PIN)    
#define CLR_SDA()     GPIO_ResetBits(CT_SDA_GPIO_PORT,CT_SDA_GPIO_PIN)  

#define SET_CLK()     GPIO_SetBits(CT_SCL_GPIO_PORT,CT_SCL_GPIO_PIN)    
#define CLR_CLK()     GPIO_ResetBits(CT_SCL_GPIO_PORT,CT_SCL_GPIO_PIN)

#define CT_READ_SDA   GPIO_ReadInputDataBit(CT_SDA_GPIO_PORT,CT_SDA_GPIO_PIN)
#define CT_IIC_SDA     

#define CT_SDA_CLK    	   RCC_AHB1Periph_GPIOB
#define CT_SDA_GPIO_PORT   GPIOB
#define CT_SDA_GPIO_PIN    GPIO_Pin_7

#define CT_SCL_CLK    	   RCC_AHB1Periph_GPIOB
#define CT_SCL_GPIO_PORT   GPIOB
#define CT_SCL_GPIO_PIN    GPIO_Pin_6


#define CT_INT_CLK    	    RCC_AHB1Periph_GPIOH
#define CT_INT_GPIO_PORT   	GPIOH
#define CT_INT_GPIO_PIN   	GPIO_Pin_4
#define CT_INT_EXTI_LINE    EXTI_Line4

//IIC所有操作函数
void CT_I2C_Init(void);		 
void CT_I2C_Start(void);				//发送IIC开始信号
void CT_I2C_Stop(void);	  				//发送IIC停止信号
void CT_I2C_Send_Byte(u8 txd);			//IIC发送一个字节
u8 CT_I2C_Read_Byte(unsigned char ack);	//IIC读取一个字节
u8 CT_I2C_Wait_Ack(void); 				//IIC等待ACK信号
void CT_I2C_Ack(void);					//IIC发送ACK信号
void CT_I2C_NAck(void);					//IIC不发送ACK信号	  



#endif /*__CAP_I2C_H_*/


