1 /**
2 ******************************************************************************
3 * @file lps33k_reg.c
4 * @author Sensors Software Solution Team
5 * @brief LPS33K 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 "lps33k_reg.h"
21
22 /**
23 * @defgroup LPS33K
24 * @brief This file provides a set of functions needed to drive the
25 * ultra-compact piezoresistive absolute pressure sensor.
26 * @{
27 *
28 */
29
30 /**
31 * @defgroup LPS33K_Interfaces_functions
32 * @brief This section provide a set of functions used to read and
33 * write a generic register of the device.
34 * @{
35 *
36 */
37
38 /**
39 * @brief Read generic device register
40 *
41 * @param ctx read / write interface definitions(ptr)
42 * @param reg register to read
43 * @param data pointer to buffer that store the data read(ptr)
44 * @param len number of consecutive register to read
45 * @retval interface status (MANDATORY: return 0 -> no Error)
46 *
47 */
lps33k_read_reg(stmdev_ctx_t * ctx,uint8_t reg,uint8_t * data,uint16_t len)48 int32_t __weak lps33k_read_reg(stmdev_ctx_t *ctx, uint8_t reg, uint8_t *data,
49 uint16_t len)
50 {
51 int32_t ret;
52
53 ret = ctx->read_reg(ctx->handle, reg, data, len);
54
55 return ret;
56 }
57
58 /**
59 * @brief Write generic device register
60 *
61 * @param ctx read / write interface definitions(ptr)
62 * @param reg register to write
63 * @param data pointer to data to write in register reg(ptr)
64 * @param len number of consecutive register to write
65 * @retval interface status (MANDATORY: return 0 -> no Error)
66 *
67 */
lps33k_write_reg(stmdev_ctx_t * ctx,uint8_t reg,uint8_t * data,uint16_t len)68 int32_t __weak lps33k_write_reg(stmdev_ctx_t *ctx, uint8_t reg,
69 uint8_t *data,
70 uint16_t len)
71 {
72 int32_t ret;
73
74 ret = ctx->write_reg(ctx->handle, reg, data, len);
75
76 return ret;
77 }
78
79 /**
80 * @}
81 *
82 */
83
84 /**
85 * @defgroup LPS33K_Sensitivity
86 * @brief These functions convert raw-data into engineering units.
87 * @{
88 *
89 */
90
lps33k_from_lsb_to_hpa(int32_t lsb)91 float_t lps33k_from_lsb_to_hpa(int32_t lsb)
92 {
93 return ((float_t)lsb / 4096.0f);
94 }
95
lps33k_from_lsb_to_degc(int16_t lsb)96 float_t lps33k_from_lsb_to_degc(int16_t lsb)
97 {
98 return ((float_t)lsb / 100.0f);
99 }
100
101 /**
102 * @}
103 *
104 */
105
106 /**
107 * @defgroup LPS33K_data_generation_c
108 * @brief This section group all the functions concerning data
109 * generation
110 * @{
111 *
112 */
113
114 /**
115 * @brief Block data update.[set]
116 *
117 * @param ctx Read / write interface definitions
118 * @param val Change the values of bdu in reg CTRL_REG1
119 * @retval Interface status (MANDATORY: return 0 -> no Error).
120 *
121 */
lps33k_block_data_update_set(stmdev_ctx_t * ctx,uint8_t val)122 int32_t lps33k_block_data_update_set(stmdev_ctx_t *ctx, uint8_t val)
123 {
124 lps33k_ctrl_reg1_t ctrl_reg1;
125 int32_t ret;
126
127 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG1, (uint8_t *)&ctrl_reg1, 1);
128
129 if (ret == 0)
130 {
131 ctrl_reg1.bdu = val;
132 ret = lps33k_write_reg(ctx, LPS33K_CTRL_REG1, (uint8_t *)&ctrl_reg1, 1);
133 }
134
135 return ret;
136 }
137
138 /**
139 * @brief Block data update.[get]
140 *
141 * @param ctx Read / write interface definitions
142 * @param val Change the values of bdu in reg CTRL_REG1
143 * @retval Interface status (MANDATORY: return 0 -> no Error).
144 *
145 */
lps33k_block_data_update_get(stmdev_ctx_t * ctx,uint8_t * val)146 int32_t lps33k_block_data_update_get(stmdev_ctx_t *ctx, uint8_t *val)
147 {
148 lps33k_ctrl_reg1_t ctrl_reg1;
149 int32_t ret;
150
151 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG1, (uint8_t *)&ctrl_reg1, 1);
152 *val = ctrl_reg1.bdu;
153
154 return ret;
155 }
156
157 /**
158 * @brief Low-pass bandwidth selection.[set]
159 *
160 * @param ctx Read / write interface definitions
161 * @param val Change the values of lpfp in reg CTRL_REG1
162 * @retval Interface status (MANDATORY: return 0 -> no Error).
163 *
164 */
lps33k_low_pass_filter_mode_set(stmdev_ctx_t * ctx,lps33k_lpfp_t val)165 int32_t lps33k_low_pass_filter_mode_set(stmdev_ctx_t *ctx,
166 lps33k_lpfp_t val)
167 {
168 lps33k_ctrl_reg1_t ctrl_reg1;
169 int32_t ret;
170
171 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG1, (uint8_t *)&ctrl_reg1, 1);
172
173 if (ret == 0)
174 {
175 ctrl_reg1.lpfp = (uint8_t)val;
176 ret = lps33k_write_reg(ctx, LPS33K_CTRL_REG1, (uint8_t *)&ctrl_reg1, 1);
177 }
178
179 return ret;
180 }
181
182 /**
183 * @brief Low-pass bandwidth selection.[get]
184 *
185 * @param ctx Read / write interface definitions
186 * @param val Get the values of lpfp in reg CTRL_REG1
187 * @retval Interface status (MANDATORY: return 0 -> no Error).
188 *
189 */
lps33k_low_pass_filter_mode_get(stmdev_ctx_t * ctx,lps33k_lpfp_t * val)190 int32_t lps33k_low_pass_filter_mode_get(stmdev_ctx_t *ctx,
191 lps33k_lpfp_t *val)
192 {
193 lps33k_ctrl_reg1_t ctrl_reg1;
194 int32_t ret;
195
196 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG1, (uint8_t *)&ctrl_reg1, 1);
197
198 switch (ctrl_reg1.lpfp)
199 {
200 case LPS33K_LPF_ODR_DIV_2:
201 *val = LPS33K_LPF_ODR_DIV_2;
202 break;
203
204 case LPS33K_LPF_ODR_DIV_9:
205 *val = LPS33K_LPF_ODR_DIV_9;
206 break;
207
208 case LPS33K_LPF_ODR_DIV_20:
209 *val = LPS33K_LPF_ODR_DIV_20;
210 break;
211
212 default:
213 *val = LPS33K_LPF_ODR_DIV_2;
214 break;
215 }
216
217 return ret;
218 }
219
220 /**
221 * @brief Output data rate selection.[set]
222 *
223 * @param ctx Read / write interface definitions
224 * @param val Change the values of odr in reg CTRL_REG1
225 * @retval Interface status (MANDATORY: return 0 -> no Error).
226 *
227 */
lps33k_data_rate_set(stmdev_ctx_t * ctx,lps33k_odr_t val)228 int32_t lps33k_data_rate_set(stmdev_ctx_t *ctx, lps33k_odr_t val)
229 {
230 lps33k_ctrl_reg1_t ctrl_reg1;
231 int32_t ret;
232
233 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG1, (uint8_t *)&ctrl_reg1, 1);
234
235 if (ret == 0)
236 {
237 ctrl_reg1.odr = (uint8_t)val;
238 ret = lps33k_write_reg(ctx, LPS33K_CTRL_REG1, (uint8_t *)&ctrl_reg1, 1);
239 }
240
241 return ret;
242 }
243
244 /**
245 * @brief Output data rate selection.[get]
246 *
247 * @param ctx Read / write interface definitions
248 * @param val Get the values of odr in reg CTRL_REG1
249 * @retval Interface status (MANDATORY: return 0 -> no Error).
250 *
251 */
lps33k_data_rate_get(stmdev_ctx_t * ctx,lps33k_odr_t * val)252 int32_t lps33k_data_rate_get(stmdev_ctx_t *ctx, lps33k_odr_t *val)
253 {
254 lps33k_ctrl_reg1_t ctrl_reg1;
255 int32_t ret;
256
257 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG1, (uint8_t *)&ctrl_reg1, 1);
258
259 switch (ctrl_reg1.odr)
260 {
261 case LPS33K_POWER_DOWN:
262 *val = LPS33K_POWER_DOWN;
263 break;
264
265 case LPS33K_ODR_1_Hz:
266 *val = LPS33K_ODR_1_Hz;
267 break;
268
269 case LPS33K_ODR_10_Hz:
270 *val = LPS33K_ODR_10_Hz;
271 break;
272
273 case LPS33K_ODR_25_Hz:
274 *val = LPS33K_ODR_25_Hz;
275 break;
276
277 case LPS33K_ODR_50_Hz:
278 *val = LPS33K_ODR_50_Hz;
279 break;
280
281 case LPS33K_ODR_75_Hz:
282 *val = LPS33K_ODR_75_Hz;
283 break;
284
285 default:
286 *val = LPS33K_ODR_1_Hz;
287 break;
288 }
289
290 return ret;
291 }
292
293 /**
294 * @brief One-shot mode. Device perform a single measure.[set]
295 *
296 * @param ctx Read / write interface definitions
297 * @param val Change the values of one_shot in reg CTRL_REG2
298 * @retval Interface status (MANDATORY: return 0 -> no Error).
299 *
300 */
lps33k_one_shoot_trigger_set(stmdev_ctx_t * ctx,uint8_t val)301 int32_t lps33k_one_shoot_trigger_set(stmdev_ctx_t *ctx, uint8_t val)
302 {
303 lps33k_ctrl_reg2_t ctrl_reg2;
304 int32_t ret;
305
306 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG2, (uint8_t *)&ctrl_reg2, 1);
307
308 if (ret == 0)
309 {
310 ctrl_reg2.one_shot = val;
311 ret = lps33k_write_reg(ctx, LPS33K_CTRL_REG2, (uint8_t *)&ctrl_reg2, 1);
312 }
313
314 return ret;
315 }
316
317 /**
318 * @brief One-shot mode. Device perform a single measure.[get]
319 *
320 * @param ctx Read / write interface definitions
321 * @param val Change the values of one_shot in reg CTRL_REG2
322 * @retval Interface status (MANDATORY: return 0 -> no Error).
323 *
324 */
lps33k_one_shoot_trigger_get(stmdev_ctx_t * ctx,uint8_t * val)325 int32_t lps33k_one_shoot_trigger_get(stmdev_ctx_t *ctx, uint8_t *val)
326 {
327 lps33k_ctrl_reg2_t ctrl_reg2;
328 int32_t ret;
329
330 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG2, (uint8_t *)&ctrl_reg2, 1);
331 *val = ctrl_reg2.one_shot;
332
333 return ret;
334 }
335
336 /**
337 * @brief The pressure offset value is 16-bit data that can be used to
338 * implement one-point calibration (OPC) after soldering.[set]
339 *
340 * @param ctx Read / write interface definitions
341 * @param buff Buffer that contains data to write
342 * @retval Interface status (MANDATORY: return 0 -> no Error).
343 *
344 */
lps33k_pressure_offset_set(stmdev_ctx_t * ctx,int16_t val)345 int32_t lps33k_pressure_offset_set(stmdev_ctx_t *ctx, int16_t val)
346 {
347 uint8_t buff[2];
348 int32_t ret;
349
350 buff[1] = (uint8_t)((uint16_t)val / 256U);
351 buff[0] = (uint8_t)((uint16_t)val - (buff[1] * 256U));
352 ret = lps33k_write_reg(ctx, LPS33K_RPDS_L, buff, 2);
353
354 return ret;
355 }
356
357 /**
358 * @brief The pressure offset value is 16-bit data that can be used to
359 * implement one-point calibration (OPC) after soldering.[get]
360 *
361 * @param ctx Read / write interface definitions
362 * @param buff Buffer that stores data read
363 * @retval Interface status (MANDATORY: return 0 -> no Error).
364 *
365 */
lps33k_pressure_offset_get(stmdev_ctx_t * ctx,int16_t * val)366 int32_t lps33k_pressure_offset_get(stmdev_ctx_t *ctx, int16_t *val)
367 {
368 uint8_t buff[2];
369 int32_t ret;
370
371 ret = lps33k_read_reg(ctx, LPS33K_RPDS_L, buff, 2);
372 *val = (int16_t)buff[1];
373 *val = (*val * 256) + (int16_t)buff[0];
374
375 return ret;
376 }
377
378 /**
379 * @brief Pressure data available.[get]
380 *
381 * @param ctx Read / write interface definitions
382 * @param val Change the values of p_da in reg STATUS
383 * @retval Interface status (MANDATORY: return 0 -> no Error).
384 *
385 */
lps33k_press_data_ready_get(stmdev_ctx_t * ctx,uint8_t * val)386 int32_t lps33k_press_data_ready_get(stmdev_ctx_t *ctx, uint8_t *val)
387 {
388 lps33k_status_t status;
389 int32_t ret;
390
391 ret = lps33k_read_reg(ctx, LPS33K_STATUS, (uint8_t *)&status, 1);
392 *val = status.p_da;
393
394 return ret;
395 }
396
397 /**
398 * @brief Temperature data available.[get]
399 *
400 * @param ctx Read / write interface definitions
401 * @param val Change the values of t_da in reg STATUS
402 * @retval Interface status (MANDATORY: return 0 -> no Error).
403 *
404 */
lps33k_temp_data_ready_get(stmdev_ctx_t * ctx,uint8_t * val)405 int32_t lps33k_temp_data_ready_get(stmdev_ctx_t *ctx, uint8_t *val)
406 {
407 lps33k_status_t status;
408 int32_t ret;
409
410 ret = lps33k_read_reg(ctx, LPS33K_STATUS, (uint8_t *)&status, 1);
411 *val = status.t_da;
412
413 return ret;
414 }
415
416 /**
417 * @brief Pressure data overrun.[get]
418 *
419 * @param ctx Read / write interface definitions
420 * @param val Change the values of p_or in reg STATUS
421 * @retval Interface status (MANDATORY: return 0 -> no Error).
422 *
423 */
lps33k_press_data_ovr_get(stmdev_ctx_t * ctx,uint8_t * val)424 int32_t lps33k_press_data_ovr_get(stmdev_ctx_t *ctx, uint8_t *val)
425 {
426 lps33k_status_t status;
427 int32_t ret;
428
429 ret = lps33k_read_reg(ctx, LPS33K_STATUS, (uint8_t *)&status, 1);
430 *val = status.p_or;
431
432 return ret;
433 }
434
435 /**
436 * @brief Temperature data overrun.[get]
437 *
438 * @param ctx Read / write interface definitions
439 * @param val Change the values of t_or in reg STATUS
440 * @retval Interface status (MANDATORY: return 0 -> no Error).
441 *
442 */
lps33k_temp_data_ovr_get(stmdev_ctx_t * ctx,uint8_t * val)443 int32_t lps33k_temp_data_ovr_get(stmdev_ctx_t *ctx, uint8_t *val)
444 {
445 lps33k_status_t status;
446 int32_t ret;
447
448 ret = lps33k_read_reg(ctx, LPS33K_STATUS, (uint8_t *)&status, 1);
449 *val = status.t_or;
450
451 return ret;
452 }
453
454 /**
455 * @brief Pressure output value[get]
456 *
457 * @param ctx Read / write interface definitions
458 * @param buff Buffer that stores data read
459 * @retval Interface status (MANDATORY: return 0 -> no Error).
460 *
461 */
lps33k_pressure_raw_get(stmdev_ctx_t * ctx,uint32_t * buff)462 int32_t lps33k_pressure_raw_get(stmdev_ctx_t *ctx, uint32_t *buff)
463 {
464 uint8_t reg[3];
465 int32_t ret;
466
467 ret = lps33k_read_reg(ctx, LPS33K_PRESS_OUT_XL, reg, 3);
468 *buff = reg[2];
469 *buff = (*buff * 256) + reg[1];
470 *buff = (*buff * 256) + reg[0];
471 *buff *= 256;
472
473 return ret;
474 }
475
476 /**
477 * @brief temperature_raw: Temperature output value[get]
478 *
479 * @param ctx Read / write interface definitions
480 * @param buff Buffer that stores data read.
481 * @retval Interface status (MANDATORY: return 0 -> no Error).
482 *
483 */
lps33k_temperature_raw_get(stmdev_ctx_t * ctx,int16_t * buff)484 int32_t lps33k_temperature_raw_get(stmdev_ctx_t *ctx, int16_t *buff)
485 {
486 uint8_t reg[2];
487 int32_t ret;
488
489 ret = lps33k_read_reg(ctx, LPS33K_TEMP_OUT_L, (uint8_t *) reg, 2);
490 *buff = reg[1];
491 *buff = (*buff * 256) + reg[0];
492
493 return ret;
494 }
495
496 /**
497 * @brief Low-pass filter reset register. If the LPFP is active, in
498 * order to avoid the transitory phase, the filter can be
499 * reset by reading this register before generating pressure
500 * measurements.[get]
501 *
502 * @param ctx Read / write interface definitions
503 * @param buff Buffer that stores data read
504 * @retval Interface status (MANDATORY: return 0 -> no Error).
505 *
506 */
lps33k_low_pass_rst_get(stmdev_ctx_t * ctx,uint8_t * buff)507 int32_t lps33k_low_pass_rst_get(stmdev_ctx_t *ctx, uint8_t *buff)
508 {
509 int32_t ret;
510
511 ret = lps33k_read_reg(ctx, LPS33K_LPFP_RES, (uint8_t *) buff, 1);
512
513 return ret;
514 }
515
516 /**
517 * @}
518 *
519 */
520
521 /**
522 * @defgroup LPS33K_common
523 * @brief This section group common useful functions
524 * @{
525 *
526 */
527
528 /**
529 * @brief Device Who am I[get]
530 *
531 * @param ctx Read / write interface definitions
532 * @param buff Buffer that stores data read
533 * @retval Interface status (MANDATORY: return 0 -> no Error).
534 *
535 */
lps33k_device_id_get(stmdev_ctx_t * ctx,uint8_t * buff)536 int32_t lps33k_device_id_get(stmdev_ctx_t *ctx, uint8_t *buff)
537 {
538 int32_t ret;
539
540 ret = lps33k_read_reg(ctx, LPS33K_WHO_AM_I, (uint8_t *) buff, 1);
541
542 return ret;
543 }
544
545 /**
546 * @brief Software reset. Restore the default values in user registers[set]
547 *
548 * @param ctx Read / write interface definitions
549 * @param val Change the values of swreset in reg CTRL_REG2
550 * @retval Interface status (MANDATORY: return 0 -> no Error).
551 *
552 */
lps33k_reset_set(stmdev_ctx_t * ctx,uint8_t val)553 int32_t lps33k_reset_set(stmdev_ctx_t *ctx, uint8_t val)
554 {
555 lps33k_ctrl_reg2_t ctrl_reg2;
556 int32_t ret;
557
558 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG2, (uint8_t *)&ctrl_reg2, 1);
559
560 if (ret == 0)
561 {
562 ctrl_reg2.swreset = val;
563 ret = lps33k_write_reg(ctx, LPS33K_CTRL_REG2, (uint8_t *)&ctrl_reg2, 1);
564 }
565
566 return ret;
567 }
568
569 /**
570 * @brief Software reset. Restore the default values in user registers[get]
571 *
572 * @param ctx Read / write interface definitions
573 * @param val Change the values of swreset in reg CTRL_REG2
574 * @retval Interface status (MANDATORY: return 0 -> no Error).
575 *
576 */
lps33k_reset_get(stmdev_ctx_t * ctx,uint8_t * val)577 int32_t lps33k_reset_get(stmdev_ctx_t *ctx, uint8_t *val)
578 {
579 lps33k_ctrl_reg2_t ctrl_reg2;
580 int32_t ret;
581
582 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG2, (uint8_t *)&ctrl_reg2, 1);
583 *val = ctrl_reg2.swreset;
584
585 return ret;
586 }
587
588 /**
589 * @brief Reboot memory content. Reload the calibration parameters.[set]
590 *
591 * @param ctx Read / write interface definitions
592 * @param val Change the values of boot in reg CTRL_REG2
593 * @retval Interface status (MANDATORY: return 0 -> no Error).
594 *
595 */
lps33k_boot_set(stmdev_ctx_t * ctx,uint8_t val)596 int32_t lps33k_boot_set(stmdev_ctx_t *ctx, uint8_t val)
597 {
598 lps33k_ctrl_reg2_t ctrl_reg2;
599 int32_t ret;
600
601 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG2, (uint8_t *)&ctrl_reg2, 1);
602
603 if (ret == 0)
604 {
605 ctrl_reg2.boot = val;
606 ret = lps33k_write_reg(ctx, LPS33K_CTRL_REG2, (uint8_t *)&ctrl_reg2, 1);
607 }
608
609 return ret;
610 }
611
612 /**
613 * @brief Reboot memory content. Reload the calibration parameters.[get]
614 *
615 * @param ctx Read / write interface definitions
616 * @param val Change the values of boot in reg CTRL_REG2
617 * @retval Interface status (MANDATORY: return 0 -> no Error).
618 *
619 */
lps33k_boot_get(stmdev_ctx_t * ctx,uint8_t * val)620 int32_t lps33k_boot_get(stmdev_ctx_t *ctx, uint8_t *val)
621 {
622 lps33k_ctrl_reg2_t ctrl_reg2;
623 int32_t ret;
624
625 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG2, (uint8_t *)&ctrl_reg2, 1);
626 *val = ctrl_reg2.boot;
627
628 return ret;
629 }
630
631 /**
632 * @brief Low current mode.[set]
633 *
634 * @param ctx Read / write interface definitions
635 * @param val Change the values of lc_en in reg RES_CONF
636 * @retval Interface status (MANDATORY: return 0 -> no Error).
637 *
638 */
lps33k_low_power_set(stmdev_ctx_t * ctx,uint8_t val)639 int32_t lps33k_low_power_set(stmdev_ctx_t *ctx, uint8_t val)
640 {
641 lps33k_res_conf_t res_conf;
642 int32_t ret;
643
644 ret = lps33k_read_reg(ctx, LPS33K_RES_CONF, (uint8_t *)&res_conf, 1);
645
646 if (ret == 0)
647 {
648 res_conf.lc_en = val;
649 ret = lps33k_write_reg(ctx, LPS33K_RES_CONF, (uint8_t *)&res_conf, 1);
650 }
651
652 return ret;
653 }
654
655 /**
656 * @brief Low current mode.[get]
657 *
658 * @param ctx Read / write interface definitions
659 * @param val Change the values of lc_en in reg RES_CONF
660 * @retval Interface status (MANDATORY: return 0 -> no Error).
661 *
662 */
lps33k_low_power_get(stmdev_ctx_t * ctx,uint8_t * val)663 int32_t lps33k_low_power_get(stmdev_ctx_t *ctx, uint8_t *val)
664 {
665 lps33k_res_conf_t res_conf;
666 int32_t ret;
667
668 ret = lps33k_read_reg(ctx, LPS33K_RES_CONF, (uint8_t *)&res_conf, 1);
669 *val = res_conf.lc_en;
670
671 return ret;
672 }
673
674 /**
675 * @}
676 *
677 */
678
679 /**
680 * @defgroup LPS33K_serial_interface
681 * @brief This section group all the functions concerning serial
682 * interface management
683 * @{
684 *
685 */
686
687 /**
688 * @brief Register address automatically incremented during a
689 * multiple byte access with a serial interface (I2C or SPI).[set]
690 *
691 * @param ctx Read / write interface definitions
692 * @param val Change the values of if_add_inc in reg CTRL_REG2
693 * @retval Interface status (MANDATORY: return 0 -> no Error).
694 *
695 */
lps33k_auto_add_inc_set(stmdev_ctx_t * ctx,uint8_t val)696 int32_t lps33k_auto_add_inc_set(stmdev_ctx_t *ctx, uint8_t val)
697 {
698 lps33k_ctrl_reg2_t ctrl_reg2;
699 int32_t ret;
700
701 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG2, (uint8_t *)&ctrl_reg2, 1);
702
703 if (ret == 0)
704 {
705 ctrl_reg2.if_add_inc = val;
706 ret = lps33k_write_reg(ctx, LPS33K_CTRL_REG2, (uint8_t *)&ctrl_reg2, 1);
707 }
708
709 return ret;
710 }
711
712 /**
713 * @brief Register address automatically incremented during a
714 * multiple byte access with a serial interface (I2C or SPI).[get]
715 *
716 * @param ctx Read / write interface definitions
717 * @param val Change the values of if_add_inc in reg CTRL_REG2
718 * @retval Interface status (MANDATORY: return 0 -> no Error).
719 *
720 */
lps33k_auto_add_inc_get(stmdev_ctx_t * ctx,uint8_t * val)721 int32_t lps33k_auto_add_inc_get(stmdev_ctx_t *ctx, uint8_t *val)
722 {
723 lps33k_ctrl_reg2_t ctrl_reg2;
724 int32_t ret;
725
726 ret = lps33k_read_reg(ctx, LPS33K_CTRL_REG2, (uint8_t *)&ctrl_reg2, 1);
727 *val = ctrl_reg2.if_add_inc;
728
729 return ret;
730 }
731
732 /**
733 * @}
734 *
735 */
736
737 /**
738 * @}
739 *
740 */
741
742 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
743