2 * Copyright (C) 2014 Intel Corporation.
8 #define MAX_DEVICES 8 /* Check iio devices 0 to MAX_DEVICES-1 */
9 #define MAX_SENSORS 10 /* We can handle as many sensors */
10 #define MAX_CHANNELS 4 /* We can handle as many channels per sensor */
12 #define DEV_FILE_PATH "/dev/iio:device%d"
14 #define BASE_PATH "/sys/bus/iio/devices/iio:device%d/"
16 #define CHANNEL_PATH BASE_PATH "scan_elements/"
17 #define ENABLE_PATH BASE_PATH "buffer/enable"
18 #define NAME_PATH BASE_PATH "name"
19 #define TRIGGER_PATH BASE_PATH "trigger/current_trigger"
20 #define COMMON_OFFSET_PATH BASE_PATH "in_%s_offset"
21 #define COMMON_SCALE_PATH BASE_PATH "in_%s_scale"
23 #define MAX_TYPE_SPEC_LEN 32 /* Channel type spec len; ex: "le:u10/16>>0" */
24 #define MAX_SENSOR_REPORT_SIZE 32 /* Sensor report buffer size */
26 #define MAX_NAME_SIZE 32
28 #define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
30 struct channel_descriptor_t
32 /* sysfs entries located under scan_elements */
33 const char *en_path; /* Enabled sysfs file name ; ex: "in_temp_en" */
34 const char *type_path; /* _type sysfs file name */
35 const char *index_path; /* _index sysfs file name */
37 /* sysfs entries located in /sys/bus/iio/devices/iio:deviceX */
38 const char *raw_path; /* _raw sysfs file name */
39 const char *input_path; /* _input sysfs file name */
42 struct sensor_catalog_entry_t
44 const char *tag; /* Prefix such as "accel", "gyro", "temp"... */
45 const int type; /* Sensor type ; ex: SENSOR_TYPE_ACCELEROMETER */
46 const int num_channels; /* Expected iio channels for this sensor */
47 struct channel_descriptor_t channel[MAX_CHANNELS];
61 int offset; /* Offset in bytes within the iio character device report */
62 int size; /* Field size in bytes */
63 char type_spec[MAX_TYPE_SPEC_LEN]; /* From driver; ex: le:u10/16>>0 */
64 struct datum_info_t type_info; /* Decoded contents of type spec */
69 char friendly_name[MAX_NAME_SIZE]; /* ex: Accelerometer */
70 char internal_name[MAX_NAME_SIZE]; /* ex: accel_3d */
71 char vendor_name[MAX_NAME_SIZE]; /* ex: Intel */
77 float offset; /* (cooked = raw + offset) * scale */
80 int dev_num; /* Associated iio dev num, ex: 3 for /dev/iio:device3 */
83 int catalog_index;/* Associated entry within the sensor_catalog array */
85 int num_channels; /* Actual channel count ; 0 for poll mode sensors */
88 * The array below indicates where to gather report data for this
89 * sensor inside the reports that we read from the iio character device.
90 * It is updated whenever channels are enabled or disabled on the same
91 * device. Channel size indicates the size in bytes of fields, and
92 * should be zero for disabled channels. The type field indicates how a
93 * specific channel data item is structured.
95 struct channel_info_t channel[MAX_CHANNELS];
98 * This flag is set if we acquired data from the sensor but did not
99 * forward it to upper layers (i.e. Android) yet. If so, report_buffer
100 * contains that data.
104 unsigned char report_buffer[MAX_SENSOR_REPORT_SIZE];
106 /* Note: we may have to explicitely serialize access to some fields */
109 /* Reference a few commonly used variables... */
110 extern int sensor_count;
111 extern struct sensor_info_t sensor_info[MAX_SENSORS];
112 extern struct sensor_catalog_entry_t sensor_catalog[];