2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef SENSOR_CONFIG_H
18 #define SENSOR_CONFIG_H
20 #include <hardware/hardware.h>
21 #include <hardware/sensors.h>
24 /* Maps senor id's to the sensor list */
39 /*****************************************************************************/
41 /* Board specific sensor configs. */
42 #define GRAVITY 9.80665f
43 #define EVENT_TYPE_ACCEL_X REL_X
44 #define EVENT_TYPE_ACCEL_Y REL_Y
45 #define EVENT_TYPE_ACCEL_Z REL_Z
47 #define EVENT_TYPE_COMP_X REL_X
48 #define EVENT_TYPE_COMP_Y REL_Y
49 #define EVENT_TYPE_COMP_Z REL_Z
51 #define EVENT_TYPE_YAW REL_RX
52 #define EVENT_TYPE_PITCH REL_RY
53 #define EVENT_TYPE_ROLL REL_RZ
54 #define EVENT_TYPE_ORIENT_STATUS REL_WHEEL
56 #define EVENT_TYPE_MAGV_X REL_DIAL
57 #define EVENT_TYPE_MAGV_Y REL_HWHEEL
58 #define EVENT_TYPE_MAGV_Z REL_MISC
60 #define EVENT_TYPE_PROXIMITY ABS_DISTANCE
61 #define EVENT_TYPE_LIGHT ABS_MISC
63 #define EVENT_TYPE_GYRO_X REL_X
64 #define EVENT_TYPE_GYRO_Y REL_Y
65 #define EVENT_TYPE_GYRO_Z REL_Z
67 #define EVENT_TYPE_PRESSURE REL_X
68 #define EVENT_TYPE_TEMPERATURE REL_Y
72 #define NUMOFACCDATA (8.0f)
74 // conversion of acceleration data to SI units (m/s^2)
76 #define RANGE_A (2*GRAVITY_EARTH)
77 #define RESOLUTION_A (RANGE_A/(256*NUMOFACCDATA))
78 #define CONVERT_A (GRAVITY_EARTH / LSG / NUMOFACCDATA)
79 #define CONVERT_A_X(x) ((float(x)/1000) * (GRAVITY * -1.0))
80 #define CONVERT_A_Y(x) ((float(x)/1000) * (GRAVITY * 1.0))
81 #define CONVERT_A_Z(x) ((float(x)/1000) * (GRAVITY * 1.0))
82 // conversion of magnetic data to uT units
83 #define RANGE_M (2048.0f)
84 #define RESOLUTION_M (0.01)
85 #define CONVERT_M (1.0f/6.6f)
86 #define CONVERT_M_X (-CONVERT_M)
87 #define CONVERT_M_Y (-CONVERT_M)
88 #define CONVERT_M_Z (CONVERT_M)
90 /* conversion of orientation data to degree units */
91 #define CONVERT_O (1.0f/64.0f)
92 #define CONVERT_O_A (CONVERT_O)
93 #define CONVERT_O_P (CONVERT_O)
94 #define CONVERT_O_R (-CONVERT_O)
96 // conversion of gyro data to SI units (radian/sec)
97 #define RANGE_GYRO (2000.0f*(float)M_PI/180.0f)
98 #define CONVERT_GYRO ((2000.0f / 32767.0f) * ((float)M_PI / 180.0f))
99 #define CONVERT_GYRO_X (-CONVERT_GYRO)
100 #define CONVERT_GYRO_Y (-CONVERT_GYRO)
101 #define CONVERT_GYRO_Z (CONVERT_GYRO)
103 // conversion of pressure and temperature data
104 #define CONVERT_PRESSURE (1.0f/100.0f)
105 #define CONVERT_TEMPERATURE (1.0f/100.0f)
107 #define RESOLUTION_GYRO (RANGE_GYRO/(2000*NUMOFACCDATA))
108 #define SENSOR_STATE_MASK (0x7FFF)
110 // Proximity Threshold
111 #define PROXIMITY_THRESHOLD_GP2A 5.0f
113 //Used in timespec_to_ns calculations
114 #define NSEC_PER_SEC 1000000000L
116 #define BIT(x) (1 << (x))
118 inline unsigned int set_bit_range(int start, int end)
121 unsigned int value = 0;
123 for (i = start; i < end; ++i)
128 inline float convert_from_vtf_format(int size, int exponent, unsigned int value)
135 value = value & set_bit_range(0, size*8);
136 if (value & BIT(size*8-1)) {
137 value = ((1LL << (size*8)) - value);
140 sample = value * 1.0;
142 exponent = abs(exponent);
143 for (i = 0; i < exponent; ++i) {
144 divider = divider*10;
146 return mul * sample/divider;
148 return mul * sample * pow(10.0, exponent);
152 // Platform sensor orientatation
153 #define DEF_ORIENT_ACCEL_X -1
154 #define DEF_ORIENT_ACCEL_Y -1
155 #define DEF_ORIENT_ACCEL_Z -1
157 #define DEF_ORIENT_GYRO_X 1
158 #define DEF_ORIENT_GYRO_Y 1
159 #define DEF_ORIENT_GYRO_Z 1
162 #define CONVERT_FROM_VTF16(s,d,x) (convert_from_vtf_format(s,d,x))
163 #define CONVERT_A_G_VTF16E14_X(s,d,x) (DEF_ORIENT_ACCEL_X *\
164 convert_from_vtf_format(s,d,x)*GRAVITY)
165 #define CONVERT_A_G_VTF16E14_Y(s,d,x) (DEF_ORIENT_ACCEL_Y *\
166 convert_from_vtf_format(s,d,x)*GRAVITY)
167 #define CONVERT_A_G_VTF16E14_Z(s,d,x) (DEF_ORIENT_ACCEL_Z *\
168 convert_from_vtf_format(s,d,x)*GRAVITY)
170 // Degree/sec to radian/sec
171 #define CONVERT_G_D_VTF16E14_X(s,d,x) (DEF_ORIENT_GYRO_X *\
172 convert_from_vtf_format(s,d,x) * ((float)M_PI/180.0f))
173 #define CONVERT_G_D_VTF16E14_Y(s,d,x) (DEF_ORIENT_GYRO_Y *\
174 convert_from_vtf_format(s,d,x) * ((float)M_PI/180.0f))
175 #define CONVERT_G_D_VTF16E14_Z(s,d,x) (DEF_ORIENT_GYRO_Z *\
176 convert_from_vtf_format(s,d,x) * ((float)M_PI/180.0f))
178 // Milli gauss to micro tesla
179 #define CONVERT_M_MG_VTF16E14_X(s,d,x) (convert_from_vtf_format(s,d,x)/10)
180 #define CONVERT_M_MG_VTF16E14_Y(s,d,x) (convert_from_vtf_format(s,d,x)/10)
181 #define CONVERT_M_MG_VTF16E14_Z(s,d,x) (convert_from_vtf_format(s,d,x)/10)
183 /*****************************************************************************/
185 #endif // SENSOR_CONFIG_H