2026-03-20 21:16:58 +08:00
|
|
|
#ifndef __LHL_I2C_SLAVE_H__
|
|
|
|
|
#define __LHL_I2C_SLAVE_H__
|
|
|
|
|
|
|
|
|
|
#define MASTER_READ_SLAVE 1
|
|
|
|
|
#define MASTER_WRITE_SLAVE 0
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
u32 SB: 1;
|
|
|
|
|
u32 ADDR: 1;
|
|
|
|
|
u32 BTF: 1;
|
|
|
|
|
u32 ADD10: 1;
|
|
|
|
|
u32 STOPF: 1;
|
|
|
|
|
u32 TXSRE: 1;
|
|
|
|
|
u32 RXNE: 1;
|
|
|
|
|
u32 TXE: 1;
|
|
|
|
|
u32 BERR: 1;
|
|
|
|
|
u32 ARLO: 1;
|
|
|
|
|
u32 AF: 1;
|
|
|
|
|
u32 OVR: 1;
|
|
|
|
|
u32 : 4;
|
|
|
|
|
|
|
|
|
|
u32 MSL: 1;
|
|
|
|
|
u32 BUSY: 1;
|
|
|
|
|
u32 TRA: 1;
|
|
|
|
|
u32 : 1;
|
|
|
|
|
u32 GENCALL: 1;
|
|
|
|
|
u32 : 2;
|
|
|
|
|
u32 DAULF: 1;
|
|
|
|
|
u32 PEC: 8;
|
|
|
|
|
} __HWI2C_SR_BIT_TypeDef;
|
|
|
|
|
|
|
|
|
|
typedef union
|
|
|
|
|
{
|
|
|
|
|
__HWI2C_SR_BIT_TypeDef Bit;
|
|
|
|
|
u32 DWord;
|
|
|
|
|
u16 Word[2];
|
|
|
|
|
} __HWI2C_SR_REG_TypeDef;
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
u16 ReceivedData: 1;
|
|
|
|
|
u16 SendingData: 1;
|
|
|
|
|
u16 TransparentMode: 1;
|
|
|
|
|
u16 AutoReview: 1;
|
|
|
|
|
u16 Reset: 1;
|
|
|
|
|
u16 CommError: 1;
|
|
|
|
|
u16 Command: 1;
|
|
|
|
|
u16 ReceivedAdr: 1;
|
|
|
|
|
u16 WriteData: 1;
|
|
|
|
|
} __I2C_BIT_TypeDef;
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
__I2C_BIT_TypeDef state;
|
|
|
|
|
u16 rxIndex;
|
|
|
|
|
u16 txLenth;
|
|
|
|
|
u16 rxCounter;
|
|
|
|
|
u16 txCounter;
|
|
|
|
|
u16 Index;
|
|
|
|
|
u16 regCounter;
|
|
|
|
|
u16 regLen;
|
|
|
|
|
u16 readAddr;
|
|
|
|
|
u8 rxData[20];
|
|
|
|
|
u8 txData[20];
|
|
|
|
|
__HWI2C_SR_REG_TypeDef status;
|
|
|
|
|
u8 Adr;
|
|
|
|
|
} I2C_DATA_TypeDef;
|
|
|
|
|
|
|
|
|
|
extern I2C_DATA_TypeDef I2CData;
|
|
|
|
|
void I2C_Slave_Init(u32 clockSpeed ,u16 slaveAddress);
|
2026-03-20 21:19:04 +08:00
|
|
|
void DMA_I2C_Slave_Init(u32 clockSpeed ,u16 slaveAddress);
|
2026-03-20 21:16:58 +08:00
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
|
|
|
|
|
|
void IIC_Cmd_Check_Test(void);
|
|
|
|
|
void enter_streaming_mode(void);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|