-
Notifications
You must be signed in to change notification settings - Fork 14
/
sw_i2c.h
44 lines (33 loc) · 1.21 KB
/
sw_i2c.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef _SW_I2C_H_
#define _SW_I2C_H_
#include <stdint.h>
#define SW_I2C_WAIT_TIME 10 // 10us 100kHz
#define I2C_READ 0x01
#define READ_CMD 1
#define WRITE_CMD 0
typedef enum
{
HAL_IO_OPT_SET_SDA_LOW = 0,
HAL_IO_OPT_SET_SDA_HIGH,
HAL_IO_OPT_SET_SCL_LOW,
HAL_IO_OPT_SET_SCL_HIGH,
HAL_IO_OPT_SET_SDA_INPUT,
HAL_IO_OPT_SET_SDA_OUTPUT,
HAL_IO_OPT_SET_SCL_INPUT,
HAL_IO_OPT_SET_SCL_OUTPUT,
HAL_IO_OPT_GET_SDA_LEVEL,
HAL_IO_OPT_GET_SCL_LEVEL,
}hal_io_opt_e;
typedef struct sw_i2c_s {
int (*hal_init)(void);
int (*hal_io_ctl)(hal_io_opt_e opt, void *arg);
void (*hal_delay_us)(uint32_t us);
} sw_i2c_t;
/* functions */
void SW_I2C_initial(sw_i2c_t *d);
uint8_t SW_I2C_Read_8addr(sw_i2c_t *d, uint8_t IICID, uint8_t regaddr, uint8_t *pdata, uint8_t rcnt);
uint8_t SW_I2C_Read_16addr(sw_i2c_t *d, uint8_t IICID, uint16_t regaddr, uint8_t *pdata, uint8_t rcnt);
uint8_t SW_I2C_Write_8addr(sw_i2c_t *d, uint8_t IICID, uint8_t regaddr, uint8_t *pdata, uint8_t rcnt);
uint8_t SW_I2C_Write_16addr(sw_i2c_t *d, uint8_t IICID, uint16_t regaddr, uint8_t *pdata, uint8_t rcnt);
uint8_t SW_I2C_Check_SlaveAddr(sw_i2c_t *d, uint8_t IICID);
#endif /* __I2C_SW_H */