LibDriver ADXL362
Loading...
Searching...
No Matches
driver_adxl362_fifo.c
Go to the documentation of this file.
1
36
37#include "driver_adxl362_fifo.h"
38
39static adxl362_handle_t gs_handle;
40static adxl362_frame_t gs_frame[180];
41static void (*gs_callback)(adxl362_frame_t *frame, uint16_t frame_len) = NULL;
42
51{
52 if (adxl362_irq_handler(&gs_handle) != 0)
53 {
54 return 1;
55 }
56 else
57 {
58 return 0;
59 }
60}
61
67static void a_adxl362_interface_receive_callback(uint8_t type)
68{
69 switch (type)
70 {
72 {
73 adxl362_interface_debug_print("adxl362: irq seu error detect.\n");
74
75 break;
76 }
78 {
79 break;
80 }
82 {
83 adxl362_interface_debug_print("adxl362: irq inactivity.\n");
84
85 break;
86 }
88 {
89 adxl362_interface_debug_print("adxl362: irq activity.\n");
90
91 break;
92 }
94 {
95 uint8_t res;
96 uint16_t frame_len;
97
98 /* total 180 */
99 frame_len = 180;
100
101 /* read fifo */
102 res = adxl362_read_fifo(&gs_handle, gs_frame, &frame_len);
103 if (res != 0)
104 {
105 return;
106 }
107
108 /* output */
109 adxl362_interface_debug_print("adxl362: irq fifo overrun with %d.\n", frame_len);
110
111 break;
112 }
114 {
115 uint8_t res;
116 uint16_t frame_len;
117
118 /* total 180 */
119 frame_len = 180;
120
121 /* read fifo */
122 res = adxl362_read_fifo(&gs_handle, gs_frame, &frame_len);
123 if (res != 0)
124 {
125 return;
126 }
127
128 /* if not null */
129 if (gs_callback != NULL)
130 {
131 /* run the callback */
132 gs_callback(gs_frame, frame_len);
133 }
134
135 break;
136 }
138 {
139 break;
140 }
142 {
143 break;
144 }
145 default :
146 {
147 adxl362_interface_debug_print("adxl362: unknown code.\n");
148
149 break;
150 }
151 }
152}
153
162uint8_t adxl362_fifo_init(void (*callback)(adxl362_frame_t *frame, uint16_t frame_len))
163{
164 uint8_t res;
165
166 /* link interface function */
175 DRIVER_ADXL362_LINK_RECEIVE_CALLBACK(&gs_handle, a_adxl362_interface_receive_callback);
176
177 /* init the adxl362 */
178 res = adxl362_init(&gs_handle);
179 if (res != 0)
180 {
181 adxl362_interface_debug_print("adxl362: init failed.\n");
182
183 return 1;
184 }
185
186 /* set default fifo temperature */
188 if (res != 0)
189 {
190 adxl362_interface_debug_print("adxl362: set fifo temperature failed.\n");
191 (void)adxl362_deinit(&gs_handle);
192
193 return 1;
194 }
195
196 /* set default fifo mode */
198 if (res != 0)
199 {
200 adxl362_interface_debug_print("adxl362: set fifo mode failed.\n");
201 (void)adxl362_deinit(&gs_handle);
202
203 return 1;
204 }
205
206 /* set default fifo sample */
208 if (res != 0)
209 {
210 adxl362_interface_debug_print("adxl362: set fifo sample failed.\n");
211 (void)adxl362_deinit(&gs_handle);
212
213 return 1;
214 }
215
216 /* set default interrupt pin1 active level */
218 if (res != 0)
219 {
220 adxl362_interface_debug_print("adxl362: set interrupt pin1 active level failed.\n");
221 (void)adxl362_deinit(&gs_handle);
222
223 return 1;
224 }
225
226 /* disable awake map */
228 if (res != 0)
229 {
230 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
231 (void)adxl362_deinit(&gs_handle);
232
233 return 1;
234 }
235
236 /* disable inact map */
238 if (res != 0)
239 {
240 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
241 (void)adxl362_deinit(&gs_handle);
242
243 return 1;
244 }
245
246 /* disable act map */
248 if (res != 0)
249 {
250 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
251 (void)adxl362_deinit(&gs_handle);
252
253 return 1;
254 }
255
256 /* enable fifo overrun map */
258 if (res != 0)
259 {
260 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
261 (void)adxl362_deinit(&gs_handle);
262
263 return 1;
264 }
265
266 /* enable fifo watermark map */
268 if (res != 0)
269 {
270 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
271 (void)adxl362_deinit(&gs_handle);
272
273 return 1;
274 }
275
276 /* disable fifo ready map */
278 if (res != 0)
279 {
280 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
281 (void)adxl362_deinit(&gs_handle);
282
283 return 1;
284 }
285
286 /* disable data ready map */
288 if (res != 0)
289 {
290 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
291 (void)adxl362_deinit(&gs_handle);
292
293 return 1;
294 }
295
296 /* set interrupt pin2 active level low */
298 if (res != 0)
299 {
300 adxl362_interface_debug_print("adxl362: set interrupt pin2 active level failed.\n");
301 (void)adxl362_deinit(&gs_handle);
302
303 return 1;
304 }
305
306 /* disable awake map */
308 if (res != 0)
309 {
310 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
311 (void)adxl362_deinit(&gs_handle);
312
313 return 1;
314 }
315
316 /* disable inact map */
318 if (res != 0)
319 {
320 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
321 (void)adxl362_deinit(&gs_handle);
322
323 return 1;
324 }
325
326 /* disable act map */
328 if (res != 0)
329 {
330 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
331 (void)adxl362_deinit(&gs_handle);
332
333 return 1;
334 }
335
336 /* disable fifo overrun map */
338 if (res != 0)
339 {
340 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
341 (void)adxl362_deinit(&gs_handle);
342
343 return 1;
344 }
345
346 /* disable fifo watermark map */
348 if (res != 0)
349 {
350 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
351 (void)adxl362_deinit(&gs_handle);
352
353 return 1;
354 }
355
356 /* disable fifo ready map */
358 if (res != 0)
359 {
360 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
361 (void)adxl362_deinit(&gs_handle);
362
363 return 1;
364 }
365
366 /* disable data ready map */
368 if (res != 0)
369 {
370 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
371 (void)adxl362_deinit(&gs_handle);
372
373 return 1;
374 }
375
376 /* set default bandwidth */
378 if (res != 0)
379 {
380 adxl362_interface_debug_print("adxl362: set bandwidth failed.\n");
381 (void)adxl362_deinit(&gs_handle);
382
383 return 1;
384 }
385
386 /* set default noise mode */
388 if (res != 0)
389 {
390 adxl362_interface_debug_print("adxl362: set noise mode failed.\n");
391 (void)adxl362_deinit(&gs_handle);
392
393 return 1;
394 }
395
396 /* disable wake up */
397 res = adxl362_set_wake_up(&gs_handle, ADXL362_BOOL_FALSE);
398 if (res != 0)
399 {
400 adxl362_interface_debug_print("adxl362: set wake up failed.\n");
401 (void)adxl362_deinit(&gs_handle);
402
403 return 1;
404 }
405
406 /* disable auto sleep */
408 if (res != 0)
409 {
410 adxl362_interface_debug_print("adxl362: set auto sleep failed.\n");
411 (void)adxl362_deinit(&gs_handle);
412
413 return 1;
414 }
415
416 /* disable interrupt pin2 as external sampling trigger */
418 if (res != 0)
419 {
420 adxl362_interface_debug_print("adxl362: set interrupt pin2 as external sampling trigger failed.\n");
421 (void)adxl362_deinit(&gs_handle);
422
423 return 1;
424 }
425
426 /* disable interrupt pin1 as external clock */
428 if (res != 0)
429 {
430 adxl362_interface_debug_print("adxl362: set interrupt pin1 as external clock failed.\n");
431 (void)adxl362_deinit(&gs_handle);
432
433 return 1;
434 }
435
436 /* set activity threshold 0x0000 */
437 res = adxl362_set_activity_threshold(&gs_handle, 0x0000);
438 if (res != 0)
439 {
440 adxl362_interface_debug_print("adxl362: set activity threshold failed.\n");
441 (void)adxl362_deinit(&gs_handle);
442
443 return 1;
444 }
445
446 /* set activity time 0x00 */
447 res = adxl362_set_activity_time(&gs_handle, 0x00);
448 if (res != 0)
449 {
450 adxl362_interface_debug_print("adxl362: set activity time failed.\n");
451 (void)adxl362_deinit(&gs_handle);
452
453 return 1;
454 }
455
456 /* set inactivity threshold 0x0000 */
457 res = adxl362_set_inactivity_threshold(&gs_handle, 0x0000);
458 if (res != 0)
459 {
460 adxl362_interface_debug_print("adxl362: set inactivity threshold failed.\n");
461 (void)adxl362_deinit(&gs_handle);
462
463 return 1;
464 }
465
466 /* set inactivity time 0x0000 */
467 res = adxl362_set_inactivity_time(&gs_handle, 0x0000);
468 if (res != 0)
469 {
470 adxl362_interface_debug_print("adxl362: set inactivity time failed.\n");
471 (void)adxl362_deinit(&gs_handle);
472
473 return 1;
474 }
475
476 /* set detect link mode */
478 if (res != 0)
479 {
480 adxl362_interface_debug_print("adxl362: set detect mode failed.\n");
481 (void)adxl362_deinit(&gs_handle);
482
483 return 1;
484 }
485
486 /* set inactivity detect trigger */
488 if (res != 0)
489 {
490 adxl362_interface_debug_print("adxl362: set inactivity detect trigger failed.\n");
491 (void)adxl362_deinit(&gs_handle);
492
493 return 1;
494 }
495
496 /* set activity detect trigger */
498 if (res != 0)
499 {
500 adxl362_interface_debug_print("adxl362: set activity detect trigger failed.\n");
501 (void)adxl362_deinit(&gs_handle);
502
503 return 1;
504 }
505
506 /* disable inactivity */
508 if (res != 0)
509 {
510 adxl362_interface_debug_print("adxl362: set inactivity failed.\n");
511 (void)adxl362_deinit(&gs_handle);
512
513 return 1;
514 }
515
516 /* disable activity */
517 res = adxl362_set_activity(&gs_handle, ADXL362_BOOL_FALSE);
518 if (res != 0)
519 {
520 adxl362_interface_debug_print("adxl362: set activity failed.\n");
521 (void)adxl362_deinit(&gs_handle);
522
523 return 1;
524 }
525
526 /* disable self test */
527 res = adxl362_set_self_test(&gs_handle, ADXL362_BOOL_FALSE);
528 if (res != 0)
529 {
530 adxl362_interface_debug_print("adxl362: set self test failed.\n");
531 (void)adxl362_deinit(&gs_handle);
532
533 return 1;
534 }
535
536 /* set default odr */
537 res = adxl362_set_odr(&gs_handle, ADXL362_FIFO_DEFAULT_ODR);
538 if (res != 0)
539 {
540 adxl362_interface_debug_print("adxl362: set odr failed.\n");
541 (void)adxl362_deinit(&gs_handle);
542
543 return 1;
544 }
545
546 /* set default range */
548 if (res != 0)
549 {
550 adxl362_interface_debug_print("adxl362: set range failed.\n");
551 (void)adxl362_deinit(&gs_handle);
552
553 return 1;
554 }
555
556 /* start measurement */
558 if (res != 0)
559 {
560 adxl362_interface_debug_print("adxl362: set mode failed.\n");
561 (void)adxl362_deinit(&gs_handle);
562
563 return 1;
564 }
565
566 /* set the callback */
567 gs_callback = callback;
568
569 return 0;
570}
571
580{
581 /* deinit */
582 if (adxl362_deinit(&gs_handle) != 0)
583 {
584 return 1;
585 }
586
587 return 0;
588}
driver adxl362 fifo header file
uint8_t adxl362_set_range(adxl362_handle_t *handle, adxl362_range_t range)
set the measurement range
uint8_t adxl362_set_interrupt_pin2_map(adxl362_handle_t *handle, adxl362_interrupt_map_t map, adxl362_bool_t enable)
set the interrupt pin2 map
uint8_t adxl362_set_inactivity_detect_trigger(adxl362_handle_t *handle, adxl362_detect_trigger_t trigger)
set the inactivity detect trigger mode
uint8_t adxl362_set_fifo_sample(adxl362_handle_t *handle, uint16_t sample)
set the fifo sample
uint8_t adxl362_set_inactivity_time(adxl362_handle_t *handle, uint16_t tim)
set the inactivity time
uint8_t adxl362_set_fifo_mode(adxl362_handle_t *handle, adxl362_fifo_mode_t mode)
set the fifo mode
uint8_t adxl362_set_self_test(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable the self test
uint8_t adxl362_init(adxl362_handle_t *handle)
initialize the chip
uint8_t adxl362_set_detect_mode(adxl362_handle_t *handle, adxl362_detect_mode_t mode)
set the detect mode
struct adxl362_frame_s adxl362_frame_t
adxl362 frame structure definition
uint8_t adxl362_set_interrupt_pin2_active_level(adxl362_handle_t *handle, adxl362_interrupt_pin_level_t level)
set the interrupt pin2 active level
struct adxl362_handle_s adxl362_handle_t
adxl362 handle structure definition
uint8_t adxl362_set_wake_up(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable chip wake up
uint8_t adxl362_set_inactivity_threshold(adxl362_handle_t *handle, uint16_t threshold)
set the inactivity threshold
uint8_t adxl362_set_interrupt_pin1_map(adxl362_handle_t *handle, adxl362_interrupt_map_t map, adxl362_bool_t enable)
set the interrupt pin1 map
uint8_t adxl362_set_noise_mode(adxl362_handle_t *handle, adxl362_noise_mode_t mode)
set the noise mode
uint8_t adxl362_set_activity_threshold(adxl362_handle_t *handle, uint16_t threshold)
set the activity threshold
uint8_t adxl362_set_activity_time(adxl362_handle_t *handle, uint8_t tim)
set the activity time
uint8_t adxl362_read_fifo(adxl362_handle_t *handle, adxl362_frame_t *frame, uint16_t *frame_len)
read data from the fifo
uint8_t adxl362_set_interrupt_pin1_active_level(adxl362_handle_t *handle, adxl362_interrupt_pin_level_t level)
set the interrupt pin1 active level
uint8_t adxl362_set_fifo_temperature(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable saving temperature data to fifo
uint8_t adxl362_set_activity_detect_trigger(adxl362_handle_t *handle, adxl362_detect_trigger_t trigger)
set the activity detect trigger mode
uint8_t adxl362_set_interrupt_pin1_as_external_clock(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable interrupt pin1 as the external clock
uint8_t adxl362_irq_handler(adxl362_handle_t *handle)
irq handler
uint8_t adxl362_set_mode(adxl362_handle_t *handle, adxl362_mode_t mode)
set the chip mode
uint8_t adxl362_set_inactivity(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable inactivity
uint8_t adxl362_set_interrupt_pin2_as_external_sampling_trigger(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable interrupt pin2 as the external sampling trigger
uint8_t adxl362_set_activity(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable activity
uint8_t adxl362_set_auto_sleep(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable auto sleep
uint8_t adxl362_set_bandwidth(adxl362_handle_t *handle, adxl362_bandwidth_t bandwidth)
set the filter bandwidth
uint8_t adxl362_deinit(adxl362_handle_t *handle)
close the chip
uint8_t adxl362_set_odr(adxl362_handle_t *handle, adxl362_odr_t odr)
set the output data rate
@ ADXL362_DETECT_MODE_LINK
@ ADXL362_INTERRUPT_MAP_FIFO_READY
@ ADXL362_INTERRUPT_MAP_ACT
@ ADXL362_INTERRUPT_MAP_FIFO_OVERRUN
@ ADXL362_INTERRUPT_MAP_FIFO_WATERMARK
@ ADXL362_INTERRUPT_MAP_DATA_READY
@ ADXL362_INTERRUPT_MAP_AWAKE
@ ADXL362_INTERRUPT_MAP_INACT
@ ADXL362_MODE_MEASUREMENT
@ ADXL362_STATUS_DATA_READY
@ ADXL362_STATUS_FIFO_OVERRUN
@ ADXL362_STATUS_AWAKE
@ ADXL362_STATUS_INACT
@ ADXL362_STATUS_FIFO_READY
@ ADXL362_STATUS_ERR_USER_REGS
@ ADXL362_STATUS_ACT
@ ADXL362_STATUS_FIFO_WATERMARK
@ ADXL362_BOOL_FALSE
@ ADXL362_BOOL_TRUE
@ ADXL362_DETECT_TRIGGER_REFERENCED
@ ADXL362_INTERRUPT_PIN_LOW
#define ADXL362_FIFO_DEFAULT_BANDWIDTH_ODR
#define ADXL362_FIFO_DEFAULT_FIFO_TEMPERATURE
adxl362 fifo example default definition
#define ADXL362_FIFO_DEFAULT_INTERRUPT_PIN_LEVEL
uint8_t adxl362_fifo_irq_handler(void)
fifo irq
#define ADXL362_FIFO_DEFAULT_ODR
#define ADXL362_FIFO_DEFAULT_FIFO_MODE
#define ADXL362_FIFO_DEFAULT_RANGE
uint8_t adxl362_fifo_deinit(void)
fifo example deinit
uint8_t adxl362_fifo_init(void(*callback)(adxl362_frame_t *frame, uint16_t frame_len))
fifo example init
#define ADXL362_FIFO_DEFAULT_NOISE_MODE
#define ADXL362_FIFO_DEFAULT_FIFO_SAMPLE
uint8_t adxl362_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t adxl362_interface_spi_deinit(void)
interface spi bus deinit
uint8_t adxl362_interface_spi_init(void)
interface spi bus init
void adxl362_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t adxl362_interface_spi_write_address16(uint16_t addr, uint8_t *buf, uint16_t len)
interface spi bus write
void adxl362_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t adxl362_interface_spi_read_address16(uint16_t addr, uint8_t *buf, uint16_t len)
interface spi bus read