OSDN Git Service

STPK-966: Fix orientation of accelerometer z-axis
[android-x86/hardware-intel-libsensors.git] / common.h
1 /*
2  * Copyright (C) 2014 Intel Corporation.
3  */
4
5 #ifndef __COMMON_H__
6 #define __COMMON_H__
7
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 */
11
12 #define DEV_FILE_PATH   "/dev/iio:device%d"
13
14 #define BASE_PATH       "/sys/bus/iio/devices/iio:device%d/"
15
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 SENSOR_OFFSET_PATH      BASE_PATH "in_%s_offset"
21 #define SENSOR_SCALE_PATH       BASE_PATH "in_%s_scale"
22 #define SENSOR_SAMPLING_PATH    BASE_PATH "in_%s_sampling_frequency"
23 #define DEVICE_SAMPLING_PATH    BASE_PATH "sampling_frequency"
24 #define DEVICE_AVAIL_FREQ_PATH  BASE_PATH "sampling_frequency_available"
25
26 #define PROP_BASE       "ro.iio.%s.%s" /* Note: PROPERTY_KEY_MAX is small */
27
28 #define MAX_TYPE_SPEC_LEN 32    /* Channel type spec len; ex: "le:u10/16>>0" */
29 #define MAX_SENSOR_REPORT_SIZE  32      /* Sensor report buffer size */
30
31 #define MAX_NAME_SIZE           32
32
33 #define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
34
35 struct channel_descriptor_t
36 {
37         /* sysfs entries located under scan_elements */
38         const char *en_path;    /* Enabled sysfs file name ; ex: "in_temp_en" */
39         const char *type_path;  /* _type sysfs file name  */
40         const char *index_path; /* _index sysfs file name */
41
42         /* sysfs entries located in /sys/bus/iio/devices/iio:deviceX */
43         const char *raw_path;   /* _raw sysfs file name  */
44         const char *input_path; /* _input sysfs file name */
45 };
46
47 struct sensor_catalog_entry_t
48 {
49         const char *tag; /* Prefix such as "accel", "gyro", "temp"... */
50         const int type;  /* Sensor type ; ex: SENSOR_TYPE_ACCELEROMETER */
51         const int num_channels; /* Expected iio channels for this sensor */
52         struct channel_descriptor_t channel[MAX_CHANNELS];
53 };
54
55 struct datum_info_t
56 {
57         char sign;
58         char endianness;
59         short realbits;
60         short storagebits;
61         short shift;
62 };
63
64 struct channel_info_t
65 {
66         int offset; /* Offset in bytes within the iio character device report */
67         int size;                       /* Field size in bytes */
68         char type_spec[MAX_TYPE_SPEC_LEN]; /* From driver; ex: le:u10/16>>0 */
69         struct datum_info_t type_info;     /* Decoded contents of type spec */
70 };
71
72 struct sample_ops_t
73 {
74         /* Conversion function called once per channel */
75         float (*transform)(int s, int c, unsigned char* sample_data);
76
77         /* Function called once per sample */
78         void (*finalize)(int s, struct sensors_event_t* data);
79 };
80
81 struct sensor_info_t
82 {
83         char friendly_name[MAX_NAME_SIZE];      /* ex: Accelerometer */
84         char internal_name[MAX_NAME_SIZE];      /* ex: accel_3d */
85         char vendor_name[MAX_NAME_SIZE];        /* ex: Intel */
86
87         float max_range;
88         float resolution;
89         float power;
90
91         float offset;   /* (cooked = raw + offset) * scale */
92         float scale;
93
94         int sampling_rate;      /* requested events / second */
95
96         int dev_num;    /* Associated iio dev num, ex: 3 for /dev/iio:device3 */
97         int enable_count;
98
99         int catalog_index;/* Associated entry within the sensor_catalog array */
100
101         int num_channels; /* Actual channel count ; 0 for poll mode sensors */
102
103         /*
104          * The array below indicates where to gather report data for this
105          * sensor inside the reports that we read from the iio character device.
106          * It is updated whenever channels are enabled or disabled on the same
107          * device. Channel size indicates the size in bytes of fields, and
108          * should be zero for disabled channels. The type field indicates how a
109          * specific channel data item is structured.
110          */
111         struct channel_info_t channel[MAX_CHANNELS];
112
113         /*
114          * This flag is set if we acquired data from the sensor but did not
115          * forward it to upper layers (i.e. Android) yet. If so, report_buffer
116          * contains that data.
117          */
118         int report_pending;
119
120         unsigned char report_buffer[MAX_SENSOR_REPORT_SIZE];
121
122         int64_t last_integration_ts; /* Last time an event was reported */
123
124         struct sample_ops_t ops;
125
126         /* Note: we may have to explicitely serialize access to some fields */
127 };
128
129 /* Reference a few commonly used variables... */
130 extern int                              sensor_count;
131 extern struct sensor_info_t             sensor_info[MAX_SENSORS];
132 extern struct sensor_catalog_entry_t    sensor_catalog[];
133
134 #endif