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/"
17 #define CHANNEL_PATH BASE_PATH "scan_elements/"
18 #define ENABLE_PATH BASE_PATH "buffer/enable"
19 #define NAME_PATH BASE_PATH "name"
20 #define TRIGGER_PATH BASE_PATH "trigger/current_trigger"
21 #define SENSOR_OFFSET_PATH BASE_PATH "in_%s_offset"
22 #define SENSOR_SCALE_PATH BASE_PATH "in_%s_scale"
23 #define SENSOR_SAMPLING_PATH BASE_PATH "in_%s_sampling_frequency"
24 #define DEVICE_SAMPLING_PATH BASE_PATH "sampling_frequency"
25 #define DEVICE_AVAIL_FREQ_PATH BASE_PATH "sampling_frequency_available"
26 #define ILLUMINATION_CALIBPATH BASE_PATH "in_illuminance_calibscale"
28 #define PROP_BASE "ro.iio.%s.%s" /* Note: PROPERTY_KEY_MAX is small */
30 #define MAX_TYPE_SPEC_LEN 32 /* Channel type spec len; ex: "le:u10/16>>0" */
31 #define MAX_SENSOR_REPORT_SIZE 32 /* Sensor report buffer size */
33 #define MAX_NAME_SIZE 32
35 #define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
38 struct channel_descriptor_t
40 const char *name; /* channel name ; ex: x */
42 /* sysfs entries located under scan_elements */
43 const char *en_path; /* Enabled sysfs file name ; ex: "in_temp_en" */
44 const char *type_path; /* _type sysfs file name */
45 const char *index_path; /* _index sysfs file name */
47 /* sysfs entries located in /sys/bus/iio/devices/iio:deviceX */
48 const char *raw_path; /* _raw sysfs file name */
49 const char *input_path; /* _input sysfs file name */
50 const char *scale_path; /* _scale sysfs file name */
53 struct sensor_catalog_entry_t
55 const char *tag; /* Prefix such as "accel", "gyro", "temp"... */
56 const int type; /* Sensor type ; ex: SENSOR_TYPE_ACCELEROMETER */
57 const int num_channels; /* Expected iio channels for this sensor */
58 struct channel_descriptor_t channel[MAX_CHANNELS];
72 int offset; /* Offset in bytes within the iio character device report */
73 int size; /* Field size in bytes */
74 float scale; /* scale for each channel */
75 char type_spec[MAX_TYPE_SPEC_LEN]; /* From driver; ex: le:u10/16>>0 */
76 struct datum_info_t type_info; /* Decoded contents of type spec */
77 float opt_scale; /* Optional correction scale read from a property such
78 * as iio.accel.x.scale, allowing late compensation of
79 * problems such as misconfigured axes ; set to 1 by
80 * default. Applied at the end of the scaling process.
86 /* Conversion function called once per channel */
87 float (*transform)(int s, int c, unsigned char* sample_data);
89 /* Function called once per sample */
90 void (*finalize)(int s, struct sensors_event_t* data);
95 char friendly_name[MAX_NAME_SIZE]; /* ex: Accelerometer */
96 char internal_name[MAX_NAME_SIZE]; /* ex: accel_3d */
97 char vendor_name[MAX_NAME_SIZE]; /* ex: Intel */
103 float offset; /* (cooked = raw + offset) * scale */
104 float scale; /*default: 1. when set to 0, use channel specific value*/
105 float illumincalib; /* to set the calibration for the ALS */
107 int sampling_rate; /* requested events / second */
109 int dev_num; /* Associated iio dev num, ex: 3 for /dev/iio:device3 */
112 int catalog_index;/* Associated entry within the sensor_catalog array */
114 int num_channels; /* Actual channel count ; 0 for poll mode sensors */
117 * The array below indicates where to gather report data for this
118 * sensor inside the reports that we read from the iio character device.
119 * It is updated whenever channels are enabled or disabled on the same
120 * device. Channel size indicates the size in bytes of fields, and
121 * should be zero for disabled channels. The type field indicates how a
122 * specific channel data item is structured.
124 struct channel_info_t channel[MAX_CHANNELS];
127 * This flag is set if we acquired data from the sensor but did not
128 * forward it to upper layers (i.e. Android) yet. If so, report_buffer
129 * contains that data.
134 * Timestamp closely matching the date of sampling, preferably retrieved
135 * from a iio channel alongside sample data. Value zero indicates that
136 * we couldn't get such a closely correlated timestamp, and that one
137 * has to be generated before the report gets sent up to Android.
141 unsigned char report_buffer[MAX_SENSOR_REPORT_SIZE];
143 int64_t last_integration_ts; /* Last time an event was reported */
145 struct sample_ops_t ops;
147 /* Note: we may have to explicitely serialize access to some fields */
150 /* Reference a few commonly used variables... */
151 extern int sensor_count;
152 extern struct sensor_info_t sensor_info[MAX_SENSORS];
153 extern struct sensor_catalog_entry_t sensor_catalog[];