54 lines
2.3 KiB
C
54 lines
2.3 KiB
C
|
#ifndef __I2C_H
|
|||
|
#define __I2C_H
|
|||
|
|
|||
|
#include "stm32h7xx.h"
|
|||
|
|
|||
|
/*<2A>趨<EFBFBD><E8B6A8>AP3216C IIC<49>豸<EFBFBD><E8B1B8>ַ*/
|
|||
|
#define AP3216C_ADDR 0x3C
|
|||
|
|
|||
|
#define I2CT_FLAG_TIMEOUT ((uint32_t)0x1000)
|
|||
|
#define I2CT_LONG_TIMEOUT ((uint32_t)(10 * I2CT_FLAG_TIMEOUT))
|
|||
|
|
|||
|
/*I2C<32><43><EFBFBD><EFBFBD>*/
|
|||
|
#define AP3216C_I2C_SCL_PIN GPIO_PIN_8
|
|||
|
#define AP3216C_I2C_SCL_GPIO_PORT GPIOB
|
|||
|
#define AP3216C_I2C_SCL_GPIO_CLK_ENABLE() __GPIOB_CLK_ENABLE()
|
|||
|
|
|||
|
#define AP3216C_I2C_SDA_PIN GPIO_PIN_9
|
|||
|
#define AP3216C_I2C_SDA_GPIO_PORT GPIOB
|
|||
|
#define AP3216C_I2C_SDA_GPIO_CLK_ENABLE() __GPIOB_CLK_ENABLE()
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>IICʹ<43>õĺ<C3B5>
|
|||
|
#define I2C_SCL_1() HAL_GPIO_WritePin(AP3216C_I2C_SCL_GPIO_PORT, AP3216C_I2C_SCL_PIN,GPIO_PIN_SET) /* SCL = 1 */
|
|||
|
#define I2C_SCL_0() HAL_GPIO_WritePin(AP3216C_I2C_SCL_GPIO_PORT, AP3216C_I2C_SCL_PIN,GPIO_PIN_RESET) /* SCL = 0 */
|
|||
|
|
|||
|
#define I2C_SDA_1() HAL_GPIO_WritePin(AP3216C_I2C_SDA_GPIO_PORT, AP3216C_I2C_SDA_PIN,GPIO_PIN_SET) /* SDA = 1 */
|
|||
|
#define I2C_SDA_0() HAL_GPIO_WritePin(AP3216C_I2C_SDA_GPIO_PORT, AP3216C_I2C_SDA_PIN,GPIO_PIN_RESET) /* SDA = 0 */
|
|||
|
|
|||
|
#define I2C_SDA_READ() HAL_GPIO_ReadPin(AP3216C_I2C_SDA_GPIO_PORT, AP3216C_I2C_SDA_PIN) /* <20><>SDA<44><41><EFBFBD><EFBFBD>״̬ */
|
|||
|
|
|||
|
/*<2A><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>*/
|
|||
|
#define I2C_DEBUG_ON 1
|
|||
|
#define I2C_DEBUG_FUNC_ON 0
|
|||
|
|
|||
|
#define I2C_INFO(fmt,arg...) printf("<<-I2C-INFO->> "fmt"\n",##arg)
|
|||
|
#define I2C_ERROR(fmt,arg...) printf("<<-I2C-ERROR->> "fmt"\n",##arg)
|
|||
|
#define I2C_DEBUG(fmt,arg...) do{\
|
|||
|
if(I2C_DEBUG_ON)\
|
|||
|
printf("<<-I2C-DEBUG->> [%d]"fmt"\n",__LINE__, ##arg);\
|
|||
|
}while(0)
|
|||
|
|
|||
|
#define I2C_DEBUG_FUNC() do{\
|
|||
|
if(I2C_DEBUG_FUNC_ON)\
|
|||
|
printf("<<-I2C-FUNC->> Func:%s@Line:%d\n",__func__,__LINE__);\
|
|||
|
}while(0)
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
|||
|
void I2C_Init(void);
|
|||
|
uint32_t I2C_WriteBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint8_t NumByteToWrite);
|
|||
|
uint32_t I2C_ReadBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint16_t NumByteToRead);
|
|||
|
uint32_t Sensor_write(uint8_t reg_add,uint8_t reg_dat);
|
|||
|
uint32_t Sensor_Read(uint8_t reg_add,unsigned char* Read,uint8_t num);
|
|||
|
|
|||
|
#endif /* __BSP_I2C */
|