OSDN Git Service

STPK-1429 Rename misleading macro definition
[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
24 #define PROP_BASE       "ro.iio.%s.%s" /* Note: PROPERTY_KEY_MAX is small */
25
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 */
28
29 #define MAX_NAME_SIZE           32
30
31 #define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
32
33 struct channel_descriptor_t
34 {
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 */
39
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 */
43 };
44
45 struct sensor_catalog_entry_t
46 {
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];
51 };
52
53 struct datum_info_t
54 {
55         char sign;
56         char endianness;
57         short realbits;
58         short storagebits;
59         short shift;
60 };
61
62 struct channel_info_t
63 {
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 */
68 };
69
70 struct sample_ops_t
71 {
72         /* Conversion function called once per channel */
73         float (*transform)(int s, int c, unsigned char* sample_data);
74
75         /* Function called once per sample */
76         void (*finalize)(int s, struct sensors_event_t* data);
77 };
78
79 struct sensor_info_t
80 {
81         char friendly_name[MAX_NAME_SIZE];      /* ex: Accelerometer */
82         char internal_name[MAX_NAME_SIZE];      /* ex: accel_3d */
83         char vendor_name[MAX_NAME_SIZE];        /* ex: Intel */
84
85         float max_range;
86         float resolution;
87         float power;
88
89         float offset;   /* (cooked = raw + offset) * scale */
90         float scale;
91
92         int sampling_rate;      /* requested events / second */
93
94         int dev_num;    /* Associated iio dev num, ex: 3 for /dev/iio:device3 */
95         int enable_count;
96
97         int catalog_index;/* Associated entry within the sensor_catalog array */
98
99         int num_channels; /* Actual channel count ; 0 for poll mode sensors */
100
101         /*
102          * The array below indicates where to gather report data for this
103          * sensor inside the reports that we read from the iio character device.
104          * It is updated whenever channels are enabled or disabled on the same
105          * device. Channel size indicates the size in bytes of fields, and
106          * should be zero for disabled channels. The type field indicates how a
107          * specific channel data item is structured.
108          */
109         struct channel_info_t channel[MAX_CHANNELS];
110
111         /*
112          * This flag is set if we acquired data from the sensor but did not
113          * forward it to upper layers (i.e. Android) yet. If so, report_buffer
114          * contains that data.
115          */
116         int report_pending;
117
118         unsigned char report_buffer[MAX_SENSOR_REPORT_SIZE];
119
120         int64_t last_integration_ts; /* Last time an event was reported */
121
122         struct sample_ops_t ops;
123
124         /* Note: we may have to explicitely serialize access to some fields */
125 };
126
127 /* Reference a few commonly used variables... */
128 extern int                              sensor_count;
129 extern struct sensor_info_t             sensor_info[MAX_SENSORS];
130 extern struct sensor_catalog_entry_t    sensor_catalog[];
131
132 #endif