LibDriver ADXL345  2.0.0
ADXL345 full-featured driver
driver_adxl345_interrupt.c
Go to the documentation of this file.
1 
39 
40 static adxl345_handle_t gs_handle;
41 static void (*a_callback)(uint8_t type) = NULL;
51 {
52  if (adxl345_irq_handler(&gs_handle) != 0)
53  {
54  return 1;
55  }
56  else
57  {
58  return 0;
59  }
60 }
61 
67 static void a_adxl345_interrupt_receive_callback(uint8_t type)
68 {
69  switch (type)
70  {
72  {
73  if (a_callback != NULL)
74  {
75  a_callback(ADXL345_INTERRUPT_DATA_READY);
76  }
77 
78  break;
79  }
81  {
82  if (a_callback != NULL)
83  {
84  a_callback(ADXL345_INTERRUPT_SINGLE_TAP);
85  }
86 
87  break;
88  }
90  {
91  if (a_callback != NULL)
92  {
93  a_callback(ADXL345_INTERRUPT_DOUBLE_TAP);
94  }
95 
96  break;
97  }
99  {
100  if (a_callback != NULL)
101  {
102  a_callback(ADXL345_INTERRUPT_ACTIVITY);
103  }
104 
105  break;
106  }
108  {
109  if (a_callback != NULL)
110  {
111  a_callback(ADXL345_INTERRUPT_INACTIVITY);
112  }
113 
114  break;
115  }
117  {
118  if (a_callback != NULL)
119  {
120  a_callback(ADXL345_INTERRUPT_FREE_FALL);
121  }
122 
123  break;
124  }
125  default :
126  {
127  break;
128  }
129  }
130 }
131 
147  void (*callback)(uint8_t type),
148  adxl345_bool_t tap_enable, adxl345_bool_t action_enable,
149  adxl345_bool_t inaction_enable, adxl345_bool_t fall_enable)
150 {
151  uint8_t res;
152  uint8_t source;
153  int8_t reg;
154 
155  /* link interface function */
167  DRIVER_ADXL345_LINK_RECEIVE_CALLBACK(&gs_handle, a_adxl345_interrupt_receive_callback);
168 
169  /* set the interface */
170  res = adxl345_set_interface(&gs_handle, interface);
171  if (res != 0)
172  {
173  adxl345_interface_debug_print("adxl345: set interface failed.\n");
174 
175  return 1;
176  }
177 
178  /* set addr pin */
179  res = adxl345_set_addr_pin(&gs_handle, addr_pin);
180  if (res != 0)
181  {
182  adxl345_interface_debug_print("adxl345: set addr pin failed.\n");
183 
184  return 1;
185  }
186 
187  /* adxl345 initialization */
188  res = adxl345_init(&gs_handle);
189  if (res != 0)
190  {
191  adxl345_interface_debug_print("adxl345: init failed.\n");
192 
193  return 1;
194  }
195 
196  /* set default rate */
198  if (res != 0)
199  {
200  adxl345_interface_debug_print("adxl345: set rate failed.\n");
201  (void)adxl345_deinit(&gs_handle);
202 
203  return 1;
204  }
205 
206  /* set default spi wire */
208  if (res != 0)
209  {
210  adxl345_interface_debug_print("adxl345: set spi wire failed.\n");
211  (void)adxl345_deinit(&gs_handle);
212 
213  return 1;
214  }
215 
216  /* set interrupt pin */
218  if (res != 0)
219  {
220  adxl345_interface_debug_print("adxl345: set adxl345 set interrupt active level failed.\n");
221  (void)adxl345_deinit(&gs_handle);
222 
223  return 1;
224  }
225 
226  /* set full resolution */
228  if (res != 0)
229  {
230  adxl345_interface_debug_print("adxl345: set full resolution failed.\n");
231  (void)adxl345_deinit(&gs_handle);
232 
233  return 1;
234  }
235 
236  /* set auto sleep */
238  if (res != 0)
239  {
240  adxl345_interface_debug_print("adxl345: set auto sleep failed.\n");
241  (void)adxl345_deinit(&gs_handle);
242 
243  return 1;
244  }
245 
246  /* set sleep */
248  if (res != 0)
249  {
250  adxl345_interface_debug_print("adxl345: set sleep failed.\n");
251  (void)adxl345_deinit(&gs_handle);
252 
253  return 1;
254  }
255 
256  /* set sleep frequency */
258  if (res != 0)
259  {
260  adxl345_interface_debug_print("adxl345: set sleep frequency failed.\n");
261  (void)adxl345_deinit(&gs_handle);
262 
263  return 1;
264  }
265 
266  /* set justify */
268  if (res != 0)
269  {
270  adxl345_interface_debug_print("adxl345: set justify failed.\n");
271  (void)adxl345_deinit(&gs_handle);
272 
273  return 1;
274  }
275 
276  /* set range */
278  if (res != 0)
279  {
280  adxl345_interface_debug_print("adxl345: set range failed.\n");
281  (void)adxl345_deinit(&gs_handle);
282 
283  return 1;
284  }
285 
286  /* set mode */
288  if (res != 0)
289  {
290  adxl345_interface_debug_print("adxl345: set mode failed.\n");
291  (void)adxl345_deinit(&gs_handle);
292 
293  return 1;
294  }
295 
296  /* set trigger pin */
298  if (res != 0)
299  {
300  adxl345_interface_debug_print("adxl345: set trigger pin failed.\n");
301  (void)adxl345_deinit(&gs_handle);
302 
303  return 1;
304  }
305 
306  /* set watermark level */
308  if (res != 0)
309  {
310  adxl345_interface_debug_print("adxl345: set watermark failed.\n");
311  (void)adxl345_deinit(&gs_handle);
312 
313  return 1;
314  }
315 
316  /* set default offset */
317  res = adxl345_offset_convert_to_register(&gs_handle, ADXL345_INTERRUPT_DEFAULT_OFFSET, (int8_t *)&reg);
318  if (res != 0)
319  {
320  adxl345_interface_debug_print("adxl345: offset convert to register failed.\n");
321  (void)adxl345_deinit(&gs_handle);
322 
323  return 1;
324  }
325  res = adxl345_set_offset(&gs_handle, reg, reg, reg);
326  if (res != 0)
327  {
328  adxl345_interface_debug_print("adxl345: set offset failed.\n");
329  (void)adxl345_deinit(&gs_handle);
330 
331  return 1;
332  }
333 
334  /* set default tap threshold */
336  if (res != 0)
337  {
338  adxl345_interface_debug_print("adxl345: tap threshold convert to register failed.\n");
339  (void)adxl345_deinit(&gs_handle);
340 
341  return 1;
342  }
343  res = adxl345_set_tap_threshold(&gs_handle, reg);
344  if (res != 0)
345  {
346  adxl345_interface_debug_print("adxl345: set tap threshold failed.\n");
347  (void)adxl345_deinit(&gs_handle);
348 
349  return 1;
350  }
351 
352  /* set default duration */
354  if (res != 0)
355  {
356  adxl345_interface_debug_print("adxl345: duration convert to register failed.\n");
357  (void)adxl345_deinit(&gs_handle);
358 
359  return 1;
360  }
361  res = adxl345_set_duration(&gs_handle, reg);
362  if (res != 0)
363  {
364  adxl345_interface_debug_print("adxl345: set duration failed.\n");
365  (void)adxl345_deinit(&gs_handle);
366 
367  return 1;
368  }
369 
370  /* set latent time */
371  res = adxl345_latent_convert_to_register(&gs_handle, ADXL345_INTERRUPT_DEFAULT_LATENT, (uint8_t *)&reg);
372  if (res != 0)
373  {
374  adxl345_interface_debug_print("adxl345: latent convert to register failed.\n");
375  (void)adxl345_deinit(&gs_handle);
376 
377  return 1;
378  }
379  res = adxl345_set_latent(&gs_handle, reg);
380  if (res != 0)
381  {
382  adxl345_interface_debug_print("adxl345: set latent failed.\n");
383  (void)adxl345_deinit(&gs_handle);
384 
385  return 1;
386  }
387 
388  /* set window time */
389  res = adxl345_window_convert_to_register(&gs_handle, ADXL345_INTERRUPT_DEFAULT_WINDOW, (uint8_t *)&reg);
390  if (res != 0)
391  {
392  adxl345_interface_debug_print("adxl345: window convert to register failed.\n");
393  (void)adxl345_deinit(&gs_handle);
394 
395  return 1;
396  }
397  res = adxl345_set_window(&gs_handle, reg);
398  if (res != 0)
399  {
400  adxl345_interface_debug_print("adxl345: set window failed.\n");
401  (void)adxl345_deinit(&gs_handle);
402 
403  return 1;
404  }
405 
406  /* set tap */
407  res = adxl345_set_tap_axis(&gs_handle, ADXL345_TAP_AXIS_X, tap_enable);
408  if (res != 0)
409  {
410  adxl345_interface_debug_print("adxl345: set tap axis failed.\n");
411  (void)adxl345_deinit(&gs_handle);
412 
413  return 1;
414  }
415  res = adxl345_set_tap_axis(&gs_handle, ADXL345_TAP_AXIS_Y, tap_enable);
416  if (res != 0)
417  {
418  adxl345_interface_debug_print("adxl345: set tap axis failed.\n");
419  (void)adxl345_deinit(&gs_handle);
420 
421  return 1;
422  }
423  res = adxl345_set_tap_axis(&gs_handle, ADXL345_TAP_AXIS_Z, tap_enable);
424  if (res != 0)
425  {
426  adxl345_interface_debug_print("adxl345: set tap axis failed.\n");
427  (void)adxl345_deinit(&gs_handle);
428 
429  return 1;
430  }
431 
432  /* set default suppress */
434  if (res != 0)
435  {
436  adxl345_interface_debug_print("adxl345: set tap suppress failed.\n");
437  (void)adxl345_deinit(&gs_handle);
438 
439  return 1;
440  }
441 
442  /* set default single tap map */
444  if (res != 0)
445  {
446  adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
447  (void)adxl345_deinit(&gs_handle);
448 
449  return 1;
450  }
451 
452  /* disable single tap */
453  res = adxl345_set_interrupt(&gs_handle, ADXL345_INTERRUPT_SINGLE_TAP, tap_enable);
454  if (res != 0)
455  {
456  adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
457  (void)adxl345_deinit(&gs_handle);
458 
459  return 1;
460  }
461 
462  /* set default double tap map */
464  if (res != 0)
465  {
466  adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
467  (void)adxl345_deinit(&gs_handle);
468 
469  return 1;
470  }
471 
472  /* disable single tap */
473  res = adxl345_set_interrupt(&gs_handle, ADXL345_INTERRUPT_DOUBLE_TAP, tap_enable);
474  if (res != 0)
475  {
476  adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
477  (void)adxl345_deinit(&gs_handle);
478 
479  return 1;
480  }
481 
484  if (res != 0)
485  {
486  adxl345_interface_debug_print("adxl345: set link activity inactivity failed.\n");
487  (void)adxl345_deinit(&gs_handle);
488 
489  return 1;
490  }
491 
492  /* set default action threshold */
494  if (res != 0)
495  {
496  adxl345_interface_debug_print("adxl345: action threshold convert to register failed.\n");
497  (void)adxl345_deinit(&gs_handle);
498 
499  return 1;
500  }
501  res = adxl345_set_action_threshold(&gs_handle, reg);
502  if (res != 0)
503  {
504  adxl345_interface_debug_print("adxl345: set action threshold failed.\n");
505  (void)adxl345_deinit(&gs_handle);
506 
507  return 1;
508  }
509 
510  /* set default inaction threshold */
512  if (res != 0)
513  {
514  adxl345_interface_debug_print("adxl345: inaction threshold convert to register failed.\n");
515  (void)adxl345_deinit(&gs_handle);
516 
517  return 1;
518  }
519  res = adxl345_set_inaction_threshold(&gs_handle, reg);
520  if (res != 0)
521  {
522  adxl345_interface_debug_print("adxl345: set inaction threshold failed.\n");
523  (void)adxl345_deinit(&gs_handle);
524 
525  return 1;
526  }
527 
528  /* set default inaction time */
530  if (res != 0)
531  {
532  adxl345_interface_debug_print("adxl345: inaction time convert to register failed.\n");
533  (void)adxl345_deinit(&gs_handle);
534 
535  return 1;
536  }
537  res = adxl345_set_inaction_time(&gs_handle, reg);
538  if (res != 0)
539  {
540  adxl345_interface_debug_print("adxl345: set inaction time failed.\n");
541  (void)adxl345_deinit(&gs_handle);
542 
543  return 1;
544  }
545 
546  /* set action */
547  res = adxl345_set_action_inaction(&gs_handle, ADXL345_ACTION_X, action_enable);
548  if (res != 0)
549  {
550  adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
551  (void)adxl345_deinit(&gs_handle);
552 
553  return 1;
554  }
555  res = adxl345_set_action_inaction(&gs_handle, ADXL345_ACTION_Y, action_enable);
556  if (res != 0)
557  {
558  adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
559  (void)adxl345_deinit(&gs_handle);
560 
561  return 1;
562  }
563  res = adxl345_set_action_inaction(&gs_handle, ADXL345_ACTION_Z, action_enable);
564  if (res != 0)
565  {
566  adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
567  (void)adxl345_deinit(&gs_handle);
568 
569  return 1;
570  }
571 
572  /* set inaction */
573  res = adxl345_set_action_inaction(&gs_handle, ADXL345_INACTION_X, inaction_enable);
574  if (res != 0)
575  {
576  adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
577  (void)adxl345_deinit(&gs_handle);
578 
579  return 1;
580  }
581  res = adxl345_set_action_inaction(&gs_handle, ADXL345_INACTION_Y, inaction_enable);
582  if (res != 0)
583  {
584  adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
585  (void)adxl345_deinit(&gs_handle);
586 
587  return 1;
588  }
589  res = adxl345_set_action_inaction(&gs_handle, ADXL345_INACTION_Z, inaction_enable);
590  if (res != 0)
591  {
592  adxl345_interface_debug_print("adxl345: set action inaction failed.\n");
593  (void)adxl345_deinit(&gs_handle);
594 
595  return 1;
596  }
597 
598  /* set default action coupled */
600  if (res != 0)
601  {
602  adxl345_interface_debug_print("adxl345: set action coupled failed.\n");
603  (void)adxl345_deinit(&gs_handle);
604 
605  return 1;
606  }
607 
608  /* set default inaction coupled */
610  if (res != 0)
611  {
612  adxl345_interface_debug_print("adxl345: set inaction coupled failed.\n");
613  (void)adxl345_deinit(&gs_handle);
614 
615  return 1;
616  }
617 
618  /* set default activity map */
620  if (res != 0)
621  {
622  adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
623  (void)adxl345_deinit(&gs_handle);
624 
625  return 1;
626  }
627  res = adxl345_set_interrupt(&gs_handle, ADXL345_INTERRUPT_ACTIVITY, action_enable);
628  if (res != 0)
629  {
630  adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
631  (void)adxl345_deinit(&gs_handle);
632 
633  return 1;
634  }
635 
636  /* set default inactivity map */
638  if (res != 0)
639  {
640  adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
641  (void)adxl345_deinit(&gs_handle);
642 
643  return 1;
644  }
645  res = adxl345_set_interrupt(&gs_handle, ADXL345_INTERRUPT_INACTIVITY, inaction_enable);
646  if (res != 0)
647  {
648  adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
649  (void)adxl345_deinit(&gs_handle);
650 
651  return 1;
652  }
653 
654  /* set free fall threshold */
656  if (res != 0)
657  {
658  adxl345_interface_debug_print("adxl345: free fall threshold convert to register failed.\n");
659  (void)adxl345_deinit(&gs_handle);
660 
661  return 1;
662  }
663  res = adxl345_set_free_fall_threshold(&gs_handle, reg);
664  if (res != 0)
665  {
666  adxl345_interface_debug_print("adxl345: set free fall threshold failed.\n");
667  (void)adxl345_deinit(&gs_handle);
668 
669  return 1;
670  }
671 
672  /* set free fall time */
674  if (res != 0)
675  {
676  adxl345_interface_debug_print("adxl345: free fall time convert to register failed.\n");
677  (void)adxl345_deinit(&gs_handle);
678 
679  return 1;
680  }
681  res = adxl345_set_free_fall_time(&gs_handle, reg);
682  if (res != 0)
683  {
684  adxl345_interface_debug_print("adxl345: set free fall time failed.\n");
685  (void)adxl345_deinit(&gs_handle);
686 
687  return 1;
688  }
689 
690  /* set default free fall map */
692  if (res != 0)
693  {
694  adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
695  (void)adxl345_deinit(&gs_handle);
696 
697  return 1;
698  }
699  res = adxl345_set_interrupt(&gs_handle, ADXL345_INTERRUPT_FREE_FALL, fall_enable);
700  if (res != 0)
701  {
702  adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
703  (void)adxl345_deinit(&gs_handle);
704 
705  return 1;
706  }
707 
708  /* set default data ready map */
710  if (res != 0)
711  {
712  adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
713  (void)adxl345_deinit(&gs_handle);
714 
715  return 1;
716  }
718  if (res != 0)
719  {
720  adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
721  (void)adxl345_deinit(&gs_handle);
722 
723  return 1;
724  }
725 
726  /* set default watermark map */
728  if (res != 0)
729  {
730  adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
731  (void)adxl345_deinit(&gs_handle);
732 
733  return 1;
734  }
736  if (res != 0)
737  {
738  adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
739  (void)adxl345_deinit(&gs_handle);
740 
741  return 1;
742  }
743 
744  /* set default overrun map */
746  if (res != 0)
747  {
748  adxl345_interface_debug_print("adxl345: set interrupt map failed.\n");
749  (void)adxl345_deinit(&gs_handle);
750 
751  return 1;
752  }
754  if (res != 0)
755  {
756  adxl345_interface_debug_print("adxl345: set interrupt failed.\n");
757  (void)adxl345_deinit(&gs_handle);
758 
759  return 1;
760  }
761 
762  /* clear interrupt */
763  res = adxl345_get_interrupt_source(&gs_handle, &source);
764  if (res != 0)
765  {
766  adxl345_interface_debug_print("adxl345: get interrupt source failed.\n");
767  (void)adxl345_deinit(&gs_handle);
768 
769  return 1;
770  }
771 
772  /* start measure */
773  res = adxl345_set_measure(&gs_handle, ADXL345_BOOL_TRUE);
774  if (res != 0)
775  {
776  adxl345_interface_debug_print("adxl345: set measure failed.\n");
777  (void)adxl345_deinit(&gs_handle);
778 
779  return 1;
780  }
781  a_callback = callback;
782 
783  return 0;
784 }
785 
794 {
795  int16_t raw[3];
796  float g_out[3];
797  uint16_t len;
798 
799  len = 1;
800 
801  /* read data */
802  if (adxl345_read(&gs_handle, (int16_t (*)[3])&raw, (float (*)[3])&g_out, (uint16_t *)&len) != 0)
803  {
804  return 1;
805  }
806 
807  return 0;
808 }
809 
818 {
819  if (adxl345_deinit(&gs_handle) != 0)
820  {
821  return 1;
822  }
823  else
824  {
825  return 0;
826  }
827 }
driver adxl345 interrupt 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_duration_convert_to_register(adxl345_handle_t *handle, uint32_t us, uint8_t *reg)
convert the duration to the register raw data
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_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_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_set_spi_wire(adxl345_handle_t *handle, adxl345_spi_wire_t wire)
set the chip spi wire
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_irq_handler(adxl345_handle_t *handle)
irq handler
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_set_action_threshold(adxl345_handle_t *handle, uint8_t threshold)
set the action 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_read(adxl345_handle_t *handle, int16_t(*raw)[3], float(*g)[3], uint16_t *len)
read the data
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_set_addr_pin(adxl345_handle_t *handle, adxl345_address_t addr_pin)
set the iic address pin
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_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_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_set_tap_axis(adxl345_handle_t *handle, adxl345_tap_axis_t axis, adxl345_bool_t enable)
enable or disable the tap axis
uint8_t adxl345_set_free_fall_time(adxl345_handle_t *handle, uint8_t t)
set the free fall time
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
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_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_set_mode(adxl345_handle_t *handle, adxl345_mode_t mode)
set the chip mode
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
@ ADXL345_ACTION_Z
@ ADXL345_INACTION_Z
@ ADXL345_INACTION_X
@ ADXL345_INACTION_Y
@ ADXL345_ACTION_X
@ ADXL345_ACTION_Y
@ ADXL345_TAP_AXIS_Z
@ ADXL345_TAP_AXIS_Y
@ ADXL345_TAP_AXIS_X
@ ADXL345_BOOL_TRUE
uint8_t adxl345_interrupt_irq_handler(void)
interrupt irq
#define ADXL345_INTERRUPT_DEFAULT_JUSTIFY
#define ADXL345_INTERRUPT_DEFAULT_TRIGGER_PIN
#define ADXL345_INTERRUPT_DEFAULT_INTERRUPT_OVERRUN_MAP
#define ADXL345_INTERRUPT_DEFAULT_RATE
adxl345 interrupt example default definition
#define ADXL345_INTERRUPT_DEFAULT_INTERRUPT_DATA_READY
#define ADXL345_INTERRUPT_DEFAULT_INACTION_TIME
#define ADXL345_INTERRUPT_DEFAULT_INTERRUPT_DOUBLE_TAP_MAP
#define ADXL345_INTERRUPT_DEFAULT_ACTION_THRESHOLD
#define ADXL345_INTERRUPT_DEFAULT_LATENT
#define ADXL345_INTERRUPT_DEFAULT_INTERRUPT_WATERMARK
#define ADXL345_INTERRUPT_DEFAULT_ACTION_COUPLED
uint8_t adxl345_interrupt_init(adxl345_interface_t interface, adxl345_address_t addr_pin, void(*callback)(uint8_t type), adxl345_bool_t tap_enable, adxl345_bool_t action_enable, adxl345_bool_t inaction_enable, adxl345_bool_t fall_enable)
interrupt example init
#define ADXL345_INTERRUPT_DEFAULT_AUTO_SLEEP
#define ADXL345_INTERRUPT_DEFAULT_SLEEP_FREQUENCY
#define ADXL345_INTERRUPT_DEFAULT_MODE
#define ADXL345_INTERRUPT_DEFAULT_OFFSET
#define ADXL345_INTERRUPT_DEFAULT_INTERRUPT_ACTIVITY_MAP
#define ADXL345_INTERRUPT_DEFAULT_TAP_THRESHOLD
#define ADXL345_INTERRUPT_DEFAULT_INTERRUPT_INACTIVITY_MAP
#define ADXL345_INTERRUPT_DEFAULT_INTERRUPT_OVERRUN
#define ADXL345_INTERRUPT_DEFAULT_INTERRUPT_DATA_READY_MAP
#define ADXL345_INTERRUPT_DEFAULT_WATERMARK
uint8_t adxl345_interrupt_server(void)
interrupt server
#define ADXL345_INTERRUPT_DEFAULT_TAP_SUPPRESS
#define ADXL345_INTERRUPT_DEFAULT_FULL_RESOLUTION
#define ADXL345_INTERRUPT_DEFAULT_WINDOW
#define ADXL345_INTERRUPT_DEFAULT_INTERRUPT_ACTIVE_LEVEL
#define ADXL345_INTERRUPT_DEFAULT_INTERRUPT_FREE_FALL_MAP
#define ADXL345_INTERRUPT_DEFAULT_RANGE
#define ADXL345_INTERRUPT_DEFAULT_INTERRUPT_SINGLE_TAP_MAP
#define ADXL345_INTERRUPT_DEFAULT_SLEEP
#define ADXL345_INTERRUPT_DEFAULT_INACTION_COUPLED
#define ADXL345_INTERRUPT_DEFAULT_INTERRUPT_WATERMARK_MAP
#define ADXL345_INTERRUPT_DEFAULT_FREE_FALL_TIME
#define ADXL345_INTERRUPT_DEFAULT_FREE_FALL_THRESHOLD
#define ADXL345_INTERRUPT_DEFAULT_SPI_WIRE
uint8_t adxl345_interrupt_deinit(void)
interrupt example deinit
#define ADXL345_INTERRUPT_DEFAULT_DURATION
#define ADXL345_INTERRUPT_DEFAULT_INACTION_THRESHOLD
#define ADXL345_INTERRUPT_DEFAULT_LINK_ACTIVITY_INACTIVITY
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
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
uint8_t adxl345_get_interrupt_source(adxl345_handle_t *handle, uint8_t *source)
get the interrupt source
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_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
@ 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
adxl345 handle structure definition