LibDriver ADXL362
Loading...
Searching...
No Matches
driver_adxl362_basic.c
Go to the documentation of this file.
1
36
38
39static adxl362_handle_t gs_handle;
40
48uint8_t adxl362_basic_init(void)
49{
50 uint8_t res;
51
52 /* link interface function */
62
63 /* init the adxl362 */
64 res = adxl362_init(&gs_handle);
65 if (res != 0)
66 {
67 adxl362_interface_debug_print("adxl362: init failed.\n");
68
69 return 1;
70 }
71
72 /* disable fifo temperature */
74 if (res != 0)
75 {
76 adxl362_interface_debug_print("adxl362: set fifo temperature failed.\n");
77 (void)adxl362_deinit(&gs_handle);
78
79 return 1;
80 }
81
82 /* disable fifo */
84 if (res != 0)
85 {
86 adxl362_interface_debug_print("adxl362: set fifo mode failed.\n");
87 (void)adxl362_deinit(&gs_handle);
88
89 return 1;
90 }
91
92 /* set fifo sample 0 */
93 res = adxl362_set_fifo_sample(&gs_handle, 0);
94 if (res != 0)
95 {
96 adxl362_interface_debug_print("adxl362: set fifo sample failed.\n");
97 (void)adxl362_deinit(&gs_handle);
98
99 return 1;
100 }
101
102 /* set interrupt pin1 active level low */
104 if (res != 0)
105 {
106 adxl362_interface_debug_print("adxl362: set interrupt pin1 active level failed.\n");
107 (void)adxl362_deinit(&gs_handle);
108
109 return 1;
110 }
111
112 /* disable awake map */
114 if (res != 0)
115 {
116 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
117 (void)adxl362_deinit(&gs_handle);
118
119 return 1;
120 }
121
122 /* disable inact map */
124 if (res != 0)
125 {
126 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
127 (void)adxl362_deinit(&gs_handle);
128
129 return 1;
130 }
131
132 /* disable act map */
134 if (res != 0)
135 {
136 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
137 (void)adxl362_deinit(&gs_handle);
138
139 return 1;
140 }
141
142 /* disable fifo overrun map */
144 if (res != 0)
145 {
146 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
147 (void)adxl362_deinit(&gs_handle);
148
149 return 1;
150 }
151
152 /* disable fifo watermark map */
154 if (res != 0)
155 {
156 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
157 (void)adxl362_deinit(&gs_handle);
158
159 return 1;
160 }
161
162 /* disable fifo ready map */
164 if (res != 0)
165 {
166 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
167 (void)adxl362_deinit(&gs_handle);
168
169 return 1;
170 }
171
172 /* disable data ready map */
174 if (res != 0)
175 {
176 adxl362_interface_debug_print("adxl362: set interrupt pin1 map failed.\n");
177 (void)adxl362_deinit(&gs_handle);
178
179 return 1;
180 }
181
182 /* set interrupt pin2 active level low */
184 if (res != 0)
185 {
186 adxl362_interface_debug_print("adxl362: set interrupt pin2 active level failed.\n");
187 (void)adxl362_deinit(&gs_handle);
188
189 return 1;
190 }
191
192 /* disable awake map */
194 if (res != 0)
195 {
196 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
197 (void)adxl362_deinit(&gs_handle);
198
199 return 1;
200 }
201
202 /* disable inact map */
204 if (res != 0)
205 {
206 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
207 (void)adxl362_deinit(&gs_handle);
208
209 return 1;
210 }
211
212 /* disable act map */
214 if (res != 0)
215 {
216 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
217 (void)adxl362_deinit(&gs_handle);
218
219 return 1;
220 }
221
222 /* disable fifo overrun map */
224 if (res != 0)
225 {
226 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
227 (void)adxl362_deinit(&gs_handle);
228
229 return 1;
230 }
231
232 /* disable fifo watermark map */
234 if (res != 0)
235 {
236 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
237 (void)adxl362_deinit(&gs_handle);
238
239 return 1;
240 }
241
242 /* disable fifo ready map */
244 if (res != 0)
245 {
246 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
247 (void)adxl362_deinit(&gs_handle);
248
249 return 1;
250 }
251
252 /* disable data ready map */
254 if (res != 0)
255 {
256 adxl362_interface_debug_print("adxl362: set interrupt pin2 map failed.\n");
257 (void)adxl362_deinit(&gs_handle);
258
259 return 1;
260 }
261
262 /* set default bandwidth */
264 if (res != 0)
265 {
266 adxl362_interface_debug_print("adxl362: set bandwidth failed.\n");
267 (void)adxl362_deinit(&gs_handle);
268
269 return 1;
270 }
271
272 /* set default noise mode */
274 if (res != 0)
275 {
276 adxl362_interface_debug_print("adxl362: set noise mode failed.\n");
277 (void)adxl362_deinit(&gs_handle);
278
279 return 1;
280 }
281
282 /* disable wake up */
283 res = adxl362_set_wake_up(&gs_handle, ADXL362_BOOL_FALSE);
284 if (res != 0)
285 {
286 adxl362_interface_debug_print("adxl362: set wake up failed.\n");
287 (void)adxl362_deinit(&gs_handle);
288
289 return 1;
290 }
291
292 /* disable auto sleep */
294 if (res != 0)
295 {
296 adxl362_interface_debug_print("adxl362: set auto sleep failed.\n");
297 (void)adxl362_deinit(&gs_handle);
298
299 return 1;
300 }
301
302 /* disable interrupt pin2 as external sampling trigger */
304 if (res != 0)
305 {
306 adxl362_interface_debug_print("adxl362: set interrupt pin2 as external sampling trigger failed.\n");
307 (void)adxl362_deinit(&gs_handle);
308
309 return 1;
310 }
311
312 /* disable interrupt pin1 as external clock */
314 if (res != 0)
315 {
316 adxl362_interface_debug_print("adxl362: set interrupt pin1 as external clock failed.\n");
317 (void)adxl362_deinit(&gs_handle);
318
319 return 1;
320 }
321
322 /* set activity threshold 0x0000 */
323 res = adxl362_set_activity_threshold(&gs_handle, 0x0000);
324 if (res != 0)
325 {
326 adxl362_interface_debug_print("adxl362: set activity threshold failed.\n");
327 (void)adxl362_deinit(&gs_handle);
328
329 return 1;
330 }
331
332 /* set activity time 0x00 */
333 res = adxl362_set_activity_time(&gs_handle, 0x00);
334 if (res != 0)
335 {
336 adxl362_interface_debug_print("adxl362: set activity time failed.\n");
337 (void)adxl362_deinit(&gs_handle);
338
339 return 1;
340 }
341
342 /* set inactivity threshold 0x0000 */
343 res = adxl362_set_inactivity_threshold(&gs_handle, 0x0000);
344 if (res != 0)
345 {
346 adxl362_interface_debug_print("adxl362: set inactivity threshold failed.\n");
347 (void)adxl362_deinit(&gs_handle);
348
349 return 1;
350 }
351
352 /* set inactivity time 0x0000 */
353 res = adxl362_set_inactivity_time(&gs_handle, 0x0000);
354 if (res != 0)
355 {
356 adxl362_interface_debug_print("adxl362: set inactivity time failed.\n");
357 (void)adxl362_deinit(&gs_handle);
358
359 return 1;
360 }
361
362 /* set detect link mode */
364 if (res != 0)
365 {
366 adxl362_interface_debug_print("adxl362: set detect mode failed.\n");
367 (void)adxl362_deinit(&gs_handle);
368
369 return 1;
370 }
371
372 /* set inactivity detect trigger */
374 if (res != 0)
375 {
376 adxl362_interface_debug_print("adxl362: set inactivity detect trigger failed.\n");
377 (void)adxl362_deinit(&gs_handle);
378
379 return 1;
380 }
381
382 /* set activity detect trigger */
384 if (res != 0)
385 {
386 adxl362_interface_debug_print("adxl362: set activity detect trigger failed.\n");
387 (void)adxl362_deinit(&gs_handle);
388
389 return 1;
390 }
391
392 /* disable inactivity */
394 if (res != 0)
395 {
396 adxl362_interface_debug_print("adxl362: set inactivity failed.\n");
397 (void)adxl362_deinit(&gs_handle);
398
399 return 1;
400 }
401
402 /* disable activity */
403 res = adxl362_set_activity(&gs_handle, ADXL362_BOOL_FALSE);
404 if (res != 0)
405 {
406 adxl362_interface_debug_print("adxl362: set activity failed.\n");
407 (void)adxl362_deinit(&gs_handle);
408
409 return 1;
410 }
411
412 /* disable self test */
413 res = adxl362_set_self_test(&gs_handle, ADXL362_BOOL_FALSE);
414 if (res != 0)
415 {
416 adxl362_interface_debug_print("adxl362: set self test failed.\n");
417 (void)adxl362_deinit(&gs_handle);
418
419 return 1;
420 }
421
422 /* set default odr */
424 if (res != 0)
425 {
426 adxl362_interface_debug_print("adxl362: set odr failed.\n");
427 (void)adxl362_deinit(&gs_handle);
428
429 return 1;
430 }
431
432 /* set default range */
434 if (res != 0)
435 {
436 adxl362_interface_debug_print("adxl362: set range failed.\n");
437 (void)adxl362_deinit(&gs_handle);
438
439 return 1;
440 }
441
442 /* start measurement */
444 if (res != 0)
445 {
446 adxl362_interface_debug_print("adxl362: set mode failed.\n");
447 (void)adxl362_deinit(&gs_handle);
448
449 return 1;
450 }
451
452 return 0;
453}
454
463{
464 /* deinit */
465 if (adxl362_deinit(&gs_handle) != 0)
466 {
467 return 1;
468 }
469
470 return 0;
471}
472
481uint8_t adxl362_basic_read(float g[3])
482{
483 int16_t raw[3];
484
485 /* read data */
486 if (adxl362_read(&gs_handle, raw, g) != 0)
487 {
488 return 1;
489 }
490
491 return 0;
492}
493
502uint8_t adxl362_basic_read_8msb(float g[3])
503{
504 int8_t raw[3];
505
506 /* read data */
507 if (adxl362_read_8msb(&gs_handle, raw, g) != 0)
508 {
509 return 1;
510 }
511
512 return 0;
513}
514
524{
525 int16_t raw;
526
527 /* read data */
528 if (adxl362_read_temperature(&gs_handle, &raw, temp) != 0)
529 {
530 return 1;
531 }
532
533 return 0;
534}
driver adxl362 basic header file
uint8_t adxl362_set_range(adxl362_handle_t *handle, adxl362_range_t range)
set the measurement range
uint8_t adxl362_read_8msb(adxl362_handle_t *handle, int8_t raw[3], float g[3])
read the data with eight most significant bits
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_read(adxl362_handle_t *handle, int16_t raw[3], float g[3])
read the data
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_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_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_read_temperature(adxl362_handle_t *handle, int16_t *raw, float *temp)
read the temperature
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_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_DETECT_TRIGGER_REFERENCED
@ ADXL362_INTERRUPT_PIN_LOW
uint8_t adxl362_basic_deinit(void)
basic example deinit
uint8_t adxl362_basic_read(float g[3])
basic example read
#define ADXL362_BASIC_DEFAULT_BANDWIDTH_ODR
adxl362 basic example default definition
#define ADXL362_BASIC_DEFAULT_RANGE
#define ADXL362_BASIC_DEFAULT_ODR
uint8_t adxl362_basic_read_temperature(float *temp)
basic example read temperature
#define ADXL362_BASIC_DEFAULT_NOISE_MODE
uint8_t adxl362_basic_init(void)
basic example init
uint8_t adxl362_basic_read_8msb(float g[3])
basic example read 8msb
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
void adxl362_interface_receive_callback(uint8_t type)
interface receive callback
uint8_t adxl362_interface_spi_read_address16(uint16_t addr, uint8_t *buf, uint16_t len)
interface spi bus read