i2c.h
Go to the documentation of this file.
1 
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8 
9 #include <sys/types.h>
10 #include <linux/i2c.h>
11 #include <linux/i2c-dev.h>
12 
16 typedef struct i2c_device
17 {
18  int bus;
19  unsigned short addr;
20  unsigned char tenbit;
21  unsigned char delay;
22  unsigned short flags;
23  unsigned int page_bytes;
24  unsigned int iaddr_bytes;
25 } I2CDevice;
26 
27 /* Open i2c bus, return i2c bus fd */
28 int i2c_open(const char *bus_name);
29 
30 /* Close i2c bus */
31 void i2c_close(int bus);
32 
33 /* Initialize I2CDevice with default value */
34 void i2c_init_device(I2CDevice *device);
35 
36 /* Get i2c device description */
37 char* i2c_get_device_desc(const I2CDevice *device, char *buf, size_t size);
38 
39 /* Select i2c device on i2c bus */
40 int i2c_select(int bus, unsigned long dev_addr, unsigned long tenbit);
41 
42 /* I2C internal(word) address convert */
43 void i2c_iaddr_convert(unsigned int int_addr, unsigned int iaddr_bytes, unsigned char *addr);
44 
45 /* I2C file I/O read, write */
46 ssize_t i2c_read(const I2CDevice *device, unsigned int iaddr, void *buf, size_t len);
47 ssize_t i2c_write(const I2CDevice *device, unsigned int iaddr, const void *buf, size_t len);
48 
49 /* I2c ioctl read, write can set i2c flags */
50 ssize_t i2c_ioctl_read(const I2CDevice *device, unsigned int iaddr, void *buf, size_t len);
51 ssize_t i2c_ioctl_write(const I2CDevice *device, unsigned int iaddr, const void *buf, size_t len);
52 
53 /* I2C smbus read, write */
54 ssize_t i2c_smbus_read(const I2CDevice *device, unsigned int iaddr, unsigned char *buf, size_t len);
55 ssize_t i2c_smbus_write(const I2CDevice *device, unsigned int iaddr, const unsigned char *buf, size_t len);
56 
57 /* I2C read, write to update MCU (SBL)*/
58 ssize_t i2c_sbl_read(const I2CDevice *device, void *buf, size_t len);
59 ssize_t i2c_sbl_write(const I2CDevice *device, const void *buf, size_t len);
60 
64 typedef ssize_t (*I2C_READ_HANDLE)(const I2CDevice *dev, unsigned int iaddr, void *buf, size_t len);
68 typedef ssize_t (*I2C_WRITE_HANDLE)(const I2CDevice *dev, unsigned int iaddr, const void *buf, size_t len);
69 
70 #ifdef __cplusplus
71 }
72 #endif
unsigned char tenbit
I2C is 10 bit device address.
Definition: i2c.h:20
unsigned short flags
I2C i2c_ioctl_read/write flags.
Definition: i2c.h:22
int bus
I2C Bus fd, return from i2c_open.
Definition: i2c.h:18
unsigned short addr
I2C device(slave) address.
Definition: i2c.h:19
ssize_t(* I2C_WRITE_HANDLE)(const I2CDevice *dev, unsigned int iaddr, const void *buf, size_t len)
I2C write handle function.
Definition: i2c.h:68
unsigned int page_bytes
I2C max number of bytes per page, 1K/2K 8, 4K/8K/16K 16, 32K/64K 32 etc.
Definition: i2c.h:23
unsigned int iaddr_bytes
I2C device internal(word) address bytes, such as: 24C04 1 byte, 24C64 2 bytes.
Definition: i2c.h:24
struct i2c_device I2CDevice
I2c device structure.
unsigned char delay
I2C internal operation delay, unit millisecond.
Definition: i2c.h:21
ssize_t(* I2C_READ_HANDLE)(const I2CDevice *dev, unsigned int iaddr, void *buf, size_t len)
I2C read handle function.
Definition: i2c.h:64
I2c device structure.
Definition: i2c.h:16