RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_i2c_helpers.h
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#pragma once
12
13#ifndef I2C_M_TEN
14#include <linux/i2c.h>
15#endif
16
17static inline vrpn_int32 vrpn_i2c_smbus_access(
18 int file, char read_write, vrpn_uint8 command,
19 int size, union i2c_smbus_data *data)
20{
21 struct i2c_smbus_ioctl_data args;
22
23 args.read_write = read_write;
24 args.command = command;
25 args.size = size;
26 args.data = data;
27 return ioctl(file,I2C_SMBUS,&args);
28}
29
30static inline vrpn_int32 vrpn_i2c_smbus_write_byte_data(
31 int file, vrpn_uint8 command, vrpn_uint8 value)
32{
33 union i2c_smbus_data data;
34 data.byte = value;
35 return vrpn_i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
36 I2C_SMBUS_BYTE_DATA, &data);
37}
38
39static inline vrpn_int32 vrpn_i2c_smbus_read_i2c_block_data(
40 int file, vrpn_uint8 command,
41 vrpn_uint8 length, vrpn_uint8 *values)
42{
43 union i2c_smbus_data data;
44 int i;
45
46 if (length > 32) { length = 32; }
47 data.block[0] = length;
48 if (vrpn_i2c_smbus_access(file,I2C_SMBUS_READ,command,
49 length == 32 ? I2C_SMBUS_I2C_BLOCK_BROKEN :
50 I2C_SMBUS_I2C_BLOCK_DATA,&data)) {
51 return -1;
52 } else {
53 for (i = 0; i < data.block[0]; i++) {
54 values[i] = data.block[i+1];
55 }
56 return data.block[0];
57 }
58}
59