LibDriver ADXL345
Loading...
Searching...
No Matches
driver_adxl345_register_test.c
Go to the documentation of this file.
1
37
39#include <stdlib.h>
40
41static adxl345_handle_t gs_handle;
42
53{
54 uint8_t res, reg, check;
55 int8_t x, y, z;
56 int8_t x_check, y_check, z_check;
57 float f, f_check;
58 int8_t i_reg;
59 uint32_t us, us_check;
60 uint16_t ms, ms_check;
61 adxl345_info_t info;
62 adxl345_interface_t interface_test;
64 adxl345_bool_t bool_test;
65 adxl345_coupled_t coupled;
66 adxl345_rate_t rate;
69 adxl345_justify_t justify;
70 adxl345_range_t range;
71 adxl345_mode_t mode;
72 adxl345_sleep_frequency_t sleep_frequency;
74
75 /* link interface function */
88
89 /* get information */
90 res = adxl345_info(&info);
91 if (res != 0)
92 {
93 adxl345_interface_debug_print("adxl345: get info failed.\n");
94
95 return 1;
96 }
97 else
98 {
99 /* print chip info */
100 adxl345_interface_debug_print("adxl345: chip is %s.\n", info.chip_name);
101 adxl345_interface_debug_print("adxl345: manufacturer is %s.\n", info.manufacturer_name);
102 adxl345_interface_debug_print("adxl345: interface is %s.\n", info.interface);
103 adxl345_interface_debug_print("adxl345: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
104 adxl345_interface_debug_print("adxl345: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
105 adxl345_interface_debug_print("adxl345: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
106 adxl345_interface_debug_print("adxl345: max current is %0.2fmA.\n", info.max_current_ma);
107 adxl345_interface_debug_print("adxl345: max temperature is %0.1fC.\n", info.temperature_max);
108 adxl345_interface_debug_print("adxl345: min temperature is %0.1fC.\n", info.temperature_min);
109 }
110
111 /* start register test */
112 adxl345_interface_debug_print("adxl345: start register test.\n");
113
114 /* adxl345_set_interface/adxl345_get_interface test */
115 adxl345_interface_debug_print("adxl345: adxl345_set_interface/adxl345_get_interface test.\n");
116
117 /* set IIC interface */
119 if (res != 0)
120 {
121 adxl345_interface_debug_print("adxl345: set interface failed.\n");
122
123 return 1;
124 }
125 adxl345_interface_debug_print("adxl345: set interface iic.\n");
126 res = adxl345_get_interface(&gs_handle, &interface_test);
127 if (res != 0)
128 {
129 adxl345_interface_debug_print("adxl345: get interface failed.\n");
130
131 return 1;
132 }
133 adxl345_interface_debug_print("adxl345: check interface %s.\n", interface_test==ADXL345_INTERFACE_IIC?"ok":"error");
134
135 /* set SPI interface */
137 if (res != 0)
138 {
139 adxl345_interface_debug_print("adxl345: set interface failed.\n");
140
141 return 1;
142 }
143 adxl345_interface_debug_print("adxl345: set interface spi.\n");
144 res = adxl345_get_interface(&gs_handle, &interface_test);
145 if (res != 0)
146 {
147 adxl345_interface_debug_print("adxl345: get interface failed.\n");
148
149 return 1;
150 }
151 adxl345_interface_debug_print("adxl345: check interface %s.\n", interface_test==ADXL345_INTERFACE_SPI?"ok":"error");
152
153 /* adxl345_set_addr_pin/adxl345_get_addr_pin test */
154 adxl345_interface_debug_print("adxl345: adxl345_set_addr_pin/adxl345_get_addr_pin test.\n");
155
156 /* ALT0 */
158 if (res != 0)
159 {
160 adxl345_interface_debug_print("adxl345: set addr pin failed.\n");
161
162 return 1;
163 }
164 adxl345_interface_debug_print("adxl345: set addr pin alt0.\n");
165 res = adxl345_get_addr_pin(&gs_handle, &addr);
166 if (res != 0)
167 {
168 adxl345_interface_debug_print("adxl345: get addr pin failed.\n");
169
170 return 1;
171 }
172 adxl345_interface_debug_print("adxl345: check addr pin %s.\n", addr==ADXL345_ADDRESS_ALT_0?"ok":"error");
173
174 /* ALT1 */
176 if (res != 0)
177 {
178 adxl345_interface_debug_print("adxl345: set addr pin failed.\n");
179
180 return 1;
181 }
182 adxl345_interface_debug_print("adxl345: set addr pin alt1.\n");
183 res = adxl345_get_addr_pin(&gs_handle, &addr);
184 if (res != 0)
185 {
186 adxl345_interface_debug_print("adxl345: get addr pin failed.\n");
187
188 return 1;
189 }
190 adxl345_interface_debug_print("adxl345: check addr pin %s.\n", addr==ADXL345_ADDRESS_ALT_1?"ok":"error");
191
192 /* set the interface */
193 res = adxl345_set_interface(&gs_handle, interface);
194 if (res != 0)
195 {
196 adxl345_interface_debug_print("adxl345: set interface failed.\n");
197
198 return 1;
199 }
200
201 /* set the address pin */
202 res = adxl345_set_addr_pin(&gs_handle, addr_pin);
203 if (res != 0)
204 {
205 adxl345_interface_debug_print("adxl345: set addr pin failed.\n");
206
207 return 1;
208 }
209
210 /* init the adxl345 */
211 res = adxl345_init(&gs_handle);
212 if (res != 0)
213 {
214 adxl345_interface_debug_print("adxl345: init failed.\n");
215
216 return 1;
217 }
218
219 /* adxl345_set_tap_threshold/adxl345_get_tap_threshold test */
220 adxl345_interface_debug_print("adxl345: adxl345_set_tap_threshold/adxl345_get_tap_threshold test.\n");
221 reg = rand()%256;
222 res = adxl345_set_tap_threshold(&gs_handle, reg);
223 if (res != 0)
224 {
225 adxl345_interface_debug_print("adxl345: set tap threshold failed.\n");
226 (void)adxl345_deinit(&gs_handle);
227
228 return 1;
229 }
230 adxl345_interface_debug_print("adxl345: set tap threshold 0x%02X.\n", reg);
231 res = adxl345_get_tap_threshold(&gs_handle, (uint8_t *)&check);
232 if (res != 0)
233 {
234 adxl345_interface_debug_print("adxl345: get tap threshold failed.\n");
235 (void)adxl345_deinit(&gs_handle);
236
237 return 1;
238 }
239 adxl345_interface_debug_print("adxl345: check tap threshold %s.\n", check==reg?"ok":"error");
240
241 /* adxl345_set_offset/adxl345_get_offset test */
242 adxl345_interface_debug_print("adxl345: adxl345_set_offset/adxl345_get_offset test.\n");
243 x = rand()%128;
244 y = rand()%128;
245 y = -y;
246 z = rand()%128;
247 res = adxl345_set_offset(&gs_handle, x, y, z);
248 if (res != 0)
249 {
250 adxl345_interface_debug_print("adxl345: set offset failed.\n");
251 (void)adxl345_deinit(&gs_handle);
252
253 return 1;
254 }
255 adxl345_interface_debug_print("adxl345: set x offset %d.\n", x);
256 adxl345_interface_debug_print("adxl345: set y offset %d.\n", y);
257 adxl345_interface_debug_print("adxl345: set z offset %d.\n", z);
258 res = adxl345_get_offset(&gs_handle, (int8_t *)&x_check, (int8_t *)&y_check, (int8_t *)&z_check);
259 if (res != 0)
260 {
261 adxl345_interface_debug_print("adxl345: get offset failed.\n");
262 (void)adxl345_deinit(&gs_handle);
263
264 return 1;
265 }
266 adxl345_interface_debug_print("adxl345: check x offset %s.\n", x==x_check?"ok":"error");
267 adxl345_interface_debug_print("adxl345: check y offset %s.\n", y==y_check?"ok":"error");
268 adxl345_interface_debug_print("adxl345: check z offset %s.\n", z==z_check?"ok":"error");
269
270 /* adxl345_set_duration/adxl345_get_duration test */
271 adxl345_interface_debug_print("adxl345: adxl345_set_duration/adxl345_get_duration test.\n");
272 reg = rand()%256;
273 res = adxl345_set_duration(&gs_handle, reg);
274 if (res != 0)
275 {
276 adxl345_interface_debug_print("adxl345: set duration failed.\n");
277 (void)adxl345_deinit(&gs_handle);
278
279 return 1;
280 }
281 adxl345_interface_debug_print("adxl345: set duration 0x%02X.\n", reg);
282 res = adxl345_get_duration(&gs_handle, (uint8_t *)&check);
283 if (res != 0)
284 {
285 adxl345_interface_debug_print("adxl345: get duration failed.\n");
286 (void)adxl345_deinit(&gs_handle);
287
288 return 1;
289 }
290 adxl345_interface_debug_print("adxl345: check duration %s.\n", check==reg?"ok":"error");
291
292 /* adxl345_set_latent/adxl345_get_latent test */
293 adxl345_interface_debug_print("adxl345: adxl345_set_latent/adxl345_get_latent test.\n");
294 reg = rand()%256;
295 res = adxl345_set_latent(&gs_handle, reg);
296 if (res != 0)
297 {
298 adxl345_interface_debug_print("adxl345: set latent failed.\n");
299 (void)adxl345_deinit(&gs_handle);
300
301 return 1;
302 }
303 adxl345_interface_debug_print("adxl345: set latent 0x%02X.\n", reg);
304 res = adxl345_get_latent(&gs_handle, (uint8_t *)&check);
305 if (res != 0)
306 {
307 adxl345_interface_debug_print("adxl345: get latent failed.\n");
308 (void)adxl345_deinit(&gs_handle);
309
310 return 1;
311 }
312 adxl345_interface_debug_print("adxl345: check latent %s.\n", check==reg?"ok":"error");
313
314 /* adxl345_set_window/adxl345_get_window test */
315 adxl345_interface_debug_print("adxl345: adxl345_set_window/adxl345_get_window test.\n");
316 reg = rand()%256;
317 res = adxl345_set_window(&gs_handle, reg);
318 if (res != 0)
319 {
320 adxl345_interface_debug_print("adxl345: set window failed.\n");
321 (void)adxl345_deinit(&gs_handle);
322
323 return 1;
324 }
325 adxl345_interface_debug_print("adxl345: set window 0x%02X.\n", reg);
326 res = adxl345_get_window(&gs_handle, (uint8_t *)&check);
327 if (res != 0)
328 {
329 adxl345_interface_debug_print("adxl345: get window failed.\n");
330 (void)adxl345_deinit(&gs_handle);
331
332 return 1;
333 }
334 adxl345_interface_debug_print("adxl345: check window %s.\n", check==reg?"ok":"error");
335
336 /* adxl345_set_action_threshold/adxl345_get_action_threshold test */
337 adxl345_interface_debug_print("adxl345: adxl345_set_action_threshold/adxl345_get_action_threshold test.\n");
338 reg = rand()%256;
339 res = adxl345_set_action_threshold(&gs_handle, reg);
340 if (res != 0)
341 {
342 adxl345_interface_debug_print("adxl345: set action threshold failed.\n");
343 (void)adxl345_deinit(&gs_handle);
344
345 return 1;
346 }
347 adxl345_interface_debug_print("adxl345: set action threshold 0x%02X.\n", reg);
348 res = adxl345_get_action_threshold(&gs_handle, (uint8_t *)&check);
349 if (res != 0)
350 {
351 adxl345_interface_debug_print("adxl345: get action threshold failed.\n");
352 (void)adxl345_deinit(&gs_handle);
353
354 return 1;
355 }
356 adxl345_interface_debug_print("adxl345: check action threshold %s.\n", check==reg?"ok":"error");
357
358 /* adxl345_set_inaction_threshold/adxl345_get_inaction_threshold test */
359 adxl345_interface_debug_print("adxl345: adxl345_set_inaction_threshold/adxl345_get_inaction_threshold test.\n");
360 reg = rand()%256;
361 res = adxl345_set_inaction_threshold(&gs_handle, reg);
362 if (res != 0)
363 {
364 adxl345_interface_debug_print("adxl345: set inaction threshold failed.\n");
365 (void)adxl345_deinit(&gs_handle);
366
367 return 1;
368 }
369 adxl345_interface_debug_print("adxl345: set inaction threshold 0x%02X.\n", reg);
370 res = adxl345_get_inaction_threshold(&gs_handle, (uint8_t *)&check);
371 if (res != 0)
372 {
373 adxl345_interface_debug_print("adxl345: get inaction threshold failed.\n");
374 (void)adxl345_deinit(&gs_handle);
375
376 return 1;
377 }
378 adxl345_interface_debug_print("adxl345: check inaction threshold %s.\n", check==reg?"ok":"error");
379
380 /* adxl345_set_inaction_time/adxl345_get_inaction_time test */
381 adxl345_interface_debug_print("adxl345: adxl345_set_inaction_time/adxl345_get_inaction_time test.\n");
382 reg = rand()%256;
383 res = adxl345_set_inaction_time(&gs_handle, reg);
384 if (res != 0)
385 {
386 adxl345_interface_debug_print("adxl345: set inaction time failed.\n");
387 (void)adxl345_deinit(&gs_handle);
388
389 return 1;
390 }
391 adxl345_interface_debug_print("adxl345: set inaction time 0x%02X.\n", reg);
392 res = adxl345_get_inaction_time(&gs_handle, (uint8_t *)&check);
393 if (res != 0)
394 {
395 adxl345_interface_debug_print("adxl345: get inaction time failed.\n");
396 (void)adxl345_deinit(&gs_handle);
397
398 return 1;
399 }
400 adxl345_interface_debug_print("adxl345: check inaction time %s.\n", check==reg?"ok":"error");
401
402 /* adxl345_set_action_inaction/adxl345_get_action_inaction test */
403 adxl345_interface_debug_print("adxl345: adxl345_set_action_inaction/adxl345_get_action_inaction test.\n");
404
405 /* action_x_enable */
407 if (res != 0)
408 {
409 adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
410 (void)adxl345_deinit(&gs_handle);
411
412 return 1;
413 }
414 adxl345_interface_debug_print("adxl345: set action x enable.\n");
415 res = adxl345_get_action_inaction(&gs_handle, ADXL345_ACTION_X, &bool_test);
416 if (res != 0)
417 {
418 adxl345_interface_debug_print("adxl345: get action inaction failed.\n");
419 (void)adxl345_deinit(&gs_handle);
420
421 return 1;
422 }
423 adxl345_interface_debug_print("adxl345: check action inaction %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
424
425 /* action_x_disable */
427 if (res != 0)
428 {
429 adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
430 (void)adxl345_deinit(&gs_handle);
431
432 return 1;
433 }
434 adxl345_interface_debug_print("adxl345: set action x disable.\n");
435 res = adxl345_get_action_inaction(&gs_handle, ADXL345_ACTION_X, &bool_test);
436 if (res != 0)
437 {
438 adxl345_interface_debug_print("adxl345: get action inaction failed.\n");
439 (void)adxl345_deinit(&gs_handle);
440
441 return 1;
442 }
443 adxl345_interface_debug_print("adxl345: check action inaction %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
444
445 /* action_y_enable */
447 if (res != 0)
448 {
449 adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
450 (void)adxl345_deinit(&gs_handle);
451
452 return 1;
453 }
454 adxl345_interface_debug_print("adxl345: set action y enable.\n");
455 res = adxl345_get_action_inaction(&gs_handle, ADXL345_ACTION_Y, &bool_test);
456 if (res != 0)
457 {
458 adxl345_interface_debug_print("adxl345: get action inaction failed.\n");
459 (void)adxl345_deinit(&gs_handle);
460
461 return 1;
462 }
463 adxl345_interface_debug_print("adxl345: check action inaction %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
464
465 /* action_y_disable */
467 if (res != 0)
468 {
469 adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
470 (void)adxl345_deinit(&gs_handle);
471
472 return 1;
473 }
474 adxl345_interface_debug_print("adxl345: set action y disable.\n");
475 res = adxl345_get_action_inaction(&gs_handle, ADXL345_ACTION_Y, &bool_test);
476 if (res != 0)
477 {
478 adxl345_interface_debug_print("adxl345: get action inaction failed.\n");
479 (void)adxl345_deinit(&gs_handle);
480
481 return 1;
482 }
483 adxl345_interface_debug_print("adxl345: check action inaction %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
484
485 /* action_z_enable */
487 if (res != 0)
488 {
489 adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
490 (void)adxl345_deinit(&gs_handle);
491
492 return 1;
493 }
494 adxl345_interface_debug_print("adxl345: set action z enable.\n");
495 res = adxl345_get_action_inaction(&gs_handle, ADXL345_ACTION_Z, &bool_test);
496 if (res != 0)
497 {
498 adxl345_interface_debug_print("adxl345: get action inaction failed.\n");
499 (void)adxl345_deinit(&gs_handle);
500
501 return 1;
502 }
503 adxl345_interface_debug_print("adxl345: check action inaction %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
504
505 /* action_z_disable */
507 if (res != 0)
508 {
509 adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
510 (void)adxl345_deinit(&gs_handle);
511
512 return 1;
513 }
514 adxl345_interface_debug_print("adxl345: set action z disable.\n");
515 res = adxl345_get_action_inaction(&gs_handle, ADXL345_ACTION_Z, &bool_test);
516 if (res != 0)
517 {
518 adxl345_interface_debug_print("adxl345: get action inaction failed.\n");
519 (void)adxl345_deinit(&gs_handle);
520
521 return 1;
522 }
523 adxl345_interface_debug_print("adxl345: check action inaction %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
524
525 /* inaction_x_enable */
527 if (res != 0)
528 {
529 adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
530 (void)adxl345_deinit(&gs_handle);
531
532 return 1;
533 }
534 adxl345_interface_debug_print("adxl345: set inaction x enable.\n");
535 res = adxl345_get_action_inaction(&gs_handle, ADXL345_INACTION_X, &bool_test);
536 if (res != 0)
537 {
538 adxl345_interface_debug_print("adxl345: get action inaction failed.\n");
539 (void)adxl345_deinit(&gs_handle);
540
541 return 1;
542 }
543 adxl345_interface_debug_print("adxl345: check action inaction %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
544
545 /* inaction_x_disable */
547 if (res != 0)
548 {
549 adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
550 (void)adxl345_deinit(&gs_handle);
551
552 return 1;
553 }
554 adxl345_interface_debug_print("adxl345: set inaction x disable.\n");
555 res = adxl345_get_action_inaction(&gs_handle, ADXL345_INACTION_X, &bool_test);
556 if (res != 0)
557 {
558 adxl345_interface_debug_print("adxl345: get action inaction failed.\n");
559 (void)adxl345_deinit(&gs_handle);
560
561 return 1;
562 }
563 adxl345_interface_debug_print("adxl345: check action inaction %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
564
565 /* inaction_y_enable */
567 if (res != 0)
568 {
569 adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
570 (void)adxl345_deinit(&gs_handle);
571
572 return 1;
573 }
574 adxl345_interface_debug_print("adxl345: set inaction y enable.\n");
575 res = adxl345_get_action_inaction(&gs_handle, ADXL345_INACTION_Y, &bool_test);
576 if (res != 0)
577 {
578 adxl345_interface_debug_print("adxl345: get action inaction failed.\n");
579 (void)adxl345_deinit(&gs_handle);
580
581 return 1;
582 }
583 adxl345_interface_debug_print("adxl345: check action inaction %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
584
585 /* inaction_y_disable */
587 if (res != 0)
588 {
589 adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
590 (void)adxl345_deinit(&gs_handle);
591
592 return 1;
593 }
594 adxl345_interface_debug_print("adxl345: set inaction y disable.\n");
595 res = adxl345_get_action_inaction(&gs_handle, ADXL345_INACTION_Y, &bool_test);
596 if (res != 0)
597 {
598 adxl345_interface_debug_print("adxl345: get action inaction failed.\n");
599 (void)adxl345_deinit(&gs_handle);
600
601 return 1;
602 }
603 adxl345_interface_debug_print("adxl345: check action inaction %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
604
605 /* inaction_z_enable */
607 if (res != 0)
608 {
609 adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
610 (void)adxl345_deinit(&gs_handle);
611
612 return 1;
613 }
614 adxl345_interface_debug_print("adxl345: set inaction z enable.\n");
615 res = adxl345_get_action_inaction(&gs_handle, ADXL345_INACTION_Z, &bool_test);
616 if (res != 0)
617 {
618 adxl345_interface_debug_print("adxl345: get action inaction failed.\n");
619 (void)adxl345_deinit(&gs_handle);
620
621 return 1;
622 }
623 adxl345_interface_debug_print("adxl345: check action inaction %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
624
625 /* inaction_z_disable */
627 if (res != 0)
628 {
629 adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
630 (void)adxl345_deinit(&gs_handle);
631
632 return 1;
633 }
634 adxl345_interface_debug_print("adxl345: set inaction z disable.\n");
635 res = adxl345_get_action_inaction(&gs_handle, ADXL345_INACTION_Z, &bool_test);
636 if (res != 0)
637 {
638 adxl345_interface_debug_print("adxl345: get action inaction failed.\n");
639 (void)adxl345_deinit(&gs_handle);
640
641 return 1;
642 }
643 adxl345_interface_debug_print("adxl345: check action inaction %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
644
645 /* adxl345_set_action_coupled/adxl345_get_action_coupled test */
646 adxl345_interface_debug_print("adxl345: adxl345_set_action_coupled/adxl345_get_action_coupled test.\n");
647
648 /* coupled dc */
650 if (res != 0)
651 {
652 adxl345_interface_debug_print("adxl345: set action coupled failed.\n");
653 (void)adxl345_deinit(&gs_handle);
654
655 return 1;
656 }
657 adxl345_interface_debug_print("adxl345: set action coupled dc.\n");
658 res = adxl345_get_action_coupled(&gs_handle, &coupled);
659 if (res != 0)
660 {
661 adxl345_interface_debug_print("adxl345: get action coupled failed.\n");
662 (void)adxl345_deinit(&gs_handle);
663
664 return 1;
665 }
666 adxl345_interface_debug_print("adxl345: check action coupled %s.\n", coupled==ADXL345_COUPLED_DC?"ok":"error");
667
668 /* coupled ac */
670 if (res != 0)
671 {
672 adxl345_interface_debug_print("adxl345: set action coupled failed.\n");
673 (void)adxl345_deinit(&gs_handle);
674
675 return 1;
676 }
677 adxl345_interface_debug_print("adxl345: set action coupled ac.\n");
678 res = adxl345_get_action_coupled(&gs_handle, &coupled);
679 if (res != 0)
680 {
681 adxl345_interface_debug_print("adxl345: get action coupled failed.\n");
682 (void)adxl345_deinit(&gs_handle);
683
684 return 1;
685 }
686 adxl345_interface_debug_print("adxl345: check action coupled %s.\n", coupled==ADXL345_COUPLED_AC?"ok":"error");
687
688 /* adxl345_set_inaction_coupled/adxl345_get_inaction_coupled test */
689 adxl345_interface_debug_print("adxl345: adxl345_set_inaction_coupled/adxl345_get_inaction_coupled test.\n");
690
691 /* coupled dc */
693 if (res != 0)
694 {
695 adxl345_interface_debug_print("adxl345: set inaction coupled failed.\n");
696 (void)adxl345_deinit(&gs_handle);
697
698 return 1;
699 }
700 adxl345_interface_debug_print("adxl345: set inaction coupled dc.\n");
701 res = adxl345_get_inaction_coupled(&gs_handle, &coupled);
702 if (res != 0)
703 {
704 adxl345_interface_debug_print("adxl345: get inaction coupled failed.\n");
705 (void)adxl345_deinit(&gs_handle);
706
707 return 1;
708 }
709 adxl345_interface_debug_print("adxl345: check inaction coupled %s.\n", coupled==ADXL345_COUPLED_DC?"ok":"error");
710
711 /* coupled ac */
713 if (res != 0)
714 {
715 adxl345_interface_debug_print("adxl345: set inaction coupled failed.\n");
716 (void)adxl345_deinit(&gs_handle);
717
718 return 1;
719 }
720 adxl345_interface_debug_print("adxl345: set inaction coupled ac.\n");
721 res = adxl345_get_inaction_coupled(&gs_handle, &coupled);
722 if (res != 0)
723 {
724 adxl345_interface_debug_print("adxl345: get inaction coupled failed.\n");
725 (void)adxl345_deinit(&gs_handle);
726
727 return 1;
728 }
729 adxl345_interface_debug_print("adxl345: check inaction coupled %s.\n", coupled==ADXL345_COUPLED_AC?"ok":"error");
730
731 /* adxl345_set_free_fall_threshold/adxl345_get_free_fall_threshold test */
732 adxl345_interface_debug_print("adxl345: adxl345_set_free_fall_threshold/adxl345_get_free_fall_threshold test.\n");
733 reg = rand()%256;
734 res = adxl345_set_free_fall_threshold(&gs_handle, reg);
735 if (res != 0)
736 {
737 adxl345_interface_debug_print("adxl345: set free fall threshold failed.\n");
738 (void)adxl345_deinit(&gs_handle);
739
740 return 1;
741 }
742 adxl345_interface_debug_print("adxl345: set free fall threshold 0x%02X.\n", reg);
743 res = adxl345_get_free_fall_threshold(&gs_handle, (uint8_t *)&check);
744 if (res != 0)
745 {
746 adxl345_interface_debug_print("adxl345: get free fall threshold failed.\n");
747 (void)adxl345_deinit(&gs_handle);
748
749 return 1;
750 }
751 adxl345_interface_debug_print("adxl345: check free fall threshold %s.\n", check==reg?"ok":"error");
752
753 /* adxl345_set_free_fall_time/adxl345_get_free_fall_time test */
754 adxl345_interface_debug_print("adxl345: adxl345_set_free_fall_time/adxl345_get_free_fall_time test.\n");
755 reg = rand()%256;
756 res = adxl345_set_free_fall_time(&gs_handle, reg);
757 if (res != 0)
758 {
759 adxl345_interface_debug_print("adxl345: set free fall time failed.\n");
760 (void)adxl345_deinit(&gs_handle);
761
762 return 1;
763 }
764 adxl345_interface_debug_print("adxl345: set free fall time 0x%02X.\n", reg);
765 res = adxl345_get_free_fall_time(&gs_handle, (uint8_t *)&check);
766 if (res != 0)
767 {
768 adxl345_interface_debug_print("adxl345: get free fall time failed.\n");
769 (void)adxl345_deinit(&gs_handle);
770
771 return 1;
772 }
773 adxl345_interface_debug_print("adxl345: check free fall time %s.\n", check==reg?"ok":"error");
774
775 /* adxl345_set_tap_axis/adxl345_get_tap_axis test */
776 adxl345_interface_debug_print("adxl345: adxl345_set_tap_axis/adxl345_get_tap_axis test.\n");
777
778 /* tap_x_enable */
780 if (res != 0)
781 {
782 adxl345_interface_debug_print("adxl345: set tap axis failed.\n");
783 (void)adxl345_deinit(&gs_handle);
784
785 return 1;
786 }
787 adxl345_interface_debug_print("adxl345: set tap axis x enable.\n");
788 res = adxl345_get_tap_axis(&gs_handle, ADXL345_TAP_AXIS_X, &bool_test);
789 if (res != 0)
790 {
791 adxl345_interface_debug_print("adxl345: get tap axis failed.\n");
792 (void)adxl345_deinit(&gs_handle);
793
794 return 1;
795 }
796 adxl345_interface_debug_print("adxl345: check tap axis %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
797
798 /* tap_x_disable */
800 if (res != 0)
801 {
802 adxl345_interface_debug_print("adxl345: set tap axis failed.\n");
803 (void)adxl345_deinit(&gs_handle);
804
805 return 1;
806 }
807 adxl345_interface_debug_print("adxl345: set tap axis x disable.\n");
808 res = adxl345_get_tap_axis(&gs_handle, ADXL345_TAP_AXIS_X, &bool_test);
809 if (res != 0)
810 {
811 adxl345_interface_debug_print("adxl345: get tap axis failed.\n");
812 (void)adxl345_deinit(&gs_handle);
813
814 return 1;
815 }
816 adxl345_interface_debug_print("adxl345: check tap axis %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
817
818 /* tap_y_enable */
820 if (res != 0)
821 {
822 adxl345_interface_debug_print("adxl345: set tap axis failed.\n");
823 (void)adxl345_deinit(&gs_handle);
824
825 return 1;
826 }
827 adxl345_interface_debug_print("adxl345: set tap axis y enable.\n");
828 res = adxl345_get_tap_axis(&gs_handle, ADXL345_TAP_AXIS_Y, &bool_test);
829 if (res != 0)
830 {
831 adxl345_interface_debug_print("adxl345: get tap axis failed.\n");
832 (void)adxl345_deinit(&gs_handle);
833
834 return 1;
835 }
836 adxl345_interface_debug_print("adxl345: check tap axis %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
837
838 /* tap_y_disable */
840 if (res != 0)
841 {
842 adxl345_interface_debug_print("adxl345: set tap axis failed.\n");
843 (void)adxl345_deinit(&gs_handle);
844
845 return 1;
846 }
847 adxl345_interface_debug_print("adxl345: set tap axis y disable.\n");
848 res = adxl345_get_tap_axis(&gs_handle, ADXL345_TAP_AXIS_Y, &bool_test);
849 if (res != 0)
850 {
851 adxl345_interface_debug_print("adxl345: get tap axis failed.\n");
852 (void)adxl345_deinit(&gs_handle);
853
854 return 1;
855 }
856 adxl345_interface_debug_print("adxl345: check tap axis %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
857
858 /* tap_z_enable */
860 if (res != 0)
861 {
862 adxl345_interface_debug_print("adxl345: set tap axis failed.\n");
863 (void)adxl345_deinit(&gs_handle);
864
865 return 1;
866 }
867 adxl345_interface_debug_print("adxl345: set tap axis z enable.\n");
868 res = adxl345_get_tap_axis(&gs_handle, ADXL345_TAP_AXIS_Z, &bool_test);
869 if (res != 0)
870 {
871 adxl345_interface_debug_print("adxl345: get tap axis failed.\n");
872 (void)adxl345_deinit(&gs_handle);
873
874 return 1;
875 }
876 adxl345_interface_debug_print("adxl345: check tap axis %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
877
878 /* tap_z_disable */
880 if (res != 0)
881 {
882 adxl345_interface_debug_print("adxl345: set tap axis failed.\n");
883 (void)adxl345_deinit(&gs_handle);
884
885 return 1;
886 }
887 adxl345_interface_debug_print("adxl345: set tap axis z disable.\n");
888 res = adxl345_get_tap_axis(&gs_handle, ADXL345_TAP_AXIS_Z, &bool_test);
889 if (res != 0)
890 {
891 adxl345_interface_debug_print("adxl345: get tap axis failed.\n");
892 (void)adxl345_deinit(&gs_handle);
893
894 return 1;
895 }
896 adxl345_interface_debug_print("adxl345: check tap axis %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
897
898 /* adxl345_set_tap_suppress/adxl345_get_tap_suppress test */
899 adxl345_interface_debug_print("adxl345: adxl345_set_tap_suppress/adxl345_get_tap_suppress test.\n");
900
901 /* enable */
903 if (res != 0)
904 {
905 adxl345_interface_debug_print("adxl345: set tap suppress failed.\n");
906 (void)adxl345_deinit(&gs_handle);
907
908 return 1;
909 }
910 adxl345_interface_debug_print("adxl345: set tap suppress enable.\n");
911 res = adxl345_get_tap_suppress(&gs_handle, &bool_test);
912 if (res != 0)
913 {
914 adxl345_interface_debug_print("adxl345: get tap suppress failed.\n");
915 (void)adxl345_deinit(&gs_handle);
916
917 return 1;
918 }
919 adxl345_interface_debug_print("adxl345: check tap suppress %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
920
921 /* disable */
923 if (res != 0)
924 {
925 adxl345_interface_debug_print("adxl345: set tap suppress failed.\n");
926 (void)adxl345_deinit(&gs_handle);
927
928 return 1;
929 }
930 adxl345_interface_debug_print("adxl345: set tap suppress disable.\n");
931 res = adxl345_get_tap_suppress(&gs_handle, &bool_test);
932 if (res != 0)
933 {
934 adxl345_interface_debug_print("adxl345: get tap suppress failed.\n");
935 (void)adxl345_deinit(&gs_handle);
936
937 return 1;
938 }
939 adxl345_interface_debug_print("adxl345: check tap suppress %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
940
941 /* get tap status test */
942 adxl345_interface_debug_print("adxl345: get tap status test.\n");
943 res = adxl345_get_tap_status(&gs_handle, (uint8_t *)&reg);
944 if (res != 0)
945 {
946 adxl345_interface_debug_print("adxl345: get tap status failed.\n");
947 (void)adxl345_deinit(&gs_handle);
948
949 return 1;
950 }
951 adxl345_interface_debug_print("adxl345: tap status is 0x%02X.\n", reg);
952
953 /* adxl345_set_rate/adxl345_get_rate test */
954 adxl345_interface_debug_print("adxl345: adxl345_set_rate/adxl345_get_rate test.\n");
955
956 /* 0.1Hz */
957 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_0P1);
958 if (res != 0)
959 {
960 adxl345_interface_debug_print("adxl345: set rate failed.\n");
961 (void)adxl345_deinit(&gs_handle);
962
963 return 1;
964 }
965 adxl345_interface_debug_print("adxl345: set rate 0.1Hz.\n");
966 res = adxl345_get_rate(&gs_handle, &rate);
967 if (res != 0)
968 {
969 adxl345_interface_debug_print("adxl345: get rate failed.\n");
970 (void)adxl345_deinit(&gs_handle);
971
972 return 1;
973 }
974 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_0P1?"ok":"error");
975
976 /* 0.2Hz */
977 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_0P2);
978 if (res != 0)
979 {
980 adxl345_interface_debug_print("adxl345: set rate failed.\n");
981 (void)adxl345_deinit(&gs_handle);
982
983 return 1;
984 }
985 adxl345_interface_debug_print("adxl345: set rate 0.2Hz.\n");
986 res = adxl345_get_rate(&gs_handle, &rate);
987 if (res != 0)
988 {
989 adxl345_interface_debug_print("adxl345: get rate failed.\n");
990 (void)adxl345_deinit(&gs_handle);
991
992 return 1;
993 }
994 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_0P2?"ok":"error");
995
996 /* 0.39Hz */
997 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_0P39);
998 if (res != 0)
999 {
1000 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1001 (void)adxl345_deinit(&gs_handle);
1002
1003 return 1;
1004 }
1005 adxl345_interface_debug_print("adxl345: set rate 0.39Hz.\n");
1006 res = adxl345_get_rate(&gs_handle, &rate);
1007 if (res != 0)
1008 {
1009 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1010 (void)adxl345_deinit(&gs_handle);
1011
1012 return 1;
1013 }
1014 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_0P39?"ok":"error");
1015
1016 /* 0.78Hz */
1017 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_0P78);
1018 if (res != 0)
1019 {
1020 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1021 (void)adxl345_deinit(&gs_handle);
1022
1023 return 1;
1024 }
1025 adxl345_interface_debug_print("adxl345: set rate 0.78Hz.\n");
1026 res = adxl345_get_rate(&gs_handle, &rate);
1027 if (res != 0)
1028 {
1029 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1030 (void)adxl345_deinit(&gs_handle);
1031
1032 return 1;
1033 }
1034 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_0P78?"ok":"error");
1035
1036 /* 1.56Hz */
1037 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_1P56);
1038 if (res != 0)
1039 {
1040 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1041 (void)adxl345_deinit(&gs_handle);
1042
1043 return 1;
1044 }
1045 adxl345_interface_debug_print("adxl345: set rate 1.56Hz.\n");
1046 res = adxl345_get_rate(&gs_handle, &rate);
1047 if (res != 0)
1048 {
1049 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1050 (void)adxl345_deinit(&gs_handle);
1051
1052 return 1;
1053 }
1054 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_1P56?"ok":"error");
1055
1056 /* 3.13Hz */
1057 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_3P13);
1058 if (res != 0)
1059 {
1060 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1061 (void)adxl345_deinit(&gs_handle);
1062
1063 return 1;
1064 }
1065 adxl345_interface_debug_print("adxl345: set rate 3.13Hz.\n");
1066 res = adxl345_get_rate(&gs_handle, &rate);
1067 if (res != 0)
1068 {
1069 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1070 (void)adxl345_deinit(&gs_handle);
1071
1072 return 1;
1073 }
1074 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_3P13?"ok":"error");
1075
1076 /* 6.25Hz */
1077 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_6P25);
1078 if (res != 0)
1079 {
1080 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1081 (void)adxl345_deinit(&gs_handle);
1082
1083 return 1;
1084 }
1085 adxl345_interface_debug_print("adxl345: set rate 6.25Hz.\n");
1086 res = adxl345_get_rate(&gs_handle, &rate);
1087 if (res != 0)
1088 {
1089 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1090 (void)adxl345_deinit(&gs_handle);
1091
1092 return 1;
1093 }
1094 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_6P25?"ok":"error");
1095
1096 /* 12.5Hz */
1097 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_12P5);
1098 if (res != 0)
1099 {
1100 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1101 (void)adxl345_deinit(&gs_handle);
1102
1103 return 1;
1104 }
1105 adxl345_interface_debug_print("adxl345: set rate 12.5Hz.\n");
1106 res = adxl345_get_rate(&gs_handle, &rate);
1107 if (res != 0)
1108 {
1109 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1110 (void)adxl345_deinit(&gs_handle);
1111
1112 return 1;
1113 }
1114 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_12P5?"ok":"error");
1115
1116 /* 25Hz */
1117 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_25);
1118 if (res != 0)
1119 {
1120 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1121 (void)adxl345_deinit(&gs_handle);
1122
1123 return 1;
1124 }
1125 adxl345_interface_debug_print("adxl345: set rate 25Hz.\n");
1126 res = adxl345_get_rate(&gs_handle, &rate);
1127 if (res != 0)
1128 {
1129 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1130 (void)adxl345_deinit(&gs_handle);
1131
1132 return 1;
1133 }
1134 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_25?"ok":"error");
1135
1136 /* 50Hz */
1137 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_50);
1138 if (res != 0)
1139 {
1140 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1141 (void)adxl345_deinit(&gs_handle);
1142
1143 return 1;
1144 }
1145 adxl345_interface_debug_print("adxl345: set rate 50Hz.\n");
1146 res = adxl345_get_rate(&gs_handle, &rate);
1147 if (res != 0)
1148 {
1149 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1150 (void)adxl345_deinit(&gs_handle);
1151
1152 return 1;
1153 }
1154 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_50?"ok":"error");
1155
1156 /* 100Hz */
1157 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_100);
1158 if (res != 0)
1159 {
1160 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1161 (void)adxl345_deinit(&gs_handle);
1162
1163 return 1;
1164 }
1165 adxl345_interface_debug_print("adxl345: set rate 100Hz.\n");
1166 res = adxl345_get_rate(&gs_handle, &rate);
1167 if (res != 0)
1168 {
1169 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1170 (void)adxl345_deinit(&gs_handle);
1171
1172 return 1;
1173 }
1174 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_100?"ok":"error");
1175
1176 /* 200Hz */
1177 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_200);
1178 if (res != 0)
1179 {
1180 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1181 (void)adxl345_deinit(&gs_handle);
1182
1183 return 1;
1184 }
1185 adxl345_interface_debug_print("adxl345: set rate 200Hz.\n");
1186 res = adxl345_get_rate(&gs_handle, &rate);
1187 if (res != 0)
1188 {
1189 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1190 (void)adxl345_deinit(&gs_handle);
1191
1192 return 1;
1193 }
1194 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_200?"ok":"error");
1195
1196 /* 400Hz */
1197 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_400);
1198 if (res != 0)
1199 {
1200 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1201 (void)adxl345_deinit(&gs_handle);
1202
1203 return 1;
1204 }
1205 adxl345_interface_debug_print("adxl345: set rate 400Hz.\n");
1206 res = adxl345_get_rate(&gs_handle, &rate);
1207 if (res != 0)
1208 {
1209 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1210 (void)adxl345_deinit(&gs_handle);
1211
1212 return 1;
1213 }
1214 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_400?"ok":"error");
1215
1216 /* 800Hz */
1217 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_800);
1218 if (res != 0)
1219 {
1220 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1221 (void)adxl345_deinit(&gs_handle);
1222
1223 return 1;
1224 }
1225 adxl345_interface_debug_print("adxl345: set rate 800Hz.\n");
1226 res = adxl345_get_rate(&gs_handle, &rate);
1227 if (res != 0)
1228 {
1229 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1230 (void)adxl345_deinit(&gs_handle);
1231
1232 return 1;
1233 }
1234 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_800?"ok":"error");
1235
1236 /* 1600Hz */
1237 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_1600);
1238 if (res != 0)
1239 {
1240 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1241 (void)adxl345_deinit(&gs_handle);
1242
1243 return 1;
1244 }
1245 adxl345_interface_debug_print("adxl345: set rate 1600Hz.\n");
1246 res = adxl345_get_rate(&gs_handle, &rate);
1247 if (res != 0)
1248 {
1249 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1250 (void)adxl345_deinit(&gs_handle);
1251
1252 return 1;
1253 }
1254 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_1600?"ok":"error");
1255
1256 /* 3200Hz */
1257 res = adxl345_set_rate(&gs_handle, ADXL345_RATE_3200);
1258 if (res != 0)
1259 {
1260 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1261 (void)adxl345_deinit(&gs_handle);
1262
1263 return 1;
1264 }
1265 adxl345_interface_debug_print("adxl345: set rate 3200Hz.\n");
1266 res = adxl345_get_rate(&gs_handle, &rate);
1267 if (res != 0)
1268 {
1269 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1270 (void)adxl345_deinit(&gs_handle);
1271
1272 return 1;
1273 }
1274 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_RATE_3200?"ok":"error");
1275
1276 /* low 12.5Hz */
1278 if (res != 0)
1279 {
1280 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1281 (void)adxl345_deinit(&gs_handle);
1282
1283 return 1;
1284 }
1285 adxl345_interface_debug_print("adxl345: set rate low 12.5Hz.\n");
1286 res = adxl345_get_rate(&gs_handle, &rate);
1287 if (res != 0)
1288 {
1289 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1290 (void)adxl345_deinit(&gs_handle);
1291
1292 return 1;
1293 }
1294 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_LOW_POWER_RATE_12P5?"ok":"error");
1295
1296 /* low 25Hz */
1298 if (res != 0)
1299 {
1300 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1301 (void)adxl345_deinit(&gs_handle);
1302
1303 return 1;
1304 }
1305 adxl345_interface_debug_print("adxl345: set rate low 25Hz.\n");
1306 res = adxl345_get_rate(&gs_handle, &rate);
1307 if (res != 0)
1308 {
1309 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1310 (void)adxl345_deinit(&gs_handle);
1311
1312 return 1;
1313 }
1314 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_LOW_POWER_RATE_25?"ok":"error");
1315
1316 /* low 50Hz */
1318 if (res != 0)
1319 {
1320 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1321 (void)adxl345_deinit(&gs_handle);
1322
1323 return 1;
1324 }
1325 adxl345_interface_debug_print("adxl345: set rate low 50Hz.\n");
1326 res = adxl345_get_rate(&gs_handle, &rate);
1327 if (res != 0)
1328 {
1329 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1330 (void)adxl345_deinit(&gs_handle);
1331
1332 return 1;
1333 }
1334 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_LOW_POWER_RATE_50?"ok":"error");
1335
1336 /* low 100Hz */
1338 if (res != 0)
1339 {
1340 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1341 (void)adxl345_deinit(&gs_handle);
1342
1343 return 1;
1344 }
1345 adxl345_interface_debug_print("adxl345: set rate low 100Hz.\n");
1346 res = adxl345_get_rate(&gs_handle, &rate);
1347 if (res != 0)
1348 {
1349 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1350 (void)adxl345_deinit(&gs_handle);
1351
1352 return 1;
1353 }
1354 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_LOW_POWER_RATE_100?"ok":"error");
1355
1356 /* low 200Hz */
1358 if (res != 0)
1359 {
1360 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1361 (void)adxl345_deinit(&gs_handle);
1362
1363 return 1;
1364 }
1365 adxl345_interface_debug_print("adxl345: set rate low 200Hz.\n");
1366 res = adxl345_get_rate(&gs_handle, &rate);
1367 if (res != 0)
1368 {
1369 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1370 (void)adxl345_deinit(&gs_handle);
1371
1372 return 1;
1373 }
1374 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_LOW_POWER_RATE_200?"ok":"error");
1375
1376 /* low 400Hz */
1378 if (res != 0)
1379 {
1380 adxl345_interface_debug_print("adxl345: set rate failed.\n");
1381 (void)adxl345_deinit(&gs_handle);
1382
1383 return 1;
1384 }
1385 adxl345_interface_debug_print("adxl345: set rate low 400Hz.\n");
1386 res = adxl345_get_rate(&gs_handle, &rate);
1387 if (res != 0)
1388 {
1389 adxl345_interface_debug_print("adxl345: get rate failed.\n");
1390 (void)adxl345_deinit(&gs_handle);
1391
1392 return 1;
1393 }
1394 adxl345_interface_debug_print("adxl345: check rate %s.\n", rate==ADXL345_LOW_POWER_RATE_400?"ok":"error");
1395
1396 /* adxl345_set_interrupt/adxl345_get_interrupt test */
1397 adxl345_interface_debug_print("adxl345: adxl345_set_interrupt/adxl345_get_interrupt test.\n");
1398
1399 /* data enable */
1401 if (res != 0)
1402 {
1403 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1404 (void)adxl345_deinit(&gs_handle);
1405
1406 return 1;
1407 }
1408 adxl345_interface_debug_print("adxl345: set interrupt data ready enable.\n");
1409 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_DATA_READY, &bool_test);
1410 if (res != 0)
1411 {
1412 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1413 (void)adxl345_deinit(&gs_handle);
1414
1415 return 1;
1416 }
1417 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
1418
1419 /* data disable */
1421 if (res != 0)
1422 {
1423 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1424 (void)adxl345_deinit(&gs_handle);
1425
1426 return 1;
1427 }
1428 adxl345_interface_debug_print("adxl345: set interrupt data ready disable.\n");
1429 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_DATA_READY, &bool_test);
1430 if (res != 0)
1431 {
1432 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1433 (void)adxl345_deinit(&gs_handle);
1434
1435 return 1;
1436 }
1437 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
1438
1439 /* single enable */
1441 if (res != 0)
1442 {
1443 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1444 (void)adxl345_deinit(&gs_handle);
1445
1446 return 1;
1447 }
1448 adxl345_interface_debug_print("adxl345: set interrupt single enable.\n");
1449 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_SINGLE_TAP, &bool_test);
1450 if (res != 0)
1451 {
1452 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1453 (void)adxl345_deinit(&gs_handle);
1454
1455 return 1;
1456 }
1457 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
1458
1459 /* single disable */
1461 if (res != 0)
1462 {
1463 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1464 (void)adxl345_deinit(&gs_handle);
1465
1466 return 1;
1467 }
1468 adxl345_interface_debug_print("adxl345: set interrupt single disable.\n");
1469 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_SINGLE_TAP, &bool_test);
1470 if (res != 0)
1471 {
1472 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1473 (void)adxl345_deinit(&gs_handle);
1474
1475 return 1;
1476 }
1477 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
1478
1479 /* double enable */
1481 if (res != 0)
1482 {
1483 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1484 (void)adxl345_deinit(&gs_handle);
1485
1486 return 1;
1487 }
1488 adxl345_interface_debug_print("adxl345: set interrupt double enable.\n");
1489 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_DOUBLE_TAP, &bool_test);
1490 if (res != 0)
1491 {
1492 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1493 (void)adxl345_deinit(&gs_handle);
1494
1495 return 1;
1496 }
1497 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
1498
1499 /* double disable */
1501 if (res != 0)
1502 {
1503 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1504 (void)adxl345_deinit(&gs_handle);
1505
1506 return 1;
1507 }
1508 adxl345_interface_debug_print("adxl345: set interrupt double disable.\n");
1509 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_DOUBLE_TAP, &bool_test);
1510 if (res != 0)
1511 {
1512 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1513 (void)adxl345_deinit(&gs_handle);
1514
1515 return 1;
1516 }
1517 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
1518
1519 /* activity enable */
1521 if (res != 0)
1522 {
1523 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1524 (void)adxl345_deinit(&gs_handle);
1525
1526 return 1;
1527 }
1528 adxl345_interface_debug_print("adxl345: set interrupt activity enable.\n");
1529 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_ACTIVITY, &bool_test);
1530 if (res != 0)
1531 {
1532 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1533 (void)adxl345_deinit(&gs_handle);
1534
1535 return 1;
1536 }
1537 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
1538
1539 /* activity disable */
1541 if (res != 0)
1542 {
1543 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1544 (void)adxl345_deinit(&gs_handle);
1545
1546 return 1;
1547 }
1548 adxl345_interface_debug_print("adxl345: set interrupt activity disable.\n");
1549 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_ACTIVITY, &bool_test);
1550 if (res != 0)
1551 {
1552 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1553 (void)adxl345_deinit(&gs_handle);
1554
1555 return 1;
1556 }
1557 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
1558
1559 /* inactivity enable */
1561 if (res != 0)
1562 {
1563 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1564 (void)adxl345_deinit(&gs_handle);
1565
1566 return 1;
1567 }
1568 adxl345_interface_debug_print("adxl345: set interrupt inactivity enable.\n");
1569 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_INACTIVITY, &bool_test);
1570 if (res != 0)
1571 {
1572 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1573 (void)adxl345_deinit(&gs_handle);
1574
1575 return 1;
1576 }
1577 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
1578
1579 /* inactivity disable */
1581 if (res != 0)
1582 {
1583 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1584 (void)adxl345_deinit(&gs_handle);
1585
1586 return 1;
1587 }
1588 adxl345_interface_debug_print("adxl345: set interrupt inactivity disable.\n");
1589 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_INACTIVITY, &bool_test);
1590 if (res != 0)
1591 {
1592 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1593 (void)adxl345_deinit(&gs_handle);
1594
1595 return 1;
1596 }
1597 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
1598
1599 /* free fall enable */
1601 if (res != 0)
1602 {
1603 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1604 (void)adxl345_deinit(&gs_handle);
1605
1606 return 1;
1607 }
1608 adxl345_interface_debug_print("adxl345: set interrupt free fall enable.\n");
1609 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_FREE_FALL, &bool_test);
1610 if (res != 0)
1611 {
1612 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1613 (void)adxl345_deinit(&gs_handle);
1614
1615 return 1;
1616 }
1617 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
1618
1619 /* free fall disable */
1621 if (res != 0)
1622 {
1623 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1624 (void)adxl345_deinit(&gs_handle);
1625
1626 return 1;
1627 }
1628 adxl345_interface_debug_print("adxl345: set interrupt free fall disable.\n");
1629 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_FREE_FALL, &bool_test);
1630 if (res != 0)
1631 {
1632 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1633 (void)adxl345_deinit(&gs_handle);
1634
1635 return 1;
1636 }
1637 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
1638
1639 /* watermark enable */
1641 if (res != 0)
1642 {
1643 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1644 (void)adxl345_deinit(&gs_handle);
1645
1646 return 1;
1647 }
1648 adxl345_interface_debug_print("adxl345: set interrupt watermark enable.\n");
1649 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_WATERMARK, &bool_test);
1650 if (res != 0)
1651 {
1652 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1653 (void)adxl345_deinit(&gs_handle);
1654
1655 return 1;
1656 }
1657 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
1658
1659 /* watermark disable */
1661 if (res != 0)
1662 {
1663 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1664 (void)adxl345_deinit(&gs_handle);
1665
1666 return 1;
1667 }
1668 adxl345_interface_debug_print("adxl345: set interrupt watermark disable.\n");
1669 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_WATERMARK, &bool_test);
1670 if (res != 0)
1671 {
1672 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1673 (void)adxl345_deinit(&gs_handle);
1674
1675 return 1;
1676 }
1677 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
1678
1679 /* overrun enable */
1681 if (res != 0)
1682 {
1683 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1684 (void)adxl345_deinit(&gs_handle);
1685
1686 return 1;
1687 }
1688 adxl345_interface_debug_print("adxl345: set interrupt overrun enable.\n");
1689 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_OVERRUN, &bool_test);
1690 if (res != 0)
1691 {
1692 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1693 (void)adxl345_deinit(&gs_handle);
1694
1695 return 1;
1696 }
1697 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
1698
1699 /* overrun disable */
1701 if (res != 0)
1702 {
1703 adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
1704 (void)adxl345_deinit(&gs_handle);
1705
1706 return 1;
1707 }
1708 adxl345_interface_debug_print("adxl345: set interrupt overrun disable.\n");
1709 res = adxl345_get_interrupt(&gs_handle, ADXL345_INTERRUPT_OVERRUN, &bool_test);
1710 if (res != 0)
1711 {
1712 adxl345_interface_debug_print("adxl345: get interrupt failed.\n");
1713 (void)adxl345_deinit(&gs_handle);
1714
1715 return 1;
1716 }
1717 adxl345_interface_debug_print("adxl345: check interrupt %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
1718
1719 /* adxl345_set_interrupt_map/adxl345_get_interrupt_map test */
1720 adxl345_interface_debug_print("adxl345: adxl345_set_interrupt_map/adxl345_get_interrupt_map test.\n");
1721
1722 /* data pin1 */
1724 if (res != 0)
1725 {
1726 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1727 (void)adxl345_deinit(&gs_handle);
1728
1729 return 1;
1730 }
1731 adxl345_interface_debug_print("adxl345: set interrupt map data ready pin1.\n");
1733 if (res != 0)
1734 {
1735 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1736 (void)adxl345_deinit(&gs_handle);
1737
1738 return 1;
1739 }
1740 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN1?"ok":"error");
1741
1742 /* data pin2 */
1744 if (res != 0)
1745 {
1746 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1747 (void)adxl345_deinit(&gs_handle);
1748
1749 return 1;
1750 }
1751 adxl345_interface_debug_print("adxl345: set interrupt map data ready pin2.\n");
1753 if (res != 0)
1754 {
1755 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1756 (void)adxl345_deinit(&gs_handle);
1757
1758 return 1;
1759 }
1760 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN2?"ok":"error");
1761
1762 /* single tap pin1 */
1764 if (res != 0)
1765 {
1766 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1767 (void)adxl345_deinit(&gs_handle);
1768
1769 return 1;
1770 }
1771 adxl345_interface_debug_print("adxl345: set interrupt map single tap pin1.\n");
1773 if (res != 0)
1774 {
1775 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1776 (void)adxl345_deinit(&gs_handle);
1777
1778 return 1;
1779 }
1780 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN1?"ok":"error");
1781
1782 /* single pin2 */
1784 if (res != 0)
1785 {
1786 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1787 (void)adxl345_deinit(&gs_handle);
1788
1789 return 1;
1790 }
1791 adxl345_interface_debug_print("adxl345: set interrupt map single pin2.\n");
1793 if (res != 0)
1794 {
1795 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1796 (void)adxl345_deinit(&gs_handle);
1797
1798 return 1;
1799 }
1800 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN2?"ok":"error");
1801
1802 /* double tap pin1 */
1804 if (res != 0)
1805 {
1806 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1807 (void)adxl345_deinit(&gs_handle);
1808
1809 return 1;
1810 }
1811 adxl345_interface_debug_print("adxl345: set interrupt map double tap pin1.\n");
1813 if (res != 0)
1814 {
1815 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1816 (void)adxl345_deinit(&gs_handle);
1817
1818 return 1;
1819 }
1820 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN1?"ok":"error");
1821
1822 /* double pin2 */
1824 if (res != 0)
1825 {
1826 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1827 (void)adxl345_deinit(&gs_handle);
1828
1829 return 1;
1830 }
1831 adxl345_interface_debug_print("adxl345: set interrupt map double pin2.\n");
1833 if (res != 0)
1834 {
1835 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1836 (void)adxl345_deinit(&gs_handle);
1837
1838 return 1;
1839 }
1840 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN2?"ok":"error");
1841
1842 /* activity pin1 */
1844 if (res != 0)
1845 {
1846 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1847 (void)adxl345_deinit(&gs_handle);
1848
1849 return 1;
1850 }
1851 adxl345_interface_debug_print("adxl345: set interrupt map activity pin1.\n");
1853 if (res != 0)
1854 {
1855 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1856 (void)adxl345_deinit(&gs_handle);
1857
1858 return 1;
1859 }
1860 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN1?"ok":"error");
1861
1862 /* activity pin2 */
1864 if (res != 0)
1865 {
1866 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1867 (void)adxl345_deinit(&gs_handle);
1868
1869 return 1;
1870 }
1871 adxl345_interface_debug_print("adxl345: set interrupt activity pin2.\n");
1873 if (res != 0)
1874 {
1875 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1876 (void)adxl345_deinit(&gs_handle);
1877
1878 return 1;
1879 }
1880 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN2?"ok":"error");
1881
1882 /* inactivity pin1 */
1884 if (res != 0)
1885 {
1886 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1887 (void)adxl345_deinit(&gs_handle);
1888
1889 return 1;
1890 }
1891 adxl345_interface_debug_print("adxl345: set interrupt map inactivity pin1.\n");
1893 if (res != 0)
1894 {
1895 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1896 (void)adxl345_deinit(&gs_handle);
1897
1898 return 1;
1899 }
1900 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN1?"ok":"error");
1901
1902 /* inactivity pin2 */
1904 if (res != 0)
1905 {
1906 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1907 (void)adxl345_deinit(&gs_handle);
1908
1909 return 1;
1910 }
1911 adxl345_interface_debug_print("adxl345: set interrupt inactivity pin2.\n");
1913 if (res != 0)
1914 {
1915 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1916 (void)adxl345_deinit(&gs_handle);
1917
1918 return 1;
1919 }
1920 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN2?"ok":"error");
1921
1922 /* free fall pin1 */
1924 if (res != 0)
1925 {
1926 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1927 (void)adxl345_deinit(&gs_handle);
1928
1929 return 1;
1930 }
1931 adxl345_interface_debug_print("adxl345: set interrupt map free fall pin1.\n");
1933 if (res != 0)
1934 {
1935 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1936 (void)adxl345_deinit(&gs_handle);
1937
1938 return 1;
1939 }
1940 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN1?"ok":"error");
1941
1942 /* free fall pin2 */
1944 if (res != 0)
1945 {
1946 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1947 (void)adxl345_deinit(&gs_handle);
1948
1949 return 1;
1950 }
1951 adxl345_interface_debug_print("adxl345: set interrupt free fall pin2.\n");
1953 if (res != 0)
1954 {
1955 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1956 (void)adxl345_deinit(&gs_handle);
1957
1958 return 1;
1959 }
1960 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN2?"ok":"error");
1961
1962 /* watermark pin1 */
1964 if (res != 0)
1965 {
1966 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1967 (void)adxl345_deinit(&gs_handle);
1968
1969 return 1;
1970 }
1971 adxl345_interface_debug_print("adxl345: set interrupt map watermark pin1.\n");
1973 if (res != 0)
1974 {
1975 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1976 (void)adxl345_deinit(&gs_handle);
1977
1978 return 1;
1979 }
1980 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN1?"ok":"error");
1981
1982 /* watermark pin2 */
1984 if (res != 0)
1985 {
1986 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
1987 (void)adxl345_deinit(&gs_handle);
1988
1989 return 1;
1990 }
1991 adxl345_interface_debug_print("adxl345: set interrupt watermark pin2.\n");
1993 if (res != 0)
1994 {
1995 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
1996 (void)adxl345_deinit(&gs_handle);
1997
1998 return 1;
1999 }
2000 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN2?"ok":"error");
2001
2002 /* overrun pin1 */
2004 if (res != 0)
2005 {
2006 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
2007 (void)adxl345_deinit(&gs_handle);
2008
2009 return 1;
2010 }
2011 adxl345_interface_debug_print("adxl345: set interrupt map overrun pin1.\n");
2013 if (res != 0)
2014 {
2015 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
2016 (void)adxl345_deinit(&gs_handle);
2017
2018 return 1;
2019 }
2020 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN1?"ok":"error");
2021
2022 /* overrun pin2 */
2024 if (res != 0)
2025 {
2026 adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
2027 (void)adxl345_deinit(&gs_handle);
2028
2029 return 1;
2030 }
2031 adxl345_interface_debug_print("adxl345: set interrupt overrun pin2.\n");
2033 if (res != 0)
2034 {
2035 adxl345_interface_debug_print("adxl345: get interrupt map failed.\n");
2036 (void)adxl345_deinit(&gs_handle);
2037
2038 return 1;
2039 }
2040 adxl345_interface_debug_print("adxl345: check interrupt map %s.\n", pin==ADXL345_INTERRUPT_PIN2?"ok":"error");
2041
2042 /* adxl345_get_interrupt_source test */
2043 adxl345_interface_debug_print("adxl345: adxl345_get_interrupt_source test.\n");
2044 res = adxl345_get_interrupt_source(&gs_handle, (uint8_t *)&reg);
2045 if (res != 0)
2046 {
2047 adxl345_interface_debug_print("adxl345: get interrupt source failed.\n");
2048 (void)adxl345_deinit(&gs_handle);
2049
2050 return 1;
2051 }
2052 adxl345_interface_debug_print("adxl345: check interrupt source 0x%02X.\n", res);
2053
2054 /* adxl345_set_self_test/adxl345_get_self_test test */
2055 adxl345_interface_debug_print("adxl345: adxl345_set_self_test/adxl345_get_self_test test.\n");
2056
2057 /* enable */
2058 res = adxl345_set_self_test(&gs_handle, ADXL345_BOOL_TRUE);
2059 if (res != 0)
2060 {
2061 adxl345_interface_debug_print("adxl345: set self test failed.\n");
2062 (void)adxl345_deinit(&gs_handle);
2063
2064 return 1;
2065 }
2066 adxl345_interface_debug_print("adxl345: set self test enable.\n");
2067 res = adxl345_get_self_test(&gs_handle, &bool_test);
2068 if (res != 0)
2069 {
2070 adxl345_interface_debug_print("adxl345: get self test failed.\n");
2071 (void)adxl345_deinit(&gs_handle);
2072
2073 return 1;
2074 }
2075 adxl345_interface_debug_print("adxl345: check self test %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
2076
2077 /* disable */
2078 res = adxl345_set_self_test(&gs_handle, ADXL345_BOOL_FALSE);
2079 if (res != 0)
2080 {
2081 adxl345_interface_debug_print("adxl345: set self test failed.\n");
2082 (void)adxl345_deinit(&gs_handle);
2083
2084 return 1;
2085 }
2086 adxl345_interface_debug_print("adxl345: set self test disable.\n");
2087 res = adxl345_get_self_test(&gs_handle, &bool_test);
2088 if (res != 0)
2089 {
2090 adxl345_interface_debug_print("adxl345: get self test failed.\n");
2091 (void)adxl345_deinit(&gs_handle);
2092
2093 return 1;
2094 }
2095 adxl345_interface_debug_print("adxl345: check self test %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
2096
2097 /* adxl345_set_spi_wire/adxl345_get_spi_wire test */
2098 adxl345_interface_debug_print("adxl345: adxl345_set_spi_wire/adxl345_get_spi_wire test.\n");
2099
2100 /* enable */
2101 res = adxl345_set_self_test(&gs_handle, ADXL345_BOOL_TRUE);
2102 if (res != 0)
2103 {
2104 adxl345_interface_debug_print("adxl345: set self test failed.\n");
2105 (void)adxl345_deinit(&gs_handle);
2106
2107 return 1;
2108 }
2109 adxl345_interface_debug_print("adxl345: set self test enable.\n");
2110 res = adxl345_get_self_test(&gs_handle, &bool_test);
2111 if (res != 0)
2112 {
2113 adxl345_interface_debug_print("adxl345: get self test failed.\n");
2114 (void)adxl345_deinit(&gs_handle);
2115
2116 return 1;
2117 }
2118 adxl345_interface_debug_print("adxl345: check self test %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
2119
2120 /* disable */
2121 res = adxl345_set_self_test(&gs_handle, ADXL345_BOOL_FALSE);
2122 if (res != 0)
2123 {
2124 adxl345_interface_debug_print("adxl345: set self test failed.\n");
2125 (void)adxl345_deinit(&gs_handle);
2126
2127 return 1;
2128 }
2129 adxl345_interface_debug_print("adxl345: set self test disable.\n");
2130 res = adxl345_get_self_test(&gs_handle, &bool_test);
2131 if (res != 0)
2132 {
2133 adxl345_interface_debug_print("adxl345: get self test failed.\n");
2134 (void)adxl345_deinit(&gs_handle);
2135
2136 return 1;
2137 }
2138 adxl345_interface_debug_print("adxl345: check self test %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
2139
2140 /* adxl345_set_interrupt_active_level/adxl345_get_interrupt_active_level test */
2141 adxl345_interface_debug_print("adxl345: adxl345_set_interrupt_active_level/adxl345_get_interrupt_active_level test.\n");
2142
2143 /* high */
2145 if (res != 0)
2146 {
2147 adxl345_interface_debug_print("adxl345: set interrupt active level failed.\n");
2148 (void)adxl345_deinit(&gs_handle);
2149
2150 return 1;
2151 }
2152 adxl345_interface_debug_print("adxl345: set interrupt active level high.\n");
2153 res = adxl345_get_interrupt_active_level(&gs_handle, &pin_type);
2154 if (res != 0)
2155 {
2156 adxl345_interface_debug_print("adxl345: get interrupt active level failed.\n");
2157 (void)adxl345_deinit(&gs_handle);
2158
2159 return 1;
2160 }
2161 adxl345_interface_debug_print("adxl345: check interrupt active level %s.\n", pin_type==ADXL345_INTERRUPT_ACTIVE_LEVEL_HIGH?"ok":"error");
2162
2163 /* low */
2165 if (res != 0)
2166 {
2167 adxl345_interface_debug_print("adxl345: set interrupt active level failed.\n");
2168 (void)adxl345_deinit(&gs_handle);
2169
2170 return 1;
2171 }
2172 adxl345_interface_debug_print("adxl345: set interrupt active level low.\n");
2173 res = adxl345_get_interrupt_active_level(&gs_handle, &pin_type);
2174 if (res != 0)
2175 {
2176 adxl345_interface_debug_print("adxl345: get interrupt active level failed.\n");
2177 (void)adxl345_deinit(&gs_handle);
2178
2179 return 1;
2180 }
2181 adxl345_interface_debug_print("adxl345: check interrupt active level %s.\n", pin_type==ADXL345_INTERRUPT_ACTIVE_LEVEL_LOW?"ok":"error");
2182
2183 /* adxl345_set_full_resolution/adxl345_get_full_resolution test */
2184 adxl345_interface_debug_print("adxl345: adxl345_set_full_resolution/adxl345_get_full_resolution test.\n");
2185
2186 /* enable */
2188 if (res != 0)
2189 {
2190 adxl345_interface_debug_print("adxl345: set full resolution failed.\n");
2191 (void)adxl345_deinit(&gs_handle);
2192
2193 return 1;
2194 }
2195 adxl345_interface_debug_print("adxl345: enable full resolution.\n");
2196 res = adxl345_get_full_resolution(&gs_handle, &bool_test);
2197 if (res != 0)
2198 {
2199 adxl345_interface_debug_print("adxl345: get full resolution failed.\n");
2200 (void)adxl345_deinit(&gs_handle);
2201
2202 return 1;
2203 }
2204 adxl345_interface_debug_print("adxl345: check full resolution %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
2205
2206 /* disable */
2208 if (res != 0)
2209 {
2210 adxl345_interface_debug_print("adxl345: set full resolution failed.\n");
2211 (void)adxl345_deinit(&gs_handle);
2212
2213 return 1;
2214 }
2215 adxl345_interface_debug_print("adxl345: disable full resolution.\n");
2216 res = adxl345_get_full_resolution(&gs_handle, &bool_test);
2217 if (res != 0)
2218 {
2219 adxl345_interface_debug_print("adxl345: get full resolution failed.\n");
2220 (void)adxl345_deinit(&gs_handle);
2221
2222 return 1;
2223 }
2224 adxl345_interface_debug_print("adxl345: check full resolution %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
2225
2226 /* adxl345_set_justify/adxl345_get_justify test */
2227 adxl345_interface_debug_print("adxl345: adxl345_set_justify/adxl345_get_justify test.\n");
2228
2229 /* right */
2230 res = adxl345_set_justify(&gs_handle, ADXL345_JUSTIFY_RIGHT);
2231 if (res != 0)
2232 {
2233 adxl345_interface_debug_print("adxl345: set justify failed.\n");
2234 (void)adxl345_deinit(&gs_handle);
2235
2236 return 1;
2237 }
2238 adxl345_interface_debug_print("adxl345: set justify right.\n");
2239 res = adxl345_get_justify(&gs_handle, &justify);
2240 if (res != 0)
2241 {
2242 adxl345_interface_debug_print("adxl345: get justify failed.\n");
2243 (void)adxl345_deinit(&gs_handle);
2244
2245 return 1;
2246 }
2247 adxl345_interface_debug_print("adxl345: check justify %s.\n", justify==ADXL345_JUSTIFY_RIGHT?"ok":"error");
2248
2249 /* left */
2250 res = adxl345_set_justify(&gs_handle, ADXL345_JUSTIFY_LEFT);
2251 if (res != 0)
2252 {
2253 adxl345_interface_debug_print("adxl345: set justify failed.\n");
2254 (void)adxl345_deinit(&gs_handle);
2255
2256 return 1;
2257 }
2258 adxl345_interface_debug_print("adxl345: set justify left.\n");
2259 res = adxl345_get_justify(&gs_handle, &justify);
2260 if (res != 0)
2261 {
2262 adxl345_interface_debug_print("adxl345: get justify failed.\n");
2263 (void)adxl345_deinit(&gs_handle);
2264
2265 return 1;
2266 }
2267 adxl345_interface_debug_print("adxl345: check justify %s.\n", justify==ADXL345_JUSTIFY_LEFT?"ok":"error");
2268
2269 /* adxl345_set_range/adxl345_get_range test */
2270 adxl345_interface_debug_print("adxl345: adxl345_set_range/adxl345_get_range test.\n");
2271
2272 /* 2g */
2273 res = adxl345_set_range(&gs_handle, ADXL345_RANGE_2G);
2274 if (res != 0)
2275 {
2276 adxl345_interface_debug_print("adxl345: set range failed.\n");
2277 (void)adxl345_deinit(&gs_handle);
2278
2279 return 1;
2280 }
2281 adxl345_interface_debug_print("adxl345: set range 2g.\n");
2282 res = adxl345_get_range(&gs_handle, &range);
2283 if (res != 0)
2284 {
2285 adxl345_interface_debug_print("adxl345: get range failed.\n");
2286 (void)adxl345_deinit(&gs_handle);
2287
2288 return 1;
2289 }
2290 adxl345_interface_debug_print("adxl345: check range %s.\n", range==ADXL345_RANGE_2G?"ok":"error");
2291
2292 /* 4g */
2293 res = adxl345_set_range(&gs_handle, ADXL345_RANGE_4G);
2294 if (res != 0)
2295 {
2296 adxl345_interface_debug_print("adxl345: set range failed.\n");
2297 (void)adxl345_deinit(&gs_handle);
2298
2299 return 1;
2300 }
2301 adxl345_interface_debug_print("adxl345: set range 4g.\n");
2302 res = adxl345_get_range(&gs_handle, &range);
2303 if (res != 0)
2304 {
2305 adxl345_interface_debug_print("adxl345: get range failed.\n");
2306 (void)adxl345_deinit(&gs_handle);
2307
2308 return 1;
2309 }
2310 adxl345_interface_debug_print("adxl345: check range %s.\n", range==ADXL345_RANGE_4G?"ok":"error");
2311
2312 /* 8g */
2313 res = adxl345_set_range(&gs_handle, ADXL345_RANGE_8G);
2314 if (res != 0)
2315 {
2316 adxl345_interface_debug_print("adxl345: set range failed.\n");
2317 (void)adxl345_deinit(&gs_handle);
2318
2319 return 1;
2320 }
2321 adxl345_interface_debug_print("adxl345: set range 8g.\n");
2322 res = adxl345_get_range(&gs_handle, &range);
2323 if (res != 0)
2324 {
2325 adxl345_interface_debug_print("adxl345: get range failed.\n");
2326 (void)adxl345_deinit(&gs_handle);
2327
2328 return 1;
2329 }
2330 adxl345_interface_debug_print("adxl345: check range %s.\n", range==ADXL345_RANGE_8G?"ok":"error");
2331
2332 /* 16g */
2333 res = adxl345_set_range(&gs_handle, ADXL345_RANGE_16G);
2334 if (res != 0)
2335 {
2336 adxl345_interface_debug_print("adxl345: set range failed.\n");
2337 (void)adxl345_deinit(&gs_handle);
2338
2339 return 1;
2340 }
2341 adxl345_interface_debug_print("adxl345: set range 16g.\n");
2342 res = adxl345_get_range(&gs_handle, &range);
2343 if (res != 0)
2344 {
2345 adxl345_interface_debug_print("adxl345: get range failed.\n");
2346 (void)adxl345_deinit(&gs_handle);
2347
2348 return 1;
2349 }
2350 adxl345_interface_debug_print("adxl345: check range %s.\n", range==ADXL345_RANGE_16G?"ok":"error");
2351
2352 /* adxl345_set_mode/adxl345_get_mode */
2353 adxl345_interface_debug_print("adxl345: adxl345_set_mode/adxl345_get_mode test.\n");
2354
2355 /* bypass */
2356 res = adxl345_set_mode(&gs_handle, ADXL345_MODE_BYPASS);
2357 if (res != 0)
2358 {
2359 adxl345_interface_debug_print("adxl345: set mode failed.\n");
2360 (void)adxl345_deinit(&gs_handle);
2361
2362 return 1;
2363 }
2364 adxl345_interface_debug_print("adxl345: set mode bypass.\n");
2365 res = adxl345_get_mode(&gs_handle, &mode);
2366 if (res != 0)
2367 {
2368 adxl345_interface_debug_print("adxl345: get mode failed.\n");
2369 (void)adxl345_deinit(&gs_handle);
2370
2371 return 1;
2372 }
2373 adxl345_interface_debug_print("adxl345: check mode %s.\n", mode==ADXL345_MODE_BYPASS?"ok":"error");
2374
2375 /* fifo */
2376 res = adxl345_set_mode(&gs_handle, ADXL345_MODE_FIFO);
2377 if (res != 0)
2378 {
2379 adxl345_interface_debug_print("adxl345: set mode failed.\n");
2380 (void)adxl345_deinit(&gs_handle);
2381
2382 return 1;
2383 }
2384 adxl345_interface_debug_print("adxl345: set mode fifo.\n");
2385 res = adxl345_get_mode(&gs_handle, &mode);
2386 if (res != 0)
2387 {
2388 adxl345_interface_debug_print("adxl345: get mode failed.\n");
2389 (void)adxl345_deinit(&gs_handle);
2390
2391 return 1;
2392 }
2393 adxl345_interface_debug_print("adxl345: check mode %s.\n", mode==ADXL345_MODE_FIFO?"ok":"error");
2394
2395 /* stream */
2396 res = adxl345_set_mode(&gs_handle, ADXL345_MODE_STREAM);
2397 if (res != 0)
2398 {
2399 adxl345_interface_debug_print("adxl345: set mode failed.\n");
2400 (void)adxl345_deinit(&gs_handle);
2401
2402 return 1;
2403 }
2404 adxl345_interface_debug_print("adxl345: set mode stream.\n");
2405 res = adxl345_get_mode(&gs_handle, &mode);
2406 if (res != 0)
2407 {
2408 adxl345_interface_debug_print("adxl345: get mode failed.\n");
2409 (void)adxl345_deinit(&gs_handle);
2410
2411 return 1;
2412 }
2413 adxl345_interface_debug_print("adxl345: check mode %s.\n", mode==ADXL345_MODE_STREAM?"ok":"error");
2414
2415 /* trigger */
2416 res = adxl345_set_mode(&gs_handle, ADXL345_MODE_TRIGGER);
2417 if (res != 0)
2418 {
2419 adxl345_interface_debug_print("adxl345: set mode failed.\n");
2420 (void)adxl345_deinit(&gs_handle);
2421
2422 return 1;
2423 }
2424 adxl345_interface_debug_print("adxl345: set mode trigger.\n");
2425 res = adxl345_get_mode(&gs_handle, &mode);
2426 if (res != 0)
2427 {
2428 adxl345_interface_debug_print("adxl345: get mode failed.\n");
2429 (void)adxl345_deinit(&gs_handle);
2430
2431 return 1;
2432 }
2433 adxl345_interface_debug_print("adxl345: check mode %s.\n", mode==ADXL345_MODE_TRIGGER?"ok":"error");
2434
2435 /* adxl345_set_trigger_pin/adxl345_get_trigger_pin test */
2436 adxl345_interface_debug_print("adxl345: adxl345_set_trigger_pin/adxl345_get_trigger_pin test.\n");
2437
2438 /* pin1 */
2440 if (res != 0)
2441 {
2442 adxl345_interface_debug_print("adxl345: set trigger pin failed.\n");
2443 (void)adxl345_deinit(&gs_handle);
2444
2445 return 1;
2446 }
2447 adxl345_interface_debug_print("adxl345: set trigger pin 1.\n");
2448 res = adxl345_get_trigger_pin(&gs_handle, &pin);
2449 if (res != 0)
2450 {
2451 adxl345_interface_debug_print("adxl345: get trigger pin failed.\n");
2452 (void)adxl345_deinit(&gs_handle);
2453
2454 return 1;
2455 }
2456 adxl345_interface_debug_print("adxl345: check trigger pin %s.\n", pin==ADXL345_INTERRUPT_PIN1?"ok":"error");
2457
2458 /* pin2 */
2460 if (res != 0)
2461 {
2462 adxl345_interface_debug_print("adxl345: set trigger pin failed.\n");
2463 (void)adxl345_deinit(&gs_handle);
2464
2465 return 1;
2466 }
2467 adxl345_interface_debug_print("adxl345: set trigger pin 2.\n");
2468 res = adxl345_get_trigger_pin(&gs_handle, &pin);
2469 if (res != 0)
2470 {
2471 adxl345_interface_debug_print("adxl345: get trigger pin failed.\n");
2472 (void)adxl345_deinit(&gs_handle);
2473
2474 return 1;
2475 }
2476 adxl345_interface_debug_print("adxl345: check trigger pin %s.\n", pin==ADXL345_INTERRUPT_PIN2?"ok":"error");
2477
2478 /* adxl345_set_watermark/adxl345_get_watermark test */
2479 adxl345_interface_debug_print("adxl345: adxl345_set_watermark/adxl345_get_watermark test.\n");
2480 reg = rand()%32;
2481 res = adxl345_set_watermark(&gs_handle, reg);
2482 if (res != 0)
2483 {
2484 adxl345_interface_debug_print("adxl345: set watermark failed.\n");
2485 (void)adxl345_deinit(&gs_handle);
2486
2487 return 1;
2488 }
2489 adxl345_interface_debug_print("adxl345: set watermark 0x%02X.\n", reg);
2490 res = adxl345_get_watermark(&gs_handle, (uint8_t *)&check);
2491 if (res != 0)
2492 {
2493 adxl345_interface_debug_print("adxl345: get watermark failed.\n");
2494 (void)adxl345_deinit(&gs_handle);
2495
2496 return 1;
2497 }
2498 adxl345_interface_debug_print("adxl345: check watermark %s.\n", check==reg?"ok":"error");
2499
2500 /* adxl345_get_watermark_level test */
2501 adxl345_interface_debug_print("adxl345: adxl345_get_watermark_level test.\n");
2502 res = adxl345_get_watermark_level(&gs_handle, (uint8_t *)&reg);
2503 if (res != 0)
2504 {
2505 adxl345_interface_debug_print("adxl345: get watermark level failed.\n");
2506 (void)adxl345_deinit(&gs_handle);
2507
2508 return 1;
2509 }
2510 adxl345_interface_debug_print("adxl345: watermark level is 0x%02X.\n", reg);
2511
2512 /* adxl345_get_trigger_status test */
2513 adxl345_interface_debug_print("adxl345: adxl345_get_trigger_status test.\n");
2514 res = adxl345_get_trigger_status(&gs_handle, (adxl345_trigger_status_t *)&trigger);
2515 if (res != 0)
2516 {
2517 adxl345_interface_debug_print("adxl345: get trigger status failed.\n");
2518 (void)adxl345_deinit(&gs_handle);
2519
2520 return 1;
2521 }
2522 adxl345_interface_debug_print("adxl345: trigger status is 0x%02X.\n", trigger);
2523
2524 /* adxl345_set_link_activity_inactivity/adxl345_get_link_activity_inactivity test */
2525 adxl345_interface_debug_print("adxl345: adxl345_set_link_activity_inactivity/adxl345_get_link_activity_inactivity test.\n");
2526
2527 /* enable */
2529 if (res != 0)
2530 {
2531 adxl345_interface_debug_print("adxl345: set link activity inactivity failed.\n");
2532 (void)adxl345_deinit(&gs_handle);
2533
2534 return 1;
2535 }
2536 adxl345_interface_debug_print("adxl345: enable link activity inactivity.\n");
2537 res = adxl345_get_link_activity_inactivity(&gs_handle, &bool_test);
2538 if (res != 0)
2539 {
2540 adxl345_interface_debug_print("adxl345: get link activity inactivity failed.\n");
2541 (void)adxl345_deinit(&gs_handle);
2542
2543 return 1;
2544 }
2545 adxl345_interface_debug_print("adxl345: check link activity inactivity %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
2546
2547 /* disable */
2549 if (res != 0)
2550 {
2551 adxl345_interface_debug_print("adxl345: set link activity inactivity failed.\n");
2552 (void)adxl345_deinit(&gs_handle);
2553
2554 return 1;
2555 }
2556 adxl345_interface_debug_print("adxl345: disable link activity inactivity.\n");
2557 res = adxl345_get_link_activity_inactivity(&gs_handle, &bool_test);
2558 if (res != 0)
2559 {
2560 adxl345_interface_debug_print("adxl345: get link activity inactivity failed.\n");
2561 (void)adxl345_deinit(&gs_handle);
2562
2563 return 1;
2564 }
2565 adxl345_interface_debug_print("adxl345: check link activity inactivity %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
2566
2567 /* adxl345_set_auto_sleep/adxl345_get_auto_sleep test */
2568 adxl345_interface_debug_print("adxl345: adxl345_set_auto_sleep/adxl345_get_auto_sleep test.\n");
2569
2570 /* enable */
2571 res = adxl345_set_auto_sleep(&gs_handle, ADXL345_BOOL_TRUE);
2572 if (res != 0)
2573 {
2574 adxl345_interface_debug_print("adxl345: set auto sleep failed.\n");
2575 (void)adxl345_deinit(&gs_handle);
2576
2577 return 1;
2578 }
2579 adxl345_interface_debug_print("adxl345: enable auto sleep.\n");
2580 res = adxl345_get_auto_sleep(&gs_handle, &bool_test);
2581 if (res != 0)
2582 {
2583 adxl345_interface_debug_print("adxl345: get auto sleep failed.\n");
2584 (void)adxl345_deinit(&gs_handle);
2585
2586 return 1;
2587 }
2588 adxl345_interface_debug_print("adxl345: check auto sleep %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
2589
2590 /* disable */
2591 res = adxl345_set_auto_sleep(&gs_handle, ADXL345_BOOL_FALSE);
2592 if (res != 0)
2593 {
2594 adxl345_interface_debug_print("adxl345: set auto sleep failed.\n");
2595 (void)adxl345_deinit(&gs_handle);
2596
2597 return 1;
2598 }
2599 adxl345_interface_debug_print("adxl345: disable auto sleep.\n");
2600 res = adxl345_get_auto_sleep(&gs_handle, &bool_test);
2601 if (res != 0)
2602 {
2603 adxl345_interface_debug_print("adxl345: get auto sleep failed.\n");
2604 (void)adxl345_deinit(&gs_handle);
2605
2606 return 1;
2607 }
2608 adxl345_interface_debug_print("adxl345: check auto sleep %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
2609
2610 /* adxl345_set_measure/adxl345_get_measure test */
2611 adxl345_interface_debug_print("adxl345: adxl345_set_measure/adxl345_get_measure test.\n");
2612
2613 /* enable */
2614 res = adxl345_set_measure(&gs_handle, ADXL345_BOOL_TRUE);
2615 if (res != 0)
2616 {
2617 adxl345_interface_debug_print("adxl345: set measure failed.\n");
2618 (void)adxl345_deinit(&gs_handle);
2619
2620 return 1;
2621 }
2622 adxl345_interface_debug_print("adxl345: enable measure.\n");
2623 res = adxl345_get_measure(&gs_handle, &bool_test);
2624 if (res != 0)
2625 {
2626 adxl345_interface_debug_print("adxl345: get measure failed.\n");
2627 (void)adxl345_deinit(&gs_handle);
2628
2629 return 1;
2630 }
2631 adxl345_interface_debug_print("adxl345: check measure %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
2632
2633 /* disable */
2634 res = adxl345_set_measure(&gs_handle, ADXL345_BOOL_FALSE);
2635 if (res != 0)
2636 {
2637 adxl345_interface_debug_print("adxl345: set measure failed.\n");
2638 (void)adxl345_deinit(&gs_handle);
2639
2640 return 1;
2641 }
2642 adxl345_interface_debug_print("adxl345: disable measure.\n");
2643 res = adxl345_get_measure(&gs_handle, &bool_test);
2644 if (res != 0)
2645 {
2646 adxl345_interface_debug_print("adxl345: get measure failed.\n");
2647 (void)adxl345_deinit(&gs_handle);
2648
2649 return 1;
2650 }
2651 adxl345_interface_debug_print("adxl345: check measure %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
2652
2653 /* adxl345_set_sleep/adxl345_get_sleep test */
2654 adxl345_interface_debug_print("adxl345: adxl345_set_sleep/adxl345_get_sleep test.\n");
2655
2656 /* enable */
2657 res = adxl345_set_sleep(&gs_handle, ADXL345_BOOL_TRUE);
2658 if (res != 0)
2659 {
2660 adxl345_interface_debug_print("adxl345: set sleep failed.\n");
2661 (void)adxl345_deinit(&gs_handle);
2662
2663 return 1;
2664 }
2665 adxl345_interface_debug_print("adxl345: enable sleep.\n");
2666 res = adxl345_get_sleep(&gs_handle, &bool_test);
2667 if (res != 0)
2668 {
2669 adxl345_interface_debug_print("adxl345: get sleep failed.\n");
2670 (void)adxl345_deinit(&gs_handle);
2671
2672 return 1;
2673 }
2674 adxl345_interface_debug_print("adxl345: check sleep %s.\n", bool_test==ADXL345_BOOL_TRUE?"ok":"error");
2675
2676 /* disable */
2677 res = adxl345_set_sleep(&gs_handle, ADXL345_BOOL_FALSE);
2678 if (res != 0)
2679 {
2680 adxl345_interface_debug_print("adxl345: set sleep failed.\n");
2681 (void)adxl345_deinit(&gs_handle);
2682
2683 return 1;
2684 }
2685 adxl345_interface_debug_print("adxl345: disable sleep.\n");
2686 res = adxl345_get_sleep(&gs_handle, &bool_test);
2687 if (res != 0)
2688 {
2689 adxl345_interface_debug_print("adxl345: get sleep failed.\n");
2690 (void)adxl345_deinit(&gs_handle);
2691
2692 return 1;
2693 }
2694 adxl345_interface_debug_print("adxl345: check sleep %s.\n", bool_test==ADXL345_BOOL_FALSE?"ok":"error");
2695
2696 /* adxl345_set_sleep_frequency/adxl345_get_sleep_frequency test */
2697 adxl345_interface_debug_print("adxl345: adxl345_set_sleep_frequency/adxl345_get_sleep_frequency test.\n");
2698
2699 /* 8Hz */
2701 if (res != 0)
2702 {
2703 adxl345_interface_debug_print("adxl345: set sleep frequency failed.\n");
2704 (void)adxl345_deinit(&gs_handle);
2705
2706 return 1;
2707 }
2708 adxl345_interface_debug_print("adxl345: set sleep frequency 8 Hz.\n");
2709 res = adxl345_get_sleep_frequency(&gs_handle, &sleep_frequency);
2710 if (res != 0)
2711 {
2712 adxl345_interface_debug_print("adxl345: get sleep frequency failed.\n");
2713 (void)adxl345_deinit(&gs_handle);
2714
2715 return 1;
2716 }
2717 adxl345_interface_debug_print("adxl345: check sleep frequency %s.\n", sleep_frequency==ADXL345_SLEEP_FREQUENCY_8HZ?"ok":"error");
2718
2719 /* 4Hz */
2721 if (res != 0)
2722 {
2723 adxl345_interface_debug_print("adxl345: set sleep frequency failed.\n");
2724 (void)adxl345_deinit(&gs_handle);
2725
2726 return 1;
2727 }
2728 adxl345_interface_debug_print("adxl345: set sleep frequency 4 Hz.\n");
2729 res = adxl345_get_sleep_frequency(&gs_handle, &sleep_frequency);
2730 if (res != 0)
2731 {
2732 adxl345_interface_debug_print("adxl345: get sleep frequency failed.\n");
2733 (void)adxl345_deinit(&gs_handle);
2734
2735 return 1;
2736 }
2737 adxl345_interface_debug_print("adxl345: check sleep frequency %s.\n", sleep_frequency==ADXL345_SLEEP_FREQUENCY_4HZ?"ok":"error");
2738
2739 /* 2Hz */
2741 if (res != 0)
2742 {
2743 adxl345_interface_debug_print("adxl345: set sleep frequency failed.\n");
2744 (void)adxl345_deinit(&gs_handle);
2745
2746 return 1;
2747 }
2748 adxl345_interface_debug_print("adxl345: set sleep frequency 2 Hz.\n");
2749 res = adxl345_get_sleep_frequency(&gs_handle, &sleep_frequency);
2750 if (res != 0)
2751 {
2752 adxl345_interface_debug_print("adxl345: get sleep frequency failed.\n");
2753 (void)adxl345_deinit(&gs_handle);
2754
2755 return 1;
2756 }
2757 adxl345_interface_debug_print("adxl345: check sleep frequency %s.\n", sleep_frequency==ADXL345_SLEEP_FREQUENCY_2HZ?"ok":"error");
2758
2759 /* 1Hz */
2761 if (res != 0)
2762 {
2763 adxl345_interface_debug_print("adxl345: set sleep frequency failed.\n");
2764 (void)adxl345_deinit(&gs_handle);
2765
2766 return 1;
2767 }
2768 adxl345_interface_debug_print("adxl345: set sleep frequency 1 Hz.\n");
2769 res = adxl345_get_sleep_frequency(&gs_handle, &sleep_frequency);
2770 if (res != 0)
2771 {
2772 adxl345_interface_debug_print("adxl345: get sleep frequency failed.\n");
2773 (void)adxl345_deinit(&gs_handle);
2774
2775 return 1;
2776 }
2777 adxl345_interface_debug_print("adxl345: check sleep frequency %s.\n", sleep_frequency==ADXL345_SLEEP_FREQUENCY_1HZ?"ok":"error");
2778
2779 /* adxl345_tap_threshold_convert_to_register/adxl345_tap_threshold_convert_to_data test */
2780 adxl345_interface_debug_print("adxl345: adxl345_tap_threshold_convert_to_register/adxl345_tap_threshold_convert_to_data test.\n");
2781 f = (rand()%800)/100.0f;
2782 res = adxl345_tap_threshold_convert_to_register(&gs_handle, f, (uint8_t *)&reg);
2783 if (res != 0)
2784 {
2785 adxl345_interface_debug_print("adxl345: tap threshold convert to register failed.\n");
2786 (void)adxl345_deinit(&gs_handle);
2787
2788 return 1;
2789 }
2790 res = adxl345_tap_threshold_convert_to_data(&gs_handle, reg, (float *)&f_check);
2791 if (res != 0)
2792 {
2793 adxl345_interface_debug_print("adxl345: tap threshold convert to data failed.\n");
2794 (void)adxl345_deinit(&gs_handle);
2795
2796 return 1;
2797 }
2798 adxl345_interface_debug_print("adxl345: tap threshold before is %.4f.\n", f);
2799 adxl345_interface_debug_print("adxl345: tap threshold register is 0x%02X.\n", reg);
2800 adxl345_interface_debug_print("adxl345: tap threshold convert is %.4f.\n", f_check);
2801
2802 /* adxl345_offset_convert_to_register/adxl345_offset_convert_to_data test */
2803 adxl345_interface_debug_print("adxl345: adxl345_offset_convert_to_register/adxl345_offset_convert_to_data test.\n");
2804 f = (rand()%100)/100.0f;
2805 res = adxl345_offset_convert_to_register(&gs_handle, f, (int8_t *)&i_reg);
2806 if (res != 0)
2807 {
2808 adxl345_interface_debug_print("adxl345: offset convert to register failed.\n");
2809 (void)adxl345_deinit(&gs_handle);
2810
2811 return 1;
2812 }
2813 res = adxl345_offset_convert_to_data(&gs_handle, i_reg, (float *)&f_check);
2814 if (res != 0)
2815 {
2816 adxl345_interface_debug_print("adxl345: offset convert to data failed.\n");
2817 (void)adxl345_deinit(&gs_handle);
2818
2819 return 1;
2820 }
2821 adxl345_interface_debug_print("adxl345: offset before is %.4f.\n", f);
2822 adxl345_interface_debug_print("adxl345: offset register is 0x%02X.\n", i_reg);
2823 adxl345_interface_debug_print("adxl345: offset convert is %.4f.\n", f_check);
2824
2825 /* adxl345_duration_convert_to_register/adxl345_duration_convert_to_data test */
2826 adxl345_interface_debug_print("adxl345: adxl345_duration_convert_to_register/adxl345_duration_convert_to_data test.\n");
2827 us = (rand()%10)*625;
2828 res = adxl345_duration_convert_to_register(&gs_handle, us, (uint8_t *)&reg);
2829 if (res != 0)
2830 {
2831 adxl345_interface_debug_print("adxl345: duration convert to register failed.\n");
2832 (void)adxl345_deinit(&gs_handle);
2833
2834 return 1;
2835 }
2836 res = adxl345_duration_convert_to_data(&gs_handle, reg, (uint32_t *)&us_check);
2837 if (res != 0)
2838 {
2839 adxl345_interface_debug_print("adxl345: duration convert to data failed.\n");
2840 (void)adxl345_deinit(&gs_handle);
2841
2842 return 1;
2843 }
2844 adxl345_interface_debug_print("adxl345: duration before is %d.\n", us);
2845 adxl345_interface_debug_print("adxl345: duration register is 0x%02X.\n", reg);
2846 adxl345_interface_debug_print("adxl345: duration convert is %d.\n", us_check);
2847
2848 /* adxl345_latent_convert_to_register/adxl345_latent_convert_to_data test */
2849 adxl345_interface_debug_print("adxl345: adxl345_latent_convert_to_register/adxl345_latent_convert_to_data test.\n");
2850 f = (rand()%800)/10.0f;
2851 res = adxl345_latent_convert_to_register(&gs_handle, f, (uint8_t *)&reg);
2852 if (res != 0)
2853 {
2854 adxl345_interface_debug_print("adxl345: latent convert to register failed.\n");
2855 (void)adxl345_deinit(&gs_handle);
2856
2857 return 1;
2858 }
2859 res = adxl345_latent_convert_to_data(&gs_handle, reg, (float *)&f_check);
2860 if (res != 0)
2861 {
2862 adxl345_interface_debug_print("adxl345: latent convert to data failed.\n");
2863 (void)adxl345_deinit(&gs_handle);
2864
2865 return 1;
2866 }
2867 adxl345_interface_debug_print("adxl345: latent before is %.4f.\n", f);
2868 adxl345_interface_debug_print("adxl345: latent register is 0x%02X.\n", reg);
2869 adxl345_interface_debug_print("adxl345: latent convert is %.4f.\n", f_check);
2870
2871 /* adxl345_window_convert_to_register/adxl345_window_convert_to_data test */
2872 adxl345_interface_debug_print("adxl345: adxl345_window_convert_to_register/adxl345_window_convert_to_data test.\n");
2873 f = (rand()%800)/100.0f;
2874 res = adxl345_window_convert_to_register(&gs_handle, f, (uint8_t *)&reg);
2875 if (res != 0)
2876 {
2877 adxl345_interface_debug_print("adxl345: window convert to register failed.\n");
2878 (void)adxl345_deinit(&gs_handle);
2879
2880 return 1;
2881 }
2882 res = adxl345_window_convert_to_data(&gs_handle, reg, (float *)&f_check);
2883 if (res != 0)
2884 {
2885 adxl345_interface_debug_print("adxl345: window convert to data failed.\n");
2886 (void)adxl345_deinit(&gs_handle);
2887
2888 return 1;
2889 }
2890 adxl345_interface_debug_print("adxl345: window before is %.4f.\n", f);
2891 adxl345_interface_debug_print("adxl345: window register is 0x%02X.\n", reg);
2892 adxl345_interface_debug_print("adxl345: window convert is %.4f.\n", f_check);
2893
2894 /* adxl345_action_threshold_convert_to_register/adxl345_action_threshold_convert_to_data test */
2895 adxl345_interface_debug_print("adxl345: adxl345_action_threshold_convert_to_register/adxl345_action_threshold_convert_to_data test.\n");
2896 f = (rand()%800)/100.0f;
2897 res = adxl345_action_threshold_convert_to_register(&gs_handle, f, (uint8_t *)&reg);
2898 if (res != 0)
2899 {
2900 adxl345_interface_debug_print("adxl345: action threshold convert to register failed.\n");
2901 (void)adxl345_deinit(&gs_handle);
2902
2903 return 1;
2904 }
2905 res = adxl345_action_threshold_convert_to_data(&gs_handle, reg, (float *)&f_check);
2906 if (res != 0)
2907 {
2908 adxl345_interface_debug_print("adxl345: action threshold convert to data failed.\n");
2909 (void)adxl345_deinit(&gs_handle);
2910
2911 return 1;
2912 }
2913 adxl345_interface_debug_print("adxl345: action threshold before is %.4f.\n", f);
2914 adxl345_interface_debug_print("adxl345: action threshold register is 0x%02X.\n", reg);
2915 adxl345_interface_debug_print("adxl345: action threshold convert is %.4f.\n", f_check);
2916
2917 /* adxl345_inaction_threshold_convert_to_register/adxl345_inaction_threshold_convert_to_data test */
2918 adxl345_interface_debug_print("adxl345: adxl345_inaction_threshold_convert_to_register/adxl345_inaction_threshold_convert_to_data test.\n");
2919 f = (rand()%800)/100.0f;
2920 res = adxl345_inaction_threshold_convert_to_register(&gs_handle, f, (uint8_t *)&reg);
2921 if (res != 0)
2922 {
2923 adxl345_interface_debug_print("adxl345: inaction threshold convert to register failed.\n");
2924 (void)adxl345_deinit(&gs_handle);
2925
2926 return 1;
2927 }
2928 res = adxl345_inaction_threshold_convert_to_data(&gs_handle, reg, (float *)&f_check);
2929 if (res != 0)
2930 {
2931 adxl345_interface_debug_print("adxl345: inaction threshold convert to data failed.\n");
2932 (void)adxl345_deinit(&gs_handle);
2933
2934 return 1;
2935 }
2936 adxl345_interface_debug_print("adxl345: inaction threshold before is %.4f.\n", f);
2937 adxl345_interface_debug_print("adxl345: inaction threshold register is 0x%02X.\n", reg);
2938 adxl345_interface_debug_print("adxl345: inaction threshold convert is %.4f.\n", f_check);
2939
2940 /* adxl345_inaction_time_convert_to_register/adxl345_inaction_time_convert_to_data test */
2941 adxl345_interface_debug_print("adxl345: adxl345_inaction_time_convert_to_register/adxl345_inaction_time_convert_to_data test.\n");
2942 check = rand()%256;
2943 res = adxl345_inaction_time_convert_to_register(&gs_handle, check, (uint8_t *)&reg);
2944 if (res != 0)
2945 {
2946 adxl345_interface_debug_print("adxl345: inaction time convert to register failed.\n");
2947 (void)adxl345_deinit(&gs_handle);
2948
2949 return 1;
2950 }
2951 res = adxl345_inaction_time_convert_to_data(&gs_handle, reg, (uint8_t *)&check);
2952 if (res != 0)
2953 {
2954 adxl345_interface_debug_print("adxl345: inaction time convert to data failed.\n");
2955 (void)adxl345_deinit(&gs_handle);
2956
2957 return 1;
2958 }
2959 adxl345_interface_debug_print("adxl345: inaction time before is 0x%02X.\n", check);
2960 adxl345_interface_debug_print("adxl345: inaction time register is 0x%02X.\n", reg);
2961 adxl345_interface_debug_print("adxl345: inaction time convert is 0x%02X.\n", check);
2962
2963 /* adxl345_free_fall_threshold_convert_to_register/adxl345_free_fall_threshold_convert_to_data test */
2964 adxl345_interface_debug_print("adxl345: adxl345_free_fall_threshold_convert_to_register/adxl345_free_fall_threshold_convert_to_data test.\n");
2965 f = (rand()%800)/100.0f;
2966 res = adxl345_free_fall_threshold_convert_to_register(&gs_handle, f, (uint8_t *)&reg);
2967 if (res != 0)
2968 {
2969 adxl345_interface_debug_print("adxl345: free fall threshold convert to register failed.\n");
2970 (void)adxl345_deinit(&gs_handle);
2971
2972 return 1;
2973 }
2974 res = adxl345_free_fall_threshold_convert_to_data(&gs_handle, reg, (float *)&f_check);
2975 if (res != 0)
2976 {
2977 adxl345_interface_debug_print("adxl345: free fall threshold convert to data failed.\n");
2978 (void)adxl345_deinit(&gs_handle);
2979
2980 return 1;
2981 }
2982 adxl345_interface_debug_print("adxl345: free fall threshold before is %.4f.\n", f);
2983 adxl345_interface_debug_print("adxl345: free fall threshold register is 0x%02X.\n", reg);
2984 adxl345_interface_debug_print("adxl345: free fall threshold convert is %.4f.\n", f_check);
2985
2986 /* adxl345_free_fall_time_convert_to_register/adxl345_free_fall_time_convert_to_data test */
2987 adxl345_interface_debug_print("adxl345: adxl345_free_fall_time_convert_to_register/adxl345_free_fall_time_convert_to_data test.\n");
2988 ms = rand()%800;
2989 res = adxl345_free_fall_time_convert_to_register(&gs_handle, ms, (uint8_t *)&reg);
2990 if (res != 0)
2991 {
2992 adxl345_interface_debug_print("adxl345: free fall time convert to register failed.\n");
2993 (void)adxl345_deinit(&gs_handle);
2994
2995 return 1;
2996 }
2997 res = adxl345_free_fall_time_convert_to_data(&gs_handle, reg, (uint16_t *)&ms_check);
2998 if (res != 0)
2999 {
3000 adxl345_interface_debug_print("adxl345: free fall time convert to data failed.\n");
3001 (void)adxl345_deinit(&gs_handle);
3002
3003 return 1;
3004 }
3005 adxl345_interface_debug_print("adxl345: free time threshold before is %d.\n", ms);
3006 adxl345_interface_debug_print("adxl345: free time threshold register is 0x%02X.\n", reg);
3007 adxl345_interface_debug_print("adxl345: free time threshold convert is %d.\n", ms_check);
3008
3009 /* finish register test */
3010 adxl345_interface_debug_print("adxl345: finish register test.\n");
3011 (void)adxl345_deinit(&gs_handle);
3012
3013 return 0;
3014}
driver adxl345 register test header file
adxl345_interface_t
adxl345 interface enumeration definition
uint8_t adxl345_inaction_time_convert_to_register(adxl345_handle_t *handle, uint8_t s, uint8_t *reg)
convert the inaction time to the register raw data
uint8_t adxl345_get_justify(adxl345_handle_t *handle, adxl345_justify_t *enable)
get the justify status
uint8_t adxl345_get_action_coupled(adxl345_handle_t *handle, adxl345_coupled_t *coupled)
get the action coupled
uint8_t adxl345_get_link_activity_inactivity(adxl345_handle_t *handle, adxl345_bool_t *enable)
get the activity and inactivity linking status
uint8_t adxl345_duration_convert_to_register(adxl345_handle_t *handle, uint32_t us, uint8_t *reg)
convert the duration to the register raw data
struct adxl345_info_s adxl345_info_t
adxl345 information structure definition
uint8_t adxl345_inaction_threshold_convert_to_register(adxl345_handle_t *handle, float g, uint8_t *reg)
convert the inaction threshold to the register raw data
uint8_t adxl345_get_auto_sleep(adxl345_handle_t *handle, adxl345_bool_t *enable)
get the auto sleep status
uint8_t adxl345_set_full_resolution(adxl345_handle_t *handle, adxl345_bool_t enable)
enable or disable the full resolution
uint8_t adxl345_set_inaction_time(adxl345_handle_t *handle, uint8_t t)
set the inaction time
uint8_t adxl345_duration_convert_to_data(adxl345_handle_t *handle, uint8_t reg, uint32_t *us)
convert the register raw data to the duration
adxl345_justify_t
adxl345 justify enumeration definition
uint8_t adxl345_get_tap_threshold(adxl345_handle_t *handle, uint8_t *threshold)
get the tap threshold
uint8_t adxl345_deinit(adxl345_handle_t *handle)
close the chip
uint8_t adxl345_set_inaction_coupled(adxl345_handle_t *handle, adxl345_coupled_t coupled)
set the inaction coupled
uint8_t adxl345_get_tap_axis(adxl345_handle_t *handle, adxl345_tap_axis_t axis, adxl345_bool_t *enable)
get the tap axis status
uint8_t adxl345_get_trigger_pin(adxl345_handle_t *handle, adxl345_interrupt_pin_t *pin)
get the trigger pin
uint8_t adxl345_inaction_threshold_convert_to_data(adxl345_handle_t *handle, uint8_t reg, float *g)
convert the register raw data to the inaction threshold
uint8_t adxl345_set_measure(adxl345_handle_t *handle, adxl345_bool_t enable)
enable or disable the measure
uint8_t adxl345_set_trigger_pin(adxl345_handle_t *handle, adxl345_interrupt_pin_t pin)
set the trigger pin
uint8_t adxl345_get_full_resolution(adxl345_handle_t *handle, adxl345_bool_t *enable)
get the full resolution status
uint8_t adxl345_set_link_activity_inactivity(adxl345_handle_t *handle, adxl345_bool_t enable)
enable or disable the activity and inactivity linking
uint8_t adxl345_get_free_fall_time(adxl345_handle_t *handle, uint8_t *t)
get the free fall time
uint8_t adxl345_free_fall_time_convert_to_data(adxl345_handle_t *handle, uint8_t reg, uint16_t *ms)
convert the register raw data to the free fall time
uint8_t adxl345_get_sleep_frequency(adxl345_handle_t *handle, adxl345_sleep_frequency_t *sleep_frequency)
get the sleep frequency
uint8_t adxl345_get_sleep(adxl345_handle_t *handle, adxl345_bool_t *enable)
get the sleep mode status
uint8_t adxl345_get_mode(adxl345_handle_t *handle, adxl345_mode_t *mode)
get the chip mode
uint8_t adxl345_set_action_threshold(adxl345_handle_t *handle, uint8_t threshold)
set the action threshold
uint8_t adxl345_get_offset(adxl345_handle_t *handle, int8_t *x, int8_t *y, int8_t *z)
get the axis offset
uint8_t adxl345_get_free_fall_threshold(adxl345_handle_t *handle, uint8_t *threshold)
get the free fall threshold
uint8_t adxl345_set_free_fall_threshold(adxl345_handle_t *handle, uint8_t threshold)
set the free fall threshold
uint8_t adxl345_set_sleep(adxl345_handle_t *handle, adxl345_bool_t enable)
enable or disable the sleep mode
uint8_t adxl345_get_interface(adxl345_handle_t *handle, adxl345_interface_t *interface)
get the chip interface
uint8_t adxl345_get_window(adxl345_handle_t *handle, uint8_t *t)
get the window
adxl345_trigger_status_t
adxl345 trigger status enumeration definition
uint8_t adxl345_get_duration(adxl345_handle_t *handle, uint8_t *t)
get the duration
uint8_t adxl345_action_threshold_convert_to_data(adxl345_handle_t *handle, uint8_t reg, float *g)
convert the register raw data to the action threshold
uint8_t adxl345_get_latent(adxl345_handle_t *handle, uint8_t *t)
get the latent
uint8_t adxl345_set_offset(adxl345_handle_t *handle, int8_t x, int8_t y, int8_t z)
set the axis offset
uint8_t adxl345_set_latent(adxl345_handle_t *handle, uint8_t t)
set the latent
uint8_t adxl345_set_rate(adxl345_handle_t *handle, adxl345_rate_t rate)
set the sampling rate
uint8_t adxl345_set_inaction_threshold(adxl345_handle_t *handle, uint8_t threshold)
set the inaction threshold
uint8_t adxl345_get_inaction_time(adxl345_handle_t *handle, uint8_t *t)
get the inaction time
uint8_t adxl345_set_addr_pin(adxl345_handle_t *handle, adxl345_address_t addr_pin)
set the iic address pin
uint8_t adxl345_get_range(adxl345_handle_t *handle, adxl345_range_t *range)
get the chip range
uint8_t adxl345_set_self_test(adxl345_handle_t *handle, adxl345_bool_t enable)
enable or disable the self test
uint8_t adxl345_tap_threshold_convert_to_data(adxl345_handle_t *handle, uint8_t reg, float *g)
convert the register raw data to the tap threshold
uint8_t adxl345_free_fall_time_convert_to_register(adxl345_handle_t *handle, uint16_t ms, uint8_t *reg)
convert the free fall time to the register raw data
uint8_t adxl345_get_measure(adxl345_handle_t *handle, adxl345_bool_t *enable)
get the measure status
adxl345_range_t
adxl345 range enumeration definition
uint8_t adxl345_get_action_inaction(adxl345_handle_t *handle, adxl345_action_inaction_t type, adxl345_bool_t *enable)
get the action or inaction status
uint8_t adxl345_get_rate(adxl345_handle_t *handle, adxl345_rate_t *rate)
get the sampling rate
uint8_t adxl345_set_action_inaction(adxl345_handle_t *handle, adxl345_action_inaction_t type, adxl345_bool_t enable)
enable or disable the action or inaction
uint8_t adxl345_free_fall_threshold_convert_to_register(adxl345_handle_t *handle, float g, uint8_t *reg)
convert the free fall threshold to the register raw data
uint8_t adxl345_window_convert_to_register(adxl345_handle_t *handle, float ms, uint8_t *reg)
convert the window time to the register raw data
uint8_t adxl345_get_trigger_status(adxl345_handle_t *handle, adxl345_trigger_status_t *status)
get the trigger status
uint8_t adxl345_set_duration(adxl345_handle_t *handle, uint8_t t)
set the duration
uint8_t adxl345_tap_threshold_convert_to_register(adxl345_handle_t *handle, float g, uint8_t *reg)
convert the tap threshold to the register raw data
uint8_t adxl345_set_tap_suppress(adxl345_handle_t *handle, adxl345_bool_t enable)
enable or disable the tap suppress
uint8_t adxl345_set_auto_sleep(adxl345_handle_t *handle, adxl345_bool_t enable)
enable or disable the auto sleep
uint8_t adxl345_get_addr_pin(adxl345_handle_t *handle, adxl345_address_t *addr_pin)
get the iic address pin
uint8_t adxl345_set_tap_axis(adxl345_handle_t *handle, adxl345_tap_axis_t axis, adxl345_bool_t enable)
enable or disable the tap axis
adxl345_rate_t
adxl345 rate enumeration definition
uint8_t adxl345_set_free_fall_time(adxl345_handle_t *handle, uint8_t t)
set the free fall time
uint8_t adxl345_get_inaction_coupled(adxl345_handle_t *handle, adxl345_coupled_t *coupled)
get the inaction coupled
uint8_t adxl345_set_window(adxl345_handle_t *handle, uint8_t t)
set the window
uint8_t adxl345_action_threshold_convert_to_register(adxl345_handle_t *handle, float g, uint8_t *reg)
convert the action threshold to the register raw data
uint8_t adxl345_set_sleep_frequency(adxl345_handle_t *handle, adxl345_sleep_frequency_t sleep_frequency)
set the sleep frequency
adxl345_address_t
adxl345 address enumeration definition
uint8_t adxl345_latent_convert_to_register(adxl345_handle_t *handle, float ms, uint8_t *reg)
convert the latent to the register raw data
uint8_t adxl345_offset_convert_to_register(adxl345_handle_t *handle, float g, int8_t *reg)
convert the offset to the register raw data
uint8_t adxl345_init(adxl345_handle_t *handle)
initialize the chip
struct adxl345_handle_s adxl345_handle_t
adxl345 handle structure definition
adxl345_coupled_t
adxl345 coupled enumeration definition
uint8_t adxl345_inaction_time_convert_to_data(adxl345_handle_t *handle, uint8_t reg, uint8_t *s)
convert the register raw data to the inaction time
uint8_t adxl345_window_convert_to_data(adxl345_handle_t *handle, uint8_t reg, float *ms)
convert the register raw data to the window time
uint8_t adxl345_set_action_coupled(adxl345_handle_t *handle, adxl345_coupled_t coupled)
set the action coupled
adxl345_bool_t
adxl345 bool enumeration definition
uint8_t adxl345_get_inaction_threshold(adxl345_handle_t *handle, uint8_t *threshold)
get the inaction threshold
uint8_t adxl345_get_tap_status(adxl345_handle_t *handle, uint8_t *status)
get the tap status
uint8_t adxl345_get_self_test(adxl345_handle_t *handle, adxl345_bool_t *enable)
get the self test status
uint8_t adxl345_set_justify(adxl345_handle_t *handle, adxl345_justify_t enable)
enable or disable the justify
uint8_t adxl345_set_interface(adxl345_handle_t *handle, adxl345_interface_t interface)
set the chip interface
uint8_t adxl345_get_action_threshold(adxl345_handle_t *handle, uint8_t *threshold)
get the action threshold
uint8_t adxl345_set_mode(adxl345_handle_t *handle, adxl345_mode_t mode)
set the chip mode
uint8_t adxl345_latent_convert_to_data(adxl345_handle_t *handle, uint8_t reg, float *ms)
convert the register raw data to the latent
uint8_t adxl345_get_tap_suppress(adxl345_handle_t *handle, adxl345_bool_t *enable)
get the tap suppress status
adxl345_sleep_frequency_t
adxl345 sleep frequency enumeration definition
uint8_t adxl345_offset_convert_to_data(adxl345_handle_t *handle, int8_t reg, float *g)
convert the register raw data to the offset
adxl345_mode_t
adxl345 mode enumeration definition
uint8_t adxl345_info(adxl345_info_t *info)
get chip's information
uint8_t adxl345_set_tap_threshold(adxl345_handle_t *handle, uint8_t threshold)
set the tap threshold
uint8_t adxl345_set_range(adxl345_handle_t *handle, adxl345_range_t range)
set the chip range
uint8_t adxl345_free_fall_threshold_convert_to_data(adxl345_handle_t *handle, uint8_t reg, float *g)
convert the register raw data to the free fall threshold
@ ADXL345_INTERFACE_SPI
@ ADXL345_INTERFACE_IIC
@ ADXL345_JUSTIFY_LEFT
@ ADXL345_JUSTIFY_RIGHT
@ ADXL345_ACTION_Z
@ ADXL345_INACTION_Z
@ ADXL345_INACTION_X
@ ADXL345_INACTION_Y
@ ADXL345_ACTION_X
@ ADXL345_ACTION_Y
@ ADXL345_RANGE_8G
@ ADXL345_RANGE_2G
@ ADXL345_RANGE_16G
@ ADXL345_RANGE_4G
@ ADXL345_RATE_800
@ ADXL345_RATE_6P25
@ ADXL345_RATE_1P56
@ ADXL345_RATE_1600
@ ADXL345_LOW_POWER_RATE_200
@ ADXL345_RATE_3200
@ ADXL345_RATE_50
@ ADXL345_RATE_0P2
@ ADXL345_RATE_100
@ ADXL345_RATE_3P13
@ ADXL345_RATE_200
@ ADXL345_RATE_400
@ ADXL345_RATE_0P1
@ ADXL345_RATE_0P78
@ ADXL345_LOW_POWER_RATE_12P5
@ ADXL345_RATE_0P39
@ ADXL345_LOW_POWER_RATE_100
@ ADXL345_RATE_12P5
@ ADXL345_LOW_POWER_RATE_50
@ ADXL345_LOW_POWER_RATE_400
@ ADXL345_RATE_25
@ ADXL345_LOW_POWER_RATE_25
@ ADXL345_ADDRESS_ALT_1
@ ADXL345_ADDRESS_ALT_0
@ ADXL345_TAP_AXIS_Z
@ ADXL345_TAP_AXIS_Y
@ ADXL345_TAP_AXIS_X
@ ADXL345_COUPLED_DC
@ ADXL345_COUPLED_AC
@ ADXL345_BOOL_FALSE
@ ADXL345_BOOL_TRUE
@ ADXL345_SLEEP_FREQUENCY_2HZ
@ ADXL345_SLEEP_FREQUENCY_4HZ
@ ADXL345_SLEEP_FREQUENCY_8HZ
@ ADXL345_SLEEP_FREQUENCY_1HZ
@ ADXL345_MODE_BYPASS
@ ADXL345_MODE_FIFO
@ ADXL345_MODE_STREAM
@ ADXL345_MODE_TRIGGER
uint8_t adxl345_get_watermark(adxl345_handle_t *handle, uint8_t *level)
get the fifo watermark
uint8_t adxl345_get_watermark_level(adxl345_handle_t *handle, uint8_t *level)
get the current fifo watermark level
uint8_t adxl345_set_watermark(adxl345_handle_t *handle, uint8_t level)
set the fifo watermark
uint8_t adxl345_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t adxl345_interface_spi_deinit(void)
interface spi bus deinit
uint8_t adxl345_interface_iic_deinit(void)
interface iic bus deinit
uint8_t adxl345_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
void adxl345_interface_receive_callback(uint8_t type)
interface receive callback
uint8_t adxl345_interface_iic_init(void)
interface iic bus init
uint8_t adxl345_interface_spi_init(void)
interface spi bus init
uint8_t adxl345_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void adxl345_interface_delay_ms(uint32_t ms)
interface delay ms
void adxl345_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t adxl345_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
adxl345_interrupt_active_level_t
adxl345 interrupt active_level enumeration definition
adxl345_interrupt_pin_t
adxl345 interrupt pin enumeration definition
uint8_t adxl345_get_interrupt_source(adxl345_handle_t *handle, uint8_t *source)
get the interrupt source
uint8_t adxl345_get_interrupt_active_level(adxl345_handle_t *handle, adxl345_interrupt_active_level_t *active_level)
get the interrupt active level
uint8_t adxl345_set_interrupt(adxl345_handle_t *handle, adxl345_interrupt_t type, adxl345_bool_t enable)
enable or disable the interrupt
uint8_t adxl345_get_interrupt(adxl345_handle_t *handle, adxl345_interrupt_t type, adxl345_bool_t *enable)
get the interrupt status
uint8_t adxl345_set_interrupt_map(adxl345_handle_t *handle, adxl345_interrupt_t type, adxl345_interrupt_pin_t pin)
set the interrupt map
uint8_t adxl345_set_interrupt_active_level(adxl345_handle_t *handle, adxl345_interrupt_active_level_t active_level)
set the interrupt active level
uint8_t adxl345_get_interrupt_map(adxl345_handle_t *handle, adxl345_interrupt_t type, adxl345_interrupt_pin_t *pin)
get the interrupt map
@ ADXL345_INTERRUPT_ACTIVE_LEVEL_HIGH
@ ADXL345_INTERRUPT_ACTIVE_LEVEL_LOW
@ ADXL345_INTERRUPT_PIN2
@ ADXL345_INTERRUPT_PIN1
@ ADXL345_INTERRUPT_DATA_READY
@ ADXL345_INTERRUPT_DOUBLE_TAP
@ ADXL345_INTERRUPT_ACTIVITY
@ ADXL345_INTERRUPT_SINGLE_TAP
@ ADXL345_INTERRUPT_INACTIVITY
@ ADXL345_INTERRUPT_WATERMARK
@ ADXL345_INTERRUPT_OVERRUN
@ ADXL345_INTERRUPT_FREE_FALL
uint8_t adxl345_register_test(adxl345_interface_t interface, adxl345_address_t addr_pin)
register test
uint32_t driver_version
char manufacturer_name[32]