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