motion_sensor.h
10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* motion_sensor.h
*
* Project:
* --------
* Maui_Software
*
* Description:
* ------------
* This Module is for motion sensor driver.
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
#ifndef _MOTIONSENSOR_H
#define _MOTIONSENSOR_H
#define SIN_INTERVAL_NUM 91
#define SIN_0 0
#define SIN_1 9
#define SIN_2 18
#define SIN_3 27
#define SIN_4 36
#define SIN_5 45
#define SIN_6 53
#define SIN_7 62
#define SIN_8 71
#define SIN_9 80
#define SIN_10 89
#define SIN_11 98
#define SIN_12 106
#define SIN_13 115
#define SIN_14 124
#define SIN_15 132
#define SIN_16 141
#define SIN_17 150
#define SIN_18 158
#define SIN_19 167
#define SIN_20 175
#define SIN_21 183
#define SIN_22 192
#define SIN_23 200
#define SIN_24 208
#define SIN_25 216
#define SIN_26 224
#define SIN_27 232
#define SIN_28 240
#define SIN_29 248
#define SIN_30 256
#define SIN_31 264
#define SIN_32 271
#define SIN_33 279
#define SIN_34 286
#define SIN_35 294
#define SIN_36 301
#define SIN_37 308
#define SIN_38 315
#define SIN_39 322
#define SIN_40 329
#define SIN_41 336
#define SIN_42 342
#define SIN_43 349
#define SIN_44 356
#define SIN_45 362
#define SIN_46 368
#define SIN_47 374
#define SIN_48 380
#define SIN_49 386
#define SIN_50 392
#define SIN_51 398
#define SIN_52 403
#define SIN_53 409
#define SIN_54 414
#define SIN_55 419
#define SIN_56 424
#define SIN_57 429
#define SIN_58 434
#define SIN_59 439
#define SIN_60 443
#define SIN_61 448
#define SIN_62 452
#define SIN_63 456
#define SIN_64 460
#define SIN_65 464
#define SIN_66 468
#define SIN_67 471
#define SIN_68 475
#define SIN_69 478
#define SIN_70 481
#define SIN_71 484
#define SIN_72 487
#define SIN_73 490
#define SIN_74 492
#define SIN_75 494
#define SIN_76 497
#define SIN_77 499
#define SIN_78 501
#define SIN_79 503
#define SIN_80 504
#define SIN_81 506
#define SIN_82 507
#define SIN_83 508
#define SIN_84 509
#define SIN_85 510
#define SIN_86 511
#define SIN_87 511
#define SIN_88 512
#define SIN_89 512
#define SIN_90 512
/* Must be a power of 2. */
#define MOTION_SENSOR_BUFFER_SIZE 128
#define MOTION_SENSOR_CALI_SAMPLE_NUM 10
#define MOTION_SENSOR_MILLI_ACC_CALI_THRESHOLD 100 // 0.1G
#define MOTION_SENSOR_CALI_TIMEOUT_MS 5000 // 5sec
typedef enum {
BUFF_EMPTY,
BUFF_DATA_EXIST,
BUFF_FULL
} Motion_Sensor_BuffState_enum;
typedef enum {
MS_TAP,
MS_STEP,
MS_DROP,
MS_FLIP,
MS_HW_GESTURE_MAX
} Motion_Sensor_Gesture_enum;
typedef enum {
MS_ACC_DATA_RESOLUTION = 0x0
} Motion_Sensor_General_Params_enum;
typedef enum {
MS_DEV_STATUS = 0x100,
MS_TAP_PULSE = 0x101,
MS_TAP_THRESHOLD = 0x102
} mCube_Sensor_Params_enum;
typedef enum {
MS_CALI_FINISHED,
MS_CALI_TIMEOUT
} Motion_Sensor_Cali_Status_enum;
typedef struct
{
kal_uint32 curr_val;
kal_uint32 max_val;
kal_uint32 min_val;
}MotionSensorQueryStruct;
typedef struct
{
kal_int16 x_acc;
kal_int16 y_acc;
kal_int16 z_acc;
kal_uint32 timeStampMs;
kal_uint32 motion_info;
}MotionSensorDataStruct;
typedef struct
{
kal_int16 x_cali_acc;
kal_int16 y_cali_acc;
kal_int16 z_cali_acc;
kal_uint16 cali_info;
}MotionSensorCaliNVRamStruct;
typedef struct
{
kal_int16 x_gain;
kal_int16 y_gain;
kal_int16 z_gain;
kal_int16 x_offset;
kal_int16 y_offset;
kal_int16 z_offset;
}MotionSensorCaliStruct;
typedef void (*MS_DATA_FUNC)(void *parameter, Motion_Sensor_BuffState_enum state);
typedef void (*MS_INT_CB_FUNC)(void);
typedef void (*MS_CALI_CB_FUNC)(void *parameter, Motion_Sensor_Cali_Status_enum state);
typedef struct
{
MotionSensorCaliStruct cali;
MotionSensorDataStruct pre;
kal_uint8 sample_period;
kal_uint8 gpt_handle;
kal_timerid motionsensor_timerid;
kal_uint32 acc_offset;
kal_uint32 low_g_level;
kal_uint32 high_g_level;
kal_uint32 low_g_debounce;
kal_uint32 high_g_debounce;
MS_DATA_FUNC cb_func;
MS_INT_CB_FUNC low_g_cb;
MS_INT_CB_FUNC high_g_cb;
void *para;
}MotionSensorStruct;
typedef struct
{
MotionSensorDataStruct motion_sensor_data[MOTION_SENSOR_BUFFER_SIZE];
kal_uint16 motion_sensor_rindex;
kal_uint16 motion_sensor_windex;
}MotionSensorBufferStruct;
/*customization part*/
typedef struct {
/*ADC*/
kal_uint16 x_0g_adc;
kal_uint16 x_1g_adc;
kal_uint16 x_minus1g_adc;
kal_uint16 y_0g_adc;
kal_uint16 y_1g_adc;
kal_uint16 y_minus1g_adc;
kal_uint16 z_0g_adc;
kal_uint16 z_1g_adc;
kal_uint16 z_minus1g_adc;
kal_bool int_support;
kal_uint8 int_level;
kal_uint8 int_chan;
} MotionSensor_custom_data_struct;
typedef struct {
MotionSensor_custom_data_struct * (*ms_get_data)(void);
void (*ms_read_adc)(kal_uint16 *x, kal_uint16 *y, kal_uint16 *z);
void (*ms_custom_init)(void);
void (*ms_power_up)(void);
void (*ms_power_down)(void);
/*read interrupt*/
void (*ms_read_int_status)(kal_bool *low_g, kal_bool *high_g);
/*clear interrupt*/
void (*ms_clear_int_status)(void);
void (*ms_configure_low_g)(kal_uint32 debounce, kal_uint32 threshold);
void (*ms_configure_high_g)(kal_uint32 debounce, kal_uint32 threshold);
/*read device status*/
kal_bool (*ms_query_gesture)(kal_uint16 ms_gest_type);
kal_bool (*ms_get_sensor_params)(kal_uint16 ms_params_type, MotionSensorQueryStruct *ms_params);
kal_bool (*ms_set_sensor_params)(kal_uint16 ms_params_type, kal_uint32 ms_params);
}MotionSensor_customize_function_struct;
/*For MMI */
extern void motion_sensor_start_cali(void);
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
extern kal_bool motion_sensor_power(kal_bool enable);
extern void motion_sensor_conf_sample_period(kal_uint32 period);
extern void motion_sensor_flush_buff(void);
extern void motion_sensor_cb_registration(MS_DATA_FUNC cb_fun, void *para);
extern void motion_sensor_sample(kal_bool enable);
extern void motion_sensor_conf_filter(kal_uint32 acc_offset);
extern kal_bool motion_sensor_get_data(MotionSensorDataStruct *ms_data);
extern void motion_sensor_int_cb_registration(MS_INT_CB_FUNC low_g_cb_fun, MS_INT_CB_FUNC high_g_cb_fun);
extern void motion_sensor_int_config(kal_uint32 low_g_level, kal_uint32 high_g_level,
kal_uint32 low_g_debounce, kal_uint32 high_g_debounce);
extern void motion_sensor_int_enable(kal_bool enable);
extern void motion_sensor_cali_cb_registration(MS_CALI_CB_FUNC ms_cali_cb_func);
extern kal_bool motion_sensor_query_gesture(kal_uint16 ms_gest_type);
extern kal_bool motion_sensor_get_sensor_params(kal_uint16 ms_params_type, MotionSensorQueryStruct *ms_params);
extern kal_bool motion_sensor_set_sensor_params(kal_uint16 ms_params_type, kal_uint32 ms_params);
extern kal_bool motion_sensor_write_cali_to_nvram(void);
extern kal_bool motion_sensor_read_cali_from_nvram(void);
// MoDIS parser skip start
// Private APIs
/*For driver */
extern void motion_sensor_eint_hisr(void);
extern kal_bool motion_sensor_filter(MotionSensorDataStruct data);
extern void motion_sensor_sample_cb(void *parameter);
extern void motion_sensor_check_cali(kal_int16 x, kal_int16 y, kal_int16 z);
extern void motion_sensor_init(void);
extern void motion_sensor_get_acc(MotionSensorDataStruct *acc_data,
kal_uint16 x_adc, kal_uint16 y_adc, kal_uint16 z_adc);
extern void motion_sensor_sample_cb(void *parameter);
extern void motion_sensor_reset(void);
#ifdef __MOTION_SENSOR_TILT_SUPPORT__
extern void motion_sensor_get_tilt(kal_uint16 x, kal_uint16 y, kal_uint16 z);
extern kal_uint16 motion_sensor_get_angle(kal_uint16 value);
#endif
// MoDIS parser skip end
#endif