#ifndef _SOFT_IIC_H
#define _SOFT_IIC_H

#include "include.h"

/**软件IIC引脚定义**/
#define I2C_SDA_GPIO    GPIOB_REG
#define I2C_SDA_PIN     GPIO_PIN_2
#define I2C_SCL_GPIO    GPIOB_REG
#define I2C_SCL_PIN     GPIO_PIN_1


#define SDA_DIR_OUT()       {I2C_SDA_GPIO->de |= I2C_SDA_PIN; I2C_SDA_GPIO->dir &= ~I2C_SDA_PIN;}
#define SDA_DIR_IN()        {I2C_SDA_GPIO->dir |= I2C_SDA_PIN; I2C_SDA_GPIO->pupd[0] |= I2C_SDA_PIN;}
#define SDA_OUT_H()         {I2C_SDA_GPIO->io_set = I2C_SDA_PIN;}
#define SDA_OUT_L()         {I2C_SDA_GPIO->io_clr = I2C_SDA_PIN;}
#define SDA_STA()           (I2C_SDA_GPIO->dr & I2C_SDA_PIN)

#define SCL_DIR_OUT()       {I2C_SCL_GPIO->de |= I2C_SCL_PIN; I2C_SCL_GPIO->dir &= ~I2C_SCL_PIN;}
#define SCL_DIR_IN()        {I2C_SCL_GPIO->dir |= I2C_SCL_PIN; I2C_SCL_GPIO->pupd[0]  |= I2C_SCL_PIN;}
#define SCL_OUT_H()         {I2C_SCL_GPIO->io_set = I2C_SCL_PIN;}
#define SCL_OUT_L()         {I2C_SCL_GPIO->io_clr = I2C_SCL_PIN;}
#define SCL_STA()           (I2C_SCL_GPIO->dr & I2C_SCL_PIN)

void i2c_init(void);
void i2c_start(void);
void i2c_stop(void);
void i2c_send_byte(u8 data);
u8 i2c_read_byte(u8 ack);
u8 i2c_wait_ack(void);
void i2c_ack(void);
void i2c_nack(void);

#endif // _SOFT_IIC_H
