vrpn 07.35
Virtual Reality Peripheral Network
 
Loading...
Searching...
No Matches
vrpn_i2c_helpers.h
Go to the documentation of this file.
1// Helper functions that are not present in the i2c-dev.h file on
2// all platforms. They fill in the parameters and call the appropriate
3// ioctl() and then package info for return.
4
5// Ensure that we don't include i2c.h on platforms like Raspberry Pi
6// where they pulled these definitions into i2c-dev.h rather than just
7// doing #include i2c.h, and where they also did not define _LINUX_I2C_H
8// to guard against its future inclusion. Here, we pick one of the
9// things that are defined in that file and check for it.
10
11#ifndef I2C_M_TEN
12#include <linux/i2c.h>
13#endif
14
15static inline vrpn_int32 vrpn_i2c_smbus_access(
16 int file, char read_write, vrpn_uint8 command,
17 int size, union i2c_smbus_data *data)
18{
19 struct i2c_smbus_ioctl_data args;
20
21 args.read_write = read_write;
22 args.command = command;
23 args.size = size;
24 args.data = data;
25 return ioctl(file,I2C_SMBUS,&args);
26}
27
28static inline vrpn_int32 vrpn_i2c_smbus_write_byte_data(
29 int file, vrpn_uint8 command, vrpn_uint8 value)
30{
31 union i2c_smbus_data data;
32 data.byte = value;
33 return vrpn_i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
34 I2C_SMBUS_BYTE_DATA, &data);
35}
36
37static inline vrpn_int32 vrpn_i2c_smbus_read_i2c_block_data(
38 int file, vrpn_uint8 command,
39 vrpn_uint8 length, vrpn_uint8 *values)
40{
41 union i2c_smbus_data data;
42 int i;
43
44 if (length > 32) { length = 32; }
45 data.block[0] = length;
46 if (vrpn_i2c_smbus_access(file,I2C_SMBUS_READ,command,
47 length == 32 ? I2C_SMBUS_I2C_BLOCK_BROKEN :
48 I2C_SMBUS_I2C_BLOCK_DATA,&data)) {
49 return -1;
50 } else {
51 for (i = 0; i < data.block[0]; i++) {
52 values[i] = data.block[i+1];
53 }
54 return data.block[0];
55 }
56}
57