LibDriver ADXL362
Loading...
Searching...
No Matches
driver_adxl362_motion_test.c
Go to the documentation of this file.
1
36
38
39static adxl362_handle_t gs_handle;
40volatile static uint8_t gs_flag = 0;
41
50{
51 if (adxl362_irq_handler(&gs_handle) != 0)
52 {
53 return 1;
54 }
55 else
56 {
57 return 0;
58 }
59}
60
66static void a_adxl362_interface_receive_callback(uint8_t type)
67{
68 switch (type)
69 {
71 {
72 adxl362_interface_debug_print("adxl362: irq seu error detect.\n");
73
74 break;
75 }
77 {
78 break;
79 }
81 {
82 break;
83 }
85 {
86 /* flag happened */
87 gs_flag = 1;
88
89 /* output */
90 adxl362_interface_debug_print("adxl362: irq activity.\n");
91
92 break;
93 }
95 {
96 adxl362_interface_debug_print("adxl362: irq fifo overrun.\n");
97
98 break;
99 }
101 {
102 adxl362_interface_debug_print("adxl362: irq fifo watermark.\n");
103
104 break;
105 }
107 {
108 adxl362_interface_debug_print("adxl362: irq fifo ready.\n");
109
110 break;
111 }
113 {
114 break;
115 }
116 default :
117 {
118 adxl362_interface_debug_print("adxl362: unknown code.\n");
119
120 break;
121 }
122 }
123}
124
133uint8_t adxl362_motion_test(uint32_t times)
134{
135 uint8_t res;
136 uint8_t reg_short;
137 uint8_t status;
138 uint16_t reg;
139 uint32_t t;
140 adxl362_info_t info;
141
142 /* link interface function */
151 DRIVER_ADXL362_LINK_RECEIVE_CALLBACK(&gs_handle, a_adxl362_interface_receive_callback);
152
153 /* get information */
154 res = adxl362_info(&info);
155 if (res != 0)
156 {
157 adxl362_interface_debug_print("adxl362: get info failed.\n");
158
159 return 1;
160 }
161 else
162 {
163 /* print chip info */
164 adxl362_interface_debug_print("adxl362: chip is %s.\n", info.chip_name);
165 adxl362_interface_debug_print("adxl362: manufacturer is %s.\n", info.manufacturer_name);
166 adxl362_interface_debug_print("adxl362: interface is %s.\n", info.interface);
167 adxl362_interface_debug_print("adxl362: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
168 adxl362_interface_debug_print("adxl362: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
169 adxl362_interface_debug_print("adxl362: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
170 adxl362_interface_debug_print("adxl362: max current is %0.2fmA.\n", info.max_current_ma);
171 adxl362_interface_debug_print("adxl362: max temperature is %0.1fC.\n", info.temperature_max);
172 adxl362_interface_debug_print("adxl362: min temperature is %0.1fC.\n", info.temperature_min);
173 }
174
175 /* start motion test */
176 adxl362_interface_debug_print("adxl362: start motion test.\n");
177
178 /* init the adxl362 */
179 res = adxl362_init(&gs_handle);
180 if (res != 0)
181 {
182 adxl362_interface_debug_print("adxl362: init failed.\n");
183
184 return 1;
185 }
186
187 /* disable fifo temperature */
189 if (res != 0)
190 {
191 adxl362_interface_debug_print("adxl362: set fifo temperature failed.\n");
192 (void)adxl362_deinit(&gs_handle);
193
194 return 1;
195 }
196
197 /* disable fifo */
199 if (res != 0)
200 {
201 adxl362_interface_debug_print("adxl362: set fifo mode failed.\n");
202 (void)adxl362_deinit(&gs_handle);
203
204 return 1;
205 }
206
207 /* set fifo sample 0 */
208 res = adxl362_set_fifo_sample(&gs_handle, 0);
209 if (res != 0)
210 {
211 adxl362_interface_debug_print("adxl362: set fifo sample failed.\n");
212 (void)adxl362_deinit(&gs_handle);
213
214 return 1;
215 }
216
217 /* set interrupt pin1 active level low */
219 if (res != 0)
220 {
221 adxl362_interface_debug_print("adxl362: set interrupt pin1 active level failed.\n");
222 (void)adxl362_deinit(&gs_handle);
223
224 return 1;
225 }
226
227 /* disable awake map */
229 if (res != 0)
230 {
231 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
232 (void)adxl362_deinit(&gs_handle);
233
234 return 1;
235 }
236
237 /* enable inact map */
239 if (res != 0)
240 {
241 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
242 (void)adxl362_deinit(&gs_handle);
243
244 return 1;
245 }
246
247 /* enable act map */
249 if (res != 0)
250 {
251 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
252 (void)adxl362_deinit(&gs_handle);
253
254 return 1;
255 }
256
257 /* disable fifo overrun map */
259 if (res != 0)
260 {
261 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
262 (void)adxl362_deinit(&gs_handle);
263
264 return 1;
265 }
266
267 /* disable fifo watermark map */
269 if (res != 0)
270 {
271 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
272 (void)adxl362_deinit(&gs_handle);
273
274 return 1;
275 }
276
277 /* disable fifo ready map */
279 if (res != 0)
280 {
281 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
282 (void)adxl362_deinit(&gs_handle);
283
284 return 1;
285 }
286
287 /* disable data ready map */
289 if (res != 0)
290 {
291 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
292 (void)adxl362_deinit(&gs_handle);
293
294 return 1;
295 }
296
297 /* set interrupt pin2 active level low */
299 if (res != 0)
300 {
301 adxl362_interface_debug_print("adxl362: set interrupt pin2 active level failed.\n");
302 (void)adxl362_deinit(&gs_handle);
303
304 return 1;
305 }
306
307 /* disable awake map */
309 if (res != 0)
310 {
311 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
312 (void)adxl362_deinit(&gs_handle);
313
314 return 1;
315 }
316
317 /* disable inact map */
319 if (res != 0)
320 {
321 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
322 (void)adxl362_deinit(&gs_handle);
323
324 return 1;
325 }
326
327 /* disable act map */
329 if (res != 0)
330 {
331 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
332 (void)adxl362_deinit(&gs_handle);
333
334 return 1;
335 }
336
337 /* disable fifo overrun map */
339 if (res != 0)
340 {
341 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
342 (void)adxl362_deinit(&gs_handle);
343
344 return 1;
345 }
346
347 /* disable fifo watermark map */
349 if (res != 0)
350 {
351 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
352 (void)adxl362_deinit(&gs_handle);
353
354 return 1;
355 }
356
357 /* disable fifo ready map */
359 if (res != 0)
360 {
361 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
362 (void)adxl362_deinit(&gs_handle);
363
364 return 1;
365 }
366
367 /* disable data ready map */
369 if (res != 0)
370 {
371 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
372 (void)adxl362_deinit(&gs_handle);
373
374 return 1;
375 }
376
377 /* odr 1/2 */
379 if (res != 0)
380 {
381 adxl362_interface_debug_print("adxl362: set bandwidth failed.\n");
382 (void)adxl362_deinit(&gs_handle);
383
384 return 1;
385 }
386
387 /* normal mode */
389 if (res != 0)
390 {
391 adxl362_interface_debug_print("adxl362: set noise mode failed.\n");
392 (void)adxl362_deinit(&gs_handle);
393
394 return 1;
395 }
396
397 /* disable wake up */
398 res = adxl362_set_wake_up(&gs_handle, ADXL362_BOOL_FALSE);
399 if (res != 0)
400 {
401 adxl362_interface_debug_print("adxl362: set wake up failed.\n");
402 (void)adxl362_deinit(&gs_handle);
403
404 return 1;
405 }
406
407 /* disable auto sleep */
409 if (res != 0)
410 {
411 adxl362_interface_debug_print("adxl362: set auto sleep failed.\n");
412 (void)adxl362_deinit(&gs_handle);
413
414 return 1;
415 }
416
417 /* disable interrupt pin2 as external sampling trigger */
419 if (res != 0)
420 {
421 adxl362_interface_debug_print("adxl362: set interrupt pin2 as external sampling trigger failed.\n");
422 (void)adxl362_deinit(&gs_handle);
423
424 return 1;
425 }
426
427 /* disable interrupt pin1 as external clock */
429 if (res != 0)
430 {
431 adxl362_interface_debug_print("adxl362: set interrupt pin1 as external clock failed.\n");
432 (void)adxl362_deinit(&gs_handle);
433
434 return 1;
435 }
436
437 /* set 12.5Hz */
438 res = adxl362_set_odr(&gs_handle, ADXL362_ODR_12P5HZ);
439 if (res != 0)
440 {
441 adxl362_interface_debug_print("adxl362: set odr failed.\n");
442 (void)adxl362_deinit(&gs_handle);
443
444 return 1;
445 }
446
447 /* set 2g */
448 res = adxl362_set_range(&gs_handle, ADXL362_RANGE_2G);
449 if (res != 0)
450 {
451 adxl362_interface_debug_print("adxl362: set range failed.\n");
452 (void)adxl362_deinit(&gs_handle);
453
454 return 1;
455 }
456
457 /* activity threshold 0.25g */
458 res = adxl362_activity_threshold_convert_to_register(&gs_handle, 0.25f, &reg);
459 if (res != 0)
460 {
461 adxl362_interface_debug_print("adxl362: activity threshold convert to register failed.\n");
462 (void)adxl362_deinit(&gs_handle);
463
464 return 1;
465 }
466
467 /* set activity threshold */
468 res = adxl362_set_activity_threshold(&gs_handle, reg);
469 if (res != 0)
470 {
471 adxl362_interface_debug_print("adxl362: set activity threshold failed.\n");
472 (void)adxl362_deinit(&gs_handle);
473
474 return 1;
475 }
476
477 /* activity time 30.0ms */
478 res = adxl362_activity_time_convert_to_register(&gs_handle, 30.0, &reg_short);
479 if (res != 0)
480 {
481 adxl362_interface_debug_print("adxl362: activity time convert to register failed.\n");
482 (void)adxl362_deinit(&gs_handle);
483
484 return 1;
485 }
486
487 /* set activity time */
488 res = adxl362_set_activity_time(&gs_handle, reg_short);
489 if (res != 0)
490 {
491 adxl362_interface_debug_print("adxl362: set activity time failed.\n");
492 (void)adxl362_deinit(&gs_handle);
493
494 return 1;
495 }
496
497 /* inactivity threshold 0.15g */
498 res = adxl362_inactivity_threshold_convert_to_register(&gs_handle, 0.15f, &reg);
499 if (res != 0)
500 {
501 adxl362_interface_debug_print("adxl362: inactivity threshold convert to register failed.\n");
502 (void)adxl362_deinit(&gs_handle);
503
504 return 1;
505 }
506
507 /* set inactivity threshold */
508 res = adxl362_set_inactivity_threshold(&gs_handle, reg);
509 if (res != 0)
510 {
511 adxl362_interface_debug_print("adxl362: set inactivity threshold failed.\n");
512 (void)adxl362_deinit(&gs_handle);
513
514 return 1;
515 }
516
517 /* inactivity time 500ms */
518 res = adxl362_inactivity_time_convert_to_register(&gs_handle, 500.0f, &reg);
519 if (res != 0)
520 {
521 adxl362_interface_debug_print("adxl362: inactivity time convert to register failed.\n");
522 (void)adxl362_deinit(&gs_handle);
523
524 return 1;
525 }
526
527 /* set inactivity time */
528 res = adxl362_set_inactivity_time(&gs_handle, reg);
529 if (res != 0)
530 {
531 adxl362_interface_debug_print("adxl362: set inactivity time failed.\n");
532 (void)adxl362_deinit(&gs_handle);
533
534 return 1;
535 }
536
537 /* set detect loop mode */
539 if (res != 0)
540 {
541 adxl362_interface_debug_print("adxl362: set detect mode failed.\n");
542 (void)adxl362_deinit(&gs_handle);
543
544 return 1;
545 }
546
547 /* set inactivity detect trigger */
549 if (res != 0)
550 {
551 adxl362_interface_debug_print("adxl362: set inactivity detect trigger failed.\n");
552 (void)adxl362_deinit(&gs_handle);
553
554 return 1;
555 }
556
557 /* set activity detect trigger */
559 if (res != 0)
560 {
561 adxl362_interface_debug_print("adxl362: set activity detect trigger failed.\n");
562 (void)adxl362_deinit(&gs_handle);
563
564 return 1;
565 }
566
567 /* enable inactivity */
568 res = adxl362_set_inactivity(&gs_handle, ADXL362_BOOL_TRUE);
569 if (res != 0)
570 {
571 adxl362_interface_debug_print("adxl362: set inactivity failed.\n");
572 (void)adxl362_deinit(&gs_handle);
573
574 return 1;
575 }
576
577 /* enable activity */
578 res = adxl362_set_activity(&gs_handle, ADXL362_BOOL_TRUE);
579 if (res != 0)
580 {
581 adxl362_interface_debug_print("adxl362: set activity failed.\n");
582 (void)adxl362_deinit(&gs_handle);
583
584 return 1;
585 }
586
587 /* disable self test */
588 res = adxl362_set_self_test(&gs_handle, ADXL362_BOOL_FALSE);
589 if (res != 0)
590 {
591 adxl362_interface_debug_print("adxl362: set self test failed.\n");
592 (void)adxl362_deinit(&gs_handle);
593
594 return 1;
595 }
596
597 /* get status */
598 res = adxl362_get_status(&gs_handle, &status);
599 if (res != 0)
600 {
601 adxl362_interface_debug_print("adxl362: get status failed.\n");
602 (void)adxl362_deinit(&gs_handle);
603
604 return 1;
605 }
606
607 /* start measurement */
609 if (res != 0)
610 {
611 adxl362_interface_debug_print("adxl362: set mode failed.\n");
612 (void)adxl362_deinit(&gs_handle);
613
614 return 1;
615 }
616
617 /* flag 0 */
618 gs_flag = 0;
619
620 /* set the times */
621 t = times;
622
623 /* loop */
624 while (t != 0)
625 {
626 /* check the flag */
627 if (gs_flag != 0)
628 {
629 /* t-- */
630 t--;
631
632 /* restart */
633 gs_flag = 0;
634 }
635 }
636
637 /* finish motion test */
638 adxl362_interface_debug_print("adxl362: finish motion test.\n");
639 (void)adxl362_deinit(&gs_handle);
640
641 return 0;
642}
driver adxl362 motion test header file
uint8_t adxl362_set_range(adxl362_handle_t *handle, adxl362_range_t range)
set the measurement range
uint8_t adxl362_set_interrupt_pin2_map(adxl362_handle_t *handle, adxl362_interrupt_map_t map, adxl362_bool_t enable)
set the interrupt pin2 map
uint8_t adxl362_set_inactivity_detect_trigger(adxl362_handle_t *handle, adxl362_detect_trigger_t trigger)
set the inactivity detect trigger mode
uint8_t adxl362_set_fifo_sample(adxl362_handle_t *handle, uint16_t sample)
set the fifo sample
uint8_t adxl362_set_inactivity_time(adxl362_handle_t *handle, uint16_t tim)
set the inactivity time
struct adxl362_info_s adxl362_info_t
adxl362 information structure definition
uint8_t adxl362_set_fifo_mode(adxl362_handle_t *handle, adxl362_fifo_mode_t mode)
set the fifo mode
uint8_t adxl362_info(adxl362_info_t *info)
get chip's information
uint8_t adxl362_set_self_test(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable the self test
uint8_t adxl362_init(adxl362_handle_t *handle)
initialize the chip
uint8_t adxl362_set_detect_mode(adxl362_handle_t *handle, adxl362_detect_mode_t mode)
set the detect mode
uint8_t adxl362_set_interrupt_pin2_active_level(adxl362_handle_t *handle, adxl362_interrupt_pin_level_t level)
set the interrupt pin2 active level
struct adxl362_handle_s adxl362_handle_t
adxl362 handle structure definition
uint8_t adxl362_set_wake_up(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable chip wake up
uint8_t adxl362_set_inactivity_threshold(adxl362_handle_t *handle, uint16_t threshold)
set the inactivity threshold
uint8_t adxl362_set_interrupt_pin1_map(adxl362_handle_t *handle, adxl362_interrupt_map_t map, adxl362_bool_t enable)
set the interrupt pin1 map
uint8_t adxl362_set_noise_mode(adxl362_handle_t *handle, adxl362_noise_mode_t mode)
set the noise mode
uint8_t adxl362_set_activity_threshold(adxl362_handle_t *handle, uint16_t threshold)
set the activity threshold
uint8_t adxl362_activity_threshold_convert_to_register(adxl362_handle_t *handle, float g, uint16_t *reg)
convert the activity threshold to the register raw data
uint8_t adxl362_set_activity_time(adxl362_handle_t *handle, uint8_t tim)
set the activity time
uint8_t adxl362_set_interrupt_pin1_active_level(adxl362_handle_t *handle, adxl362_interrupt_pin_level_t level)
set the interrupt pin1 active level
uint8_t adxl362_inactivity_time_convert_to_register(adxl362_handle_t *handle, float ms, uint16_t *reg)
convert the inactivity time to the register raw data
uint8_t adxl362_set_fifo_temperature(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable saving temperature data to fifo
uint8_t adxl362_set_activity_detect_trigger(adxl362_handle_t *handle, adxl362_detect_trigger_t trigger)
set the activity detect trigger mode
uint8_t adxl362_set_interrupt_pin1_as_external_clock(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable interrupt pin1 as the external clock
uint8_t adxl362_irq_handler(adxl362_handle_t *handle)
irq handler
uint8_t adxl362_set_mode(adxl362_handle_t *handle, adxl362_mode_t mode)
set the chip mode
uint8_t adxl362_set_inactivity(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable inactivity
uint8_t adxl362_activity_time_convert_to_register(adxl362_handle_t *handle, float ms, uint8_t *reg)
convert the activity time to the register raw data
uint8_t adxl362_inactivity_threshold_convert_to_register(adxl362_handle_t *handle, float g, uint16_t *reg)
convert the inactivity threshold to the register raw data
uint8_t adxl362_set_interrupt_pin2_as_external_sampling_trigger(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable interrupt pin2 as the external sampling trigger
uint8_t adxl362_get_status(adxl362_handle_t *handle, uint8_t *status)
get the chip status
uint8_t adxl362_set_activity(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable activity
uint8_t adxl362_set_auto_sleep(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable auto sleep
uint8_t adxl362_set_bandwidth(adxl362_handle_t *handle, adxl362_bandwidth_t bandwidth)
set the filter bandwidth
uint8_t adxl362_deinit(adxl362_handle_t *handle)
close the chip
uint8_t adxl362_set_odr(adxl362_handle_t *handle, adxl362_odr_t odr)
set the output data rate
@ ADXL362_DETECT_MODE_LOOP
@ ADXL362_FIFO_MODE_DISABLE
@ ADXL362_BANDWIDTH_ODR_DIV_2
@ ADXL362_ODR_12P5HZ
@ ADXL362_INTERRUPT_MAP_FIFO_READY
@ ADXL362_INTERRUPT_MAP_ACT
@ ADXL362_INTERRUPT_MAP_FIFO_OVERRUN
@ ADXL362_INTERRUPT_MAP_FIFO_WATERMARK
@ ADXL362_INTERRUPT_MAP_DATA_READY
@ ADXL362_INTERRUPT_MAP_AWAKE
@ ADXL362_INTERRUPT_MAP_INACT
@ ADXL362_MODE_MEASUREMENT
@ ADXL362_STATUS_DATA_READY
@ ADXL362_STATUS_FIFO_OVERRUN
@ ADXL362_STATUS_AWAKE
@ ADXL362_STATUS_INACT
@ ADXL362_STATUS_FIFO_READY
@ ADXL362_STATUS_ERR_USER_REGS
@ ADXL362_STATUS_ACT
@ ADXL362_STATUS_FIFO_WATERMARK
@ ADXL362_NOISE_MODE_NORMAL
@ ADXL362_BOOL_FALSE
@ ADXL362_BOOL_TRUE
@ ADXL362_RANGE_2G
@ ADXL362_DETECT_TRIGGER_REFERENCED
@ ADXL362_INTERRUPT_PIN_LOW
uint8_t adxl362_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t adxl362_interface_spi_deinit(void)
interface spi bus deinit
uint8_t adxl362_interface_spi_init(void)
interface spi bus init
void adxl362_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t adxl362_interface_spi_write_address16(uint16_t addr, uint8_t *buf, uint16_t len)
interface spi bus write
void adxl362_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t adxl362_interface_spi_read_address16(uint16_t addr, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t adxl362_motion_test_irq_handler(void)
motion test irq
uint8_t adxl362_motion_test(uint32_t times)
motion test
uint32_t driver_version
char manufacturer_name[32]