#ifndef __IIC_SOFTWARE_H__
#define __IIC_SOFTWARE_H__

#include "BoardConfig.h"
#include "ch32v30x_conf.h"

// #define   MS933X_SCL      (GPIO_Pin_19)
// #define   MS933X_SDA      (GPIO_Pin_18)

//IO鏂瑰悜璁剧疆
//0XFFFF0FFF -> GPIOB-Pin11
//GPIOB->CFGHR PB8-PB15 , GPIOB->CFGLR PB0-PB7
// #define SDA_IN()  {GPIOB->CFGHR&=0XFFFFFF0F;GPIOB->CFGHR|=8<<(4*1);} //GPIOB9 配置成上拉（下拉）输入模式
// #define SDA_OUT() {GPIOB->CFGHR&=0XFFFFFF0F;GPIOB->CFGHR|=3<<(4*1);}

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

#define SDA_IN()  {GPIOC->CFGLR&=0XF0FFFFFF;GPIOC->CFGLR|=8<<(4*6);} //PC6
#define SDA_OUT() {GPIOC->CFGLR&=0XF0FFFFFF;GPIOC->CFGLR|=3<<(4*6);}

//IO鎿嶄綔鍑芥暟
#define IIC_SCL(i)       GPIO_WriteBit(GPIOC,MS933X_SCL,i) //SCL
#define IIC_SDA(i)       GPIO_WriteBit(GPIOC,MS933X_SDA,i)
#define READ_SDA         GPIO_ReadInputDataBit(GPIOC,MS933X_SDA) //输入SDA

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

VOID mculib_i2c_init(VOID);            //初始化IIC的IO口

u8 IIC_Check_Address(u8 Address);
u8 IIC_Send_8bitMultiBytes(u8 address, u8 reg, u8 *str, u8 num);
u8 IIC_Read_8bitMultiBytes(u8 address, u8 reg, u8 *str, u8 num);
u8 IIC_Read_8bitMultiBytes_sgm832(u8 address, u8 reg, u16 *str, u8 num);


u8 IIC_Send_16bit_LE_MultiBytes(u8 address, u16 reg, u8 *str, u8 num);
u8 IIC_Read_16bit_LE_MultiBytes(u8 address, u16 reg, u8 *str, u8 num);

u8 IIC_Send_16bit_BE_MultiBytes(u8 address, u16 reg, u8 *str, u8 num);
u8 IIC_Read_16bit_BE_MultiBytes(u8 address, u16 reg, u8 *str, u8 num);

#endif
