-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLPS22HHSensor.cpp
More file actions
726 lines (612 loc) · 19.1 KB
/
Copy pathLPS22HHSensor.cpp
File metadata and controls
726 lines (612 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
/**
******************************************************************************
* @file LPS22HHSensor.cpp
* @author SRA
* @version V1.0.0
* @date February 2019
* @brief Implementation of a LPS22HH pressure sensor.
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2019 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "LPS22HHSensor.h"
/* Class Implementation ------------------------------------------------------*/
/** Constructor
* @param i2c object of an helper class which handles the I2C peripheral
* @param address the address of the component's instance
*/
LPS22HHSensor::LPS22HHSensor(TwoWire *i2c, uint8_t address) : dev_i2c(i2c), address(address)
{
dev_spi = NULL;
reg_ctx.write_reg = LPS22HH_io_write;
reg_ctx.read_reg = LPS22HH_io_read;
reg_ctx.handle = (void *)this;
enabled = 0;
}
/** Constructor
* @param spi object of an helper class which handles the SPI peripheral
* @param cs_pin the chip select pin
* @param spi_speed the SPI speed
*/
LPS22HHSensor::LPS22HHSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed) : dev_spi(spi), cs_pin(cs_pin), spi_speed(spi_speed)
{
reg_ctx.write_reg = LPS22HH_io_write;
reg_ctx.read_reg = LPS22HH_io_read;
reg_ctx.handle = (void *)this;
dev_i2c = NULL;
address = 0;
enabled = 0;
}
/**
* @brief Configure the sensor in order to be used
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::begin()
{
if (dev_spi) {
// Configure CS pin
pinMode(cs_pin, OUTPUT);
digitalWrite(cs_pin, HIGH);
}
/* Disable MIPI I3C(SM) interface */
if (lps22hh_i3c_interface_set(®_ctx, LPS22HH_I3C_DISABLE) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
/* Power down the device, set Low Noise Enable (bit 5), clear One Shot (bit 4) */
if (lps22hh_data_rate_set(®_ctx, (lps22hh_odr_t)(LPS22HH_POWER_DOWN | 0x10)) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
/* Disable low-pass filter on LPS22HH pressure data */
if (lps22hh_lp_bandwidth_set(®_ctx, LPS22HH_LPF_ODR_DIV_2) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
/* Set block data update mode */
if (lps22hh_block_data_update_set(®_ctx, PROPERTY_ENABLE) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
/* Set autoincrement for multi-byte read/write */
if (lps22hh_auto_increment_set(®_ctx, PROPERTY_ENABLE) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
last_odr = LPS22HH_25_Hz;
last_lp = LPS22HH_LPF_ODR_DIV_2;
enabled = 0;
return LPS22HH_OK;
}
/**
* @brief Disable the sensor and relative resources
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::end()
{
/* Disable pressure and temperature sensor */
if (Disable() != LPS22HH_OK) {
return LPS22HH_ERROR;
}
/* Reset CS configuration */
if (dev_spi) {
// Configure CS pin
pinMode(cs_pin, INPUT);
}
return LPS22HH_OK;
}
/**
* @brief Get WHO_AM_I value
* @param Id the WHO_AM_I value
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::ReadID(uint8_t *Id)
{
if (lps22hh_device_id_get(®_ctx, Id) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Enable the LPS22HH pressure sensor
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Enable()
{
/* Check if the component is already enabled */
if (enabled == 1U) {
return LPS22HH_OK;
}
/* Output data rate selection. */
if (lps22hh_data_rate_set(®_ctx, last_odr) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
enabled = 1;
return LPS22HH_OK;
}
/**
* @brief Disable the LPS22HH pressure sensor
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Disable()
{
/* Check if the component is already disabled */
if (enabled == 0U) {
return LPS22HH_OK;
}
/* Get current output data rate. */
if (lps22hh_data_rate_get(®_ctx, &last_odr) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
/* Output data rate selection - power down. */
if (lps22hh_data_rate_set(®_ctx, LPS22HH_POWER_DOWN) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
enabled = 0;
return LPS22HH_OK;
}
/**
* @brief Get output data rate
* @param Odr the output data rate value
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::GetOutputDataRate(float *Odr)
{
LPS22HHStatusTypeDef ret = LPS22HH_OK;
lps22hh_odr_t odr_low_level;
if (lps22hh_data_rate_get(®_ctx, &odr_low_level) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
switch (odr_low_level) {
case LPS22HH_POWER_DOWN:
*Odr = 0.0f;
break;
case LPS22HH_1_Hz:
*Odr = 1.0f;
break;
case LPS22HH_10_Hz:
*Odr = 10.0f;
break;
case LPS22HH_25_Hz:
*Odr = 25.0f;
break;
case LPS22HH_50_Hz:
*Odr = 50.0f;
break;
case LPS22HH_75_Hz:
*Odr = 75.0f;
break;
case LPS22HH_100_Hz:
*Odr = 100.0f;
break;
case LPS22HH_200_Hz:
*Odr = 200.0f;
break;
default:
ret = LPS22HH_ERROR;
break;
}
return ret;
}
/**
* @brief Set the LPS22HH pressure sensor output data rate
* @param Odr the output data rate value to be set
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::SetOutputDataRate(float Odr)
{
/* Check if the component is enabled */
if (enabled == 1U) {
return SetOutputDataRate_When_Enabled(Odr);
} else {
return SetOutputDataRate_When_Disabled(Odr);
}
if (lps22hh_lp_bandwidth_set(®_ctx, LPS22HH_LPF_ODR_DIV_2) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
}
/**
* @brief Get output low pass bandwidth
* @param Lp the low pass bandwidth value
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::GetLPBandwidth(float *Lp)
{
LPS22HHStatusTypeDef ret = LPS22HH_OK;
lps22hh_lpfp_cfg_t lp_low_level;
if (lps22hh_lp_bandwidth_get(®_ctx, &lp_low_level) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
switch (lp_low_level) {
case LPS22HH_LPF_ODR_DIV_2:
*Lp = 2.0f;
break;
case LPS22HH_LPF_ODR_DIV_9:
*Lp = 9.0f;
break;
case LPS22HH_LPF_ODR_DIV_20:
*Lp = 20.0f;
break;
default:
ret = LPS22HH_ERROR;
break;
}
return ret;
}
/**
* @brief Set the LPS22HH pressure sensor low pass filter bandwidth
* @param Lp the LP bandwidth value to be set
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::SetLPBandwidth(float Lp)
{
lps22hh_lpfp_cfg_t new_lp;
new_lp = (Lp <= 2.0f) ? LPS22HH_LPF_ODR_DIV_2
: (Lp <= 9.0f) ? LPS22HH_LPF_ODR_DIV_9
: LPS22HH_LPF_ODR_DIV_20;
if (lps22hh_lp_bandwidth_set(®_ctx, new_lp) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
if (lps22hh_lp_bandwidth_get(®_ctx, &last_lp) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Set output data rate
* @param Odr the output data rate value to be set
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::SetOutputDataRate_When_Enabled(float Odr)
{
lps22hh_odr_t new_odr;
new_odr = (Odr <= 1.0f) ? LPS22HH_1_Hz
: (Odr <= 10.0f) ? LPS22HH_10_Hz
: (Odr <= 25.0f) ? LPS22HH_25_Hz
: (Odr <= 50.0f) ? LPS22HH_50_Hz
: (Odr <= 75.0f) ? LPS22HH_75_Hz
: (Odr <= 100.0f) ? LPS22HH_100_Hz
: LPS22HH_200_Hz;
if (lps22hh_data_rate_set(®_ctx, new_odr) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
if (lps22hh_data_rate_get(®_ctx, &last_odr) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Set output data rate when disabled
* @param Odr the output data rate value to be set
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::SetOutputDataRate_When_Disabled(float Odr)
{
last_odr = (Odr <= 1.0f) ? LPS22HH_1_Hz
: (Odr <= 10.0f) ? LPS22HH_10_Hz
: (Odr <= 25.0f) ? LPS22HH_25_Hz
: (Odr <= 50.0f) ? LPS22HH_50_Hz
: (Odr <= 75.0f) ? LPS22HH_75_Hz
: (Odr <= 100.0f) ? LPS22HH_100_Hz
: LPS22HH_200_Hz;
return LPS22HH_OK;
}
/**
* @brief Get the LPS22HH pressure value
* @param Value pointer where the pressure value is written
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::GetPressure(float *Value)
{
axis1bit32_t data_raw_pressure;
(void)memset(data_raw_pressure.u8bit, 0x00, sizeof(int32_t));
if (lps22hh_pressure_raw_get(®_ctx, data_raw_pressure.u8bit) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
*Value = LPS22HH_FROM_LSB_TO_hPa((float)(data_raw_pressure.i32bit));
return LPS22HH_OK;
}
/**
* @brief Get the LPS22HH pressure data ready bit value
* @param Status the status of data ready bit
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Get_PRESS_DRDY_Status(uint8_t *Status)
{
if (lps22hh_press_flag_data_ready_get(®_ctx, Status) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Get the LPS22HH temperature value
* @param Value pointer where the temperature value is written
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::GetTemperature(float *Value)
{
axis1bit16_t data_raw_temperature;
(void)memset(data_raw_temperature.u8bit, 0x00, sizeof(int16_t));
if (lps22hh_temperature_raw_get(®_ctx, data_raw_temperature.u8bit) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
*Value = LPS22HH_FROM_LSB_TO_degC((float)(data_raw_temperature.i16bit));
return LPS22HH_OK;
}
/**
* @brief Get the LPS22HH temperature data ready bit value
* @param Status the status of data ready bit
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Get_TEMP_DRDY_Status(uint8_t *Status)
{
if (lps22hh_temp_flag_data_ready_get(®_ctx, Status) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Get the LPS22HH register value
* @param Reg address to be written
* @param Data value to be written
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Read_Reg(uint8_t Reg, uint8_t *Data)
{
if (lps22hh_read_reg(®_ctx, Reg, Data, 1) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Set the LPS22HH register value
* @param pObj the device pObj
* @param Reg address to be written
* @param Data value to be written
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Write_Reg(uint8_t Reg, uint8_t Data)
{
if (lps22hh_write_reg(®_ctx, Reg, &Data, 1) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Get the LPS22HH FIFO data level
* @param Status the status of data ready bit
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Get_FIFO_Data(float *Press, float *Temp)
{
axis1bit32_t data_raw_pressure;
axis1bit16_t data_raw_temperature;
(void)memset(data_raw_pressure.u8bit, 0x00, sizeof(int32_t));
if (lps22hh_fifo_pressure_raw_get(®_ctx, data_raw_pressure.u8bit) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
*Press = LPS22HH_FROM_LSB_TO_hPa((float)(data_raw_pressure.i32bit));
(void)memset(data_raw_temperature.u8bit, 0x00, sizeof(int16_t));
if (lps22hh_fifo_temperature_raw_get(®_ctx, data_raw_temperature.u8bit) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
*Temp = LPS22HH_FROM_LSB_TO_degC((float)(data_raw_temperature.i16bit));
return LPS22HH_OK;
}
/**
* @brief Get the LPS22HH FIFO threshold
* @param Status the status of data ready bit
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Get_FIFO_FTh_Status(uint8_t *Status)
{
if (lps22hh_fifo_wtm_flag_get(®_ctx, Status) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Get the LPS22HH FIFO full status
* @param Status the status of data ready bit
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Get_FIFO_Full_Status(uint8_t *Status)
{
if (lps22hh_fifo_full_flag_get(®_ctx, Status) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Get the LPS22HH FIFO OVR status
* @param Status the status of data ready bit
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Get_FIFO_Ovr_Status(uint8_t *Status)
{
if (lps22hh_fifo_ovr_flag_get(®_ctx, Status) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Get the LPS22HH FIFO data level
* @param Status the status of data ready bit
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Get_FIFO_Level(uint8_t *Status)
{
if (lps22hh_fifo_data_level_get(®_ctx, Status) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Reset the FIFO interrupt
* @param interrupt The FIFO interrupt to be reset; values: 0 = FTH; 1 = FULL; 2 = OVR
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Reset_FIFO_Interrupt(uint8_t interrupt)
{
switch (interrupt) {
case 0:
if (lps22hh_fifo_threshold_on_int_set(®_ctx, PROPERTY_DISABLE) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
break;
case 1:
if (lps22hh_fifo_full_on_int_set(®_ctx, PROPERTY_DISABLE) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
break;
case 2:
if (lps22hh_fifo_ovr_on_int_set(®_ctx, PROPERTY_DISABLE) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
break;
default:
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Set the FIFO interrupt
* @param interrupt The FIFO interrupt to be reset; values: 0 = FTH; 1 = FULL; 2 = OVR
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Set_FIFO_Interrupt(uint8_t interrupt)
{
switch (interrupt) {
case 0:
if (lps22hh_fifo_threshold_on_int_set(®_ctx, PROPERTY_ENABLE) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
break;
case 1:
if (lps22hh_fifo_full_on_int_set(®_ctx, PROPERTY_ENABLE) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
break;
case 2:
if (lps22hh_fifo_ovr_on_int_set(®_ctx, PROPERTY_ENABLE) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
break;
default:
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Set the FIFO mode
* @param Mode the FIFO mode to be set
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Set_FIFO_Mode(uint8_t Mode)
{
/* Verify that the passed parameter contains one of the valid values */
switch ((lps22hh_f_mode_t)Mode) {
case LPS22HH_BYPASS_MODE:
case LPS22HH_FIFO_MODE:
case LPS22HH_STREAM_MODE:
case LPS22HH_STREAM_TO_FIFO_MODE:
case LPS22HH_BYPASS_TO_STREAM_MODE:
case LPS22HH_BYPASS_TO_FIFO_MODE:
break;
default:
return LPS22HH_ERROR;
}
if (lps22hh_fifo_mode_set(®_ctx, (lps22hh_f_mode_t)Mode) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Set the LPS22HH FIFO data level
* @param Status the status of data ready bit
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Set_FIFO_Watermark_Level(uint8_t Watermark)
{
if (lps22hh_fifo_watermark_set(®_ctx, Watermark) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Set the LPS22HH stop on watermark function
* @param Stop the state of stop on watermark function
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Stop_FIFO_On_Watermark(uint8_t Stop)
{
if (lps22hh_fifo_stop_on_wtm_set(®_ctx, Stop) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Set the LPS22HH One Shot Mode
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Set_One_Shot()
{
/* Start One Shot Measurement */
if (lps22hh_data_rate_set(®_ctx, LPS22HH_ONE_SHOOT) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
return LPS22HH_OK;
}
/**
* @brief Get the LPS22HH One Shot Status
* @param Status pointer to the one shot status (1 means measurements available, 0 means measurements not available yet)
* @retval 0 in case of success, an error code otherwise
*/
LPS22HHStatusTypeDef LPS22HHSensor::Get_One_Shot_Status(uint8_t *Status)
{
uint8_t p_da;
uint8_t t_da;
/* Get DataReady for pressure */
if (lps22hh_press_flag_data_ready_get(®_ctx, &p_da) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
/* Get DataReady for temperature */
if (lps22hh_temp_flag_data_ready_get(®_ctx, &t_da) != LPS22HH_OK) {
return LPS22HH_ERROR;
}
if (p_da && t_da) {
*Status = 1;
} else {
*Status = 0;
}
return LPS22HH_OK;
}
int32_t LPS22HH_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite)
{
return ((LPS22HHSensor *)handle)->IO_Write(pBuffer, WriteAddr, nBytesToWrite);
}
int32_t LPS22HH_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead)
{
return ((LPS22HHSensor *)handle)->IO_Read(pBuffer, ReadAddr, nBytesToRead);
}