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 */
36 /*****************************************************************************/
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
44 #define EVENT_TYPE_COMP_X REL_X
45 #define EVENT_TYPE_COMP_Y REL_Y
46 #define EVENT_TYPE_COMP_Z REL_Z
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
53 #define EVENT_TYPE_MAGV_X REL_DIAL
54 #define EVENT_TYPE_MAGV_Y REL_HWHEEL
55 #define EVENT_TYPE_MAGV_Z REL_MISC
57 #define EVENT_TYPE_PROXIMITY ABS_DISTANCE
58 #define EVENT_TYPE_LIGHT ABS_MISC
60 #define EVENT_TYPE_GYRO_X REL_X
61 #define EVENT_TYPE_GYRO_Y REL_Y
62 #define EVENT_TYPE_GYRO_Z REL_Z
64 #define EVENT_TYPE_PRESSURE REL_X
65 #define EVENT_TYPE_TEMPERATURE REL_Y
69 #define NUMOFACCDATA (8.0f)
71 // conversion of acceleration data to SI units (m/s^2)
73 #define RANGE_A (2*GRAVITY_EARTH)
74 #define RESOLUTION_A (RANGE_A/(256*NUMOFACCDATA))
75 #define CONVERT_A (GRAVITY_EARTH / LSG / NUMOFACCDATA)
76 #define CONVERT_A_X(x) ((float(x)/1000) * (GRAVITY * -1.0))
77 #define CONVERT_A_Y(x) ((float(x)/1000) * (GRAVITY * 1.0))
78 #define CONVERT_A_Z(x) ((float(x)/1000) * (GRAVITY * 1.0))
79 // conversion of magnetic data to uT units
80 #define RANGE_M (2048.0f)
81 #define RESOLUTION_M (0.01)
82 #define CONVERT_M (1.0f/6.6f)
83 #define CONVERT_M_X (-CONVERT_M)
84 #define CONVERT_M_Y (-CONVERT_M)
85 #define CONVERT_M_Z (CONVERT_M)
87 /* conversion of orientation data to degree units */
88 #define CONVERT_O (1.0f/64.0f)
89 #define CONVERT_O_A (CONVERT_O)
90 #define CONVERT_O_P (CONVERT_O)
91 #define CONVERT_O_R (-CONVERT_O)
93 // conversion of gyro data to SI units (radian/sec)
94 #define RANGE_GYRO (2000.0f*(float)M_PI/180.0f)
95 #define CONVERT_GYRO ((2000.0f / 32767.0f) * ((float)M_PI / 180.0f))
96 #define CONVERT_GYRO_X (-CONVERT_GYRO)
97 #define CONVERT_GYRO_Y (-CONVERT_GYRO)
98 #define CONVERT_GYRO_Z (CONVERT_GYRO)
100 // conversion of pressure and temperature data
101 #define CONVERT_PRESSURE (1.0f/100.0f)
102 #define CONVERT_TEMPERATURE (1.0f/100.0f)
104 #define RESOLUTION_GYRO (RANGE_GYRO/(2000*NUMOFACCDATA))
105 #define SENSOR_STATE_MASK (0x7FFF)
107 // Proximity Threshold
108 #define PROXIMITY_THRESHOLD_GP2A 5.0f
110 //Used in timespec_to_ns calculations
111 #define NSEC_PER_SEC 1000000000L
113 #define BIT(x) (1 << (x))
115 inline unsigned int set_bit_range(int start, int end)
118 unsigned int value = 0;
120 for (i = start; i < end; ++i)
125 inline float convert_from_vtf_format(int size, int exponent, unsigned int value)
132 value = value & set_bit_range(0, size*8);
133 if (value & BIT(size*8-1)) {
134 value = ((1LL << (size*8)) - value);
137 sample = value * 1.0;
139 exponent = abs(exponent);
140 for (i = 0; i < exponent; ++i) {
141 divider = divider*10;
143 return mul * sample/divider;
145 return mul * sample * pow(10.0, exponent);
149 // Platform sensor orientatation
150 #define DEF_ORIENT_ACCEL_X -1
151 #define DEF_ORIENT_ACCEL_Y -1
152 #define DEF_ORIENT_ACCEL_Z -1
154 #define DEF_ORIENT_GYRO_X 1
155 #define DEF_ORIENT_GYRO_Y 1
156 #define DEF_ORIENT_GYRO_Z 1
159 #define CONVERT_FROM_VTF16(s,d,x) (convert_from_vtf_format(s,d,x))
160 #define CONVERT_A_G_VTF16E14_X(s,d,x) (DEF_ORIENT_ACCEL_X *\
161 convert_from_vtf_format(s,d,x)*GRAVITY)
162 #define CONVERT_A_G_VTF16E14_Y(s,d,x) (DEF_ORIENT_ACCEL_Y *\
163 convert_from_vtf_format(s,d,x)*GRAVITY)
164 #define CONVERT_A_G_VTF16E14_Z(s,d,x) (DEF_ORIENT_ACCEL_Z *\
165 convert_from_vtf_format(s,d,x)*GRAVITY)
167 // Degree/sec to radian/sec
168 #define CONVERT_G_D_VTF16E14_X(s,d,x) (DEF_ORIENT_GYRO_X *\
169 convert_from_vtf_format(s,d,x) * ((float)M_PI/180.0f))
170 #define CONVERT_G_D_VTF16E14_Y(s,d,x) (DEF_ORIENT_GYRO_Y *\
171 convert_from_vtf_format(s,d,x) * ((float)M_PI/180.0f))
172 #define CONVERT_G_D_VTF16E14_Z(s,d,x) (DEF_ORIENT_GYRO_Z *\
173 convert_from_vtf_format(s,d,x) * ((float)M_PI/180.0f))
175 // Milli gauss to micro tesla
176 #define CONVERT_M_MG_VTF16E14_X(s,d,x) (convert_from_vtf_format(s,d,x)/10)
177 #define CONVERT_M_MG_VTF16E14_Y(s,d,x) (convert_from_vtf_format(s,d,x)/10)
178 #define CONVERT_M_MG_VTF16E14_Z(s,d,x) (convert_from_vtf_format(s,d,x)/10)
180 /*****************************************************************************/
182 #endif // SENSOR_CONFIG_H