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"
22 #define COMMON_SAMPLING_PATH BASE_PATH "in_%s_sampling_frequency"
24 #define PROP_BASE "ro.iio.%s.%s" /* Note: PROPERTY_KEY_MAX is small */
26 #define MAX_TYPE_SPEC_LEN 32 /* Channel type spec len; ex: "le:u10/16>>0" */
27 #define MAX_SENSOR_REPORT_SIZE 32 /* Sensor report buffer size */
29 #define MAX_NAME_SIZE 32
31 #define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
33 struct channel_descriptor_t
35 /* sysfs entries located under scan_elements */
36 const char *en_path; /* Enabled sysfs file name ; ex: "in_temp_en" */
37 const char *type_path; /* _type sysfs file name */
38 const char *index_path; /* _index sysfs file name */
40 /* sysfs entries located in /sys/bus/iio/devices/iio:deviceX */
41 const char *raw_path; /* _raw sysfs file name */
42 const char *input_path; /* _input sysfs file name */
45 struct sensor_catalog_entry_t
47 const char *tag; /* Prefix such as "accel", "gyro", "temp"... */
48 const int type; /* Sensor type ; ex: SENSOR_TYPE_ACCELEROMETER */
49 const int num_channels; /* Expected iio channels for this sensor */
50 struct channel_descriptor_t channel[MAX_CHANNELS];
64 int offset; /* Offset in bytes within the iio character device report */
65 int size; /* Field size in bytes */
66 char type_spec[MAX_TYPE_SPEC_LEN]; /* From driver; ex: le:u10/16>>0 */
67 struct datum_info_t type_info; /* Decoded contents of type spec */
72 char friendly_name[MAX_NAME_SIZE]; /* ex: Accelerometer */
73 char internal_name[MAX_NAME_SIZE]; /* ex: accel_3d */
74 char vendor_name[MAX_NAME_SIZE]; /* ex: Intel */
80 float offset; /* (cooked = raw + offset) * scale */
83 int sampling_rate; /* requested events / second */
85 int dev_num; /* Associated iio dev num, ex: 3 for /dev/iio:device3 */
88 int catalog_index;/* Associated entry within the sensor_catalog array */
90 int num_channels; /* Actual channel count ; 0 for poll mode sensors */
93 * The array below indicates where to gather report data for this
94 * sensor inside the reports that we read from the iio character device.
95 * It is updated whenever channels are enabled or disabled on the same
96 * device. Channel size indicates the size in bytes of fields, and
97 * should be zero for disabled channels. The type field indicates how a
98 * specific channel data item is structured.
100 struct channel_info_t channel[MAX_CHANNELS];
103 * This flag is set if we acquired data from the sensor but did not
104 * forward it to upper layers (i.e. Android) yet. If so, report_buffer
105 * contains that data.
109 unsigned char report_buffer[MAX_SENSOR_REPORT_SIZE];
111 /* Note: we may have to explicitely serialize access to some fields */
114 /* Reference a few commonly used variables... */
115 extern int sensor_count;
116 extern struct sensor_info_t sensor_info[MAX_SENSORS];
117 extern struct sensor_catalog_entry_t sensor_catalog[];