OSDN Git Service

libsensors: modified default gyro orientation
[android-x86/hardware-intel-libsensors.git] / bigcore / libsensors / SensorConfig.h
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef SENSOR_CONFIG_H
18 #define SENSOR_CONFIG_H
19
20 #include <hardware/hardware.h>
21 #include <hardware/sensors.h>
22 #include <cmath>
23
24 /* Maps senor id's to the sensor list */
25 enum {
26     accel           = 0,
27     gyro,
28     compass,
29     light,
30     numSensorDrivers,
31     numFds,
32 };
33
34
35
36 /*****************************************************************************/
37
38 /* Board specific sensor configs. */
39 #define GRAVITY 9.80665f
40 #define EVENT_TYPE_ACCEL_X          REL_X
41 #define EVENT_TYPE_ACCEL_Y          REL_Y
42 #define EVENT_TYPE_ACCEL_Z          REL_Z
43
44 #define EVENT_TYPE_COMP_X           REL_X
45 #define EVENT_TYPE_COMP_Y           REL_Y
46 #define EVENT_TYPE_COMP_Z           REL_Z
47
48 #define EVENT_TYPE_YAW              REL_RX
49 #define EVENT_TYPE_PITCH            REL_RY
50 #define EVENT_TYPE_ROLL             REL_RZ
51 #define EVENT_TYPE_ORIENT_STATUS    REL_WHEEL
52
53 #define EVENT_TYPE_MAGV_X           REL_DIAL
54 #define EVENT_TYPE_MAGV_Y           REL_HWHEEL
55 #define EVENT_TYPE_MAGV_Z           REL_MISC
56
57 #define EVENT_TYPE_PROXIMITY        ABS_DISTANCE
58 #define EVENT_TYPE_LIGHT            ABS_MISC
59
60 #define EVENT_TYPE_GYRO_X           REL_X
61 #define EVENT_TYPE_GYRO_Y           REL_Y
62 #define EVENT_TYPE_GYRO_Z           REL_Z
63
64 #define EVENT_TYPE_PRESSURE         REL_X
65 #define EVENT_TYPE_TEMPERATURE      REL_Y
66
67 // 720 LSG = 1G
68 #define LSG                         (1024.0f)
69 #define NUMOFACCDATA                (8.0f)
70 // conversion of acceleration data to SI units (m/s^2)
71
72 #define RANGE_A                     (2*GRAVITY_EARTH)
73 #define RESOLUTION_A                (RANGE_A/(256*NUMOFACCDATA))
74 #define CONVERT_A                   (GRAVITY_EARTH / LSG / NUMOFACCDATA)
75 #define CONVERT_A_X(x)              ((float(x)/1000) * (GRAVITY * -1.0))
76 #define CONVERT_A_Y(x)              ((float(x)/1000) * (GRAVITY * 1.0))
77 #define CONVERT_A_Z(x)              ((float(x)/1000) * (GRAVITY * 1.0))
78 // conversion of magnetic data to uT units
79 #define RANGE_M                     (2048.0f)
80 #define RESOLUTION_M                (0.01)
81 #define CONVERT_M                   (1.0f/6.6f)
82 #define CONVERT_M_X                 (-CONVERT_M)
83 #define CONVERT_M_Y                 (-CONVERT_M)
84 #define CONVERT_M_Z                 (CONVERT_M)
85
86 /* conversion of orientation data to degree units */
87 #define CONVERT_O                   (1.0f/64.0f)
88 #define CONVERT_O_A                 (CONVERT_O)
89 #define CONVERT_O_P                 (CONVERT_O)
90 #define CONVERT_O_R                 (-CONVERT_O)
91
92 // conversion of gyro data to SI units (radian/sec)
93 #define RANGE_GYRO                  (2000.0f*(float)M_PI/180.0f)
94 #define CONVERT_GYRO                ((2000.0f / 32767.0f) * ((float)M_PI / 180.0f))
95 #define CONVERT_GYRO_X              (-CONVERT_GYRO)
96 #define CONVERT_GYRO_Y              (-CONVERT_GYRO)
97 #define CONVERT_GYRO_Z              (CONVERT_GYRO)
98
99 // conversion of pressure and temperature data
100 #define CONVERT_PRESSURE            (1.0f/100.0f)
101 #define CONVERT_TEMPERATURE         (1.0f/100.0f)
102
103 #define RESOLUTION_GYRO             (RANGE_GYRO/(2000*NUMOFACCDATA))
104 #define SENSOR_STATE_MASK           (0x7FFF)
105
106 // Proximity Threshold
107 #define PROXIMITY_THRESHOLD_GP2A  5.0f
108
109 //Used in timespec_to_ns calculations
110 #define NSEC_PER_SEC    1000000000L
111
112 #define BIT(x) (1 << (x))
113
114 inline unsigned int set_bit_range(int start, int end)
115 {
116     int i;
117     unsigned int value = 0;
118
119     for (i = start; i < end; ++i)
120         value |= BIT(i);
121     return value;
122 }
123
124 inline float convert_from_vtf_format(int size, int exponent, unsigned int value)
125 {
126     int divider=1;
127     int i;
128     float sample;
129     int mul = 1.0;
130
131     value = value & set_bit_range(0, size*8);
132     if (value & BIT(size*8-1)) {
133         value =  ((1LL << (size*8)) - value);
134         mul = -1.0;
135     }
136     sample = value * 1.0;
137     if (exponent < 0) {
138         exponent = abs(exponent);
139         for (i = 0; i < exponent; ++i) {
140             divider = divider*10;
141         }
142         return mul * sample/divider;
143     } else {
144         return mul * sample * pow(10.0, exponent);
145     }
146 }
147
148 // Platform sensor orientatation
149 #define DEF_ORIENT_ACCEL_X                   -1
150 #define DEF_ORIENT_ACCEL_Y                   -1
151 #define DEF_ORIENT_ACCEL_Z                   -1
152
153 #define DEF_ORIENT_GYRO_X                   1
154 #define DEF_ORIENT_GYRO_Y                   1
155 #define DEF_ORIENT_GYRO_Z                   1
156
157 // G to m/s2
158 #define CONVERT_FROM_VTF16(s,d,x)      (convert_from_vtf_format(s,d,x))
159 #define CONVERT_A_G_VTF16E14_X(s,d,x)  (DEF_ORIENT_ACCEL_X *\
160                                         convert_from_vtf_format(s,d,x)*GRAVITY)
161 #define CONVERT_A_G_VTF16E14_Y(s,d,x)  (DEF_ORIENT_ACCEL_Y *\
162                                         convert_from_vtf_format(s,d,x)*GRAVITY)
163 #define CONVERT_A_G_VTF16E14_Z(s,d,x)  (DEF_ORIENT_ACCEL_Z *\
164                                         convert_from_vtf_format(s,d,x)*GRAVITY)
165
166 // Degree/sec to radian/sec
167 #define CONVERT_G_D_VTF16E14_X(s,d,x)  (DEF_ORIENT_GYRO_X *\
168                                         convert_from_vtf_format(s,d,x) * ((float)M_PI/180.0f))
169 #define CONVERT_G_D_VTF16E14_Y(s,d,x)  (DEF_ORIENT_GYRO_Y *\
170                                         convert_from_vtf_format(s,d,x) * ((float)M_PI/180.0f))
171 #define CONVERT_G_D_VTF16E14_Z(s,d,x)  (DEF_ORIENT_GYRO_Z *\
172                                         convert_from_vtf_format(s,d,x) * ((float)M_PI/180.0f))
173
174 // Milli gauss to micro tesla
175 #define CONVERT_M_MG_VTF16E14_X(s,d,x) (convert_from_vtf_format(s,d,x)/10)
176 #define CONVERT_M_MG_VTF16E14_Y(s,d,x) (convert_from_vtf_format(s,d,x)/10)
177 #define CONVERT_M_MG_VTF16E14_Z(s,d,x) (convert_from_vtf_format(s,d,x)/10)
178
179 /*****************************************************************************/
180
181 #endif  // SENSOR_CONFIG_H