OSDN Git Service

STPK-1429 Minor optimization to poll-mode sensor handling
[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 COMMON_OFFSET_PATH      BASE_PATH "in_%s_offset"
21 #define COMMON_SCALE_PATH       BASE_PATH "in_%s_scale"
22
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 */
25
26 #define MAX_NAME_SIZE           32
27
28 #define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
29
30 struct channel_descriptor_t
31 {
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 */
36
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 */
40 };
41
42 struct sensor_catalog_entry_t
43 {
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];
48 };
49
50 struct datum_info_t
51 {
52         char sign;
53         char endianness;
54         short realbits;
55         short storagebits;
56         short shift;
57 };
58
59 struct channel_info_t
60 {
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 */
65 };
66
67 struct sensor_info_t
68 {
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 */
72
73         float max_range;
74         float resolution;
75         float power;
76
77         float offset;   /* (cooked = raw + offset) * scale */
78         float scale;
79
80         int dev_num;    /* Associated iio dev num, ex: 3 for /dev/iio:device3 */
81         int enable_count;
82
83         int catalog_index;/* Associated entry within the sensor_catalog array */
84
85         int num_channels; /* Actual channel count ; 0 for poll mode sensors */
86
87         /*
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.
94          */
95         struct channel_info_t channel[MAX_CHANNELS];
96
97         /*
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.
101          */
102         int report_pending;
103
104         unsigned char report_buffer[MAX_SENSOR_REPORT_SIZE];
105
106         /* Note: we may have to explicitely serialize access to some fields */
107 };
108
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[];
113
114 #endif