1 /**
2 ******************************************************************************
3 * @file lsm6dso_reg.c
4 * @author Sensors Software Solution Team
5 * @brief LSM6DSO driver file
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>© Copyright (c) 2021 STMicroelectronics.
10 * All rights reserved.</center></h2>
11 *
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
16 *
17 ******************************************************************************
18 */
19
20 #include "lsm6dso_reg.h"
21 #include <stddef.h>
22
23 /**
24 * @defgroup LSM6DSO
25 * @brief This file provides a set of functions needed to drive the
26 * lsm6dso enhanced inertial module.
27 * @{
28 *
29 */
30
31 /**
32 * @defgroup LSM6DSO_Interfaces_Functions
33 * @brief This section provide a set of functions used to read and
34 * write a generic register of the device.
35 * MANDATORY: return 0 -> no Error.
36 * @{
37 *
38 */
39
40 /**
41 * @brief Read generic device register
42 *
43 * @param ctx read / write interface definitions(ptr)
44 * @param reg register to read
45 * @param data pointer to buffer that store the data read(ptr)
46 * @param len number of consecutive register to read
47 * @retval interface status (MANDATORY: return 0 -> no Error)
48 *
49 */
lsm6dso_read_reg(stmdev_ctx_t * ctx,uint8_t reg,uint8_t * data,uint16_t len)50 int32_t __weak lsm6dso_read_reg(stmdev_ctx_t *ctx, uint8_t reg,
51 uint8_t *data,
52 uint16_t len)
53 {
54 int32_t ret;
55
56 ret = ctx->read_reg(ctx->handle, reg, data, len);
57
58 return ret;
59 }
60
61 /**
62 * @brief Write generic device register
63 *
64 * @param ctx read / write interface definitions(ptr)
65 * @param reg register to write
66 * @param data pointer to data to write in register reg(ptr)
67 * @param len number of consecutive register to write
68 * @retval interface status (MANDATORY: return 0 -> no Error)
69 *
70 */
lsm6dso_write_reg(stmdev_ctx_t * ctx,uint8_t reg,uint8_t * data,uint16_t len)71 int32_t __weak lsm6dso_write_reg(stmdev_ctx_t *ctx, uint8_t reg,
72 uint8_t *data,
73 uint16_t len)
74 {
75 int32_t ret;
76
77 ret = ctx->write_reg(ctx->handle, reg, data, len);
78
79 return ret;
80 }
81
82 /**
83 * @}
84 *
85 */
86
87 /**
88 * @defgroup LSM6DSOX_Private_functions
89 * @brief Section collect all the utility functions needed by APIs.
90 * @{
91 *
92 */
93
bytecpy(uint8_t * target,uint8_t * source)94 static void bytecpy(uint8_t *target, uint8_t *source)
95 {
96 if ((target != NULL) && (source != NULL))
97 {
98 *target = *source;
99 }
100 }
101
102 /**
103 * @defgroup LSM6DSO_Sensitivity
104 * @brief These functions convert raw-data into engineering units.
105 * @{
106 *
107 */
lsm6dso_from_fs2_to_mg(int16_t lsb)108 float_t lsm6dso_from_fs2_to_mg(int16_t lsb)
109 {
110 return ((float_t)lsb) * 0.061f;
111 }
112
lsm6dso_from_fs4_to_mg(int16_t lsb)113 float_t lsm6dso_from_fs4_to_mg(int16_t lsb)
114 {
115 return ((float_t)lsb) * 0.122f;
116 }
117
lsm6dso_from_fs8_to_mg(int16_t lsb)118 float_t lsm6dso_from_fs8_to_mg(int16_t lsb)
119 {
120 return ((float_t)lsb) * 0.244f;
121 }
122
lsm6dso_from_fs16_to_mg(int16_t lsb)123 float_t lsm6dso_from_fs16_to_mg(int16_t lsb)
124 {
125 return ((float_t)lsb) * 0.488f;
126 }
127
lsm6dso_from_fs125_to_mdps(int16_t lsb)128 float_t lsm6dso_from_fs125_to_mdps(int16_t lsb)
129 {
130 return ((float_t)lsb) * 4.375f;
131 }
132
lsm6dso_from_fs500_to_mdps(int16_t lsb)133 float_t lsm6dso_from_fs500_to_mdps(int16_t lsb)
134 {
135 return ((float_t)lsb) * 17.50f;
136 }
137
lsm6dso_from_fs250_to_mdps(int16_t lsb)138 float_t lsm6dso_from_fs250_to_mdps(int16_t lsb)
139 {
140 return ((float_t)lsb) * 8.750f;
141 }
142
lsm6dso_from_fs1000_to_mdps(int16_t lsb)143 float_t lsm6dso_from_fs1000_to_mdps(int16_t lsb)
144 {
145 return ((float_t)lsb) * 35.0f;
146 }
147
lsm6dso_from_fs2000_to_mdps(int16_t lsb)148 float_t lsm6dso_from_fs2000_to_mdps(int16_t lsb)
149 {
150 return ((float_t)lsb) * 70.0f;
151 }
152
lsm6dso_from_lsb_to_celsius(int16_t lsb)153 float_t lsm6dso_from_lsb_to_celsius(int16_t lsb)
154 {
155 return (((float_t)lsb / 256.0f) + 25.0f);
156 }
157
lsm6dso_from_lsb_to_nsec(int16_t lsb)158 float_t lsm6dso_from_lsb_to_nsec(int16_t lsb)
159 {
160 return ((float_t)lsb * 25000.0f);
161 }
162
163 /**
164 * @}
165 *
166 */
167
168 /**
169 * @defgroup LSM6DSO_Data_Generation
170 * @brief This section groups all the functions concerning
171 * data generation.
172 *
173 */
174
175 /**
176 * @brief Accelerometer full-scale selection.[set]
177 *
178 * @param ctx read / write interface definitions
179 * @param val change the values of fs_xl in reg CTRL1_XL
180 * @retval interface status (MANDATORY: return 0 -> no Error)
181 *
182 */
lsm6dso_xl_full_scale_set(stmdev_ctx_t * ctx,lsm6dso_fs_xl_t val)183 int32_t lsm6dso_xl_full_scale_set(stmdev_ctx_t *ctx,
184 lsm6dso_fs_xl_t val)
185 {
186 lsm6dso_ctrl1_xl_t reg;
187 int32_t ret;
188
189 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_XL, (uint8_t *)®, 1);
190
191 if (ret == 0)
192 {
193 reg.fs_xl = (uint8_t) val;
194 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL1_XL, (uint8_t *)®, 1);
195 }
196
197 return ret;
198 }
199
200 /**
201 * @brief Accelerometer full-scale selection.[get]
202 *
203 * @param ctx read / write interface definitions
204 * @param val Get the values of fs_xl in reg CTRL1_XL
205 * @retval interface status (MANDATORY: return 0 -> no Error)
206 *
207 */
lsm6dso_xl_full_scale_get(stmdev_ctx_t * ctx,lsm6dso_fs_xl_t * val)208 int32_t lsm6dso_xl_full_scale_get(stmdev_ctx_t *ctx,
209 lsm6dso_fs_xl_t *val)
210 {
211 lsm6dso_ctrl1_xl_t reg;
212 int32_t ret;
213
214 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_XL, (uint8_t *)®, 1);
215
216 switch (reg.fs_xl)
217 {
218 case LSM6DSO_2g:
219 *val = LSM6DSO_2g;
220 break;
221
222 case LSM6DSO_16g:
223 *val = LSM6DSO_16g;
224 break;
225
226 case LSM6DSO_4g:
227 *val = LSM6DSO_4g;
228 break;
229
230 case LSM6DSO_8g:
231 *val = LSM6DSO_8g;
232 break;
233
234 default:
235 *val = LSM6DSO_2g;
236 break;
237 }
238
239 return ret;
240 }
241
242 /**
243 * @brief Accelerometer UI data rate selection.[set]
244 *
245 * @param ctx read / write interface definitions
246 * @param val change the values of odr_xl in reg CTRL1_XL
247 * @retval interface status (MANDATORY: return 0 -> no Error)
248 *
249 */
lsm6dso_xl_data_rate_set(stmdev_ctx_t * ctx,lsm6dso_odr_xl_t val)250 int32_t lsm6dso_xl_data_rate_set(stmdev_ctx_t *ctx,
251 lsm6dso_odr_xl_t val)
252 {
253 lsm6dso_odr_xl_t odr_xl = val;
254 lsm6dso_emb_fsm_enable_t fsm_enable;
255 lsm6dso_fsm_odr_t fsm_odr;
256 lsm6dso_ctrl1_xl_t reg;
257 int32_t ret;
258
259 /* Check the Finite State Machine data rate constraints */
260 ret = lsm6dso_fsm_enable_get(ctx, &fsm_enable);
261
262 if (ret == 0)
263 {
264 if ((fsm_enable.fsm_enable_a.fsm1_en |
265 fsm_enable.fsm_enable_a.fsm2_en |
266 fsm_enable.fsm_enable_a.fsm3_en |
267 fsm_enable.fsm_enable_a.fsm4_en |
268 fsm_enable.fsm_enable_a.fsm5_en |
269 fsm_enable.fsm_enable_a.fsm6_en |
270 fsm_enable.fsm_enable_a.fsm7_en |
271 fsm_enable.fsm_enable_a.fsm8_en |
272 fsm_enable.fsm_enable_b.fsm9_en |
273 fsm_enable.fsm_enable_b.fsm10_en |
274 fsm_enable.fsm_enable_b.fsm11_en |
275 fsm_enable.fsm_enable_b.fsm12_en |
276 fsm_enable.fsm_enable_b.fsm13_en |
277 fsm_enable.fsm_enable_b.fsm14_en |
278 fsm_enable.fsm_enable_b.fsm15_en |
279 fsm_enable.fsm_enable_b.fsm16_en) == PROPERTY_ENABLE)
280 {
281 ret = lsm6dso_fsm_data_rate_get(ctx, &fsm_odr);
282
283 if (ret == 0)
284 {
285 switch (fsm_odr)
286 {
287 case LSM6DSO_ODR_FSM_12Hz5:
288 if (val == LSM6DSO_XL_ODR_OFF)
289 {
290 odr_xl = LSM6DSO_XL_ODR_12Hz5;
291 }
292
293 else
294 {
295 odr_xl = val;
296 }
297
298 break;
299
300 case LSM6DSO_ODR_FSM_26Hz:
301 if (val == LSM6DSO_XL_ODR_OFF)
302 {
303 odr_xl = LSM6DSO_XL_ODR_26Hz;
304 }
305
306 else if (val == LSM6DSO_XL_ODR_12Hz5)
307 {
308 odr_xl = LSM6DSO_XL_ODR_26Hz;
309 }
310
311 else
312 {
313 odr_xl = val;
314 }
315
316 break;
317
318 case LSM6DSO_ODR_FSM_52Hz:
319 if (val == LSM6DSO_XL_ODR_OFF)
320 {
321 odr_xl = LSM6DSO_XL_ODR_52Hz;
322 }
323
324 else if (val == LSM6DSO_XL_ODR_12Hz5)
325 {
326 odr_xl = LSM6DSO_XL_ODR_52Hz;
327 }
328
329 else if (val == LSM6DSO_XL_ODR_26Hz)
330 {
331 odr_xl = LSM6DSO_XL_ODR_52Hz;
332 }
333
334 else
335 {
336 odr_xl = val;
337 }
338
339 break;
340
341 case LSM6DSO_ODR_FSM_104Hz:
342 if (val == LSM6DSO_XL_ODR_OFF)
343 {
344 odr_xl = LSM6DSO_XL_ODR_104Hz;
345 }
346
347 else if (val == LSM6DSO_XL_ODR_12Hz5)
348 {
349 odr_xl = LSM6DSO_XL_ODR_104Hz;
350 }
351
352 else if (val == LSM6DSO_XL_ODR_26Hz)
353 {
354 odr_xl = LSM6DSO_XL_ODR_104Hz;
355 }
356
357 else if (val == LSM6DSO_XL_ODR_52Hz)
358 {
359 odr_xl = LSM6DSO_XL_ODR_104Hz;
360 }
361
362 else
363 {
364 odr_xl = val;
365 }
366
367 break;
368
369 default:
370 odr_xl = val;
371 break;
372 }
373 }
374 }
375 }
376
377 if (ret == 0)
378 {
379 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_XL, (uint8_t *)®, 1);
380 }
381
382 if (ret == 0)
383 {
384 reg.odr_xl = (uint8_t) odr_xl;
385 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL1_XL, (uint8_t *)®, 1);
386 }
387
388 return ret;
389 }
390
391 /**
392 * @brief Accelerometer UI data rate selection.[get]
393 *
394 * @param ctx read / write interface definitions
395 * @param val Get the values of odr_xl in reg CTRL1_XL
396 * @retval interface status (MANDATORY: return 0 -> no Error)
397 *
398 */
lsm6dso_xl_data_rate_get(stmdev_ctx_t * ctx,lsm6dso_odr_xl_t * val)399 int32_t lsm6dso_xl_data_rate_get(stmdev_ctx_t *ctx,
400 lsm6dso_odr_xl_t *val)
401 {
402 lsm6dso_ctrl1_xl_t reg;
403 int32_t ret;
404
405 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_XL, (uint8_t *)®, 1);
406
407 switch (reg.odr_xl)
408 {
409 case LSM6DSO_XL_ODR_OFF:
410 *val = LSM6DSO_XL_ODR_OFF;
411 break;
412
413 case LSM6DSO_XL_ODR_12Hz5:
414 *val = LSM6DSO_XL_ODR_12Hz5;
415 break;
416
417 case LSM6DSO_XL_ODR_26Hz:
418 *val = LSM6DSO_XL_ODR_26Hz;
419 break;
420
421 case LSM6DSO_XL_ODR_52Hz:
422 *val = LSM6DSO_XL_ODR_52Hz;
423 break;
424
425 case LSM6DSO_XL_ODR_104Hz:
426 *val = LSM6DSO_XL_ODR_104Hz;
427 break;
428
429 case LSM6DSO_XL_ODR_208Hz:
430 *val = LSM6DSO_XL_ODR_208Hz;
431 break;
432
433 case LSM6DSO_XL_ODR_417Hz:
434 *val = LSM6DSO_XL_ODR_417Hz;
435 break;
436
437 case LSM6DSO_XL_ODR_833Hz:
438 *val = LSM6DSO_XL_ODR_833Hz;
439 break;
440
441 case LSM6DSO_XL_ODR_1667Hz:
442 *val = LSM6DSO_XL_ODR_1667Hz;
443 break;
444
445 case LSM6DSO_XL_ODR_3333Hz:
446 *val = LSM6DSO_XL_ODR_3333Hz;
447 break;
448
449 case LSM6DSO_XL_ODR_6667Hz:
450 *val = LSM6DSO_XL_ODR_6667Hz;
451 break;
452
453 case LSM6DSO_XL_ODR_1Hz6:
454 *val = LSM6DSO_XL_ODR_1Hz6;
455 break;
456
457 default:
458 *val = LSM6DSO_XL_ODR_OFF;
459 break;
460 }
461
462 return ret;
463 }
464
465 /**
466 * @brief Gyroscope UI chain full-scale selection.[set]
467 *
468 * @param ctx read / write interface definitions
469 * @param val change the values of fs_g in reg CTRL2_G
470 * @retval interface status (MANDATORY: return 0 -> no Error)
471 *
472 */
lsm6dso_gy_full_scale_set(stmdev_ctx_t * ctx,lsm6dso_fs_g_t val)473 int32_t lsm6dso_gy_full_scale_set(stmdev_ctx_t *ctx,
474 lsm6dso_fs_g_t val)
475 {
476 lsm6dso_ctrl2_g_t reg;
477 int32_t ret;
478
479 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL2_G, (uint8_t *)®, 1);
480
481 if (ret == 0)
482 {
483 reg.fs_g = (uint8_t) val;
484 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL2_G, (uint8_t *)®, 1);
485 }
486
487 return ret;
488 }
489
490 /**
491 * @brief Gyroscope UI chain full-scale selection.[get]
492 *
493 * @param ctx read / write interface definitions
494 * @param val Get the values of fs_g in reg CTRL2_G
495 * @retval interface status (MANDATORY: return 0 -> no Error)
496 *
497 */
lsm6dso_gy_full_scale_get(stmdev_ctx_t * ctx,lsm6dso_fs_g_t * val)498 int32_t lsm6dso_gy_full_scale_get(stmdev_ctx_t *ctx,
499 lsm6dso_fs_g_t *val)
500 {
501 lsm6dso_ctrl2_g_t reg;
502 int32_t ret;
503
504 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL2_G, (uint8_t *)®, 1);
505
506 switch (reg.fs_g)
507 {
508 case LSM6DSO_250dps:
509 *val = LSM6DSO_250dps;
510 break;
511
512 case LSM6DSO_125dps:
513 *val = LSM6DSO_125dps;
514 break;
515
516 case LSM6DSO_500dps:
517 *val = LSM6DSO_500dps;
518 break;
519
520 case LSM6DSO_1000dps:
521 *val = LSM6DSO_1000dps;
522 break;
523
524 case LSM6DSO_2000dps:
525 *val = LSM6DSO_2000dps;
526 break;
527
528 default:
529 *val = LSM6DSO_250dps;
530 break;
531 }
532
533 return ret;
534 }
535
536 /**
537 * @brief Gyroscope UI data rate selection.[set]
538 *
539 * @param ctx read / write interface definitions
540 * @param val change the values of odr_g in reg CTRL2_G
541 * @retval interface status (MANDATORY: return 0 -> no Error)
542 *
543 */
lsm6dso_gy_data_rate_set(stmdev_ctx_t * ctx,lsm6dso_odr_g_t val)544 int32_t lsm6dso_gy_data_rate_set(stmdev_ctx_t *ctx,
545 lsm6dso_odr_g_t val)
546 {
547 lsm6dso_odr_g_t odr_gy = val;
548 lsm6dso_emb_fsm_enable_t fsm_enable;
549 lsm6dso_fsm_odr_t fsm_odr;
550 lsm6dso_ctrl2_g_t reg;
551 int32_t ret;
552
553 /* Check the Finite State Machine data rate constraints */
554 ret = lsm6dso_fsm_enable_get(ctx, &fsm_enable);
555
556 if (ret == 0)
557 {
558 if ((fsm_enable.fsm_enable_a.fsm1_en |
559 fsm_enable.fsm_enable_a.fsm2_en |
560 fsm_enable.fsm_enable_a.fsm3_en |
561 fsm_enable.fsm_enable_a.fsm4_en |
562 fsm_enable.fsm_enable_a.fsm5_en |
563 fsm_enable.fsm_enable_a.fsm6_en |
564 fsm_enable.fsm_enable_a.fsm7_en |
565 fsm_enable.fsm_enable_a.fsm8_en |
566 fsm_enable.fsm_enable_b.fsm9_en |
567 fsm_enable.fsm_enable_b.fsm10_en |
568 fsm_enable.fsm_enable_b.fsm11_en |
569 fsm_enable.fsm_enable_b.fsm12_en |
570 fsm_enable.fsm_enable_b.fsm13_en |
571 fsm_enable.fsm_enable_b.fsm14_en |
572 fsm_enable.fsm_enable_b.fsm15_en |
573 fsm_enable.fsm_enable_b.fsm16_en) == PROPERTY_ENABLE)
574 {
575 ret = lsm6dso_fsm_data_rate_get(ctx, &fsm_odr);
576
577 if (ret == 0)
578 {
579 switch (fsm_odr)
580 {
581 case LSM6DSO_ODR_FSM_12Hz5:
582 if (val == LSM6DSO_GY_ODR_OFF)
583 {
584 odr_gy = LSM6DSO_GY_ODR_12Hz5;
585 }
586
587 else
588 {
589 odr_gy = val;
590 }
591
592 break;
593
594 case LSM6DSO_ODR_FSM_26Hz:
595 if (val == LSM6DSO_GY_ODR_OFF)
596 {
597 odr_gy = LSM6DSO_GY_ODR_26Hz;
598 }
599
600 else if (val == LSM6DSO_GY_ODR_12Hz5)
601 {
602 odr_gy = LSM6DSO_GY_ODR_26Hz;
603 }
604
605 else
606 {
607 odr_gy = val;
608 }
609
610 break;
611
612 case LSM6DSO_ODR_FSM_52Hz:
613 if (val == LSM6DSO_GY_ODR_OFF)
614 {
615 odr_gy = LSM6DSO_GY_ODR_52Hz;
616 }
617
618 else if (val == LSM6DSO_GY_ODR_12Hz5)
619 {
620 odr_gy = LSM6DSO_GY_ODR_52Hz;
621 }
622
623 else if (val == LSM6DSO_GY_ODR_26Hz)
624 {
625 odr_gy = LSM6DSO_GY_ODR_52Hz;
626 }
627
628 else
629 {
630 odr_gy = val;
631 }
632
633 break;
634
635 case LSM6DSO_ODR_FSM_104Hz:
636 if (val == LSM6DSO_GY_ODR_OFF)
637 {
638 odr_gy = LSM6DSO_GY_ODR_104Hz;
639 }
640
641 else if (val == LSM6DSO_GY_ODR_12Hz5)
642 {
643 odr_gy = LSM6DSO_GY_ODR_104Hz;
644 }
645
646 else if (val == LSM6DSO_GY_ODR_26Hz)
647 {
648 odr_gy = LSM6DSO_GY_ODR_104Hz;
649 }
650
651 else if (val == LSM6DSO_GY_ODR_52Hz)
652 {
653 odr_gy = LSM6DSO_GY_ODR_104Hz;
654 }
655
656 else
657 {
658 odr_gy = val;
659 }
660
661 break;
662
663 default:
664 odr_gy = val;
665 break;
666 }
667 }
668 }
669 }
670
671 if (ret == 0)
672 {
673 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL2_G, (uint8_t *)®, 1);
674 }
675
676 if (ret == 0)
677 {
678 reg.odr_g = (uint8_t) odr_gy;
679 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL2_G, (uint8_t *)®, 1);
680 }
681
682 return ret;
683 }
684
685 /**
686 * @brief Gyroscope UI data rate selection.[get]
687 *
688 * @param ctx read / write interface definitions
689 * @param val Get the values of odr_g in reg CTRL2_G
690 * @retval interface status (MANDATORY: return 0 -> no Error)
691 *
692 */
lsm6dso_gy_data_rate_get(stmdev_ctx_t * ctx,lsm6dso_odr_g_t * val)693 int32_t lsm6dso_gy_data_rate_get(stmdev_ctx_t *ctx,
694 lsm6dso_odr_g_t *val)
695 {
696 lsm6dso_ctrl2_g_t reg;
697 int32_t ret;
698
699 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL2_G, (uint8_t *)®, 1);
700
701 switch (reg.odr_g)
702 {
703 case LSM6DSO_GY_ODR_OFF:
704 *val = LSM6DSO_GY_ODR_OFF;
705 break;
706
707 case LSM6DSO_GY_ODR_12Hz5:
708 *val = LSM6DSO_GY_ODR_12Hz5;
709 break;
710
711 case LSM6DSO_GY_ODR_26Hz:
712 *val = LSM6DSO_GY_ODR_26Hz;
713 break;
714
715 case LSM6DSO_GY_ODR_52Hz:
716 *val = LSM6DSO_GY_ODR_52Hz;
717 break;
718
719 case LSM6DSO_GY_ODR_104Hz:
720 *val = LSM6DSO_GY_ODR_104Hz;
721 break;
722
723 case LSM6DSO_GY_ODR_208Hz:
724 *val = LSM6DSO_GY_ODR_208Hz;
725 break;
726
727 case LSM6DSO_GY_ODR_417Hz:
728 *val = LSM6DSO_GY_ODR_417Hz;
729 break;
730
731 case LSM6DSO_GY_ODR_833Hz:
732 *val = LSM6DSO_GY_ODR_833Hz;
733 break;
734
735 case LSM6DSO_GY_ODR_1667Hz:
736 *val = LSM6DSO_GY_ODR_1667Hz;
737 break;
738
739 case LSM6DSO_GY_ODR_3333Hz:
740 *val = LSM6DSO_GY_ODR_3333Hz;
741 break;
742
743 case LSM6DSO_GY_ODR_6667Hz:
744 *val = LSM6DSO_GY_ODR_6667Hz;
745 break;
746
747 default:
748 *val = LSM6DSO_GY_ODR_OFF;
749 break;
750 }
751
752 return ret;
753 }
754
755 /**
756 * @brief Block data update.[set]
757 *
758 * @param ctx read / write interface definitions
759 * @param val change the values of bdu in reg CTRL3_C
760 * @retval interface status (MANDATORY: return 0 -> no Error)
761 *
762 */
lsm6dso_block_data_update_set(stmdev_ctx_t * ctx,uint8_t val)763 int32_t lsm6dso_block_data_update_set(stmdev_ctx_t *ctx, uint8_t val)
764 {
765 lsm6dso_ctrl3_c_t reg;
766 int32_t ret;
767
768 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
769
770 if (ret == 0)
771 {
772 reg.bdu = val;
773 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
774 }
775
776 return ret;
777 }
778
779 /**
780 * @brief Block data update.[get]
781 *
782 * @param ctx read / write interface definitions
783 * @param val Get the values of bdu in reg CTRL3_C
784 * @retval interface status (MANDATORY: return 0 -> no Error)
785 *
786 */
lsm6dso_block_data_update_get(stmdev_ctx_t * ctx,uint8_t * val)787 int32_t lsm6dso_block_data_update_get(stmdev_ctx_t *ctx, uint8_t *val)
788 {
789 lsm6dso_ctrl3_c_t reg;
790 int32_t ret;
791
792 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
793 *val = reg.bdu;
794
795 return ret;
796 }
797
798 /**
799 * @brief Weight of XL user offset bits of registers X_OFS_USR (73h),
800 * Y_OFS_USR (74h), Z_OFS_USR (75h).[set]
801 *
802 * @param ctx read / write interface definitions
803 * @param val change the values of usr_off_w in reg CTRL6_C
804 * @retval interface status (MANDATORY: return 0 -> no Error)
805 *
806 */
lsm6dso_xl_offset_weight_set(stmdev_ctx_t * ctx,lsm6dso_usr_off_w_t val)807 int32_t lsm6dso_xl_offset_weight_set(stmdev_ctx_t *ctx,
808 lsm6dso_usr_off_w_t val)
809 {
810 lsm6dso_ctrl6_c_t reg;
811 int32_t ret;
812
813 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL6_C, (uint8_t *)®, 1);
814
815 if (ret == 0)
816 {
817 reg.usr_off_w = (uint8_t)val;
818 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL6_C, (uint8_t *)®, 1);
819 }
820
821 return ret;
822 }
823
824 /**
825 * @brief Weight of XL user offset bits of registers X_OFS_USR (73h),
826 * Y_OFS_USR (74h), Z_OFS_USR (75h).[get]
827 *
828 * @param ctx read / write interface definitions
829 * @param val Get the values of usr_off_w in reg CTRL6_C
830 * @retval interface status (MANDATORY: return 0 -> no Error)
831 *
832 */
lsm6dso_xl_offset_weight_get(stmdev_ctx_t * ctx,lsm6dso_usr_off_w_t * val)833 int32_t lsm6dso_xl_offset_weight_get(stmdev_ctx_t *ctx,
834 lsm6dso_usr_off_w_t *val)
835 {
836 lsm6dso_ctrl6_c_t reg;
837 int32_t ret;
838
839 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL6_C, (uint8_t *)®, 1);
840
841 switch (reg.usr_off_w)
842 {
843 case LSM6DSO_LSb_1mg:
844 *val = LSM6DSO_LSb_1mg;
845 break;
846
847 case LSM6DSO_LSb_16mg:
848 *val = LSM6DSO_LSb_16mg;
849 break;
850
851 default:
852 *val = LSM6DSO_LSb_1mg;
853 break;
854 }
855
856 return ret;
857 }
858
859 /**
860 * @brief Accelerometer power mode.[set]
861 *
862 * @param ctx read / write interface definitions
863 * @param val change the values of xl_hm_mode in
864 * reg CTRL6_C
865 * @retval interface status (MANDATORY: return 0 -> no Error)
866 *
867 */
lsm6dso_xl_power_mode_set(stmdev_ctx_t * ctx,lsm6dso_xl_hm_mode_t val)868 int32_t lsm6dso_xl_power_mode_set(stmdev_ctx_t *ctx,
869 lsm6dso_xl_hm_mode_t val)
870 {
871 lsm6dso_ctrl5_c_t ctrl5_c;
872 lsm6dso_ctrl6_c_t ctrl6_c;
873 int32_t ret;
874
875 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL5_C, (uint8_t *) &ctrl5_c, 1);
876
877 if (ret == 0)
878 {
879 ctrl5_c.xl_ulp_en = ((uint8_t)val & 0x02U) >> 1;
880 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL5_C, (uint8_t *) &ctrl5_c, 1);
881 }
882
883 if (ret == 0)
884 {
885 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL6_C, (uint8_t *) &ctrl6_c, 1);
886 }
887
888 if (ret == 0)
889 {
890 ctrl6_c.xl_hm_mode = (uint8_t)val & 0x01U;
891 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL6_C, (uint8_t *) &ctrl6_c, 1);
892 }
893
894 return ret;
895 }
896
897 /**
898 * @brief Accelerometer power mode.[get]
899 *
900 * @param ctx read / write interface definitions
901 * @param val Get the values of xl_hm_mode in reg CTRL6_C
902 * @retval interface status (MANDATORY: return 0 -> no Error)
903 *
904 */
lsm6dso_xl_power_mode_get(stmdev_ctx_t * ctx,lsm6dso_xl_hm_mode_t * val)905 int32_t lsm6dso_xl_power_mode_get(stmdev_ctx_t *ctx,
906 lsm6dso_xl_hm_mode_t *val)
907 {
908 lsm6dso_ctrl5_c_t ctrl5_c;
909 lsm6dso_ctrl6_c_t ctrl6_c;
910 int32_t ret;
911
912 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL5_C, (uint8_t *) &ctrl5_c, 1);
913
914 if (ret == 0)
915 {
916 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL6_C, (uint8_t *) &ctrl6_c, 1);
917
918 switch ((ctrl5_c.xl_ulp_en << 1) | ctrl6_c.xl_hm_mode)
919 {
920 case LSM6DSO_HIGH_PERFORMANCE_MD:
921 *val = LSM6DSO_HIGH_PERFORMANCE_MD;
922 break;
923
924 case LSM6DSO_LOW_NORMAL_POWER_MD:
925 *val = LSM6DSO_LOW_NORMAL_POWER_MD;
926 break;
927
928 case LSM6DSO_ULTRA_LOW_POWER_MD:
929 *val = LSM6DSO_ULTRA_LOW_POWER_MD;
930 break;
931
932 default:
933 *val = LSM6DSO_HIGH_PERFORMANCE_MD;
934 break;
935 }
936 }
937
938 return ret;
939 }
940
941 /**
942 * @brief Operating mode for gyroscope.[set]
943 *
944 * @param ctx read / write interface definitions
945 * @param val change the values of g_hm_mode in reg CTRL7_G
946 * @retval interface status (MANDATORY: return 0 -> no Error)
947 *
948 */
lsm6dso_gy_power_mode_set(stmdev_ctx_t * ctx,lsm6dso_g_hm_mode_t val)949 int32_t lsm6dso_gy_power_mode_set(stmdev_ctx_t *ctx,
950 lsm6dso_g_hm_mode_t val)
951 {
952 lsm6dso_ctrl7_g_t reg;
953 int32_t ret;
954
955 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL7_G, (uint8_t *)®, 1);
956
957 if (ret == 0)
958 {
959 reg.g_hm_mode = (uint8_t)val;
960 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL7_G, (uint8_t *)®, 1);
961 }
962
963 return ret;
964 }
965
966 /**
967 * @brief Operating mode for gyroscope.[get]
968 *
969 * @param ctx read / write interface definitions
970 * @param val Get the values of g_hm_mode in reg CTRL7_G
971 * @retval interface status (MANDATORY: return 0 -> no Error)
972 *
973 */
lsm6dso_gy_power_mode_get(stmdev_ctx_t * ctx,lsm6dso_g_hm_mode_t * val)974 int32_t lsm6dso_gy_power_mode_get(stmdev_ctx_t *ctx,
975 lsm6dso_g_hm_mode_t *val)
976 {
977 lsm6dso_ctrl7_g_t reg;
978 int32_t ret;
979
980 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL7_G, (uint8_t *)®, 1);
981
982 switch (reg.g_hm_mode)
983 {
984 case LSM6DSO_GY_HIGH_PERFORMANCE:
985 *val = LSM6DSO_GY_HIGH_PERFORMANCE;
986 break;
987
988 case LSM6DSO_GY_NORMAL:
989 *val = LSM6DSO_GY_NORMAL;
990 break;
991
992 default:
993 *val = LSM6DSO_GY_HIGH_PERFORMANCE;
994 break;
995 }
996
997 return ret;
998 }
999
1000 /**
1001 * @brief The STATUS_REG register is read by the primary interface.[get]
1002 *
1003 * @param ctx read / write interface definitions
1004 * @param val register STATUS_REG
1005 * @retval interface status (MANDATORY: return 0 -> no Error)
1006 *
1007 */
lsm6dso_status_reg_get(stmdev_ctx_t * ctx,lsm6dso_status_reg_t * val)1008 int32_t lsm6dso_status_reg_get(stmdev_ctx_t *ctx,
1009 lsm6dso_status_reg_t *val)
1010 {
1011 int32_t ret;
1012
1013 ret = lsm6dso_read_reg(ctx, LSM6DSO_STATUS_REG, (uint8_t *) val, 1);
1014
1015 return ret;
1016 }
1017
1018 /**
1019 * @brief Accelerometer new data available.[get]
1020 *
1021 * @param ctx read / write interface definitions
1022 * @param val Get the values of xlda in reg STATUS_REG
1023 * @retval interface status (MANDATORY: return 0 -> no Error)
1024 *
1025 */
lsm6dso_xl_flag_data_ready_get(stmdev_ctx_t * ctx,uint8_t * val)1026 int32_t lsm6dso_xl_flag_data_ready_get(stmdev_ctx_t *ctx,
1027 uint8_t *val)
1028 {
1029 lsm6dso_status_reg_t reg;
1030 int32_t ret;
1031
1032 ret = lsm6dso_read_reg(ctx, LSM6DSO_STATUS_REG, (uint8_t *)®, 1);
1033 *val = reg.xlda;
1034
1035 return ret;
1036 }
1037
1038 /**
1039 * @brief Gyroscope new data available.[get]
1040 *
1041 * @param ctx read / write interface definitions
1042 * @param val Get the values of gda in reg STATUS_REG
1043 * @retval interface status (MANDATORY: return 0 -> no Error)
1044 *
1045 */
lsm6dso_gy_flag_data_ready_get(stmdev_ctx_t * ctx,uint8_t * val)1046 int32_t lsm6dso_gy_flag_data_ready_get(stmdev_ctx_t *ctx,
1047 uint8_t *val)
1048 {
1049 lsm6dso_status_reg_t reg;
1050 int32_t ret;
1051
1052 ret = lsm6dso_read_reg(ctx, LSM6DSO_STATUS_REG, (uint8_t *)®, 1);
1053 *val = reg.gda;
1054
1055 return ret;
1056 }
1057
1058 /**
1059 * @brief Temperature new data available.[get]
1060 *
1061 * @param ctx read / write interface definitions
1062 * @param val Get the values of tda in reg STATUS_REG
1063 * @retval interface status (MANDATORY: return 0 -> no Error)
1064 *
1065 */
lsm6dso_temp_flag_data_ready_get(stmdev_ctx_t * ctx,uint8_t * val)1066 int32_t lsm6dso_temp_flag_data_ready_get(stmdev_ctx_t *ctx,
1067 uint8_t *val)
1068 {
1069 lsm6dso_status_reg_t reg;
1070 int32_t ret;
1071
1072 ret = lsm6dso_read_reg(ctx, LSM6DSO_STATUS_REG, (uint8_t *)®, 1);
1073 *val = reg.tda;
1074
1075 return ret;
1076 }
1077
1078 /**
1079 * @brief Accelerometer X-axis user offset correction expressed in
1080 * two's complement, weight depends on USR_OFF_W in CTRL6_C (15h).
1081 * The value must be in the range [-127 127].[set]
1082 *
1083 * @param ctx read / write interface definitions
1084 * @param buff buffer that contains data to write
1085 * @retval interface status (MANDATORY: return 0 -> no Error)
1086 *
1087 */
lsm6dso_xl_usr_offset_x_set(stmdev_ctx_t * ctx,uint8_t * buff)1088 int32_t lsm6dso_xl_usr_offset_x_set(stmdev_ctx_t *ctx, uint8_t *buff)
1089 {
1090 int32_t ret;
1091
1092 ret = lsm6dso_write_reg(ctx, LSM6DSO_X_OFS_USR, buff, 1);
1093
1094 return ret;
1095 }
1096
1097 /**
1098 * @brief Accelerometer X-axis user offset correction expressed in two's
1099 * complement, weight depends on USR_OFF_W in CTRL6_C (15h).
1100 * The value must be in the range [-127 127].[get]
1101 *
1102 * @param ctx read / write interface definitions
1103 * @param buff buffer that stores data read
1104 * @retval interface status (MANDATORY: return 0 -> no Error)
1105 *
1106 */
lsm6dso_xl_usr_offset_x_get(stmdev_ctx_t * ctx,uint8_t * buff)1107 int32_t lsm6dso_xl_usr_offset_x_get(stmdev_ctx_t *ctx, uint8_t *buff)
1108 {
1109 int32_t ret;
1110
1111 ret = lsm6dso_read_reg(ctx, LSM6DSO_X_OFS_USR, buff, 1);
1112
1113 return ret;
1114 }
1115
1116 /**
1117 * @brief Accelerometer Y-axis user offset correction expressed in two's
1118 * complement, weight depends on USR_OFF_W in CTRL6_C (15h).
1119 * The value must be in the range [-127 127].[set]
1120 *
1121 * @param ctx read / write interface definitions
1122 * @param buff buffer that contains data to write
1123 * @retval interface status (MANDATORY: return 0 -> no Error)
1124 *
1125 */
lsm6dso_xl_usr_offset_y_set(stmdev_ctx_t * ctx,uint8_t * buff)1126 int32_t lsm6dso_xl_usr_offset_y_set(stmdev_ctx_t *ctx, uint8_t *buff)
1127 {
1128 int32_t ret;
1129
1130 ret = lsm6dso_write_reg(ctx, LSM6DSO_Y_OFS_USR, buff, 1);
1131
1132 return ret;
1133 }
1134
1135 /**
1136 * @brief Accelerometer Y-axis user offset correction expressed in two's
1137 * complement, weight depends on USR_OFF_W in CTRL6_C (15h).
1138 * The value must be in the range [-127 127].[get]
1139 *
1140 * @param ctx read / write interface definitions
1141 * @param buff buffer that stores data read
1142 * @retval interface status (MANDATORY: return 0 -> no Error)
1143 *
1144 */
lsm6dso_xl_usr_offset_y_get(stmdev_ctx_t * ctx,uint8_t * buff)1145 int32_t lsm6dso_xl_usr_offset_y_get(stmdev_ctx_t *ctx, uint8_t *buff)
1146 {
1147 int32_t ret;
1148
1149 ret = lsm6dso_read_reg(ctx, LSM6DSO_Y_OFS_USR, buff, 1);
1150
1151 return ret;
1152 }
1153
1154 /**
1155 * @brief Accelerometer Z-axis user offset correction expressed in two's
1156 * complement, weight depends on USR_OFF_W in CTRL6_C (15h).
1157 * The value must be in the range [-127 127].[set]
1158 *
1159 * @param ctx read / write interface definitions
1160 * @param buff buffer that contains data to write
1161 * @retval interface status (MANDATORY: return 0 -> no Error)
1162 *
1163 */
lsm6dso_xl_usr_offset_z_set(stmdev_ctx_t * ctx,uint8_t * buff)1164 int32_t lsm6dso_xl_usr_offset_z_set(stmdev_ctx_t *ctx, uint8_t *buff)
1165 {
1166 int32_t ret;
1167
1168 ret = lsm6dso_write_reg(ctx, LSM6DSO_Z_OFS_USR, buff, 1);
1169
1170 return ret;
1171 }
1172
1173 /**
1174 * @brief Accelerometer Z-axis user offset correction expressed in two's
1175 * complement, weight depends on USR_OFF_W in CTRL6_C (15h).
1176 * The value must be in the range [-127 127].[get]
1177 *
1178 * @param ctx read / write interface definitions
1179 * @param buff buffer that stores data read
1180 * @retval interface status (MANDATORY: return 0 -> no Error)
1181 *
1182 */
lsm6dso_xl_usr_offset_z_get(stmdev_ctx_t * ctx,uint8_t * buff)1183 int32_t lsm6dso_xl_usr_offset_z_get(stmdev_ctx_t *ctx, uint8_t *buff)
1184 {
1185 int32_t ret;
1186
1187 ret = lsm6dso_read_reg(ctx, LSM6DSO_Z_OFS_USR, buff, 1);
1188
1189 return ret;
1190 }
1191
1192 /**
1193 * @brief Enables user offset on out.[set]
1194 *
1195 * @param ctx read / write interface definitions
1196 * @param val change the values of usr_off_on_out in reg CTRL7_G
1197 * @retval interface status (MANDATORY: return 0 -> no Error)
1198 *
1199 */
lsm6dso_xl_usr_offset_set(stmdev_ctx_t * ctx,uint8_t val)1200 int32_t lsm6dso_xl_usr_offset_set(stmdev_ctx_t *ctx, uint8_t val)
1201 {
1202 lsm6dso_ctrl7_g_t reg;
1203 int32_t ret;
1204
1205 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL7_G, (uint8_t *)®, 1);
1206
1207 if (ret == 0)
1208 {
1209 reg.usr_off_on_out = val;
1210 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL7_G, (uint8_t *)®, 1);
1211 }
1212
1213 return ret;
1214 }
1215
1216 /**
1217 * @brief User offset on out flag.[get]
1218 *
1219 * @param ctx read / write interface definitions
1220 * @param val values of usr_off_on_out in reg CTRL7_G
1221 * @retval interface status (MANDATORY: return 0 -> no Error)
1222 *
1223 */
lsm6dso_xl_usr_offset_get(stmdev_ctx_t * ctx,uint8_t * val)1224 int32_t lsm6dso_xl_usr_offset_get(stmdev_ctx_t *ctx, uint8_t *val)
1225 {
1226 lsm6dso_ctrl7_g_t reg;
1227 int32_t ret;
1228
1229 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL7_G, (uint8_t *)®, 1);
1230 *val = reg.usr_off_on_out;
1231
1232 return ret;
1233 }
1234
1235 /**
1236 * @}
1237 *
1238 */
1239
1240 /**
1241 * @defgroup LSM6DSO_Timestamp
1242 * @brief This section groups all the functions that manage the
1243 * timestamp generation.
1244 * @{
1245 *
1246 */
1247
1248 /**
1249 * @brief Reset timestamp counter.[set]
1250 *
1251 * @param ctx Read / write interface definitions.(ptr)
1252 * @retval Interface status (MANDATORY: return 0 -> no Error)
1253 *
1254 */
lsm6dso_timestamp_rst(stmdev_ctx_t * ctx)1255 int32_t lsm6dso_timestamp_rst(stmdev_ctx_t *ctx)
1256 {
1257 uint8_t rst_val = 0xAA;
1258 return lsm6dso_write_reg(ctx, LSM6DSO_TIMESTAMP2, &rst_val, 1);
1259 }
1260
1261 /**
1262 * @brief Enables timestamp counter.[set]
1263 *
1264 * @param ctx read / write interface definitions
1265 * @param val change the values of timestamp_en in reg CTRL10_C
1266 * @retval interface status (MANDATORY: return 0 -> no Error)
1267 *
1268 */
lsm6dso_timestamp_set(stmdev_ctx_t * ctx,uint8_t val)1269 int32_t lsm6dso_timestamp_set(stmdev_ctx_t *ctx, uint8_t val)
1270 {
1271 lsm6dso_ctrl10_c_t reg;
1272 int32_t ret;
1273
1274 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL10_C, (uint8_t *)®, 1);
1275
1276 if (ret == 0)
1277 {
1278 reg.timestamp_en = val;
1279 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL10_C, (uint8_t *)®, 1);
1280 }
1281
1282 return ret;
1283 }
1284
1285 /**
1286 * @brief Enables timestamp counter.[get]
1287 *
1288 * @param ctx read / write interface definitions
1289 * @param val Get the values of timestamp_en in reg CTRL10_C
1290 * @retval interface status (MANDATORY: return 0 -> no Error)
1291 *
1292 */
lsm6dso_timestamp_get(stmdev_ctx_t * ctx,uint8_t * val)1293 int32_t lsm6dso_timestamp_get(stmdev_ctx_t *ctx, uint8_t *val)
1294 {
1295 lsm6dso_ctrl10_c_t reg;
1296 int32_t ret;
1297
1298 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL10_C, (uint8_t *)®, 1);
1299 *val = reg.timestamp_en;
1300
1301 return ret;
1302 }
1303
1304 /**
1305 * @brief Timestamp first data output register (r).
1306 * The value is expressed as a 32-bit word and the bit
1307 * resolution is 25 us.[get]
1308 *
1309 * @param ctx read / write interface definitions
1310 * @param buff buffer that stores data read
1311 * @retval interface status (MANDATORY: return 0 -> no Error)
1312 *
1313 */
lsm6dso_timestamp_raw_get(stmdev_ctx_t * ctx,uint32_t * val)1314 int32_t lsm6dso_timestamp_raw_get(stmdev_ctx_t *ctx, uint32_t *val)
1315 {
1316 uint8_t buff[4];
1317 int32_t ret;
1318
1319 ret = lsm6dso_read_reg(ctx, LSM6DSO_TIMESTAMP0, buff, 4);
1320 *val = buff[3];
1321 *val = (*val * 256U) + buff[2];
1322 *val = (*val * 256U) + buff[1];
1323 *val = (*val * 256U) + buff[0];
1324
1325 return ret;
1326 }
1327
1328 /**
1329 * @}
1330 *
1331 */
1332
1333 /**
1334 * @defgroup LSM6DSO_Data output
1335 * @brief This section groups all the data output functions.
1336 * @{
1337 *
1338 */
1339
1340 /**
1341 * @brief Circular burst-mode (rounding) read of the output
1342 * registers.[set]
1343 *
1344 * @param ctx read / write interface definitions
1345 * @param val change the values of rounding in reg CTRL5_C
1346 * @retval interface status (MANDATORY: return 0 -> no Error)
1347 *
1348 */
lsm6dso_rounding_mode_set(stmdev_ctx_t * ctx,lsm6dso_rounding_t val)1349 int32_t lsm6dso_rounding_mode_set(stmdev_ctx_t *ctx,
1350 lsm6dso_rounding_t val)
1351 {
1352 lsm6dso_ctrl5_c_t reg;
1353 int32_t ret;
1354
1355 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL5_C, (uint8_t *)®, 1);
1356
1357 if (ret == 0)
1358 {
1359 reg.rounding = (uint8_t)val;
1360 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL5_C, (uint8_t *)®, 1);
1361 }
1362
1363 return ret;
1364 }
1365
1366 /**
1367 * @brief Gyroscope UI chain full-scale selection.[get]
1368 *
1369 * @param ctx read / write interface definitions
1370 * @param val Get the values of rounding in reg CTRL5_C
1371 * @retval interface status (MANDATORY: return 0 -> no Error)
1372 *
1373 */
lsm6dso_rounding_mode_get(stmdev_ctx_t * ctx,lsm6dso_rounding_t * val)1374 int32_t lsm6dso_rounding_mode_get(stmdev_ctx_t *ctx,
1375 lsm6dso_rounding_t *val)
1376 {
1377 lsm6dso_ctrl5_c_t reg;
1378 int32_t ret;
1379
1380 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL5_C, (uint8_t *)®, 1);
1381
1382 switch (reg.rounding)
1383 {
1384 case LSM6DSO_NO_ROUND:
1385 *val = LSM6DSO_NO_ROUND;
1386 break;
1387
1388 case LSM6DSO_ROUND_XL:
1389 *val = LSM6DSO_ROUND_XL;
1390 break;
1391
1392 case LSM6DSO_ROUND_GY:
1393 *val = LSM6DSO_ROUND_GY;
1394 break;
1395
1396 case LSM6DSO_ROUND_GY_XL:
1397 *val = LSM6DSO_ROUND_GY_XL;
1398 break;
1399
1400 default:
1401 *val = LSM6DSO_NO_ROUND;
1402 break;
1403 }
1404
1405 return ret;
1406 }
1407
1408 /**
1409 * @brief Temperature data output register (r).
1410 * L and H registers together express a 16-bit word in two's
1411 * complement.[get]
1412 *
1413 * @param ctx read / write interface definitions
1414 * @param buff buffer that stores data read
1415 * @retval interface status (MANDATORY: return 0 -> no Error)
1416 *
1417 */
lsm6dso_temperature_raw_get(stmdev_ctx_t * ctx,int16_t * val)1418 int32_t lsm6dso_temperature_raw_get(stmdev_ctx_t *ctx, int16_t *val)
1419 {
1420 uint8_t buff[2];
1421 int32_t ret;
1422
1423 ret = lsm6dso_read_reg(ctx, LSM6DSO_OUT_TEMP_L, buff, 2);
1424 val[0] = (int16_t)buff[1];
1425 val[0] = (val[0] * 256) + (int16_t)buff[0];
1426
1427 return ret;
1428 }
1429
1430 /**
1431 * @brief Angular rate sensor. The value is expressed as a 16-bit
1432 * word in two's complement.[get]
1433 *
1434 * @param ctx read / write interface definitions
1435 * @param buff buffer that stores data read
1436 * @retval interface status (MANDATORY: return 0 -> no Error)
1437 *
1438 */
lsm6dso_angular_rate_raw_get(stmdev_ctx_t * ctx,int16_t * val)1439 int32_t lsm6dso_angular_rate_raw_get(stmdev_ctx_t *ctx, int16_t *val)
1440 {
1441 uint8_t buff[6];
1442 int32_t ret;
1443
1444 ret = lsm6dso_read_reg(ctx, LSM6DSO_OUTX_L_G, buff, 6);
1445 val[0] = (int16_t)buff[1];
1446 val[0] = (val[0] * 256) + (int16_t)buff[0];
1447 val[1] = (int16_t)buff[3];
1448 val[1] = (val[1] * 256) + (int16_t)buff[2];
1449 val[2] = (int16_t)buff[5];
1450 val[2] = (val[2] * 256) + (int16_t)buff[4];
1451
1452 return ret;
1453 }
1454
1455 /**
1456 * @brief Linear acceleration output register.
1457 * The value is expressed as a 16-bit word in two's complement.[get]
1458 *
1459 * @param ctx read / write interface definitions
1460 * @param buff buffer that stores data read
1461 * @retval interface status (MANDATORY: return 0 -> no Error)
1462 *
1463 */
lsm6dso_acceleration_raw_get(stmdev_ctx_t * ctx,int16_t * val)1464 int32_t lsm6dso_acceleration_raw_get(stmdev_ctx_t *ctx, int16_t *val)
1465 {
1466 uint8_t buff[6];
1467 int32_t ret;
1468
1469 ret = lsm6dso_read_reg(ctx, LSM6DSO_OUTX_L_A, buff, 6);
1470 val[0] = (int16_t)buff[1];
1471 val[0] = (val[0] * 256) + (int16_t)buff[0];
1472 val[1] = (int16_t)buff[3];
1473 val[1] = (val[1] * 256) + (int16_t)buff[2];
1474 val[2] = (int16_t)buff[5];
1475 val[2] = (val[2] * 256) + (int16_t)buff[4];
1476
1477 return ret;
1478 }
1479
1480 /**
1481 * @brief FIFO data output [get]
1482 *
1483 * @param ctx read / write interface definitions
1484 * @param buff buffer that stores data read
1485 * @retval interface status (MANDATORY: return 0 -> no Error)
1486 *
1487 */
lsm6dso_fifo_out_raw_get(stmdev_ctx_t * ctx,uint8_t * buff)1488 int32_t lsm6dso_fifo_out_raw_get(stmdev_ctx_t *ctx, uint8_t *buff)
1489 {
1490 int32_t ret;
1491
1492 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_DATA_OUT_X_L, buff, 6);
1493
1494 return ret;
1495 }
1496
1497 /**
1498 * @brief Step counter output register.[get]
1499 *
1500 * @param ctx read / write interface definitions
1501 * @param buff buffer that stores data read
1502 * @retval interface status (MANDATORY: return 0 -> no Error)
1503 *
1504 */
lsm6dso_number_of_steps_get(stmdev_ctx_t * ctx,uint16_t * val)1505 int32_t lsm6dso_number_of_steps_get(stmdev_ctx_t *ctx, uint16_t *val)
1506 {
1507 uint8_t buff[2];
1508 int32_t ret;
1509
1510 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
1511
1512 if (ret == 0)
1513 {
1514 ret = lsm6dso_read_reg(ctx, LSM6DSO_STEP_COUNTER_L, buff, 2);
1515 }
1516
1517 if (ret == 0)
1518 {
1519 *val = buff[1];
1520 *val = (*val * 256U) + buff[0];
1521 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
1522 }
1523
1524 return ret;
1525 }
1526
1527 /**
1528 * @brief Reset step counter register.[get]
1529 *
1530 * @param ctx read / write interface definitions
1531 * @retval interface status (MANDATORY: return 0 -> no Error)
1532 *
1533 */
lsm6dso_steps_reset(stmdev_ctx_t * ctx)1534 int32_t lsm6dso_steps_reset(stmdev_ctx_t *ctx)
1535 {
1536 lsm6dso_emb_func_src_t reg;
1537 int32_t ret;
1538
1539 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
1540
1541 if (ret == 0)
1542 {
1543 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_SRC, (uint8_t *)®, 1);
1544 }
1545
1546 if (ret == 0)
1547 {
1548 reg.pedo_rst_step = PROPERTY_ENABLE;
1549 ret = lsm6dso_write_reg(ctx, LSM6DSO_EMB_FUNC_SRC, (uint8_t *)®, 1);
1550 }
1551
1552 if (ret == 0)
1553 {
1554 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
1555 }
1556
1557 return ret;
1558 }
1559
1560 /**
1561 * @}
1562 *
1563 */
1564
1565 /**
1566 * @defgroup LSM6DSO_common
1567 * @brief This section groups common useful functions.
1568 * @{
1569 *
1570 */
1571
1572 /**
1573 * @brief Difference in percentage of the effective ODR(and timestamp rate)
1574 * with respect to the typical.
1575 * Step: 0.15%. 8-bit format, 2's complement.[set]
1576 *
1577 * @param ctx read / write interface definitions
1578 * @param val change the values of freq_fine in reg
1579 * INTERNAL_FREQ_FINE
1580 * @retval interface status (MANDATORY: return 0 -> no Error)
1581 *
1582 */
lsm6dso_odr_cal_reg_set(stmdev_ctx_t * ctx,uint8_t val)1583 int32_t lsm6dso_odr_cal_reg_set(stmdev_ctx_t *ctx, uint8_t val)
1584 {
1585 lsm6dso_internal_freq_fine_t reg;
1586 int32_t ret;
1587
1588 ret = lsm6dso_read_reg(ctx, LSM6DSO_INTERNAL_FREQ_FINE,
1589 (uint8_t *)®, 1);
1590
1591 if (ret == 0)
1592 {
1593 reg.freq_fine = val;
1594 ret = lsm6dso_write_reg(ctx, LSM6DSO_INTERNAL_FREQ_FINE,
1595 (uint8_t *)®, 1);
1596 }
1597
1598 return ret;
1599 }
1600
1601 /**
1602 * @brief Difference in percentage of the effective ODR(and timestamp rate)
1603 * with respect to the typical.
1604 * Step: 0.15%. 8-bit format, 2's complement.[get]
1605 *
1606 * @param ctx read / write interface definitions
1607 * @param val Get the values of freq_fine in reg INTERNAL_FREQ_FINE
1608 * @retval interface status (MANDATORY: return 0 -> no Error)
1609 *
1610 */
lsm6dso_odr_cal_reg_get(stmdev_ctx_t * ctx,uint8_t * val)1611 int32_t lsm6dso_odr_cal_reg_get(stmdev_ctx_t *ctx, uint8_t *val)
1612 {
1613 lsm6dso_internal_freq_fine_t reg;
1614 int32_t ret;
1615
1616 ret = lsm6dso_read_reg(ctx, LSM6DSO_INTERNAL_FREQ_FINE,
1617 (uint8_t *)®, 1);
1618 *val = reg.freq_fine;
1619
1620 return ret;
1621 }
1622
1623
1624 /**
1625 * @brief Enable access to the embedded functions/sensor
1626 * hub configuration registers.[set]
1627 *
1628 * @param ctx read / write interface definitions
1629 * @param val change the values of reg_access in
1630 * reg FUNC_CFG_ACCESS
1631 * @retval interface status (MANDATORY: return 0 -> no Error)
1632 *
1633 */
lsm6dso_mem_bank_set(stmdev_ctx_t * ctx,lsm6dso_reg_access_t val)1634 int32_t lsm6dso_mem_bank_set(stmdev_ctx_t *ctx,
1635 lsm6dso_reg_access_t val)
1636 {
1637 lsm6dso_func_cfg_access_t reg;
1638 int32_t ret;
1639
1640 ret = lsm6dso_read_reg(ctx, LSM6DSO_FUNC_CFG_ACCESS, (uint8_t *)®, 1);
1641
1642 if (ret == 0)
1643 {
1644 reg.reg_access = (uint8_t)val;
1645 ret = lsm6dso_write_reg(ctx, LSM6DSO_FUNC_CFG_ACCESS, (uint8_t *)®, 1);
1646 }
1647
1648 return ret;
1649 }
1650
1651 /**
1652 * @brief Enable access to the embedded functions/sensor
1653 * hub configuration registers.[get]
1654 *
1655 * @param ctx read / write interface definitions
1656 * @param val Get the values of reg_access in
1657 * reg FUNC_CFG_ACCESS
1658 * @retval interface status (MANDATORY: return 0 -> no Error)
1659 *
1660 */
lsm6dso_mem_bank_get(stmdev_ctx_t * ctx,lsm6dso_reg_access_t * val)1661 int32_t lsm6dso_mem_bank_get(stmdev_ctx_t *ctx,
1662 lsm6dso_reg_access_t *val)
1663 {
1664 lsm6dso_func_cfg_access_t reg;
1665 int32_t ret;
1666
1667 ret = lsm6dso_read_reg(ctx, LSM6DSO_FUNC_CFG_ACCESS, (uint8_t *)®, 1);
1668
1669 switch (reg.reg_access)
1670 {
1671 case LSM6DSO_USER_BANK:
1672 *val = LSM6DSO_USER_BANK;
1673 break;
1674
1675 case LSM6DSO_SENSOR_HUB_BANK:
1676 *val = LSM6DSO_SENSOR_HUB_BANK;
1677 break;
1678
1679 case LSM6DSO_EMBEDDED_FUNC_BANK:
1680 *val = LSM6DSO_EMBEDDED_FUNC_BANK;
1681 break;
1682
1683 default:
1684 *val = LSM6DSO_USER_BANK;
1685 break;
1686 }
1687
1688 return ret;
1689 }
1690
1691 /**
1692 * @brief Write a line(byte) in a page.[set]
1693 *
1694 * @param ctx read / write interface definitions
1695 * @param uint8_t address: page line address
1696 * @param val value to write
1697 * @retval interface status (MANDATORY: return 0 -> no Error)
1698 *
1699 */
lsm6dso_ln_pg_write_byte(stmdev_ctx_t * ctx,uint16_t address,uint8_t * val)1700 int32_t lsm6dso_ln_pg_write_byte(stmdev_ctx_t *ctx, uint16_t address,
1701 uint8_t *val)
1702 {
1703 lsm6dso_page_rw_t page_rw;
1704 lsm6dso_page_sel_t page_sel;
1705 lsm6dso_page_address_t page_address;
1706 int32_t ret;
1707
1708 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
1709
1710 if (ret == 0)
1711 {
1712 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
1713 }
1714
1715 if (ret == 0)
1716 {
1717 page_rw.page_rw = 0x02; /* page_write enable */
1718 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
1719 }
1720
1721 if (ret == 0)
1722 {
1723 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_SEL, (uint8_t *) &page_sel, 1);
1724 }
1725
1726 if (ret == 0)
1727 {
1728 page_sel.page_sel = ((uint8_t)(address >> 8) & 0x0FU);
1729 page_sel.not_used_01 = 1;
1730 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_SEL, (uint8_t *) &page_sel, 1);
1731 }
1732
1733 if (ret == 0)
1734 {
1735 page_address.page_addr = (uint8_t)address & 0xFFU;
1736 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_ADDRESS,
1737 (uint8_t *)&page_address, 1);
1738 }
1739
1740 if (ret == 0)
1741 {
1742 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_VALUE, val, 1);
1743 }
1744
1745 if (ret == 0)
1746 {
1747 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
1748 }
1749
1750 if (ret == 0)
1751 {
1752 page_rw.page_rw = 0x00; /* page_write disable */
1753 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
1754 }
1755
1756 if (ret == 0)
1757 {
1758 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
1759 }
1760
1761 return ret;
1762 }
1763
1764 /**
1765 * @brief Write buffer in a page.[set]
1766 *
1767 * @param ctx read / write interface definitions
1768 * @param uint8_t address: page line address
1769 * @param uint8_t *buf: buffer to write
1770 * @param uint8_t len: buffer len
1771 * @retval interface status (MANDATORY: return 0 -> no Error)
1772 *
1773 */
lsm6dso_ln_pg_write(stmdev_ctx_t * ctx,uint16_t address,uint8_t * buf,uint8_t len)1774 int32_t lsm6dso_ln_pg_write(stmdev_ctx_t *ctx, uint16_t address,
1775 uint8_t *buf, uint8_t len)
1776 {
1777 lsm6dso_page_rw_t page_rw;
1778 lsm6dso_page_sel_t page_sel;
1779 lsm6dso_page_address_t page_address;
1780 uint16_t addr_pointed;
1781 int32_t ret;
1782
1783 uint8_t i ;
1784 addr_pointed = address;
1785 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
1786
1787 if (ret == 0)
1788 {
1789 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
1790 }
1791
1792 if (ret == 0)
1793 {
1794 page_rw.page_rw = 0x02; /* page_write enable*/
1795 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
1796 }
1797
1798 if (ret == 0)
1799 {
1800 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_SEL, (uint8_t *) &page_sel, 1);
1801 }
1802
1803 if (ret == 0)
1804 {
1805 page_sel.page_sel = ((uint8_t)(addr_pointed >> 8) & 0x0FU);
1806 page_sel.not_used_01 = 1;
1807 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_SEL, (uint8_t *) &page_sel, 1);
1808 }
1809
1810 if (ret == 0)
1811 {
1812 page_address.page_addr = (uint8_t)(addr_pointed & 0x00FFU);
1813 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_ADDRESS,
1814 (uint8_t *)&page_address, 1);
1815 }
1816
1817 if (ret == 0)
1818 {
1819 for (i = 0; ((i < len) && (ret == 0)); i++)
1820 {
1821 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_VALUE, &buf[i], 1);
1822 addr_pointed++;
1823
1824 /* Check if page wrap */
1825 if (((addr_pointed % 0x0100U) == 0x00U) && (ret == 0))
1826 {
1827 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_SEL, (uint8_t *)&page_sel, 1);
1828
1829 if (ret == 0)
1830 {
1831 page_sel.page_sel = ((uint8_t)(addr_pointed >> 8) & 0x0FU);
1832 page_sel.not_used_01 = 1;
1833 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_SEL,
1834 (uint8_t *)&page_sel, 1);
1835 }
1836 }
1837 }
1838
1839 page_sel.page_sel = 0;
1840 page_sel.not_used_01 = 1;
1841 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_SEL, (uint8_t *) &page_sel, 1);
1842 }
1843
1844 if (ret == 0)
1845 {
1846 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
1847 }
1848
1849 if (ret == 0)
1850 {
1851 page_rw.page_rw = 0x00; /* page_write disable */
1852 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
1853 }
1854
1855 if (ret == 0)
1856 {
1857 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
1858 }
1859
1860 return ret;
1861 }
1862
1863 /**
1864 * @brief Read a line(byte) in a page.[get]
1865 *
1866 * @param ctx read / write interface definitions
1867 * @param uint8_t address: page line address
1868 * @param val read value
1869 * @retval interface status (MANDATORY: return 0 -> no Error)
1870 *
1871 */
lsm6dso_ln_pg_read_byte(stmdev_ctx_t * ctx,uint16_t address,uint8_t * val)1872 int32_t lsm6dso_ln_pg_read_byte(stmdev_ctx_t *ctx, uint16_t address,
1873 uint8_t *val)
1874 {
1875 lsm6dso_page_rw_t page_rw;
1876 lsm6dso_page_sel_t page_sel;
1877 lsm6dso_page_address_t page_address;
1878 int32_t ret;
1879
1880 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
1881
1882 if (ret == 0)
1883 {
1884 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
1885 }
1886
1887 if (ret == 0)
1888 {
1889 page_rw.page_rw = 0x01; /* page_read enable*/
1890 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
1891 }
1892
1893 if (ret == 0)
1894 {
1895 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_SEL, (uint8_t *) &page_sel, 1);
1896 }
1897
1898 if (ret == 0)
1899 {
1900 page_sel.page_sel = ((uint8_t)(address >> 8) & 0x0FU);
1901 page_sel.not_used_01 = 1;
1902 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_SEL, (uint8_t *) &page_sel, 1);
1903 }
1904
1905 if (ret == 0)
1906 {
1907 page_address.page_addr = (uint8_t)address & 0x00FFU;
1908 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_ADDRESS,
1909 (uint8_t *)&page_address, 1);
1910 }
1911
1912 if (ret == 0)
1913 {
1914 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_VALUE, val, 1);
1915 }
1916
1917 if (ret == 0)
1918 {
1919 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
1920 }
1921
1922 if (ret == 0)
1923 {
1924 page_rw.page_rw = 0x00; /* page_read disable */
1925 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
1926 }
1927
1928 if (ret == 0)
1929 {
1930 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
1931 }
1932
1933 return ret;
1934 }
1935
1936 /**
1937 * @brief Data-ready pulsed / letched mode.[set]
1938 *
1939 * @param ctx read / write interface definitions
1940 * @param val change the values of
1941 * dataready_pulsed in
1942 * reg COUNTER_BDR_REG1
1943 * @retval interface status (MANDATORY: return 0 -> no Error)
1944 *
1945 */
lsm6dso_data_ready_mode_set(stmdev_ctx_t * ctx,lsm6dso_dataready_pulsed_t val)1946 int32_t lsm6dso_data_ready_mode_set(stmdev_ctx_t *ctx,
1947 lsm6dso_dataready_pulsed_t val)
1948 {
1949 lsm6dso_counter_bdr_reg1_t reg;
1950 int32_t ret;
1951
1952 ret = lsm6dso_read_reg(ctx, LSM6DSO_COUNTER_BDR_REG1, (uint8_t *)®, 1);
1953
1954 if (ret == 0)
1955 {
1956 reg.dataready_pulsed = (uint8_t)val;
1957 ret = lsm6dso_write_reg(ctx, LSM6DSO_COUNTER_BDR_REG1,
1958 (uint8_t *)®, 1);
1959 }
1960
1961 return ret;
1962 }
1963
1964 /**
1965 * @brief Data-ready pulsed / letched mode.[get]
1966 *
1967 * @param ctx read / write interface definitions
1968 * @param val Get the values of
1969 * dataready_pulsed in
1970 * reg COUNTER_BDR_REG1
1971 * @retval interface status (MANDATORY: return 0 -> no Error)
1972 *
1973 */
lsm6dso_data_ready_mode_get(stmdev_ctx_t * ctx,lsm6dso_dataready_pulsed_t * val)1974 int32_t lsm6dso_data_ready_mode_get(stmdev_ctx_t *ctx,
1975 lsm6dso_dataready_pulsed_t *val)
1976 {
1977 lsm6dso_counter_bdr_reg1_t reg;
1978 int32_t ret;
1979
1980 ret = lsm6dso_read_reg(ctx, LSM6DSO_COUNTER_BDR_REG1, (uint8_t *)®, 1);
1981
1982 switch (reg.dataready_pulsed)
1983 {
1984 case LSM6DSO_DRDY_LATCHED:
1985 *val = LSM6DSO_DRDY_LATCHED;
1986 break;
1987
1988 case LSM6DSO_DRDY_PULSED:
1989 *val = LSM6DSO_DRDY_PULSED;
1990 break;
1991
1992 default:
1993 *val = LSM6DSO_DRDY_LATCHED;
1994 break;
1995 }
1996
1997 return ret;
1998 }
1999
2000 /**
2001 * @brief Device "Who am I".[get]
2002 *
2003 * @param ctx read / write interface definitions
2004 * @param buff buffer that stores data read
2005 * @retval interface status (MANDATORY: return 0 -> no Error)
2006 *
2007 */
lsm6dso_device_id_get(stmdev_ctx_t * ctx,uint8_t * buff)2008 int32_t lsm6dso_device_id_get(stmdev_ctx_t *ctx, uint8_t *buff)
2009 {
2010 int32_t ret;
2011
2012 ret = lsm6dso_read_reg(ctx, LSM6DSO_WHO_AM_I, buff, 1);
2013
2014 return ret;
2015 }
2016
2017 /**
2018 * @brief Software reset. Restore the default values
2019 * in user registers[set]
2020 *
2021 * @param ctx read / write interface definitions
2022 * @param val change the values of sw_reset in reg CTRL3_C
2023 * @retval interface status (MANDATORY: return 0 -> no Error)
2024 *
2025 */
lsm6dso_reset_set(stmdev_ctx_t * ctx,uint8_t val)2026 int32_t lsm6dso_reset_set(stmdev_ctx_t *ctx, uint8_t val)
2027 {
2028 lsm6dso_ctrl3_c_t reg;
2029 int32_t ret;
2030
2031 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
2032
2033 if (ret == 0)
2034 {
2035 reg.sw_reset = val;
2036 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
2037 }
2038
2039 return ret;
2040 }
2041
2042 /**
2043 * @brief Software reset. Restore the default values in user registers.[get]
2044 *
2045 * @param ctx read / write interface definitions
2046 * @param val Get the values of sw_reset in reg CTRL3_C
2047 * @retval interface status (MANDATORY: return 0 -> no Error)
2048 *
2049 */
lsm6dso_reset_get(stmdev_ctx_t * ctx,uint8_t * val)2050 int32_t lsm6dso_reset_get(stmdev_ctx_t *ctx, uint8_t *val)
2051 {
2052 lsm6dso_ctrl3_c_t reg;
2053 int32_t ret;
2054
2055 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
2056 *val = reg.sw_reset;
2057
2058 return ret;
2059 }
2060
2061 /**
2062 * @brief Register address automatically incremented during a multiple byte
2063 * access with a serial interface.[set]
2064 *
2065 * @param ctx read / write interface definitions
2066 * @param val change the values of if_inc in reg CTRL3_C
2067 * @retval interface status (MANDATORY: return 0 -> no Error)
2068 *
2069 */
lsm6dso_auto_increment_set(stmdev_ctx_t * ctx,uint8_t val)2070 int32_t lsm6dso_auto_increment_set(stmdev_ctx_t *ctx, uint8_t val)
2071 {
2072 lsm6dso_ctrl3_c_t reg;
2073 int32_t ret;
2074
2075 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
2076
2077 if (ret == 0)
2078 {
2079 reg.if_inc = val;
2080 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
2081 }
2082
2083 return ret;
2084 }
2085
2086 /**
2087 * @brief Register address automatically incremented during a multiple byte
2088 * access with a serial interface.[get]
2089 *
2090 * @param ctx read / write interface definitions
2091 * @param val Get the values of if_inc in reg CTRL3_C
2092 * @retval interface status (MANDATORY: return 0 -> no Error)
2093 *
2094 */
lsm6dso_auto_increment_get(stmdev_ctx_t * ctx,uint8_t * val)2095 int32_t lsm6dso_auto_increment_get(stmdev_ctx_t *ctx, uint8_t *val)
2096 {
2097 lsm6dso_ctrl3_c_t reg;
2098 int32_t ret;
2099
2100 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
2101 *val = reg.if_inc;
2102
2103 return ret;
2104 }
2105
2106 /**
2107 * @brief Reboot memory content. Reload the calibration parameters.[set]
2108 *
2109 * @param ctx read / write interface definitions
2110 * @param val change the values of boot in reg CTRL3_C
2111 * @retval interface status (MANDATORY: return 0 -> no Error)
2112 *
2113 */
lsm6dso_boot_set(stmdev_ctx_t * ctx,uint8_t val)2114 int32_t lsm6dso_boot_set(stmdev_ctx_t *ctx, uint8_t val)
2115 {
2116 lsm6dso_ctrl3_c_t reg;
2117 int32_t ret;
2118
2119 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
2120
2121 if (ret == 0)
2122 {
2123 reg.boot = val;
2124 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
2125 }
2126
2127 return ret;
2128 }
2129
2130 /**
2131 * @brief Reboot memory content. Reload the calibration parameters.[get]
2132 *
2133 * @param ctx read / write interface definitions
2134 * @param val Get the values of boot in reg CTRL3_C
2135 * @retval interface status (MANDATORY: return 0 -> no Error)
2136 *
2137 */
lsm6dso_boot_get(stmdev_ctx_t * ctx,uint8_t * val)2138 int32_t lsm6dso_boot_get(stmdev_ctx_t *ctx, uint8_t *val)
2139 {
2140 lsm6dso_ctrl3_c_t reg;
2141 int32_t ret;
2142
2143 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
2144 *val = reg.boot;
2145
2146 return ret;
2147 }
2148
2149 /**
2150 * @brief Linear acceleration sensor self-test enable.[set]
2151 *
2152 * @param ctx read / write interface definitions
2153 * @param val change the values of st_xl in reg CTRL5_C
2154 * @retval interface status (MANDATORY: return 0 -> no Error)
2155 *
2156 */
lsm6dso_xl_self_test_set(stmdev_ctx_t * ctx,lsm6dso_st_xl_t val)2157 int32_t lsm6dso_xl_self_test_set(stmdev_ctx_t *ctx,
2158 lsm6dso_st_xl_t val)
2159 {
2160 lsm6dso_ctrl5_c_t reg;
2161 int32_t ret;
2162
2163 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL5_C, (uint8_t *)®, 1);
2164
2165 if (ret == 0)
2166 {
2167 reg.st_xl = (uint8_t)val;
2168 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL5_C, (uint8_t *)®, 1);
2169 }
2170
2171 return ret;
2172 }
2173
2174 /**
2175 * @brief Linear acceleration sensor self-test enable.[get]
2176 *
2177 * @param ctx read / write interface definitions
2178 * @param val Get the values of st_xl in reg CTRL5_C
2179 * @retval interface status (MANDATORY: return 0 -> no Error)
2180 *
2181 */
lsm6dso_xl_self_test_get(stmdev_ctx_t * ctx,lsm6dso_st_xl_t * val)2182 int32_t lsm6dso_xl_self_test_get(stmdev_ctx_t *ctx,
2183 lsm6dso_st_xl_t *val)
2184 {
2185 lsm6dso_ctrl5_c_t reg;
2186 int32_t ret;
2187
2188 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL5_C, (uint8_t *)®, 1);
2189
2190 switch (reg.st_xl)
2191 {
2192 case LSM6DSO_XL_ST_DISABLE:
2193 *val = LSM6DSO_XL_ST_DISABLE;
2194 break;
2195
2196 case LSM6DSO_XL_ST_POSITIVE:
2197 *val = LSM6DSO_XL_ST_POSITIVE;
2198 break;
2199
2200 case LSM6DSO_XL_ST_NEGATIVE:
2201 *val = LSM6DSO_XL_ST_NEGATIVE;
2202 break;
2203
2204 default:
2205 *val = LSM6DSO_XL_ST_DISABLE;
2206 break;
2207 }
2208
2209 return ret;
2210 }
2211
2212 /**
2213 * @brief Angular rate sensor self-test enable.[set]
2214 *
2215 * @param ctx read / write interface definitions
2216 * @param val change the values of st_g in reg CTRL5_C
2217 * @retval interface status (MANDATORY: return 0 -> no Error)
2218 *
2219 */
lsm6dso_gy_self_test_set(stmdev_ctx_t * ctx,lsm6dso_st_g_t val)2220 int32_t lsm6dso_gy_self_test_set(stmdev_ctx_t *ctx,
2221 lsm6dso_st_g_t val)
2222 {
2223 lsm6dso_ctrl5_c_t reg;
2224 int32_t ret;
2225
2226 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL5_C, (uint8_t *)®, 1);
2227
2228 if (ret == 0)
2229 {
2230 reg.st_g = (uint8_t)val;
2231 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL5_C, (uint8_t *)®, 1);
2232 }
2233
2234 return ret;
2235 }
2236
2237 /**
2238 * @brief Angular rate sensor self-test enable.[get]
2239 *
2240 * @param ctx read / write interface definitions
2241 * @param val Get the values of st_g in reg CTRL5_C
2242 * @retval interface status (MANDATORY: return 0 -> no Error)
2243 *
2244 */
lsm6dso_gy_self_test_get(stmdev_ctx_t * ctx,lsm6dso_st_g_t * val)2245 int32_t lsm6dso_gy_self_test_get(stmdev_ctx_t *ctx,
2246 lsm6dso_st_g_t *val)
2247 {
2248 lsm6dso_ctrl5_c_t reg;
2249 int32_t ret;
2250
2251 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL5_C, (uint8_t *)®, 1);
2252
2253 switch (reg.st_g)
2254 {
2255 case LSM6DSO_GY_ST_DISABLE:
2256 *val = LSM6DSO_GY_ST_DISABLE;
2257 break;
2258
2259 case LSM6DSO_GY_ST_POSITIVE:
2260 *val = LSM6DSO_GY_ST_POSITIVE;
2261 break;
2262
2263 case LSM6DSO_GY_ST_NEGATIVE:
2264 *val = LSM6DSO_GY_ST_NEGATIVE;
2265 break;
2266
2267 default:
2268 *val = LSM6DSO_GY_ST_DISABLE;
2269 break;
2270 }
2271
2272 return ret;
2273 }
2274
2275 /**
2276 * @}
2277 *
2278 */
2279
2280 /**
2281 * @defgroup LSM6DSO_filters
2282 * @brief This section group all the functions concerning the
2283 * filters configuration
2284 * @{
2285 *
2286 */
2287
2288 /**
2289 * @brief Accelerometer output from LPF2 filtering stage selection.[set]
2290 *
2291 * @param ctx read / write interface definitions
2292 * @param val change the values of lpf2_xl_en in reg CTRL1_XL
2293 * @retval interface status (MANDATORY: return 0 -> no Error)
2294 *
2295 */
lsm6dso_xl_filter_lp2_set(stmdev_ctx_t * ctx,uint8_t val)2296 int32_t lsm6dso_xl_filter_lp2_set(stmdev_ctx_t *ctx, uint8_t val)
2297 {
2298 lsm6dso_ctrl1_xl_t reg;
2299 int32_t ret;
2300
2301 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_XL, (uint8_t *)®, 1);
2302
2303 if (ret == 0)
2304 {
2305 reg.lpf2_xl_en = val;
2306 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL1_XL, (uint8_t *)®, 1);
2307 }
2308
2309 return ret;
2310 }
2311
2312 /**
2313 * @brief Accelerometer output from LPF2 filtering stage selection.[get]
2314 *
2315 * @param ctx read / write interface definitions
2316 * @param val Get the values of lpf2_xl_en in reg CTRL1_XL
2317 * @retval interface status (MANDATORY: return 0 -> no Error)
2318 *
2319 */
lsm6dso_xl_filter_lp2_get(stmdev_ctx_t * ctx,uint8_t * val)2320 int32_t lsm6dso_xl_filter_lp2_get(stmdev_ctx_t *ctx, uint8_t *val)
2321 {
2322 lsm6dso_ctrl1_xl_t reg;
2323 int32_t ret;
2324
2325 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_XL, (uint8_t *)®, 1);
2326 *val = reg.lpf2_xl_en;
2327
2328 return ret;
2329 }
2330
2331 /**
2332 * @brief Enables gyroscope digital LPF1 if auxiliary SPI is disabled;
2333 * the bandwidth can be selected through FTYPE [2:0]
2334 * in CTRL6_C (15h).[set]
2335 *
2336 * @param ctx read / write interface definitions
2337 * @param val change the values of lpf1_sel_g in reg CTRL4_C
2338 * @retval interface status (MANDATORY: return 0 -> no Error)
2339 *
2340 */
lsm6dso_gy_filter_lp1_set(stmdev_ctx_t * ctx,uint8_t val)2341 int32_t lsm6dso_gy_filter_lp1_set(stmdev_ctx_t *ctx, uint8_t val)
2342 {
2343 lsm6dso_ctrl4_c_t reg;
2344 int32_t ret;
2345
2346 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
2347
2348 if (ret == 0)
2349 {
2350 reg.lpf1_sel_g = val;
2351 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
2352 }
2353
2354 return ret;
2355 }
2356
2357 /**
2358 * @brief Enables gyroscope digital LPF1 if auxiliary SPI is disabled;
2359 * the bandwidth can be selected through FTYPE [2:0]
2360 * in CTRL6_C (15h).[get]
2361 *
2362 * @param ctx read / write interface definitions
2363 * @param val Get the values of lpf1_sel_g in reg CTRL4_C
2364 * @retval interface status (MANDATORY: return 0 -> no Error)
2365 *
2366 */
lsm6dso_gy_filter_lp1_get(stmdev_ctx_t * ctx,uint8_t * val)2367 int32_t lsm6dso_gy_filter_lp1_get(stmdev_ctx_t *ctx, uint8_t *val)
2368 {
2369 lsm6dso_ctrl4_c_t reg;
2370 int32_t ret;
2371
2372 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
2373 *val = reg.lpf1_sel_g;
2374
2375 return ret;
2376 }
2377
2378 /**
2379 * @brief Mask DRDY on pin (both XL & Gyro) until filter settling ends
2380 * (XL and Gyro independently masked).[set]
2381 *
2382 * @param ctx read / write interface definitions
2383 * @param val change the values of drdy_mask in reg CTRL4_C
2384 * @retval interface status (MANDATORY: return 0 -> no Error)
2385 *
2386 */
lsm6dso_filter_settling_mask_set(stmdev_ctx_t * ctx,uint8_t val)2387 int32_t lsm6dso_filter_settling_mask_set(stmdev_ctx_t *ctx,
2388 uint8_t val)
2389 {
2390 lsm6dso_ctrl4_c_t reg;
2391 int32_t ret;
2392
2393 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
2394
2395 if (ret == 0)
2396 {
2397 reg.drdy_mask = val;
2398 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
2399 }
2400
2401 return ret;
2402 }
2403
2404 /**
2405 * @brief Mask DRDY on pin (both XL & Gyro) until filter settling ends
2406 * (XL and Gyro independently masked).[get]
2407 *
2408 * @param ctx read / write interface definitions
2409 * @param val Get the values of drdy_mask in reg CTRL4_C
2410 * @retval interface status (MANDATORY: return 0 -> no Error)
2411 *
2412 */
lsm6dso_filter_settling_mask_get(stmdev_ctx_t * ctx,uint8_t * val)2413 int32_t lsm6dso_filter_settling_mask_get(stmdev_ctx_t *ctx,
2414 uint8_t *val)
2415 {
2416 lsm6dso_ctrl4_c_t reg;
2417 int32_t ret;
2418
2419 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
2420 *val = reg.drdy_mask;
2421
2422 return ret;
2423 }
2424
2425 /**
2426 * @brief Gyroscope lp1 bandwidth.[set]
2427 *
2428 * @param ctx read / write interface definitions
2429 * @param val change the values of ftype in reg CTRL6_C
2430 * @retval interface status (MANDATORY: return 0 -> no Error)
2431 *
2432 */
lsm6dso_gy_lp1_bandwidth_set(stmdev_ctx_t * ctx,lsm6dso_ftype_t val)2433 int32_t lsm6dso_gy_lp1_bandwidth_set(stmdev_ctx_t *ctx,
2434 lsm6dso_ftype_t val)
2435 {
2436 lsm6dso_ctrl6_c_t reg;
2437 int32_t ret;
2438
2439 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL6_C, (uint8_t *)®, 1);
2440
2441 if (ret == 0)
2442 {
2443 reg.ftype = (uint8_t)val;
2444 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL6_C, (uint8_t *)®, 1);
2445 }
2446
2447 return ret;
2448 }
2449
2450 /**
2451 * @brief Gyroscope lp1 bandwidth.[get]
2452 *
2453 * @param ctx read / write interface definitions
2454 * @param val Get the values of ftype in reg CTRL6_C
2455 * @retval interface status (MANDATORY: return 0 -> no Error)
2456 *
2457 */
lsm6dso_gy_lp1_bandwidth_get(stmdev_ctx_t * ctx,lsm6dso_ftype_t * val)2458 int32_t lsm6dso_gy_lp1_bandwidth_get(stmdev_ctx_t *ctx,
2459 lsm6dso_ftype_t *val)
2460 {
2461 lsm6dso_ctrl6_c_t reg;
2462 int32_t ret;
2463
2464 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL6_C, (uint8_t *)®, 1);
2465
2466 switch (reg.ftype)
2467 {
2468 case LSM6DSO_ULTRA_LIGHT:
2469 *val = LSM6DSO_ULTRA_LIGHT;
2470 break;
2471
2472 case LSM6DSO_VERY_LIGHT:
2473 *val = LSM6DSO_VERY_LIGHT;
2474 break;
2475
2476 case LSM6DSO_LIGHT:
2477 *val = LSM6DSO_LIGHT;
2478 break;
2479
2480 case LSM6DSO_MEDIUM:
2481 *val = LSM6DSO_MEDIUM;
2482 break;
2483
2484 case LSM6DSO_STRONG:
2485 *val = LSM6DSO_STRONG;
2486 break;
2487
2488 case LSM6DSO_VERY_STRONG:
2489 *val = LSM6DSO_VERY_STRONG;
2490 break;
2491
2492 case LSM6DSO_AGGRESSIVE:
2493 *val = LSM6DSO_AGGRESSIVE;
2494 break;
2495
2496 case LSM6DSO_XTREME:
2497 *val = LSM6DSO_XTREME;
2498 break;
2499
2500 default:
2501 *val = LSM6DSO_ULTRA_LIGHT;
2502 break;
2503 }
2504
2505 return ret;
2506 }
2507
2508 /**
2509 * @brief Low pass filter 2 on 6D function selection.[set]
2510 *
2511 * @param ctx read / write interface definitions
2512 * @param val change the values of low_pass_on_6d in reg CTRL8_XL
2513 * @retval interface status (MANDATORY: return 0 -> no Error)
2514 *
2515 */
lsm6dso_xl_lp2_on_6d_set(stmdev_ctx_t * ctx,uint8_t val)2516 int32_t lsm6dso_xl_lp2_on_6d_set(stmdev_ctx_t *ctx, uint8_t val)
2517 {
2518 lsm6dso_ctrl8_xl_t reg;
2519 int32_t ret;
2520
2521 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL8_XL, (uint8_t *)®, 1);
2522
2523 if (ret == 0)
2524 {
2525 reg.low_pass_on_6d = val;
2526 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL8_XL, (uint8_t *)®, 1);
2527 }
2528
2529 return ret;
2530 }
2531
2532 /**
2533 * @brief Low pass filter 2 on 6D function selection.[get]
2534 *
2535 * @param ctx read / write interface definitions
2536 * @param val Get the values of low_pass_on_6d in reg CTRL8_XL
2537 * @retval interface status (MANDATORY: return 0 -> no Error)
2538 *
2539 */
lsm6dso_xl_lp2_on_6d_get(stmdev_ctx_t * ctx,uint8_t * val)2540 int32_t lsm6dso_xl_lp2_on_6d_get(stmdev_ctx_t *ctx, uint8_t *val)
2541 {
2542 lsm6dso_ctrl8_xl_t reg;
2543 int32_t ret;
2544
2545 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL8_XL, (uint8_t *)®, 1);
2546 *val = reg.low_pass_on_6d;
2547
2548 return ret;
2549 }
2550
2551 /**
2552 * @brief Accelerometer slope filter / high-pass filter selection
2553 * on output.[set]
2554 *
2555 * @param ctx read / write interface definitions
2556 * @param val change the values of hp_slope_xl_en
2557 * in reg CTRL8_XL
2558 * @retval interface status (MANDATORY: return 0 -> no Error)
2559 *
2560 */
lsm6dso_xl_hp_path_on_out_set(stmdev_ctx_t * ctx,lsm6dso_hp_slope_xl_en_t val)2561 int32_t lsm6dso_xl_hp_path_on_out_set(stmdev_ctx_t *ctx,
2562 lsm6dso_hp_slope_xl_en_t val)
2563 {
2564 lsm6dso_ctrl8_xl_t reg;
2565 int32_t ret;
2566
2567 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL8_XL, (uint8_t *)®, 1);
2568
2569 if (ret == 0)
2570 {
2571 reg.hp_slope_xl_en = ((uint8_t)val & 0x10U) >> 4;
2572 reg.hp_ref_mode_xl = ((uint8_t)val & 0x20U) >> 5;
2573 reg.hpcf_xl = (uint8_t)val & 0x07U;
2574 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL8_XL, (uint8_t *)®, 1);
2575 }
2576
2577 return ret;
2578 }
2579
2580 /**
2581 * @brief Accelerometer slope filter / high-pass filter selection
2582 * on output.[get]
2583 *
2584 * @param ctx read / write interface definitions
2585 * @param val Get the values of hp_slope_xl_en
2586 * in reg CTRL8_XL
2587 * @retval interface status (MANDATORY: return 0 -> no Error)
2588 *
2589 */
lsm6dso_xl_hp_path_on_out_get(stmdev_ctx_t * ctx,lsm6dso_hp_slope_xl_en_t * val)2590 int32_t lsm6dso_xl_hp_path_on_out_get(stmdev_ctx_t *ctx,
2591 lsm6dso_hp_slope_xl_en_t *val)
2592 {
2593 lsm6dso_ctrl8_xl_t reg;
2594 int32_t ret;
2595
2596 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL8_XL, (uint8_t *)®, 1);
2597
2598 switch ((reg.hp_ref_mode_xl << 5) | (reg.hp_slope_xl_en << 4) |
2599 reg.hpcf_xl)
2600 {
2601 case LSM6DSO_HP_PATH_DISABLE_ON_OUT:
2602 *val = LSM6DSO_HP_PATH_DISABLE_ON_OUT;
2603 break;
2604
2605 case LSM6DSO_SLOPE_ODR_DIV_4:
2606 *val = LSM6DSO_SLOPE_ODR_DIV_4;
2607 break;
2608
2609 case LSM6DSO_HP_ODR_DIV_10:
2610 *val = LSM6DSO_HP_ODR_DIV_10;
2611 break;
2612
2613 case LSM6DSO_HP_ODR_DIV_20:
2614 *val = LSM6DSO_HP_ODR_DIV_20;
2615 break;
2616
2617 case LSM6DSO_HP_ODR_DIV_45:
2618 *val = LSM6DSO_HP_ODR_DIV_45;
2619 break;
2620
2621 case LSM6DSO_HP_ODR_DIV_100:
2622 *val = LSM6DSO_HP_ODR_DIV_100;
2623 break;
2624
2625 case LSM6DSO_HP_ODR_DIV_200:
2626 *val = LSM6DSO_HP_ODR_DIV_200;
2627 break;
2628
2629 case LSM6DSO_HP_ODR_DIV_400:
2630 *val = LSM6DSO_HP_ODR_DIV_400;
2631 break;
2632
2633 case LSM6DSO_HP_ODR_DIV_800:
2634 *val = LSM6DSO_HP_ODR_DIV_800;
2635 break;
2636
2637 case LSM6DSO_HP_REF_MD_ODR_DIV_10:
2638 *val = LSM6DSO_HP_REF_MD_ODR_DIV_10;
2639 break;
2640
2641 case LSM6DSO_HP_REF_MD_ODR_DIV_20:
2642 *val = LSM6DSO_HP_REF_MD_ODR_DIV_20;
2643 break;
2644
2645 case LSM6DSO_HP_REF_MD_ODR_DIV_45:
2646 *val = LSM6DSO_HP_REF_MD_ODR_DIV_45;
2647 break;
2648
2649 case LSM6DSO_HP_REF_MD_ODR_DIV_100:
2650 *val = LSM6DSO_HP_REF_MD_ODR_DIV_100;
2651 break;
2652
2653 case LSM6DSO_HP_REF_MD_ODR_DIV_200:
2654 *val = LSM6DSO_HP_REF_MD_ODR_DIV_200;
2655 break;
2656
2657 case LSM6DSO_HP_REF_MD_ODR_DIV_400:
2658 *val = LSM6DSO_HP_REF_MD_ODR_DIV_400;
2659 break;
2660
2661 case LSM6DSO_HP_REF_MD_ODR_DIV_800:
2662 *val = LSM6DSO_HP_REF_MD_ODR_DIV_800;
2663 break;
2664
2665 case LSM6DSO_LP_ODR_DIV_10:
2666 *val = LSM6DSO_LP_ODR_DIV_10;
2667 break;
2668
2669 case LSM6DSO_LP_ODR_DIV_20:
2670 *val = LSM6DSO_LP_ODR_DIV_20;
2671 break;
2672
2673 case LSM6DSO_LP_ODR_DIV_45:
2674 *val = LSM6DSO_LP_ODR_DIV_45;
2675 break;
2676
2677 case LSM6DSO_LP_ODR_DIV_100:
2678 *val = LSM6DSO_LP_ODR_DIV_100;
2679 break;
2680
2681 case LSM6DSO_LP_ODR_DIV_200:
2682 *val = LSM6DSO_LP_ODR_DIV_200;
2683 break;
2684
2685 case LSM6DSO_LP_ODR_DIV_400:
2686 *val = LSM6DSO_LP_ODR_DIV_400;
2687 break;
2688
2689 case LSM6DSO_LP_ODR_DIV_800:
2690 *val = LSM6DSO_LP_ODR_DIV_800;
2691 break;
2692
2693 default:
2694 *val = LSM6DSO_HP_PATH_DISABLE_ON_OUT;
2695 break;
2696 }
2697
2698 return ret;
2699 }
2700
2701 /**
2702 * @brief Enables accelerometer LPF2 and HPF fast-settling mode.
2703 * The filter sets the second samples after writing this bit.
2704 * Active only during device exit from power-down mode.[set]
2705 *
2706 * @param ctx read / write interface definitions
2707 * @param val change the values of fastsettl_mode_xl in
2708 * reg CTRL8_XL
2709 * @retval interface status (MANDATORY: return 0 -> no Error)
2710 *
2711 */
lsm6dso_xl_fast_settling_set(stmdev_ctx_t * ctx,uint8_t val)2712 int32_t lsm6dso_xl_fast_settling_set(stmdev_ctx_t *ctx, uint8_t val)
2713 {
2714 lsm6dso_ctrl8_xl_t reg;
2715 int32_t ret;
2716
2717 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL8_XL, (uint8_t *)®, 1);
2718
2719 if (ret == 0)
2720 {
2721 reg.fastsettl_mode_xl = val;
2722 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL8_XL, (uint8_t *)®, 1);
2723 }
2724
2725 return ret;
2726 }
2727
2728 /**
2729 * @brief Enables accelerometer LPF2 and HPF fast-settling mode.
2730 * The filter sets the second samples after writing this bit.
2731 * Active only during device exit from power-down mode.[get]
2732 *
2733 * @param ctx read / write interface definitions
2734 * @param val Get the values of fastsettl_mode_xl in reg CTRL8_XL
2735 * @retval interface status (MANDATORY: return 0 -> no Error)
2736 *
2737 */
lsm6dso_xl_fast_settling_get(stmdev_ctx_t * ctx,uint8_t * val)2738 int32_t lsm6dso_xl_fast_settling_get(stmdev_ctx_t *ctx, uint8_t *val)
2739 {
2740 lsm6dso_ctrl8_xl_t reg;
2741 int32_t ret;
2742
2743 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL8_XL, (uint8_t *)®, 1);
2744 *val = reg.fastsettl_mode_xl;
2745
2746 return ret;
2747 }
2748
2749 /**
2750 * @brief HPF or SLOPE filter selection on wake-up and Activity/Inactivity
2751 * functions.[set]
2752 *
2753 * @param ctx read / write interface definitions
2754 * @param val change the values of slope_fds in reg TAP_CFG0
2755 * @retval interface status (MANDATORY: return 0 -> no Error)
2756 *
2757 */
lsm6dso_xl_hp_path_internal_set(stmdev_ctx_t * ctx,lsm6dso_slope_fds_t val)2758 int32_t lsm6dso_xl_hp_path_internal_set(stmdev_ctx_t *ctx,
2759 lsm6dso_slope_fds_t val)
2760 {
2761 lsm6dso_tap_cfg0_t reg;
2762 int32_t ret;
2763
2764 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
2765
2766 if (ret == 0)
2767 {
2768 reg.slope_fds = (uint8_t)val;
2769 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
2770 }
2771
2772 return ret;
2773 }
2774
2775 /**
2776 * @brief HPF or SLOPE filter selection on wake-up and Activity/Inactivity
2777 * functions.[get]
2778 *
2779 * @param ctx read / write interface definitions
2780 * @param val Get the values of slope_fds in reg TAP_CFG0
2781 * @retval interface status (MANDATORY: return 0 -> no Error)
2782 *
2783 */
lsm6dso_xl_hp_path_internal_get(stmdev_ctx_t * ctx,lsm6dso_slope_fds_t * val)2784 int32_t lsm6dso_xl_hp_path_internal_get(stmdev_ctx_t *ctx,
2785 lsm6dso_slope_fds_t *val)
2786 {
2787 lsm6dso_tap_cfg0_t reg;
2788 int32_t ret;
2789
2790 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
2791
2792 switch (reg.slope_fds)
2793 {
2794 case LSM6DSO_USE_SLOPE:
2795 *val = LSM6DSO_USE_SLOPE;
2796 break;
2797
2798 case LSM6DSO_USE_HPF:
2799 *val = LSM6DSO_USE_HPF;
2800 break;
2801
2802 default:
2803 *val = LSM6DSO_USE_SLOPE;
2804 break;
2805 }
2806
2807 return ret;
2808 }
2809
2810 /**
2811 * @brief Enables gyroscope digital high-pass filter. The filter is
2812 * enabled only if the gyro is in HP mode.[set]
2813 *
2814 * @param ctx read / write interface definitions
2815 * @param val change the values of hp_en_g and hp_en_g
2816 * in reg CTRL7_G
2817 * @retval interface status (MANDATORY: return 0 -> no Error)
2818 *
2819 */
lsm6dso_gy_hp_path_internal_set(stmdev_ctx_t * ctx,lsm6dso_hpm_g_t val)2820 int32_t lsm6dso_gy_hp_path_internal_set(stmdev_ctx_t *ctx,
2821 lsm6dso_hpm_g_t val)
2822 {
2823 lsm6dso_ctrl7_g_t reg;
2824 int32_t ret;
2825
2826 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL7_G, (uint8_t *)®, 1);
2827
2828 if (ret == 0)
2829 {
2830 reg.hp_en_g = ((uint8_t)val & 0x80U) >> 7;
2831 reg.hpm_g = (uint8_t)val & 0x03U;
2832 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL7_G, (uint8_t *)®, 1);
2833 }
2834
2835 return ret;
2836 }
2837
2838 /**
2839 * @brief Enables gyroscope digital high-pass filter. The filter is
2840 * enabled only if the gyro is in HP mode.[get]
2841 *
2842 * @param ctx read / write interface definitions
2843 * @param val Get the values of hp_en_g and hp_en_g
2844 * in reg CTRL7_G
2845 * @retval interface status (MANDATORY: return 0 -> no Error)
2846 *
2847 */
lsm6dso_gy_hp_path_internal_get(stmdev_ctx_t * ctx,lsm6dso_hpm_g_t * val)2848 int32_t lsm6dso_gy_hp_path_internal_get(stmdev_ctx_t *ctx,
2849 lsm6dso_hpm_g_t *val)
2850 {
2851 lsm6dso_ctrl7_g_t reg;
2852 int32_t ret;
2853
2854 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL7_G, (uint8_t *)®, 1);
2855
2856 switch ((reg.hp_en_g << 7) + reg.hpm_g)
2857 {
2858 case LSM6DSO_HP_FILTER_NONE:
2859 *val = LSM6DSO_HP_FILTER_NONE;
2860 break;
2861
2862 case LSM6DSO_HP_FILTER_16mHz:
2863 *val = LSM6DSO_HP_FILTER_16mHz;
2864 break;
2865
2866 case LSM6DSO_HP_FILTER_65mHz:
2867 *val = LSM6DSO_HP_FILTER_65mHz;
2868 break;
2869
2870 case LSM6DSO_HP_FILTER_260mHz:
2871 *val = LSM6DSO_HP_FILTER_260mHz;
2872 break;
2873
2874 case LSM6DSO_HP_FILTER_1Hz04:
2875 *val = LSM6DSO_HP_FILTER_1Hz04;
2876 break;
2877
2878 default:
2879 *val = LSM6DSO_HP_FILTER_NONE;
2880 break;
2881 }
2882
2883 return ret;
2884 }
2885
2886 /**
2887 * @}
2888 *
2889 */
2890
2891 /**
2892 * @defgroup LSM6DSO_ Auxiliary_interface
2893 * @brief This section groups all the functions concerning
2894 * auxiliary interface.
2895 * @{
2896 *
2897 */
2898
2899 /**
2900 * @brief aOn auxiliary interface connect/disconnect SDO and OCS
2901 * internal pull-up.[set]
2902 *
2903 * @param ctx read / write interface definitions
2904 * @param val change the values of ois_pu_dis in
2905 * reg PIN_CTRL
2906 * @retval interface status (MANDATORY: return 0 -> no Error)
2907 *
2908 */
lsm6dso_aux_sdo_ocs_mode_set(stmdev_ctx_t * ctx,lsm6dso_ois_pu_dis_t val)2909 int32_t lsm6dso_aux_sdo_ocs_mode_set(stmdev_ctx_t *ctx,
2910 lsm6dso_ois_pu_dis_t val)
2911 {
2912 lsm6dso_pin_ctrl_t reg;
2913 int32_t ret;
2914
2915 ret = lsm6dso_read_reg(ctx, LSM6DSO_PIN_CTRL, (uint8_t *)®, 1);
2916
2917 if (ret == 0)
2918 {
2919 reg.ois_pu_dis = (uint8_t)val;
2920 ret = lsm6dso_write_reg(ctx, LSM6DSO_PIN_CTRL, (uint8_t *)®, 1);
2921 }
2922
2923 return ret;
2924 }
2925
2926 /**
2927 * @brief On auxiliary interface connect/disconnect SDO and OCS
2928 * internal pull-up.[get]
2929 *
2930 * @param ctx read / write interface definitions
2931 * @param val Get the values of ois_pu_dis in reg PIN_CTRL
2932 * @retval interface status (MANDATORY: return 0 -> no Error)
2933 *
2934 */
lsm6dso_aux_sdo_ocs_mode_get(stmdev_ctx_t * ctx,lsm6dso_ois_pu_dis_t * val)2935 int32_t lsm6dso_aux_sdo_ocs_mode_get(stmdev_ctx_t *ctx,
2936 lsm6dso_ois_pu_dis_t *val)
2937 {
2938 lsm6dso_pin_ctrl_t reg;
2939 int32_t ret;
2940
2941 ret = lsm6dso_read_reg(ctx, LSM6DSO_PIN_CTRL, (uint8_t *)®, 1);
2942
2943 switch (reg.ois_pu_dis)
2944 {
2945 case LSM6DSO_AUX_PULL_UP_DISC:
2946 *val = LSM6DSO_AUX_PULL_UP_DISC;
2947 break;
2948
2949 case LSM6DSO_AUX_PULL_UP_CONNECT:
2950 *val = LSM6DSO_AUX_PULL_UP_CONNECT;
2951 break;
2952
2953 default:
2954 *val = LSM6DSO_AUX_PULL_UP_DISC;
2955 break;
2956 }
2957
2958 return ret;
2959 }
2960
2961 /**
2962 * @brief OIS chain on aux interface power on mode.[set]
2963 *
2964 * @param ctx read / write interface definitions
2965 * @param val change the values of ois_on in reg CTRL7_G
2966 * @retval interface status (MANDATORY: return 0 -> no Error)
2967 *
2968 */
lsm6dso_aux_pw_on_ctrl_set(stmdev_ctx_t * ctx,lsm6dso_ois_on_t val)2969 int32_t lsm6dso_aux_pw_on_ctrl_set(stmdev_ctx_t *ctx,
2970 lsm6dso_ois_on_t val)
2971 {
2972 lsm6dso_ctrl7_g_t reg;
2973 int32_t ret;
2974
2975 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL7_G, (uint8_t *)®, 1);
2976
2977 if (ret == 0)
2978 {
2979 reg.ois_on_en = (uint8_t)val & 0x01U;
2980 reg.ois_on = (uint8_t)val & 0x01U;
2981 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL7_G, (uint8_t *)®, 1);
2982 }
2983
2984 return ret;
2985 }
2986
2987 /**
2988 * @brief aux_pw_on_ctrl: [get] OIS chain on aux interface power on mode
2989 *
2990 * @param ctx read / write interface definitions
2991 * @param val Get the values of ois_on in reg CTRL7_G
2992 * @retval interface status (MANDATORY: return 0 -> no Error)
2993 *
2994 */
lsm6dso_aux_pw_on_ctrl_get(stmdev_ctx_t * ctx,lsm6dso_ois_on_t * val)2995 int32_t lsm6dso_aux_pw_on_ctrl_get(stmdev_ctx_t *ctx,
2996 lsm6dso_ois_on_t *val)
2997 {
2998 lsm6dso_ctrl7_g_t reg;
2999 int32_t ret;
3000
3001 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL7_G, (uint8_t *)®, 1);
3002
3003 switch (reg.ois_on)
3004 {
3005 case LSM6DSO_AUX_ON:
3006 *val = LSM6DSO_AUX_ON;
3007 break;
3008
3009 case LSM6DSO_AUX_ON_BY_AUX_INTERFACE:
3010 *val = LSM6DSO_AUX_ON_BY_AUX_INTERFACE;
3011 break;
3012
3013 default:
3014 *val = LSM6DSO_AUX_ON;
3015 break;
3016 }
3017
3018 return ret;
3019 }
3020
3021 /**
3022 * @brief Accelerometer full-scale management between UI chain and
3023 * OIS chain. When XL UI is on, the full scale is the same
3024 * between UI/OIS and is chosen by the UI CTRL registers;
3025 * when XL UI is in PD, the OIS can choose the FS.
3026 * Full scales are independent between the UI/OIS chain
3027 * but both bound to 8 g.[set]
3028 *
3029 * @param ctx read / write interface definitions
3030 * @param val change the values of xl_fs_mode in
3031 * reg CTRL8_XL
3032 * @retval interface status (MANDATORY: return 0 -> no Error)
3033 *
3034 */
lsm6dso_aux_xl_fs_mode_set(stmdev_ctx_t * ctx,lsm6dso_xl_fs_mode_t val)3035 int32_t lsm6dso_aux_xl_fs_mode_set(stmdev_ctx_t *ctx,
3036 lsm6dso_xl_fs_mode_t val)
3037 {
3038 lsm6dso_ctrl8_xl_t reg;
3039 int32_t ret;
3040
3041 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL8_XL, (uint8_t *)®, 1);
3042
3043 if (ret == 0)
3044 {
3045 reg.xl_fs_mode = (uint8_t)val;
3046 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL8_XL, (uint8_t *)®, 1);
3047 }
3048
3049 return ret;
3050 }
3051
3052 /**
3053 * @brief Accelerometer full-scale management between UI chain and
3054 * OIS chain. When XL UI is on, the full scale is the same
3055 * between UI/OIS and is chosen by the UI CTRL registers;
3056 * when XL UI is in PD, the OIS can choose the FS.
3057 * Full scales are independent between the UI/OIS chain
3058 * but both bound to 8 g.[get]
3059 *
3060 * @param ctx read / write interface definitions
3061 * @param val Get the values of xl_fs_mode in reg CTRL8_XL
3062 * @retval interface status (MANDATORY: return 0 -> no Error)
3063 *
3064 */
lsm6dso_aux_xl_fs_mode_get(stmdev_ctx_t * ctx,lsm6dso_xl_fs_mode_t * val)3065 int32_t lsm6dso_aux_xl_fs_mode_get(stmdev_ctx_t *ctx,
3066 lsm6dso_xl_fs_mode_t *val)
3067 {
3068 lsm6dso_ctrl8_xl_t reg;
3069 int32_t ret;
3070
3071 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL8_XL, (uint8_t *)®, 1);
3072
3073 switch (reg.xl_fs_mode)
3074 {
3075 case LSM6DSO_USE_SAME_XL_FS:
3076 *val = LSM6DSO_USE_SAME_XL_FS;
3077 break;
3078
3079 case LSM6DSO_USE_DIFFERENT_XL_FS:
3080 *val = LSM6DSO_USE_DIFFERENT_XL_FS;
3081 break;
3082
3083 default:
3084 *val = LSM6DSO_USE_SAME_XL_FS;
3085 break;
3086 }
3087
3088 return ret;
3089 }
3090
3091 /**
3092 * @brief The STATUS_SPIAux register is read by the auxiliary SPI.[get]
3093 *
3094 * @param ctx read / write interface definitions
3095 * @param lsm6dso_status_spiaux_t: registers STATUS_SPIAUX
3096 * @retval interface status (MANDATORY: return 0 -> no Error)
3097 *
3098 */
lsm6dso_aux_status_reg_get(stmdev_ctx_t * ctx,lsm6dso_status_spiaux_t * val)3099 int32_t lsm6dso_aux_status_reg_get(stmdev_ctx_t *ctx,
3100 lsm6dso_status_spiaux_t *val)
3101 {
3102 int32_t ret;
3103
3104 ret = lsm6dso_read_reg(ctx, LSM6DSO_STATUS_SPIAUX, (uint8_t *) val, 1);
3105
3106 return ret;
3107 }
3108
3109 /**
3110 * @brief aux_xl_flag_data_ready: [get] AUX accelerometer data available
3111 *
3112 * @param ctx read / write interface definitions
3113 * @param val Get the values of xlda in reg STATUS_SPIAUX
3114 * @retval interface status (MANDATORY: return 0 -> no Error)
3115 *
3116 */
lsm6dso_aux_xl_flag_data_ready_get(stmdev_ctx_t * ctx,uint8_t * val)3117 int32_t lsm6dso_aux_xl_flag_data_ready_get(stmdev_ctx_t *ctx,
3118 uint8_t *val)
3119 {
3120 lsm6dso_status_spiaux_t reg;
3121 int32_t ret;
3122
3123 ret = lsm6dso_read_reg(ctx, LSM6DSO_STATUS_SPIAUX, (uint8_t *)®, 1);
3124 *val = reg.xlda;
3125
3126 return ret;
3127 }
3128
3129 /**
3130 * @brief aux_gy_flag_data_ready: [get] AUX gyroscope data available.
3131 *
3132 * @param ctx read / write interface definitions
3133 * @param val Get the values of gda in reg STATUS_SPIAUX
3134 * @retval interface status (MANDATORY: return 0 -> no Error)
3135 *
3136 */
lsm6dso_aux_gy_flag_data_ready_get(stmdev_ctx_t * ctx,uint8_t * val)3137 int32_t lsm6dso_aux_gy_flag_data_ready_get(stmdev_ctx_t *ctx,
3138 uint8_t *val)
3139 {
3140 lsm6dso_status_spiaux_t reg;
3141 int32_t ret;
3142
3143 ret = lsm6dso_read_reg(ctx, LSM6DSO_STATUS_SPIAUX, (uint8_t *)®, 1);
3144 *val = reg.gda;
3145
3146 return ret;
3147 }
3148
3149 /**
3150 * @brief High when the gyroscope output is in the settling phase.[get]
3151 *
3152 * @param ctx read / write interface definitions
3153 * @param val Get the values of gyro_settling in reg STATUS_SPIAUX
3154 * @retval interface status (MANDATORY: return 0 -> no Error)
3155 *
3156 */
lsm6dso_aux_gy_flag_settling_get(stmdev_ctx_t * ctx,uint8_t * val)3157 int32_t lsm6dso_aux_gy_flag_settling_get(stmdev_ctx_t *ctx,
3158 uint8_t *val)
3159 {
3160 lsm6dso_status_spiaux_t reg;
3161 int32_t ret;
3162
3163 ret = lsm6dso_read_reg(ctx, LSM6DSO_STATUS_SPIAUX, (uint8_t *)®, 1);
3164 *val = reg.gyro_settling;
3165
3166 return ret;
3167 }
3168
3169 /**
3170 * @brief Selects accelerometer self-test. Effective only if XL OIS
3171 * chain is enabled.[set]
3172 *
3173 * @param ctx read / write interface definitions
3174 * @param val change the values of st_xl_ois in reg INT_OIS
3175 * @retval interface status (MANDATORY: return 0 -> no Error)
3176 *
3177 */
lsm6dso_aux_xl_self_test_set(stmdev_ctx_t * ctx,lsm6dso_st_xl_ois_t val)3178 int32_t lsm6dso_aux_xl_self_test_set(stmdev_ctx_t *ctx,
3179 lsm6dso_st_xl_ois_t val)
3180 {
3181 lsm6dso_int_ois_t reg;
3182 int32_t ret;
3183
3184 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_OIS, (uint8_t *)®, 1);
3185
3186 if (ret == 0)
3187 {
3188 reg.st_xl_ois = (uint8_t)val;
3189 ret = lsm6dso_write_reg(ctx, LSM6DSO_INT_OIS, (uint8_t *)®, 1);
3190 }
3191
3192 return ret;
3193 }
3194
3195 /**
3196 * @brief Selects accelerometer self-test. Effective only if XL OIS
3197 * chain is enabled.[get]
3198 *
3199 * @param ctx read / write interface definitions
3200 * @param val Get the values of st_xl_ois in reg INT_OIS
3201 * @retval interface status (MANDATORY: return 0 -> no Error)
3202 *
3203 */
lsm6dso_aux_xl_self_test_get(stmdev_ctx_t * ctx,lsm6dso_st_xl_ois_t * val)3204 int32_t lsm6dso_aux_xl_self_test_get(stmdev_ctx_t *ctx,
3205 lsm6dso_st_xl_ois_t *val)
3206 {
3207 lsm6dso_int_ois_t reg;
3208 int32_t ret;
3209
3210 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_OIS, (uint8_t *)®, 1);
3211
3212 switch (reg.st_xl_ois)
3213 {
3214 case LSM6DSO_AUX_XL_DISABLE:
3215 *val = LSM6DSO_AUX_XL_DISABLE;
3216 break;
3217
3218 case LSM6DSO_AUX_XL_POS:
3219 *val = LSM6DSO_AUX_XL_POS;
3220 break;
3221
3222 case LSM6DSO_AUX_XL_NEG:
3223 *val = LSM6DSO_AUX_XL_NEG;
3224 break;
3225
3226 default:
3227 *val = LSM6DSO_AUX_XL_DISABLE;
3228 break;
3229 }
3230
3231 return ret;
3232 }
3233
3234 /**
3235 * @brief Indicates polarity of DEN signal on OIS chain.[set]
3236 *
3237 * @param ctx read / write interface definitions
3238 * @param val change the values of den_lh_ois in
3239 * reg INT_OIS
3240 * @retval interface status (MANDATORY: return 0 -> no Error)
3241 *
3242 */
lsm6dso_aux_den_polarity_set(stmdev_ctx_t * ctx,lsm6dso_den_lh_ois_t val)3243 int32_t lsm6dso_aux_den_polarity_set(stmdev_ctx_t *ctx,
3244 lsm6dso_den_lh_ois_t val)
3245 {
3246 lsm6dso_int_ois_t reg;
3247 int32_t ret;
3248
3249 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_OIS, (uint8_t *)®, 1);
3250
3251 if (ret == 0)
3252 {
3253 reg.den_lh_ois = (uint8_t)val;
3254 ret = lsm6dso_write_reg(ctx, LSM6DSO_INT_OIS, (uint8_t *)®, 1);
3255 }
3256
3257 return ret;
3258 }
3259
3260 /**
3261 * @brief Indicates polarity of DEN signal on OIS chain.[get]
3262 *
3263 * @param ctx read / write interface definitions
3264 * @param val Get the values of den_lh_ois in reg INT_OIS
3265 * @retval interface status (MANDATORY: return 0 -> no Error)
3266 *
3267 */
lsm6dso_aux_den_polarity_get(stmdev_ctx_t * ctx,lsm6dso_den_lh_ois_t * val)3268 int32_t lsm6dso_aux_den_polarity_get(stmdev_ctx_t *ctx,
3269 lsm6dso_den_lh_ois_t *val)
3270 {
3271 lsm6dso_int_ois_t reg;
3272 int32_t ret;
3273
3274 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_OIS, (uint8_t *)®, 1);
3275
3276 switch (reg.den_lh_ois)
3277 {
3278 case LSM6DSO_AUX_DEN_ACTIVE_LOW:
3279 *val = LSM6DSO_AUX_DEN_ACTIVE_LOW;
3280 break;
3281
3282 case LSM6DSO_AUX_DEN_ACTIVE_HIGH:
3283 *val = LSM6DSO_AUX_DEN_ACTIVE_HIGH;
3284 break;
3285
3286 default:
3287 *val = LSM6DSO_AUX_DEN_ACTIVE_LOW;
3288 break;
3289 }
3290
3291 return ret;
3292 }
3293
3294 /**
3295 * @brief Configure DEN mode on the OIS chain.[set]
3296 *
3297 * @param ctx read / write interface definitions
3298 * @param val change the values of lvl2_ois in reg INT_OIS
3299 * @retval interface status (MANDATORY: return 0 -> no Error)
3300 *
3301 */
lsm6dso_aux_den_mode_set(stmdev_ctx_t * ctx,lsm6dso_lvl2_ois_t val)3302 int32_t lsm6dso_aux_den_mode_set(stmdev_ctx_t *ctx,
3303 lsm6dso_lvl2_ois_t val)
3304 {
3305 lsm6dso_ctrl1_ois_t ctrl1_ois;
3306 lsm6dso_int_ois_t int_ois;
3307 int32_t ret;
3308
3309 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_OIS, (uint8_t *) &int_ois, 1);
3310
3311 if (ret == 0)
3312 {
3313 int_ois.lvl2_ois = (uint8_t)val & 0x01U;
3314 ret = lsm6dso_write_reg(ctx, LSM6DSO_INT_OIS, (uint8_t *) &int_ois, 1);
3315 }
3316
3317 if (ret == 0)
3318 {
3319 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_OIS, (uint8_t *) &ctrl1_ois, 1);
3320 }
3321
3322 if (ret == 0)
3323 {
3324 ctrl1_ois.lvl1_ois = ((uint8_t)val & 0x02U) >> 1;
3325 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL1_OIS,
3326 (uint8_t *) &ctrl1_ois, 1);
3327 }
3328
3329 return ret;
3330 }
3331
3332 /**
3333 * @brief Configure DEN mode on the OIS chain.[get]
3334 *
3335 * @param ctx read / write interface definitions
3336 * @param val Get the values of lvl2_ois in reg INT_OIS
3337 * @retval interface status (MANDATORY: return 0 -> no Error)
3338 *
3339 */
lsm6dso_aux_den_mode_get(stmdev_ctx_t * ctx,lsm6dso_lvl2_ois_t * val)3340 int32_t lsm6dso_aux_den_mode_get(stmdev_ctx_t *ctx,
3341 lsm6dso_lvl2_ois_t *val)
3342 {
3343 lsm6dso_ctrl1_ois_t ctrl1_ois;
3344 lsm6dso_int_ois_t int_ois;
3345 int32_t ret;
3346
3347 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_OIS, (uint8_t *) &int_ois, 1);
3348
3349 if (ret == 0)
3350 {
3351 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_OIS, (uint8_t *) &ctrl1_ois, 1);
3352
3353 switch ((ctrl1_ois.lvl1_ois << 1) + int_ois.lvl2_ois)
3354 {
3355 case LSM6DSO_AUX_DEN_DISABLE:
3356 *val = LSM6DSO_AUX_DEN_DISABLE;
3357 break;
3358
3359 case LSM6DSO_AUX_DEN_LEVEL_LATCH:
3360 *val = LSM6DSO_AUX_DEN_LEVEL_LATCH;
3361 break;
3362
3363 case LSM6DSO_AUX_DEN_LEVEL_TRIG:
3364 *val = LSM6DSO_AUX_DEN_LEVEL_TRIG;
3365 break;
3366
3367 default:
3368 *val = LSM6DSO_AUX_DEN_DISABLE;
3369 break;
3370 }
3371 }
3372
3373 return ret;
3374 }
3375
3376 /**
3377 * @brief Enables/Disable OIS chain DRDY on INT2 pin.
3378 * This setting has priority over all other INT2 settings.[set]
3379 *
3380 * @param ctx read / write interface definitions
3381 * @param val change the values of int2_drdy_ois in reg INT_OIS
3382 * @retval interface status (MANDATORY: return 0 -> no Error)
3383 *
3384 */
lsm6dso_aux_drdy_on_int2_set(stmdev_ctx_t * ctx,uint8_t val)3385 int32_t lsm6dso_aux_drdy_on_int2_set(stmdev_ctx_t *ctx, uint8_t val)
3386 {
3387 lsm6dso_int_ois_t reg;
3388 int32_t ret;
3389
3390 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_OIS, (uint8_t *)®, 1);
3391
3392 if (ret == 0)
3393 {
3394 reg.int2_drdy_ois = val;
3395 ret = lsm6dso_write_reg(ctx, LSM6DSO_INT_OIS, (uint8_t *)®, 1);
3396 }
3397
3398 return ret;
3399 }
3400
3401 /**
3402 * @brief Enables/Disable OIS chain DRDY on INT2 pin.
3403 * This setting has priority over all other INT2 settings.[get]
3404 *
3405 * @param ctx read / write interface definitions
3406 * @param val Get the values of int2_drdy_ois in reg INT_OIS
3407 * @retval interface status (MANDATORY: return 0 -> no Error)
3408 *
3409 */
lsm6dso_aux_drdy_on_int2_get(stmdev_ctx_t * ctx,uint8_t * val)3410 int32_t lsm6dso_aux_drdy_on_int2_get(stmdev_ctx_t *ctx, uint8_t *val)
3411 {
3412 lsm6dso_int_ois_t reg;
3413 int32_t ret;
3414
3415 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_OIS, (uint8_t *)®, 1);
3416 *val = reg.int2_drdy_ois;
3417
3418 return ret;
3419 }
3420
3421 /**
3422 * @brief Enables OIS chain data processing for gyro in Mode 3 and Mode 4
3423 * (mode4_en = 1) and accelerometer data in and Mode 4 (mode4_en = 1).
3424 * When the OIS chain is enabled, the OIS outputs are available
3425 * through the SPI2 in registers OUTX_L_G (22h) through
3426 * OUTZ_H_G (27h) and STATUS_REG (1Eh) / STATUS_SPIAux, and
3427 * LPF1 is dedicated to this chain.[set]
3428 *
3429 * @param ctx read / write interface definitions
3430 * @param val change the values of ois_en_spi2 in
3431 * reg CTRL1_OIS
3432 * @retval interface status (MANDATORY: return 0 -> no Error)
3433 *
3434 */
lsm6dso_aux_mode_set(stmdev_ctx_t * ctx,lsm6dso_ois_en_spi2_t val)3435 int32_t lsm6dso_aux_mode_set(stmdev_ctx_t *ctx,
3436 lsm6dso_ois_en_spi2_t val)
3437 {
3438 lsm6dso_ctrl1_ois_t reg;
3439 int32_t ret;
3440
3441 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_OIS, (uint8_t *)®, 1);
3442
3443 if (ret == 0)
3444 {
3445 reg.ois_en_spi2 = (uint8_t)val & 0x01U;
3446 reg.mode4_en = ((uint8_t)val & 0x02U) >> 1;
3447 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL1_OIS, (uint8_t *)®, 1);
3448 }
3449
3450 return ret;
3451 }
3452
3453 /**
3454 * @brief Enables OIS chain data processing for gyro in Mode 3 and Mode 4
3455 * (mode4_en = 1) and accelerometer data in and Mode 4 (mode4_en = 1).
3456 * When the OIS chain is enabled, the OIS outputs are available
3457 * through the SPI2 in registers OUTX_L_G (22h) through
3458 * OUTZ_H_G (27h) and STATUS_REG (1Eh) / STATUS_SPIAux, and
3459 * LPF1 is dedicated to this chain.[get]
3460 *
3461 * @param ctx read / write interface definitions
3462 * @param val Get the values of ois_en_spi2 in
3463 * reg CTRL1_OIS
3464 * @retval interface status (MANDATORY: return 0 -> no Error)
3465 *
3466 */
lsm6dso_aux_mode_get(stmdev_ctx_t * ctx,lsm6dso_ois_en_spi2_t * val)3467 int32_t lsm6dso_aux_mode_get(stmdev_ctx_t *ctx,
3468 lsm6dso_ois_en_spi2_t *val)
3469 {
3470 lsm6dso_ctrl1_ois_t reg;
3471 int32_t ret;
3472
3473 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_OIS, (uint8_t *)®, 1);
3474
3475 switch ((reg.mode4_en << 1) | reg.ois_en_spi2)
3476 {
3477 case LSM6DSO_AUX_DISABLE:
3478 *val = LSM6DSO_AUX_DISABLE;
3479 break;
3480
3481 case LSM6DSO_MODE_3_GY:
3482 *val = LSM6DSO_MODE_3_GY;
3483 break;
3484
3485 case LSM6DSO_MODE_4_GY_XL:
3486 *val = LSM6DSO_MODE_4_GY_XL;
3487 break;
3488
3489 default:
3490 *val = LSM6DSO_AUX_DISABLE;
3491 break;
3492 }
3493
3494 return ret;
3495 }
3496
3497 /**
3498 * @brief Selects gyroscope OIS chain full-scale.[set]
3499 *
3500 * @param ctx read / write interface definitions
3501 * @param val change the values of fs_g_ois in reg CTRL1_OIS
3502 * @retval interface status (MANDATORY: return 0 -> no Error)
3503 *
3504 */
lsm6dso_aux_gy_full_scale_set(stmdev_ctx_t * ctx,lsm6dso_fs_g_ois_t val)3505 int32_t lsm6dso_aux_gy_full_scale_set(stmdev_ctx_t *ctx,
3506 lsm6dso_fs_g_ois_t val)
3507 {
3508 lsm6dso_ctrl1_ois_t reg;
3509 int32_t ret;
3510
3511 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_OIS, (uint8_t *)®, 1);
3512
3513 if (ret == 0)
3514 {
3515 reg.fs_g_ois = (uint8_t)val;
3516 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL1_OIS, (uint8_t *)®, 1);
3517 }
3518
3519 return ret;
3520 }
3521
3522 /**
3523 * @brief Selects gyroscope OIS chain full-scale.[get]
3524 *
3525 * @param ctx read / write interface definitions
3526 * @param val Get the values of fs_g_ois in reg CTRL1_OIS
3527 * @retval interface status (MANDATORY: return 0 -> no Error)
3528 *
3529 */
lsm6dso_aux_gy_full_scale_get(stmdev_ctx_t * ctx,lsm6dso_fs_g_ois_t * val)3530 int32_t lsm6dso_aux_gy_full_scale_get(stmdev_ctx_t *ctx,
3531 lsm6dso_fs_g_ois_t *val)
3532 {
3533 lsm6dso_ctrl1_ois_t reg;
3534 int32_t ret;
3535
3536 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_OIS, (uint8_t *)®, 1);
3537
3538 switch (reg.fs_g_ois)
3539 {
3540 case LSM6DSO_250dps_AUX:
3541 *val = LSM6DSO_250dps_AUX;
3542 break;
3543
3544 case LSM6DSO_125dps_AUX:
3545 *val = LSM6DSO_125dps_AUX;
3546 break;
3547
3548 case LSM6DSO_500dps_AUX:
3549 *val = LSM6DSO_500dps_AUX;
3550 break;
3551
3552 case LSM6DSO_1000dps_AUX:
3553 *val = LSM6DSO_1000dps_AUX;
3554 break;
3555
3556 case LSM6DSO_2000dps_AUX:
3557 *val = LSM6DSO_2000dps_AUX;
3558 break;
3559
3560 default:
3561 *val = LSM6DSO_250dps_AUX;
3562 break;
3563 }
3564
3565 return ret;
3566 }
3567
3568 /**
3569 * @brief SPI2 3- or 4-wire interface.[set]
3570 *
3571 * @param ctx read / write interface definitions
3572 * @param val change the values of sim_ois in reg CTRL1_OIS
3573 * @retval interface status (MANDATORY: return 0 -> no Error)
3574 *
3575 */
lsm6dso_aux_spi_mode_set(stmdev_ctx_t * ctx,lsm6dso_sim_ois_t val)3576 int32_t lsm6dso_aux_spi_mode_set(stmdev_ctx_t *ctx,
3577 lsm6dso_sim_ois_t val)
3578 {
3579 lsm6dso_ctrl1_ois_t reg;
3580 int32_t ret;
3581
3582 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_OIS, (uint8_t *)®, 1);
3583
3584 if (ret == 0)
3585 {
3586 reg.sim_ois = (uint8_t)val;
3587 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL1_OIS, (uint8_t *)®, 1);
3588 }
3589
3590 return ret;
3591 }
3592
3593 /**
3594 * @brief SPI2 3- or 4-wire interface.[get]
3595 *
3596 * @param ctx read / write interface definitions
3597 * @param val Get the values of sim_ois in reg CTRL1_OIS
3598 * @retval interface status (MANDATORY: return 0 -> no Error)
3599 *
3600 */
lsm6dso_aux_spi_mode_get(stmdev_ctx_t * ctx,lsm6dso_sim_ois_t * val)3601 int32_t lsm6dso_aux_spi_mode_get(stmdev_ctx_t *ctx,
3602 lsm6dso_sim_ois_t *val)
3603 {
3604 lsm6dso_ctrl1_ois_t reg;
3605 int32_t ret;
3606
3607 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_OIS, (uint8_t *)®, 1);
3608
3609 switch (reg.sim_ois)
3610 {
3611 case LSM6DSO_AUX_SPI_4_WIRE:
3612 *val = LSM6DSO_AUX_SPI_4_WIRE;
3613 break;
3614
3615 case LSM6DSO_AUX_SPI_3_WIRE:
3616 *val = LSM6DSO_AUX_SPI_3_WIRE;
3617 break;
3618
3619 default:
3620 *val = LSM6DSO_AUX_SPI_4_WIRE;
3621 break;
3622 }
3623
3624 return ret;
3625 }
3626
3627 /**
3628 * @brief Selects gyroscope digital LPF1 filter bandwidth.[set]
3629 *
3630 * @param ctx read / write interface definitions
3631 * @param val change the values of ftype_ois in
3632 * reg CTRL2_OIS
3633 * @retval interface status (MANDATORY: return 0 -> no Error)
3634 *
3635 */
lsm6dso_aux_gy_lp1_bandwidth_set(stmdev_ctx_t * ctx,lsm6dso_ftype_ois_t val)3636 int32_t lsm6dso_aux_gy_lp1_bandwidth_set(stmdev_ctx_t *ctx,
3637 lsm6dso_ftype_ois_t val)
3638 {
3639 lsm6dso_ctrl2_ois_t reg;
3640 int32_t ret;
3641
3642 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL2_OIS, (uint8_t *)®, 1);
3643
3644 if (ret == 0)
3645 {
3646 reg.ftype_ois = (uint8_t)val;
3647 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL2_OIS, (uint8_t *)®, 1);
3648 }
3649
3650 return ret;
3651 }
3652
3653 /**
3654 * @brief Selects gyroscope digital LPF1 filter bandwidth.[get]
3655 *
3656 * @param ctx read / write interface definitions
3657 * @param val Get the values of ftype_ois in reg CTRL2_OIS
3658 * @retval interface status (MANDATORY: return 0 -> no Error)
3659 *
3660 */
lsm6dso_aux_gy_lp1_bandwidth_get(stmdev_ctx_t * ctx,lsm6dso_ftype_ois_t * val)3661 int32_t lsm6dso_aux_gy_lp1_bandwidth_get(stmdev_ctx_t *ctx,
3662 lsm6dso_ftype_ois_t *val)
3663 {
3664 lsm6dso_ctrl2_ois_t reg;
3665 int32_t ret;
3666
3667 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL2_OIS, (uint8_t *)®, 1);
3668
3669 switch (reg.ftype_ois)
3670 {
3671 case LSM6DSO_351Hz39:
3672 *val = LSM6DSO_351Hz39;
3673 break;
3674
3675 case LSM6DSO_236Hz63:
3676 *val = LSM6DSO_236Hz63;
3677 break;
3678
3679 case LSM6DSO_172Hz70:
3680 *val = LSM6DSO_172Hz70;
3681 break;
3682
3683 case LSM6DSO_937Hz91:
3684 *val = LSM6DSO_937Hz91;
3685 break;
3686
3687 default:
3688 *val = LSM6DSO_351Hz39;
3689 break;
3690 }
3691
3692 return ret;
3693 }
3694
3695 /**
3696 * @brief Selects gyroscope OIS chain digital high-pass filter cutoff.[set]
3697 *
3698 * @param ctx read / write interface definitions
3699 * @param val change the values of hpm_ois in reg CTRL2_OIS
3700 * @retval interface status (MANDATORY: return 0 -> no Error)
3701 *
3702 */
lsm6dso_aux_gy_hp_bandwidth_set(stmdev_ctx_t * ctx,lsm6dso_hpm_ois_t val)3703 int32_t lsm6dso_aux_gy_hp_bandwidth_set(stmdev_ctx_t *ctx,
3704 lsm6dso_hpm_ois_t val)
3705 {
3706 lsm6dso_ctrl2_ois_t reg;
3707 int32_t ret;
3708
3709 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL2_OIS, (uint8_t *)®, 1);
3710
3711 if (ret == 0)
3712 {
3713 reg.hpm_ois = (uint8_t)val & 0x03U;
3714 reg.hp_en_ois = ((uint8_t)val & 0x10U) >> 4;
3715 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL2_OIS, (uint8_t *)®, 1);
3716 }
3717
3718 return ret;
3719 }
3720
3721 /**
3722 * @brief Selects gyroscope OIS chain digital high-pass filter cutoff.[get]
3723 *
3724 * @param ctx read / write interface definitions
3725 * @param val Get the values of hpm_ois in reg CTRL2_OIS
3726 * @retval interface status (MANDATORY: return 0 -> no Error)
3727 *
3728 */
lsm6dso_aux_gy_hp_bandwidth_get(stmdev_ctx_t * ctx,lsm6dso_hpm_ois_t * val)3729 int32_t lsm6dso_aux_gy_hp_bandwidth_get(stmdev_ctx_t *ctx,
3730 lsm6dso_hpm_ois_t *val)
3731 {
3732 lsm6dso_ctrl2_ois_t reg;
3733 int32_t ret;
3734
3735 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL2_OIS, (uint8_t *)®, 1);
3736
3737 switch ((reg.hp_en_ois << 4) | reg.hpm_ois)
3738 {
3739 case LSM6DSO_AUX_HP_DISABLE:
3740 *val = LSM6DSO_AUX_HP_DISABLE;
3741 break;
3742
3743 case LSM6DSO_AUX_HP_Hz016:
3744 *val = LSM6DSO_AUX_HP_Hz016;
3745 break;
3746
3747 case LSM6DSO_AUX_HP_Hz065:
3748 *val = LSM6DSO_AUX_HP_Hz065;
3749 break;
3750
3751 case LSM6DSO_AUX_HP_Hz260:
3752 *val = LSM6DSO_AUX_HP_Hz260;
3753 break;
3754
3755 case LSM6DSO_AUX_HP_1Hz040:
3756 *val = LSM6DSO_AUX_HP_1Hz040;
3757 break;
3758
3759 default:
3760 *val = LSM6DSO_AUX_HP_DISABLE;
3761 break;
3762 }
3763
3764 return ret;
3765 }
3766
3767 /**
3768 * @brief Enable / Disables OIS chain clamp.
3769 * Enable: All OIS chain outputs = 8000h
3770 * during self-test; Disable: OIS chain self-test
3771 * outputs dependent from the aux gyro full
3772 * scale selected.[set]
3773 *
3774 * @param ctx read / write interface definitions
3775 * @param val change the values of st_ois_clampdis in
3776 * reg CTRL3_OIS
3777 * @retval interface status (MANDATORY: return 0 -> no Error)
3778 *
3779 */
lsm6dso_aux_gy_clamp_set(stmdev_ctx_t * ctx,lsm6dso_st_ois_clampdis_t val)3780 int32_t lsm6dso_aux_gy_clamp_set(stmdev_ctx_t *ctx,
3781 lsm6dso_st_ois_clampdis_t val)
3782 {
3783 lsm6dso_ctrl3_ois_t reg;
3784 int32_t ret;
3785
3786 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_OIS, (uint8_t *)®, 1);
3787
3788 if (ret == 0)
3789 {
3790 reg.st_ois_clampdis = (uint8_t)val;
3791 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_OIS, (uint8_t *)®, 1);
3792 }
3793
3794 return ret;
3795 }
3796
3797 /**
3798 * @brief Enable / Disables OIS chain clamp.
3799 * Enable: All OIS chain outputs = 8000h
3800 * during self-test; Disable: OIS chain self-test
3801 * outputs dependent from the aux gyro full
3802 * scale selected.[set]
3803 *
3804 * @param ctx read / write interface definitions
3805 * @param val Get the values of st_ois_clampdis in
3806 * reg CTRL3_OIS
3807 * @retval interface status (MANDATORY: return 0 -> no Error)
3808 *
3809 */
lsm6dso_aux_gy_clamp_get(stmdev_ctx_t * ctx,lsm6dso_st_ois_clampdis_t * val)3810 int32_t lsm6dso_aux_gy_clamp_get(stmdev_ctx_t *ctx,
3811 lsm6dso_st_ois_clampdis_t *val)
3812 {
3813 lsm6dso_ctrl3_ois_t reg;
3814 int32_t ret;
3815
3816 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_OIS, (uint8_t *)®, 1);
3817
3818 switch (reg.st_ois_clampdis)
3819 {
3820 case LSM6DSO_ENABLE_CLAMP:
3821 *val = LSM6DSO_ENABLE_CLAMP;
3822 break;
3823
3824 case LSM6DSO_DISABLE_CLAMP:
3825 *val = LSM6DSO_DISABLE_CLAMP;
3826 break;
3827
3828 default:
3829 *val = LSM6DSO_ENABLE_CLAMP;
3830 break;
3831 }
3832
3833 return ret;
3834 }
3835
3836 /**
3837 * @brief Selects gyroscope OIS chain self-test.[set]
3838 *
3839 * @param ctx read / write interface definitions
3840 * @param val change the values of st_ois in reg CTRL3_OIS
3841 * @retval interface status (MANDATORY: return 0 -> no Error)
3842 *
3843 */
lsm6dso_aux_gy_self_test_set(stmdev_ctx_t * ctx,lsm6dso_st_ois_t val)3844 int32_t lsm6dso_aux_gy_self_test_set(stmdev_ctx_t *ctx,
3845 lsm6dso_st_ois_t val)
3846 {
3847 lsm6dso_ctrl3_ois_t reg;
3848 int32_t ret;
3849
3850 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_OIS, (uint8_t *)®, 1);
3851
3852 if (ret == 0)
3853 {
3854 reg.st_ois = (uint8_t)val;
3855 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_OIS, (uint8_t *)®, 1);
3856 }
3857
3858 return ret;
3859 }
3860
3861 /**
3862 * @brief Selects gyroscope OIS chain self-test.[get]
3863 *
3864 * @param ctx read / write interface definitions
3865 * @param val Get the values of st_ois in reg CTRL3_OIS
3866 * @retval interface status (MANDATORY: return 0 -> no Error)
3867 *
3868 */
lsm6dso_aux_gy_self_test_get(stmdev_ctx_t * ctx,lsm6dso_st_ois_t * val)3869 int32_t lsm6dso_aux_gy_self_test_get(stmdev_ctx_t *ctx,
3870 lsm6dso_st_ois_t *val)
3871 {
3872 lsm6dso_ctrl3_ois_t reg;
3873 int32_t ret;
3874
3875 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_OIS, (uint8_t *)®, 1);
3876
3877 switch (reg.st_ois)
3878 {
3879 case LSM6DSO_AUX_GY_DISABLE:
3880 *val = LSM6DSO_AUX_GY_DISABLE;
3881 break;
3882
3883 case LSM6DSO_AUX_GY_POS:
3884 *val = LSM6DSO_AUX_GY_POS;
3885 break;
3886
3887 case LSM6DSO_AUX_GY_NEG:
3888 *val = LSM6DSO_AUX_GY_NEG;
3889 break;
3890
3891 default:
3892 *val = LSM6DSO_AUX_GY_DISABLE;
3893 break;
3894 }
3895
3896 return ret;
3897 }
3898
3899 /**
3900 * @brief Selects accelerometer OIS channel bandwidth.[set]
3901 *
3902 * @param ctx read / write interface definitions
3903 * @param val change the values of
3904 * filter_xl_conf_ois in reg CTRL3_OIS
3905 * @retval interface status (MANDATORY: return 0 -> no Error)
3906 *
3907 */
lsm6dso_aux_xl_bandwidth_set(stmdev_ctx_t * ctx,lsm6dso_filter_xl_conf_ois_t val)3908 int32_t lsm6dso_aux_xl_bandwidth_set(stmdev_ctx_t *ctx,
3909 lsm6dso_filter_xl_conf_ois_t val)
3910 {
3911 lsm6dso_ctrl3_ois_t reg;
3912 int32_t ret;
3913
3914 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_OIS, (uint8_t *)®, 1);
3915
3916 if (ret == 0)
3917 {
3918 reg.filter_xl_conf_ois = (uint8_t)val;
3919 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_OIS, (uint8_t *)®, 1);
3920 }
3921
3922 return ret;
3923 }
3924
3925 /**
3926 * @brief Selects accelerometer OIS channel bandwidth.[get]
3927 *
3928 * @param ctx read / write interface definitions
3929 * @param val Get the values of
3930 * filter_xl_conf_ois in reg CTRL3_OIS
3931 * @retval interface status (MANDATORY: return 0 -> no Error)
3932 *
3933 */
lsm6dso_aux_xl_bandwidth_get(stmdev_ctx_t * ctx,lsm6dso_filter_xl_conf_ois_t * val)3934 int32_t lsm6dso_aux_xl_bandwidth_get(stmdev_ctx_t *ctx,
3935 lsm6dso_filter_xl_conf_ois_t *val)
3936 {
3937 lsm6dso_ctrl3_ois_t reg;
3938 int32_t ret;
3939
3940 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_OIS, (uint8_t *)®, 1);
3941
3942 switch (reg.filter_xl_conf_ois)
3943 {
3944 case LSM6DSO_289Hz:
3945 *val = LSM6DSO_289Hz;
3946 break;
3947
3948 case LSM6DSO_258Hz:
3949 *val = LSM6DSO_258Hz;
3950 break;
3951
3952 case LSM6DSO_120Hz:
3953 *val = LSM6DSO_120Hz;
3954 break;
3955
3956 case LSM6DSO_65Hz2:
3957 *val = LSM6DSO_65Hz2;
3958 break;
3959
3960 case LSM6DSO_33Hz2:
3961 *val = LSM6DSO_33Hz2;
3962 break;
3963
3964 case LSM6DSO_16Hz6:
3965 *val = LSM6DSO_16Hz6;
3966 break;
3967
3968 case LSM6DSO_8Hz30:
3969 *val = LSM6DSO_8Hz30;
3970 break;
3971
3972 case LSM6DSO_4Hz15:
3973 *val = LSM6DSO_4Hz15;
3974 break;
3975
3976 default:
3977 *val = LSM6DSO_289Hz;
3978 break;
3979 }
3980
3981 return ret;
3982 }
3983
3984 /**
3985 * @brief Selects accelerometer OIS channel full-scale.[set]
3986 *
3987 * @param ctx read / write interface definitions
3988 * @param val change the values of fs_xl_ois in
3989 * reg CTRL3_OIS
3990 * @retval interface status (MANDATORY: return 0 -> no Error)
3991 *
3992 */
lsm6dso_aux_xl_full_scale_set(stmdev_ctx_t * ctx,lsm6dso_fs_xl_ois_t val)3993 int32_t lsm6dso_aux_xl_full_scale_set(stmdev_ctx_t *ctx,
3994 lsm6dso_fs_xl_ois_t val)
3995 {
3996 lsm6dso_ctrl3_ois_t reg;
3997 int32_t ret;
3998
3999 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_OIS, (uint8_t *)®, 1);
4000
4001 if (ret == 0)
4002 {
4003 reg.fs_xl_ois = (uint8_t)val;
4004 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_OIS, (uint8_t *)®, 1);
4005 }
4006
4007 return ret;
4008 }
4009
4010 /**
4011 * @brief Selects accelerometer OIS channel full-scale.[get]
4012 *
4013 * @param ctx read / write interface definitions
4014 * @param val Get the values of fs_xl_ois in reg CTRL3_OIS
4015 * @retval interface status (MANDATORY: return 0 -> no Error)
4016 *
4017 */
lsm6dso_aux_xl_full_scale_get(stmdev_ctx_t * ctx,lsm6dso_fs_xl_ois_t * val)4018 int32_t lsm6dso_aux_xl_full_scale_get(stmdev_ctx_t *ctx,
4019 lsm6dso_fs_xl_ois_t *val)
4020 {
4021 lsm6dso_ctrl3_ois_t reg;
4022 int32_t ret;
4023
4024 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_OIS, (uint8_t *)®, 1);
4025
4026 switch (reg.fs_xl_ois)
4027 {
4028 case LSM6DSO_AUX_2g:
4029 *val = LSM6DSO_AUX_2g;
4030 break;
4031
4032 case LSM6DSO_AUX_16g:
4033 *val = LSM6DSO_AUX_16g;
4034 break;
4035
4036 case LSM6DSO_AUX_4g:
4037 *val = LSM6DSO_AUX_4g;
4038 break;
4039
4040 case LSM6DSO_AUX_8g:
4041 *val = LSM6DSO_AUX_8g;
4042 break;
4043
4044 default:
4045 *val = LSM6DSO_AUX_2g;
4046 break;
4047 }
4048
4049 return ret;
4050 }
4051
4052 /**
4053 * @}
4054 *
4055 */
4056
4057 /**
4058 * @defgroup LSM6DSO_ main_serial_interface
4059 * @brief This section groups all the functions concerning main
4060 * serial interface management (not auxiliary)
4061 * @{
4062 *
4063 */
4064
4065 /**
4066 * @brief Connect/Disconnect SDO/SA0 internal pull-up.[set]
4067 *
4068 * @param ctx read / write interface definitions
4069 * @param val change the values of sdo_pu_en in
4070 * reg PIN_CTRL
4071 * @retval interface status (MANDATORY: return 0 -> no Error)
4072 *
4073 */
lsm6dso_sdo_sa0_mode_set(stmdev_ctx_t * ctx,lsm6dso_sdo_pu_en_t val)4074 int32_t lsm6dso_sdo_sa0_mode_set(stmdev_ctx_t *ctx,
4075 lsm6dso_sdo_pu_en_t val)
4076 {
4077 lsm6dso_pin_ctrl_t reg;
4078 int32_t ret;
4079
4080 ret = lsm6dso_read_reg(ctx, LSM6DSO_PIN_CTRL, (uint8_t *)®, 1);
4081
4082 if (ret == 0)
4083 {
4084 reg.sdo_pu_en = (uint8_t)val;
4085 ret = lsm6dso_write_reg(ctx, LSM6DSO_PIN_CTRL, (uint8_t *)®, 1);
4086 }
4087
4088 return ret;
4089 }
4090
4091 /**
4092 * @brief Connect/Disconnect SDO/SA0 internal pull-up.[get]
4093 *
4094 * @param ctx read / write interface definitions
4095 * @param val Get the values of sdo_pu_en in reg PIN_CTRL
4096 * @retval interface status (MANDATORY: return 0 -> no Error)
4097 *
4098 */
lsm6dso_sdo_sa0_mode_get(stmdev_ctx_t * ctx,lsm6dso_sdo_pu_en_t * val)4099 int32_t lsm6dso_sdo_sa0_mode_get(stmdev_ctx_t *ctx,
4100 lsm6dso_sdo_pu_en_t *val)
4101 {
4102 lsm6dso_pin_ctrl_t reg;
4103 int32_t ret;
4104
4105 ret = lsm6dso_read_reg(ctx, LSM6DSO_PIN_CTRL, (uint8_t *)®, 1);
4106
4107 switch (reg.sdo_pu_en)
4108 {
4109 case LSM6DSO_PULL_UP_DISC:
4110 *val = LSM6DSO_PULL_UP_DISC;
4111 break;
4112
4113 case LSM6DSO_PULL_UP_CONNECT:
4114 *val = LSM6DSO_PULL_UP_CONNECT;
4115 break;
4116
4117 default:
4118 *val = LSM6DSO_PULL_UP_DISC;
4119 break;
4120 }
4121
4122 return ret;
4123 }
4124
4125 /**
4126 * @brief SPI Serial Interface Mode selection.[set]
4127 *
4128 * @param ctx read / write interface definitions
4129 * @param val change the values of sim in reg CTRL3_C
4130 * @retval interface status (MANDATORY: return 0 -> no Error)
4131 *
4132 */
lsm6dso_spi_mode_set(stmdev_ctx_t * ctx,lsm6dso_sim_t val)4133 int32_t lsm6dso_spi_mode_set(stmdev_ctx_t *ctx, lsm6dso_sim_t val)
4134 {
4135 lsm6dso_ctrl3_c_t reg;
4136 int32_t ret;
4137
4138 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
4139
4140 if (ret == 0)
4141 {
4142 reg.sim = (uint8_t)val;
4143 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
4144 }
4145
4146 return ret;
4147 }
4148
4149 /**
4150 * @brief SPI Serial Interface Mode selection.[get]
4151 *
4152 * @param ctx read / write interface definitions
4153 * @param val Get the values of sim in reg CTRL3_C
4154 * @retval interface status (MANDATORY: return 0 -> no Error)
4155 *
4156 */
lsm6dso_spi_mode_get(stmdev_ctx_t * ctx,lsm6dso_sim_t * val)4157 int32_t lsm6dso_spi_mode_get(stmdev_ctx_t *ctx, lsm6dso_sim_t *val)
4158 {
4159 lsm6dso_ctrl3_c_t reg;
4160 int32_t ret;
4161
4162 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
4163
4164 switch (reg.sim)
4165 {
4166 case LSM6DSO_SPI_4_WIRE:
4167 *val = LSM6DSO_SPI_4_WIRE;
4168 break;
4169
4170 case LSM6DSO_SPI_3_WIRE:
4171 *val = LSM6DSO_SPI_3_WIRE;
4172 break;
4173
4174 default:
4175 *val = LSM6DSO_SPI_4_WIRE;
4176 break;
4177 }
4178
4179 return ret;
4180 }
4181
4182 /**
4183 * @brief Disable / Enable I2C interface.[set]
4184 *
4185 * @param ctx read / write interface definitions
4186 * @param val change the values of i2c_disable in
4187 * reg CTRL4_C
4188 * @retval interface status (MANDATORY: return 0 -> no Error)
4189 *
4190 */
lsm6dso_i2c_interface_set(stmdev_ctx_t * ctx,lsm6dso_i2c_disable_t val)4191 int32_t lsm6dso_i2c_interface_set(stmdev_ctx_t *ctx,
4192 lsm6dso_i2c_disable_t val)
4193 {
4194 lsm6dso_ctrl4_c_t reg;
4195 int32_t ret;
4196
4197 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
4198
4199 if (ret == 0)
4200 {
4201 reg.i2c_disable = (uint8_t)val;
4202 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
4203 }
4204
4205 return ret;
4206 }
4207
4208 /**
4209 * @brief Disable / Enable I2C interface.[get]
4210 *
4211 * @param ctx read / write interface definitions
4212 * @param val Get the values of i2c_disable in
4213 * reg CTRL4_C
4214 * @retval interface status (MANDATORY: return 0 -> no Error)
4215 *
4216 */
lsm6dso_i2c_interface_get(stmdev_ctx_t * ctx,lsm6dso_i2c_disable_t * val)4217 int32_t lsm6dso_i2c_interface_get(stmdev_ctx_t *ctx,
4218 lsm6dso_i2c_disable_t *val)
4219 {
4220 lsm6dso_ctrl4_c_t reg;
4221 int32_t ret;
4222
4223 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
4224
4225 switch (reg.i2c_disable)
4226 {
4227 case LSM6DSO_I2C_ENABLE:
4228 *val = LSM6DSO_I2C_ENABLE;
4229 break;
4230
4231 case LSM6DSO_I2C_DISABLE:
4232 *val = LSM6DSO_I2C_DISABLE;
4233 break;
4234
4235 default:
4236 *val = LSM6DSO_I2C_ENABLE;
4237 break;
4238 }
4239
4240 return ret;
4241 }
4242
4243 /**
4244 * @brief I3C Enable/Disable communication protocol[.set]
4245 *
4246 * @param ctx read / write interface definitions
4247 * @param val change the values of i3c_disable
4248 * in reg CTRL9_XL
4249 * @retval interface status (MANDATORY: return 0 -> no Error)
4250 *
4251 */
lsm6dso_i3c_disable_set(stmdev_ctx_t * ctx,lsm6dso_i3c_disable_t val)4252 int32_t lsm6dso_i3c_disable_set(stmdev_ctx_t *ctx,
4253 lsm6dso_i3c_disable_t val)
4254 {
4255 lsm6dso_i3c_bus_avb_t i3c_bus_avb;
4256 lsm6dso_ctrl9_xl_t ctrl9_xl;
4257 int32_t ret;
4258
4259 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)&ctrl9_xl, 1);
4260
4261 if (ret == 0)
4262 {
4263 ctrl9_xl.i3c_disable = ((uint8_t)val & 0x80U) >> 7;
4264 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)&ctrl9_xl, 1);
4265 }
4266
4267 if (ret == 0)
4268 {
4269 ret = lsm6dso_read_reg(ctx, LSM6DSO_I3C_BUS_AVB,
4270 (uint8_t *)&i3c_bus_avb, 1);
4271 }
4272
4273 if (ret == 0)
4274 {
4275 i3c_bus_avb.i3c_bus_avb_sel = (uint8_t)val & 0x03U;
4276 ret = lsm6dso_write_reg(ctx, LSM6DSO_I3C_BUS_AVB,
4277 (uint8_t *)&i3c_bus_avb, 1);
4278 }
4279
4280 return ret;
4281 }
4282
4283 /**
4284 * @brief I3C Enable/Disable communication protocol.[get]
4285 *
4286 * @param ctx read / write interface definitions
4287 * @param val Get the values of i3c_disable in
4288 * reg CTRL9_XL
4289 * @retval interface status (MANDATORY: return 0 -> no Error)
4290 *
4291 */
lsm6dso_i3c_disable_get(stmdev_ctx_t * ctx,lsm6dso_i3c_disable_t * val)4292 int32_t lsm6dso_i3c_disable_get(stmdev_ctx_t *ctx,
4293 lsm6dso_i3c_disable_t *val)
4294 {
4295 lsm6dso_ctrl9_xl_t ctrl9_xl;
4296 lsm6dso_i3c_bus_avb_t i3c_bus_avb;
4297 int32_t ret;
4298
4299 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)&ctrl9_xl, 1);
4300
4301 if (ret == 0)
4302 {
4303 ret = lsm6dso_read_reg(ctx, LSM6DSO_I3C_BUS_AVB,
4304 (uint8_t *)&i3c_bus_avb, 1);
4305
4306 switch ((ctrl9_xl.i3c_disable << 7) | i3c_bus_avb.i3c_bus_avb_sel)
4307 {
4308 case LSM6DSO_I3C_DISABLE:
4309 *val = LSM6DSO_I3C_DISABLE;
4310 break;
4311
4312 case LSM6DSO_I3C_ENABLE_T_50us:
4313 *val = LSM6DSO_I3C_ENABLE_T_50us;
4314 break;
4315
4316 case LSM6DSO_I3C_ENABLE_T_2us:
4317 *val = LSM6DSO_I3C_ENABLE_T_2us;
4318 break;
4319
4320 case LSM6DSO_I3C_ENABLE_T_1ms:
4321 *val = LSM6DSO_I3C_ENABLE_T_1ms;
4322 break;
4323
4324 case LSM6DSO_I3C_ENABLE_T_25ms:
4325 *val = LSM6DSO_I3C_ENABLE_T_25ms;
4326 break;
4327
4328 default:
4329 *val = LSM6DSO_I3C_DISABLE;
4330 break;
4331 }
4332 }
4333
4334 return ret;
4335 }
4336
4337 /**
4338 * @}
4339 *
4340 */
4341
4342 /**
4343 * @defgroup LSM6DSO_interrupt_pins
4344 * @brief This section groups all the functions that manage interrupt pins
4345 * @{
4346 *
4347 */
4348
4349 /**
4350 * @brief Connect/Disconnect INT1 internal pull-down.[set]
4351 *
4352 * @param ctx read / write interface definitions
4353 * @param val change the values of pd_dis_int1 in reg I3C_BUS_AVB
4354 * @retval interface status (MANDATORY: return 0 -> no Error)
4355 *
4356 */
lsm6dso_int1_mode_set(stmdev_ctx_t * ctx,lsm6dso_int1_pd_en_t val)4357 int32_t lsm6dso_int1_mode_set(stmdev_ctx_t *ctx,
4358 lsm6dso_int1_pd_en_t val)
4359 {
4360 lsm6dso_i3c_bus_avb_t reg;
4361 int32_t ret;
4362
4363 ret = lsm6dso_read_reg(ctx, LSM6DSO_I3C_BUS_AVB, (uint8_t *)®, 1);
4364
4365 if (ret == 0)
4366 {
4367 reg.pd_dis_int1 = (uint8_t)val;
4368 ret = lsm6dso_write_reg(ctx, LSM6DSO_I3C_BUS_AVB, (uint8_t *)®, 1);
4369 }
4370
4371 return ret;
4372 }
4373
4374 /**
4375 * @brief Connect/Disconnect INT1 internal pull-down.[get]
4376 *
4377 * @param ctx read / write interface definitions
4378 * @param val Get the values of pd_dis_int1 in reg I3C_BUS_AVB
4379 * @retval interface status (MANDATORY: return 0 -> no Error)
4380 *
4381 */
lsm6dso_int1_mode_get(stmdev_ctx_t * ctx,lsm6dso_int1_pd_en_t * val)4382 int32_t lsm6dso_int1_mode_get(stmdev_ctx_t *ctx,
4383 lsm6dso_int1_pd_en_t *val)
4384 {
4385 lsm6dso_i3c_bus_avb_t reg;
4386 int32_t ret;
4387
4388 ret = lsm6dso_read_reg(ctx, LSM6DSO_I3C_BUS_AVB, (uint8_t *)®, 1);
4389
4390 switch (reg.pd_dis_int1)
4391 {
4392 case LSM6DSO_PULL_DOWN_DISC:
4393 *val = LSM6DSO_PULL_DOWN_DISC;
4394 break;
4395
4396 case LSM6DSO_PULL_DOWN_CONNECT:
4397 *val = LSM6DSO_PULL_DOWN_CONNECT;
4398 break;
4399
4400 default:
4401 *val = LSM6DSO_PULL_DOWN_DISC;
4402 break;
4403 }
4404
4405 return ret;
4406 }
4407
4408 /**
4409 * @brief Push-pull/open drain selection on interrupt pads.[set]
4410 *
4411 * @param ctx read / write interface definitions
4412 * @param val change the values of pp_od in reg CTRL3_C
4413 * @retval interface status (MANDATORY: return 0 -> no Error)
4414 *
4415 */
lsm6dso_pin_mode_set(stmdev_ctx_t * ctx,lsm6dso_pp_od_t val)4416 int32_t lsm6dso_pin_mode_set(stmdev_ctx_t *ctx, lsm6dso_pp_od_t val)
4417 {
4418 lsm6dso_ctrl3_c_t reg;
4419 int32_t ret;
4420
4421 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
4422
4423 if (ret == 0)
4424 {
4425 reg.pp_od = (uint8_t)val;
4426 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
4427 }
4428
4429 return ret;
4430 }
4431
4432 /**
4433 * @brief Push-pull/open drain selection on interrupt pads.[get]
4434 *
4435 * @param ctx read / write interface definitions
4436 * @param val Get the values of pp_od in reg CTRL3_C
4437 * @retval interface status (MANDATORY: return 0 -> no Error)
4438 *
4439 */
lsm6dso_pin_mode_get(stmdev_ctx_t * ctx,lsm6dso_pp_od_t * val)4440 int32_t lsm6dso_pin_mode_get(stmdev_ctx_t *ctx, lsm6dso_pp_od_t *val)
4441 {
4442 lsm6dso_ctrl3_c_t reg;
4443 int32_t ret;
4444
4445 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
4446
4447 switch (reg.pp_od)
4448 {
4449 case LSM6DSO_PUSH_PULL:
4450 *val = LSM6DSO_PUSH_PULL;
4451 break;
4452
4453 case LSM6DSO_OPEN_DRAIN:
4454 *val = LSM6DSO_OPEN_DRAIN;
4455 break;
4456
4457 default:
4458 *val = LSM6DSO_PUSH_PULL;
4459 break;
4460 }
4461
4462 return ret;
4463 }
4464
4465 /**
4466 * @brief Interrupt active-high/low.[set]
4467 *
4468 * @param ctx read / write interface definitions
4469 * @param val change the values of h_lactive in reg CTRL3_C
4470 * @retval interface status (MANDATORY: return 0 -> no Error)
4471 *
4472 */
lsm6dso_pin_polarity_set(stmdev_ctx_t * ctx,lsm6dso_h_lactive_t val)4473 int32_t lsm6dso_pin_polarity_set(stmdev_ctx_t *ctx,
4474 lsm6dso_h_lactive_t val)
4475 {
4476 lsm6dso_ctrl3_c_t reg;
4477 int32_t ret;
4478
4479 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
4480
4481 if (ret == 0)
4482 {
4483 reg.h_lactive = (uint8_t)val;
4484 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
4485 }
4486
4487 return ret;
4488 }
4489
4490 /**
4491 * @brief Interrupt active-high/low.[get]
4492 *
4493 * @param ctx read / write interface definitions
4494 * @param val Get the values of h_lactive in reg CTRL3_C
4495 * @retval interface status (MANDATORY: return 0 -> no Error)
4496 *
4497 */
lsm6dso_pin_polarity_get(stmdev_ctx_t * ctx,lsm6dso_h_lactive_t * val)4498 int32_t lsm6dso_pin_polarity_get(stmdev_ctx_t *ctx,
4499 lsm6dso_h_lactive_t *val)
4500 {
4501 lsm6dso_ctrl3_c_t reg;
4502 int32_t ret;
4503
4504 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)®, 1);
4505
4506 switch (reg.h_lactive)
4507 {
4508 case LSM6DSO_ACTIVE_HIGH:
4509 *val = LSM6DSO_ACTIVE_HIGH;
4510 break;
4511
4512 case LSM6DSO_ACTIVE_LOW:
4513 *val = LSM6DSO_ACTIVE_LOW;
4514 break;
4515
4516 default:
4517 *val = LSM6DSO_ACTIVE_HIGH;
4518 break;
4519 }
4520
4521 return ret;
4522 }
4523
4524 /**
4525 * @brief All interrupt signals become available on INT1 pin.[set]
4526 *
4527 * @param ctx read / write interface definitions
4528 * @param val change the values of int2_on_int1 in reg CTRL4_C
4529 * @retval interface status (MANDATORY: return 0 -> no Error)
4530 *
4531 */
lsm6dso_all_on_int1_set(stmdev_ctx_t * ctx,uint8_t val)4532 int32_t lsm6dso_all_on_int1_set(stmdev_ctx_t *ctx, uint8_t val)
4533 {
4534 lsm6dso_ctrl4_c_t reg;
4535 int32_t ret;
4536
4537 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
4538
4539 if (ret == 0)
4540 {
4541 reg.int2_on_int1 = val;
4542 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
4543 }
4544
4545 return ret;
4546 }
4547
4548 /**
4549 * @brief All interrupt signals become available on INT1 pin.[get]
4550 *
4551 * @param ctx read / write interface definitions
4552 * @param val Get the values of int2_on_int1 in reg CTRL4_C
4553 * @retval interface status (MANDATORY: return 0 -> no Error)
4554 *
4555 */
lsm6dso_all_on_int1_get(stmdev_ctx_t * ctx,uint8_t * val)4556 int32_t lsm6dso_all_on_int1_get(stmdev_ctx_t *ctx, uint8_t *val)
4557 {
4558 lsm6dso_ctrl4_c_t reg;
4559 int32_t ret;
4560
4561 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
4562 *val = reg.int2_on_int1;
4563
4564 return ret;
4565 }
4566
4567 /**
4568 * @brief Interrupt notification mode.[set]
4569 *
4570 * @param ctx read / write interface definitions
4571 * @param val change the values of lir in reg TAP_CFG0
4572 * @retval interface status (MANDATORY: return 0 -> no Error)
4573 *
4574 */
lsm6dso_int_notification_set(stmdev_ctx_t * ctx,lsm6dso_lir_t val)4575 int32_t lsm6dso_int_notification_set(stmdev_ctx_t *ctx,
4576 lsm6dso_lir_t val)
4577 {
4578 lsm6dso_tap_cfg0_t tap_cfg0;
4579 lsm6dso_page_rw_t page_rw;
4580 int32_t ret;
4581
4582 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *) &tap_cfg0, 1);
4583
4584 if (ret == 0)
4585 {
4586 tap_cfg0.lir = (uint8_t)val & 0x01U;
4587 tap_cfg0.int_clr_on_read = (uint8_t)val & 0x01U;
4588 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *) &tap_cfg0, 1);
4589 }
4590
4591 if (ret == 0)
4592 {
4593 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
4594 }
4595
4596 if (ret == 0)
4597 {
4598 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
4599 }
4600
4601 if (ret == 0)
4602 {
4603 page_rw.emb_func_lir = ((uint8_t)val & 0x02U) >> 1;
4604 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
4605 }
4606
4607 if (ret == 0)
4608 {
4609 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
4610 }
4611
4612 return ret;
4613 }
4614
4615 /**
4616 * @brief Interrupt notification mode.[get]
4617 *
4618 * @param ctx read / write interface definitions
4619 * @param val Get the values of lir in reg TAP_CFG0
4620 * @retval interface status (MANDATORY: return 0 -> no Error)
4621 *
4622 */
lsm6dso_int_notification_get(stmdev_ctx_t * ctx,lsm6dso_lir_t * val)4623 int32_t lsm6dso_int_notification_get(stmdev_ctx_t *ctx,
4624 lsm6dso_lir_t *val)
4625 {
4626 lsm6dso_tap_cfg0_t tap_cfg0;
4627 lsm6dso_page_rw_t page_rw;
4628 int32_t ret;
4629
4630 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *) &tap_cfg0, 1);
4631
4632 if (ret == 0)
4633 {
4634 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
4635 }
4636
4637 if (ret == 0)
4638 {
4639 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
4640 }
4641
4642 if (ret == 0)
4643 {
4644 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
4645 }
4646
4647 if (ret == 0)
4648 {
4649 switch ((page_rw.emb_func_lir << 1) | tap_cfg0.lir)
4650 {
4651 case LSM6DSO_ALL_INT_PULSED:
4652 *val = LSM6DSO_ALL_INT_PULSED;
4653 break;
4654
4655 case LSM6DSO_BASE_LATCHED_EMB_PULSED:
4656 *val = LSM6DSO_BASE_LATCHED_EMB_PULSED;
4657 break;
4658
4659 case LSM6DSO_BASE_PULSED_EMB_LATCHED:
4660 *val = LSM6DSO_BASE_PULSED_EMB_LATCHED;
4661 break;
4662
4663 case LSM6DSO_ALL_INT_LATCHED:
4664 *val = LSM6DSO_ALL_INT_LATCHED;
4665 break;
4666
4667 default:
4668 *val = LSM6DSO_ALL_INT_PULSED;
4669 break;
4670 }
4671
4672 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
4673 }
4674
4675 if (ret == 0)
4676 {
4677 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
4678 }
4679
4680 if (ret == 0)
4681 {
4682 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
4683 }
4684
4685 return ret;
4686 }
4687
4688 /**
4689 * @}
4690 *
4691 */
4692
4693 /**
4694 * @defgroup LSM6DSO_Wake_Up_event
4695 * @brief This section groups all the functions that manage the Wake Up
4696 * event generation.
4697 * @{
4698 *
4699 */
4700
4701 /**
4702 * @brief Weight of 1 LSB of wakeup threshold.[set]
4703 * 0: 1 LSB =FS_XL / 64
4704 * 1: 1 LSB = FS_XL / 256
4705 *
4706 * @param ctx read / write interface definitions
4707 * @param val change the values of wake_ths_w in
4708 * reg WAKE_UP_DUR
4709 * @retval interface status (MANDATORY: return 0 -> no Error)
4710 *
4711 */
lsm6dso_wkup_ths_weight_set(stmdev_ctx_t * ctx,lsm6dso_wake_ths_w_t val)4712 int32_t lsm6dso_wkup_ths_weight_set(stmdev_ctx_t *ctx,
4713 lsm6dso_wake_ths_w_t val)
4714 {
4715 lsm6dso_wake_up_dur_t reg;
4716 int32_t ret;
4717
4718 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_DUR, (uint8_t *)®, 1);
4719
4720 if (ret == 0)
4721 {
4722 reg.wake_ths_w = (uint8_t)val;
4723 ret = lsm6dso_write_reg(ctx, LSM6DSO_WAKE_UP_DUR, (uint8_t *)®, 1);
4724 }
4725
4726 return ret;
4727 }
4728
4729 /**
4730 * @brief Weight of 1 LSB of wakeup threshold.[get]
4731 * 0: 1 LSB =FS_XL / 64
4732 * 1: 1 LSB = FS_XL / 256
4733 *
4734 * @param ctx read / write interface definitions
4735 * @param val Get the values of wake_ths_w in
4736 * reg WAKE_UP_DUR
4737 * @retval interface status (MANDATORY: return 0 -> no Error)
4738 *
4739 */
lsm6dso_wkup_ths_weight_get(stmdev_ctx_t * ctx,lsm6dso_wake_ths_w_t * val)4740 int32_t lsm6dso_wkup_ths_weight_get(stmdev_ctx_t *ctx,
4741 lsm6dso_wake_ths_w_t *val)
4742 {
4743 lsm6dso_wake_up_dur_t reg;
4744 int32_t ret;
4745
4746 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_DUR, (uint8_t *)®, 1);
4747
4748 switch (reg.wake_ths_w)
4749 {
4750 case LSM6DSO_LSb_FS_DIV_64:
4751 *val = LSM6DSO_LSb_FS_DIV_64;
4752 break;
4753
4754 case LSM6DSO_LSb_FS_DIV_256:
4755 *val = LSM6DSO_LSb_FS_DIV_256;
4756 break;
4757
4758 default:
4759 *val = LSM6DSO_LSb_FS_DIV_64;
4760 break;
4761 }
4762
4763 return ret;
4764 }
4765
4766 /**
4767 * @brief Threshold for wakeup: 1 LSB weight depends on WAKE_THS_W in
4768 * WAKE_UP_DUR.[set]
4769 *
4770 * @param ctx read / write interface definitions
4771 * @param val change the values of wk_ths in reg WAKE_UP_THS
4772 * @retval interface status (MANDATORY: return 0 -> no Error)
4773 *
4774 */
lsm6dso_wkup_threshold_set(stmdev_ctx_t * ctx,uint8_t val)4775 int32_t lsm6dso_wkup_threshold_set(stmdev_ctx_t *ctx, uint8_t val)
4776 {
4777 lsm6dso_wake_up_ths_t reg;
4778 int32_t ret;
4779
4780 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_THS, (uint8_t *)®, 1);
4781
4782 if (ret == 0)
4783 {
4784 reg.wk_ths = val;
4785 ret = lsm6dso_write_reg(ctx, LSM6DSO_WAKE_UP_THS, (uint8_t *)®, 1);
4786 }
4787
4788 return ret;
4789 }
4790
4791 /**
4792 * @brief Threshold for wakeup: 1 LSB weight depends on WAKE_THS_W in
4793 * WAKE_UP_DUR.[get]
4794 *
4795 * @param ctx read / write interface definitions
4796 * @param val Get the values of wk_ths in reg WAKE_UP_THS
4797 * @retval interface status (MANDATORY: return 0 -> no Error)
4798 *
4799 */
lsm6dso_wkup_threshold_get(stmdev_ctx_t * ctx,uint8_t * val)4800 int32_t lsm6dso_wkup_threshold_get(stmdev_ctx_t *ctx, uint8_t *val)
4801 {
4802 lsm6dso_wake_up_ths_t reg;
4803 int32_t ret;
4804
4805 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_THS, (uint8_t *)®, 1);
4806 *val = reg.wk_ths;
4807
4808 return ret;
4809 }
4810
4811 /**
4812 * @brief Wake up duration event.[set]
4813 * 1LSb = 1 / ODR
4814 *
4815 * @param ctx read / write interface definitions
4816 * @param val change the values of usr_off_on_wu in reg WAKE_UP_THS
4817 * @retval interface status (MANDATORY: return 0 -> no Error)
4818 *
4819 */
lsm6dso_xl_usr_offset_on_wkup_set(stmdev_ctx_t * ctx,uint8_t val)4820 int32_t lsm6dso_xl_usr_offset_on_wkup_set(stmdev_ctx_t *ctx,
4821 uint8_t val)
4822 {
4823 lsm6dso_wake_up_ths_t reg;
4824 int32_t ret;
4825
4826 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_THS, (uint8_t *)®, 1);
4827
4828 if (ret == 0)
4829 {
4830 reg.usr_off_on_wu = val;
4831 ret = lsm6dso_write_reg(ctx, LSM6DSO_WAKE_UP_THS, (uint8_t *)®, 1);
4832 }
4833
4834 return ret;
4835 }
4836
4837 /**
4838 * @brief Wake up duration event.[get]
4839 * 1LSb = 1 / ODR
4840 *
4841 * @param ctx read / write interface definitions
4842 * @param val Get the values of usr_off_on_wu in reg WAKE_UP_THS
4843 * @retval interface status (MANDATORY: return 0 -> no Error)
4844 *
4845 */
lsm6dso_xl_usr_offset_on_wkup_get(stmdev_ctx_t * ctx,uint8_t * val)4846 int32_t lsm6dso_xl_usr_offset_on_wkup_get(stmdev_ctx_t *ctx,
4847 uint8_t *val)
4848 {
4849 lsm6dso_wake_up_ths_t reg;
4850 int32_t ret;
4851
4852 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_THS, (uint8_t *)®, 1);
4853 *val = reg.usr_off_on_wu;
4854
4855 return ret;
4856 }
4857
4858 /**
4859 * @brief Wake up duration event.[set]
4860 * 1LSb = 1 / ODR
4861 *
4862 * @param ctx read / write interface definitions
4863 * @param val change the values of wake_dur in reg WAKE_UP_DUR
4864 * @retval interface status (MANDATORY: return 0 -> no Error)
4865 *
4866 */
lsm6dso_wkup_dur_set(stmdev_ctx_t * ctx,uint8_t val)4867 int32_t lsm6dso_wkup_dur_set(stmdev_ctx_t *ctx, uint8_t val)
4868 {
4869 lsm6dso_wake_up_dur_t reg;
4870 int32_t ret;
4871
4872 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_DUR, (uint8_t *)®, 1);
4873
4874 if (ret == 0)
4875 {
4876 reg.wake_dur = val;
4877 ret = lsm6dso_write_reg(ctx, LSM6DSO_WAKE_UP_DUR, (uint8_t *)®, 1);
4878 }
4879
4880 return ret;
4881 }
4882
4883 /**
4884 * @brief Wake up duration event.[get]
4885 * 1LSb = 1 / ODR
4886 *
4887 * @param ctx read / write interface definitions
4888 * @param val Get the values of wake_dur in reg WAKE_UP_DUR
4889 * @retval interface status (MANDATORY: return 0 -> no Error)
4890 *
4891 */
lsm6dso_wkup_dur_get(stmdev_ctx_t * ctx,uint8_t * val)4892 int32_t lsm6dso_wkup_dur_get(stmdev_ctx_t *ctx, uint8_t *val)
4893 {
4894 lsm6dso_wake_up_dur_t reg;
4895 int32_t ret;
4896
4897 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_DUR, (uint8_t *)®, 1);
4898 *val = reg.wake_dur;
4899
4900 return ret;
4901 }
4902
4903 /**
4904 * @}
4905 *
4906 */
4907
4908 /**
4909 * @defgroup LSM6DSO_ Activity/Inactivity_detection
4910 * @brief This section groups all the functions concerning
4911 * activity/inactivity detection.
4912 * @{
4913 *
4914 */
4915
4916 /**
4917 * @brief Enables gyroscope Sleep mode.[set]
4918 *
4919 * @param ctx read / write interface definitions
4920 * @param val change the values of sleep_g in reg CTRL4_C
4921 * @retval interface status (MANDATORY: return 0 -> no Error)
4922 *
4923 */
lsm6dso_gy_sleep_mode_set(stmdev_ctx_t * ctx,uint8_t val)4924 int32_t lsm6dso_gy_sleep_mode_set(stmdev_ctx_t *ctx, uint8_t val)
4925 {
4926 lsm6dso_ctrl4_c_t reg;
4927 int32_t ret;
4928
4929 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
4930
4931 if (ret == 0)
4932 {
4933 reg.sleep_g = val;
4934 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
4935 }
4936
4937 return ret;
4938 }
4939
4940 /**
4941 * @brief Enables gyroscope Sleep mode.[get]
4942 *
4943 * @param ctx read / write interface definitions
4944 * @param val Get the values of sleep_g in reg CTRL4_C
4945 * @retval interface status (MANDATORY: return 0 -> no Error)
4946 *
4947 */
lsm6dso_gy_sleep_mode_get(stmdev_ctx_t * ctx,uint8_t * val)4948 int32_t lsm6dso_gy_sleep_mode_get(stmdev_ctx_t *ctx, uint8_t *val)
4949 {
4950 lsm6dso_ctrl4_c_t reg;
4951 int32_t ret;
4952
4953 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)®, 1);
4954 *val = reg.sleep_g;
4955
4956 return ret;
4957 }
4958
4959 /**
4960 * @brief Drives the sleep status instead of
4961 * sleep change on INT pins
4962 * (only if INT1_SLEEP_CHANGE or
4963 * INT2_SLEEP_CHANGE bits are enabled).[set]
4964 *
4965 * @param ctx read / write interface definitions
4966 * @param val change the values of sleep_status_on_int in reg TAP_CFG0
4967 * @retval interface status (MANDATORY: return 0 -> no Error)
4968 *
4969 */
lsm6dso_act_pin_notification_set(stmdev_ctx_t * ctx,lsm6dso_sleep_status_on_int_t val)4970 int32_t lsm6dso_act_pin_notification_set(stmdev_ctx_t *ctx,
4971 lsm6dso_sleep_status_on_int_t val)
4972 {
4973 lsm6dso_tap_cfg0_t reg;
4974 int32_t ret;
4975
4976 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
4977
4978 if (ret == 0)
4979 {
4980 reg.sleep_status_on_int = (uint8_t)val;
4981 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
4982 }
4983
4984 return ret;
4985 }
4986
4987 /**
4988 * @brief Drives the sleep status instead of
4989 * sleep change on INT pins (only if
4990 * INT1_SLEEP_CHANGE or
4991 * INT2_SLEEP_CHANGE bits are enabled).[get]
4992 *
4993 * @param ctx read / write interface definitions
4994 * @param val Get the values of sleep_status_on_int in reg TAP_CFG0
4995 * @retval interface status (MANDATORY: return 0 -> no Error)
4996 *
4997 */
lsm6dso_act_pin_notification_get(stmdev_ctx_t * ctx,lsm6dso_sleep_status_on_int_t * val)4998 int32_t lsm6dso_act_pin_notification_get(stmdev_ctx_t *ctx,
4999 lsm6dso_sleep_status_on_int_t *val)
5000 {
5001 lsm6dso_tap_cfg0_t reg;
5002 int32_t ret;
5003
5004 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
5005
5006 switch (reg.sleep_status_on_int)
5007 {
5008 case LSM6DSO_DRIVE_SLEEP_CHG_EVENT:
5009 *val = LSM6DSO_DRIVE_SLEEP_CHG_EVENT;
5010 break;
5011
5012 case LSM6DSO_DRIVE_SLEEP_STATUS:
5013 *val = LSM6DSO_DRIVE_SLEEP_STATUS;
5014 break;
5015
5016 default:
5017 *val = LSM6DSO_DRIVE_SLEEP_CHG_EVENT;
5018 break;
5019 }
5020
5021 return ret;
5022 }
5023
5024 /**
5025 * @brief Enable inactivity function.[set]
5026 *
5027 * @param ctx read / write interface definitions
5028 * @param val change the values of inact_en in reg TAP_CFG2
5029 * @retval interface status (MANDATORY: return 0 -> no Error)
5030 *
5031 */
lsm6dso_act_mode_set(stmdev_ctx_t * ctx,lsm6dso_inact_en_t val)5032 int32_t lsm6dso_act_mode_set(stmdev_ctx_t *ctx,
5033 lsm6dso_inact_en_t val)
5034 {
5035 lsm6dso_tap_cfg2_t reg;
5036 int32_t ret;
5037
5038 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG2, (uint8_t *)®, 1);
5039
5040 if (ret == 0)
5041 {
5042 reg.inact_en = (uint8_t)val;
5043 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_CFG2, (uint8_t *)®, 1);
5044 }
5045
5046 return ret;
5047 }
5048
5049 /**
5050 * @brief Enable inactivity function.[get]
5051 *
5052 * @param ctx read / write interface definitions
5053 * @param val Get the values of inact_en in reg TAP_CFG2
5054 * @retval interface status (MANDATORY: return 0 -> no Error)
5055 *
5056 */
lsm6dso_act_mode_get(stmdev_ctx_t * ctx,lsm6dso_inact_en_t * val)5057 int32_t lsm6dso_act_mode_get(stmdev_ctx_t *ctx,
5058 lsm6dso_inact_en_t *val)
5059 {
5060 lsm6dso_tap_cfg2_t reg;
5061 int32_t ret;
5062
5063 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG2, (uint8_t *)®, 1);
5064
5065 switch (reg.inact_en)
5066 {
5067 case LSM6DSO_XL_AND_GY_NOT_AFFECTED:
5068 *val = LSM6DSO_XL_AND_GY_NOT_AFFECTED;
5069 break;
5070
5071 case LSM6DSO_XL_12Hz5_GY_NOT_AFFECTED:
5072 *val = LSM6DSO_XL_12Hz5_GY_NOT_AFFECTED;
5073 break;
5074
5075 case LSM6DSO_XL_12Hz5_GY_SLEEP:
5076 *val = LSM6DSO_XL_12Hz5_GY_SLEEP;
5077 break;
5078
5079 case LSM6DSO_XL_12Hz5_GY_PD:
5080 *val = LSM6DSO_XL_12Hz5_GY_PD;
5081 break;
5082
5083 default:
5084 *val = LSM6DSO_XL_AND_GY_NOT_AFFECTED;
5085 break;
5086 }
5087
5088 return ret;
5089 }
5090
5091 /**
5092 * @brief Duration to go in sleep mode.[set]
5093 * 1 LSb = 512 / ODR
5094 *
5095 * @param ctx read / write interface definitions
5096 * @param val change the values of sleep_dur in reg WAKE_UP_DUR
5097 * @retval interface status (MANDATORY: return 0 -> no Error)
5098 *
5099 */
lsm6dso_act_sleep_dur_set(stmdev_ctx_t * ctx,uint8_t val)5100 int32_t lsm6dso_act_sleep_dur_set(stmdev_ctx_t *ctx, uint8_t val)
5101 {
5102 lsm6dso_wake_up_dur_t reg;
5103 int32_t ret;
5104
5105 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_DUR, (uint8_t *)®, 1);
5106
5107 if (ret == 0)
5108 {
5109 reg.sleep_dur = val;
5110 ret = lsm6dso_write_reg(ctx, LSM6DSO_WAKE_UP_DUR, (uint8_t *)®, 1);
5111 }
5112
5113 return ret;
5114 }
5115
5116 /**
5117 * @brief Duration to go in sleep mode.[get]
5118 * 1 LSb = 512 / ODR
5119 *
5120 * @param ctx read / write interface definitions
5121 * @param val Get the values of sleep_dur in reg WAKE_UP_DUR
5122 * @retval interface status (MANDATORY: return 0 -> no Error)
5123 *
5124 */
lsm6dso_act_sleep_dur_get(stmdev_ctx_t * ctx,uint8_t * val)5125 int32_t lsm6dso_act_sleep_dur_get(stmdev_ctx_t *ctx, uint8_t *val)
5126 {
5127 lsm6dso_wake_up_dur_t reg;
5128 int32_t ret;
5129
5130 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_DUR, (uint8_t *)®, 1);
5131 *val = reg.sleep_dur;
5132
5133 return ret;
5134 }
5135
5136 /**
5137 * @}
5138 *
5139 */
5140
5141 /**
5142 * @defgroup LSM6DSO_tap_generator
5143 * @brief This section groups all the functions that manage the
5144 * tap and double tap event generation.
5145 * @{
5146 *
5147 */
5148
5149 /**
5150 * @brief Enable Z direction in tap recognition.[set]
5151 *
5152 * @param ctx read / write interface definitions
5153 * @param val change the values of tap_z_en in reg TAP_CFG0
5154 * @retval interface status (MANDATORY: return 0 -> no Error)
5155 *
5156 */
lsm6dso_tap_detection_on_z_set(stmdev_ctx_t * ctx,uint8_t val)5157 int32_t lsm6dso_tap_detection_on_z_set(stmdev_ctx_t *ctx, uint8_t val)
5158 {
5159 lsm6dso_tap_cfg0_t reg;
5160 int32_t ret;
5161
5162 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
5163
5164 if (ret == 0)
5165 {
5166 reg.tap_z_en = val;
5167 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
5168 }
5169
5170 return ret;
5171 }
5172
5173 /**
5174 * @brief Enable Z direction in tap recognition.[get]
5175 *
5176 * @param ctx read / write interface definitions
5177 * @param val Get the values of tap_z_en in reg TAP_CFG0
5178 * @retval interface status (MANDATORY: return 0 -> no Error)
5179 *
5180 */
lsm6dso_tap_detection_on_z_get(stmdev_ctx_t * ctx,uint8_t * val)5181 int32_t lsm6dso_tap_detection_on_z_get(stmdev_ctx_t *ctx,
5182 uint8_t *val)
5183 {
5184 lsm6dso_tap_cfg0_t reg;
5185 int32_t ret;
5186
5187 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
5188 *val = reg.tap_z_en;
5189
5190 return ret;
5191 }
5192
5193 /**
5194 * @brief Enable Y direction in tap recognition.[set]
5195 *
5196 * @param ctx read / write interface definitions
5197 * @param val change the values of tap_y_en in reg TAP_CFG0
5198 * @retval interface status (MANDATORY: return 0 -> no Error)
5199 *
5200 */
lsm6dso_tap_detection_on_y_set(stmdev_ctx_t * ctx,uint8_t val)5201 int32_t lsm6dso_tap_detection_on_y_set(stmdev_ctx_t *ctx, uint8_t val)
5202 {
5203 lsm6dso_tap_cfg0_t reg;
5204 int32_t ret;
5205
5206 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
5207
5208 if (ret == 0)
5209 {
5210 reg.tap_y_en = val;
5211 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
5212 }
5213
5214 return ret;
5215 }
5216
5217 /**
5218 * @brief Enable Y direction in tap recognition.[get]
5219 *
5220 * @param ctx read / write interface definitions
5221 * @param val Get the values of tap_y_en in reg TAP_CFG0
5222 * @retval interface status (MANDATORY: return 0 -> no Error)
5223 *
5224 */
lsm6dso_tap_detection_on_y_get(stmdev_ctx_t * ctx,uint8_t * val)5225 int32_t lsm6dso_tap_detection_on_y_get(stmdev_ctx_t *ctx,
5226 uint8_t *val)
5227 {
5228 lsm6dso_tap_cfg0_t reg;
5229 int32_t ret;
5230
5231 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
5232 *val = reg.tap_y_en;
5233
5234 return ret;
5235 }
5236
5237 /**
5238 * @brief Enable X direction in tap recognition.[set]
5239 *
5240 * @param ctx read / write interface definitions
5241 * @param val change the values of tap_x_en in reg TAP_CFG0
5242 * @retval interface status (MANDATORY: return 0 -> no Error)
5243 *
5244 */
lsm6dso_tap_detection_on_x_set(stmdev_ctx_t * ctx,uint8_t val)5245 int32_t lsm6dso_tap_detection_on_x_set(stmdev_ctx_t *ctx, uint8_t val)
5246 {
5247 lsm6dso_tap_cfg0_t reg;
5248 int32_t ret;
5249
5250 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
5251
5252 if (ret == 0)
5253 {
5254 reg.tap_x_en = val;
5255 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
5256 }
5257
5258 return ret;
5259 }
5260
5261 /**
5262 * @brief Enable X direction in tap recognition.[get]
5263 *
5264 * @param ctx read / write interface definitions
5265 * @param val Get the values of tap_x_en in reg TAP_CFG0
5266 * @retval interface status (MANDATORY: return 0 -> no Error)
5267 *
5268 */
lsm6dso_tap_detection_on_x_get(stmdev_ctx_t * ctx,uint8_t * val)5269 int32_t lsm6dso_tap_detection_on_x_get(stmdev_ctx_t *ctx,
5270 uint8_t *val)
5271 {
5272 lsm6dso_tap_cfg0_t reg;
5273 int32_t ret;
5274
5275 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *)®, 1);
5276 *val = reg.tap_x_en;
5277
5278 return ret;
5279 }
5280
5281 /**
5282 * @brief X-axis tap recognition threshold.[set]
5283 *
5284 * @param ctx read / write interface definitions
5285 * @param val change the values of tap_ths_x in reg TAP_CFG1
5286 * @retval interface status (MANDATORY: return 0 -> no Error)
5287 *
5288 */
lsm6dso_tap_threshold_x_set(stmdev_ctx_t * ctx,uint8_t val)5289 int32_t lsm6dso_tap_threshold_x_set(stmdev_ctx_t *ctx, uint8_t val)
5290 {
5291 lsm6dso_tap_cfg1_t reg;
5292 int32_t ret;
5293
5294 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG1, (uint8_t *)®, 1);
5295
5296 if (ret == 0)
5297 {
5298 reg.tap_ths_x = val;
5299 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_CFG1, (uint8_t *)®, 1);
5300 }
5301
5302 return ret;
5303 }
5304
5305 /**
5306 * @brief X-axis tap recognition threshold.[get]
5307 *
5308 * @param ctx read / write interface definitions
5309 * @param val Get the values of tap_ths_x in reg TAP_CFG1
5310 * @retval interface status (MANDATORY: return 0 -> no Error)
5311 *
5312 */
lsm6dso_tap_threshold_x_get(stmdev_ctx_t * ctx,uint8_t * val)5313 int32_t lsm6dso_tap_threshold_x_get(stmdev_ctx_t *ctx, uint8_t *val)
5314 {
5315 lsm6dso_tap_cfg1_t reg;
5316 int32_t ret;
5317
5318 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG1, (uint8_t *)®, 1);
5319 *val = reg.tap_ths_x;
5320
5321 return ret;
5322 }
5323
5324 /**
5325 * @brief Selection of axis priority for TAP detection.[set]
5326 *
5327 * @param ctx read / write interface definitions
5328 * @param val change the values of tap_priority in
5329 * reg TAP_CFG1
5330 * @retval interface status (MANDATORY: return 0 -> no Error)
5331 *
5332 */
lsm6dso_tap_axis_priority_set(stmdev_ctx_t * ctx,lsm6dso_tap_priority_t val)5333 int32_t lsm6dso_tap_axis_priority_set(stmdev_ctx_t *ctx,
5334 lsm6dso_tap_priority_t val)
5335 {
5336 lsm6dso_tap_cfg1_t reg;
5337 int32_t ret;
5338
5339 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG1, (uint8_t *)®, 1);
5340
5341 if (ret == 0)
5342 {
5343 reg.tap_priority = (uint8_t)val;
5344 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_CFG1, (uint8_t *)®, 1);
5345 }
5346
5347 return ret;
5348 }
5349
5350 /**
5351 * @brief Selection of axis priority for TAP detection.[get]
5352 *
5353 * @param ctx read / write interface definitions
5354 * @param val Get the values of tap_priority in
5355 * reg TAP_CFG1
5356 * @retval interface status (MANDATORY: return 0 -> no Error)
5357 *
5358 */
lsm6dso_tap_axis_priority_get(stmdev_ctx_t * ctx,lsm6dso_tap_priority_t * val)5359 int32_t lsm6dso_tap_axis_priority_get(stmdev_ctx_t *ctx,
5360 lsm6dso_tap_priority_t *val)
5361 {
5362 lsm6dso_tap_cfg1_t reg;
5363 int32_t ret;
5364
5365 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG1, (uint8_t *)®, 1);
5366
5367 switch (reg.tap_priority)
5368 {
5369 case LSM6DSO_XYZ:
5370 *val = LSM6DSO_XYZ;
5371 break;
5372
5373 case LSM6DSO_YXZ:
5374 *val = LSM6DSO_YXZ;
5375 break;
5376
5377 case LSM6DSO_XZY:
5378 *val = LSM6DSO_XZY;
5379 break;
5380
5381 case LSM6DSO_ZYX:
5382 *val = LSM6DSO_ZYX;
5383 break;
5384
5385 case LSM6DSO_YZX:
5386 *val = LSM6DSO_YZX;
5387 break;
5388
5389 case LSM6DSO_ZXY:
5390 *val = LSM6DSO_ZXY;
5391 break;
5392
5393 default:
5394 *val = LSM6DSO_XYZ;
5395 break;
5396 }
5397
5398 return ret;
5399 }
5400
5401 /**
5402 * @brief Y-axis tap recognition threshold.[set]
5403 *
5404 * @param ctx read / write interface definitions
5405 * @param val change the values of tap_ths_y in reg TAP_CFG2
5406 * @retval interface status (MANDATORY: return 0 -> no Error)
5407 *
5408 */
lsm6dso_tap_threshold_y_set(stmdev_ctx_t * ctx,uint8_t val)5409 int32_t lsm6dso_tap_threshold_y_set(stmdev_ctx_t *ctx, uint8_t val)
5410 {
5411 lsm6dso_tap_cfg2_t reg;
5412 int32_t ret;
5413
5414 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG2, (uint8_t *)®, 1);
5415
5416 if (ret == 0)
5417 {
5418 reg.tap_ths_y = val;
5419 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_CFG2, (uint8_t *)®, 1);
5420 }
5421
5422 return ret;
5423 }
5424
5425 /**
5426 * @brief Y-axis tap recognition threshold.[get]
5427 *
5428 * @param ctx read / write interface definitions
5429 * @param val Get the values of tap_ths_y in reg TAP_CFG2
5430 * @retval interface status (MANDATORY: return 0 -> no Error)
5431 *
5432 */
lsm6dso_tap_threshold_y_get(stmdev_ctx_t * ctx,uint8_t * val)5433 int32_t lsm6dso_tap_threshold_y_get(stmdev_ctx_t *ctx, uint8_t *val)
5434 {
5435 lsm6dso_tap_cfg2_t reg;
5436 int32_t ret;
5437
5438 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG2, (uint8_t *)®, 1);
5439 *val = reg.tap_ths_y;
5440
5441 return ret;
5442 }
5443
5444 /**
5445 * @brief Z-axis recognition threshold.[set]
5446 *
5447 * @param ctx read / write interface definitions
5448 * @param val change the values of tap_ths_z in reg TAP_THS_6D
5449 * @retval interface status (MANDATORY: return 0 -> no Error)
5450 *
5451 */
lsm6dso_tap_threshold_z_set(stmdev_ctx_t * ctx,uint8_t val)5452 int32_t lsm6dso_tap_threshold_z_set(stmdev_ctx_t *ctx, uint8_t val)
5453 {
5454 lsm6dso_tap_ths_6d_t reg;
5455 int32_t ret;
5456
5457 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_THS_6D, (uint8_t *)®, 1);
5458
5459 if (ret == 0)
5460 {
5461 reg.tap_ths_z = val;
5462 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_THS_6D, (uint8_t *)®, 1);
5463 }
5464
5465 return ret;
5466 }
5467
5468 /**
5469 * @brief Z-axis recognition threshold.[get]
5470 *
5471 * @param ctx read / write interface definitions
5472 * @param val Get the values of tap_ths_z in reg TAP_THS_6D
5473 * @retval interface status (MANDATORY: return 0 -> no Error)
5474 *
5475 */
lsm6dso_tap_threshold_z_get(stmdev_ctx_t * ctx,uint8_t * val)5476 int32_t lsm6dso_tap_threshold_z_get(stmdev_ctx_t *ctx, uint8_t *val)
5477 {
5478 lsm6dso_tap_ths_6d_t reg;
5479 int32_t ret;
5480
5481 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_THS_6D, (uint8_t *)®, 1);
5482 *val = reg.tap_ths_z;
5483
5484 return ret;
5485 }
5486
5487 /**
5488 * @brief Maximum duration is the maximum time of an
5489 * over threshold signal detection to be recognized
5490 * as a tap event. The default value of these bits
5491 * is 00b which corresponds to 4*ODR_XL time.
5492 * If the SHOCK[1:0] bits are set to a different
5493 * value, 1LSB corresponds to 8*ODR_XL time.[set]
5494 *
5495 * @param ctx read / write interface definitions
5496 * @param val change the values of shock in reg INT_DUR2
5497 * @retval interface status (MANDATORY: return 0 -> no Error)
5498 *
5499 */
lsm6dso_tap_shock_set(stmdev_ctx_t * ctx,uint8_t val)5500 int32_t lsm6dso_tap_shock_set(stmdev_ctx_t *ctx, uint8_t val)
5501 {
5502 lsm6dso_int_dur2_t reg;
5503 int32_t ret;
5504
5505 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_DUR2, (uint8_t *)®, 1);
5506
5507 if (ret == 0)
5508 {
5509 reg.shock = val;
5510 ret = lsm6dso_write_reg(ctx, LSM6DSO_INT_DUR2, (uint8_t *)®, 1);
5511 }
5512
5513 return ret;
5514 }
5515
5516 /**
5517 * @brief Maximum duration is the maximum time of an
5518 * over threshold signal detection to be recognized
5519 * as a tap event. The default value of these bits
5520 * is 00b which corresponds to 4*ODR_XL time.
5521 * If the SHOCK[1:0] bits are set to a different
5522 * value, 1LSB corresponds to 8*ODR_XL time.[get]
5523 *
5524 * @param ctx read / write interface definitions
5525 * @param val Get the values of shock in reg INT_DUR2
5526 * @retval interface status (MANDATORY: return 0 -> no Error)
5527 *
5528 */
lsm6dso_tap_shock_get(stmdev_ctx_t * ctx,uint8_t * val)5529 int32_t lsm6dso_tap_shock_get(stmdev_ctx_t *ctx, uint8_t *val)
5530 {
5531 lsm6dso_int_dur2_t reg;
5532 int32_t ret;
5533
5534 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_DUR2, (uint8_t *)®, 1);
5535 *val = reg.shock;
5536
5537 return ret;
5538 }
5539
5540 /**
5541 * @brief Quiet time is the time after the first detected
5542 * tap in which there must not be any over threshold
5543 * event.
5544 * The default value of these bits is 00b which
5545 * corresponds to 2*ODR_XL time. If the QUIET[1:0]
5546 * bits are set to a different value,
5547 * 1LSB corresponds to 4*ODR_XL time.[set]
5548 *
5549 * @param ctx read / write interface definitions
5550 * @param val change the values of quiet in reg INT_DUR2
5551 * @retval interface status (MANDATORY: return 0 -> no Error)
5552 *
5553 */
lsm6dso_tap_quiet_set(stmdev_ctx_t * ctx,uint8_t val)5554 int32_t lsm6dso_tap_quiet_set(stmdev_ctx_t *ctx, uint8_t val)
5555 {
5556 lsm6dso_int_dur2_t reg;
5557 int32_t ret;
5558
5559 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_DUR2, (uint8_t *)®, 1);
5560
5561 if (ret == 0)
5562 {
5563 reg.quiet = val;
5564 ret = lsm6dso_write_reg(ctx, LSM6DSO_INT_DUR2, (uint8_t *)®, 1);
5565 }
5566
5567 return ret;
5568 }
5569
5570 /**
5571 * @brief Quiet time is the time after the first detected
5572 * tap in which there must not be any over threshold
5573 * event.
5574 * The default value of these bits is 00b which
5575 * corresponds to 2*ODR_XL time.
5576 * If the QUIET[1:0] bits are set to a different
5577 * value, 1LSB corresponds to 4*ODR_XL time.[get]
5578 *
5579 * @param ctx read / write interface definitions
5580 * @param val Get the values of quiet in reg INT_DUR2
5581 * @retval interface status (MANDATORY: return 0 -> no Error)
5582 *
5583 */
lsm6dso_tap_quiet_get(stmdev_ctx_t * ctx,uint8_t * val)5584 int32_t lsm6dso_tap_quiet_get(stmdev_ctx_t *ctx, uint8_t *val)
5585 {
5586 lsm6dso_int_dur2_t reg;
5587 int32_t ret;
5588
5589 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_DUR2, (uint8_t *)®, 1);
5590 *val = reg.quiet;
5591
5592 return ret;
5593 }
5594
5595 /**
5596 * @brief When double tap recognition is enabled,
5597 * this register expresses the maximum time
5598 * between two consecutive detected taps to
5599 * determine a double tap event.
5600 * The default value of these bits is 0000b which
5601 * corresponds to 16*ODR_XL time.
5602 * If the DUR[3:0] bits are set to a different value,
5603 * 1LSB corresponds to 32*ODR_XL time.[set]
5604 *
5605 * @param ctx read / write interface definitions
5606 * @param val change the values of dur in reg INT_DUR2
5607 * @retval interface status (MANDATORY: return 0 -> no Error)
5608 *
5609 */
lsm6dso_tap_dur_set(stmdev_ctx_t * ctx,uint8_t val)5610 int32_t lsm6dso_tap_dur_set(stmdev_ctx_t *ctx, uint8_t val)
5611 {
5612 lsm6dso_int_dur2_t reg;
5613 int32_t ret;
5614
5615 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_DUR2, (uint8_t *)®, 1);
5616
5617 if (ret == 0)
5618 {
5619 reg.dur = val;
5620 ret = lsm6dso_write_reg(ctx, LSM6DSO_INT_DUR2, (uint8_t *)®, 1);
5621 }
5622
5623 return ret;
5624 }
5625
5626 /**
5627 * @brief When double tap recognition is enabled,
5628 * this register expresses the maximum time
5629 * between two consecutive detected taps to
5630 * determine a double tap event.
5631 * The default value of these bits is 0000b which
5632 * corresponds to 16*ODR_XL time. If the DUR[3:0]
5633 * bits are set to a different value,
5634 * 1LSB corresponds to 32*ODR_XL time.[get]
5635 *
5636 * @param ctx read / write interface definitions
5637 * @param val Get the values of dur in reg INT_DUR2
5638 * @retval interface status (MANDATORY: return 0 -> no Error)
5639 *
5640 */
lsm6dso_tap_dur_get(stmdev_ctx_t * ctx,uint8_t * val)5641 int32_t lsm6dso_tap_dur_get(stmdev_ctx_t *ctx, uint8_t *val)
5642 {
5643 lsm6dso_int_dur2_t reg;
5644 int32_t ret;
5645
5646 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT_DUR2, (uint8_t *)®, 1);
5647 *val = reg.dur;
5648
5649 return ret;
5650 }
5651
5652 /**
5653 * @brief Single/double-tap event enable.[set]
5654 *
5655 * @param ctx read / write interface definitions
5656 * @param val change the values of single_double_tap in reg WAKE_UP_THS
5657 * @retval interface status (MANDATORY: return 0 -> no Error)
5658 *
5659 */
lsm6dso_tap_mode_set(stmdev_ctx_t * ctx,lsm6dso_single_double_tap_t val)5660 int32_t lsm6dso_tap_mode_set(stmdev_ctx_t *ctx,
5661 lsm6dso_single_double_tap_t val)
5662 {
5663 lsm6dso_wake_up_ths_t reg;
5664 int32_t ret;
5665
5666 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_THS, (uint8_t *)®, 1);
5667
5668 if (ret == 0)
5669 {
5670 reg.single_double_tap = (uint8_t)val;
5671 ret = lsm6dso_write_reg(ctx, LSM6DSO_WAKE_UP_THS, (uint8_t *)®, 1);
5672 }
5673
5674 return ret;
5675 }
5676
5677 /**
5678 * @brief Single/double-tap event enable.[get]
5679 *
5680 * @param ctx read / write interface definitions
5681 * @param val Get the values of single_double_tap in reg WAKE_UP_THS
5682 * @retval interface status (MANDATORY: return 0 -> no Error)
5683 *
5684 */
lsm6dso_tap_mode_get(stmdev_ctx_t * ctx,lsm6dso_single_double_tap_t * val)5685 int32_t lsm6dso_tap_mode_get(stmdev_ctx_t *ctx,
5686 lsm6dso_single_double_tap_t *val)
5687 {
5688 lsm6dso_wake_up_ths_t reg;
5689 int32_t ret;
5690
5691 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_THS, (uint8_t *)®, 1);
5692
5693 switch (reg.single_double_tap)
5694 {
5695 case LSM6DSO_ONLY_SINGLE:
5696 *val = LSM6DSO_ONLY_SINGLE;
5697 break;
5698
5699 case LSM6DSO_BOTH_SINGLE_DOUBLE:
5700 *val = LSM6DSO_BOTH_SINGLE_DOUBLE;
5701 break;
5702
5703 default:
5704 *val = LSM6DSO_ONLY_SINGLE;
5705 break;
5706 }
5707
5708 return ret;
5709 }
5710
5711 /**
5712 * @}
5713 *
5714 */
5715
5716 /**
5717 * @defgroup LSM6DSO_ Six_position_detection(6D/4D)
5718 * @brief This section groups all the functions concerning six position
5719 * detection (6D).
5720 * @{
5721 *
5722 */
5723
5724 /**
5725 * @brief Threshold for 4D/6D function.[set]
5726 *
5727 * @param ctx read / write interface definitions
5728 * @param val change the values of sixd_ths in reg TAP_THS_6D
5729 * @retval interface status (MANDATORY: return 0 -> no Error)
5730 *
5731 */
lsm6dso_6d_threshold_set(stmdev_ctx_t * ctx,lsm6dso_sixd_ths_t val)5732 int32_t lsm6dso_6d_threshold_set(stmdev_ctx_t *ctx,
5733 lsm6dso_sixd_ths_t val)
5734 {
5735 lsm6dso_tap_ths_6d_t reg;
5736 int32_t ret;
5737
5738 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_THS_6D, (uint8_t *)®, 1);
5739
5740 if (ret == 0)
5741 {
5742 reg.sixd_ths = (uint8_t)val;
5743 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_THS_6D, (uint8_t *)®, 1);
5744 }
5745
5746 return ret;
5747 }
5748
5749 /**
5750 * @brief Threshold for 4D/6D function.[get]
5751 *
5752 * @param ctx read / write interface definitions
5753 * @param val Get the values of sixd_ths in reg TAP_THS_6D
5754 * @retval interface status (MANDATORY: return 0 -> no Error)
5755 *
5756 */
lsm6dso_6d_threshold_get(stmdev_ctx_t * ctx,lsm6dso_sixd_ths_t * val)5757 int32_t lsm6dso_6d_threshold_get(stmdev_ctx_t *ctx,
5758 lsm6dso_sixd_ths_t *val)
5759 {
5760 lsm6dso_tap_ths_6d_t reg;
5761 int32_t ret;
5762
5763 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_THS_6D, (uint8_t *)®, 1);
5764
5765 switch (reg.sixd_ths)
5766 {
5767 case LSM6DSO_DEG_80:
5768 *val = LSM6DSO_DEG_80;
5769 break;
5770
5771 case LSM6DSO_DEG_70:
5772 *val = LSM6DSO_DEG_70;
5773 break;
5774
5775 case LSM6DSO_DEG_60:
5776 *val = LSM6DSO_DEG_60;
5777 break;
5778
5779 case LSM6DSO_DEG_50:
5780 *val = LSM6DSO_DEG_50;
5781 break;
5782
5783 default:
5784 *val = LSM6DSO_DEG_80;
5785 break;
5786 }
5787
5788 return ret;
5789 }
5790
5791 /**
5792 * @brief 4D orientation detection enable.[set]
5793 *
5794 * @param ctx read / write interface definitions
5795 * @param val change the values of d4d_en in reg TAP_THS_6D
5796 * @retval interface status (MANDATORY: return 0 -> no Error)
5797 *
5798 */
lsm6dso_4d_mode_set(stmdev_ctx_t * ctx,uint8_t val)5799 int32_t lsm6dso_4d_mode_set(stmdev_ctx_t *ctx, uint8_t val)
5800 {
5801 lsm6dso_tap_ths_6d_t reg;
5802 int32_t ret;
5803
5804 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_THS_6D, (uint8_t *)®, 1);
5805
5806 if (ret == 0)
5807 {
5808 reg.d4d_en = val;
5809 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_THS_6D, (uint8_t *)®, 1);
5810 }
5811
5812 return ret;
5813 }
5814
5815 /**
5816 * @brief 4D orientation detection enable.[get]
5817 *
5818 * @param ctx read / write interface definitions
5819 * @param val Get the values of d4d_en in reg TAP_THS_6D
5820 * @retval interface status (MANDATORY: return 0 -> no Error)
5821 *
5822 */
lsm6dso_4d_mode_get(stmdev_ctx_t * ctx,uint8_t * val)5823 int32_t lsm6dso_4d_mode_get(stmdev_ctx_t *ctx, uint8_t *val)
5824 {
5825 lsm6dso_tap_ths_6d_t reg;
5826 int32_t ret;
5827
5828 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_THS_6D, (uint8_t *)®, 1);
5829 *val = reg.d4d_en;
5830
5831 return ret;
5832 }
5833
5834 /**
5835 * @}
5836 *
5837 */
5838
5839 /**
5840 * @defgroup LSM6DSO_free_fall
5841 * @brief This section group all the functions concerning the free
5842 * fall detection.
5843 * @{
5844 *
5845 */
5846 /**
5847 * @brief Free fall threshold setting.[set]
5848 *
5849 * @param ctx read / write interface definitions
5850 * @param val change the values of ff_ths in reg FREE_FALL
5851 * @retval interface status (MANDATORY: return 0 -> no Error)
5852 *
5853 */
lsm6dso_ff_threshold_set(stmdev_ctx_t * ctx,lsm6dso_ff_ths_t val)5854 int32_t lsm6dso_ff_threshold_set(stmdev_ctx_t *ctx,
5855 lsm6dso_ff_ths_t val)
5856 {
5857 lsm6dso_free_fall_t reg;
5858 int32_t ret;
5859
5860 ret = lsm6dso_read_reg(ctx, LSM6DSO_FREE_FALL, (uint8_t *)®, 1);
5861
5862 if (ret == 0)
5863 {
5864 reg.ff_ths = (uint8_t)val;
5865 ret = lsm6dso_write_reg(ctx, LSM6DSO_FREE_FALL, (uint8_t *)®, 1);
5866 }
5867
5868 return ret;
5869 }
5870
5871 /**
5872 * @brief Free fall threshold setting.[get]
5873 *
5874 * @param ctx read / write interface definitions
5875 * @param val Get the values of ff_ths in reg FREE_FALL
5876 * @retval interface status (MANDATORY: return 0 -> no Error)
5877 *
5878 */
lsm6dso_ff_threshold_get(stmdev_ctx_t * ctx,lsm6dso_ff_ths_t * val)5879 int32_t lsm6dso_ff_threshold_get(stmdev_ctx_t *ctx,
5880 lsm6dso_ff_ths_t *val)
5881 {
5882 lsm6dso_free_fall_t reg;
5883 int32_t ret;
5884
5885 ret = lsm6dso_read_reg(ctx, LSM6DSO_FREE_FALL, (uint8_t *)®, 1);
5886
5887 switch (reg.ff_ths)
5888 {
5889 case LSM6DSO_FF_TSH_156mg:
5890 *val = LSM6DSO_FF_TSH_156mg;
5891 break;
5892
5893 case LSM6DSO_FF_TSH_219mg:
5894 *val = LSM6DSO_FF_TSH_219mg;
5895 break;
5896
5897 case LSM6DSO_FF_TSH_250mg:
5898 *val = LSM6DSO_FF_TSH_250mg;
5899 break;
5900
5901 case LSM6DSO_FF_TSH_312mg:
5902 *val = LSM6DSO_FF_TSH_312mg;
5903 break;
5904
5905 case LSM6DSO_FF_TSH_344mg:
5906 *val = LSM6DSO_FF_TSH_344mg;
5907 break;
5908
5909 case LSM6DSO_FF_TSH_406mg:
5910 *val = LSM6DSO_FF_TSH_406mg;
5911 break;
5912
5913 case LSM6DSO_FF_TSH_469mg:
5914 *val = LSM6DSO_FF_TSH_469mg;
5915 break;
5916
5917 case LSM6DSO_FF_TSH_500mg:
5918 *val = LSM6DSO_FF_TSH_500mg;
5919 break;
5920
5921 default:
5922 *val = LSM6DSO_FF_TSH_156mg;
5923 break;
5924 }
5925
5926 return ret;
5927 }
5928
5929 /**
5930 * @brief Free-fall duration event.[set]
5931 * 1LSb = 1 / ODR
5932 *
5933 * @param ctx read / write interface definitions
5934 * @param val change the values of ff_dur in reg FREE_FALL
5935 * @retval interface status (MANDATORY: return 0 -> no Error)
5936 *
5937 */
lsm6dso_ff_dur_set(stmdev_ctx_t * ctx,uint8_t val)5938 int32_t lsm6dso_ff_dur_set(stmdev_ctx_t *ctx, uint8_t val)
5939 {
5940 lsm6dso_wake_up_dur_t wake_up_dur;
5941 lsm6dso_free_fall_t free_fall;
5942 int32_t ret;
5943
5944 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_DUR,
5945 (uint8_t *)&wake_up_dur, 1);
5946
5947 if (ret == 0)
5948 {
5949 ret = lsm6dso_read_reg(ctx, LSM6DSO_FREE_FALL, (uint8_t *)&free_fall, 1);
5950 }
5951
5952 if (ret == 0)
5953 {
5954 wake_up_dur.ff_dur = ((uint8_t)val & 0x20U) >> 5;
5955 free_fall.ff_dur = (uint8_t)val & 0x1FU;
5956 ret = lsm6dso_write_reg(ctx, LSM6DSO_WAKE_UP_DUR,
5957 (uint8_t *)&wake_up_dur, 1);
5958 }
5959
5960 if (ret == 0)
5961 {
5962 ret = lsm6dso_write_reg(ctx, LSM6DSO_FREE_FALL, (uint8_t *)&free_fall, 1);
5963 }
5964
5965 return ret;
5966 }
5967
5968 /**
5969 * @brief Free-fall duration event.[get]
5970 * 1LSb = 1 / ODR
5971 *
5972 * @param ctx read / write interface definitions
5973 * @param val Get the values of ff_dur in reg FREE_FALL
5974 * @retval interface status (MANDATORY: return 0 -> no Error)
5975 *
5976 */
lsm6dso_ff_dur_get(stmdev_ctx_t * ctx,uint8_t * val)5977 int32_t lsm6dso_ff_dur_get(stmdev_ctx_t *ctx, uint8_t *val)
5978 {
5979 lsm6dso_wake_up_dur_t wake_up_dur;
5980 lsm6dso_free_fall_t free_fall;
5981 int32_t ret;
5982
5983 ret = lsm6dso_read_reg(ctx, LSM6DSO_WAKE_UP_DUR,
5984 (uint8_t *)&wake_up_dur, 1);
5985
5986 if (ret == 0)
5987 {
5988 ret = lsm6dso_read_reg(ctx, LSM6DSO_FREE_FALL, (uint8_t *)&free_fall, 1);
5989 *val = (wake_up_dur.ff_dur << 5) + free_fall.ff_dur;
5990 }
5991
5992 return ret;
5993 }
5994
5995 /**
5996 * @}
5997 *
5998 */
5999
6000 /**
6001 * @defgroup LSM6DSO_fifo
6002 * @brief This section group all the functions concerning the fifo usage
6003 * @{
6004 *
6005 */
6006
6007 /**
6008 * @brief FIFO watermark level selection.[set]
6009 *
6010 * @param ctx read / write interface definitions
6011 * @param val change the values of wtm in reg FIFO_CTRL1
6012 * @retval interface status (MANDATORY: return 0 -> no Error)
6013 *
6014 */
lsm6dso_fifo_watermark_set(stmdev_ctx_t * ctx,uint16_t val)6015 int32_t lsm6dso_fifo_watermark_set(stmdev_ctx_t *ctx, uint16_t val)
6016 {
6017 lsm6dso_fifo_ctrl1_t fifo_ctrl1;
6018 lsm6dso_fifo_ctrl2_t fifo_ctrl2;
6019 int32_t ret;
6020
6021 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL2,
6022 (uint8_t *)&fifo_ctrl2, 1);
6023
6024 if (ret == 0)
6025 {
6026 fifo_ctrl1.wtm = 0x00FFU & (uint8_t)val;
6027 fifo_ctrl2.wtm = (uint8_t)((0x0100U & val) >> 8);
6028 ret = lsm6dso_write_reg(ctx, LSM6DSO_FIFO_CTRL1,
6029 (uint8_t *)&fifo_ctrl1, 1);
6030 }
6031
6032 if (ret == 0)
6033 {
6034 ret = lsm6dso_write_reg(ctx, LSM6DSO_FIFO_CTRL2,
6035 (uint8_t *)&fifo_ctrl2, 1);
6036 }
6037
6038 return ret;
6039 }
6040
6041 /**
6042 * @brief FIFO watermark level selection.[get]
6043 *
6044 * @param ctx read / write interface definitions
6045 * @param val Get the values of wtm in reg FIFO_CTRL1
6046 * @retval interface status (MANDATORY: return 0 -> no Error)
6047 *
6048 */
lsm6dso_fifo_watermark_get(stmdev_ctx_t * ctx,uint16_t * val)6049 int32_t lsm6dso_fifo_watermark_get(stmdev_ctx_t *ctx, uint16_t *val)
6050 {
6051 lsm6dso_fifo_ctrl1_t fifo_ctrl1;
6052 lsm6dso_fifo_ctrl2_t fifo_ctrl2;
6053 int32_t ret;
6054
6055 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL1,
6056 (uint8_t *)&fifo_ctrl1, 1);
6057
6058 if (ret == 0)
6059 {
6060 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL2,
6061 (uint8_t *)&fifo_ctrl2, 1);
6062 *val = ((uint16_t)fifo_ctrl2.wtm << 8) + (uint16_t)fifo_ctrl1.wtm;
6063 }
6064
6065 return ret;
6066 }
6067
6068 /**
6069 * @brief FIFO compression feature initialization request [set].
6070 *
6071 * @param ctx read / write interface definitions
6072 * @param val change the values of FIFO_COMPR_INIT in
6073 * reg EMB_FUNC_INIT_B
6074 * @retval interface status (MANDATORY: return 0 -> no Error)
6075 *
6076 */
lsm6dso_compression_algo_init_set(stmdev_ctx_t * ctx,uint8_t val)6077 int32_t lsm6dso_compression_algo_init_set(stmdev_ctx_t *ctx,
6078 uint8_t val)
6079 {
6080 lsm6dso_emb_func_init_b_t reg;
6081 int32_t ret;
6082
6083 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
6084
6085 if (ret == 0)
6086 {
6087 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_INIT_B, (uint8_t *)®, 1);
6088 }
6089
6090 if (ret == 0)
6091 {
6092 reg.fifo_compr_init = val;
6093 ret = lsm6dso_write_reg(ctx, LSM6DSO_EMB_FUNC_INIT_B, (uint8_t *)®, 1);
6094 }
6095
6096 if (ret == 0)
6097 {
6098 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
6099 }
6100
6101 return ret;
6102 }
6103
6104 /**
6105 * @brief FIFO compression feature initialization request [get].
6106 *
6107 * @param ctx read / write interface definitions
6108 * @param val Get the values of FIFO_COMPR_INIT in
6109 * reg EMB_FUNC_INIT_B
6110 * @retval interface status (MANDATORY: return 0 -> no Error)
6111 *
6112 */
lsm6dso_compression_algo_init_get(stmdev_ctx_t * ctx,uint8_t * val)6113 int32_t lsm6dso_compression_algo_init_get(stmdev_ctx_t *ctx,
6114 uint8_t *val)
6115 {
6116 lsm6dso_emb_func_init_b_t reg;
6117 int32_t ret;
6118
6119 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
6120
6121 if (ret == 0)
6122 {
6123 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_INIT_B, (uint8_t *)®, 1);
6124 }
6125
6126 if (ret == 0)
6127 {
6128 *val = reg.fifo_compr_init;
6129 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
6130 }
6131
6132 return ret;
6133 }
6134
6135 /**
6136 * @brief Enable and configure compression algo.[set]
6137 *
6138 * @param ctx read / write interface definitions
6139 * @param val change the values of uncoptr_rate in
6140 * reg FIFO_CTRL2
6141 * @retval interface status (MANDATORY: return 0 -> no Error)
6142 *
6143 */
lsm6dso_compression_algo_set(stmdev_ctx_t * ctx,lsm6dso_uncoptr_rate_t val)6144 int32_t lsm6dso_compression_algo_set(stmdev_ctx_t *ctx,
6145 lsm6dso_uncoptr_rate_t val)
6146 {
6147 lsm6dso_fifo_ctrl2_t fifo_ctrl2;
6148 int32_t ret;
6149
6150 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL2,
6151 (uint8_t *)&fifo_ctrl2, 1);
6152
6153 if (ret == 0)
6154 {
6155 fifo_ctrl2.fifo_compr_rt_en = ((uint8_t)val & 0x04U) >> 2;
6156 fifo_ctrl2.uncoptr_rate = (uint8_t)val & 0x03U;
6157 ret = lsm6dso_write_reg(ctx, LSM6DSO_FIFO_CTRL2,
6158 (uint8_t *)&fifo_ctrl2, 1);
6159 }
6160
6161 return ret;
6162 }
6163
6164 /**
6165 * @brief Enable and configure compression algo.[get]
6166 *
6167 * @param ctx read / write interface definitions
6168 * @param val Get the values of uncoptr_rate in
6169 * reg FIFO_CTRL2
6170 * @retval interface status (MANDATORY: return 0 -> no Error)
6171 *
6172 */
lsm6dso_compression_algo_get(stmdev_ctx_t * ctx,lsm6dso_uncoptr_rate_t * val)6173 int32_t lsm6dso_compression_algo_get(stmdev_ctx_t *ctx,
6174 lsm6dso_uncoptr_rate_t *val)
6175 {
6176 lsm6dso_fifo_ctrl2_t reg;
6177 int32_t ret;
6178
6179 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL2, (uint8_t *)®, 1);
6180
6181 switch ((reg.fifo_compr_rt_en << 2) | reg.uncoptr_rate)
6182 {
6183 case LSM6DSO_CMP_DISABLE:
6184 *val = LSM6DSO_CMP_DISABLE;
6185 break;
6186
6187 case LSM6DSO_CMP_ALWAYS:
6188 *val = LSM6DSO_CMP_ALWAYS;
6189 break;
6190
6191 case LSM6DSO_CMP_8_TO_1:
6192 *val = LSM6DSO_CMP_8_TO_1;
6193 break;
6194
6195 case LSM6DSO_CMP_16_TO_1:
6196 *val = LSM6DSO_CMP_16_TO_1;
6197 break;
6198
6199 case LSM6DSO_CMP_32_TO_1:
6200 *val = LSM6DSO_CMP_32_TO_1;
6201 break;
6202
6203 default:
6204 *val = LSM6DSO_CMP_DISABLE;
6205 break;
6206 }
6207
6208 return ret;
6209 }
6210
6211 /**
6212 * @brief Enables ODR CHANGE virtual sensor to be batched in FIFO.[set]
6213 *
6214 * @param ctx read / write interface definitions
6215 * @param val change the values of odrchg_en in reg FIFO_CTRL2
6216 * @retval interface status (MANDATORY: return 0 -> no Error)
6217 *
6218 */
lsm6dso_fifo_virtual_sens_odr_chg_set(stmdev_ctx_t * ctx,uint8_t val)6219 int32_t lsm6dso_fifo_virtual_sens_odr_chg_set(stmdev_ctx_t *ctx,
6220 uint8_t val)
6221 {
6222 lsm6dso_fifo_ctrl2_t reg;
6223 int32_t ret;
6224
6225 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL2, (uint8_t *)®, 1);
6226
6227 if (ret == 0)
6228 {
6229 reg.odrchg_en = val;
6230 ret = lsm6dso_write_reg(ctx, LSM6DSO_FIFO_CTRL2, (uint8_t *)®, 1);
6231 }
6232
6233 return ret;
6234 }
6235
6236 /**
6237 * @brief Enables ODR CHANGE virtual sensor to be batched in FIFO.[get]
6238 *
6239 * @param ctx read / write interface definitions
6240 * @param val Get the values of odrchg_en in reg FIFO_CTRL2
6241 * @retval interface status (MANDATORY: return 0 -> no Error)
6242 *
6243 */
lsm6dso_fifo_virtual_sens_odr_chg_get(stmdev_ctx_t * ctx,uint8_t * val)6244 int32_t lsm6dso_fifo_virtual_sens_odr_chg_get(stmdev_ctx_t *ctx,
6245 uint8_t *val)
6246 {
6247 lsm6dso_fifo_ctrl2_t reg;
6248 int32_t ret;
6249
6250 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL2, (uint8_t *)®, 1);
6251 *val = reg.odrchg_en;
6252
6253 return ret;
6254 }
6255
6256 /**
6257 * @brief Enables/Disables compression algorithm runtime.[set]
6258 *
6259 * @param ctx read / write interface definitions
6260 * @param val change the values of fifo_compr_rt_en in
6261 * reg FIFO_CTRL2
6262 * @retval interface status (MANDATORY: return 0 -> no Error)
6263 *
6264 */
lsm6dso_compression_algo_real_time_set(stmdev_ctx_t * ctx,uint8_t val)6265 int32_t lsm6dso_compression_algo_real_time_set(stmdev_ctx_t *ctx,
6266 uint8_t val)
6267 {
6268 lsm6dso_fifo_ctrl2_t reg;
6269 int32_t ret;
6270
6271 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL2, (uint8_t *)®, 1);
6272
6273 if (ret == 0)
6274 {
6275 reg.fifo_compr_rt_en = val;
6276 ret = lsm6dso_write_reg(ctx, LSM6DSO_FIFO_CTRL2, (uint8_t *)®, 1);
6277 }
6278
6279 return ret;
6280 }
6281
6282 /**
6283 * @brief Enables/Disables compression algorithm runtime. [get]
6284 *
6285 * @param ctx read / write interface definitions
6286 * @param val Get the values of fifo_compr_rt_en in reg FIFO_CTRL2
6287 * @retval interface status (MANDATORY: return 0 -> no Error)
6288 *
6289 */
lsm6dso_compression_algo_real_time_get(stmdev_ctx_t * ctx,uint8_t * val)6290 int32_t lsm6dso_compression_algo_real_time_get(stmdev_ctx_t *ctx,
6291 uint8_t *val)
6292 {
6293 lsm6dso_fifo_ctrl2_t reg;
6294 int32_t ret;
6295
6296 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL2, (uint8_t *)®, 1);
6297 *val = reg.fifo_compr_rt_en;
6298
6299 return ret;
6300 }
6301
6302 /**
6303 * @brief Sensing chain FIFO stop values memorization at
6304 * threshold level.[set]
6305 *
6306 * @param ctx read / write interface definitions
6307 * @param val change the values of stop_on_wtm in reg FIFO_CTRL2
6308 * @retval interface status (MANDATORY: return 0 -> no Error)
6309 *
6310 */
lsm6dso_fifo_stop_on_wtm_set(stmdev_ctx_t * ctx,uint8_t val)6311 int32_t lsm6dso_fifo_stop_on_wtm_set(stmdev_ctx_t *ctx, uint8_t val)
6312 {
6313 lsm6dso_fifo_ctrl2_t reg;
6314 int32_t ret;
6315
6316 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL2, (uint8_t *)®, 1);
6317
6318 if (ret == 0)
6319 {
6320 reg.stop_on_wtm = val;
6321 ret = lsm6dso_write_reg(ctx, LSM6DSO_FIFO_CTRL2, (uint8_t *)®, 1);
6322 }
6323
6324 return ret;
6325 }
6326
6327 /**
6328 * @brief Sensing chain FIFO stop values memorization at
6329 * threshold level.[get]
6330 *
6331 * @param ctx read / write interface definitions
6332 * @param val Get the values of stop_on_wtm in reg FIFO_CTRL2
6333 * @retval interface status (MANDATORY: return 0 -> no Error)
6334 *
6335 */
lsm6dso_fifo_stop_on_wtm_get(stmdev_ctx_t * ctx,uint8_t * val)6336 int32_t lsm6dso_fifo_stop_on_wtm_get(stmdev_ctx_t *ctx, uint8_t *val)
6337 {
6338 lsm6dso_fifo_ctrl2_t reg;
6339 int32_t ret;
6340
6341 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL2, (uint8_t *)®, 1);
6342 *val = reg.stop_on_wtm;
6343
6344 return ret;
6345 }
6346
6347 /**
6348 * @brief Selects Batching Data Rate (writing frequency in FIFO)
6349 * for accelerometer data.[set]
6350 *
6351 * @param ctx read / write interface definitions
6352 * @param val change the values of bdr_xl in reg FIFO_CTRL3
6353 * @retval interface status (MANDATORY: return 0 -> no Error)
6354 *
6355 */
lsm6dso_fifo_xl_batch_set(stmdev_ctx_t * ctx,lsm6dso_bdr_xl_t val)6356 int32_t lsm6dso_fifo_xl_batch_set(stmdev_ctx_t *ctx,
6357 lsm6dso_bdr_xl_t val)
6358 {
6359 lsm6dso_fifo_ctrl3_t reg;
6360 int32_t ret;
6361
6362 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL3, (uint8_t *)®, 1);
6363
6364 if (ret == 0)
6365 {
6366 reg.bdr_xl = (uint8_t)val;
6367 ret = lsm6dso_write_reg(ctx, LSM6DSO_FIFO_CTRL3, (uint8_t *)®, 1);
6368 }
6369
6370 return ret;
6371 }
6372
6373 /**
6374 * @brief Selects Batching Data Rate (writing frequency in FIFO)
6375 * for accelerometer data.[get]
6376 *
6377 * @param ctx read / write interface definitions
6378 * @param val Get the values of bdr_xl in reg FIFO_CTRL3
6379 * @retval interface status (MANDATORY: return 0 -> no Error)
6380 *
6381 */
lsm6dso_fifo_xl_batch_get(stmdev_ctx_t * ctx,lsm6dso_bdr_xl_t * val)6382 int32_t lsm6dso_fifo_xl_batch_get(stmdev_ctx_t *ctx,
6383 lsm6dso_bdr_xl_t *val)
6384 {
6385 lsm6dso_fifo_ctrl3_t reg;
6386 int32_t ret;
6387
6388 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL3, (uint8_t *)®, 1);
6389
6390 switch (reg.bdr_xl)
6391 {
6392 case LSM6DSO_XL_NOT_BATCHED:
6393 *val = LSM6DSO_XL_NOT_BATCHED;
6394 break;
6395
6396 case LSM6DSO_XL_BATCHED_AT_12Hz5:
6397 *val = LSM6DSO_XL_BATCHED_AT_12Hz5;
6398 break;
6399
6400 case LSM6DSO_XL_BATCHED_AT_26Hz:
6401 *val = LSM6DSO_XL_BATCHED_AT_26Hz;
6402 break;
6403
6404 case LSM6DSO_XL_BATCHED_AT_52Hz:
6405 *val = LSM6DSO_XL_BATCHED_AT_52Hz;
6406 break;
6407
6408 case LSM6DSO_XL_BATCHED_AT_104Hz:
6409 *val = LSM6DSO_XL_BATCHED_AT_104Hz;
6410 break;
6411
6412 case LSM6DSO_XL_BATCHED_AT_208Hz:
6413 *val = LSM6DSO_XL_BATCHED_AT_208Hz;
6414 break;
6415
6416 case LSM6DSO_XL_BATCHED_AT_417Hz:
6417 *val = LSM6DSO_XL_BATCHED_AT_417Hz;
6418 break;
6419
6420 case LSM6DSO_XL_BATCHED_AT_833Hz:
6421 *val = LSM6DSO_XL_BATCHED_AT_833Hz;
6422 break;
6423
6424 case LSM6DSO_XL_BATCHED_AT_1667Hz:
6425 *val = LSM6DSO_XL_BATCHED_AT_1667Hz;
6426 break;
6427
6428 case LSM6DSO_XL_BATCHED_AT_3333Hz:
6429 *val = LSM6DSO_XL_BATCHED_AT_3333Hz;
6430 break;
6431
6432 case LSM6DSO_XL_BATCHED_AT_6667Hz:
6433 *val = LSM6DSO_XL_BATCHED_AT_6667Hz;
6434 break;
6435
6436 case LSM6DSO_XL_BATCHED_AT_6Hz5:
6437 *val = LSM6DSO_XL_BATCHED_AT_6Hz5;
6438 break;
6439
6440 default:
6441 *val = LSM6DSO_XL_NOT_BATCHED;
6442 break;
6443 }
6444
6445 return ret;
6446 }
6447
6448 /**
6449 * @brief Selects Batching Data Rate (writing frequency in FIFO)
6450 * for gyroscope data.[set]
6451 *
6452 * @param ctx read / write interface definitions
6453 * @param val change the values of bdr_gy in reg FIFO_CTRL3
6454 * @retval interface status (MANDATORY: return 0 -> no Error)
6455 *
6456 */
lsm6dso_fifo_gy_batch_set(stmdev_ctx_t * ctx,lsm6dso_bdr_gy_t val)6457 int32_t lsm6dso_fifo_gy_batch_set(stmdev_ctx_t *ctx,
6458 lsm6dso_bdr_gy_t val)
6459 {
6460 lsm6dso_fifo_ctrl3_t reg;
6461 int32_t ret;
6462
6463 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL3, (uint8_t *)®, 1);
6464
6465 if (ret == 0)
6466 {
6467 reg.bdr_gy = (uint8_t)val;
6468 ret = lsm6dso_write_reg(ctx, LSM6DSO_FIFO_CTRL3, (uint8_t *)®, 1);
6469 }
6470
6471 return ret;
6472 }
6473
6474 /**
6475 * @brief Selects Batching Data Rate (writing frequency in FIFO)
6476 * for gyroscope data.[get]
6477 *
6478 * @param ctx read / write interface definitions
6479 * @param val Get the values of bdr_gy in reg FIFO_CTRL3
6480 * @retval interface status (MANDATORY: return 0 -> no Error)
6481 *
6482 */
lsm6dso_fifo_gy_batch_get(stmdev_ctx_t * ctx,lsm6dso_bdr_gy_t * val)6483 int32_t lsm6dso_fifo_gy_batch_get(stmdev_ctx_t *ctx,
6484 lsm6dso_bdr_gy_t *val)
6485 {
6486 lsm6dso_fifo_ctrl3_t reg;
6487 int32_t ret;
6488
6489 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL3, (uint8_t *)®, 1);
6490
6491 switch (reg.bdr_gy)
6492 {
6493 case LSM6DSO_GY_NOT_BATCHED:
6494 *val = LSM6DSO_GY_NOT_BATCHED;
6495 break;
6496
6497 case LSM6DSO_GY_BATCHED_AT_12Hz5:
6498 *val = LSM6DSO_GY_BATCHED_AT_12Hz5;
6499 break;
6500
6501 case LSM6DSO_GY_BATCHED_AT_26Hz:
6502 *val = LSM6DSO_GY_BATCHED_AT_26Hz;
6503 break;
6504
6505 case LSM6DSO_GY_BATCHED_AT_52Hz:
6506 *val = LSM6DSO_GY_BATCHED_AT_52Hz;
6507 break;
6508
6509 case LSM6DSO_GY_BATCHED_AT_104Hz:
6510 *val = LSM6DSO_GY_BATCHED_AT_104Hz;
6511 break;
6512
6513 case LSM6DSO_GY_BATCHED_AT_208Hz:
6514 *val = LSM6DSO_GY_BATCHED_AT_208Hz;
6515 break;
6516
6517 case LSM6DSO_GY_BATCHED_AT_417Hz:
6518 *val = LSM6DSO_GY_BATCHED_AT_417Hz;
6519 break;
6520
6521 case LSM6DSO_GY_BATCHED_AT_833Hz:
6522 *val = LSM6DSO_GY_BATCHED_AT_833Hz;
6523 break;
6524
6525 case LSM6DSO_GY_BATCHED_AT_1667Hz:
6526 *val = LSM6DSO_GY_BATCHED_AT_1667Hz;
6527 break;
6528
6529 case LSM6DSO_GY_BATCHED_AT_3333Hz:
6530 *val = LSM6DSO_GY_BATCHED_AT_3333Hz;
6531 break;
6532
6533 case LSM6DSO_GY_BATCHED_AT_6667Hz:
6534 *val = LSM6DSO_GY_BATCHED_AT_6667Hz;
6535 break;
6536
6537 case LSM6DSO_GY_BATCHED_AT_6Hz5:
6538 *val = LSM6DSO_GY_BATCHED_AT_6Hz5;
6539 break;
6540
6541 default:
6542 *val = LSM6DSO_GY_NOT_BATCHED;
6543 break;
6544 }
6545
6546 return ret;
6547 }
6548
6549 /**
6550 * @brief FIFO mode selection.[set]
6551 *
6552 * @param ctx read / write interface definitions
6553 * @param val change the values of fifo_mode in reg FIFO_CTRL4
6554 * @retval interface status (MANDATORY: return 0 -> no Error)
6555 *
6556 */
lsm6dso_fifo_mode_set(stmdev_ctx_t * ctx,lsm6dso_fifo_mode_t val)6557 int32_t lsm6dso_fifo_mode_set(stmdev_ctx_t *ctx,
6558 lsm6dso_fifo_mode_t val)
6559 {
6560 lsm6dso_fifo_ctrl4_t reg;
6561 int32_t ret;
6562
6563 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL4, (uint8_t *)®, 1);
6564
6565 if (ret == 0)
6566 {
6567 reg.fifo_mode = (uint8_t)val;
6568 ret = lsm6dso_write_reg(ctx, LSM6DSO_FIFO_CTRL4, (uint8_t *)®, 1);
6569 }
6570
6571 return ret;
6572 }
6573
6574 /**
6575 * @brief FIFO mode selection.[get]
6576 *
6577 * @param ctx read / write interface definitions
6578 * @param val Get the values of fifo_mode in reg FIFO_CTRL4
6579 * @retval interface status (MANDATORY: return 0 -> no Error)
6580 *
6581 */
lsm6dso_fifo_mode_get(stmdev_ctx_t * ctx,lsm6dso_fifo_mode_t * val)6582 int32_t lsm6dso_fifo_mode_get(stmdev_ctx_t *ctx,
6583 lsm6dso_fifo_mode_t *val)
6584 {
6585 lsm6dso_fifo_ctrl4_t reg;
6586 int32_t ret;
6587
6588 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL4, (uint8_t *)®, 1);
6589
6590 switch (reg.fifo_mode)
6591 {
6592 case LSM6DSO_BYPASS_MODE:
6593 *val = LSM6DSO_BYPASS_MODE;
6594 break;
6595
6596 case LSM6DSO_FIFO_MODE:
6597 *val = LSM6DSO_FIFO_MODE;
6598 break;
6599
6600 case LSM6DSO_STREAM_TO_FIFO_MODE:
6601 *val = LSM6DSO_STREAM_TO_FIFO_MODE;
6602 break;
6603
6604 case LSM6DSO_BYPASS_TO_STREAM_MODE:
6605 *val = LSM6DSO_BYPASS_TO_STREAM_MODE;
6606 break;
6607
6608 case LSM6DSO_STREAM_MODE:
6609 *val = LSM6DSO_STREAM_MODE;
6610 break;
6611
6612 case LSM6DSO_BYPASS_TO_FIFO_MODE:
6613 *val = LSM6DSO_BYPASS_TO_FIFO_MODE;
6614 break;
6615
6616 default:
6617 *val = LSM6DSO_BYPASS_MODE;
6618 break;
6619 }
6620
6621 return ret;
6622 }
6623
6624 /**
6625 * @brief Selects Batching Data Rate (writing frequency in FIFO)
6626 * for temperature data.[set]
6627 *
6628 * @param ctx read / write interface definitions
6629 * @param val change the values of odr_t_batch in reg FIFO_CTRL4
6630 * @retval interface status (MANDATORY: return 0 -> no Error)
6631 *
6632 */
lsm6dso_fifo_temp_batch_set(stmdev_ctx_t * ctx,lsm6dso_odr_t_batch_t val)6633 int32_t lsm6dso_fifo_temp_batch_set(stmdev_ctx_t *ctx,
6634 lsm6dso_odr_t_batch_t val)
6635 {
6636 lsm6dso_fifo_ctrl4_t reg;
6637 int32_t ret;
6638
6639 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL4, (uint8_t *)®, 1);
6640
6641 if (ret == 0)
6642 {
6643 reg.odr_t_batch = (uint8_t)val;
6644 ret = lsm6dso_write_reg(ctx, LSM6DSO_FIFO_CTRL4, (uint8_t *)®, 1);
6645 }
6646
6647 return ret;
6648 }
6649
6650 /**
6651 * @brief Selects Batching Data Rate (writing frequency in FIFO)
6652 * for temperature data.[get]
6653 *
6654 * @param ctx read / write interface definitions
6655 * @param val Get the values of odr_t_batch in reg FIFO_CTRL4
6656 * @retval interface status (MANDATORY: return 0 -> no Error)
6657 *
6658 */
lsm6dso_fifo_temp_batch_get(stmdev_ctx_t * ctx,lsm6dso_odr_t_batch_t * val)6659 int32_t lsm6dso_fifo_temp_batch_get(stmdev_ctx_t *ctx,
6660 lsm6dso_odr_t_batch_t *val)
6661 {
6662 lsm6dso_fifo_ctrl4_t reg;
6663 int32_t ret;
6664
6665 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL4, (uint8_t *)®, 1);
6666
6667 switch (reg.odr_t_batch)
6668 {
6669 case LSM6DSO_TEMP_NOT_BATCHED:
6670 *val = LSM6DSO_TEMP_NOT_BATCHED;
6671 break;
6672
6673 case LSM6DSO_TEMP_BATCHED_AT_1Hz6:
6674 *val = LSM6DSO_TEMP_BATCHED_AT_1Hz6;
6675 break;
6676
6677 case LSM6DSO_TEMP_BATCHED_AT_12Hz5:
6678 *val = LSM6DSO_TEMP_BATCHED_AT_12Hz5;
6679 break;
6680
6681 case LSM6DSO_TEMP_BATCHED_AT_52Hz:
6682 *val = LSM6DSO_TEMP_BATCHED_AT_52Hz;
6683 break;
6684
6685 default:
6686 *val = LSM6DSO_TEMP_NOT_BATCHED;
6687 break;
6688 }
6689
6690 return ret;
6691 }
6692
6693 /**
6694 * @brief Selects decimation for timestamp batching in FIFO.
6695 * Writing rate will be the maximum rate between XL and
6696 * GYRO BDR divided by decimation decoder.[set]
6697 *
6698 * @param ctx read / write interface definitions
6699 * @param val change the values of odr_ts_batch in reg FIFO_CTRL4
6700 * @retval interface status (MANDATORY: return 0 -> no Error)
6701 *
6702 */
lsm6dso_fifo_timestamp_decimation_set(stmdev_ctx_t * ctx,lsm6dso_odr_ts_batch_t val)6703 int32_t lsm6dso_fifo_timestamp_decimation_set(stmdev_ctx_t *ctx,
6704 lsm6dso_odr_ts_batch_t val)
6705 {
6706 lsm6dso_fifo_ctrl4_t reg;
6707 int32_t ret;
6708
6709 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL4, (uint8_t *)®, 1);
6710
6711 if (ret == 0)
6712 {
6713 reg.odr_ts_batch = (uint8_t)val;
6714 ret = lsm6dso_write_reg(ctx, LSM6DSO_FIFO_CTRL4, (uint8_t *)®, 1);
6715 }
6716
6717 return ret;
6718 }
6719
6720 /**
6721 * @brief Selects decimation for timestamp batching in FIFO.
6722 * Writing rate will be the maximum rate between XL and
6723 * GYRO BDR divided by decimation decoder.[get]
6724 *
6725 * @param ctx read / write interface definitions
6726 * @param val Get the values of odr_ts_batch in reg FIFO_CTRL4
6727 * @retval interface status (MANDATORY: return 0 -> no Error)
6728 *
6729 */
lsm6dso_fifo_timestamp_decimation_get(stmdev_ctx_t * ctx,lsm6dso_odr_ts_batch_t * val)6730 int32_t lsm6dso_fifo_timestamp_decimation_get(stmdev_ctx_t *ctx,
6731 lsm6dso_odr_ts_batch_t *val)
6732 {
6733 lsm6dso_fifo_ctrl4_t reg;
6734 int32_t ret;
6735
6736 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_CTRL4, (uint8_t *)®, 1);
6737
6738 switch (reg.odr_ts_batch)
6739 {
6740 case LSM6DSO_NO_DECIMATION:
6741 *val = LSM6DSO_NO_DECIMATION;
6742 break;
6743
6744 case LSM6DSO_DEC_1:
6745 *val = LSM6DSO_DEC_1;
6746 break;
6747
6748 case LSM6DSO_DEC_8:
6749 *val = LSM6DSO_DEC_8;
6750 break;
6751
6752 case LSM6DSO_DEC_32:
6753 *val = LSM6DSO_DEC_32;
6754 break;
6755
6756 default:
6757 *val = LSM6DSO_NO_DECIMATION;
6758 break;
6759 }
6760
6761 return ret;
6762 }
6763
6764 /**
6765 * @brief Selects the trigger for the internal counter of batching events
6766 * between XL and gyro.[set]
6767 *
6768 * @param ctx read / write interface definitions
6769 * @param val change the values of trig_counter_bdr
6770 * in reg COUNTER_BDR_REG1
6771 * @retval interface status (MANDATORY: return 0 -> no Error)
6772 *
6773 */
lsm6dso_fifo_cnt_event_batch_set(stmdev_ctx_t * ctx,lsm6dso_trig_counter_bdr_t val)6774 int32_t lsm6dso_fifo_cnt_event_batch_set(stmdev_ctx_t *ctx,
6775 lsm6dso_trig_counter_bdr_t val)
6776 {
6777 lsm6dso_counter_bdr_reg1_t reg;
6778 int32_t ret;
6779
6780 ret = lsm6dso_read_reg(ctx, LSM6DSO_COUNTER_BDR_REG1, (uint8_t *)®, 1);
6781
6782 if (ret == 0)
6783 {
6784 reg.trig_counter_bdr = (uint8_t)val;
6785 ret = lsm6dso_write_reg(ctx, LSM6DSO_COUNTER_BDR_REG1,
6786 (uint8_t *)®, 1);
6787 }
6788
6789 return ret;
6790 }
6791
6792 /**
6793 * @brief Selects the trigger for the internal counter of batching events
6794 * between XL and gyro.[get]
6795 *
6796 * @param ctx read / write interface definitions
6797 * @param val Get the values of trig_counter_bdr
6798 * in reg COUNTER_BDR_REG1
6799 * @retval interface status (MANDATORY: return 0 -> no Error)
6800 *
6801 */
lsm6dso_fifo_cnt_event_batch_get(stmdev_ctx_t * ctx,lsm6dso_trig_counter_bdr_t * val)6802 int32_t lsm6dso_fifo_cnt_event_batch_get(stmdev_ctx_t *ctx,
6803 lsm6dso_trig_counter_bdr_t *val)
6804 {
6805 lsm6dso_counter_bdr_reg1_t reg;
6806 int32_t ret;
6807
6808 ret = lsm6dso_read_reg(ctx, LSM6DSO_COUNTER_BDR_REG1, (uint8_t *)®, 1);
6809
6810 switch (reg.trig_counter_bdr)
6811 {
6812 case LSM6DSO_XL_BATCH_EVENT:
6813 *val = LSM6DSO_XL_BATCH_EVENT;
6814 break;
6815
6816 case LSM6DSO_GYRO_BATCH_EVENT:
6817 *val = LSM6DSO_GYRO_BATCH_EVENT;
6818 break;
6819
6820 default:
6821 *val = LSM6DSO_XL_BATCH_EVENT;
6822 break;
6823 }
6824
6825 return ret;
6826 }
6827
6828 /**
6829 * @brief Resets the internal counter of batching vents for a single sensor.
6830 * This bit is automatically reset to zero if it was set to '1'.[set]
6831 *
6832 * @param ctx read / write interface definitions
6833 * @param val change the values of rst_counter_bdr in
6834 * reg COUNTER_BDR_REG1
6835 * @retval interface status (MANDATORY: return 0 -> no Error)
6836 *
6837 */
lsm6dso_rst_batch_counter_set(stmdev_ctx_t * ctx,uint8_t val)6838 int32_t lsm6dso_rst_batch_counter_set(stmdev_ctx_t *ctx, uint8_t val)
6839 {
6840 lsm6dso_counter_bdr_reg1_t reg;
6841 int32_t ret;
6842
6843 ret = lsm6dso_read_reg(ctx, LSM6DSO_COUNTER_BDR_REG1, (uint8_t *)®, 1);
6844
6845 if (ret == 0)
6846 {
6847 reg.rst_counter_bdr = val;
6848 ret = lsm6dso_write_reg(ctx, LSM6DSO_COUNTER_BDR_REG1,
6849 (uint8_t *)®, 1);
6850 }
6851
6852 return ret;
6853 }
6854
6855 /**
6856 * @brief Resets the internal counter of batching events for a single sensor.
6857 * This bit is automatically reset to zero if it was set to '1'.[get]
6858 *
6859 * @param ctx read / write interface definitions
6860 * @param val Get the values of rst_counter_bdr in
6861 * reg COUNTER_BDR_REG1
6862 * @retval interface status (MANDATORY: return 0 -> no Error)
6863 *
6864 */
lsm6dso_rst_batch_counter_get(stmdev_ctx_t * ctx,uint8_t * val)6865 int32_t lsm6dso_rst_batch_counter_get(stmdev_ctx_t *ctx, uint8_t *val)
6866 {
6867 lsm6dso_counter_bdr_reg1_t reg;
6868 int32_t ret;
6869
6870 ret = lsm6dso_read_reg(ctx, LSM6DSO_COUNTER_BDR_REG1, (uint8_t *)®, 1);
6871 *val = reg.rst_counter_bdr;
6872
6873 return ret;
6874 }
6875
6876 /**
6877 * @brief Batch data rate counter.[set]
6878 *
6879 * @param ctx read / write interface definitions
6880 * @param val change the values of cnt_bdr_th in
6881 * reg COUNTER_BDR_REG2 and COUNTER_BDR_REG1.
6882 * @retval interface status (MANDATORY: return 0 -> no Error)
6883 *
6884 */
lsm6dso_batch_counter_threshold_set(stmdev_ctx_t * ctx,uint16_t val)6885 int32_t lsm6dso_batch_counter_threshold_set(stmdev_ctx_t *ctx,
6886 uint16_t val)
6887 {
6888 lsm6dso_counter_bdr_reg1_t counter_bdr_reg1;
6889 lsm6dso_counter_bdr_reg2_t counter_bdr_reg2;
6890 int32_t ret;
6891
6892 ret = lsm6dso_read_reg(ctx, LSM6DSO_COUNTER_BDR_REG1,
6893 (uint8_t *)&counter_bdr_reg1, 1);
6894
6895 if (ret == 0)
6896 {
6897 counter_bdr_reg2.cnt_bdr_th = 0x00FFU & (uint8_t)val;
6898 counter_bdr_reg1.cnt_bdr_th = (uint8_t)(0x0700U & val) >> 8;
6899 ret = lsm6dso_write_reg(ctx, LSM6DSO_COUNTER_BDR_REG1,
6900 (uint8_t *)&counter_bdr_reg1, 1);
6901 }
6902
6903 if (ret == 0)
6904 {
6905 ret = lsm6dso_write_reg(ctx, LSM6DSO_COUNTER_BDR_REG2,
6906 (uint8_t *)&counter_bdr_reg2, 1);
6907 }
6908
6909 return ret;
6910 }
6911
6912 /**
6913 * @brief Batch data rate counter.[get]
6914 *
6915 * @param ctx read / write interface definitions
6916 * @param val Get the values of cnt_bdr_th in
6917 * reg COUNTER_BDR_REG2 and COUNTER_BDR_REG1.
6918 * @retval interface status (MANDATORY: return 0 -> no Error)
6919 *
6920 */
lsm6dso_batch_counter_threshold_get(stmdev_ctx_t * ctx,uint16_t * val)6921 int32_t lsm6dso_batch_counter_threshold_get(stmdev_ctx_t *ctx,
6922 uint16_t *val)
6923 {
6924 lsm6dso_counter_bdr_reg1_t counter_bdr_reg1;
6925 lsm6dso_counter_bdr_reg2_t counter_bdr_reg2;
6926 int32_t ret;
6927
6928 ret = lsm6dso_read_reg(ctx, LSM6DSO_COUNTER_BDR_REG1,
6929 (uint8_t *)&counter_bdr_reg1, 1);
6930
6931 if (ret == 0)
6932 {
6933 ret = lsm6dso_read_reg(ctx, LSM6DSO_COUNTER_BDR_REG2,
6934 (uint8_t *)&counter_bdr_reg2, 1);
6935 *val = ((uint16_t)counter_bdr_reg1.cnt_bdr_th << 8)
6936 + (uint16_t)counter_bdr_reg2.cnt_bdr_th;
6937 }
6938
6939 return ret;
6940 }
6941
6942 /**
6943 * @brief Number of unread sensor data(TAG + 6 bytes) stored in FIFO.[get]
6944 *
6945 * @param ctx read / write interface definitions
6946 * @param val Get the values of diff_fifo in reg FIFO_STATUS1
6947 * @retval interface status (MANDATORY: return 0 -> no Error)
6948 *
6949 */
lsm6dso_fifo_data_level_get(stmdev_ctx_t * ctx,uint16_t * val)6950 int32_t lsm6dso_fifo_data_level_get(stmdev_ctx_t *ctx, uint16_t *val)
6951 {
6952 lsm6dso_fifo_status1_t fifo_status1;
6953 lsm6dso_fifo_status2_t fifo_status2;
6954 int32_t ret;
6955
6956 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS1,
6957 (uint8_t *)&fifo_status1, 1);
6958
6959 if (ret == 0)
6960 {
6961 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS2,
6962 (uint8_t *)&fifo_status2, 1);
6963 *val = ((uint16_t)fifo_status2.diff_fifo << 8) +
6964 (uint16_t)fifo_status1.diff_fifo;
6965 }
6966
6967 return ret;
6968 }
6969
6970 /**
6971 * @brief FIFO status.[get]
6972 *
6973 * @param ctx read / write interface definitions
6974 * @param val registers FIFO_STATUS2
6975 * @retval interface status (MANDATORY: return 0 -> no Error)
6976 *
6977 */
lsm6dso_fifo_status_get(stmdev_ctx_t * ctx,lsm6dso_fifo_status2_t * val)6978 int32_t lsm6dso_fifo_status_get(stmdev_ctx_t *ctx,
6979 lsm6dso_fifo_status2_t *val)
6980 {
6981 int32_t ret;
6982
6983 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS2, (uint8_t *) val, 1);
6984
6985 return ret;
6986 }
6987
6988 /**
6989 * @brief Smart FIFO full status.[get]
6990 *
6991 * @param ctx read / write interface definitions
6992 * @param val Get the values of fifo_full_ia in reg FIFO_STATUS2
6993 * @retval interface status (MANDATORY: return 0 -> no Error)
6994 *
6995 */
lsm6dso_fifo_full_flag_get(stmdev_ctx_t * ctx,uint8_t * val)6996 int32_t lsm6dso_fifo_full_flag_get(stmdev_ctx_t *ctx, uint8_t *val)
6997 {
6998 lsm6dso_fifo_status2_t reg;
6999 int32_t ret;
7000
7001 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS2, (uint8_t *)®, 1);
7002 *val = reg.fifo_full_ia;
7003
7004 return ret;
7005 }
7006
7007 /**
7008 * @brief FIFO overrun status.[get]
7009 *
7010 * @param ctx read / write interface definitions
7011 * @param val Get the values of fifo_over_run_latched in
7012 * reg FIFO_STATUS2
7013 * @retval interface status (MANDATORY: return 0 -> no Error)
7014 *
7015 */
lsm6dso_fifo_ovr_flag_get(stmdev_ctx_t * ctx,uint8_t * val)7016 int32_t lsm6dso_fifo_ovr_flag_get(stmdev_ctx_t *ctx, uint8_t *val)
7017 {
7018 lsm6dso_fifo_status2_t reg;
7019 int32_t ret;
7020
7021 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS2, (uint8_t *)®, 1);
7022 *val = reg.fifo_ovr_ia;
7023
7024 return ret;
7025 }
7026
7027 /**
7028 * @brief FIFO watermark status.[get]
7029 *
7030 * @param ctx read / write interface definitions
7031 * @param val Get the values of fifo_wtm_ia in reg FIFO_STATUS2
7032 * @retval interface status (MANDATORY: return 0 -> no Error)
7033 *
7034 */
lsm6dso_fifo_wtm_flag_get(stmdev_ctx_t * ctx,uint8_t * val)7035 int32_t lsm6dso_fifo_wtm_flag_get(stmdev_ctx_t *ctx, uint8_t *val)
7036 {
7037 lsm6dso_fifo_status2_t reg;
7038 int32_t ret;
7039
7040 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS2, (uint8_t *)®, 1);
7041 *val = reg.fifo_wtm_ia;
7042
7043 return ret;
7044 }
7045
7046 /**
7047 * @brief Identifies the sensor in FIFO_DATA_OUT.[get]
7048 *
7049 * @param ctx read / write interface definitions
7050 * @param val Get the values of tag_sensor in reg FIFO_DATA_OUT_TAG
7051 * @retval interface status (MANDATORY: return 0 -> no Error)
7052 *
7053 */
lsm6dso_fifo_sensor_tag_get(stmdev_ctx_t * ctx,lsm6dso_fifo_tag_t * val)7054 int32_t lsm6dso_fifo_sensor_tag_get(stmdev_ctx_t *ctx,
7055 lsm6dso_fifo_tag_t *val)
7056 {
7057 lsm6dso_fifo_data_out_tag_t reg;
7058 int32_t ret;
7059
7060 ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_DATA_OUT_TAG,
7061 (uint8_t *)®, 1);
7062
7063 switch (reg.tag_sensor)
7064 {
7065 case LSM6DSO_GYRO_NC_TAG:
7066 *val = LSM6DSO_GYRO_NC_TAG;
7067 break;
7068
7069 case LSM6DSO_XL_NC_TAG:
7070 *val = LSM6DSO_XL_NC_TAG;
7071 break;
7072
7073 case LSM6DSO_TEMPERATURE_TAG:
7074 *val = LSM6DSO_TEMPERATURE_TAG;
7075 break;
7076
7077 case LSM6DSO_TIMESTAMP_TAG:
7078 *val = LSM6DSO_TIMESTAMP_TAG;
7079 break;
7080
7081 case LSM6DSO_CFG_CHANGE_TAG:
7082 *val = LSM6DSO_CFG_CHANGE_TAG;
7083 break;
7084
7085 case LSM6DSO_XL_NC_T_2_TAG:
7086 *val = LSM6DSO_XL_NC_T_2_TAG;
7087 break;
7088
7089 case LSM6DSO_XL_NC_T_1_TAG:
7090 *val = LSM6DSO_XL_NC_T_1_TAG;
7091 break;
7092
7093 case LSM6DSO_XL_2XC_TAG:
7094 *val = LSM6DSO_XL_2XC_TAG;
7095 break;
7096
7097 case LSM6DSO_XL_3XC_TAG:
7098 *val = LSM6DSO_XL_3XC_TAG;
7099 break;
7100
7101 case LSM6DSO_GYRO_NC_T_2_TAG:
7102 *val = LSM6DSO_GYRO_NC_T_2_TAG;
7103 break;
7104
7105 case LSM6DSO_GYRO_NC_T_1_TAG:
7106 *val = LSM6DSO_GYRO_NC_T_1_TAG;
7107 break;
7108
7109 case LSM6DSO_GYRO_2XC_TAG:
7110 *val = LSM6DSO_GYRO_2XC_TAG;
7111 break;
7112
7113 case LSM6DSO_GYRO_3XC_TAG:
7114 *val = LSM6DSO_GYRO_3XC_TAG;
7115 break;
7116
7117 case LSM6DSO_SENSORHUB_SLAVE0_TAG:
7118 *val = LSM6DSO_SENSORHUB_SLAVE0_TAG;
7119 break;
7120
7121 case LSM6DSO_SENSORHUB_SLAVE1_TAG:
7122 *val = LSM6DSO_SENSORHUB_SLAVE1_TAG;
7123 break;
7124
7125 case LSM6DSO_SENSORHUB_SLAVE2_TAG:
7126 *val = LSM6DSO_SENSORHUB_SLAVE2_TAG;
7127 break;
7128
7129 case LSM6DSO_SENSORHUB_SLAVE3_TAG:
7130 *val = LSM6DSO_SENSORHUB_SLAVE3_TAG;
7131 break;
7132
7133 case LSM6DSO_STEP_COUNTER_TAG:
7134 *val = LSM6DSO_STEP_COUNTER_TAG;
7135 break;
7136
7137 case LSM6DSO_GAME_ROTATION_TAG:
7138 *val = LSM6DSO_GAME_ROTATION_TAG;
7139 break;
7140
7141 case LSM6DSO_GEOMAG_ROTATION_TAG:
7142 *val = LSM6DSO_GEOMAG_ROTATION_TAG;
7143 break;
7144
7145 case LSM6DSO_ROTATION_TAG:
7146 *val = LSM6DSO_ROTATION_TAG;
7147 break;
7148
7149 case LSM6DSO_SENSORHUB_NACK_TAG:
7150 *val = LSM6DSO_SENSORHUB_NACK_TAG;
7151 break;
7152
7153 default:
7154 *val = LSM6DSO_GYRO_NC_TAG;
7155 break;
7156 }
7157
7158 return ret;
7159 }
7160
7161 /**
7162 * @brief : Enable FIFO batching of pedometer embedded
7163 * function values.[set]
7164 *
7165 * @param ctx read / write interface definitions
7166 * @param val change the values of gbias_fifo_en in
7167 * reg LSM6DSO_EMB_FUNC_FIFO_CFG
7168 * @retval interface status (MANDATORY: return 0 -> no Error)
7169 *
7170 */
lsm6dso_fifo_pedo_batch_set(stmdev_ctx_t * ctx,uint8_t val)7171 int32_t lsm6dso_fifo_pedo_batch_set(stmdev_ctx_t *ctx, uint8_t val)
7172 {
7173 lsm6dso_emb_func_fifo_cfg_t reg;
7174 int32_t ret;
7175
7176 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
7177
7178 if (ret == 0)
7179 {
7180 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_FIFO_CFG,
7181 (uint8_t *)®, 1);
7182 }
7183
7184 if (ret == 0)
7185 {
7186 reg.pedo_fifo_en = val;
7187 ret = lsm6dso_write_reg(ctx, LSM6DSO_EMB_FUNC_FIFO_CFG,
7188 (uint8_t *)®, 1);
7189 }
7190
7191 if (ret == 0)
7192 {
7193 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
7194 }
7195
7196 return ret;
7197 }
7198
7199 /**
7200 * @brief Enable FIFO batching of pedometer embedded function values.[get]
7201 *
7202 * @param ctx read / write interface definitions
7203 * @param val Get the values of pedo_fifo_en in
7204 * reg LSM6DSO_EMB_FUNC_FIFO_CFG
7205 * @retval interface status (MANDATORY: return 0 -> no Error)
7206 *
7207 */
lsm6dso_fifo_pedo_batch_get(stmdev_ctx_t * ctx,uint8_t * val)7208 int32_t lsm6dso_fifo_pedo_batch_get(stmdev_ctx_t *ctx, uint8_t *val)
7209 {
7210 lsm6dso_emb_func_fifo_cfg_t reg;
7211 int32_t ret;
7212
7213 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
7214
7215 if (ret == 0)
7216 {
7217 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_FIFO_CFG,
7218 (uint8_t *)®, 1);
7219 }
7220
7221 if (ret == 0)
7222 {
7223 *val = reg.pedo_fifo_en;
7224 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
7225 }
7226
7227 return ret;
7228 }
7229
7230 /**
7231 * @brief Enable FIFO batching data of first slave.[set]
7232 *
7233 * @param ctx read / write interface definitions
7234 * @param val change the values of batch_ext_sens_0_en in
7235 * reg SLV0_CONFIG
7236 * @retval interface status (MANDATORY: return 0 -> no Error)
7237 *
7238 */
lsm6dso_sh_batch_slave_0_set(stmdev_ctx_t * ctx,uint8_t val)7239 int32_t lsm6dso_sh_batch_slave_0_set(stmdev_ctx_t *ctx, uint8_t val)
7240 {
7241 lsm6dso_slv0_config_t reg;
7242 int32_t ret;
7243
7244 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
7245
7246 if (ret == 0)
7247 {
7248 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV0_CONFIG, (uint8_t *)®, 1);
7249 }
7250
7251 if (ret == 0)
7252 {
7253 reg.batch_ext_sens_0_en = val;
7254 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV0_CONFIG, (uint8_t *)®, 1);
7255 }
7256
7257 if (ret == 0)
7258 {
7259 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
7260 }
7261
7262 return ret;
7263 }
7264
7265 /**
7266 * @brief Enable FIFO batching data of first slave.[get]
7267 *
7268 * @param ctx read / write interface definitions
7269 * @param val Get the values of batch_ext_sens_0_en in
7270 * reg SLV0_CONFIG
7271 * @retval interface status (MANDATORY: return 0 -> no Error)
7272 *
7273 */
lsm6dso_sh_batch_slave_0_get(stmdev_ctx_t * ctx,uint8_t * val)7274 int32_t lsm6dso_sh_batch_slave_0_get(stmdev_ctx_t *ctx, uint8_t *val)
7275 {
7276 lsm6dso_slv0_config_t reg;
7277 int32_t ret;
7278
7279 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
7280
7281 if (ret == 0)
7282 {
7283 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV0_CONFIG, (uint8_t *)®, 1);
7284 }
7285
7286 if (ret == 0)
7287 {
7288 *val = reg.batch_ext_sens_0_en;
7289 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
7290 }
7291
7292 return ret;
7293 }
7294
7295 /**
7296 * @brief Enable FIFO batching data of second slave.[set]
7297 *
7298 * @param ctx read / write interface definitions
7299 * @param val change the values of batch_ext_sens_1_en in
7300 * reg SLV1_CONFIG
7301 * @retval interface status (MANDATORY: return 0 -> no Error)
7302 *
7303 */
lsm6dso_sh_batch_slave_1_set(stmdev_ctx_t * ctx,uint8_t val)7304 int32_t lsm6dso_sh_batch_slave_1_set(stmdev_ctx_t *ctx, uint8_t val)
7305 {
7306 lsm6dso_slv1_config_t reg;
7307 int32_t ret;
7308
7309 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
7310
7311 if (ret == 0)
7312 {
7313 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV1_CONFIG, (uint8_t *)®, 1);
7314 }
7315
7316 if (ret == 0)
7317 {
7318 reg.batch_ext_sens_1_en = val;
7319 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV1_CONFIG, (uint8_t *)®, 1);
7320 }
7321
7322 if (ret == 0)
7323 {
7324 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
7325 }
7326
7327 return ret;
7328 }
7329
7330 /**
7331 * @brief Enable FIFO batching data of second slave.[get]
7332 *
7333 * @param ctx read / write interface definitions
7334 * @param val Get the values of batch_ext_sens_1_en in
7335 * reg SLV1_CONFIG
7336 * @retval interface status (MANDATORY: return 0 -> no Error)
7337 *
7338 */
lsm6dso_sh_batch_slave_1_get(stmdev_ctx_t * ctx,uint8_t * val)7339 int32_t lsm6dso_sh_batch_slave_1_get(stmdev_ctx_t *ctx, uint8_t *val)
7340 {
7341 lsm6dso_slv1_config_t reg;
7342 int32_t ret;
7343
7344 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
7345
7346 if (ret == 0)
7347 {
7348 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV1_CONFIG, (uint8_t *)®, 1);
7349 *val = reg.batch_ext_sens_1_en;
7350 }
7351
7352 if (ret == 0)
7353 {
7354 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
7355 }
7356
7357 return ret;
7358 }
7359
7360 /**
7361 * @brief Enable FIFO batching data of third slave.[set]
7362 *
7363 * @param ctx read / write interface definitions
7364 * @param val change the values of batch_ext_sens_2_en in
7365 * reg SLV2_CONFIG
7366 * @retval interface status (MANDATORY: return 0 -> no Error)
7367 *
7368 */
lsm6dso_sh_batch_slave_2_set(stmdev_ctx_t * ctx,uint8_t val)7369 int32_t lsm6dso_sh_batch_slave_2_set(stmdev_ctx_t *ctx, uint8_t val)
7370 {
7371 lsm6dso_slv2_config_t reg;
7372 int32_t ret;
7373
7374 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
7375
7376 if (ret == 0)
7377 {
7378 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV2_CONFIG, (uint8_t *)®, 1);
7379 }
7380
7381 if (ret == 0)
7382 {
7383 reg.batch_ext_sens_2_en = val;
7384 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV2_CONFIG, (uint8_t *)®, 1);
7385 }
7386
7387 if (ret == 0)
7388 {
7389 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
7390 }
7391
7392 return ret;
7393 }
7394
7395 /**
7396 * @brief Enable FIFO batching data of third slave.[get]
7397 *
7398 * @param ctx read / write interface definitions
7399 * @param val Get the values of batch_ext_sens_2_en in
7400 * reg SLV2_CONFIG
7401 * @retval interface status (MANDATORY: return 0 -> no Error)
7402 *
7403 */
lsm6dso_sh_batch_slave_2_get(stmdev_ctx_t * ctx,uint8_t * val)7404 int32_t lsm6dso_sh_batch_slave_2_get(stmdev_ctx_t *ctx, uint8_t *val)
7405 {
7406 lsm6dso_slv2_config_t reg;
7407 int32_t ret;
7408
7409 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
7410
7411 if (ret == 0)
7412 {
7413 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV2_CONFIG, (uint8_t *)®, 1);
7414 }
7415
7416 if (ret == 0)
7417 {
7418 *val = reg.batch_ext_sens_2_en;
7419 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
7420 }
7421
7422 return ret;
7423 }
7424
7425 /**
7426 * @brief Enable FIFO batching data of fourth slave.[set]
7427 *
7428 * @param ctx read / write interface definitions
7429 * @param val change the values of batch_ext_sens_3_en
7430 * in reg SLV3_CONFIG
7431 * @retval interface status (MANDATORY: return 0 -> no Error)
7432 *
7433 */
lsm6dso_sh_batch_slave_3_set(stmdev_ctx_t * ctx,uint8_t val)7434 int32_t lsm6dso_sh_batch_slave_3_set(stmdev_ctx_t *ctx, uint8_t val)
7435 {
7436 lsm6dso_slv3_config_t reg;
7437 int32_t ret;
7438
7439 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
7440
7441 if (ret == 0)
7442 {
7443 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV3_CONFIG, (uint8_t *)®, 1);
7444 }
7445
7446 if (ret == 0)
7447 {
7448 reg.batch_ext_sens_3_en = val;
7449 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV3_CONFIG, (uint8_t *)®, 1);
7450 }
7451
7452 if (ret == 0)
7453 {
7454 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
7455 }
7456
7457 return ret;
7458 }
7459
7460 /**
7461 * @brief Enable FIFO batching data of fourth slave.[get]
7462 *
7463 * @param ctx read / write interface definitions
7464 * @param val Get the values of batch_ext_sens_3_en in
7465 * reg SLV3_CONFIG
7466 * @retval interface status (MANDATORY: return 0 -> no Error)
7467 *
7468 */
lsm6dso_sh_batch_slave_3_get(stmdev_ctx_t * ctx,uint8_t * val)7469 int32_t lsm6dso_sh_batch_slave_3_get(stmdev_ctx_t *ctx, uint8_t *val)
7470 {
7471 lsm6dso_slv3_config_t reg;
7472 int32_t ret;
7473
7474 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
7475
7476 if (ret == 0)
7477 {
7478 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV3_CONFIG, (uint8_t *)®, 1);
7479 }
7480
7481 if (ret == 0)
7482 {
7483 *val = reg.batch_ext_sens_3_en;
7484 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
7485 }
7486
7487 return ret;
7488 }
7489
7490 /**
7491 * @}
7492 *
7493 */
7494
7495 /**
7496 * @defgroup LSM6DSO_DEN_functionality
7497 * @brief This section groups all the functions concerning
7498 * DEN functionality.
7499 * @{
7500 *
7501 */
7502
7503 /**
7504 * @brief DEN functionality marking mode.[set]
7505 *
7506 * @param ctx read / write interface definitions
7507 * @param val change the values of den_mode in reg CTRL6_C
7508 * @retval interface status (MANDATORY: return 0 -> no Error)
7509 *
7510 */
lsm6dso_den_mode_set(stmdev_ctx_t * ctx,lsm6dso_den_mode_t val)7511 int32_t lsm6dso_den_mode_set(stmdev_ctx_t *ctx,
7512 lsm6dso_den_mode_t val)
7513 {
7514 lsm6dso_ctrl6_c_t reg;
7515 int32_t ret;
7516
7517 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL6_C, (uint8_t *)®, 1);
7518
7519 if (ret == 0)
7520 {
7521 reg.den_mode = (uint8_t)val;
7522 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL6_C, (uint8_t *)®, 1);
7523 }
7524
7525 return ret;
7526 }
7527
7528 /**
7529 * @brief DEN functionality marking mode.[get]
7530 *
7531 * @param ctx read / write interface definitions
7532 * @param val Get the values of den_mode in reg CTRL6_C
7533 * @retval interface status (MANDATORY: return 0 -> no Error)
7534 *
7535 */
lsm6dso_den_mode_get(stmdev_ctx_t * ctx,lsm6dso_den_mode_t * val)7536 int32_t lsm6dso_den_mode_get(stmdev_ctx_t *ctx,
7537 lsm6dso_den_mode_t *val)
7538 {
7539 lsm6dso_ctrl6_c_t reg;
7540 int32_t ret;
7541
7542 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL6_C, (uint8_t *)®, 1);
7543
7544 switch (reg.den_mode)
7545 {
7546 case LSM6DSO_DEN_DISABLE:
7547 *val = LSM6DSO_DEN_DISABLE;
7548 break;
7549
7550 case LSM6DSO_LEVEL_FIFO:
7551 *val = LSM6DSO_LEVEL_FIFO;
7552 break;
7553
7554 case LSM6DSO_LEVEL_LETCHED:
7555 *val = LSM6DSO_LEVEL_LETCHED;
7556 break;
7557
7558 case LSM6DSO_LEVEL_TRIGGER:
7559 *val = LSM6DSO_LEVEL_TRIGGER;
7560 break;
7561
7562 case LSM6DSO_EDGE_TRIGGER:
7563 *val = LSM6DSO_EDGE_TRIGGER;
7564 break;
7565
7566 default:
7567 *val = LSM6DSO_DEN_DISABLE;
7568 break;
7569 }
7570
7571 return ret;
7572 }
7573
7574 /**
7575 * @brief DEN active level configuration.[set]
7576 *
7577 * @param ctx read / write interface definitions
7578 * @param val change the values of den_lh in reg CTRL9_XL
7579 * @retval interface status (MANDATORY: return 0 -> no Error)
7580 *
7581 */
lsm6dso_den_polarity_set(stmdev_ctx_t * ctx,lsm6dso_den_lh_t val)7582 int32_t lsm6dso_den_polarity_set(stmdev_ctx_t *ctx,
7583 lsm6dso_den_lh_t val)
7584 {
7585 lsm6dso_ctrl9_xl_t reg;
7586 int32_t ret;
7587
7588 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7589
7590 if (ret == 0)
7591 {
7592 reg.den_lh = (uint8_t)val;
7593 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7594 }
7595
7596 return ret;
7597 }
7598
7599 /**
7600 * @brief DEN active level configuration.[get]
7601 *
7602 * @param ctx read / write interface definitions
7603 * @param val Get the values of den_lh in reg CTRL9_XL
7604 * @retval interface status (MANDATORY: return 0 -> no Error)
7605 *
7606 */
lsm6dso_den_polarity_get(stmdev_ctx_t * ctx,lsm6dso_den_lh_t * val)7607 int32_t lsm6dso_den_polarity_get(stmdev_ctx_t *ctx,
7608 lsm6dso_den_lh_t *val)
7609 {
7610 lsm6dso_ctrl9_xl_t reg;
7611 int32_t ret;
7612
7613 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7614
7615 switch (reg.den_lh)
7616 {
7617 case LSM6DSO_DEN_ACT_LOW:
7618 *val = LSM6DSO_DEN_ACT_LOW;
7619 break;
7620
7621 case LSM6DSO_DEN_ACT_HIGH:
7622 *val = LSM6DSO_DEN_ACT_HIGH;
7623 break;
7624
7625 default:
7626 *val = LSM6DSO_DEN_ACT_LOW;
7627 break;
7628 }
7629
7630 return ret;
7631 }
7632
7633 /**
7634 * @brief DEN enable.[set]
7635 *
7636 * @param ctx read / write interface definitions
7637 * @param val change the values of den_xl_g in reg CTRL9_XL
7638 * @retval interface status (MANDATORY: return 0 -> no Error)
7639 *
7640 */
lsm6dso_den_enable_set(stmdev_ctx_t * ctx,lsm6dso_den_xl_g_t val)7641 int32_t lsm6dso_den_enable_set(stmdev_ctx_t *ctx,
7642 lsm6dso_den_xl_g_t val)
7643 {
7644 lsm6dso_ctrl9_xl_t reg;
7645 int32_t ret;
7646
7647 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7648
7649 if (ret == 0)
7650 {
7651 reg.den_xl_g = (uint8_t)val;
7652 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7653 }
7654
7655 return ret;
7656 }
7657
7658 /**
7659 * @brief DEN enable.[get]
7660 *
7661 * @param ctx read / write interface definitions
7662 * @param val Get the values of den_xl_g in reg CTRL9_XL
7663 * @retval interface status (MANDATORY: return 0 -> no Error)
7664 *
7665 */
lsm6dso_den_enable_get(stmdev_ctx_t * ctx,lsm6dso_den_xl_g_t * val)7666 int32_t lsm6dso_den_enable_get(stmdev_ctx_t *ctx,
7667 lsm6dso_den_xl_g_t *val)
7668 {
7669 lsm6dso_ctrl9_xl_t reg;
7670 int32_t ret;
7671
7672 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7673
7674 switch (reg.den_xl_g)
7675 {
7676 case LSM6DSO_STAMP_IN_GY_DATA:
7677 *val = LSM6DSO_STAMP_IN_GY_DATA;
7678 break;
7679
7680 case LSM6DSO_STAMP_IN_XL_DATA:
7681 *val = LSM6DSO_STAMP_IN_XL_DATA;
7682 break;
7683
7684 case LSM6DSO_STAMP_IN_GY_XL_DATA:
7685 *val = LSM6DSO_STAMP_IN_GY_XL_DATA;
7686 break;
7687
7688 default:
7689 *val = LSM6DSO_STAMP_IN_GY_DATA;
7690 break;
7691 }
7692
7693 return ret;
7694 }
7695
7696 /**
7697 * @brief DEN value stored in LSB of X-axis.[set]
7698 *
7699 * @param ctx read / write interface definitions
7700 * @param val change the values of den_z in reg CTRL9_XL
7701 * @retval interface status (MANDATORY: return 0 -> no Error)
7702 *
7703 */
lsm6dso_den_mark_axis_x_set(stmdev_ctx_t * ctx,uint8_t val)7704 int32_t lsm6dso_den_mark_axis_x_set(stmdev_ctx_t *ctx, uint8_t val)
7705 {
7706 lsm6dso_ctrl9_xl_t reg;
7707 int32_t ret;
7708
7709 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7710
7711 if (ret == 0)
7712 {
7713 reg.den_z = val;
7714 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7715 }
7716
7717 return ret;
7718 }
7719
7720 /**
7721 * @brief DEN value stored in LSB of X-axis.[get]
7722 *
7723 * @param ctx read / write interface definitions
7724 * @param val Get the values of den_z in reg CTRL9_XL
7725 * @retval interface status (MANDATORY: return 0 -> no Error)
7726 *
7727 */
lsm6dso_den_mark_axis_x_get(stmdev_ctx_t * ctx,uint8_t * val)7728 int32_t lsm6dso_den_mark_axis_x_get(stmdev_ctx_t *ctx, uint8_t *val)
7729 {
7730 lsm6dso_ctrl9_xl_t reg;
7731 int32_t ret;
7732
7733 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7734 *val = reg.den_z;
7735
7736 return ret;
7737 }
7738
7739 /**
7740 * @brief DEN value stored in LSB of Y-axis.[set]
7741 *
7742 * @param ctx read / write interface definitions
7743 * @param val change the values of den_y in reg CTRL9_XL
7744 * @retval interface status (MANDATORY: return 0 -> no Error)
7745 *
7746 */
lsm6dso_den_mark_axis_y_set(stmdev_ctx_t * ctx,uint8_t val)7747 int32_t lsm6dso_den_mark_axis_y_set(stmdev_ctx_t *ctx, uint8_t val)
7748 {
7749 lsm6dso_ctrl9_xl_t reg;
7750 int32_t ret;
7751
7752 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7753
7754 if (ret == 0)
7755 {
7756 reg.den_y = val;
7757 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7758 }
7759
7760 return ret;
7761 }
7762
7763 /**
7764 * @brief DEN value stored in LSB of Y-axis.[get]
7765 *
7766 * @param ctx read / write interface definitions
7767 * @param val Get the values of den_y in reg CTRL9_XL
7768 * @retval interface status (MANDATORY: return 0 -> no Error)
7769 *
7770 */
lsm6dso_den_mark_axis_y_get(stmdev_ctx_t * ctx,uint8_t * val)7771 int32_t lsm6dso_den_mark_axis_y_get(stmdev_ctx_t *ctx, uint8_t *val)
7772 {
7773 lsm6dso_ctrl9_xl_t reg;
7774 int32_t ret;
7775
7776 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7777 *val = reg.den_y;
7778
7779 return ret;
7780 }
7781
7782 /**
7783 * @brief DEN value stored in LSB of Z-axis.[set]
7784 *
7785 * @param ctx read / write interface definitions
7786 * @param val change the values of den_x in reg CTRL9_XL
7787 * @retval interface status (MANDATORY: return 0 -> no Error)
7788 *
7789 */
lsm6dso_den_mark_axis_z_set(stmdev_ctx_t * ctx,uint8_t val)7790 int32_t lsm6dso_den_mark_axis_z_set(stmdev_ctx_t *ctx, uint8_t val)
7791 {
7792 lsm6dso_ctrl9_xl_t reg;
7793 int32_t ret;
7794
7795 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7796
7797 if (ret == 0)
7798 {
7799 reg.den_x = val;
7800 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7801 }
7802
7803 return ret;
7804 }
7805
7806 /**
7807 * @brief DEN value stored in LSB of Z-axis.[get]
7808 *
7809 * @param ctx read / write interface definitions
7810 * @param val Get the values of den_x in reg CTRL9_XL
7811 * @retval interface status (MANDATORY: return 0 -> no Error)
7812 *
7813 */
lsm6dso_den_mark_axis_z_get(stmdev_ctx_t * ctx,uint8_t * val)7814 int32_t lsm6dso_den_mark_axis_z_get(stmdev_ctx_t *ctx, uint8_t *val)
7815 {
7816 lsm6dso_ctrl9_xl_t reg;
7817 int32_t ret;
7818
7819 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL, (uint8_t *)®, 1);
7820 *val = reg.den_x;
7821
7822 return ret;
7823 }
7824
7825 /**
7826 * @}
7827 *
7828 */
7829
7830 /**
7831 * @defgroup LSM6DSO_Pedometer
7832 * @brief This section groups all the functions that manage pedometer.
7833 * @{
7834 *
7835 */
7836
7837 /**
7838 * @brief Enable pedometer algorithm.[set]
7839 *
7840 * @param ctx read / write interface definitions
7841 * @param val turn on and configure pedometer
7842 * @retval interface status (MANDATORY: return 0 -> no Error)
7843 *
7844 */
lsm6dso_pedo_sens_set(stmdev_ctx_t * ctx,lsm6dso_pedo_md_t val)7845 int32_t lsm6dso_pedo_sens_set(stmdev_ctx_t *ctx,
7846 lsm6dso_pedo_md_t val)
7847 {
7848 lsm6dso_pedo_cmd_reg_t pedo_cmd_reg;
7849 int32_t ret;
7850
7851 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_PEDO_CMD_REG,
7852 (uint8_t *)&pedo_cmd_reg);
7853
7854 if (ret == 0)
7855 {
7856 pedo_cmd_reg.fp_rejection_en = ((uint8_t)val & 0x10U) >> 4;
7857 pedo_cmd_reg.ad_det_en = ((uint8_t)val & 0x20U) >> 5;
7858 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_PEDO_CMD_REG,
7859 (uint8_t *)&pedo_cmd_reg);
7860 }
7861
7862 return ret;
7863 }
7864
7865 /**
7866 * @brief Enable pedometer algorithm.[get]
7867 *
7868 * @param ctx read / write interface definitions
7869 * @param val turn on and configure pedometer
7870 * @retval interface status (MANDATORY: return 0 -> no Error)
7871 *
7872 */
lsm6dso_pedo_sens_get(stmdev_ctx_t * ctx,lsm6dso_pedo_md_t * val)7873 int32_t lsm6dso_pedo_sens_get(stmdev_ctx_t *ctx,
7874 lsm6dso_pedo_md_t *val)
7875 {
7876 lsm6dso_pedo_cmd_reg_t pedo_cmd_reg;
7877 int32_t ret;
7878
7879 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_PEDO_CMD_REG,
7880 (uint8_t *)&pedo_cmd_reg);
7881
7882 switch ((pedo_cmd_reg.ad_det_en << 5) | (pedo_cmd_reg.fp_rejection_en
7883 << 4))
7884 {
7885 case LSM6DSO_PEDO_BASE_MODE:
7886 *val = LSM6DSO_PEDO_BASE_MODE;
7887 break;
7888
7889 case LSM6DSO_FALSE_STEP_REJ:
7890 *val = LSM6DSO_FALSE_STEP_REJ;
7891 break;
7892
7893 case LSM6DSO_FALSE_STEP_REJ_ADV_MODE:
7894 *val = LSM6DSO_FALSE_STEP_REJ_ADV_MODE;
7895 break;
7896
7897 default:
7898 *val = LSM6DSO_PEDO_BASE_MODE;
7899 break;
7900 }
7901
7902 return ret;
7903 }
7904
7905 /**
7906 * @brief Interrupt status bit for step detection.[get]
7907 *
7908 * @param ctx read / write interface definitions
7909 * @param val Get the values of is_step_det in reg EMB_FUNC_STATUS
7910 * @retval interface status (MANDATORY: return 0 -> no Error)
7911 *
7912 */
lsm6dso_pedo_step_detect_get(stmdev_ctx_t * ctx,uint8_t * val)7913 int32_t lsm6dso_pedo_step_detect_get(stmdev_ctx_t *ctx, uint8_t *val)
7914 {
7915 lsm6dso_emb_func_status_t reg;
7916 int32_t ret;
7917
7918 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
7919
7920 if (ret == 0)
7921 {
7922 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_STATUS, (uint8_t *)®, 1);
7923 }
7924
7925 if (ret == 0)
7926 {
7927 *val = reg.is_step_det;
7928 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
7929 }
7930
7931 return ret;
7932 }
7933
7934 /**
7935 * @brief Pedometer debounce configuration register (r/w).[set]
7936 *
7937 * @param ctx read / write interface definitions
7938 * @param buff buffer that contains data to write
7939 * @retval interface status (MANDATORY: return 0 -> no Error)
7940 *
7941 */
lsm6dso_pedo_debounce_steps_set(stmdev_ctx_t * ctx,uint8_t * buff)7942 int32_t lsm6dso_pedo_debounce_steps_set(stmdev_ctx_t *ctx,
7943 uint8_t *buff)
7944 {
7945 int32_t ret;
7946
7947 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_PEDO_DEB_STEPS_CONF,
7948 buff);
7949
7950 return ret;
7951 }
7952
7953 /**
7954 * @brief Pedometer debounce configuration register (r/w).[get]
7955 *
7956 * @param ctx read / write interface definitions
7957 * @param buff buffer that stores data read
7958 * @retval interface status (MANDATORY: return 0 -> no Error)
7959 *
7960 */
lsm6dso_pedo_debounce_steps_get(stmdev_ctx_t * ctx,uint8_t * buff)7961 int32_t lsm6dso_pedo_debounce_steps_get(stmdev_ctx_t *ctx,
7962 uint8_t *buff)
7963 {
7964 int32_t ret;
7965
7966 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_PEDO_DEB_STEPS_CONF, buff);
7967
7968 return ret;
7969 }
7970
7971 /**
7972 * @brief Time period register for step detection on delta time (r/w).[set]
7973 *
7974 * @param ctx read / write interface definitions
7975 * @param buff buffer that contains data to write
7976 * @retval interface status (MANDATORY: return 0 -> no Error)
7977 *
7978 */
lsm6dso_pedo_steps_period_set(stmdev_ctx_t * ctx,uint16_t val)7979 int32_t lsm6dso_pedo_steps_period_set(stmdev_ctx_t *ctx, uint16_t val)
7980 {
7981 uint8_t buff[2];
7982 int32_t ret;
7983
7984 buff[1] = (uint8_t)(val / 256U);
7985 buff[0] = (uint8_t)(val - (buff[1] * 256U));
7986 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_PEDO_SC_DELTAT_L,
7987 &buff[0]);
7988
7989 if (ret == 0)
7990 {
7991 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_PEDO_SC_DELTAT_H,
7992 &buff[1]);
7993 }
7994
7995 return ret;
7996 }
7997
7998 /**
7999 * @brief Time period register for step detection on delta time (r/w).[get]
8000 *
8001 * @param ctx read / write interface definitions
8002 * @param buff buffer that stores data read
8003 * @retval interface status (MANDATORY: return 0 -> no Error)
8004 *
8005 */
lsm6dso_pedo_steps_period_get(stmdev_ctx_t * ctx,uint16_t * val)8006 int32_t lsm6dso_pedo_steps_period_get(stmdev_ctx_t *ctx,
8007 uint16_t *val)
8008 {
8009 uint8_t buff[2];
8010 int32_t ret;
8011
8012 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_PEDO_SC_DELTAT_L,
8013 &buff[0]);
8014
8015 if (ret == 0)
8016 {
8017 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_PEDO_SC_DELTAT_H,
8018 &buff[1]);
8019 *val = buff[1];
8020 *val = (*val * 256U) + buff[0];
8021 }
8022
8023 return ret;
8024 }
8025
8026 /**
8027 * @brief Set when user wants to generate interrupt on count overflow
8028 * event/every step.[set]
8029 *
8030 * @param ctx read / write interface definitions
8031 * @param val change the values of carry_count_en in reg PEDO_CMD_REG
8032 * @retval interface status (MANDATORY: return 0 -> no Error)
8033 *
8034 */
lsm6dso_pedo_int_mode_set(stmdev_ctx_t * ctx,lsm6dso_carry_count_en_t val)8035 int32_t lsm6dso_pedo_int_mode_set(stmdev_ctx_t *ctx,
8036 lsm6dso_carry_count_en_t val)
8037 {
8038 lsm6dso_pedo_cmd_reg_t reg;
8039 int32_t ret;
8040
8041 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_PEDO_CMD_REG,
8042 (uint8_t *)®);
8043
8044 if (ret == 0)
8045 {
8046 reg.carry_count_en = (uint8_t)val;
8047 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_PEDO_CMD_REG,
8048 (uint8_t *)®);
8049 }
8050
8051 return ret;
8052 }
8053
8054 /**
8055 * @brief Set when user wants to generate interrupt on count overflow
8056 * event/every step.[get]
8057 *
8058 * @param ctx read / write interface definitions
8059 * @param val Get the values of carry_count_en in reg PEDO_CMD_REG
8060 * @retval interface status (MANDATORY: return 0 -> no Error)
8061 *
8062 */
lsm6dso_pedo_int_mode_get(stmdev_ctx_t * ctx,lsm6dso_carry_count_en_t * val)8063 int32_t lsm6dso_pedo_int_mode_get(stmdev_ctx_t *ctx,
8064 lsm6dso_carry_count_en_t *val)
8065 {
8066 lsm6dso_pedo_cmd_reg_t reg;
8067 int32_t ret;
8068
8069 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_PEDO_CMD_REG,
8070 (uint8_t *)®);
8071
8072 switch (reg.carry_count_en)
8073 {
8074 case LSM6DSO_EVERY_STEP:
8075 *val = LSM6DSO_EVERY_STEP;
8076 break;
8077
8078 case LSM6DSO_COUNT_OVERFLOW:
8079 *val = LSM6DSO_COUNT_OVERFLOW;
8080 break;
8081
8082 default:
8083 *val = LSM6DSO_EVERY_STEP;
8084 break;
8085 }
8086
8087 return ret;
8088 }
8089
8090 /**
8091 * @}
8092 *
8093 */
8094
8095 /**
8096 * @defgroup LSM6DSO_significant_motion
8097 * @brief This section groups all the functions that manage the
8098 * significant motion detection.
8099 * @{
8100 *
8101 */
8102
8103 /**
8104 * @brief Interrupt status bit for significant motion detection.[get]
8105 *
8106 * @param ctx read / write interface definitions
8107 * @param val Get the values of is_sigmot in reg EMB_FUNC_STATUS
8108 * @retval interface status (MANDATORY: return 0 -> no Error)
8109 *
8110 */
lsm6dso_motion_flag_data_ready_get(stmdev_ctx_t * ctx,uint8_t * val)8111 int32_t lsm6dso_motion_flag_data_ready_get(stmdev_ctx_t *ctx,
8112 uint8_t *val)
8113 {
8114 lsm6dso_emb_func_status_t reg;
8115 int32_t ret;
8116
8117 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
8118
8119 if (ret == 0)
8120 {
8121 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_STATUS, (uint8_t *)®, 1);
8122 }
8123
8124 if (ret == 0)
8125 {
8126 *val = reg.is_sigmot;
8127 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
8128 }
8129
8130 return ret;
8131 }
8132
8133 /**
8134 * @}
8135 *
8136 */
8137
8138 /**
8139 * @defgroup LSM6DSO_tilt_detection
8140 * @brief This section groups all the functions that manage the tilt
8141 * event detection.
8142 * @{
8143 *
8144 */
8145
8146 /**
8147 * @brief Interrupt status bit for tilt detection.[get]
8148 *
8149 * @param ctx read / write interface definitions
8150 * @param val Get the values of is_tilt in reg EMB_FUNC_STATUS
8151 * @retval interface status (MANDATORY: return 0 -> no Error)
8152 *
8153 */
lsm6dso_tilt_flag_data_ready_get(stmdev_ctx_t * ctx,uint8_t * val)8154 int32_t lsm6dso_tilt_flag_data_ready_get(stmdev_ctx_t *ctx,
8155 uint8_t *val)
8156 {
8157 lsm6dso_emb_func_status_t reg;
8158 int32_t ret;
8159
8160 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
8161
8162 if (ret == 0)
8163 {
8164 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_STATUS, (uint8_t *)®, 1);
8165 }
8166
8167 if (ret == 0)
8168 {
8169 *val = reg.is_tilt;
8170 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
8171 }
8172
8173 return ret;
8174 }
8175
8176 /**
8177 * @}
8178 *
8179 */
8180
8181 /**
8182 * @defgroup LSM6DSO_ magnetometer_sensor
8183 * @brief This section groups all the functions that manage additional
8184 * magnetometer sensor.
8185 * @{
8186 *
8187 */
8188
8189 /**
8190 * @brief External magnetometer sensitivity value register.[set]
8191 *
8192 * @param ctx read / write interface definitions
8193 * @param buff buffer that contains data to write
8194 * @retval interface status (MANDATORY: return 0 -> no Error)
8195 *
8196 */
lsm6dso_mag_sensitivity_set(stmdev_ctx_t * ctx,uint16_t val)8197 int32_t lsm6dso_mag_sensitivity_set(stmdev_ctx_t *ctx, uint16_t val)
8198 {
8199 uint8_t buff[2];
8200 int32_t ret;
8201
8202 buff[1] = (uint8_t)(val / 256U);
8203 buff[0] = (uint8_t)(val - (buff[1] * 256U));
8204 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SENSITIVITY_L,
8205 &buff[0]);
8206
8207 if (ret == 0)
8208 {
8209 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SENSITIVITY_H,
8210 &buff[1]);
8211 }
8212
8213 return ret;
8214 }
8215
8216 /**
8217 * @brief External magnetometer sensitivity value register.[get]
8218 *
8219 * @param ctx read / write interface definitions
8220 * @param buff buffer that stores data read
8221 * @retval interface status (MANDATORY: return 0 -> no Error)
8222 *
8223 */
lsm6dso_mag_sensitivity_get(stmdev_ctx_t * ctx,uint16_t * val)8224 int32_t lsm6dso_mag_sensitivity_get(stmdev_ctx_t *ctx, uint16_t *val)
8225 {
8226 uint8_t buff[2];
8227 int32_t ret;
8228
8229 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SENSITIVITY_L,
8230 &buff[0]);
8231
8232 if (ret == 0)
8233 {
8234 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SENSITIVITY_H,
8235 &buff[1]);
8236 *val = buff[1];
8237 *val = (*val * 256U) + buff[0];
8238 }
8239
8240 return ret;
8241 }
8242
8243 /**
8244 * @brief Offset for hard-iron compensation register (r/w).[set]
8245 *
8246 * @param ctx read / write interface definitions
8247 * @param buff buffer that contains data to write
8248 * @retval interface status (MANDATORY: return 0 -> no Error)
8249 *
8250 */
lsm6dso_mag_offset_set(stmdev_ctx_t * ctx,int16_t * val)8251 int32_t lsm6dso_mag_offset_set(stmdev_ctx_t *ctx, int16_t *val)
8252 {
8253 uint8_t buff[6];
8254 int32_t ret;
8255
8256 buff[1] = (uint8_t)((uint16_t)val[0] / 256U);
8257 buff[0] = (uint8_t)((uint16_t)val[0] - (buff[1] * 256U));
8258 buff[3] = (uint8_t)((uint16_t)val[1] / 256U);
8259 buff[2] = (uint8_t)((uint16_t)val[1] - (buff[3] * 256U));
8260 buff[5] = (uint8_t)((uint16_t)val[2] / 256U);
8261 buff[4] = (uint8_t)((uint16_t)val[2] - (buff[5] * 256U));
8262 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_OFFX_L, &buff[0]);
8263
8264 if (ret == 0)
8265 {
8266 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_OFFX_H, &buff[1]);
8267 }
8268
8269 if (ret == 0)
8270 {
8271 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_OFFY_L, &buff[2]);
8272 }
8273
8274 if (ret == 0)
8275 {
8276 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_OFFY_H, &buff[3]);
8277 }
8278
8279 if (ret == 0)
8280 {
8281 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_OFFZ_L, &buff[4]);
8282 }
8283
8284 if (ret == 0)
8285 {
8286 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_OFFZ_H, &buff[5]);
8287 }
8288
8289 return ret;
8290 }
8291
8292 /**
8293 * @brief Offset for hard-iron compensation register (r/w).[get]
8294 *
8295 * @param ctx read / write interface definitions
8296 * @param buff buffer that stores data read
8297 * @retval interface status (MANDATORY: return 0 -> no Error)
8298 *
8299 */
lsm6dso_mag_offset_get(stmdev_ctx_t * ctx,int16_t * val)8300 int32_t lsm6dso_mag_offset_get(stmdev_ctx_t *ctx, int16_t *val)
8301 {
8302 uint8_t buff[6];
8303 int32_t ret;
8304
8305 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_OFFX_L, &buff[0]);
8306
8307 if (ret == 0)
8308 {
8309 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_OFFX_H, &buff[1]);
8310 }
8311
8312 if (ret == 0)
8313 {
8314 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_OFFY_L, &buff[2]);
8315 }
8316
8317 if (ret == 0)
8318 {
8319 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_OFFY_H, &buff[3]);
8320 }
8321
8322 if (ret == 0)
8323 {
8324 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_OFFZ_L, &buff[4]);
8325 }
8326
8327 if (ret == 0)
8328 {
8329 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_OFFZ_H, &buff[5]);
8330 val[0] = (int16_t)buff[1];
8331 val[0] = (val[0] * 256) + (int16_t)buff[0];
8332 val[1] = (int16_t)buff[3];
8333 val[1] = (val[1] * 256) + (int16_t)buff[2];
8334 val[2] = (int16_t)buff[5];
8335 val[2] = (val[2] * 256) + (int16_t)buff[4];
8336 }
8337
8338 return ret;
8339 }
8340
8341 /**
8342 * @brief Soft-iron (3x3 symmetric) matrix correction
8343 * register (r/w). The value is expressed as
8344 * half-precision floating-point format:
8345 * SEEEEEFFFFFFFFFF
8346 * S: 1 sign bit;
8347 * E: 5 exponent bits;
8348 * F: 10 fraction bits).[set]
8349 *
8350 * @param ctx read / write interface definitions
8351 * @param buff buffer that contains data to write
8352 * @retval interface status (MANDATORY: return 0 -> no Error)
8353 *
8354 */
lsm6dso_mag_soft_iron_set(stmdev_ctx_t * ctx,int16_t * val)8355 int32_t lsm6dso_mag_soft_iron_set(stmdev_ctx_t *ctx, int16_t *val)
8356 {
8357 uint8_t buff[12];
8358 int32_t ret;
8359
8360 uint8_t index;
8361 buff[1] = (uint8_t)((uint16_t)val[0] / 256U);
8362 buff[0] = (uint8_t)((uint16_t)val[0] - (buff[1] * 256U));
8363 buff[3] = (uint8_t)((uint16_t)val[1] / 256U);
8364 buff[2] = (uint8_t)((uint16_t)val[1] - (buff[3] * 256U));
8365 buff[5] = (uint8_t)((uint16_t)val[2] / 256U);
8366 buff[4] = (uint8_t)((uint16_t)val[2] - (buff[5] * 256U));
8367 buff[7] = (uint8_t)((uint16_t)val[3] / 256U);
8368 buff[6] = (uint8_t)((uint16_t)val[3] - (buff[7] * 256U));
8369 buff[9] = (uint8_t)((uint16_t)val[4] / 256U);
8370 buff[8] = (uint8_t)((uint16_t)val[4] - (buff[9] * 256U));
8371 buff[11] = (uint8_t)((uint16_t)val[5] / 256U);
8372 buff[10] = (uint8_t)((uint16_t)val[5] - (buff[11] * 256U));
8373 index = 0x00U;
8374 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SI_XX_L,
8375 &buff[index]);
8376
8377 if (ret == 0)
8378 {
8379 index++;
8380 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SI_XX_H,
8381 &buff[index]);
8382 }
8383
8384 if (ret == 0)
8385 {
8386 index++;
8387 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SI_XY_L,
8388 &buff[index]);
8389 }
8390
8391 if (ret == 0)
8392 {
8393 index++;
8394 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SI_XY_H,
8395 &buff[index]);
8396 }
8397
8398 if (ret == 0)
8399 {
8400 index++;
8401 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SI_XZ_L,
8402 &buff[index]);
8403 }
8404
8405 if (ret == 0)
8406 {
8407 index++;
8408 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SI_XZ_H,
8409 &buff[index]);
8410 }
8411
8412 if (ret == 0)
8413 {
8414 index++;
8415 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SI_YY_L,
8416 &buff[index]);
8417 }
8418
8419 if (ret == 0)
8420 {
8421 index++;
8422 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SI_YY_H,
8423 &buff[index]);
8424 }
8425
8426 if (ret == 0)
8427 {
8428 index++;
8429 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SI_YZ_L,
8430 &buff[index]);
8431 }
8432
8433 if (ret == 0)
8434 {
8435 index++;
8436 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SI_YZ_H,
8437 &buff[index]);
8438 }
8439
8440 if (ret == 0)
8441 {
8442 index++;
8443 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SI_ZZ_L,
8444 &buff[index]);
8445 }
8446
8447 if (ret == 0)
8448 {
8449 index++;
8450 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_SI_ZZ_H,
8451 &buff[index]);
8452 }
8453
8454 return ret;
8455 }
8456
8457 /**
8458 * @brief Soft-iron (3x3 symmetric) matrix
8459 * correction register (r/w).
8460 * The value is expressed as half-precision
8461 * floating-point format:
8462 * SEEEEEFFFFFFFFFF
8463 * S: 1 sign bit;
8464 * E: 5 exponent bits;
8465 * F: 10 fraction bits.[get]
8466 *
8467 * @param ctx read / write interface definitions
8468 * @param buff buffer that stores data read
8469 * @retval interface status (MANDATORY: return 0 -> no Error)
8470 *
8471 */
lsm6dso_mag_soft_iron_get(stmdev_ctx_t * ctx,int16_t * val)8472 int32_t lsm6dso_mag_soft_iron_get(stmdev_ctx_t *ctx, int16_t *val)
8473 {
8474 uint8_t buff[12];
8475 int32_t ret;
8476
8477 uint8_t index;
8478 index = 0x00U;
8479 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SI_XX_L, &buff[index]);
8480
8481 if (ret == 0)
8482 {
8483 index++;
8484 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SI_XX_H, &buff[index]);
8485 }
8486
8487 if (ret == 0)
8488 {
8489 index++;
8490 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SI_XY_L, &buff[index]);
8491 }
8492
8493 if (ret == 0)
8494 {
8495 index++;
8496 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SI_XY_H, &buff[index]);
8497 }
8498
8499 if (ret == 0)
8500 {
8501 index++;
8502 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SI_XZ_L, &buff[index]);
8503 }
8504
8505 if (ret == 0)
8506 {
8507 index++;
8508 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SI_XZ_H, &buff[index]);
8509 }
8510
8511 if (ret == 0)
8512 {
8513 index++;
8514 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SI_YY_L, &buff[index]);
8515 }
8516
8517 if (ret == 0)
8518 {
8519 index++;
8520 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SI_YY_H, &buff[index]);
8521 }
8522
8523 if (ret == 0)
8524 {
8525 index++;
8526 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SI_YZ_L, &buff[index]);
8527 }
8528
8529 if (ret == 0)
8530 {
8531 index++;
8532 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SI_YZ_H, &buff[index]);
8533 }
8534
8535 if (ret == 0)
8536 {
8537 index++;
8538 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SI_ZZ_L, &buff[index]);
8539 }
8540
8541 if (ret == 0)
8542 {
8543 index++;
8544 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_SI_ZZ_H, &buff[index]);
8545 }
8546
8547 val[0] = (int16_t)buff[1];
8548 val[0] = (val[0] * 256) + (int16_t)buff[0];
8549 val[1] = (int16_t)buff[3];
8550 val[1] = (val[1] * 256) + (int16_t)buff[2];
8551 val[2] = (int16_t)buff[5];
8552 val[2] = (val[2] * 256) + (int16_t)buff[4];
8553 val[3] = (int16_t)buff[7];
8554 val[3] = (val[3] * 256) + (int16_t)buff[6];
8555 val[4] = (int16_t)buff[9];
8556 val[4] = (val[4] * 256) + (int16_t)buff[8];
8557 val[5] = (int16_t)buff[11];
8558 val[5] = (val[5] * 256) + (int16_t)buff[10];
8559
8560 return ret;
8561 }
8562
8563 /**
8564 * @brief Magnetometer Z-axis coordinates
8565 * rotation (to be aligned to
8566 * accelerometer/gyroscope axes
8567 * orientation).[set]
8568 *
8569 * @param ctx read / write interface definitions
8570 * @param val change the values of mag_z_axis in reg MAG_CFG_A
8571 * @retval interface status (MANDATORY: return 0 -> no Error)
8572 *
8573 */
lsm6dso_mag_z_orient_set(stmdev_ctx_t * ctx,lsm6dso_mag_z_axis_t val)8574 int32_t lsm6dso_mag_z_orient_set(stmdev_ctx_t *ctx,
8575 lsm6dso_mag_z_axis_t val)
8576 {
8577 lsm6dso_mag_cfg_a_t reg;
8578 int32_t ret;
8579
8580 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_CFG_A,
8581 (uint8_t *)®);
8582
8583 if (ret == 0)
8584 {
8585 reg.mag_z_axis = (uint8_t) val;
8586 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_CFG_A,
8587 (uint8_t *)®);
8588 }
8589
8590 return ret;
8591 }
8592
8593 /**
8594 * @brief Magnetometer Z-axis coordinates
8595 * rotation (to be aligned to
8596 * accelerometer/gyroscope axes
8597 * orientation).[get]
8598 *
8599 * @param ctx read / write interface definitions
8600 * @param val Get the values of mag_z_axis in reg MAG_CFG_A
8601 * @retval interface status (MANDATORY: return 0 -> no Error)
8602 *
8603 */
lsm6dso_mag_z_orient_get(stmdev_ctx_t * ctx,lsm6dso_mag_z_axis_t * val)8604 int32_t lsm6dso_mag_z_orient_get(stmdev_ctx_t *ctx,
8605 lsm6dso_mag_z_axis_t *val)
8606 {
8607 lsm6dso_mag_cfg_a_t reg;
8608 int32_t ret;
8609
8610 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_CFG_A,
8611 (uint8_t *)®);
8612
8613 switch (reg.mag_z_axis)
8614 {
8615 case LSM6DSO_Z_EQ_Y:
8616 *val = LSM6DSO_Z_EQ_Y;
8617 break;
8618
8619 case LSM6DSO_Z_EQ_MIN_Y:
8620 *val = LSM6DSO_Z_EQ_MIN_Y;
8621 break;
8622
8623 case LSM6DSO_Z_EQ_X:
8624 *val = LSM6DSO_Z_EQ_X;
8625 break;
8626
8627 case LSM6DSO_Z_EQ_MIN_X:
8628 *val = LSM6DSO_Z_EQ_MIN_X;
8629 break;
8630
8631 case LSM6DSO_Z_EQ_MIN_Z:
8632 *val = LSM6DSO_Z_EQ_MIN_Z;
8633 break;
8634
8635 case LSM6DSO_Z_EQ_Z:
8636 *val = LSM6DSO_Z_EQ_Z;
8637 break;
8638
8639 default:
8640 *val = LSM6DSO_Z_EQ_Y;
8641 break;
8642 }
8643
8644 return ret;
8645 }
8646
8647 /**
8648 * @brief Magnetometer Y-axis coordinates
8649 * rotation (to be aligned to
8650 * accelerometer/gyroscope axes
8651 * orientation).[set]
8652 *
8653 * @param ctx read / write interface definitions
8654 * @param val change the values of mag_y_axis in reg MAG_CFG_A
8655 * @retval interface status (MANDATORY: return 0 -> no Error)
8656 *
8657 */
lsm6dso_mag_y_orient_set(stmdev_ctx_t * ctx,lsm6dso_mag_y_axis_t val)8658 int32_t lsm6dso_mag_y_orient_set(stmdev_ctx_t *ctx,
8659 lsm6dso_mag_y_axis_t val)
8660 {
8661 lsm6dso_mag_cfg_a_t reg;
8662 int32_t ret;
8663
8664 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_CFG_A,
8665 (uint8_t *)®);
8666
8667 if (ret == 0)
8668 {
8669 reg.mag_y_axis = (uint8_t)val;
8670 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_CFG_A,
8671 (uint8_t *) ®);
8672 }
8673
8674 return ret;
8675 }
8676
8677 /**
8678 * @brief Magnetometer Y-axis coordinates
8679 * rotation (to be aligned to
8680 * accelerometer/gyroscope axes
8681 * orientation).[get]
8682 *
8683 * @param ctx read / write interface definitions
8684 * @param val Get the values of mag_y_axis in reg MAG_CFG_A
8685 * @retval interface status (MANDATORY: return 0 -> no Error)
8686 *
8687 */
lsm6dso_mag_y_orient_get(stmdev_ctx_t * ctx,lsm6dso_mag_y_axis_t * val)8688 int32_t lsm6dso_mag_y_orient_get(stmdev_ctx_t *ctx,
8689 lsm6dso_mag_y_axis_t *val)
8690 {
8691 lsm6dso_mag_cfg_a_t reg;
8692 int32_t ret;
8693
8694 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_CFG_A,
8695 (uint8_t *)®);
8696
8697 switch (reg.mag_y_axis)
8698 {
8699 case LSM6DSO_Y_EQ_Y:
8700 *val = LSM6DSO_Y_EQ_Y;
8701 break;
8702
8703 case LSM6DSO_Y_EQ_MIN_Y:
8704 *val = LSM6DSO_Y_EQ_MIN_Y;
8705 break;
8706
8707 case LSM6DSO_Y_EQ_X:
8708 *val = LSM6DSO_Y_EQ_X;
8709 break;
8710
8711 case LSM6DSO_Y_EQ_MIN_X:
8712 *val = LSM6DSO_Y_EQ_MIN_X;
8713 break;
8714
8715 case LSM6DSO_Y_EQ_MIN_Z:
8716 *val = LSM6DSO_Y_EQ_MIN_Z;
8717 break;
8718
8719 case LSM6DSO_Y_EQ_Z:
8720 *val = LSM6DSO_Y_EQ_Z;
8721 break;
8722
8723 default:
8724 *val = LSM6DSO_Y_EQ_Y;
8725 break;
8726 }
8727
8728 return ret;
8729 }
8730
8731 /**
8732 * @brief Magnetometer X-axis coordinates
8733 * rotation (to be aligned to
8734 * accelerometer/gyroscope axes
8735 * orientation).[set]
8736 *
8737 * @param ctx read / write interface definitions
8738 * @param val change the values of mag_x_axis in reg MAG_CFG_B
8739 * @retval interface status (MANDATORY: return 0 -> no Error)
8740 *
8741 */
lsm6dso_mag_x_orient_set(stmdev_ctx_t * ctx,lsm6dso_mag_x_axis_t val)8742 int32_t lsm6dso_mag_x_orient_set(stmdev_ctx_t *ctx,
8743 lsm6dso_mag_x_axis_t val)
8744 {
8745 lsm6dso_mag_cfg_b_t reg;
8746 int32_t ret;
8747
8748 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_CFG_B,
8749 (uint8_t *)®);
8750
8751 if (ret == 0)
8752 {
8753 reg.mag_x_axis = (uint8_t)val;
8754 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_MAG_CFG_B,
8755 (uint8_t *)®);
8756 }
8757
8758 return ret;
8759 }
8760
8761 /**
8762 * @brief Magnetometer X-axis coordinates
8763 * rotation (to be aligned to
8764 * accelerometer/gyroscope axes
8765 * orientation).[get]
8766 *
8767 * @param ctx read / write interface definitions
8768 * @param val Get the values of mag_x_axis in reg MAG_CFG_B
8769 * @retval interface status (MANDATORY: return 0 -> no Error)
8770 *
8771 */
lsm6dso_mag_x_orient_get(stmdev_ctx_t * ctx,lsm6dso_mag_x_axis_t * val)8772 int32_t lsm6dso_mag_x_orient_get(stmdev_ctx_t *ctx,
8773 lsm6dso_mag_x_axis_t *val)
8774 {
8775 lsm6dso_mag_cfg_b_t reg;
8776 int32_t ret;
8777
8778 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_MAG_CFG_B,
8779 (uint8_t *)®);
8780
8781 switch (reg.mag_x_axis)
8782 {
8783 case LSM6DSO_X_EQ_Y:
8784 *val = LSM6DSO_X_EQ_Y;
8785 break;
8786
8787 case LSM6DSO_X_EQ_MIN_Y:
8788 *val = LSM6DSO_X_EQ_MIN_Y;
8789 break;
8790
8791 case LSM6DSO_X_EQ_X:
8792 *val = LSM6DSO_X_EQ_X;
8793 break;
8794
8795 case LSM6DSO_X_EQ_MIN_X:
8796 *val = LSM6DSO_X_EQ_MIN_X;
8797 break;
8798
8799 case LSM6DSO_X_EQ_MIN_Z:
8800 *val = LSM6DSO_X_EQ_MIN_Z;
8801 break;
8802
8803 case LSM6DSO_X_EQ_Z:
8804 *val = LSM6DSO_X_EQ_Z;
8805 break;
8806
8807 default:
8808 *val = LSM6DSO_X_EQ_Y;
8809 break;
8810 }
8811
8812 return ret;
8813 }
8814
8815 /**
8816 * @}
8817 *
8818 */
8819
8820 /**
8821 * @defgroup LSM6DSO_finite_state_machine
8822 * @brief This section groups all the functions that manage the
8823 * state_machine.
8824 * @{
8825 *
8826 */
8827
8828 /**
8829 * @brief Interrupt status bit for FSM long counter
8830 * timeout interrupt event.[get]
8831 *
8832 * @param ctx read / write interface definitions
8833 * @param val Get the values of is_fsm_lc in reg EMB_FUNC_STATUS
8834 * @retval interface status (MANDATORY: return 0 -> no Error)
8835 *
8836 */
lsm6dso_long_cnt_flag_data_ready_get(stmdev_ctx_t * ctx,uint8_t * val)8837 int32_t lsm6dso_long_cnt_flag_data_ready_get(stmdev_ctx_t *ctx,
8838 uint8_t *val)
8839 {
8840 lsm6dso_emb_func_status_t reg;
8841 int32_t ret;
8842
8843 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
8844
8845 if (ret == 0)
8846 {
8847 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_STATUS, (uint8_t *)®, 1);
8848 }
8849
8850 if (ret == 0)
8851 {
8852 *val = reg.is_fsm_lc;
8853 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
8854 }
8855
8856 return ret;
8857 }
8858
8859 /**
8860 * @brief Final State Machine enable.[set]
8861 *
8862 * @param ctx read / write interface definitions
8863 * @param val union of registers from FSM_ENABLE_A to FSM_ENABLE_B
8864 * @retval interface status (MANDATORY: return 0 -> no Error)
8865 *
8866 */
lsm6dso_fsm_enable_set(stmdev_ctx_t * ctx,lsm6dso_emb_fsm_enable_t * val)8867 int32_t lsm6dso_fsm_enable_set(stmdev_ctx_t *ctx,
8868 lsm6dso_emb_fsm_enable_t *val)
8869 {
8870 int32_t ret;
8871
8872 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
8873
8874 if (ret == 0)
8875 {
8876 ret = lsm6dso_write_reg(ctx, LSM6DSO_FSM_ENABLE_A,
8877 (uint8_t *)&val->fsm_enable_a, 1);
8878 }
8879
8880 if (ret == 0)
8881 {
8882 ret = lsm6dso_write_reg(ctx, LSM6DSO_FSM_ENABLE_B,
8883 (uint8_t *)&val->fsm_enable_b, 1);
8884 }
8885
8886 if (ret == 0)
8887 {
8888 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
8889 }
8890
8891 return ret;
8892 }
8893
8894 /**
8895 * @brief Final State Machine enable.[get]
8896 *
8897 * @param ctx read / write interface definitions
8898 * @param val union of registers from FSM_ENABLE_A to FSM_ENABLE_B
8899 * @retval interface status (MANDATORY: return 0 -> no Error)
8900 *
8901 */
lsm6dso_fsm_enable_get(stmdev_ctx_t * ctx,lsm6dso_emb_fsm_enable_t * val)8902 int32_t lsm6dso_fsm_enable_get(stmdev_ctx_t *ctx,
8903 lsm6dso_emb_fsm_enable_t *val)
8904 {
8905 int32_t ret;
8906
8907 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
8908
8909 if (ret == 0)
8910 {
8911 ret = lsm6dso_read_reg(ctx, LSM6DSO_FSM_ENABLE_A, (uint8_t *) val, 2);
8912 }
8913
8914 if (ret == 0)
8915 {
8916 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
8917 }
8918
8919 return ret;
8920 }
8921
8922 /**
8923 * @brief FSM long counter status register. Long counter value is an
8924 * unsigned integer value (16-bit format).[set]
8925 *
8926 * @param ctx read / write interface definitions
8927 * @param buff buffer that contains data to write
8928 * @retval interface status (MANDATORY: return 0 -> no Error)
8929 *
8930 */
lsm6dso_long_cnt_set(stmdev_ctx_t * ctx,uint16_t val)8931 int32_t lsm6dso_long_cnt_set(stmdev_ctx_t *ctx, uint16_t val)
8932 {
8933 uint8_t buff[2];
8934 int32_t ret;
8935
8936 buff[1] = (uint8_t)(val / 256U);
8937 buff[0] = (uint8_t)(val - (buff[1] * 256U));
8938 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
8939
8940 if (ret == 0)
8941 {
8942 ret = lsm6dso_write_reg(ctx, LSM6DSO_FSM_LONG_COUNTER_L, buff, 2);
8943 }
8944
8945 if (ret == 0)
8946 {
8947 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
8948 }
8949
8950 return ret;
8951 }
8952
8953 /**
8954 * @brief FSM long counter status register. Long counter value is an
8955 * unsigned integer value (16-bit format).[get]
8956 *
8957 * @param ctx read / write interface definitions
8958 * @param buff buffer that stores data read
8959 * @retval interface status (MANDATORY: return 0 -> no Error)
8960 *
8961 */
lsm6dso_long_cnt_get(stmdev_ctx_t * ctx,uint16_t * val)8962 int32_t lsm6dso_long_cnt_get(stmdev_ctx_t *ctx, uint16_t *val)
8963 {
8964 uint8_t buff[2];
8965 int32_t ret;
8966
8967 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
8968
8969 if (ret == 0)
8970 {
8971 ret = lsm6dso_read_reg(ctx, LSM6DSO_FSM_LONG_COUNTER_L, buff, 2);
8972 }
8973
8974 if (ret == 0)
8975 {
8976 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
8977 *val = buff[1];
8978 *val = (*val * 256U) + buff[0];
8979 }
8980
8981 return ret;
8982 }
8983
8984 /**
8985 * @brief Clear FSM long counter value.[set]
8986 *
8987 * @param ctx read / write interface definitions
8988 * @param val change the values of fsm_lc_clr in
8989 * reg FSM_LONG_COUNTER_CLEAR
8990 * @retval interface status (MANDATORY: return 0 -> no Error)
8991 *
8992 */
lsm6dso_long_clr_set(stmdev_ctx_t * ctx,lsm6dso_fsm_lc_clr_t val)8993 int32_t lsm6dso_long_clr_set(stmdev_ctx_t *ctx,
8994 lsm6dso_fsm_lc_clr_t val)
8995 {
8996 lsm6dso_fsm_long_counter_clear_t reg;
8997 int32_t ret;
8998
8999 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
9000
9001 if (ret == 0)
9002 {
9003 ret = lsm6dso_read_reg(ctx, LSM6DSO_FSM_LONG_COUNTER_CLEAR,
9004 (uint8_t *)®, 1);
9005 }
9006
9007 if (ret == 0)
9008 {
9009 reg. fsm_lc_clr = (uint8_t)val;
9010 ret = lsm6dso_write_reg(ctx, LSM6DSO_FSM_LONG_COUNTER_CLEAR,
9011 (uint8_t *)®, 1);
9012 }
9013
9014 if (ret == 0)
9015 {
9016 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9017 }
9018
9019 return ret;
9020 }
9021
9022 /**
9023 * @brief Clear FSM long counter value.[get]
9024 *
9025 * @param ctx read / write interface definitions
9026 * @param val Get the values of fsm_lc_clr in
9027 * reg FSM_LONG_COUNTER_CLEAR
9028 * @retval interface status (MANDATORY: return 0 -> no Error)
9029 *
9030 */
lsm6dso_long_clr_get(stmdev_ctx_t * ctx,lsm6dso_fsm_lc_clr_t * val)9031 int32_t lsm6dso_long_clr_get(stmdev_ctx_t *ctx,
9032 lsm6dso_fsm_lc_clr_t *val)
9033 {
9034 lsm6dso_fsm_long_counter_clear_t reg;
9035 int32_t ret;
9036
9037 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
9038
9039 if (ret == 0)
9040 {
9041 ret = lsm6dso_read_reg(ctx, LSM6DSO_FSM_LONG_COUNTER_CLEAR,
9042 (uint8_t *)®, 1);
9043 }
9044
9045 if (ret == 0)
9046 {
9047 switch (reg.fsm_lc_clr)
9048 {
9049 case LSM6DSO_LC_NORMAL:
9050 *val = LSM6DSO_LC_NORMAL;
9051 break;
9052
9053 case LSM6DSO_LC_CLEAR:
9054 *val = LSM6DSO_LC_CLEAR;
9055 break;
9056
9057 case LSM6DSO_LC_CLEAR_DONE:
9058 *val = LSM6DSO_LC_CLEAR_DONE;
9059 break;
9060
9061 default:
9062 *val = LSM6DSO_LC_NORMAL;
9063 break;
9064 }
9065 }
9066
9067 if (ret == 0)
9068 {
9069 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9070 }
9071
9072 return ret;
9073 }
9074
9075 /**
9076 * @brief FSM output registers[get]
9077 *
9078 * @param ctx read / write interface definitions
9079 * @param val struct of registers from FSM_OUTS1 to FSM_OUTS16
9080 * @retval interface status (MANDATORY: return 0 -> no Error)
9081 *
9082 */
lsm6dso_fsm_out_get(stmdev_ctx_t * ctx,lsm6dso_fsm_out_t * val)9083 int32_t lsm6dso_fsm_out_get(stmdev_ctx_t *ctx, lsm6dso_fsm_out_t *val)
9084 {
9085 int32_t ret;
9086
9087 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
9088
9089 if (ret == 0)
9090 {
9091 ret = lsm6dso_read_reg(ctx, LSM6DSO_FSM_OUTS1, (uint8_t *)val, 16);
9092 }
9093
9094 if (ret == 0)
9095 {
9096 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9097 }
9098
9099 return ret;
9100 }
9101
9102 /**
9103 * @brief Finite State Machine ODR configuration.[set]
9104 *
9105 * @param ctx read / write interface definitions
9106 * @param val change the values of fsm_odr in reg EMB_FUNC_ODR_CFG_B
9107 * @retval interface status (MANDATORY: return 0 -> no Error)
9108 *
9109 */
lsm6dso_fsm_data_rate_set(stmdev_ctx_t * ctx,lsm6dso_fsm_odr_t val)9110 int32_t lsm6dso_fsm_data_rate_set(stmdev_ctx_t *ctx,
9111 lsm6dso_fsm_odr_t val)
9112 {
9113 lsm6dso_emb_func_odr_cfg_b_t reg;
9114 int32_t ret;
9115
9116 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
9117
9118 if (ret == 0)
9119 {
9120 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_ODR_CFG_B,
9121 (uint8_t *)®, 1);
9122 }
9123
9124 if (ret == 0)
9125 {
9126 reg.not_used_01 = 3; /* set default values */
9127 reg.not_used_02 = 2; /* set default values */
9128 reg.fsm_odr = (uint8_t)val;
9129 ret = lsm6dso_write_reg(ctx, LSM6DSO_EMB_FUNC_ODR_CFG_B,
9130 (uint8_t *)®, 1);
9131 }
9132
9133 if (ret == 0)
9134 {
9135 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9136 }
9137
9138 return ret;
9139 }
9140
9141 /**
9142 * @brief Finite State Machine ODR configuration.[get]
9143 *
9144 * @param ctx read / write interface definitions
9145 * @param val Get the values of fsm_odr in reg EMB_FUNC_ODR_CFG_B
9146 * @retval interface status (MANDATORY: return 0 -> no Error)
9147 *
9148 */
lsm6dso_fsm_data_rate_get(stmdev_ctx_t * ctx,lsm6dso_fsm_odr_t * val)9149 int32_t lsm6dso_fsm_data_rate_get(stmdev_ctx_t *ctx,
9150 lsm6dso_fsm_odr_t *val)
9151 {
9152 lsm6dso_emb_func_odr_cfg_b_t reg;
9153 int32_t ret;
9154
9155 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
9156
9157 if (ret == 0)
9158 {
9159 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_ODR_CFG_B,
9160 (uint8_t *)®, 1);
9161 }
9162
9163 if (ret == 0)
9164 {
9165 switch (reg.fsm_odr)
9166 {
9167 case LSM6DSO_ODR_FSM_12Hz5:
9168 *val = LSM6DSO_ODR_FSM_12Hz5;
9169 break;
9170
9171 case LSM6DSO_ODR_FSM_26Hz:
9172 *val = LSM6DSO_ODR_FSM_26Hz;
9173 break;
9174
9175 case LSM6DSO_ODR_FSM_52Hz:
9176 *val = LSM6DSO_ODR_FSM_52Hz;
9177 break;
9178
9179 case LSM6DSO_ODR_FSM_104Hz:
9180 *val = LSM6DSO_ODR_FSM_104Hz;
9181 break;
9182
9183 default:
9184 *val = LSM6DSO_ODR_FSM_12Hz5;
9185 break;
9186 }
9187
9188 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9189 }
9190
9191 return ret;
9192 }
9193
9194 /**
9195 * @brief FSM initialization request.[set]
9196 *
9197 * @param ctx read / write interface definitions
9198 * @param val change the values of fsm_init in reg FSM_INIT
9199 * @retval interface status (MANDATORY: return 0 -> no Error)
9200 *
9201 */
lsm6dso_fsm_init_set(stmdev_ctx_t * ctx,uint8_t val)9202 int32_t lsm6dso_fsm_init_set(stmdev_ctx_t *ctx, uint8_t val)
9203 {
9204 lsm6dso_emb_func_init_b_t reg;
9205 int32_t ret;
9206
9207 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
9208
9209 if (ret == 0)
9210 {
9211 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_INIT_B, (uint8_t *)®, 1);
9212 }
9213
9214 if (ret == 0)
9215 {
9216 reg.fsm_init = val;
9217 ret = lsm6dso_write_reg(ctx, LSM6DSO_EMB_FUNC_INIT_B, (uint8_t *)®, 1);
9218 }
9219
9220 if (ret == 0)
9221 {
9222 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9223 }
9224
9225 return ret;
9226 }
9227
9228 /**
9229 * @brief FSM initialization request.[get]
9230 *
9231 * @param ctx read / write interface definitions
9232 * @param val Get the values of fsm_init in reg FSM_INIT
9233 * @retval interface status (MANDATORY: return 0 -> no Error)
9234 *
9235 */
lsm6dso_fsm_init_get(stmdev_ctx_t * ctx,uint8_t * val)9236 int32_t lsm6dso_fsm_init_get(stmdev_ctx_t *ctx, uint8_t *val)
9237 {
9238 lsm6dso_emb_func_init_b_t reg;
9239 int32_t ret;
9240
9241 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
9242
9243 if (ret == 0)
9244 {
9245 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_INIT_B, (uint8_t *)®, 1);
9246 }
9247
9248 if (ret == 0)
9249 {
9250 *val = reg.fsm_init;
9251 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9252 }
9253
9254 return ret;
9255 }
9256
9257 /**
9258 * @brief FSM long counter timeout register (r/w). The long counter
9259 * timeout value is an unsigned integer value (16-bit format).
9260 * When the long counter value reached this value,
9261 * the FSM generates an interrupt.[set]
9262 *
9263 * @param ctx read / write interface definitions
9264 * @param val the value of long counter
9265 * @retval interface status (MANDATORY: return 0 -> no Error)
9266 *
9267 */
lsm6dso_long_cnt_int_value_set(stmdev_ctx_t * ctx,uint16_t val)9268 int32_t lsm6dso_long_cnt_int_value_set(stmdev_ctx_t *ctx,
9269 uint16_t val)
9270 {
9271 uint8_t buff[2];
9272 int32_t ret;
9273
9274 buff[1] = (uint8_t)(val / 256U);
9275 buff[0] = (uint8_t)(val - (buff[1] * 256U));
9276 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_FSM_LC_TIMEOUT_L,
9277 &buff[0]);
9278
9279 if (ret == 0)
9280 {
9281 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_FSM_LC_TIMEOUT_H,
9282 &buff[1]);
9283 }
9284
9285 return ret;
9286 }
9287
9288 /**
9289 * @brief FSM long counter timeout register (r/w). The long counter
9290 * timeout value is an unsigned integer value (16-bit format).
9291 * When the long counter value reached this value,
9292 * the FSM generates an interrupt.[get]
9293 *
9294 * @param ctx read / write interface definitions
9295 * @param val buffer that stores the value of long counter
9296 * @retval interface status (MANDATORY: return 0 -> no Error)
9297 *
9298 */
lsm6dso_long_cnt_int_value_get(stmdev_ctx_t * ctx,uint16_t * val)9299 int32_t lsm6dso_long_cnt_int_value_get(stmdev_ctx_t *ctx,
9300 uint16_t *val)
9301 {
9302 uint8_t buff[2];
9303 int32_t ret;
9304
9305 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_FSM_LC_TIMEOUT_L,
9306 &buff[0]);
9307
9308 if (ret == 0)
9309 {
9310 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_FSM_LC_TIMEOUT_H,
9311 &buff[1]);
9312 *val = buff[1];
9313 *val = (*val * 256U) + buff[0];
9314 }
9315
9316 return ret;
9317 }
9318
9319 /**
9320 * @brief FSM number of programs register.[set]
9321 *
9322 * @param ctx read / write interface definitions
9323 * @param val value to write
9324 * @retval interface status (MANDATORY: return 0 -> no Error)
9325 *
9326 */
lsm6dso_fsm_number_of_programs_set(stmdev_ctx_t * ctx,uint8_t val)9327 int32_t lsm6dso_fsm_number_of_programs_set(stmdev_ctx_t *ctx,
9328 uint8_t val)
9329 {
9330 int32_t ret;
9331
9332 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_FSM_PROGRAMS, &val);
9333
9334 return ret;
9335 }
9336
9337 /**
9338 * @brief FSM number of programs register.[get]
9339 *
9340 * @param ctx read / write interface definitions
9341 * @param val buffer that stores data read.
9342 * @retval interface status (MANDATORY: return 0 -> no Error)
9343 *
9344 */
lsm6dso_fsm_number_of_programs_get(stmdev_ctx_t * ctx,uint8_t * val)9345 int32_t lsm6dso_fsm_number_of_programs_get(stmdev_ctx_t *ctx,
9346 uint8_t *val)
9347 {
9348 int32_t ret;
9349
9350 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_FSM_PROGRAMS, val);
9351
9352 return ret;
9353 }
9354
9355 /**
9356 * @brief FSM start address register (r/w).
9357 * First available address is 0x033C.[set]
9358 *
9359 * @param ctx read / write interface definitions
9360 * @param val the value of start address
9361 * @retval interface status (MANDATORY: return 0 -> no Error)
9362 *
9363 */
lsm6dso_fsm_start_address_set(stmdev_ctx_t * ctx,uint16_t val)9364 int32_t lsm6dso_fsm_start_address_set(stmdev_ctx_t *ctx, uint16_t val)
9365 {
9366 uint8_t buff[2];
9367 int32_t ret;
9368
9369 buff[1] = (uint8_t)(val / 256U);
9370 buff[0] = (uint8_t)(val - (buff[1] * 256U));
9371 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_FSM_START_ADD_L,
9372 &buff[0]);
9373
9374 if (ret == 0)
9375 {
9376 ret = lsm6dso_ln_pg_write_byte(ctx, LSM6DSO_FSM_START_ADD_H,
9377 &buff[1]);
9378 }
9379
9380 return ret;
9381 }
9382
9383 /**
9384 * @brief FSM start address register (r/w).
9385 * First available address is 0x033C.[get]
9386 *
9387 * @param ctx read / write interface definitions
9388 * @param val buffer the value of start address.
9389 * @retval interface status (MANDATORY: return 0 -> no Error)
9390 *
9391 */
lsm6dso_fsm_start_address_get(stmdev_ctx_t * ctx,uint16_t * val)9392 int32_t lsm6dso_fsm_start_address_get(stmdev_ctx_t *ctx,
9393 uint16_t *val)
9394 {
9395 uint8_t buff[2];
9396 int32_t ret;
9397
9398 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_FSM_START_ADD_L, &buff[0]);
9399
9400 if (ret == 0)
9401 {
9402 ret = lsm6dso_ln_pg_read_byte(ctx, LSM6DSO_FSM_START_ADD_H, &buff[1]);
9403 *val = buff[1];
9404 *val = (*val * 256U) + buff[0];
9405 }
9406
9407 return ret;
9408 }
9409
9410 /**
9411 * @}
9412 *
9413 */
9414
9415 /**
9416 * @defgroup LSM6DSO_Sensor_hub
9417 * @brief This section groups all the functions that manage the
9418 * sensor hub.
9419 * @{
9420 *
9421 */
9422
9423 /**
9424 * @brief Sensor hub output registers.[get]
9425 *
9426 * @param ctx read / write interface definitions
9427 * @param val values read from registers SENSOR_HUB_1 to SENSOR_HUB_18
9428 * @param len number of consecutive register to read (max 18)
9429 * @retval interface status (MANDATORY: return 0 -> no Error)
9430 *
9431 */
lsm6dso_sh_read_data_raw_get(stmdev_ctx_t * ctx,uint8_t * val,uint8_t len)9432 int32_t lsm6dso_sh_read_data_raw_get(stmdev_ctx_t *ctx, uint8_t *val,
9433 uint8_t len)
9434 {
9435 int32_t ret;
9436
9437 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9438
9439 if (ret == 0)
9440 {
9441 ret = lsm6dso_read_reg(ctx, LSM6DSO_SENSOR_HUB_1, (uint8_t *) val,
9442 len);
9443 }
9444
9445 if (ret == 0)
9446 {
9447 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9448 }
9449
9450 return ret;
9451 }
9452
9453 /**
9454 * @brief Number of external sensors to be read by the sensor hub.[set]
9455 *
9456 * @param ctx read / write interface definitions
9457 * @param val change the values of aux_sens_on in reg MASTER_CONFIG
9458 * @retval interface status (MANDATORY: return 0 -> no Error)
9459 *
9460 */
lsm6dso_sh_slave_connected_set(stmdev_ctx_t * ctx,lsm6dso_aux_sens_on_t val)9461 int32_t lsm6dso_sh_slave_connected_set(stmdev_ctx_t *ctx,
9462 lsm6dso_aux_sens_on_t val)
9463 {
9464 lsm6dso_master_config_t reg;
9465 int32_t ret;
9466
9467 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9468
9469 if (ret == 0)
9470 {
9471 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9472 }
9473
9474 if (ret == 0)
9475 {
9476 reg.aux_sens_on = (uint8_t)val;
9477 ret = lsm6dso_write_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9478 }
9479
9480 if (ret == 0)
9481 {
9482 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9483 }
9484
9485 return ret;
9486 }
9487
9488 /**
9489 * @brief Number of external sensors to be read by the sensor hub.[get]
9490 *
9491 * @param ctx read / write interface definitions
9492 * @param val Get the values of aux_sens_on in reg MASTER_CONFIG
9493 * @retval interface status (MANDATORY: return 0 -> no Error)
9494 *
9495 */
lsm6dso_sh_slave_connected_get(stmdev_ctx_t * ctx,lsm6dso_aux_sens_on_t * val)9496 int32_t lsm6dso_sh_slave_connected_get(stmdev_ctx_t *ctx,
9497 lsm6dso_aux_sens_on_t *val)
9498 {
9499 lsm6dso_master_config_t reg;
9500 int32_t ret;
9501
9502 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9503
9504 if (ret == 0)
9505 {
9506 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9507 }
9508
9509 if (ret == 0)
9510 {
9511 switch (reg.aux_sens_on)
9512 {
9513 case LSM6DSO_SLV_0:
9514 *val = LSM6DSO_SLV_0;
9515 break;
9516
9517 case LSM6DSO_SLV_0_1:
9518 *val = LSM6DSO_SLV_0_1;
9519 break;
9520
9521 case LSM6DSO_SLV_0_1_2:
9522 *val = LSM6DSO_SLV_0_1_2;
9523 break;
9524
9525 case LSM6DSO_SLV_0_1_2_3:
9526 *val = LSM6DSO_SLV_0_1_2_3;
9527 break;
9528
9529 default:
9530 *val = LSM6DSO_SLV_0;
9531 break;
9532 }
9533
9534 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9535 }
9536
9537 return ret;
9538 }
9539
9540 /**
9541 * @brief Sensor hub I2C master enable.[set]
9542 *
9543 * @param ctx read / write interface definitions
9544 * @param val change the values of master_on in reg MASTER_CONFIG
9545 * @retval interface status (MANDATORY: return 0 -> no Error)
9546 *
9547 */
lsm6dso_sh_master_set(stmdev_ctx_t * ctx,uint8_t val)9548 int32_t lsm6dso_sh_master_set(stmdev_ctx_t *ctx, uint8_t val)
9549 {
9550 lsm6dso_master_config_t reg;
9551 int32_t ret;
9552
9553 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9554
9555 if (ret == 0)
9556 {
9557 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9558 }
9559
9560 if (ret == 0)
9561 {
9562 reg.master_on = val;
9563 ret = lsm6dso_write_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9564 }
9565
9566 if (ret == 0)
9567 {
9568 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9569 }
9570
9571 return ret;
9572 }
9573
9574 /**
9575 * @brief Sensor hub I2C master enable.[get]
9576 *
9577 * @param ctx read / write interface definitions
9578 * @param val Get the values of master_on in reg MASTER_CONFIG
9579 * @retval interface status (MANDATORY: return 0 -> no Error)
9580 *
9581 */
lsm6dso_sh_master_get(stmdev_ctx_t * ctx,uint8_t * val)9582 int32_t lsm6dso_sh_master_get(stmdev_ctx_t *ctx, uint8_t *val)
9583 {
9584 lsm6dso_master_config_t reg;
9585 int32_t ret;
9586
9587 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9588
9589 if (ret == 0)
9590 {
9591 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9592 }
9593
9594 if (ret == 0)
9595 {
9596 *val = reg.master_on;
9597 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9598 }
9599
9600 return ret;
9601 }
9602
9603 /**
9604 * @brief Master I2C pull-up enable.[set]
9605 *
9606 * @param ctx read / write interface definitions
9607 * @param val change the values of shub_pu_en in reg MASTER_CONFIG
9608 * @retval interface status (MANDATORY: return 0 -> no Error)
9609 *
9610 */
lsm6dso_sh_pin_mode_set(stmdev_ctx_t * ctx,lsm6dso_shub_pu_en_t val)9611 int32_t lsm6dso_sh_pin_mode_set(stmdev_ctx_t *ctx,
9612 lsm6dso_shub_pu_en_t val)
9613 {
9614 lsm6dso_master_config_t reg;
9615 int32_t ret;
9616
9617 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9618
9619 if (ret == 0)
9620 {
9621 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9622 }
9623
9624 if (ret == 0)
9625 {
9626 reg.shub_pu_en = (uint8_t)val;
9627 ret = lsm6dso_write_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9628 }
9629
9630 if (ret == 0)
9631 {
9632 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9633 }
9634
9635 return ret;
9636 }
9637
9638 /**
9639 * @brief Master I2C pull-up enable.[get]
9640 *
9641 * @param ctx read / write interface definitions
9642 * @param val Get the values of shub_pu_en in reg MASTER_CONFIG
9643 * @retval interface status (MANDATORY: return 0 -> no Error)
9644 *
9645 */
lsm6dso_sh_pin_mode_get(stmdev_ctx_t * ctx,lsm6dso_shub_pu_en_t * val)9646 int32_t lsm6dso_sh_pin_mode_get(stmdev_ctx_t *ctx,
9647 lsm6dso_shub_pu_en_t *val)
9648 {
9649 lsm6dso_master_config_t reg;
9650 int32_t ret;
9651
9652 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9653
9654 if (ret == 0)
9655 {
9656 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9657 }
9658
9659 if (ret == 0)
9660 {
9661 switch (reg.shub_pu_en)
9662 {
9663 case LSM6DSO_EXT_PULL_UP:
9664 *val = LSM6DSO_EXT_PULL_UP;
9665 break;
9666
9667 case LSM6DSO_INTERNAL_PULL_UP:
9668 *val = LSM6DSO_INTERNAL_PULL_UP;
9669 break;
9670
9671 default:
9672 *val = LSM6DSO_EXT_PULL_UP;
9673 break;
9674 }
9675
9676 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9677 }
9678
9679 return ret;
9680 }
9681
9682 /**
9683 * @brief I2C interface pass-through.[set]
9684 *
9685 * @param ctx read / write interface definitions
9686 * @param val change the values of pass_through_mode in
9687 * reg MASTER_CONFIG
9688 * @retval interface status (MANDATORY: return 0 -> no Error)
9689 *
9690 */
lsm6dso_sh_pass_through_set(stmdev_ctx_t * ctx,uint8_t val)9691 int32_t lsm6dso_sh_pass_through_set(stmdev_ctx_t *ctx, uint8_t val)
9692 {
9693 lsm6dso_master_config_t reg;
9694 int32_t ret;
9695
9696 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9697
9698 if (ret == 0)
9699 {
9700 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9701 }
9702
9703 if (ret == 0)
9704 {
9705 reg.pass_through_mode = val;
9706 ret = lsm6dso_write_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9707 }
9708
9709 if (ret == 0)
9710 {
9711 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9712 }
9713
9714 return ret;
9715 }
9716
9717 /**
9718 * @brief I2C interface pass-through.[get]
9719 *
9720 * @param ctx read / write interface definitions
9721 * @param val Get the values of pass_through_mode in
9722 * reg MASTER_CONFIG
9723 * @retval interface status (MANDATORY: return 0 -> no Error)
9724 *
9725 */
lsm6dso_sh_pass_through_get(stmdev_ctx_t * ctx,uint8_t * val)9726 int32_t lsm6dso_sh_pass_through_get(stmdev_ctx_t *ctx, uint8_t *val)
9727 {
9728 lsm6dso_master_config_t reg;
9729 int32_t ret;
9730
9731 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9732
9733 if (ret == 0)
9734 {
9735 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9736 }
9737
9738 if (ret == 0)
9739 {
9740 *val = reg.pass_through_mode;
9741 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9742 }
9743
9744 return ret;
9745 }
9746
9747 /**
9748 * @brief Sensor hub trigger signal selection.[set]
9749 *
9750 * @param ctx read / write interface definitions
9751 * @param val change the values of start_config in reg MASTER_CONFIG
9752 * @retval interface status (MANDATORY: return 0 -> no Error)
9753 *
9754 */
lsm6dso_sh_syncro_mode_set(stmdev_ctx_t * ctx,lsm6dso_start_config_t val)9755 int32_t lsm6dso_sh_syncro_mode_set(stmdev_ctx_t *ctx,
9756 lsm6dso_start_config_t val)
9757 {
9758 lsm6dso_master_config_t reg;
9759 int32_t ret;
9760
9761 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9762
9763 if (ret == 0)
9764 {
9765 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9766 }
9767
9768 if (ret == 0)
9769 {
9770 reg.start_config = (uint8_t)val;
9771 ret = lsm6dso_write_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9772 }
9773
9774 if (ret == 0)
9775 {
9776 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9777 }
9778
9779 return ret;
9780 }
9781
9782 /**
9783 * @brief Sensor hub trigger signal selection.[get]
9784 *
9785 * @param ctx read / write interface definitions
9786 * @param val Get the values of start_config in reg MASTER_CONFIG
9787 * @retval interface status (MANDATORY: return 0 -> no Error)
9788 *
9789 */
lsm6dso_sh_syncro_mode_get(stmdev_ctx_t * ctx,lsm6dso_start_config_t * val)9790 int32_t lsm6dso_sh_syncro_mode_get(stmdev_ctx_t *ctx,
9791 lsm6dso_start_config_t *val)
9792 {
9793 lsm6dso_master_config_t reg;
9794 int32_t ret;
9795
9796 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9797
9798 if (ret == 0)
9799 {
9800 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9801 }
9802
9803 if (ret == 0)
9804 {
9805 switch (reg.start_config)
9806 {
9807 case LSM6DSO_EXT_ON_INT2_PIN:
9808 *val = LSM6DSO_EXT_ON_INT2_PIN;
9809 break;
9810
9811 case LSM6DSO_XL_GY_DRDY:
9812 *val = LSM6DSO_XL_GY_DRDY;
9813 break;
9814
9815 default:
9816 *val = LSM6DSO_EXT_ON_INT2_PIN;
9817 break;
9818 }
9819
9820 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9821 }
9822
9823 return ret;
9824 }
9825
9826 /**
9827 * @brief Slave 0 write operation is performed only at the first
9828 * sensor hub cycle.[set]
9829 *
9830 * @param ctx read / write interface definitions
9831 * @param val change the values of write_once in reg MASTER_CONFIG
9832 * @retval interface status (MANDATORY: return 0 -> no Error)
9833 *
9834 */
lsm6dso_sh_write_mode_set(stmdev_ctx_t * ctx,lsm6dso_write_once_t val)9835 int32_t lsm6dso_sh_write_mode_set(stmdev_ctx_t *ctx,
9836 lsm6dso_write_once_t val)
9837 {
9838 lsm6dso_master_config_t reg;
9839 int32_t ret;
9840
9841 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9842
9843 if (ret == 0)
9844 {
9845 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9846 }
9847
9848 if (ret == 0)
9849 {
9850 reg.write_once = (uint8_t)val;
9851 ret = lsm6dso_write_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9852 }
9853
9854 if (ret == 0)
9855 {
9856 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9857 }
9858
9859 return ret;
9860 }
9861
9862 /**
9863 * @brief Slave 0 write operation is performed only at the first sensor
9864 * hub cycle.[get]
9865 *
9866 * @param ctx read / write interface definitions
9867 * @param val Get the values of write_once in reg MASTER_CONFIG
9868 * @retval interface status (MANDATORY: return 0 -> no Error)
9869 *
9870 */
lsm6dso_sh_write_mode_get(stmdev_ctx_t * ctx,lsm6dso_write_once_t * val)9871 int32_t lsm6dso_sh_write_mode_get(stmdev_ctx_t *ctx,
9872 lsm6dso_write_once_t *val)
9873 {
9874 lsm6dso_master_config_t reg;
9875 int32_t ret;
9876
9877 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9878
9879 if (ret == 0)
9880 {
9881 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9882 }
9883
9884 if (ret == 0)
9885 {
9886 switch (reg.write_once)
9887 {
9888 case LSM6DSO_EACH_SH_CYCLE:
9889 *val = LSM6DSO_EACH_SH_CYCLE;
9890 break;
9891
9892 case LSM6DSO_ONLY_FIRST_CYCLE:
9893 *val = LSM6DSO_ONLY_FIRST_CYCLE;
9894 break;
9895
9896 default:
9897 *val = LSM6DSO_EACH_SH_CYCLE;
9898 break;
9899 }
9900
9901 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9902 }
9903
9904 return ret;
9905 }
9906
9907 /**
9908 * @brief Reset Master logic and output registers.[set]
9909 *
9910 * @param ctx read / write interface definitions
9911 * @retval interface status (MANDATORY: return 0 -> no Error)
9912 *
9913 */
lsm6dso_sh_reset_set(stmdev_ctx_t * ctx)9914 int32_t lsm6dso_sh_reset_set(stmdev_ctx_t *ctx)
9915 {
9916 lsm6dso_master_config_t reg;
9917 int32_t ret;
9918
9919 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9920
9921 if (ret == 0)
9922 {
9923 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9924 }
9925
9926 if (ret == 0)
9927 {
9928 reg.rst_master_regs = PROPERTY_ENABLE;
9929 ret = lsm6dso_write_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9930 }
9931
9932 if (ret == 0)
9933 {
9934 reg.rst_master_regs = PROPERTY_DISABLE;
9935 ret = lsm6dso_write_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9936 }
9937
9938 if (ret == 0)
9939 {
9940 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9941 }
9942
9943 return ret;
9944 }
9945
9946 /**
9947 * @brief Reset Master logic and output registers.[get]
9948 *
9949 * @param ctx read / write interface definitions
9950 * @param val Get the values of rst_master_regs in reg MASTER_CONFIG
9951 * @retval interface status (MANDATORY: return 0 -> no Error)
9952 *
9953 */
lsm6dso_sh_reset_get(stmdev_ctx_t * ctx,uint8_t * val)9954 int32_t lsm6dso_sh_reset_get(stmdev_ctx_t *ctx, uint8_t *val)
9955 {
9956 lsm6dso_master_config_t reg;
9957 int32_t ret;
9958
9959 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9960
9961 if (ret == 0)
9962 {
9963 ret = lsm6dso_read_reg(ctx, LSM6DSO_MASTER_CONFIG, (uint8_t *)®, 1);
9964 }
9965
9966 if (ret == 0)
9967 {
9968 *val = reg.rst_master_regs;
9969 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
9970 }
9971
9972 return ret;
9973 }
9974
9975 /**
9976 * @brief Rate at which the master communicates.[set]
9977 *
9978 * @param ctx read / write interface definitions
9979 * @param val change the values of shub_odr in reg slv1_CONFIG
9980 * @retval interface status (MANDATORY: return 0 -> no Error)
9981 *
9982 */
lsm6dso_sh_data_rate_set(stmdev_ctx_t * ctx,lsm6dso_shub_odr_t val)9983 int32_t lsm6dso_sh_data_rate_set(stmdev_ctx_t *ctx,
9984 lsm6dso_shub_odr_t val)
9985 {
9986 lsm6dso_slv0_config_t reg;
9987 int32_t ret;
9988
9989 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
9990
9991 if (ret == 0)
9992 {
9993 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV0_CONFIG, (uint8_t *)®, 1);
9994 }
9995
9996 if (ret == 0)
9997 {
9998 reg.shub_odr = (uint8_t)val;
9999 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV0_CONFIG, (uint8_t *)®, 1);
10000 }
10001
10002 if (ret == 0)
10003 {
10004 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
10005 }
10006
10007 return ret;
10008 }
10009
10010 /**
10011 * @brief Rate at which the master communicates.[get]
10012 *
10013 * @param ctx read / write interface definitions
10014 * @param val Get the values of shub_odr in reg slv1_CONFIG
10015 * @retval interface status (MANDATORY: return 0 -> no Error)
10016 *
10017 */
lsm6dso_sh_data_rate_get(stmdev_ctx_t * ctx,lsm6dso_shub_odr_t * val)10018 int32_t lsm6dso_sh_data_rate_get(stmdev_ctx_t *ctx,
10019 lsm6dso_shub_odr_t *val)
10020 {
10021 lsm6dso_slv0_config_t reg;
10022 int32_t ret;
10023
10024 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
10025
10026 if (ret == 0)
10027 {
10028 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV0_CONFIG, (uint8_t *)®, 1);
10029 }
10030
10031 if (ret == 0)
10032 {
10033 switch (reg.shub_odr)
10034 {
10035 case LSM6DSO_SH_ODR_104Hz:
10036 *val = LSM6DSO_SH_ODR_104Hz;
10037 break;
10038
10039 case LSM6DSO_SH_ODR_52Hz:
10040 *val = LSM6DSO_SH_ODR_52Hz;
10041 break;
10042
10043 case LSM6DSO_SH_ODR_26Hz:
10044 *val = LSM6DSO_SH_ODR_26Hz;
10045 break;
10046
10047 case LSM6DSO_SH_ODR_13Hz:
10048 *val = LSM6DSO_SH_ODR_13Hz;
10049 break;
10050
10051 default:
10052 *val = LSM6DSO_SH_ODR_104Hz;
10053 break;
10054 }
10055
10056 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
10057 }
10058
10059 return ret;
10060 }
10061
10062 /**
10063 * @brief Configure slave 0 for perform a write.[set]
10064 *
10065 * @param ctx read / write interface definitions
10066 * @param val a structure that contain
10067 * - uint8_t slv1_add; 8 bit i2c device address
10068 * - uint8_t slv1_subadd; 8 bit register device address
10069 * - uint8_t slv1_data; 8 bit data to write
10070 * @retval interface status (MANDATORY: return 0 -> no Error)
10071 *
10072 */
lsm6dso_sh_cfg_write(stmdev_ctx_t * ctx,lsm6dso_sh_cfg_write_t * val)10073 int32_t lsm6dso_sh_cfg_write(stmdev_ctx_t *ctx,
10074 lsm6dso_sh_cfg_write_t *val)
10075 {
10076 lsm6dso_slv0_add_t reg;
10077 int32_t ret;
10078
10079 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
10080
10081 if (ret == 0)
10082 {
10083 reg.slave0 = val->slv0_add;
10084 reg.rw_0 = 0;
10085 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV0_ADD, (uint8_t *)®, 1);
10086 }
10087
10088 if (ret == 0)
10089 {
10090 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV0_SUBADD,
10091 &(val->slv0_subadd), 1);
10092 }
10093
10094 if (ret == 0)
10095 {
10096 ret = lsm6dso_write_reg(ctx, LSM6DSO_DATAWRITE_SLV0,
10097 &(val->slv0_data), 1);
10098 }
10099
10100 if (ret == 0)
10101 {
10102 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
10103 }
10104
10105 return ret;
10106 }
10107
10108 /**
10109 * @brief Configure slave 0 for perform a read.[set]
10110 *
10111 * @param ctx read / write interface definitions
10112 * @param val Structure that contain
10113 * - uint8_t slv1_add; 8 bit i2c device address
10114 * - uint8_t slv1_subadd; 8 bit register device address
10115 * - uint8_t slv1_len; num of bit to read
10116 * @retval interface status (MANDATORY: return 0 -> no Error)
10117 *
10118 */
lsm6dso_sh_slv0_cfg_read(stmdev_ctx_t * ctx,lsm6dso_sh_cfg_read_t * val)10119 int32_t lsm6dso_sh_slv0_cfg_read(stmdev_ctx_t *ctx,
10120 lsm6dso_sh_cfg_read_t *val)
10121 {
10122 lsm6dso_slv0_add_t slv0_add;
10123 lsm6dso_slv0_config_t slv0_config;
10124 int32_t ret;
10125
10126 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
10127
10128 if (ret == 0)
10129 {
10130 slv0_add.slave0 = val->slv_add;
10131 slv0_add.rw_0 = 1;
10132 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV0_ADD, (uint8_t *)&slv0_add, 1);
10133 }
10134
10135 if (ret == 0)
10136 {
10137 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV0_SUBADD,
10138 &(val->slv_subadd), 1);
10139 }
10140
10141 if (ret == 0)
10142 {
10143 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV0_CONFIG,
10144 (uint8_t *)&slv0_config, 1);
10145 }
10146
10147 if (ret == 0)
10148 {
10149 slv0_config.slave0_numop = val->slv_len;
10150 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV0_CONFIG,
10151 (uint8_t *)&slv0_config, 1);
10152 }
10153
10154 if (ret == 0)
10155 {
10156 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
10157 }
10158
10159 return ret;
10160 }
10161
10162 /**
10163 * @brief Configure slave 0 for perform a write/read.[set]
10164 *
10165 * @param ctx read / write interface definitions
10166 * @param val Structure that contain
10167 * - uint8_t slv1_add; 8 bit i2c device address
10168 * - uint8_t slv1_subadd; 8 bit register device address
10169 * - uint8_t slv1_len; num of bit to read
10170 * @retval interface status (MANDATORY: return 0 -> no Error)
10171 *
10172 */
lsm6dso_sh_slv1_cfg_read(stmdev_ctx_t * ctx,lsm6dso_sh_cfg_read_t * val)10173 int32_t lsm6dso_sh_slv1_cfg_read(stmdev_ctx_t *ctx,
10174 lsm6dso_sh_cfg_read_t *val)
10175 {
10176 lsm6dso_slv1_add_t slv1_add;
10177 lsm6dso_slv1_config_t slv1_config;
10178 int32_t ret;
10179
10180 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
10181
10182 if (ret == 0)
10183 {
10184 slv1_add.slave1_add = val->slv_add;
10185 slv1_add.r_1 = 1;
10186 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV1_ADD, (uint8_t *)&slv1_add, 1);
10187 }
10188
10189 if (ret == 0)
10190 {
10191 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV1_SUBADD,
10192 &(val->slv_subadd), 1);
10193 }
10194
10195 if (ret == 0)
10196 {
10197 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV1_CONFIG,
10198 (uint8_t *)&slv1_config, 1);
10199 }
10200
10201 if (ret == 0)
10202 {
10203 slv1_config.slave1_numop = val->slv_len;
10204 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV1_CONFIG,
10205 (uint8_t *)&slv1_config, 1);
10206 }
10207
10208 if (ret == 0)
10209 {
10210 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
10211 }
10212
10213 return ret;
10214 }
10215
10216 /**
10217 * @brief Configure slave 0 for perform a write/read.[set]
10218 *
10219 * @param ctx read / write interface definitions
10220 * @param val Structure that contain
10221 * - uint8_t slv2_add; 8 bit i2c device address
10222 * - uint8_t slv2_subadd; 8 bit register device address
10223 * - uint8_t slv2_len; num of bit to read
10224 * @retval interface status (MANDATORY: return 0 -> no Error)
10225 *
10226 */
lsm6dso_sh_slv2_cfg_read(stmdev_ctx_t * ctx,lsm6dso_sh_cfg_read_t * val)10227 int32_t lsm6dso_sh_slv2_cfg_read(stmdev_ctx_t *ctx,
10228 lsm6dso_sh_cfg_read_t *val)
10229 {
10230 lsm6dso_slv2_add_t slv2_add;
10231 lsm6dso_slv2_config_t slv2_config;
10232 int32_t ret;
10233
10234 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
10235
10236 if (ret == 0)
10237 {
10238 slv2_add.slave2_add = val->slv_add;
10239 slv2_add.r_2 = 1;
10240 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV2_ADD, (uint8_t *)&slv2_add, 1);
10241 }
10242
10243 if (ret == 0)
10244 {
10245 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV2_SUBADD,
10246 &(val->slv_subadd), 1);
10247 }
10248
10249 if (ret == 0)
10250 {
10251 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV2_CONFIG,
10252 (uint8_t *)&slv2_config, 1);
10253 }
10254
10255 if (ret == 0)
10256 {
10257 slv2_config.slave2_numop = val->slv_len;
10258 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV2_CONFIG,
10259 (uint8_t *)&slv2_config, 1);
10260 }
10261
10262 if (ret == 0)
10263 {
10264 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
10265 }
10266
10267 return ret;
10268 }
10269
10270 /**
10271 * @brief Configure slave 0 for perform a write/read.[set]
10272 *
10273 * @param ctx read / write interface definitions
10274 * @param val Structure that contain
10275 * - uint8_t slv3_add; 8 bit i2c device address
10276 * - uint8_t slv3_subadd; 8 bit register device address
10277 * - uint8_t slv3_len; num of bit to read
10278 * @retval interface status (MANDATORY: return 0 -> no Error)
10279 *
10280 */
lsm6dso_sh_slv3_cfg_read(stmdev_ctx_t * ctx,lsm6dso_sh_cfg_read_t * val)10281 int32_t lsm6dso_sh_slv3_cfg_read(stmdev_ctx_t *ctx,
10282 lsm6dso_sh_cfg_read_t *val)
10283 {
10284 lsm6dso_slv3_add_t slv3_add;
10285 lsm6dso_slv3_config_t slv3_config;
10286 int32_t ret;
10287
10288 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
10289
10290 if (ret == 0)
10291 {
10292 slv3_add.slave3_add = val->slv_add;
10293 slv3_add.r_3 = 1;
10294 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV3_ADD, (uint8_t *)&slv3_add, 1);
10295 }
10296
10297 if (ret == 0)
10298 {
10299 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV3_SUBADD,
10300 &(val->slv_subadd), 1);
10301 }
10302
10303 if (ret == 0)
10304 {
10305 ret = lsm6dso_read_reg(ctx, LSM6DSO_SLV3_CONFIG,
10306 (uint8_t *)&slv3_config, 1);
10307 }
10308
10309 if (ret == 0)
10310 {
10311 slv3_config.slave3_numop = val->slv_len;
10312 ret = lsm6dso_write_reg(ctx, LSM6DSO_SLV3_CONFIG,
10313 (uint8_t *)&slv3_config, 1);
10314 }
10315
10316 if (ret == 0)
10317 {
10318 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
10319 }
10320
10321 return ret;
10322 }
10323
10324 /**
10325 * @brief Sensor hub source register.[get]
10326 *
10327 * @param ctx read / write interface definitions
10328 * @param val union of registers from STATUS_MASTER to
10329 * @retval interface status (MANDATORY: return 0 -> no Error)
10330 *
10331 */
lsm6dso_sh_status_get(stmdev_ctx_t * ctx,lsm6dso_status_master_t * val)10332 int32_t lsm6dso_sh_status_get(stmdev_ctx_t *ctx,
10333 lsm6dso_status_master_t *val)
10334 {
10335 int32_t ret;
10336
10337 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK);
10338
10339 if (ret == 0)
10340 {
10341 ret = lsm6dso_read_reg(ctx, LSM6DSO_STATUS_MASTER, (uint8_t *) val, 1);
10342 }
10343
10344 if (ret == 0)
10345 {
10346 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
10347 }
10348
10349 return ret;
10350 }
10351
10352 /**
10353 * @}
10354 *
10355 */
10356
10357 /**
10358 * @defgroup Basic configuration
10359 * @brief This section groups all the functions concerning
10360 * device basic configuration.
10361 * @{
10362 *
10363 */
10364
10365 /**
10366 * @brief Device "Who am I".[get]
10367 *
10368 * @param ctx communication interface handler. Use NULL to ignore
10369 * this interface.(ptr)
10370 * @param aux_ctx auxiliary communication interface handler. Use NULL
10371 * to ignore this interface.(ptr)
10372 * @param val ID values read from the two interfaces. ID values
10373 * will be the same.(ptr)
10374 * @retval interface status (MANDATORY: return 0 -> no Error)
10375 *
10376 */
lsm6dso_id_get(stmdev_ctx_t * ctx,stmdev_ctx_t * aux_ctx,lsm6dso_id_t * val)10377 int32_t lsm6dso_id_get(stmdev_ctx_t *ctx, stmdev_ctx_t *aux_ctx,
10378 lsm6dso_id_t *val)
10379 {
10380 int32_t ret = 0;
10381
10382 if (ctx != NULL)
10383 {
10384 ret = lsm6dso_read_reg(ctx, LSM6DSO_WHO_AM_I,
10385 (uint8_t *) & (val->ui), 1);
10386 }
10387
10388 if (aux_ctx != NULL)
10389 {
10390 if (ret == 0)
10391 {
10392 ret = lsm6dso_read_reg(aux_ctx, LSM6DSO_WHO_AM_I,
10393 (uint8_t *) & (val->aux), 1);
10394 }
10395 }
10396
10397 return ret;
10398 }
10399
10400 /**
10401 * @brief Re-initialize the device.[set]
10402 *
10403 * @param ctx communication interface handler.(ptr)
10404 * @param val re-initialization mode. Refer to datasheet
10405 * and application note for more information
10406 * about differencies between boot and sw_reset
10407 * procedure.
10408 * @retval interface status (MANDATORY: return 0 -> no Error)
10409 *
10410 */
lsm6dso_init_set(stmdev_ctx_t * ctx,lsm6dso_init_t val)10411 int32_t lsm6dso_init_set(stmdev_ctx_t *ctx, lsm6dso_init_t val)
10412 {
10413 lsm6dso_emb_func_init_a_t emb_func_init_a;
10414 lsm6dso_emb_func_init_b_t emb_func_init_b;
10415 lsm6dso_ctrl3_c_t ctrl3_c;
10416 int32_t ret;
10417
10418 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
10419
10420 if (ret == 0)
10421 {
10422 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_INIT_B,
10423 (uint8_t *)&emb_func_init_b, 1);
10424 }
10425
10426 if (ret == 0)
10427 {
10428 emb_func_init_b.fifo_compr_init = (uint8_t)val
10429 & ((uint8_t)LSM6DSO_FIFO_COMP >> 2);
10430 emb_func_init_b.fsm_init = (uint8_t)val
10431 & ((uint8_t)LSM6DSO_FSM >> 3);
10432 ret = lsm6dso_write_reg(ctx, LSM6DSO_EMB_FUNC_INIT_B,
10433 (uint8_t *)&emb_func_init_b, 1);
10434 }
10435
10436 if (ret == 0)
10437 {
10438 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_INIT_A,
10439 (uint8_t *)&emb_func_init_a, 1);
10440 }
10441
10442 if (ret == 0)
10443 {
10444 emb_func_init_a.step_det_init = ((uint8_t)val
10445 & (uint8_t)LSM6DSO_PEDO) >> 5;
10446 emb_func_init_a.tilt_init = ((uint8_t)val
10447 & (uint8_t)LSM6DSO_TILT) >> 6;
10448 emb_func_init_a.sig_mot_init = ((uint8_t)val
10449 & (uint8_t)LSM6DSO_SMOTION) >> 7;
10450 ret = lsm6dso_write_reg(ctx, LSM6DSO_EMB_FUNC_INIT_A,
10451 (uint8_t *)&emb_func_init_a, 1);
10452 }
10453
10454 if (ret == 0)
10455 {
10456 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
10457 }
10458
10459 if (ret == 0)
10460 {
10461 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)&ctrl3_c, 1);
10462 }
10463
10464 if (((val == LSM6DSO_BOOT) || (val == LSM6DSO_RESET)) &&
10465 (ret == 0))
10466 {
10467 ctrl3_c.boot = (uint8_t)val & (uint8_t)LSM6DSO_BOOT;
10468 ctrl3_c.sw_reset = ((uint8_t)val & (uint8_t)LSM6DSO_RESET) >> 1;
10469 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)&ctrl3_c, 1);
10470 }
10471
10472 if ((val == LSM6DSO_DRV_RDY)
10473 && ((ctrl3_c.bdu == PROPERTY_DISABLE)
10474 || (ctrl3_c.if_inc == PROPERTY_DISABLE)) && (ret == 0))
10475 {
10476 ctrl3_c.bdu = PROPERTY_ENABLE;
10477 ctrl3_c.if_inc = PROPERTY_ENABLE;
10478 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)&ctrl3_c, 1);
10479 }
10480
10481 return ret;
10482 }
10483
10484 /**
10485 * @brief Configures the bus operating mode.[set]
10486 *
10487 * @param ctx communication interface handler. Use NULL to ignore
10488 * this interface.(ptr)
10489 * @param aux_ctx auxiliary communication interface handler. Use NULL
10490 * to ignore this interface.(ptr)
10491 * @param val configures the bus operating mode for both the
10492 * main and the auxiliary interface.
10493 * @retval interface status (MANDATORY: return 0 -> no Error)
10494 *
10495 */
lsm6dso_bus_mode_set(stmdev_ctx_t * ctx,stmdev_ctx_t * aux_ctx,lsm6dso_bus_mode_t val)10496 int32_t lsm6dso_bus_mode_set(stmdev_ctx_t *ctx, stmdev_ctx_t *aux_ctx,
10497 lsm6dso_bus_mode_t val)
10498 {
10499 lsm6dso_ctrl1_ois_t ctrl1_ois;
10500 lsm6dso_i3c_bus_avb_t i3c_bus_avb;
10501 lsm6dso_ctrl9_xl_t ctrl9_xl;
10502 lsm6dso_ctrl3_c_t ctrl3_c;
10503 lsm6dso_ctrl4_c_t ctrl4_c;
10504 uint8_t bit_val;
10505 int32_t ret;
10506
10507 ret = 0;
10508
10509 if (aux_ctx != NULL)
10510 {
10511 ret = lsm6dso_read_reg(aux_ctx, LSM6DSO_CTRL1_OIS,
10512 (uint8_t *)&ctrl1_ois, 1);
10513 bit_val = ((uint8_t)val.aux_bus_md & 0x04U) >> 2;
10514
10515 if ((ret == 0) && (ctrl1_ois.sim_ois != bit_val))
10516 {
10517 ctrl1_ois.sim_ois = bit_val;
10518 ret = lsm6dso_write_reg(aux_ctx, LSM6DSO_CTRL1_OIS,
10519 (uint8_t *)&ctrl1_ois, 1);
10520 }
10521 }
10522
10523 if (ctx != NULL)
10524 {
10525 if (ret == 0)
10526 {
10527 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL,
10528 (uint8_t *)&ctrl9_xl, 1);
10529 }
10530
10531 bit_val = ((uint8_t)val.ui_bus_md & 0x04U) >> 2;
10532
10533 if ((ret == 0) && (ctrl9_xl.i3c_disable != bit_val))
10534 {
10535 ctrl9_xl.i3c_disable = bit_val;
10536 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL9_XL,
10537 (uint8_t *)&ctrl9_xl, 1);
10538 }
10539
10540 if (ret == 0)
10541 {
10542 ret = lsm6dso_read_reg(ctx, LSM6DSO_I3C_BUS_AVB,
10543 (uint8_t *)&i3c_bus_avb, 1);
10544 }
10545
10546 bit_val = ((uint8_t)val.ui_bus_md & 0x30U) >> 4;
10547
10548 if ((ret == 0) && (i3c_bus_avb.i3c_bus_avb_sel != bit_val))
10549 {
10550 i3c_bus_avb.i3c_bus_avb_sel = bit_val;
10551 ret = lsm6dso_write_reg(ctx, LSM6DSO_I3C_BUS_AVB,
10552 (uint8_t *)&i3c_bus_avb, 1);
10553 }
10554
10555 if (ret == 0)
10556 {
10557 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C,
10558 (uint8_t *)&ctrl4_c, 1);
10559 }
10560
10561 bit_val = ((uint8_t)val.ui_bus_md & 0x02U) >> 1;
10562
10563 if ((ret == 0) && (ctrl4_c.i2c_disable != bit_val))
10564 {
10565 ctrl4_c.i2c_disable = bit_val;
10566 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL4_C,
10567 (uint8_t *)&ctrl4_c, 1);
10568 }
10569
10570 if (ret == 0)
10571 {
10572 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C,
10573 (uint8_t *)&ctrl3_c, 1);
10574 }
10575
10576 bit_val = (uint8_t)val.ui_bus_md & 0x01U;
10577
10578 if ((ret == 0) && (ctrl3_c.sim != bit_val))
10579 {
10580 ctrl3_c.sim = bit_val;
10581 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_C,
10582 (uint8_t *)&ctrl3_c, 1);
10583 }
10584 }
10585
10586 return ret;
10587 }
10588
10589 /**
10590 * @brief Get the bus operating mode.[get]
10591 *
10592 * @param ctx communication interface handler. Use NULL to ignore
10593 * this interface.(ptr)
10594 * @param aux_ctx auxiliary communication interface handler. Use NULL
10595 * to ignore this interface.(ptr)
10596 * @param val retrieves the bus operating mode for both the main
10597 * and the auxiliary interface.(ptr)
10598 * @retval interface status (MANDATORY: return 0 -> no Error)
10599 *
10600 */
lsm6dso_bus_mode_get(stmdev_ctx_t * ctx,stmdev_ctx_t * aux_ctx,lsm6dso_bus_mode_t * val)10601 int32_t lsm6dso_bus_mode_get(stmdev_ctx_t *ctx, stmdev_ctx_t *aux_ctx,
10602 lsm6dso_bus_mode_t *val)
10603 {
10604 lsm6dso_ctrl1_ois_t ctrl1_ois;
10605 lsm6dso_i3c_bus_avb_t i3c_bus_avb;
10606 lsm6dso_ctrl9_xl_t ctrl9_xl;
10607 lsm6dso_ctrl3_c_t ctrl3_c;
10608 lsm6dso_ctrl4_c_t ctrl4_c;
10609 int32_t ret = 0;
10610
10611 if (aux_ctx != NULL)
10612 {
10613 ret = lsm6dso_read_reg(aux_ctx, LSM6DSO_CTRL1_OIS,
10614 (uint8_t *)&ctrl1_ois, 1);
10615
10616 switch (ctrl1_ois.sim_ois)
10617 {
10618 case LSM6DSO_SPI_4W_AUX:
10619 val->aux_bus_md = LSM6DSO_SPI_4W_AUX;
10620 break;
10621
10622 case LSM6DSO_SPI_3W_AUX:
10623 val->aux_bus_md = LSM6DSO_SPI_3W_AUX;
10624 break;
10625
10626 default:
10627 val->aux_bus_md = LSM6DSO_SPI_4W_AUX;
10628 break;
10629 }
10630 }
10631
10632 if (ctx != NULL)
10633 {
10634 if (ret == 0)
10635 {
10636 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL9_XL,
10637 (uint8_t *)&ctrl9_xl, 1);
10638 }
10639
10640 if (ret == 0)
10641 {
10642 ret = lsm6dso_read_reg(ctx, LSM6DSO_I3C_BUS_AVB,
10643 (uint8_t *)&i3c_bus_avb, 1);
10644 }
10645
10646 if (ret == 0)
10647 {
10648 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C,
10649 (uint8_t *)&ctrl4_c, 1);
10650 }
10651
10652 if (ret == 0)
10653 {
10654 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C,
10655 (uint8_t *)&ctrl3_c, 1);
10656
10657 switch ((i3c_bus_avb.i3c_bus_avb_sel << 4) &
10658 (ctrl9_xl.i3c_disable << 2) &
10659 (ctrl4_c.i2c_disable << 1) & ctrl3_c.sim)
10660 {
10661 case LSM6DSO_SEL_BY_HW:
10662 val->ui_bus_md = LSM6DSO_SEL_BY_HW;
10663 break;
10664
10665 case LSM6DSO_SPI_4W:
10666 val->ui_bus_md = LSM6DSO_SPI_4W;
10667 break;
10668
10669 case LSM6DSO_SPI_3W:
10670 val->ui_bus_md = LSM6DSO_SPI_3W;
10671 break;
10672
10673 case LSM6DSO_I2C:
10674 val->ui_bus_md = LSM6DSO_I2C;
10675 break;
10676
10677 case LSM6DSO_I3C_T_50us:
10678 val->ui_bus_md = LSM6DSO_I3C_T_50us;
10679 break;
10680
10681 case LSM6DSO_I3C_T_2us:
10682 val->ui_bus_md = LSM6DSO_I3C_T_2us;
10683 break;
10684
10685 case LSM6DSO_I3C_T_1ms:
10686 val->ui_bus_md = LSM6DSO_I3C_T_1ms;
10687 break;
10688
10689 case LSM6DSO_I3C_T_25ms:
10690 val->ui_bus_md = LSM6DSO_I3C_T_25ms;
10691 break;
10692
10693 default:
10694 val->ui_bus_md = LSM6DSO_SEL_BY_HW;
10695 break;
10696 }
10697 }
10698 }
10699
10700 return ret;
10701 }
10702
10703 /**
10704 * @brief Get the status of the device.[get]
10705 *
10706 * @param ctx communication interface handler. Use NULL to ignore
10707 * this interface.(ptr)
10708 * @param aux_ctx auxiliary communication interface handler. Use NULL
10709 * to ignore this interface.(ptr)
10710 * @param val the status of the device.(ptr)
10711 * @retval interface status (MANDATORY: return 0 -> no Error)
10712 *
10713 */
lsm6dso_status_get(stmdev_ctx_t * ctx,stmdev_ctx_t * aux_ctx,lsm6dso_status_t * val)10714 int32_t lsm6dso_status_get(stmdev_ctx_t *ctx, stmdev_ctx_t *aux_ctx,
10715 lsm6dso_status_t *val)
10716 {
10717 lsm6dso_status_spiaux_t status_spiaux;
10718 lsm6dso_status_reg_t status_reg;
10719 lsm6dso_ctrl3_c_t ctrl3_c;
10720 int32_t ret;
10721 ret = 0;
10722
10723 if (aux_ctx != NULL)
10724 {
10725 ret = lsm6dso_read_reg(aux_ctx, LSM6DSO_STATUS_SPIAUX,
10726 (uint8_t *)&status_spiaux, 1);
10727 val->ois_drdy_xl = status_spiaux.xlda;
10728 val->ois_drdy_g = status_spiaux.gda;
10729 val->ois_gyro_settling = status_spiaux.gyro_settling;
10730 }
10731
10732 if (ctx != NULL)
10733 {
10734 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)&ctrl3_c, 1);
10735 val->sw_reset = ctrl3_c.sw_reset;
10736 val->boot = ctrl3_c.boot;
10737
10738 if ((ret == 0) && (ctrl3_c.sw_reset == PROPERTY_DISABLE) &&
10739 (ctrl3_c.boot == PROPERTY_DISABLE))
10740 {
10741 ret = lsm6dso_read_reg(ctx, LSM6DSO_STATUS_REG,
10742 (uint8_t *)&status_reg, 1);
10743 val->drdy_xl = status_reg.xlda;
10744 val->drdy_g = status_reg.gda;
10745 val->drdy_temp = status_reg.tda;
10746 }
10747 }
10748
10749 return ret;
10750 }
10751
10752 /**
10753 * @brief Electrical pin configuration.[set]
10754 *
10755 * @param ctx communication interface handler.(ptr)
10756 * @param val the electrical settings for the configurable
10757 * pins.
10758 * @retval interface status (MANDATORY: return 0 -> no Error)
10759 *
10760 */
lsm6dso_pin_conf_set(stmdev_ctx_t * ctx,lsm6dso_pin_conf_t val)10761 int32_t lsm6dso_pin_conf_set(stmdev_ctx_t *ctx,
10762 lsm6dso_pin_conf_t val)
10763 {
10764 lsm6dso_i3c_bus_avb_t i3c_bus_avb;
10765 lsm6dso_pin_ctrl_t pin_ctrl;
10766 lsm6dso_ctrl3_c_t ctrl3_c;
10767 int32_t ret;
10768
10769 ret = lsm6dso_read_reg(ctx, LSM6DSO_PIN_CTRL, (uint8_t *)&pin_ctrl, 1);
10770
10771 if (ret == 0)
10772 {
10773 pin_ctrl.ois_pu_dis = ~val.aux_sdo_ocs_pull_up;
10774 pin_ctrl.sdo_pu_en = val.sdo_sa0_pull_up;
10775 ret = lsm6dso_write_reg(ctx, LSM6DSO_PIN_CTRL, (uint8_t *)&pin_ctrl, 1);
10776 }
10777
10778 if (ret == 0)
10779 {
10780 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)&ctrl3_c, 1);
10781 }
10782
10783 if (ret == 0)
10784 {
10785 ctrl3_c.pp_od = ~val.int1_int2_push_pull;
10786 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)&ctrl3_c, 1);
10787 }
10788
10789 if (ret == 0)
10790 {
10791 ret = lsm6dso_read_reg(ctx, LSM6DSO_I3C_BUS_AVB,
10792 (uint8_t *)&i3c_bus_avb, 1);
10793 }
10794
10795 if (ret == 0)
10796 {
10797 i3c_bus_avb.pd_dis_int1 = ~val.int1_pull_down;
10798 ret = lsm6dso_write_reg(ctx, LSM6DSO_I3C_BUS_AVB,
10799 (uint8_t *)&i3c_bus_avb, 1);
10800 }
10801
10802 return ret;
10803 }
10804
10805 /**
10806 * @brief Electrical pin configuration.[get]
10807 *
10808 * @param ctx communication interface handler.(ptr)
10809 * @param val the electrical settings for the configurable
10810 * pins.(ptr)
10811 * @retval interface status (MANDATORY: return 0 -> no Error)
10812 *
10813 */
lsm6dso_pin_conf_get(stmdev_ctx_t * ctx,lsm6dso_pin_conf_t * val)10814 int32_t lsm6dso_pin_conf_get(stmdev_ctx_t *ctx,
10815 lsm6dso_pin_conf_t *val)
10816 {
10817 lsm6dso_i3c_bus_avb_t i3c_bus_avb;
10818 lsm6dso_pin_ctrl_t pin_ctrl;
10819 lsm6dso_ctrl3_c_t ctrl3_c;
10820 int32_t ret;
10821
10822 ret = lsm6dso_read_reg(ctx, LSM6DSO_PIN_CTRL, (uint8_t *)&pin_ctrl, 1);
10823
10824 if (ret == 0)
10825 {
10826 val->aux_sdo_ocs_pull_up = ~pin_ctrl.ois_pu_dis;
10827 val->aux_sdo_ocs_pull_up = pin_ctrl.sdo_pu_en;
10828 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)&ctrl3_c, 1);
10829 }
10830
10831 if (ret == 0)
10832 {
10833 val->int1_int2_push_pull = ~ctrl3_c.pp_od;
10834 ret = lsm6dso_read_reg(ctx, LSM6DSO_I3C_BUS_AVB,
10835 (uint8_t *)&i3c_bus_avb, 1);
10836 }
10837
10838 if (ret == 0)
10839 {
10840 val->int1_pull_down = ~i3c_bus_avb.pd_dis_int1;
10841 }
10842
10843 return ret;
10844 }
10845
10846 /**
10847 * @brief Interrupt pins hardware signal configuration.[set]
10848 *
10849 * @param ctx communication interface handler.(ptr)
10850 * @param val the pins hardware signal settings.
10851 * @retval interface status (MANDATORY: return 0 -> no Error)
10852 *
10853 */
lsm6dso_interrupt_mode_set(stmdev_ctx_t * ctx,lsm6dso_int_mode_t val)10854 int32_t lsm6dso_interrupt_mode_set(stmdev_ctx_t *ctx,
10855 lsm6dso_int_mode_t val)
10856 {
10857 lsm6dso_tap_cfg0_t tap_cfg0;
10858 lsm6dso_page_rw_t page_rw;
10859 lsm6dso_ctrl3_c_t ctrl3_c;
10860 int32_t ret;
10861
10862 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)&ctrl3_c, 1);
10863
10864 if (ret == 0)
10865 {
10866 ctrl3_c.h_lactive = val.active_low;
10867 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)&ctrl3_c, 1);
10868 }
10869
10870 if (ret == 0)
10871 {
10872 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *) &tap_cfg0, 1);
10873 }
10874
10875 if (ret == 0)
10876 {
10877 tap_cfg0.lir = val.base_latched;
10878 tap_cfg0.int_clr_on_read = val.base_latched | val.emb_latched;
10879 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *) &tap_cfg0, 1);
10880 }
10881
10882 if (ret == 0)
10883 {
10884 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
10885 }
10886
10887 if (ret == 0)
10888 {
10889 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
10890 }
10891
10892 if (ret == 0)
10893 {
10894 page_rw.emb_func_lir = val.emb_latched;
10895 ret = lsm6dso_write_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
10896 }
10897
10898 if (ret == 0)
10899 {
10900 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
10901 }
10902
10903 return ret;
10904 }
10905
10906 /**
10907 * @brief Interrupt pins hardware signal configuration.[get]
10908 *
10909 * @param ctx communication interface handler.(ptr)
10910 * @param val the pins hardware signal settings.(ptr)
10911 * @retval interface status (MANDATORY: return 0 -> no Error)
10912 *
10913 */
lsm6dso_interrupt_mode_get(stmdev_ctx_t * ctx,lsm6dso_int_mode_t * val)10914 int32_t lsm6dso_interrupt_mode_get(stmdev_ctx_t *ctx,
10915 lsm6dso_int_mode_t *val)
10916 {
10917 lsm6dso_tap_cfg0_t tap_cfg0;
10918 lsm6dso_page_rw_t page_rw;
10919 lsm6dso_ctrl3_c_t ctrl3_c;
10920 int32_t ret;
10921
10922 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL3_C, (uint8_t *)&ctrl3_c, 1);
10923
10924 if (ret == 0)
10925 {
10926 val->active_low = ctrl3_c.h_lactive;
10927 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG0, (uint8_t *) &tap_cfg0, 1);
10928 }
10929
10930 if (ret == 0)
10931 {
10932 val->base_latched = (tap_cfg0.lir & tap_cfg0.int_clr_on_read);
10933 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
10934 }
10935
10936 if (ret == 0)
10937 {
10938 ret = lsm6dso_read_reg(ctx, LSM6DSO_PAGE_RW, (uint8_t *) &page_rw, 1);
10939 }
10940
10941 if (ret == 0)
10942 {
10943 val->emb_latched = (page_rw.emb_func_lir & tap_cfg0.int_clr_on_read);
10944 }
10945
10946 if (ret == 0)
10947 {
10948 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
10949 }
10950
10951 return ret;
10952 }
10953
10954 /**
10955 * @brief Route interrupt signals on int1 pin.[set]
10956 *
10957 * @param ctx communication interface handler.(ptr)
10958 * @param val the signals to route on int1 pin.
10959 * @retval interface status (MANDATORY: return 0 -> no Error)
10960 *
10961 */
lsm6dso_pin_int1_route_set(stmdev_ctx_t * ctx,lsm6dso_pin_int1_route_t val)10962 int32_t lsm6dso_pin_int1_route_set(stmdev_ctx_t *ctx,
10963 lsm6dso_pin_int1_route_t val)
10964 {
10965 lsm6dso_pin_int2_route_t pin_int2_route;
10966 lsm6dso_emb_func_int1_t emb_func_int1;
10967 lsm6dso_fsm_int1_a_t fsm_int1_a;
10968 lsm6dso_fsm_int1_b_t fsm_int1_b;
10969 lsm6dso_int1_ctrl_t int1_ctrl;
10970 lsm6dso_int2_ctrl_t int2_ctrl;
10971 lsm6dso_tap_cfg2_t tap_cfg2;
10972 lsm6dso_md2_cfg_t md2_cfg;
10973 lsm6dso_md1_cfg_t md1_cfg;
10974 lsm6dso_ctrl4_c_t ctrl4_c;
10975 int32_t ret;
10976 int1_ctrl.int1_drdy_xl = val.drdy_xl;
10977 int1_ctrl.int1_drdy_g = val.drdy_g;
10978 int1_ctrl.int1_boot = val.boot;
10979 int1_ctrl.int1_fifo_th = val.fifo_th;
10980 int1_ctrl.int1_fifo_ovr = val.fifo_ovr;
10981 int1_ctrl.int1_fifo_full = val.fifo_full;
10982 int1_ctrl.int1_cnt_bdr = val.fifo_bdr;
10983 int1_ctrl.den_drdy_flag = val.den_flag;
10984 md1_cfg.int1_shub = val.sh_endop;
10985 md1_cfg.int1_6d = val.six_d;
10986 md1_cfg.int1_double_tap = val.double_tap;
10987 md1_cfg.int1_ff = val.free_fall;
10988 md1_cfg.int1_wu = val.wake_up;
10989 md1_cfg.int1_single_tap = val.single_tap;
10990 md1_cfg.int1_sleep_change = val.sleep_change;
10991 emb_func_int1.not_used_01 = 0;
10992 emb_func_int1.int1_step_detector = val.step_detector;
10993 emb_func_int1.int1_tilt = val.tilt;
10994 emb_func_int1.int1_sig_mot = val.sig_mot;
10995 emb_func_int1.not_used_02 = 0;
10996 emb_func_int1.int1_fsm_lc = val.fsm_lc;
10997 fsm_int1_a.int1_fsm1 = val.fsm1;
10998 fsm_int1_a.int1_fsm2 = val.fsm2;
10999 fsm_int1_a.int1_fsm3 = val.fsm3;
11000 fsm_int1_a.int1_fsm4 = val.fsm4;
11001 fsm_int1_a.int1_fsm5 = val.fsm5;
11002 fsm_int1_a.int1_fsm6 = val.fsm6;
11003 fsm_int1_a.int1_fsm7 = val.fsm7;
11004 fsm_int1_a.int1_fsm8 = val.fsm8;
11005 fsm_int1_b.int1_fsm9 = val.fsm9 ;
11006 fsm_int1_b.int1_fsm10 = val.fsm10;
11007 fsm_int1_b.int1_fsm11 = val.fsm11;
11008 fsm_int1_b.int1_fsm12 = val.fsm12;
11009 fsm_int1_b.int1_fsm13 = val.fsm13;
11010 fsm_int1_b.int1_fsm14 = val.fsm14;
11011 fsm_int1_b.int1_fsm15 = val.fsm15;
11012 fsm_int1_b.int1_fsm16 = val.fsm16;
11013 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)&ctrl4_c, 1);
11014
11015 if (ret == 0)
11016 {
11017 if ((val.drdy_temp | val.timestamp) != PROPERTY_DISABLE)
11018 {
11019 ctrl4_c.int2_on_int1 = PROPERTY_ENABLE;
11020 }
11021
11022 else
11023 {
11024 ctrl4_c.int2_on_int1 = PROPERTY_DISABLE;
11025 }
11026
11027 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)&ctrl4_c, 1);
11028 }
11029
11030 if (ret == 0)
11031 {
11032 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
11033 }
11034
11035 if (ret == 0)
11036 {
11037 ret = lsm6dso_write_reg(ctx, LSM6DSO_EMB_FUNC_INT1,
11038 (uint8_t *)&emb_func_int1, 1);
11039 }
11040
11041 if (ret == 0)
11042 {
11043 ret = lsm6dso_write_reg(ctx, LSM6DSO_FSM_INT1_A,
11044 (uint8_t *)&fsm_int1_a, 1);
11045 }
11046
11047 if (ret == 0)
11048 {
11049 ret = lsm6dso_write_reg(ctx, LSM6DSO_FSM_INT1_B,
11050 (uint8_t *)&fsm_int1_b, 1);
11051 }
11052
11053 if (ret == 0)
11054 {
11055 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
11056 }
11057
11058 if (ret == 0)
11059 {
11060 if ((emb_func_int1.int1_fsm_lc
11061 | emb_func_int1.int1_sig_mot
11062 | emb_func_int1.int1_step_detector
11063 | emb_func_int1.int1_tilt
11064 | fsm_int1_a.int1_fsm1
11065 | fsm_int1_a.int1_fsm2
11066 | fsm_int1_a.int1_fsm3
11067 | fsm_int1_a.int1_fsm4
11068 | fsm_int1_a.int1_fsm5
11069 | fsm_int1_a.int1_fsm6
11070 | fsm_int1_a.int1_fsm7
11071 | fsm_int1_a.int1_fsm8
11072 | fsm_int1_b.int1_fsm9
11073 | fsm_int1_b.int1_fsm10
11074 | fsm_int1_b.int1_fsm11
11075 | fsm_int1_b.int1_fsm12
11076 | fsm_int1_b.int1_fsm13
11077 | fsm_int1_b.int1_fsm14
11078 | fsm_int1_b.int1_fsm15
11079 | fsm_int1_b.int1_fsm16) != PROPERTY_DISABLE)
11080 {
11081 md1_cfg.int1_emb_func = PROPERTY_ENABLE;
11082 }
11083
11084 else
11085 {
11086 md1_cfg.int1_emb_func = PROPERTY_DISABLE;
11087 }
11088
11089 ret = lsm6dso_write_reg(ctx, LSM6DSO_INT1_CTRL,
11090 (uint8_t *)&int1_ctrl, 1);
11091 }
11092
11093 if (ret == 0)
11094 {
11095 ret = lsm6dso_write_reg(ctx, LSM6DSO_MD1_CFG, (uint8_t *)&md1_cfg, 1);
11096 }
11097
11098 if (ret == 0)
11099 {
11100 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT2_CTRL, (uint8_t *)&int2_ctrl, 1);
11101 }
11102
11103 if (ret == 0)
11104 {
11105 int2_ctrl.int2_drdy_temp = val.drdy_temp;
11106 ret = lsm6dso_write_reg(ctx, LSM6DSO_INT2_CTRL, (uint8_t *)&int2_ctrl, 1);
11107 }
11108
11109 if (ret == 0)
11110 {
11111 ret = lsm6dso_read_reg(ctx, LSM6DSO_MD2_CFG, (uint8_t *)&md2_cfg, 1);
11112 }
11113
11114 if (ret == 0)
11115 {
11116 md2_cfg.int2_timestamp = val.timestamp;
11117 ret = lsm6dso_write_reg(ctx, LSM6DSO_MD2_CFG, (uint8_t *)&md2_cfg, 1);
11118 }
11119
11120 if (ret == 0)
11121 {
11122 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG2, (uint8_t *) &tap_cfg2, 1);
11123 }
11124
11125 if (ret == 0)
11126 {
11127 ret = lsm6dso_pin_int2_route_get(ctx, NULL, &pin_int2_route);
11128 }
11129
11130 if (ret == 0)
11131 {
11132 if ((pin_int2_route.fifo_bdr
11133 | pin_int2_route.drdy_g
11134 | pin_int2_route.drdy_temp
11135 | pin_int2_route.drdy_xl
11136 | pin_int2_route.fifo_full
11137 | pin_int2_route.fifo_ovr
11138 | pin_int2_route.fifo_th
11139 | pin_int2_route.six_d
11140 | pin_int2_route.double_tap
11141 | pin_int2_route.free_fall
11142 | pin_int2_route.wake_up
11143 | pin_int2_route.single_tap
11144 | pin_int2_route.sleep_change
11145 | int1_ctrl.den_drdy_flag
11146 | int1_ctrl.int1_boot
11147 | int1_ctrl.int1_cnt_bdr
11148 | int1_ctrl.int1_drdy_g
11149 | int1_ctrl.int1_drdy_xl
11150 | int1_ctrl.int1_fifo_full
11151 | int1_ctrl.int1_fifo_ovr
11152 | int1_ctrl.int1_fifo_th
11153 | md1_cfg.int1_shub
11154 | md1_cfg.int1_6d
11155 | md1_cfg.int1_double_tap
11156 | md1_cfg.int1_ff
11157 | md1_cfg.int1_wu
11158 | md1_cfg.int1_single_tap
11159 | md1_cfg.int1_sleep_change) != PROPERTY_DISABLE)
11160 {
11161 tap_cfg2.interrupts_enable = PROPERTY_ENABLE;
11162 }
11163
11164 else
11165 {
11166 tap_cfg2.interrupts_enable = PROPERTY_DISABLE;
11167 }
11168
11169 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_CFG2, (uint8_t *) &tap_cfg2, 1);
11170 }
11171
11172 return ret;
11173 }
11174
11175 /**
11176 * @brief Route interrupt signals on int1 pin.[get]
11177 *
11178 * @param ctx communication interface handler.(ptr)
11179 * @param val the signals that are routed on int1 pin.(ptr)
11180 * @retval interface status (MANDATORY: return 0 -> no Error)
11181 *
11182 */
lsm6dso_pin_int1_route_get(stmdev_ctx_t * ctx,lsm6dso_pin_int1_route_t * val)11183 int32_t lsm6dso_pin_int1_route_get(stmdev_ctx_t *ctx,
11184 lsm6dso_pin_int1_route_t *val)
11185 {
11186 lsm6dso_emb_func_int1_t emb_func_int1;
11187 lsm6dso_fsm_int1_a_t fsm_int1_a;
11188 lsm6dso_fsm_int1_b_t fsm_int1_b;
11189 lsm6dso_int1_ctrl_t int1_ctrl;
11190 lsm6dso_int2_ctrl_t int2_ctrl;
11191 lsm6dso_md2_cfg_t md2_cfg;
11192 lsm6dso_md1_cfg_t md1_cfg;
11193 lsm6dso_ctrl4_c_t ctrl4_c;
11194 int32_t ret;
11195 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
11196
11197 if (ret == 0)
11198 {
11199 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_INT1,
11200 (uint8_t *)&emb_func_int1, 1);
11201 }
11202
11203 if (ret == 0)
11204 {
11205 ret = lsm6dso_read_reg(ctx, LSM6DSO_FSM_INT1_A,
11206 (uint8_t *)&fsm_int1_a, 1);
11207 }
11208
11209 if (ret == 0)
11210 {
11211 ret = lsm6dso_read_reg(ctx, LSM6DSO_FSM_INT1_B,
11212 (uint8_t *)&fsm_int1_b, 1);
11213 }
11214
11215 if (ret == 0)
11216 {
11217 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
11218 }
11219
11220 if (ret == 0)
11221 {
11222 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT1_CTRL,
11223 (uint8_t *)&int1_ctrl, 1);
11224 }
11225
11226 if (ret == 0)
11227 {
11228 ret = lsm6dso_read_reg(ctx, LSM6DSO_MD1_CFG, (uint8_t *)&md1_cfg, 1);
11229 }
11230
11231 if (ret == 0)
11232 {
11233 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)&ctrl4_c, 1);
11234 }
11235
11236 if (ctrl4_c.int2_on_int1 == PROPERTY_ENABLE)
11237 {
11238 if (ret == 0)
11239 {
11240 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT2_CTRL, (uint8_t *)&int2_ctrl, 1);
11241 val->drdy_temp = int2_ctrl.int2_drdy_temp;
11242 }
11243
11244 if (ret == 0)
11245 {
11246 ret = lsm6dso_read_reg(ctx, LSM6DSO_MD2_CFG, (uint8_t *)&md2_cfg, 1);
11247 val->timestamp = md2_cfg.int2_timestamp;
11248 }
11249 }
11250
11251 else
11252 {
11253 val->drdy_temp = PROPERTY_DISABLE;
11254 val->timestamp = PROPERTY_DISABLE;
11255 }
11256
11257 val->drdy_xl = int1_ctrl.int1_drdy_xl;
11258 val->drdy_g = int1_ctrl.int1_drdy_g;
11259 val->boot = int1_ctrl.int1_boot;
11260 val->fifo_th = int1_ctrl.int1_fifo_th;
11261 val->fifo_ovr = int1_ctrl.int1_fifo_ovr;
11262 val->fifo_full = int1_ctrl.int1_fifo_full;
11263 val->fifo_bdr = int1_ctrl.int1_cnt_bdr;
11264 val->den_flag = int1_ctrl.den_drdy_flag;
11265 val->sh_endop = md1_cfg.int1_shub;
11266 val->six_d = md1_cfg.int1_6d;
11267 val->double_tap = md1_cfg.int1_double_tap;
11268 val->free_fall = md1_cfg.int1_ff;
11269 val->wake_up = md1_cfg.int1_wu;
11270 val->single_tap = md1_cfg.int1_single_tap;
11271 val->sleep_change = md1_cfg.int1_sleep_change;
11272 val->step_detector = emb_func_int1.int1_step_detector;
11273 val->tilt = emb_func_int1.int1_tilt;
11274 val->sig_mot = emb_func_int1.int1_sig_mot;
11275 val->fsm_lc = emb_func_int1.int1_fsm_lc;
11276 val->fsm1 = fsm_int1_a.int1_fsm1;
11277 val->fsm2 = fsm_int1_a.int1_fsm2;
11278 val->fsm3 = fsm_int1_a.int1_fsm3;
11279 val->fsm4 = fsm_int1_a.int1_fsm4;
11280 val->fsm5 = fsm_int1_a.int1_fsm5;
11281 val->fsm6 = fsm_int1_a.int1_fsm6;
11282 val->fsm7 = fsm_int1_a.int1_fsm7;
11283 val->fsm8 = fsm_int1_a.int1_fsm8;
11284 val->fsm9 = fsm_int1_b.int1_fsm9;
11285 val->fsm10 = fsm_int1_b.int1_fsm10;
11286 val->fsm11 = fsm_int1_b.int1_fsm11;
11287 val->fsm12 = fsm_int1_b.int1_fsm12;
11288 val->fsm13 = fsm_int1_b.int1_fsm13;
11289 val->fsm14 = fsm_int1_b.int1_fsm14;
11290 val->fsm15 = fsm_int1_b.int1_fsm15;
11291 val->fsm16 = fsm_int1_b.int1_fsm16;
11292
11293 return ret;
11294 }
11295
11296 /**
11297 * @brief Route interrupt signals on int2 pin.[set]
11298 *
11299 * @param ctx communication interface handler. Use NULL to ignore
11300 * this interface.(ptr)
11301 * @param aux_ctx auxiliary communication interface handler. Use NULL
11302 * to ignore this interface.(ptr)
11303 * @param val the signals to route on int2 pin.
11304 * @retval interface status (MANDATORY: return 0 -> no Error)
11305 *
11306 */
lsm6dso_pin_int2_route_set(stmdev_ctx_t * ctx,stmdev_ctx_t * aux_ctx,lsm6dso_pin_int2_route_t val)11307 int32_t lsm6dso_pin_int2_route_set(stmdev_ctx_t *ctx,
11308 stmdev_ctx_t *aux_ctx,
11309 lsm6dso_pin_int2_route_t val)
11310 {
11311 lsm6dso_pin_int1_route_t pin_int1_route;
11312 lsm6dso_emb_func_int2_t emb_func_int2;
11313 lsm6dso_fsm_int2_a_t fsm_int2_a;
11314 lsm6dso_fsm_int2_b_t fsm_int2_b;
11315 lsm6dso_int2_ctrl_t int2_ctrl;
11316 lsm6dso_tap_cfg2_t tap_cfg2;
11317 lsm6dso_md2_cfg_t md2_cfg;
11318 lsm6dso_ctrl4_c_t ctrl4_c;
11319 lsm6dso_int_ois_t int_ois;
11320 int32_t ret;
11321 ret = 0;
11322
11323 if (aux_ctx != NULL)
11324 {
11325 ret = lsm6dso_read_reg(aux_ctx, LSM6DSO_INT_OIS,
11326 (uint8_t *)&int_ois, 1);
11327
11328 if (ret == 0)
11329 {
11330 int_ois.int2_drdy_ois = val.drdy_ois;
11331 ret = lsm6dso_write_reg(aux_ctx, LSM6DSO_INT_OIS,
11332 (uint8_t *)&int_ois, 1);
11333 }
11334 }
11335
11336 if (ctx != NULL)
11337 {
11338 int2_ctrl.int2_drdy_xl = val.drdy_xl;
11339 int2_ctrl.int2_drdy_g = val.drdy_g;
11340 int2_ctrl.int2_drdy_temp = val.drdy_temp;
11341 int2_ctrl.int2_fifo_th = val.fifo_th;
11342 int2_ctrl.int2_fifo_ovr = val.fifo_ovr;
11343 int2_ctrl.int2_fifo_full = val.fifo_full;
11344 int2_ctrl.int2_cnt_bdr = val.fifo_bdr;
11345 int2_ctrl.not_used_01 = 0;
11346 md2_cfg.int2_timestamp = val.timestamp;
11347 md2_cfg.int2_6d = val.six_d;
11348 md2_cfg.int2_double_tap = val.double_tap;
11349 md2_cfg.int2_ff = val.free_fall;
11350 md2_cfg.int2_wu = val.wake_up;
11351 md2_cfg.int2_single_tap = val.single_tap;
11352 md2_cfg.int2_sleep_change = val.sleep_change;
11353 emb_func_int2.not_used_01 = 0;
11354 emb_func_int2. int2_step_detector = val.step_detector;
11355 emb_func_int2.int2_tilt = val.tilt;
11356 emb_func_int2.int2_sig_mot = val.sig_mot;
11357 emb_func_int2.not_used_02 = 0;
11358 emb_func_int2.int2_fsm_lc = val.fsm_lc;
11359 fsm_int2_a.int2_fsm1 = val.fsm1;
11360 fsm_int2_a.int2_fsm2 = val.fsm2;
11361 fsm_int2_a.int2_fsm3 = val.fsm3;
11362 fsm_int2_a.int2_fsm4 = val.fsm4;
11363 fsm_int2_a.int2_fsm5 = val.fsm5;
11364 fsm_int2_a.int2_fsm6 = val.fsm6;
11365 fsm_int2_a.int2_fsm7 = val.fsm7;
11366 fsm_int2_a.int2_fsm8 = val.fsm8;
11367 fsm_int2_b.int2_fsm9 = val.fsm9 ;
11368 fsm_int2_b.int2_fsm10 = val.fsm10;
11369 fsm_int2_b.int2_fsm11 = val.fsm11;
11370 fsm_int2_b.int2_fsm12 = val.fsm12;
11371 fsm_int2_b.int2_fsm13 = val.fsm13;
11372 fsm_int2_b.int2_fsm14 = val.fsm14;
11373 fsm_int2_b.int2_fsm15 = val.fsm15;
11374 fsm_int2_b.int2_fsm16 = val.fsm16;
11375
11376 if (ret == 0)
11377 {
11378 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)&ctrl4_c, 1);
11379
11380 if (ret == 0)
11381 {
11382 if ((val.drdy_temp | val.timestamp) != PROPERTY_DISABLE)
11383 {
11384 ctrl4_c.int2_on_int1 = PROPERTY_DISABLE;
11385 }
11386
11387 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)&ctrl4_c, 1);
11388 }
11389 }
11390
11391 if (ret == 0)
11392 {
11393 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
11394 }
11395
11396 if (ret == 0)
11397 {
11398 ret = lsm6dso_write_reg(ctx, LSM6DSO_EMB_FUNC_INT2,
11399 (uint8_t *)&emb_func_int2, 1);
11400 }
11401
11402 if (ret == 0)
11403 {
11404 ret = lsm6dso_write_reg(ctx, LSM6DSO_FSM_INT2_A,
11405 (uint8_t *)&fsm_int2_a, 1);
11406 }
11407
11408 if (ret == 0)
11409 {
11410 ret = lsm6dso_write_reg(ctx, LSM6DSO_FSM_INT2_B,
11411 (uint8_t *)&fsm_int2_b, 1);
11412 }
11413
11414 if (ret == 0)
11415 {
11416 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
11417 }
11418
11419 if (ret == 0)
11420 {
11421 if ((emb_func_int2.int2_fsm_lc
11422 | emb_func_int2.int2_sig_mot
11423 | emb_func_int2.int2_step_detector
11424 | emb_func_int2.int2_tilt
11425 | fsm_int2_a.int2_fsm1
11426 | fsm_int2_a.int2_fsm2
11427 | fsm_int2_a.int2_fsm3
11428 | fsm_int2_a.int2_fsm4
11429 | fsm_int2_a.int2_fsm5
11430 | fsm_int2_a.int2_fsm6
11431 | fsm_int2_a.int2_fsm7
11432 | fsm_int2_a.int2_fsm8
11433 | fsm_int2_b.int2_fsm9
11434 | fsm_int2_b.int2_fsm10
11435 | fsm_int2_b.int2_fsm11
11436 | fsm_int2_b.int2_fsm12
11437 | fsm_int2_b.int2_fsm13
11438 | fsm_int2_b.int2_fsm14
11439 | fsm_int2_b.int2_fsm15
11440 | fsm_int2_b.int2_fsm16) != PROPERTY_DISABLE)
11441 {
11442 md2_cfg.int2_emb_func = PROPERTY_ENABLE;
11443 }
11444
11445 else
11446 {
11447 md2_cfg.int2_emb_func = PROPERTY_DISABLE;
11448 }
11449
11450 ret = lsm6dso_write_reg(ctx, LSM6DSO_INT2_CTRL,
11451 (uint8_t *)&int2_ctrl, 1);
11452 }
11453
11454 if (ret == 0)
11455 {
11456 ret = lsm6dso_write_reg(ctx, LSM6DSO_MD2_CFG, (uint8_t *)&md2_cfg, 1);
11457 }
11458
11459 if (ret == 0)
11460 {
11461 ret = lsm6dso_read_reg(ctx, LSM6DSO_TAP_CFG2, (uint8_t *) &tap_cfg2, 1);
11462 }
11463
11464 if (ret == 0)
11465 {
11466 ret = lsm6dso_pin_int1_route_get(ctx, &pin_int1_route);
11467 }
11468
11469 if (ret == 0)
11470 {
11471 if ((val.fifo_bdr
11472 | val.drdy_g
11473 | val.drdy_temp
11474 | val.drdy_xl
11475 | val.fifo_full
11476 | val.fifo_ovr
11477 | val.fifo_th
11478 | val.six_d
11479 | val.double_tap
11480 | val.free_fall
11481 | val.wake_up
11482 | val.single_tap
11483 | val.sleep_change
11484 | pin_int1_route.den_flag
11485 | pin_int1_route.boot
11486 | pin_int1_route.fifo_bdr
11487 | pin_int1_route.drdy_g
11488 | pin_int1_route.drdy_xl
11489 | pin_int1_route.fifo_full
11490 | pin_int1_route.fifo_ovr
11491 | pin_int1_route.fifo_th
11492 | pin_int1_route.six_d
11493 | pin_int1_route.double_tap
11494 | pin_int1_route.free_fall
11495 | pin_int1_route.wake_up
11496 | pin_int1_route.single_tap
11497 | pin_int1_route.sleep_change) != PROPERTY_DISABLE)
11498 {
11499 tap_cfg2.interrupts_enable = PROPERTY_ENABLE;
11500 }
11501
11502 else
11503 {
11504 tap_cfg2.interrupts_enable = PROPERTY_DISABLE;
11505 }
11506
11507 ret = lsm6dso_write_reg(ctx, LSM6DSO_TAP_CFG2, (uint8_t *) &tap_cfg2, 1);
11508 }
11509 }
11510
11511 return ret;
11512 }
11513
11514 /**
11515 * @brief Route interrupt signals on int2 pin.[get]
11516 *
11517 * @param ctx communication interface handler. Use NULL to ignore
11518 * this interface.(ptr)
11519 * @param aux_ctx auxiliary communication interface handler. Use NULL
11520 * to ignore this interface.(ptr)
11521 * @param val the signals that are routed on int2 pin.(ptr)
11522 * @retval interface status (MANDATORY: return 0 -> no Error)
11523 *
11524 */
lsm6dso_pin_int2_route_get(stmdev_ctx_t * ctx,stmdev_ctx_t * aux_ctx,lsm6dso_pin_int2_route_t * val)11525 int32_t lsm6dso_pin_int2_route_get(stmdev_ctx_t *ctx,
11526 stmdev_ctx_t *aux_ctx,
11527 lsm6dso_pin_int2_route_t *val)
11528 {
11529 lsm6dso_emb_func_int2_t emb_func_int2;
11530 lsm6dso_fsm_int2_a_t fsm_int2_a;
11531 lsm6dso_fsm_int2_b_t fsm_int2_b;
11532 lsm6dso_int2_ctrl_t int2_ctrl;
11533 lsm6dso_md2_cfg_t md2_cfg;
11534 lsm6dso_ctrl4_c_t ctrl4_c;
11535 lsm6dso_int_ois_t int_ois;
11536 int32_t ret;
11537 ret = 0;
11538
11539 if (aux_ctx != NULL)
11540 {
11541 ret = lsm6dso_read_reg(aux_ctx, LSM6DSO_INT_OIS,
11542 (uint8_t *)&int_ois, 1);
11543 val->drdy_ois = int_ois.int2_drdy_ois;
11544 }
11545
11546 if (ctx != NULL)
11547 {
11548 if (ret == 0)
11549 {
11550 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
11551 }
11552
11553 if (ret == 0)
11554 {
11555 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_INT2,
11556 (uint8_t *)&emb_func_int2, 1);
11557 }
11558
11559 if (ret == 0)
11560 {
11561 ret = lsm6dso_read_reg(ctx, LSM6DSO_FSM_INT2_A,
11562 (uint8_t *)&fsm_int2_a, 1);
11563 }
11564
11565 if (ret == 0)
11566 {
11567 ret = lsm6dso_read_reg(ctx, LSM6DSO_FSM_INT2_B,
11568 (uint8_t *)&fsm_int2_b, 1);
11569 }
11570
11571 if (ret == 0)
11572 {
11573 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
11574 }
11575
11576 if (ret == 0)
11577 {
11578 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT2_CTRL,
11579 (uint8_t *)&int2_ctrl, 1);
11580 }
11581
11582 if (ret == 0)
11583 {
11584 ret = lsm6dso_read_reg(ctx, LSM6DSO_MD2_CFG,
11585 (uint8_t *)&md2_cfg, 1);
11586 }
11587
11588 if (ret == 0)
11589 {
11590 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL4_C, (uint8_t *)&ctrl4_c, 1);
11591 }
11592
11593 if (ctrl4_c.int2_on_int1 == PROPERTY_DISABLE)
11594 {
11595 if (ret == 0)
11596 {
11597 ret = lsm6dso_read_reg(ctx, LSM6DSO_INT2_CTRL,
11598 (uint8_t *)&int2_ctrl, 1);
11599 val->drdy_temp = int2_ctrl.int2_drdy_temp;
11600 }
11601
11602 if (ret == 0)
11603 {
11604 ret = lsm6dso_read_reg(ctx, LSM6DSO_MD2_CFG, (uint8_t *)&md2_cfg, 1);
11605 val->timestamp = md2_cfg.int2_timestamp;
11606 }
11607 }
11608
11609 else
11610 {
11611 val->drdy_temp = PROPERTY_DISABLE;
11612 val->timestamp = PROPERTY_DISABLE;
11613 }
11614
11615 val->drdy_xl = int2_ctrl.int2_drdy_xl;
11616 val->drdy_g = int2_ctrl.int2_drdy_g;
11617 val->drdy_temp = int2_ctrl.int2_drdy_temp;
11618 val->fifo_th = int2_ctrl.int2_fifo_th;
11619 val->fifo_ovr = int2_ctrl.int2_fifo_ovr;
11620 val->fifo_full = int2_ctrl.int2_fifo_full;
11621 val->fifo_bdr = int2_ctrl.int2_cnt_bdr;
11622 val->timestamp = md2_cfg.int2_timestamp;
11623 val->six_d = md2_cfg.int2_6d;
11624 val->double_tap = md2_cfg.int2_double_tap;
11625 val->free_fall = md2_cfg.int2_ff;
11626 val->wake_up = md2_cfg.int2_wu;
11627 val->single_tap = md2_cfg.int2_single_tap;
11628 val->sleep_change = md2_cfg.int2_sleep_change;
11629 val->step_detector = emb_func_int2. int2_step_detector;
11630 val->tilt = emb_func_int2.int2_tilt;
11631 val->fsm_lc = emb_func_int2.int2_fsm_lc;
11632 val->fsm1 = fsm_int2_a.int2_fsm1;
11633 val->fsm2 = fsm_int2_a.int2_fsm2;
11634 val->fsm3 = fsm_int2_a.int2_fsm3;
11635 val->fsm4 = fsm_int2_a.int2_fsm4;
11636 val->fsm5 = fsm_int2_a.int2_fsm5;
11637 val->fsm6 = fsm_int2_a.int2_fsm6;
11638 val->fsm7 = fsm_int2_a.int2_fsm7;
11639 val->fsm8 = fsm_int2_a.int2_fsm8;
11640 val->fsm9 = fsm_int2_b.int2_fsm9;
11641 val->fsm10 = fsm_int2_b.int2_fsm10;
11642 val->fsm11 = fsm_int2_b.int2_fsm11;
11643 val->fsm12 = fsm_int2_b.int2_fsm12;
11644 val->fsm13 = fsm_int2_b.int2_fsm13;
11645 val->fsm14 = fsm_int2_b.int2_fsm14;
11646 val->fsm15 = fsm_int2_b.int2_fsm15;
11647 val->fsm16 = fsm_int2_b.int2_fsm16;
11648 }
11649
11650 return ret;
11651 }
11652
11653 /**
11654 * @brief Get the status of all the interrupt sources.[get]
11655 *
11656 * @param ctx communication interface handler.(ptr)
11657 * @param val the status of all the interrupt sources.(ptr)
11658 * @retval interface status (MANDATORY: return 0 -> no Error)
11659 *
11660 */
lsm6dso_all_sources_get(stmdev_ctx_t * ctx,lsm6dso_all_sources_t * val)11661 int32_t lsm6dso_all_sources_get(stmdev_ctx_t *ctx,
11662 lsm6dso_all_sources_t *val)
11663 {
11664 lsm6dso_emb_func_status_mainpage_t emb_func_status_mainpage;
11665 lsm6dso_status_master_mainpage_t status_master_mainpage;
11666 lsm6dso_fsm_status_a_mainpage_t fsm_status_a_mainpage;
11667 lsm6dso_fsm_status_b_mainpage_t fsm_status_b_mainpage;
11668 lsm6dso_fifo_status1_t fifo_status1;
11669 lsm6dso_fifo_status2_t fifo_status2;
11670 lsm6dso_all_int_src_t all_int_src;
11671 lsm6dso_wake_up_src_t wake_up_src;
11672 lsm6dso_status_reg_t status_reg;
11673 lsm6dso_tap_src_t tap_src;
11674 lsm6dso_d6d_src_t d6d_src;
11675 uint8_t reg[5];
11676 int32_t ret;
11677 ret = lsm6dso_read_reg(ctx, LSM6DSO_ALL_INT_SRC, reg, 5);
11678
11679 if (ret == 0)
11680 {
11681 bytecpy((uint8_t *)&all_int_src, ®[0]);
11682 bytecpy((uint8_t *)&wake_up_src, ®[1]);
11683 bytecpy((uint8_t *)&tap_src, ®[2]);
11684 bytecpy((uint8_t *)&d6d_src, ®[3]);
11685 bytecpy((uint8_t *)&status_reg, ®[4]);
11686 val->timestamp = all_int_src.timestamp_endcount;
11687 val->wake_up_z = wake_up_src.z_wu;
11688 val->wake_up_y = wake_up_src.y_wu;
11689 val->wake_up_x = wake_up_src.x_wu;
11690 val->wake_up = wake_up_src.wu_ia;
11691 val->sleep_state = wake_up_src.sleep_state;
11692 val->free_fall = wake_up_src.ff_ia;
11693 val->sleep_change = wake_up_src.sleep_change_ia;
11694 val->tap_x = tap_src.x_tap;
11695 val->tap_y = tap_src.y_tap;
11696 val->tap_z = tap_src.z_tap;
11697 val->tap_sign = tap_src.tap_sign;
11698 val->double_tap = tap_src.double_tap;
11699 val->single_tap = tap_src.single_tap;
11700 val->six_d_xl = d6d_src.xl;
11701 val->six_d_xh = d6d_src.xh;
11702 val->six_d_yl = d6d_src.yl;
11703 val->six_d_yh = d6d_src.yh;
11704 val->six_d_zl = d6d_src.zl;
11705 val->six_d_zh = d6d_src.zh;
11706 val->six_d = d6d_src.d6d_ia;
11707 val->den_flag = d6d_src.den_drdy;
11708 val->drdy_xl = status_reg.xlda;
11709 val->drdy_g = status_reg.gda;
11710 val->drdy_temp = status_reg.tda;
11711 }
11712
11713 if (ret == 0)
11714 {
11715 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_STATUS_MAINPAGE, reg, 3);
11716 }
11717
11718 if (ret == 0)
11719 {
11720 bytecpy((uint8_t *)&emb_func_status_mainpage, ®[0]);
11721 bytecpy((uint8_t *)&fsm_status_a_mainpage, ®[1]);
11722 bytecpy((uint8_t *)&fsm_status_b_mainpage, ®[2]);
11723 val->step_detector = emb_func_status_mainpage.is_step_det;
11724 val->tilt = emb_func_status_mainpage.is_tilt;
11725 val->sig_mot = emb_func_status_mainpage.is_sigmot;
11726 val->fsm_lc = emb_func_status_mainpage.is_fsm_lc;
11727 val->fsm1 = fsm_status_a_mainpage.is_fsm1;
11728 val->fsm2 = fsm_status_a_mainpage.is_fsm2;
11729 val->fsm3 = fsm_status_a_mainpage.is_fsm3;
11730 val->fsm4 = fsm_status_a_mainpage.is_fsm4;
11731 val->fsm5 = fsm_status_a_mainpage.is_fsm5;
11732 val->fsm6 = fsm_status_a_mainpage.is_fsm6;
11733 val->fsm7 = fsm_status_a_mainpage.is_fsm7;
11734 val->fsm8 = fsm_status_a_mainpage.is_fsm8;
11735 val->fsm9 = fsm_status_b_mainpage.is_fsm9;
11736 val->fsm10 = fsm_status_b_mainpage.is_fsm10;
11737 val->fsm11 = fsm_status_b_mainpage.is_fsm11;
11738 val->fsm12 = fsm_status_b_mainpage.is_fsm12;
11739 val->fsm13 = fsm_status_b_mainpage.is_fsm13;
11740 val->fsm14 = fsm_status_b_mainpage.is_fsm14;
11741 val->fsm15 = fsm_status_b_mainpage.is_fsm15;
11742 val->fsm16 = fsm_status_b_mainpage.is_fsm16;
11743 }
11744
11745 if (ret == 0)
11746 {
11747 ret = lsm6dso_read_reg(ctx, LSM6DSO_STATUS_MASTER_MAINPAGE, reg, 3);
11748 }
11749
11750 if (ret == 0)
11751 {
11752 bytecpy((uint8_t *)&status_master_mainpage, ®[0]);
11753 bytecpy((uint8_t *)&fifo_status1, ®[1]);
11754 bytecpy((uint8_t *)&fifo_status2, ®[2]);
11755 val->sh_endop = status_master_mainpage.sens_hub_endop;
11756 val->sh_slave0_nack = status_master_mainpage.slave0_nack;
11757 val->sh_slave1_nack = status_master_mainpage.slave1_nack;
11758 val->sh_slave2_nack = status_master_mainpage.slave2_nack;
11759 val->sh_slave3_nack = status_master_mainpage.slave3_nack;
11760 val->sh_wr_once = status_master_mainpage.wr_once_done;
11761 val->fifo_diff = (256U * fifo_status2.diff_fifo) +
11762 fifo_status1.diff_fifo;
11763 val->fifo_ovr_latched = fifo_status2.over_run_latched;
11764 val->fifo_bdr = fifo_status2.counter_bdr_ia;
11765 val->fifo_full = fifo_status2.fifo_full_ia;
11766 val->fifo_ovr = fifo_status2.fifo_ovr_ia;
11767 val->fifo_th = fifo_status2.fifo_wtm_ia;
11768 }
11769
11770 return ret;
11771 }
11772
11773 /*
11774 * `-Wmaybe-uninitialized` warning is disabled for the `lsm6dso_mode_set`
11775 * function because GCC 12 and above may report a false positive warning
11776 * claiming that the `ctrl2_ois` variable may be used uninitialized.
11777 */
11778 #if defined(__GNUC__)
11779 #pragma GCC diagnostic push
11780 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
11781 #endif
11782
11783 /**
11784 * @brief Sensor conversion parameters selection.[set]
11785 *
11786 * @param ctx communication interface handler. Use NULL to ignore
11787 * this interface.(ptr)
11788 * @param aux_ctx auxiliary communication interface handler. Use NULL
11789 * to ignore this interface.(ptr)
11790 * @param val set the sensor conversion parameters by checking
11791 * the constraints of the device.(ptr)
11792 * @retval interface status (MANDATORY: return 0 -> no Error)
11793 *
11794 */
lsm6dso_mode_set(stmdev_ctx_t * ctx,stmdev_ctx_t * aux_ctx,lsm6dso_md_t * val)11795 int32_t lsm6dso_mode_set(stmdev_ctx_t *ctx, stmdev_ctx_t *aux_ctx,
11796 lsm6dso_md_t *val)
11797 {
11798 lsm6dso_func_cfg_access_t func_cfg_access;
11799 lsm6dso_ctrl1_ois_t ctrl1_ois;
11800 lsm6dso_ctrl2_ois_t ctrl2_ois;
11801 lsm6dso_ctrl3_ois_t ctrl3_ois;
11802 lsm6dso_ctrl1_xl_t ctrl1_xl;
11803 lsm6dso_ctrl8_xl_t ctrl8_xl;
11804 lsm6dso_ctrl2_g_t ctrl2_g;
11805 lsm6dso_ctrl3_c_t ctrl3_c;
11806 lsm6dso_ctrl4_c_t ctrl4_c;
11807 lsm6dso_ctrl5_c_t ctrl5_c;
11808 lsm6dso_ctrl6_c_t ctrl6_c;
11809 lsm6dso_ctrl7_g_t ctrl7_g;
11810 uint8_t xl_hm_mode;
11811 uint8_t g_hm_mode;
11812 uint8_t xl_ulp_en;
11813 uint8_t odr_gy;
11814 uint8_t odr_xl;
11815 uint8_t reg[8];
11816 int32_t ret;
11817
11818 ret = 0;
11819 /* FIXME: Remove warnings with STM32CubeIDE */
11820 ctrl3_c.not_used_01 = 0;
11821 ctrl4_c.not_used_01 = 0;
11822 /* reading input configuration */
11823 xl_hm_mode = ((uint8_t)val->ui.xl.odr & 0x10U) >> 4;
11824 xl_ulp_en = ((uint8_t)val->ui.xl.odr & 0x20U) >> 5;
11825 odr_xl = (uint8_t)val->ui.xl.odr & 0x0FU;
11826
11827 /* if enable xl ultra low power mode disable gy and OIS chain */
11828 if (xl_ulp_en == PROPERTY_ENABLE)
11829 {
11830 val->ois.xl.odr = LSM6DSO_XL_OIS_OFF;
11831 val->ois.gy.odr = LSM6DSO_GY_OIS_OFF;
11832 val->ui.gy.odr = LSM6DSO_GY_UI_OFF;
11833 }
11834
11835 /* if OIS xl is enabled also gyro OIS is enabled */
11836 if (val->ois.xl.odr == LSM6DSO_XL_OIS_6667Hz_HP)
11837 {
11838 val->ois.gy.odr = LSM6DSO_GY_OIS_6667Hz_HP;
11839 }
11840
11841 g_hm_mode = ((uint8_t)val->ui.gy.odr & 0x10U) >> 4;
11842 odr_gy = (uint8_t)val->ui.gy.odr & 0x0FU;
11843
11844 /* reading registers to be configured */
11845 if (ctx != NULL)
11846 {
11847 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_XL, reg, 8);
11848 bytecpy((uint8_t *)&ctrl1_xl, ®[0]);
11849 bytecpy((uint8_t *)&ctrl2_g, ®[1]);
11850 bytecpy((uint8_t *)&ctrl3_c, ®[2]);
11851 bytecpy((uint8_t *)&ctrl4_c, ®[3]);
11852 bytecpy((uint8_t *)&ctrl5_c, ®[4]);
11853 bytecpy((uint8_t *)&ctrl6_c, ®[5]);
11854 bytecpy((uint8_t *)&ctrl7_g, ®[6]);
11855 bytecpy((uint8_t *)&ctrl8_xl, ®[7]);
11856
11857 if (ret == 0)
11858 {
11859 ret = lsm6dso_read_reg(ctx, LSM6DSO_FUNC_CFG_ACCESS,
11860 (uint8_t *)&func_cfg_access, 1);
11861 }
11862
11863 /* if toggle xl ultra low power mode, turn off xl before reconfigure */
11864 if (ctrl5_c.xl_ulp_en != xl_ulp_en)
11865 {
11866 ctrl1_xl.odr_xl = (uint8_t) 0x00U;
11867 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL1_XL,
11868 (uint8_t *)&ctrl1_xl, 1);
11869 }
11870 }
11871
11872 /* reading OIS registers to be configured */
11873 if (aux_ctx != NULL)
11874 {
11875 if (ret == 0)
11876 {
11877 ret = lsm6dso_read_reg(aux_ctx, LSM6DSO_CTRL1_OIS, reg, 3);
11878 }
11879
11880 bytecpy((uint8_t *)&ctrl1_ois, ®[0]);
11881 bytecpy((uint8_t *)&ctrl2_ois, ®[1]);
11882 bytecpy((uint8_t *)&ctrl3_ois, ®[2]);
11883 }
11884
11885 else
11886 {
11887 if (ctx != NULL)
11888 {
11889 if (ret == 0)
11890 {
11891 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_OIS, reg, 3);
11892 }
11893
11894 bytecpy((uint8_t *)&ctrl1_ois, ®[0]);
11895 bytecpy((uint8_t *)&ctrl2_ois, ®[1]);
11896 bytecpy((uint8_t *)&ctrl3_ois, ®[2]);
11897 }
11898 }
11899
11900 /* Check the Finite State Machine data rate constraints */
11901 if (val->fsm.sens != LSM6DSO_FSM_DISABLE)
11902 {
11903 switch (val->fsm.odr)
11904 {
11905 case LSM6DSO_FSM_12Hz5:
11906 if ((val->fsm.sens != LSM6DSO_FSM_GY) && (odr_xl == 0x00U))
11907 {
11908 odr_xl = 0x01U;
11909 }
11910
11911 if ((val->fsm.sens != LSM6DSO_FSM_XL) && (odr_gy == 0x00U))
11912 {
11913 xl_ulp_en = PROPERTY_DISABLE;
11914 odr_gy = 0x01U;
11915 }
11916
11917 break;
11918
11919 case LSM6DSO_FSM_26Hz:
11920 if ((val->fsm.sens != LSM6DSO_FSM_GY) && (odr_xl < 0x02U))
11921 {
11922 odr_xl = 0x02U;
11923 }
11924
11925 if ((val->fsm.sens != LSM6DSO_FSM_XL) && (odr_gy < 0x02U))
11926 {
11927 xl_ulp_en = PROPERTY_DISABLE;
11928 odr_gy = 0x02U;
11929 }
11930
11931 break;
11932
11933 case LSM6DSO_FSM_52Hz:
11934 if ((val->fsm.sens != LSM6DSO_FSM_GY) && (odr_xl < 0x03U))
11935 {
11936 odr_xl = 0x03U;
11937 }
11938
11939 if ((val->fsm.sens != LSM6DSO_FSM_XL) && (odr_gy < 0x03U))
11940 {
11941 xl_ulp_en = PROPERTY_DISABLE;
11942 odr_gy = 0x03U;
11943 }
11944
11945 break;
11946
11947 case LSM6DSO_FSM_104Hz:
11948 if ((val->fsm.sens != LSM6DSO_FSM_GY) && (odr_xl < 0x04U))
11949 {
11950 odr_xl = 0x04U;
11951 }
11952
11953 if ((val->fsm.sens != LSM6DSO_FSM_XL) && (odr_gy < 0x04U))
11954 {
11955 xl_ulp_en = PROPERTY_DISABLE;
11956 odr_gy = 0x04U;
11957 }
11958
11959 break;
11960
11961 default:
11962 odr_xl = 0x00U;
11963 odr_gy = 0x00U;
11964 break;
11965 }
11966 }
11967
11968 /* Updating the accelerometer data rate configuration */
11969 switch ((ctrl5_c.xl_ulp_en << 5) | (ctrl6_c.xl_hm_mode << 4) |
11970 ctrl1_xl.odr_xl)
11971 {
11972 case LSM6DSO_XL_UI_OFF:
11973 val->ui.xl.odr = LSM6DSO_XL_UI_OFF;
11974 break;
11975
11976 case LSM6DSO_XL_UI_12Hz5_HP:
11977 val->ui.xl.odr = LSM6DSO_XL_UI_12Hz5_HP;
11978 break;
11979
11980 case LSM6DSO_XL_UI_26Hz_HP:
11981 val->ui.xl.odr = LSM6DSO_XL_UI_26Hz_HP;
11982 break;
11983
11984 case LSM6DSO_XL_UI_52Hz_HP:
11985 val->ui.xl.odr = LSM6DSO_XL_UI_52Hz_HP;
11986 break;
11987
11988 case LSM6DSO_XL_UI_104Hz_HP:
11989 val->ui.xl.odr = LSM6DSO_XL_UI_104Hz_HP;
11990 break;
11991
11992 case LSM6DSO_XL_UI_208Hz_HP:
11993 val->ui.xl.odr = LSM6DSO_XL_UI_208Hz_HP;
11994 break;
11995
11996 case LSM6DSO_XL_UI_416Hz_HP:
11997 val->ui.xl.odr = LSM6DSO_XL_UI_416Hz_HP;
11998 break;
11999
12000 case LSM6DSO_XL_UI_833Hz_HP:
12001 val->ui.xl.odr = LSM6DSO_XL_UI_833Hz_HP;
12002 break;
12003
12004 case LSM6DSO_XL_UI_1667Hz_HP:
12005 val->ui.xl.odr = LSM6DSO_XL_UI_1667Hz_HP;
12006 break;
12007
12008 case LSM6DSO_XL_UI_3333Hz_HP:
12009 val->ui.xl.odr = LSM6DSO_XL_UI_3333Hz_HP;
12010 break;
12011
12012 case LSM6DSO_XL_UI_6667Hz_HP:
12013 val->ui.xl.odr = LSM6DSO_XL_UI_6667Hz_HP;
12014 break;
12015
12016 case LSM6DSO_XL_UI_1Hz6_LP:
12017 val->ui.xl.odr = LSM6DSO_XL_UI_1Hz6_LP;
12018 break;
12019
12020 case LSM6DSO_XL_UI_12Hz5_LP:
12021 val->ui.xl.odr = LSM6DSO_XL_UI_12Hz5_LP;
12022 break;
12023
12024 case LSM6DSO_XL_UI_26Hz_LP:
12025 val->ui.xl.odr = LSM6DSO_XL_UI_26Hz_LP;
12026 break;
12027
12028 case LSM6DSO_XL_UI_52Hz_LP:
12029 val->ui.xl.odr = LSM6DSO_XL_UI_52Hz_LP;
12030 break;
12031
12032 case LSM6DSO_XL_UI_104Hz_NM:
12033 val->ui.xl.odr = LSM6DSO_XL_UI_104Hz_NM;
12034 break;
12035
12036 case LSM6DSO_XL_UI_208Hz_NM:
12037 val->ui.xl.odr = LSM6DSO_XL_UI_208Hz_NM;
12038 break;
12039
12040 case LSM6DSO_XL_UI_1Hz6_ULP:
12041 val->ui.xl.odr = LSM6DSO_XL_UI_1Hz6_ULP;
12042 break;
12043
12044 case LSM6DSO_XL_UI_12Hz5_ULP:
12045 val->ui.xl.odr = LSM6DSO_XL_UI_12Hz5_ULP;
12046 break;
12047
12048 case LSM6DSO_XL_UI_26Hz_ULP:
12049 val->ui.xl.odr = LSM6DSO_XL_UI_26Hz_ULP;
12050 break;
12051
12052 case LSM6DSO_XL_UI_52Hz_ULP:
12053 val->ui.xl.odr = LSM6DSO_XL_UI_52Hz_ULP;
12054 break;
12055
12056 case LSM6DSO_XL_UI_104Hz_ULP:
12057 val->ui.xl.odr = LSM6DSO_XL_UI_104Hz_ULP;
12058 break;
12059
12060 case LSM6DSO_XL_UI_208Hz_ULP:
12061 val->ui.xl.odr = LSM6DSO_XL_UI_208Hz_ULP;
12062 break;
12063
12064 default:
12065 val->ui.xl.odr = LSM6DSO_XL_UI_OFF;
12066 break;
12067 }
12068
12069 /* Updating the accelerometer data rate configuration */
12070 switch ((ctrl7_g.g_hm_mode << 4) | ctrl2_g.odr_g)
12071 {
12072 case LSM6DSO_GY_UI_OFF:
12073 val->ui.gy.odr = LSM6DSO_GY_UI_OFF;
12074 break;
12075
12076 case LSM6DSO_GY_UI_12Hz5_LP:
12077 val->ui.gy.odr = LSM6DSO_GY_UI_12Hz5_LP;
12078 break;
12079
12080 case LSM6DSO_GY_UI_12Hz5_HP:
12081 val->ui.gy.odr = LSM6DSO_GY_UI_12Hz5_HP;
12082 break;
12083
12084 case LSM6DSO_GY_UI_26Hz_LP:
12085 val->ui.gy.odr = LSM6DSO_GY_UI_26Hz_LP;
12086 break;
12087
12088 case LSM6DSO_GY_UI_26Hz_HP:
12089 val->ui.gy.odr = LSM6DSO_GY_UI_26Hz_HP;
12090 break;
12091
12092 case LSM6DSO_GY_UI_52Hz_LP:
12093 val->ui.gy.odr = LSM6DSO_GY_UI_52Hz_LP;
12094 break;
12095
12096 case LSM6DSO_GY_UI_52Hz_HP:
12097 val->ui.gy.odr = LSM6DSO_GY_UI_52Hz_HP;
12098 break;
12099
12100 case LSM6DSO_GY_UI_104Hz_NM:
12101 val->ui.gy.odr = LSM6DSO_GY_UI_104Hz_NM;
12102 break;
12103
12104 case LSM6DSO_GY_UI_104Hz_HP:
12105 val->ui.gy.odr = LSM6DSO_GY_UI_104Hz_HP;
12106 break;
12107
12108 case LSM6DSO_GY_UI_208Hz_NM:
12109 val->ui.gy.odr = LSM6DSO_GY_UI_208Hz_NM;
12110 break;
12111
12112 case LSM6DSO_GY_UI_208Hz_HP:
12113 val->ui.gy.odr = LSM6DSO_GY_UI_208Hz_HP;
12114 break;
12115
12116 case LSM6DSO_GY_UI_416Hz_HP:
12117 val->ui.gy.odr = LSM6DSO_GY_UI_416Hz_HP;
12118 break;
12119
12120 case LSM6DSO_GY_UI_833Hz_HP:
12121 val->ui.gy.odr = LSM6DSO_GY_UI_833Hz_HP;
12122 break;
12123
12124 case LSM6DSO_GY_UI_1667Hz_HP:
12125 val->ui.gy.odr = LSM6DSO_GY_UI_1667Hz_HP;
12126 break;
12127
12128 case LSM6DSO_GY_UI_3333Hz_HP:
12129 val->ui.gy.odr = LSM6DSO_GY_UI_3333Hz_HP;
12130 break;
12131
12132 case LSM6DSO_GY_UI_6667Hz_HP:
12133 val->ui.gy.odr = LSM6DSO_GY_UI_6667Hz_HP;
12134 break;
12135
12136 default:
12137 val->ui.gy.odr = LSM6DSO_GY_UI_OFF;
12138 break;
12139 }
12140
12141 /* Check accelerometer full scale constraints */
12142 /* Full scale of 16g must be the same for UI and OIS */
12143 if ((val->ui.xl.fs == LSM6DSO_XL_UI_16g) ||
12144 (val->ois.xl.fs == LSM6DSO_XL_OIS_16g))
12145 {
12146 val->ui.xl.fs = LSM6DSO_XL_UI_16g;
12147 val->ois.xl.fs = LSM6DSO_XL_OIS_16g;
12148 }
12149
12150 /* prapare new configuration */
12151
12152 /* Full scale of 16g must be the same for UI and OIS */
12153 if (val->ui.xl.fs == LSM6DSO_XL_UI_16g)
12154 {
12155 ctrl8_xl.xl_fs_mode = PROPERTY_DISABLE;
12156 }
12157
12158 else
12159 {
12160 ctrl8_xl.xl_fs_mode = PROPERTY_ENABLE;
12161 }
12162
12163 /* OIS new configuration */
12164 ctrl7_g.ois_on_en = val->ois.ctrl_md & 0x01U;
12165
12166 switch (val->ois.ctrl_md)
12167 {
12168 case LSM6DSO_OIS_ONLY_AUX:
12169 ctrl1_ois.fs_g_ois = (uint8_t)val->ois.gy.fs;
12170 ctrl1_ois.ois_en_spi2 = (uint8_t)val->ois.gy.odr |
12171 (uint8_t)val->ois.xl.odr;
12172 ctrl1_ois.mode4_en = (uint8_t) val->ois.xl.odr;
12173 ctrl3_ois.fs_xl_ois = (uint8_t)val->ois.xl.fs;
12174 break;
12175
12176 case LSM6DSO_OIS_MIXED:
12177 ctrl1_ois.fs_g_ois = (uint8_t)val->ois.gy.fs;
12178 ctrl7_g.ois_on = (uint8_t)val->ois.gy.odr | (uint8_t)val->ois.xl.odr;
12179 ctrl1_ois.mode4_en = (uint8_t) val->ois.xl.odr;
12180 ctrl3_ois.fs_xl_ois = (uint8_t)val->ois.xl.fs;
12181 break;
12182
12183 default:
12184 ctrl1_ois.fs_g_ois = (uint8_t)val->ois.gy.fs;
12185 ctrl1_ois.ois_en_spi2 = (uint8_t)val->ois.gy.odr |
12186 (uint8_t)val->ois.xl.odr;
12187 ctrl1_ois.mode4_en = (uint8_t) val->ois.xl.odr;
12188 ctrl3_ois.fs_xl_ois = (uint8_t)val->ois.xl.fs;
12189 break;
12190 }
12191
12192 /* UI new configuration */
12193 ctrl1_xl.odr_xl = odr_xl;
12194 ctrl1_xl.fs_xl = (uint8_t)val->ui.xl.fs;
12195 ctrl5_c.xl_ulp_en = xl_ulp_en;
12196 ctrl6_c.xl_hm_mode = xl_hm_mode;
12197 ctrl7_g.g_hm_mode = g_hm_mode;
12198 ctrl2_g.odr_g = odr_gy;
12199 ctrl2_g.fs_g = (uint8_t) val->ui.gy.fs;
12200
12201 /* writing checked configuration */
12202 if (ctx != NULL)
12203 {
12204 bytecpy(®[0], (uint8_t *)&ctrl1_xl);
12205 bytecpy(®[1], (uint8_t *)&ctrl2_g);
12206 bytecpy(®[2], (uint8_t *)&ctrl3_c);
12207 bytecpy(®[3], (uint8_t *)&ctrl4_c);
12208 bytecpy(®[4], (uint8_t *)&ctrl5_c);
12209 bytecpy(®[5], (uint8_t *)&ctrl6_c);
12210 bytecpy(®[6], (uint8_t *)&ctrl7_g);
12211 bytecpy(®[7], (uint8_t *)&ctrl8_xl);
12212
12213 if (ret == 0)
12214 {
12215 ret = lsm6dso_write_reg(ctx, LSM6DSO_CTRL1_XL, (uint8_t *)®, 8);
12216 }
12217
12218 if (ret == 0)
12219 {
12220 ret = lsm6dso_write_reg(ctx, LSM6DSO_FUNC_CFG_ACCESS,
12221 (uint8_t *)&func_cfg_access, 1);
12222 }
12223 }
12224
12225 /* writing OIS checked configuration */
12226 if (aux_ctx != NULL)
12227 {
12228 bytecpy(®[0], (uint8_t *)&ctrl1_ois);
12229 bytecpy(®[1], (uint8_t *)&ctrl2_ois);
12230 bytecpy(®[2], (uint8_t *)&ctrl3_ois);
12231
12232 if (ret == 0)
12233 {
12234 ret = lsm6dso_write_reg(aux_ctx, LSM6DSO_CTRL1_OIS, reg, 3);
12235 }
12236 }
12237
12238 return ret;
12239 }
12240
12241 #if defined(__GNUC__)
12242 #pragma GCC diagnostic pop
12243 #endif
12244
12245 /**
12246 * @brief Sensor conversion parameters selection.[get]
12247 *
12248 * @param ctx communication interface handler. Use NULL to ignore
12249 * this interface.(ptr)
12250 * @param aux_ctx auxiliary communication interface handler. Use NULL
12251 * to ignore this interface.(ptr)
12252 * @param val get the sensor conversion parameters.(ptr)
12253 * @retval interface status (MANDATORY: return 0 -> no Error)
12254 *
12255 */
lsm6dso_mode_get(stmdev_ctx_t * ctx,stmdev_ctx_t * aux_ctx,lsm6dso_md_t * val)12256 int32_t lsm6dso_mode_get(stmdev_ctx_t *ctx, stmdev_ctx_t *aux_ctx,
12257 lsm6dso_md_t *val)
12258 {
12259 lsm6dso_emb_func_odr_cfg_b_t emb_func_odr_cfg_b;
12260 lsm6dso_func_cfg_access_t func_cfg_access;
12261 lsm6dso_emb_func_en_b_t emb_func_en_b;
12262 lsm6dso_fsm_enable_a_t fsm_enable_a;
12263 lsm6dso_fsm_enable_b_t fsm_enable_b;
12264 lsm6dso_ctrl1_ois_t ctrl1_ois;
12265 lsm6dso_ctrl2_ois_t ctrl2_ois;
12266 lsm6dso_ctrl3_ois_t ctrl3_ois;
12267 lsm6dso_ctrl1_xl_t ctrl1_xl;
12268 lsm6dso_ctrl2_g_t ctrl2_g;
12269 lsm6dso_ctrl3_c_t ctrl3_c;
12270 lsm6dso_ctrl4_c_t ctrl4_c;
12271 lsm6dso_ctrl5_c_t ctrl5_c;
12272 lsm6dso_ctrl6_c_t ctrl6_c;
12273 lsm6dso_ctrl7_g_t ctrl7_g;
12274 uint8_t reg[8];
12275 int32_t ret;
12276
12277 ret = 0;
12278
12279 /* reading the registers of the device */
12280 if (ctx != NULL)
12281 {
12282 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_XL, reg, 7);
12283 bytecpy((uint8_t *)&ctrl1_xl, ®[0]);
12284 bytecpy((uint8_t *)&ctrl2_g, ®[1]);
12285 bytecpy((uint8_t *)&ctrl3_c, ®[2]);
12286 bytecpy((uint8_t *)&ctrl4_c, ®[3]);
12287 bytecpy((uint8_t *)&ctrl5_c, ®[4]);
12288 bytecpy((uint8_t *)&ctrl6_c, ®[5]);
12289 bytecpy((uint8_t *)&ctrl7_g, ®[6]);
12290
12291 if (ret == 0)
12292 {
12293 ret = lsm6dso_read_reg(ctx, LSM6DSO_FUNC_CFG_ACCESS,
12294 (uint8_t *)&func_cfg_access, 1);
12295 }
12296
12297 if (ret == 0)
12298 {
12299 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
12300 }
12301
12302 if (ret == 0)
12303 {
12304 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_ODR_CFG_B, reg, 1);
12305 bytecpy((uint8_t *)&emb_func_odr_cfg_b, ®[0]);
12306 }
12307
12308 if (ret == 0)
12309 {
12310 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_EN_B,
12311 (uint8_t *)&emb_func_en_b, 1);
12312 }
12313
12314 if (ret == 0)
12315 {
12316 ret = lsm6dso_read_reg(ctx, LSM6DSO_FSM_ENABLE_A, reg, 2);
12317 bytecpy((uint8_t *)&fsm_enable_a, ®[0]);
12318 bytecpy((uint8_t *)&fsm_enable_b, ®[1]);
12319 }
12320
12321 if (ret == 0)
12322 {
12323 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
12324 }
12325 }
12326
12327 if (aux_ctx != NULL)
12328 {
12329 if (ret == 0)
12330 {
12331 ret = lsm6dso_read_reg(aux_ctx, LSM6DSO_CTRL1_OIS, reg, 3);
12332 }
12333
12334 bytecpy((uint8_t *)&ctrl1_ois, ®[0]);
12335 bytecpy((uint8_t *)&ctrl2_ois, ®[1]);
12336 bytecpy((uint8_t *)&ctrl3_ois, ®[2]);
12337 }
12338
12339 else
12340 {
12341 if (ctx != NULL)
12342 {
12343 if (ret == 0)
12344 {
12345 ret = lsm6dso_read_reg(ctx, LSM6DSO_CTRL1_OIS, reg, 3);
12346 }
12347
12348 bytecpy((uint8_t *)&ctrl1_ois, ®[0]);
12349 bytecpy((uint8_t *)&ctrl2_ois, ®[1]);
12350 bytecpy((uint8_t *)&ctrl3_ois, ®[2]);
12351 }
12352 }
12353
12354 /* fill the input structure */
12355
12356 /* get accelerometer configuration */
12357 switch ((ctrl5_c.xl_ulp_en << 5) | (ctrl6_c.xl_hm_mode << 4) |
12358 ctrl1_xl.odr_xl)
12359 {
12360 case LSM6DSO_XL_UI_OFF:
12361 val->ui.xl.odr = LSM6DSO_XL_UI_OFF;
12362 break;
12363
12364 case LSM6DSO_XL_UI_12Hz5_HP:
12365 val->ui.xl.odr = LSM6DSO_XL_UI_12Hz5_HP;
12366 break;
12367
12368 case LSM6DSO_XL_UI_26Hz_HP:
12369 val->ui.xl.odr = LSM6DSO_XL_UI_26Hz_HP;
12370 break;
12371
12372 case LSM6DSO_XL_UI_52Hz_HP:
12373 val->ui.xl.odr = LSM6DSO_XL_UI_52Hz_HP;
12374 break;
12375
12376 case LSM6DSO_XL_UI_104Hz_HP:
12377 val->ui.xl.odr = LSM6DSO_XL_UI_104Hz_HP;
12378 break;
12379
12380 case LSM6DSO_XL_UI_208Hz_HP:
12381 val->ui.xl.odr = LSM6DSO_XL_UI_208Hz_HP;
12382 break;
12383
12384 case LSM6DSO_XL_UI_416Hz_HP:
12385 val->ui.xl.odr = LSM6DSO_XL_UI_416Hz_HP;
12386 break;
12387
12388 case LSM6DSO_XL_UI_833Hz_HP:
12389 val->ui.xl.odr = LSM6DSO_XL_UI_833Hz_HP;
12390 break;
12391
12392 case LSM6DSO_XL_UI_1667Hz_HP:
12393 val->ui.xl.odr = LSM6DSO_XL_UI_1667Hz_HP;
12394 break;
12395
12396 case LSM6DSO_XL_UI_3333Hz_HP:
12397 val->ui.xl.odr = LSM6DSO_XL_UI_3333Hz_HP;
12398 break;
12399
12400 case LSM6DSO_XL_UI_6667Hz_HP:
12401 val->ui.xl.odr = LSM6DSO_XL_UI_6667Hz_HP;
12402 break;
12403
12404 case LSM6DSO_XL_UI_1Hz6_LP:
12405 val->ui.xl.odr = LSM6DSO_XL_UI_1Hz6_LP;
12406 break;
12407
12408 case LSM6DSO_XL_UI_12Hz5_LP:
12409 val->ui.xl.odr = LSM6DSO_XL_UI_12Hz5_LP;
12410 break;
12411
12412 case LSM6DSO_XL_UI_26Hz_LP:
12413 val->ui.xl.odr = LSM6DSO_XL_UI_26Hz_LP;
12414 break;
12415
12416 case LSM6DSO_XL_UI_52Hz_LP:
12417 val->ui.xl.odr = LSM6DSO_XL_UI_52Hz_LP;
12418 break;
12419
12420 case LSM6DSO_XL_UI_104Hz_NM:
12421 val->ui.xl.odr = LSM6DSO_XL_UI_104Hz_NM;
12422 break;
12423
12424 case LSM6DSO_XL_UI_208Hz_NM:
12425 val->ui.xl.odr = LSM6DSO_XL_UI_208Hz_NM;
12426 break;
12427
12428 case LSM6DSO_XL_UI_1Hz6_ULP:
12429 val->ui.xl.odr = LSM6DSO_XL_UI_1Hz6_ULP;
12430 break;
12431
12432 case LSM6DSO_XL_UI_12Hz5_ULP:
12433 val->ui.xl.odr = LSM6DSO_XL_UI_12Hz5_ULP;
12434 break;
12435
12436 case LSM6DSO_XL_UI_26Hz_ULP:
12437 val->ui.xl.odr = LSM6DSO_XL_UI_26Hz_ULP;
12438 break;
12439
12440 case LSM6DSO_XL_UI_52Hz_ULP:
12441 val->ui.xl.odr = LSM6DSO_XL_UI_52Hz_ULP;
12442 break;
12443
12444 case LSM6DSO_XL_UI_104Hz_ULP:
12445 val->ui.xl.odr = LSM6DSO_XL_UI_104Hz_ULP;
12446 break;
12447
12448 case LSM6DSO_XL_UI_208Hz_ULP:
12449 val->ui.xl.odr = LSM6DSO_XL_UI_208Hz_ULP;
12450 break;
12451
12452 default:
12453 val->ui.xl.odr = LSM6DSO_XL_UI_OFF;
12454 break;
12455 }
12456
12457 switch (ctrl1_xl.fs_xl)
12458 {
12459 case LSM6DSO_XL_UI_2g:
12460 val->ui.xl.fs = LSM6DSO_XL_UI_2g;
12461 break;
12462
12463 case LSM6DSO_XL_UI_4g:
12464 val->ui.xl.fs = LSM6DSO_XL_UI_4g;
12465 break;
12466
12467 case LSM6DSO_XL_UI_8g:
12468 val->ui.xl.fs = LSM6DSO_XL_UI_8g;
12469 break;
12470
12471 case LSM6DSO_XL_UI_16g:
12472 val->ui.xl.fs = LSM6DSO_XL_UI_16g;
12473 break;
12474
12475 default:
12476 val->ui.xl.fs = LSM6DSO_XL_UI_2g;
12477 break;
12478 }
12479
12480 /* get gyroscope configuration */
12481 switch ((ctrl7_g.g_hm_mode << 4) | ctrl2_g.odr_g)
12482 {
12483 case LSM6DSO_GY_UI_OFF:
12484 val->ui.gy.odr = LSM6DSO_GY_UI_OFF;
12485 break;
12486
12487 case LSM6DSO_GY_UI_12Hz5_LP:
12488 val->ui.gy.odr = LSM6DSO_GY_UI_12Hz5_LP;
12489 break;
12490
12491 case LSM6DSO_GY_UI_12Hz5_HP:
12492 val->ui.gy.odr = LSM6DSO_GY_UI_12Hz5_HP;
12493 break;
12494
12495 case LSM6DSO_GY_UI_26Hz_LP:
12496 val->ui.gy.odr = LSM6DSO_GY_UI_26Hz_LP;
12497 break;
12498
12499 case LSM6DSO_GY_UI_26Hz_HP:
12500 val->ui.gy.odr = LSM6DSO_GY_UI_26Hz_HP;
12501 break;
12502
12503 case LSM6DSO_GY_UI_52Hz_LP:
12504 val->ui.gy.odr = LSM6DSO_GY_UI_52Hz_LP;
12505 break;
12506
12507 case LSM6DSO_GY_UI_52Hz_HP:
12508 val->ui.gy.odr = LSM6DSO_GY_UI_52Hz_HP;
12509 break;
12510
12511 case LSM6DSO_GY_UI_104Hz_NM:
12512 val->ui.gy.odr = LSM6DSO_GY_UI_104Hz_NM;
12513 break;
12514
12515 case LSM6DSO_GY_UI_104Hz_HP:
12516 val->ui.gy.odr = LSM6DSO_GY_UI_104Hz_HP;
12517 break;
12518
12519 case LSM6DSO_GY_UI_208Hz_NM:
12520 val->ui.gy.odr = LSM6DSO_GY_UI_208Hz_NM;
12521 break;
12522
12523 case LSM6DSO_GY_UI_208Hz_HP:
12524 val->ui.gy.odr = LSM6DSO_GY_UI_208Hz_HP;
12525 break;
12526
12527 case LSM6DSO_GY_UI_416Hz_HP:
12528 val->ui.gy.odr = LSM6DSO_GY_UI_416Hz_HP;
12529 break;
12530
12531 case LSM6DSO_GY_UI_833Hz_HP:
12532 val->ui.gy.odr = LSM6DSO_GY_UI_833Hz_HP;
12533 break;
12534
12535 case LSM6DSO_GY_UI_1667Hz_HP:
12536 val->ui.gy.odr = LSM6DSO_GY_UI_1667Hz_HP;
12537 break;
12538
12539 case LSM6DSO_GY_UI_3333Hz_HP:
12540 val->ui.gy.odr = LSM6DSO_GY_UI_3333Hz_HP;
12541 break;
12542
12543 case LSM6DSO_GY_UI_6667Hz_HP:
12544 val->ui.gy.odr = LSM6DSO_GY_UI_6667Hz_HP;
12545 break;
12546
12547 default:
12548 val->ui.gy.odr = LSM6DSO_GY_UI_OFF;
12549 break;
12550 }
12551
12552 switch (ctrl2_g.fs_g)
12553 {
12554 case LSM6DSO_GY_UI_125dps:
12555 val->ui.gy.fs = LSM6DSO_GY_UI_125dps;
12556 break;
12557
12558 case LSM6DSO_GY_UI_250dps:
12559 val->ui.gy.fs = LSM6DSO_GY_UI_250dps;
12560 break;
12561
12562 case LSM6DSO_GY_UI_500dps:
12563 val->ui.gy.fs = LSM6DSO_GY_UI_500dps;
12564 break;
12565
12566 case LSM6DSO_GY_UI_1000dps:
12567 val->ui.gy.fs = LSM6DSO_GY_UI_1000dps;
12568 break;
12569
12570 case LSM6DSO_GY_UI_2000dps:
12571 val->ui.gy.fs = LSM6DSO_GY_UI_2000dps;
12572 break;
12573
12574 default:
12575 val->ui.gy.fs = LSM6DSO_GY_UI_125dps;
12576 break;
12577 }
12578
12579 /* get finite state machine configuration */
12580 if ((fsm_enable_a.fsm1_en | fsm_enable_a.fsm2_en |
12581 fsm_enable_a.fsm3_en |
12582 fsm_enable_a.fsm4_en | fsm_enable_a.fsm5_en | fsm_enable_a.fsm6_en |
12583 fsm_enable_a.fsm7_en | fsm_enable_a.fsm8_en | fsm_enable_b.fsm9_en |
12584 fsm_enable_b.fsm10_en | fsm_enable_b.fsm11_en |
12585 fsm_enable_b.fsm12_en | fsm_enable_b.fsm13_en |
12586 fsm_enable_b.fsm14_en | fsm_enable_b.fsm15_en |
12587 fsm_enable_b.fsm16_en) == PROPERTY_ENABLE)
12588 {
12589 switch (emb_func_odr_cfg_b.fsm_odr)
12590 {
12591 case LSM6DSO_FSM_12Hz5:
12592 val->fsm.odr = LSM6DSO_FSM_12Hz5;
12593 break;
12594
12595 case LSM6DSO_FSM_26Hz:
12596 val->fsm.odr = LSM6DSO_FSM_26Hz;
12597 break;
12598
12599 case LSM6DSO_FSM_52Hz:
12600 val->fsm.odr = LSM6DSO_FSM_52Hz;
12601 break;
12602
12603 case LSM6DSO_FSM_104Hz:
12604 val->fsm.odr = LSM6DSO_FSM_104Hz;
12605 break;
12606
12607 default:
12608 val->fsm.odr = LSM6DSO_FSM_12Hz5;
12609 break;
12610 }
12611
12612 val->fsm.sens = LSM6DSO_FSM_XL_GY;
12613
12614 if (val->ui.gy.odr == LSM6DSO_GY_UI_OFF)
12615 {
12616 val->fsm.sens = LSM6DSO_FSM_XL;
12617 }
12618
12619 if (val->ui.xl.odr == LSM6DSO_XL_UI_OFF)
12620 {
12621 val->fsm.sens = LSM6DSO_FSM_GY;
12622 }
12623 }
12624
12625 else
12626 {
12627 val->fsm.sens = LSM6DSO_FSM_DISABLE;
12628 }
12629
12630 /* get ois configuration */
12631
12632 /* OIS configuration mode */
12633 switch (ctrl7_g.ois_on_en)
12634 {
12635 case LSM6DSO_OIS_ONLY_AUX:
12636 switch (ctrl3_ois.fs_xl_ois)
12637 {
12638 case LSM6DSO_XL_OIS_2g:
12639 val->ois.xl.fs = LSM6DSO_XL_OIS_2g;
12640 break;
12641
12642 case LSM6DSO_XL_OIS_4g:
12643 val->ois.xl.fs = LSM6DSO_XL_OIS_4g;
12644 break;
12645
12646 case LSM6DSO_XL_OIS_8g:
12647 val->ois.xl.fs = LSM6DSO_XL_OIS_8g;
12648 break;
12649
12650 case LSM6DSO_XL_OIS_16g:
12651 val->ois.xl.fs = LSM6DSO_XL_OIS_16g;
12652 break;
12653
12654 default:
12655 val->ois.xl.fs = LSM6DSO_XL_OIS_2g;
12656 break;
12657 }
12658
12659 switch (ctrl1_ois.mode4_en)
12660 {
12661 case LSM6DSO_XL_OIS_OFF:
12662 val->ois.xl.odr = LSM6DSO_XL_OIS_OFF;
12663 break;
12664
12665 case LSM6DSO_XL_OIS_6667Hz_HP:
12666 val->ois.xl.odr = LSM6DSO_XL_OIS_6667Hz_HP;
12667 break;
12668
12669 default:
12670 val->ois.xl.odr = LSM6DSO_XL_OIS_OFF;
12671 break;
12672 }
12673
12674 switch (ctrl1_ois.fs_g_ois)
12675 {
12676 case LSM6DSO_GY_OIS_250dps:
12677 val->ois.gy.fs = LSM6DSO_GY_OIS_250dps;
12678 break;
12679
12680 case LSM6DSO_GY_OIS_500dps:
12681 val->ois.gy.fs = LSM6DSO_GY_OIS_500dps;
12682 break;
12683
12684 case LSM6DSO_GY_OIS_1000dps:
12685 val->ois.gy.fs = LSM6DSO_GY_OIS_1000dps;
12686 break;
12687
12688 case LSM6DSO_GY_OIS_2000dps:
12689 val->ois.gy.fs = LSM6DSO_GY_OIS_2000dps;
12690 break;
12691
12692 default:
12693 val->ois.gy.fs = LSM6DSO_GY_OIS_250dps;
12694 break;
12695 }
12696
12697 switch (ctrl1_ois.ois_en_spi2)
12698 {
12699 case LSM6DSO_GY_OIS_OFF:
12700 val->ois.gy.odr = LSM6DSO_GY_OIS_OFF;
12701 break;
12702
12703 case LSM6DSO_GY_OIS_6667Hz_HP:
12704 val->ois.gy.odr = LSM6DSO_GY_OIS_6667Hz_HP;
12705 break;
12706
12707 default:
12708 val->ois.gy.odr = LSM6DSO_GY_OIS_OFF;
12709 break;
12710 }
12711
12712 val->ois.ctrl_md = LSM6DSO_OIS_ONLY_AUX;
12713 break;
12714
12715 case LSM6DSO_OIS_MIXED:
12716 switch (ctrl3_ois.fs_xl_ois)
12717 {
12718 case LSM6DSO_XL_OIS_2g:
12719 val->ois.xl.fs = LSM6DSO_XL_OIS_2g;
12720 break;
12721
12722 case LSM6DSO_XL_OIS_4g:
12723 val->ois.xl.fs = LSM6DSO_XL_OIS_4g;
12724 break;
12725
12726 case LSM6DSO_XL_OIS_8g:
12727 val->ois.xl.fs = LSM6DSO_XL_OIS_8g;
12728 break;
12729
12730 case LSM6DSO_XL_OIS_16g:
12731 val->ois.xl.fs = LSM6DSO_XL_OIS_16g;
12732 break;
12733
12734 default:
12735 val->ois.xl.fs = LSM6DSO_XL_OIS_2g;
12736 break;
12737 }
12738
12739 switch (ctrl1_ois.mode4_en)
12740 {
12741 case LSM6DSO_XL_OIS_OFF:
12742 val->ois.xl.odr = LSM6DSO_XL_OIS_OFF;
12743 break;
12744
12745 case LSM6DSO_XL_OIS_6667Hz_HP:
12746 val->ois.xl.odr = LSM6DSO_XL_OIS_6667Hz_HP;
12747 break;
12748
12749 default:
12750 val->ois.xl.odr = LSM6DSO_XL_OIS_OFF;
12751 break;
12752 }
12753
12754 switch (ctrl1_ois.fs_g_ois)
12755 {
12756 case LSM6DSO_GY_OIS_250dps:
12757 val->ois.gy.fs = LSM6DSO_GY_OIS_250dps;
12758 break;
12759
12760 case LSM6DSO_GY_OIS_500dps:
12761 val->ois.gy.fs = LSM6DSO_GY_OIS_500dps;
12762 break;
12763
12764 case LSM6DSO_GY_OIS_1000dps:
12765 val->ois.gy.fs = LSM6DSO_GY_OIS_1000dps;
12766 break;
12767
12768 case LSM6DSO_GY_OIS_2000dps:
12769 val->ois.gy.fs = LSM6DSO_GY_OIS_2000dps;
12770 break;
12771
12772 default:
12773 val->ois.gy.fs = LSM6DSO_GY_OIS_250dps;
12774 break;
12775 }
12776
12777 switch (ctrl1_ois.ois_en_spi2)
12778 {
12779 case LSM6DSO_GY_OIS_OFF:
12780 val->ois.gy.odr = LSM6DSO_GY_OIS_OFF;
12781 break;
12782
12783 case LSM6DSO_GY_OIS_6667Hz_HP:
12784 val->ois.gy.odr = LSM6DSO_GY_OIS_6667Hz_HP;
12785 break;
12786
12787 default:
12788 val->ois.gy.odr = LSM6DSO_GY_OIS_OFF;
12789 break;
12790 }
12791
12792 val->ois.ctrl_md = LSM6DSO_OIS_MIXED;
12793 break;
12794
12795 default:
12796 ctrl1_ois.fs_g_ois = (uint8_t)val->ois.gy.fs;
12797 ctrl1_ois.ois_en_spi2 = (uint8_t)val->ois.gy.odr |
12798 (uint8_t)val->ois.xl.odr;
12799 ctrl1_ois.mode4_en = (uint8_t) val->ois.xl.odr;
12800 ctrl3_ois.fs_xl_ois = (uint8_t)val->ois.xl.fs;
12801 val->ois.ctrl_md = LSM6DSO_OIS_ONLY_AUX;
12802 break;
12803 }
12804
12805 return ret;
12806 }
12807
12808 /**
12809 * @brief Read data in engineering unit.[get]
12810 *
12811 * @param ctx communication interface handler.(ptr)
12812 * @param md the sensor conversion parameters.(ptr)
12813 * @retval interface status (MANDATORY: return 0 -> no Error)
12814 *
12815 */
lsm6dso_data_get(stmdev_ctx_t * ctx,stmdev_ctx_t * aux_ctx,lsm6dso_md_t * md,lsm6dso_data_t * data)12816 int32_t lsm6dso_data_get(stmdev_ctx_t *ctx, stmdev_ctx_t *aux_ctx,
12817 lsm6dso_md_t *md, lsm6dso_data_t *data)
12818 {
12819 uint8_t buff[14];
12820 int32_t ret;
12821
12822 uint8_t i;
12823 uint8_t j;
12824 ret = 0;
12825
12826 /* read data */
12827 if (ctx != NULL)
12828 {
12829 ret = lsm6dso_read_reg(ctx, LSM6DSO_OUT_TEMP_L, buff, 14);
12830 }
12831
12832 j = 0;
12833 /* temperature conversion */
12834 data->ui.heat.raw = (int16_t)buff[j + 1U];
12835 data->ui.heat.raw = (((int16_t)data->ui.heat.raw * (int16_t)256) +
12836 (int16_t)buff[j]);
12837 j += 2U;
12838 data->ui.heat.deg_c = lsm6dso_from_lsb_to_celsius((
12839 int16_t)data->ui.heat.raw);
12840
12841 /* angular rate conversion */
12842 for (i = 0U; i < 3U; i++)
12843 {
12844 data->ui.gy.raw[i] = (int16_t)buff[j + 1U];
12845 data->ui.gy.raw[i] = (data->ui.gy.raw[i] * 256) + (int16_t) buff[j];
12846 j += 2U;
12847
12848 switch (md->ui.gy.fs)
12849 {
12850 case LSM6DSO_GY_UI_250dps:
12851 data->ui.gy.mdps[i] = lsm6dso_from_fs250_to_mdps(data->ui.gy.raw[i]);
12852 break;
12853
12854 case LSM6DSO_GY_UI_125dps:
12855 data->ui.gy.mdps[i] = lsm6dso_from_fs125_to_mdps(data->ui.gy.raw[i]);
12856 break;
12857
12858 case LSM6DSO_GY_UI_500dps:
12859 data->ui.gy.mdps[i] = lsm6dso_from_fs500_to_mdps(data->ui.gy.raw[i]);
12860 break;
12861
12862 case LSM6DSO_GY_UI_1000dps:
12863 data->ui.gy.mdps[i] = lsm6dso_from_fs1000_to_mdps(data->ui.gy.raw[i]);
12864 break;
12865
12866 case LSM6DSO_GY_UI_2000dps:
12867 data->ui.gy.mdps[i] = lsm6dso_from_fs2000_to_mdps(data->ui.gy.raw[i]);
12868 break;
12869
12870 default:
12871 data->ui.gy.mdps[i] = 0.0f;
12872 break;
12873 }
12874 }
12875
12876 /* acceleration conversion */
12877 for (i = 0U; i < 3U; i++)
12878 {
12879 data->ui.xl.raw[i] = (int16_t)buff[j + 1U];
12880 data->ui.xl.raw[i] = (data->ui.xl.raw[i] * 256) + (int16_t) buff[j];
12881 j += 2U;
12882
12883 switch (md->ui.xl.fs)
12884 {
12885 case LSM6DSO_XL_UI_2g:
12886 data->ui.xl.mg[i] = lsm6dso_from_fs2_to_mg(data->ui.xl.raw[i]);
12887 break;
12888
12889 case LSM6DSO_XL_UI_4g:
12890 data->ui.xl.mg[i] = lsm6dso_from_fs4_to_mg(data->ui.xl.raw[i]);
12891 break;
12892
12893 case LSM6DSO_XL_UI_8g:
12894 data->ui.xl.mg[i] = lsm6dso_from_fs8_to_mg(data->ui.xl.raw[i]);
12895 break;
12896
12897 case LSM6DSO_XL_UI_16g:
12898 data->ui.xl.mg[i] = lsm6dso_from_fs16_to_mg(data->ui.xl.raw[i]);
12899 break;
12900
12901 default:
12902 data->ui.xl.mg[i] = 0.0f;
12903 break;
12904 }
12905 }
12906
12907 /* read data from ois chain */
12908 if (aux_ctx != NULL)
12909 {
12910 if (ret == 0)
12911 {
12912 ret = lsm6dso_read_reg(aux_ctx, LSM6DSO_OUTX_L_G, buff, 12);
12913 }
12914 }
12915
12916 j = 0;
12917
12918 /* ois angular rate conversion */
12919 for (i = 0U; i < 3U; i++)
12920 {
12921 data->ois.gy.raw[i] = (int16_t) buff[j + 1U];
12922 data->ois.gy.raw[i] = (data->ois.gy.raw[i] * 256) + (int16_t) buff[j];
12923 j += 2U;
12924
12925 switch (md->ois.gy.fs)
12926 {
12927 case LSM6DSO_GY_UI_250dps:
12928 data->ois.gy.mdps[i] = lsm6dso_from_fs250_to_mdps(
12929 data->ois.gy.raw[i]);
12930 break;
12931
12932 case LSM6DSO_GY_UI_125dps:
12933 data->ois.gy.mdps[i] = lsm6dso_from_fs125_to_mdps(
12934 data->ois.gy.raw[i]);
12935 break;
12936
12937 case LSM6DSO_GY_UI_500dps:
12938 data->ois.gy.mdps[i] = lsm6dso_from_fs500_to_mdps(
12939 data->ois.gy.raw[i]);
12940 break;
12941
12942 case LSM6DSO_GY_UI_1000dps:
12943 data->ois.gy.mdps[i] = lsm6dso_from_fs1000_to_mdps(
12944 data->ois.gy.raw[i]);
12945 break;
12946
12947 case LSM6DSO_GY_UI_2000dps:
12948 data->ois.gy.mdps[i] = lsm6dso_from_fs2000_to_mdps(
12949 data->ois.gy.raw[i]);
12950 break;
12951
12952 default:
12953 data->ois.gy.mdps[i] = 0.0f;
12954 break;
12955 }
12956 }
12957
12958 /* ois acceleration conversion */
12959 for (i = 0U; i < 3U; i++)
12960 {
12961 data->ois.xl.raw[i] = (int16_t) buff[j + 1U];
12962 data->ois.xl.raw[i] = (data->ois.xl.raw[i] * 256) + (int16_t) buff[j];
12963 j += 2U;
12964
12965 switch (md->ois.xl.fs)
12966 {
12967 case LSM6DSO_XL_UI_2g:
12968 data->ois.xl.mg[i] = lsm6dso_from_fs2_to_mg(data->ois.xl.raw[i]);
12969 break;
12970
12971 case LSM6DSO_XL_UI_4g:
12972 data->ois.xl.mg[i] = lsm6dso_from_fs4_to_mg(data->ois.xl.raw[i]);
12973 break;
12974
12975 case LSM6DSO_XL_UI_8g:
12976 data->ois.xl.mg[i] = lsm6dso_from_fs8_to_mg(data->ois.xl.raw[i]);
12977 break;
12978
12979 case LSM6DSO_XL_UI_16g:
12980 data->ois.xl.mg[i] = lsm6dso_from_fs16_to_mg(data->ois.xl.raw[i]);
12981 break;
12982
12983 default:
12984 data->ois.xl.mg[i] = 0.0f;
12985 break;
12986 }
12987 }
12988
12989 return ret;
12990 }
12991
12992 /**
12993 * @brief Embedded functions.[set]
12994 *
12995 * @param ctx read / write interface definitions
12996 * @param val change the values of registers
12997 * EMB_FUNC_EN_A e EMB_FUNC_EN_B.
12998 * @retval interface status (MANDATORY: return 0 -> no Error)
12999 *
13000 */
lsm6dso_embedded_sens_set(stmdev_ctx_t * ctx,lsm6dso_emb_sens_t * val)13001 int32_t lsm6dso_embedded_sens_set(stmdev_ctx_t *ctx,
13002 lsm6dso_emb_sens_t *val)
13003 {
13004 lsm6dso_emb_func_en_a_t emb_func_en_a;
13005 lsm6dso_emb_func_en_b_t emb_func_en_b;
13006 int32_t ret;
13007
13008 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
13009
13010 if (ret == 0)
13011 {
13012 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_EN_A,
13013 (uint8_t *)&emb_func_en_a, 1);
13014 }
13015
13016 if (ret == 0)
13017 {
13018 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_EN_B,
13019 (uint8_t *)&emb_func_en_b, 1);
13020 emb_func_en_b.fsm_en = val->fsm;
13021 emb_func_en_a.tilt_en = val->tilt;
13022 emb_func_en_a.pedo_en = val->step;
13023 emb_func_en_b.pedo_adv_en = val->step_adv;
13024 emb_func_en_a.sign_motion_en = val->sig_mot;
13025 emb_func_en_b.fifo_compr_en = val->fifo_compr;
13026 }
13027
13028 if (ret == 0)
13029 {
13030 ret = lsm6dso_write_reg(ctx, LSM6DSO_EMB_FUNC_EN_A,
13031 (uint8_t *)&emb_func_en_a, 1);
13032 }
13033
13034 if (ret == 0)
13035 {
13036 ret = lsm6dso_write_reg(ctx, LSM6DSO_EMB_FUNC_EN_B,
13037 (uint8_t *)&emb_func_en_b, 1);
13038 }
13039
13040 if (ret == 0)
13041 {
13042 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
13043 }
13044
13045 return ret;
13046 }
13047
13048 /**
13049 * @brief Embedded functions.[get]
13050 *
13051 * @param ctx read / write interface definitions
13052 * @param val get the values of registers
13053 * EMB_FUNC_EN_A e EMB_FUNC_EN_B.
13054 * @retval interface status (MANDATORY: return 0 -> no Error)
13055 *
13056 */
lsm6dso_embedded_sens_get(stmdev_ctx_t * ctx,lsm6dso_emb_sens_t * emb_sens)13057 int32_t lsm6dso_embedded_sens_get(stmdev_ctx_t *ctx,
13058 lsm6dso_emb_sens_t *emb_sens)
13059 {
13060 lsm6dso_emb_func_en_a_t emb_func_en_a;
13061 lsm6dso_emb_func_en_b_t emb_func_en_b;
13062 int32_t ret;
13063
13064 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
13065
13066 if (ret == 0)
13067 {
13068 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_EN_A,
13069 (uint8_t *)&emb_func_en_a, 1);
13070 }
13071
13072 if (ret == 0)
13073 {
13074 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_EN_B,
13075 (uint8_t *)&emb_func_en_b, 1);
13076 emb_sens->fsm = emb_func_en_b.fsm_en;
13077 emb_sens->tilt = emb_func_en_a.tilt_en;
13078 emb_sens->step = emb_func_en_a.pedo_en;
13079 emb_sens->step_adv = emb_func_en_b.pedo_adv_en;
13080 emb_sens->sig_mot = emb_func_en_a.sign_motion_en;
13081 emb_sens->fifo_compr = emb_func_en_b.fifo_compr_en;
13082 }
13083
13084 if (ret == 0)
13085 {
13086 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
13087 }
13088
13089 return ret;
13090 }
13091
13092 /**
13093 * @brief turn off all embedded functions.[get]
13094 *
13095 * @param ctx read / write interface definitions
13096 * @param val get the values of registers
13097 * EMB_FUNC_EN_A e EMB_FUNC_EN_B.
13098 * @retval interface status (MANDATORY: return 0 -> no Error)
13099 *
13100 */
lsm6dso_embedded_sens_off(stmdev_ctx_t * ctx)13101 int32_t lsm6dso_embedded_sens_off(stmdev_ctx_t *ctx)
13102 {
13103 lsm6dso_emb_func_en_a_t emb_func_en_a;
13104 lsm6dso_emb_func_en_b_t emb_func_en_b;
13105 int32_t ret;
13106
13107 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_EMBEDDED_FUNC_BANK);
13108
13109 if (ret == 0)
13110 {
13111 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_EN_A,
13112 (uint8_t *)&emb_func_en_a, 1);
13113 }
13114
13115 if (ret == 0)
13116 {
13117 ret = lsm6dso_read_reg(ctx, LSM6DSO_EMB_FUNC_EN_B,
13118 (uint8_t *)&emb_func_en_b, 1);
13119 emb_func_en_b.fsm_en = PROPERTY_DISABLE;
13120 emb_func_en_a.tilt_en = PROPERTY_DISABLE;
13121 emb_func_en_a.pedo_en = PROPERTY_DISABLE;
13122 emb_func_en_b.pedo_adv_en = PROPERTY_DISABLE;
13123 emb_func_en_a.sign_motion_en = PROPERTY_DISABLE;
13124 emb_func_en_b.fifo_compr_en = PROPERTY_DISABLE;
13125 }
13126
13127 if (ret == 0)
13128 {
13129 ret = lsm6dso_write_reg(ctx, LSM6DSO_EMB_FUNC_EN_A,
13130 (uint8_t *)&emb_func_en_a, 1);
13131 }
13132
13133 if (ret == 0)
13134 {
13135 ret = lsm6dso_write_reg(ctx, LSM6DSO_EMB_FUNC_EN_B,
13136 (uint8_t *)&emb_func_en_b, 1);
13137 }
13138
13139 if (ret == 0)
13140 {
13141 ret = lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK);
13142 }
13143
13144 return ret;
13145 }
13146
13147 /**
13148 * @}
13149 *
13150 */
13151
13152 /**
13153 * @}
13154 *
13155 */
13156
13157 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
13158