LibDriver ADXL362
Loading...
Searching...
No Matches
driver_adxl362_motion.c
Go to the documentation of this file.
1
36
38
39static adxl362_handle_t gs_handle;
40
49{
50 if (adxl362_irq_handler(&gs_handle) != 0)
51 {
52 return 1;
53 }
54 else
55 {
56 return 0;
57 }
58}
59
68uint8_t adxl362_motion_init(void (*callback)(uint8_t type))
69{
70 uint8_t res;
71 uint8_t reg_short;
72 uint8_t status;
73 uint16_t reg;
74
75 /* link interface function */
84 DRIVER_ADXL362_LINK_RECEIVE_CALLBACK(&gs_handle, callback);
85
86 /* init the adxl362 */
87 res = adxl362_init(&gs_handle);
88 if (res != 0)
89 {
90 adxl362_interface_debug_print("adxl362: init failed.\n");
91
92 return 1;
93 }
94
95 /* disable fifo temperature */
97 if (res != 0)
98 {
99 adxl362_interface_debug_print("adxl362: set fifo temperature failed.\n");
100 (void)adxl362_deinit(&gs_handle);
101
102 return 1;
103 }
104
105 /* disable fifo */
107 if (res != 0)
108 {
109 adxl362_interface_debug_print("adxl362: set fifo mode failed.\n");
110 (void)adxl362_deinit(&gs_handle);
111
112 return 1;
113 }
114
115 /* set fifo sample 0 */
116 res = adxl362_set_fifo_sample(&gs_handle, 0);
117 if (res != 0)
118 {
119 adxl362_interface_debug_print("adxl362: set fifo sample failed.\n");
120 (void)adxl362_deinit(&gs_handle);
121
122 return 1;
123 }
124
125 /* set interrupt pin1 default active level */
127 if (res != 0)
128 {
129 adxl362_interface_debug_print("adxl362: set interrupt pin1 active level failed.\n");
130 (void)adxl362_deinit(&gs_handle);
131
132 return 1;
133 }
134
135 /* disable awake map */
137 if (res != 0)
138 {
139 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
140 (void)adxl362_deinit(&gs_handle);
141
142 return 1;
143 }
144
145 /* enable inact map */
147 if (res != 0)
148 {
149 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
150 (void)adxl362_deinit(&gs_handle);
151
152 return 1;
153 }
154
155 /* enable act map */
157 if (res != 0)
158 {
159 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
160 (void)adxl362_deinit(&gs_handle);
161
162 return 1;
163 }
164
165 /* disable fifo overrun map */
167 if (res != 0)
168 {
169 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
170 (void)adxl362_deinit(&gs_handle);
171
172 return 1;
173 }
174
175 /* disable fifo watermark map */
177 if (res != 0)
178 {
179 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
180 (void)adxl362_deinit(&gs_handle);
181
182 return 1;
183 }
184
185 /* disable fifo ready map */
187 if (res != 0)
188 {
189 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
190 (void)adxl362_deinit(&gs_handle);
191
192 return 1;
193 }
194
195 /* disable data ready map */
197 if (res != 0)
198 {
199 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
200 (void)adxl362_deinit(&gs_handle);
201
202 return 1;
203 }
204
205 /* set interrupt pin2 active level low */
207 if (res != 0)
208 {
209 adxl362_interface_debug_print("adxl362: set interrupt pin2 active level failed.\n");
210 (void)adxl362_deinit(&gs_handle);
211
212 return 1;
213 }
214
215 /* disable awake map */
217 if (res != 0)
218 {
219 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
220 (void)adxl362_deinit(&gs_handle);
221
222 return 1;
223 }
224
225 /* disable inact map */
227 if (res != 0)
228 {
229 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
230 (void)adxl362_deinit(&gs_handle);
231
232 return 1;
233 }
234
235 /* disable act map */
237 if (res != 0)
238 {
239 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
240 (void)adxl362_deinit(&gs_handle);
241
242 return 1;
243 }
244
245 /* disable fifo overrun map */
247 if (res != 0)
248 {
249 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
250 (void)adxl362_deinit(&gs_handle);
251
252 return 1;
253 }
254
255 /* disable fifo watermark map */
257 if (res != 0)
258 {
259 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
260 (void)adxl362_deinit(&gs_handle);
261
262 return 1;
263 }
264
265 /* disable fifo ready map */
267 if (res != 0)
268 {
269 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
270 (void)adxl362_deinit(&gs_handle);
271
272 return 1;
273 }
274
275 /* disable data ready map */
277 if (res != 0)
278 {
279 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
280 (void)adxl362_deinit(&gs_handle);
281
282 return 1;
283 }
284
285 /* set default bandwidth */
287 if (res != 0)
288 {
289 adxl362_interface_debug_print("adxl362: set bandwidth failed.\n");
290 (void)adxl362_deinit(&gs_handle);
291
292 return 1;
293 }
294
295 /* set default noise mode */
297 if (res != 0)
298 {
299 adxl362_interface_debug_print("adxl362: set noise mode failed.\n");
300 (void)adxl362_deinit(&gs_handle);
301
302 return 1;
303 }
304
305 /* disable wake up */
306 res = adxl362_set_wake_up(&gs_handle, ADXL362_BOOL_FALSE);
307 if (res != 0)
308 {
309 adxl362_interface_debug_print("adxl362: set wake up failed.\n");
310 (void)adxl362_deinit(&gs_handle);
311
312 return 1;
313 }
314
315 /* disable auto sleep */
317 if (res != 0)
318 {
319 adxl362_interface_debug_print("adxl362: set auto sleep failed.\n");
320 (void)adxl362_deinit(&gs_handle);
321
322 return 1;
323 }
324
325 /* disable interrupt pin2 as external sampling trigger */
327 if (res != 0)
328 {
329 adxl362_interface_debug_print("adxl362: set interrupt pin2 as external sampling trigger failed.\n");
330 (void)adxl362_deinit(&gs_handle);
331
332 return 1;
333 }
334
335 /* disable interrupt pin1 as external clock */
337 if (res != 0)
338 {
339 adxl362_interface_debug_print("adxl362: set interrupt pin1 as external clock failed.\n");
340 (void)adxl362_deinit(&gs_handle);
341
342 return 1;
343 }
344
345 /* set default odr */
347 if (res != 0)
348 {
349 adxl362_interface_debug_print("adxl362: set odr failed.\n");
350 (void)adxl362_deinit(&gs_handle);
351
352 return 1;
353 }
354
355 /* set default range */
357 if (res != 0)
358 {
359 adxl362_interface_debug_print("adxl362: set range failed.\n");
360 (void)adxl362_deinit(&gs_handle);
361
362 return 1;
363 }
364
365 /* set default activity threshold */
367 if (res != 0)
368 {
369 adxl362_interface_debug_print("adxl362: activity threshold convert to register failed.\n");
370 (void)adxl362_deinit(&gs_handle);
371
372 return 1;
373 }
374
375 /* set activity threshold */
376 res = adxl362_set_activity_threshold(&gs_handle, reg);
377 if (res != 0)
378 {
379 adxl362_interface_debug_print("adxl362: set activity threshold failed.\n");
380 (void)adxl362_deinit(&gs_handle);
381
382 return 1;
383 }
384
385 /* set default activity time */
387 if (res != 0)
388 {
389 adxl362_interface_debug_print("adxl362: activity time convert to register failed.\n");
390 (void)adxl362_deinit(&gs_handle);
391
392 return 1;
393 }
394
395 /* set activity time */
396 res = adxl362_set_activity_time(&gs_handle, reg_short);
397 if (res != 0)
398 {
399 adxl362_interface_debug_print("adxl362: set activity time failed.\n");
400 (void)adxl362_deinit(&gs_handle);
401
402 return 1;
403 }
404
405 /* set default inactivity threshold */
407 if (res != 0)
408 {
409 adxl362_interface_debug_print("adxl362: inactivity threshold convert to register failed.\n");
410 (void)adxl362_deinit(&gs_handle);
411
412 return 1;
413 }
414
415 /* set inactivity threshold */
416 res = adxl362_set_inactivity_threshold(&gs_handle, reg);
417 if (res != 0)
418 {
419 adxl362_interface_debug_print("adxl362: set inactivity threshold failed.\n");
420 (void)adxl362_deinit(&gs_handle);
421
422 return 1;
423 }
424
425 /* set default inactivity time */
427 if (res != 0)
428 {
429 adxl362_interface_debug_print("adxl362: inactivity time convert to register failed.\n");
430 (void)adxl362_deinit(&gs_handle);
431
432 return 1;
433 }
434
435 /* set inactivity time */
436 res = adxl362_set_inactivity_time(&gs_handle, reg);
437 if (res != 0)
438 {
439 adxl362_interface_debug_print("adxl362: set inactivity time failed.\n");
440 (void)adxl362_deinit(&gs_handle);
441
442 return 1;
443 }
444
445 /* set default detect mode */
447 if (res != 0)
448 {
449 adxl362_interface_debug_print("adxl362: set detect mode failed.\n");
450 (void)adxl362_deinit(&gs_handle);
451
452 return 1;
453 }
454
455 /* set default inactivity detect trigger */
457 if (res != 0)
458 {
459 adxl362_interface_debug_print("adxl362: set inactivity detect trigger failed.\n");
460 (void)adxl362_deinit(&gs_handle);
461
462 return 1;
463 }
464
465 /* set default activity detect trigger */
467 if (res != 0)
468 {
469 adxl362_interface_debug_print("adxl362: set activity detect trigger failed.\n");
470 (void)adxl362_deinit(&gs_handle);
471
472 return 1;
473 }
474
475 /* enable inactivity */
476 res = adxl362_set_inactivity(&gs_handle, ADXL362_BOOL_TRUE);
477 if (res != 0)
478 {
479 adxl362_interface_debug_print("adxl362: set inactivity failed.\n");
480 (void)adxl362_deinit(&gs_handle);
481
482 return 1;
483 }
484
485 /* enable activity */
486 res = adxl362_set_activity(&gs_handle, ADXL362_BOOL_TRUE);
487 if (res != 0)
488 {
489 adxl362_interface_debug_print("adxl362: set activity failed.\n");
490 (void)adxl362_deinit(&gs_handle);
491
492 return 1;
493 }
494
495 /* disable self test */
496 res = adxl362_set_self_test(&gs_handle, ADXL362_BOOL_FALSE);
497 if (res != 0)
498 {
499 adxl362_interface_debug_print("adxl362: set self test failed.\n");
500 (void)adxl362_deinit(&gs_handle);
501
502 return 1;
503 }
504
505 /* get status */
506 res = adxl362_get_status(&gs_handle, &status);
507 if (res != 0)
508 {
509 adxl362_interface_debug_print("adxl362: get status failed.\n");
510 (void)adxl362_deinit(&gs_handle);
511
512 return 1;
513 }
514
515 /* start measurement */
517 if (res != 0)
518 {
519 adxl362_interface_debug_print("adxl362: set mode failed.\n");
520 (void)adxl362_deinit(&gs_handle);
521
522 return 1;
523 }
524
525 return 0;
526}
527
536{
537 /* deinit */
538 if (adxl362_deinit(&gs_handle) != 0)
539 {
540 return 1;
541 }
542
543 return 0;
544}
driver adxl362 motion 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
uint8_t adxl362_set_interrupt_pin2_active_level(adxl362_handle_t *handle, adxl362_interrupt_pin_level_t level)
set the interrupt pin2 active level
struct adxl362_handle_s adxl362_handle_t
adxl362 handle structure definition
uint8_t adxl362_set_wake_up(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable chip wake up
uint8_t adxl362_set_inactivity_threshold(adxl362_handle_t *handle, uint16_t threshold)
set the inactivity threshold
uint8_t adxl362_set_interrupt_pin1_map(adxl362_handle_t *handle, adxl362_interrupt_map_t map, adxl362_bool_t enable)
set the interrupt pin1 map
uint8_t adxl362_set_noise_mode(adxl362_handle_t *handle, adxl362_noise_mode_t mode)
set the noise mode
uint8_t adxl362_set_activity_threshold(adxl362_handle_t *handle, uint16_t threshold)
set the activity threshold
uint8_t adxl362_activity_threshold_convert_to_register(adxl362_handle_t *handle, float g, uint16_t *reg)
convert the activity threshold to the register raw data
uint8_t adxl362_set_activity_time(adxl362_handle_t *handle, uint8_t tim)
set the activity time
uint8_t adxl362_set_interrupt_pin1_active_level(adxl362_handle_t *handle, adxl362_interrupt_pin_level_t level)
set the interrupt pin1 active level
uint8_t adxl362_inactivity_time_convert_to_register(adxl362_handle_t *handle, float ms, uint16_t *reg)
convert the inactivity time to the register raw data
uint8_t adxl362_set_fifo_temperature(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable saving temperature data to fifo
uint8_t adxl362_set_activity_detect_trigger(adxl362_handle_t *handle, adxl362_detect_trigger_t trigger)
set the activity detect trigger mode
uint8_t adxl362_set_interrupt_pin1_as_external_clock(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable interrupt pin1 as the external clock
uint8_t adxl362_irq_handler(adxl362_handle_t *handle)
irq handler
uint8_t adxl362_set_mode(adxl362_handle_t *handle, adxl362_mode_t mode)
set the chip mode
uint8_t adxl362_set_inactivity(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable inactivity
uint8_t adxl362_activity_time_convert_to_register(adxl362_handle_t *handle, float ms, uint8_t *reg)
convert the activity time to the register raw data
uint8_t adxl362_inactivity_threshold_convert_to_register(adxl362_handle_t *handle, float g, uint16_t *reg)
convert the inactivity threshold to the register raw data
uint8_t adxl362_set_interrupt_pin2_as_external_sampling_trigger(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable interrupt pin2 as the external sampling trigger
uint8_t adxl362_get_status(adxl362_handle_t *handle, uint8_t *status)
get the chip status
uint8_t adxl362_set_activity(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable activity
uint8_t adxl362_set_auto_sleep(adxl362_handle_t *handle, adxl362_bool_t enable)
enable or disable auto sleep
uint8_t adxl362_set_bandwidth(adxl362_handle_t *handle, adxl362_bandwidth_t bandwidth)
set the filter bandwidth
uint8_t adxl362_deinit(adxl362_handle_t *handle)
close the chip
uint8_t adxl362_set_odr(adxl362_handle_t *handle, adxl362_odr_t odr)
set the output data rate
@ ADXL362_FIFO_MODE_DISABLE
@ 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_BOOL_FALSE
@ ADXL362_BOOL_TRUE
@ ADXL362_INTERRUPT_PIN_LOW
#define ADXL362_MOTION_DEFAULT_DETECT_MODE
#define ADXL362_MOTION_DEFAULT_NOISE_MODE
#define ADXL362_MOTION_DEFAULT_BANDWIDTH_ODR
#define ADXL362_MOTION_DEFAULT_INTERRUPT_PIN_LEVEL
adxl362 motion example default definition
#define ADXL362_MOTION_DEFAULT_ACTIVITY_THRESHOLD
#define ADXL362_MOTION_DEFAULT_INACTIVITY_THRESHOLD
uint8_t adxl362_motion_irq_handler(void)
motion irq
#define ADXL362_MOTION_DEFAULT_RANGE
#define ADXL362_MOTION_DEFAULT_ACTIVITY_DETECT_TRIGGER
#define ADXL362_MOTION_DEFAULT_ACTIVITY_TIME
#define ADXL362_MOTION_DEFAULT_INACTIVITY_DETECT_TRIGGER
uint8_t adxl362_motion_init(void(*callback)(uint8_t type))
motion example init
#define ADXL362_MOTION_DEFAULT_INACTIVITY_TIME
uint8_t adxl362_motion_deinit(void)
motion example deinit
#define ADXL362_MOTION_DEFAULT_ODR
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