#ifndef __IIC3_SOFTWARE_H__
#define __IIC3_SOFTWARE_H__

#include "BoardConfig.h"
#include "ch32v30x.h"

//IO方向设置
//0XFFFF0FFF -> GPIOB-Pin11
//GPIOB->CFGHR PB8-PB15 , GPIOB->CFGLR PB0-PB7
//#define SDA3_IN()  {GPIOB->CFGHR&=0XFFFF0FFF;GPIOB->CFGHR|=8<<(4*3);} //GPIOB11 配置成上拉（下拉）输入模式
//#define SDA3_OUT() {GPIOB->CFGHR&=0XFFFF0FFF;GPIOB->CFGHR|=3<<(4*3);}

#define SDA3_IN()  {GPIOB->CFGLR&=0XFF0FFFFF;GPIOB->CFGLR|=8<<(4*5);} //PB5
#define SDA3_OUT() {GPIOB->CFGLR&=0XFF0FFFFF;GPIOB->CFGLR|=3<<(4*5);}

// #define SDA2_IN()  {}//{GPIOB->CFGLR&=0X0FFFFFFF;GPIOB->CFGLR|=8<<(4*7);} //PB7
// #define SDA2_OUT() {}//{GPIOB->CFGLR&=0X0FFFFFFF;GPIOB->CFGLR|=3<<(4*7);}

//IO操作函数
#define IIC3_SCL(i)       GPIO_WriteBit(GPIOB,SENSOR_SCL,i) //SCL
#define IIC3_SDA(i)       GPIO_WriteBit(GPIOB,SENSOR_SDA,i)
#define READ3_SDA         GPIO_ReadInputDataBit(GPIOB,SENSOR_SDA) //输入SDA

//Public functions
void IIC3_sf_Init(void);            //初始化IIC的IO口

u8 IIC3_Check_Address(u8 Address);
u8 IIC3_Send_8bitMultiBytes(u8 address, u8 reg, u8 *str, u8 num);
u8 IIC3_Read_8bitMultiBytes(u8 address, u8 reg, u8 *str, u8 num);

u8 IIC3_Send_16bit_LE_MultiBytes(u8 address, u16 reg, u8 *str, u16 num);
u8 IIC3_Read_16bit_LE_MultiBytes(u8 address, u16 reg, u8 *str, u8 num);

u8 IIC3_Send_16bit_BE_MultiBytes(u8 address, u16 reg, u8 *str, u8 num);
u8 IIC3_Read_16bit_BE_MultiBytes(u8 address, u16 reg, u8 *str, u8 num);

u8 IIC3_Read_8bitMultiBytes_sgm832(u8 address, u8 reg, u16 *str, u8 num);

#endif
