LPS22HH pressure sensor library
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
LPS22HHSensor.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file LPS22HHSensor.cpp 00004 * @author SRA 00005 * @version V1.0.0 00006 * @date February 2019 00007 * @brief Implementation of a LPS22HH pressure sensor. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2019 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 00039 /* Includes ------------------------------------------------------------------*/ 00040 00041 #include "LPS22HHSensor.h" 00042 00043 00044 /* Class Implementation ------------------------------------------------------*/ 00045 00046 /** Constructor 00047 * @param spi object of an helper class which handles the SPI peripheral 00048 * @param cs_pin the chip select pin 00049 * @param int_pin the interrupt pin 00050 * @param spi_type the SPI type 00051 */ 00052 LPS22HHSensor::LPS22HHSensor(SPI *spi, PinName cs_pin, PinName int_pin, SPI_type_t spi_type) : _dev_spi(spi), _cs_pin(cs_pin), _int_irq(int_pin), _spi_type(spi_type) 00053 { 00054 assert(spi); 00055 if (cs_pin == NC) { 00056 printf("ERROR LPS22HH CS MUST NOT BE NC\n\r"); 00057 _dev_spi = NULL; 00058 _dev_i2c = NULL; 00059 return; 00060 } 00061 00062 _reg_ctx.write_reg = LPS22HH_io_write; 00063 _reg_ctx.read_reg = LPS22HH_io_read; 00064 _reg_ctx.handle = (void *)this; 00065 _cs_pin = 1; 00066 _dev_i2c = NULL; 00067 _address = 0; 00068 00069 if (_spi_type == SPI3W) { 00070 /* Enable SPI 3-Wires on the component */ 00071 uint8_t data = 0x01; 00072 lps22hh_write_reg(&_reg_ctx, LPS22HH_CTRL_REG1, &data, 1); 00073 } 00074 } 00075 00076 /** Constructor 00077 * @param i2c object of an helper class which handles the I2C peripheral 00078 * @param address the address of the component's instance 00079 * @param int_pin the interrupt pin 00080 */ 00081 LPS22HHSensor::LPS22HHSensor(DevI2C *i2c, uint8_t address, PinName int_pin) : _dev_i2c(i2c), _address(address), _cs_pin(NC), _int_irq(int_pin) 00082 { 00083 assert(i2c); 00084 _dev_spi = NULL; 00085 _reg_ctx.write_reg = LPS22HH_io_write; 00086 _reg_ctx.read_reg = LPS22HH_io_read; 00087 _reg_ctx.handle = (void *)this; 00088 } 00089 00090 00091 /** 00092 * @brief Initializing the component 00093 * @param init pointer to device specific initalization structure 00094 * @retval 0 in case of success, an error code otherwise 00095 */ 00096 int LPS22HHSensor::init(void *init) 00097 { 00098 /* Disable MIPI I3C(SM) interface */ 00099 if (lps22hh_i3c_interface_set(&_reg_ctx, LPS22HH_I3C_DISABLE) != 0) { 00100 return 1; 00101 } 00102 00103 /* Power down the device, set Low Noise Enable (bit 5), clear One Shot (bit 4) */ 00104 if (lps22hh_data_rate_set(&_reg_ctx, (lps22hh_odr_t)(LPS22HH_POWER_DOWN | 0x10)) != 0) { 00105 return 1; 00106 } 00107 00108 /* Disable low-pass filter on LPS22HH pressure data */ 00109 if (lps22hh_lp_bandwidth_set(&_reg_ctx, LPS22HH_LPF_ODR_DIV_2) != 0) { 00110 return 1; 00111 } 00112 00113 /* Set block data update mode */ 00114 if (lps22hh_block_data_update_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { 00115 return 1; 00116 } 00117 00118 /* Set autoincrement for multi-byte read/write */ 00119 if (lps22hh_auto_increment_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { 00120 return 1; 00121 } 00122 00123 _last_odr = LPS22HH_25_Hz; 00124 _is_enabled = 0; 00125 00126 return 0; 00127 } 00128 00129 /** 00130 * @brief Get WHO_AM_I value 00131 * @param id the WHO_AM_I value 00132 * @retval 0 in case of success, an error code otherwise 00133 */ 00134 int LPS22HHSensor::read_id(uint8_t *id) 00135 { 00136 if (lps22hh_device_id_get(&_reg_ctx, id) != 0) { 00137 return 1; 00138 } 00139 00140 return 0; 00141 } 00142 00143 /** 00144 * @brief Enable the LPS22HH pressure sensor 00145 * @retval 0 in case of success, an error code otherwise 00146 */ 00147 int LPS22HHSensor::enable() 00148 { 00149 /* Check if the component is already _is_enabled */ 00150 if (_is_enabled == 1U) { 00151 return 0; 00152 } 00153 00154 /* Output data rate selection. */ 00155 if (lps22hh_data_rate_set(&_reg_ctx, _last_odr) != 0) { 00156 return 1; 00157 } 00158 00159 _is_enabled = 1; 00160 00161 return 0; 00162 } 00163 00164 /** 00165 * @brief Disable the LPS22HH pressure sensor 00166 * @retval 0 in case of success, an error code otherwise 00167 */ 00168 int LPS22HHSensor::disable() 00169 { 00170 /* Check if the component is already disabled */ 00171 if (_is_enabled == 0U) { 00172 return 0; 00173 } 00174 00175 /* Get current output data rate. */ 00176 if (lps22hh_data_rate_get(&_reg_ctx, &_last_odr) != 0) { 00177 return 1; 00178 } 00179 /* Output data rate selection - power down. */ 00180 if (lps22hh_data_rate_set(&_reg_ctx, LPS22HH_POWER_DOWN) != 0) { 00181 return 1; 00182 } 00183 00184 00185 _is_enabled = 0; 00186 00187 return 0; 00188 } 00189 00190 00191 /** 00192 * @brief Get output data rate 00193 * @param odr the output data rate value 00194 * @retval 0 in case of success, an error code otherwise 00195 */ 00196 int LPS22HHSensor::get_odr(float *odr, uint8_t *low_noise_en) 00197 { 00198 int ret = 0; 00199 lps22hh_odr_t odr_low_level; 00200 00201 if (lps22hh_data_rate_get(&_reg_ctx, &odr_low_level) != 0) { 00202 return 1; 00203 } 00204 00205 switch (odr_low_level) { 00206 case LPS22HH_POWER_DOWN: 00207 *odr = 0.0f; 00208 *low_noise_en = 0; 00209 break; 00210 00211 case LPS22HH_1_Hz: 00212 *odr = 1.0f; 00213 *low_noise_en = 0; 00214 break; 00215 00216 case LPS22HH_10_Hz: 00217 *odr = 10.0f; 00218 *low_noise_en = 0; 00219 break; 00220 00221 case LPS22HH_25_Hz: 00222 *odr = 25.0f; 00223 *low_noise_en = 0; 00224 break; 00225 00226 case LPS22HH_50_Hz: 00227 *odr = 50.0f; 00228 *low_noise_en = 0; 00229 break; 00230 00231 case LPS22HH_75_Hz: 00232 *odr = 75.0f; 00233 *low_noise_en = 0; 00234 break; 00235 00236 case LPS22HH_1_Hz_LOW_NOISE: 00237 *odr = 1.0f; 00238 *low_noise_en = 1; 00239 break; 00240 00241 case LPS22HH_10_Hz_LOW_NOISE: 00242 *odr = 10.0f; 00243 *low_noise_en = 1; 00244 break; 00245 00246 case LPS22HH_25_Hz_LOW_NOISE: 00247 *odr = 25.0f; 00248 *low_noise_en = 1; 00249 break; 00250 00251 case LPS22HH_50_Hz_LOW_NOISE: 00252 *odr = 50.0f; 00253 *low_noise_en = 1; 00254 break; 00255 00256 case LPS22HH_75_Hz_LOW_NOISE: 00257 *odr = 75.0f; 00258 *low_noise_en = 1; 00259 break; 00260 00261 case LPS22HH_100_Hz: 00262 *odr = 100.0f; 00263 *low_noise_en = 0; 00264 break; 00265 00266 case LPS22HH_200_Hz: 00267 *odr = 200.0f; 00268 *low_noise_en = 0; 00269 break; 00270 00271 default: 00272 ret = 1; 00273 break; 00274 } 00275 00276 return ret; 00277 } 00278 00279 /** 00280 * @brief Set the LPS22HH pressure sensor output data rate 00281 * @param odr the output data rate value to be set 00282 * @retval 0 in case of success, an error code otherwise 00283 */ 00284 int LPS22HHSensor::set_odr(float odr, uint8_t low_noise_en) 00285 { 00286 /* Check if the component is _is_enabled */ 00287 if (_is_enabled == 1U) { 00288 return set_odr_when_enabled(odr, low_noise_en); 00289 } else { 00290 return set_odr_when_disabled(odr, low_noise_en); 00291 } 00292 } 00293 00294 /** 00295 * @brief Set output data rate 00296 * @param odr the output data rate value to be set 00297 * @retval 0 in case of success, an error code otherwise 00298 */ 00299 int LPS22HHSensor::set_odr_when_enabled(float odr, uint8_t low_noise_en) 00300 { 00301 lps22hh_odr_t new_odr; 00302 00303 new_odr = ((odr <= 1.0f) && !low_noise_en) ? LPS22HH_1_Hz 00304 : ((odr <= 1.0f) && low_noise_en) ? LPS22HH_1_Hz_LOW_NOISE 00305 : ((odr <= 10.0f) && !low_noise_en) ? LPS22HH_10_Hz 00306 : ((odr <= 10.0f) && low_noise_en) ? LPS22HH_10_Hz_LOW_NOISE 00307 : ((odr <= 25.0f) && !low_noise_en) ? LPS22HH_25_Hz 00308 : ((odr <= 25.0f) && low_noise_en) ? LPS22HH_25_Hz_LOW_NOISE 00309 : ((odr <= 50.0f) && !low_noise_en) ? LPS22HH_50_Hz 00310 : ((odr <= 50.0f) && low_noise_en) ? LPS22HH_50_Hz_LOW_NOISE 00311 : ((odr <= 75.0f) && !low_noise_en) ? LPS22HH_75_Hz 00312 : ((odr <= 75.0f) && low_noise_en) ? LPS22HH_75_Hz_LOW_NOISE 00313 : (odr <= 100.0f) ? LPS22HH_100_Hz 00314 : LPS22HH_200_Hz; 00315 00316 if (lps22hh_data_rate_set(&_reg_ctx, new_odr) != 0) { 00317 return 1; 00318 } 00319 00320 if (lps22hh_data_rate_get(&_reg_ctx, &_last_odr) != 0) { 00321 return 1; 00322 } 00323 00324 return 0; 00325 } 00326 00327 /** 00328 * @brief Set output data rate when disabled 00329 * @param odr the output data rate value to be set 00330 * @retval 0 in case of success, an error code otherwise 00331 */ 00332 int LPS22HHSensor::set_odr_when_disabled(float odr, uint8_t low_noise_en) 00333 { 00334 _last_odr = ((odr <= 1.0f) && !low_noise_en) ? LPS22HH_1_Hz 00335 : ((odr <= 1.0f) && low_noise_en) ? LPS22HH_1_Hz_LOW_NOISE 00336 : ((odr <= 10.0f) && !low_noise_en) ? LPS22HH_10_Hz 00337 : ((odr <= 10.0f) && low_noise_en) ? LPS22HH_10_Hz_LOW_NOISE 00338 : ((odr <= 25.0f) && !low_noise_en) ? LPS22HH_25_Hz 00339 : ((odr <= 25.0f) && low_noise_en) ? LPS22HH_25_Hz_LOW_NOISE 00340 : ((odr <= 50.0f) && !low_noise_en) ? LPS22HH_50_Hz 00341 : ((odr <= 50.0f) && low_noise_en) ? LPS22HH_50_Hz_LOW_NOISE 00342 : ((odr <= 75.0f) && !low_noise_en) ? LPS22HH_75_Hz 00343 : ((odr <= 75.0f) && low_noise_en) ? LPS22HH_75_Hz_LOW_NOISE 00344 : (odr <= 100.0f) ? LPS22HH_100_Hz 00345 : LPS22HH_200_Hz; 00346 00347 return 0; 00348 } 00349 00350 00351 /** 00352 * @brief Get low-pass configuration 00353 * @param lpfp_cfg the low-pass configuration value 00354 * @retval 0 in case of success, an error code otherwise 00355 */ 00356 int LPS22HHSensor::get_lpfp_cfg(uint8_t *lpfp_cfg) 00357 { 00358 int ret = 0; 00359 lps22hh_lpfp_cfg_t lpfp_cfg_low_level; 00360 00361 if (lps22hh_lp_bandwidth_get(&_reg_ctx, &lpfp_cfg_low_level) != 0) { 00362 return 1; 00363 } 00364 00365 switch (lpfp_cfg_low_level) { 00366 case LPS22HH_LPF_ODR_DIV_2: 00367 *lpfp_cfg = 0; 00368 break; 00369 00370 case LPS22HH_LPF_ODR_DIV_9: 00371 *lpfp_cfg = 2; 00372 break; 00373 00374 case LPS22HH_LPF_ODR_DIV_20: 00375 *lpfp_cfg = 3; 00376 break; 00377 00378 default: 00379 ret = 1; 00380 break; 00381 } 00382 00383 return ret; 00384 } 00385 00386 /** 00387 * @brief Set the LPS22HH pressure sensor low-pass configuration 00388 * @param lpfp_cfg the low-pass configuration value to be set 00389 * @retval 0 in case of success, an error code otherwise 00390 */ 00391 int LPS22HHSensor::set_lpfp_cfg(uint8_t lpfp_cfg) 00392 { 00393 lps22hh_lpfp_cfg_t new_lpfp_cfg; 00394 00395 new_lpfp_cfg = (lpfp_cfg == 2) ? LPS22HH_LPF_ODR_DIV_9 00396 : (lpfp_cfg == 3) ? LPS22HH_LPF_ODR_DIV_20 00397 : LPS22HH_LPF_ODR_DIV_2; 00398 00399 if (lps22hh_lp_bandwidth_set(&_reg_ctx, new_lpfp_cfg) != 0) { 00400 return 1; 00401 } 00402 00403 return 0; 00404 } 00405 00406 /** 00407 * @brief Get the LPS22HH pressure value 00408 * @param value pointer where the pressure value is written 00409 * @retval 0 in case of success, an error code otherwise 00410 */ 00411 int LPS22HHSensor::get_pressure(float *value) 00412 { 00413 axis1bit32_t data_raw_pressure; 00414 00415 (void)memset(data_raw_pressure.u8bit, 0x00, sizeof(int32_t)); 00416 if (lps22hh_pressure_raw_get(&_reg_ctx, data_raw_pressure.u8bit) != 0) { 00417 return 1; 00418 } 00419 00420 *value = LPS22HH_FROM_LSB_TO_hPa((float)(data_raw_pressure.i32bit)); 00421 00422 return 0; 00423 } 00424 00425 /** 00426 * @brief Get the LPS22HH pressure data ready bit value 00427 * @param status the status of data ready bit 00428 * @retval 0 in case of success, an error code otherwise 00429 */ 00430 int LPS22HHSensor::get_press_drdy_status(uint8_t *status) 00431 { 00432 if (lps22hh_press_flag_data_ready_get(&_reg_ctx, status) != 0) { 00433 return 1; 00434 } 00435 00436 return 0; 00437 } 00438 00439 /** 00440 * @brief Get the LPS22HH temperature value 00441 * @param value pointer where the temperature value is written 00442 * @retval 0 in case of success, an error code otherwise 00443 */ 00444 int LPS22HHSensor::get_temperature(float *value) 00445 { 00446 axis1bit16_t data_raw_temperature; 00447 00448 (void)memset(data_raw_temperature.u8bit, 0x00, sizeof(int16_t)); 00449 if (lps22hh_temperature_raw_get(&_reg_ctx, data_raw_temperature.u8bit) != 0) { 00450 return 1; 00451 } 00452 00453 *value = LPS22HH_FROM_LSB_TO_degC((float)(data_raw_temperature.i16bit)); 00454 00455 return 0; 00456 } 00457 00458 /** 00459 * @brief Get the LPS22HH temperature data ready bit value 00460 * @param status the status of data ready bit 00461 * @retval 0 in case of success, an error code otherwise 00462 */ 00463 int LPS22HHSensor::get_temp_drdy_status(uint8_t *status) 00464 { 00465 if (lps22hh_temp_flag_data_ready_get(&_reg_ctx, status) != 0) { 00466 return 1; 00467 } 00468 00469 return 0; 00470 } 00471 00472 /** 00473 * @brief Get the LPS22HH register value 00474 * @param reg address to be written 00475 * @param data value to be written 00476 * @retval 0 in case of success, an error code otherwise 00477 */ 00478 int LPS22HHSensor::read_reg(uint8_t reg, uint8_t *data) 00479 { 00480 if (lps22hh_read_reg(&_reg_ctx, reg, data, 1) != 0) { 00481 return 1; 00482 } 00483 00484 return 0; 00485 } 00486 00487 /** 00488 * @brief Set the LPS22HH register value 00489 * @param reg address to be written 00490 * @param data value to be written 00491 * @retval 0 in case of success, an error code otherwise 00492 */ 00493 int LPS22HHSensor::write_reg(uint8_t reg, uint8_t data) 00494 { 00495 if (lps22hh_write_reg(&_reg_ctx, reg, &data, 1) != 0) { 00496 return 1; 00497 } 00498 00499 return 0; 00500 } 00501 00502 /** 00503 * @brief Get the LPS22HH FIFO data 00504 * @param press the pointer where FIFO pressure value is stored 00505 * @param temp the pointer where FIFO temperature value is stored 00506 * @retval 0 in case of success, an error code otherwise 00507 */ 00508 int LPS22HHSensor::get_fifo_data(float *press, float *temp) 00509 { 00510 axis1bit32_t data_raw_pressure; 00511 axis1bit16_t data_raw_temperature; 00512 00513 (void)memset(data_raw_pressure.u8bit, 0x00, sizeof(int32_t)); 00514 if (lps22hh_fifo_pressure_raw_get(&_reg_ctx, data_raw_pressure.u8bit) != 0) { 00515 return 1; 00516 } 00517 00518 *press = LPS22HH_FROM_LSB_TO_hPa((float)(data_raw_pressure.i32bit)); 00519 00520 (void)memset(data_raw_temperature.u8bit, 0x00, sizeof(int16_t)); 00521 if (lps22hh_fifo_temperature_raw_get(&_reg_ctx, data_raw_temperature.u8bit) != 0) { 00522 return 1; 00523 } 00524 00525 *temp = LPS22HH_FROM_LSB_TO_degC((float)(data_raw_temperature.i16bit)); 00526 00527 return 0; 00528 } 00529 00530 /** 00531 * @brief Get the LPS22HH FIFO threshold 00532 * @param status the status of FIFO threshold 00533 * @retval 0 in case of success, an error code otherwise 00534 */ 00535 int LPS22HHSensor::get_fifo_fth_status(uint8_t *status) 00536 { 00537 if (lps22hh_fifo_wtm_flag_get(&_reg_ctx, status) != 0) { 00538 return 1; 00539 } 00540 00541 return 0; 00542 } 00543 00544 /** 00545 * @brief Get the LPS22HH FIFO full status 00546 * @param status the status of FIFO full status 00547 * @retval 0 in case of success, an error code otherwise 00548 */ 00549 int LPS22HHSensor::get_fifo_full_status(uint8_t *status) 00550 { 00551 if (lps22hh_fifo_full_flag_get(&_reg_ctx, status) != 0) { 00552 return 1; 00553 } 00554 00555 return 0; 00556 } 00557 00558 /** 00559 * @brief Get the LPS22HH FIFO OVR status 00560 * @param status the status of FIFO OVR status 00561 * @retval 0 in case of success, an error code otherwise 00562 */ 00563 int LPS22HHSensor::get_fifo_ovr_status(uint8_t *status) 00564 { 00565 if (lps22hh_fifo_ovr_flag_get(&_reg_ctx, status) != 0) { 00566 return 1; 00567 } 00568 00569 return 0; 00570 } 00571 00572 /** 00573 * @brief Get the LPS22HH FIFO data level 00574 * @param status the status of FIFO data level 00575 * @retval 0 in case of success, an error code otherwise 00576 */ 00577 int LPS22HHSensor::get_fifo_level(uint8_t *status) 00578 { 00579 if (lps22hh_fifo_data_level_get(&_reg_ctx, status) != 0) { 00580 return 1; 00581 } 00582 00583 return 0; 00584 } 00585 00586 /** 00587 * @brief Reset the FIFO interrupt 00588 * @param interrupt The FIFO interrupt to be reset; values: 0 = FTH; 1 = FULL; 2 = OVR 00589 * @retval 0 in case of success, an error code otherwise 00590 */ 00591 int LPS22HHSensor::reset_fifo_interrupt(uint8_t interrupt) 00592 { 00593 switch (interrupt) { 00594 case 0: 00595 if (lps22hh_fifo_threshold_on_int_set(&_reg_ctx, PROPERTY_DISABLE) != 0) { 00596 return 1; 00597 } 00598 break; 00599 case 1: 00600 if (lps22hh_fifo_full_on_int_set(&_reg_ctx, PROPERTY_DISABLE) != 0) { 00601 return 1; 00602 } 00603 break; 00604 case 2: 00605 if (lps22hh_fifo_ovr_on_int_set(&_reg_ctx, PROPERTY_DISABLE) != 0) { 00606 return 1; 00607 } 00608 break; 00609 default: 00610 return 1; 00611 } 00612 00613 return 0; 00614 } 00615 00616 /** 00617 * @brief Set the FIFO interrupt 00618 * @param interrupt The FIFO interrupt to be set; values: 0 = FTH; 1 = FULL; 2 = OVR 00619 * @retval 0 in case of success, an error code otherwise 00620 */ 00621 int LPS22HHSensor::set_fifo_interrupt(uint8_t interrupt) 00622 { 00623 switch (interrupt) { 00624 case 0: 00625 if (lps22hh_fifo_threshold_on_int_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { 00626 return 1; 00627 } 00628 break; 00629 case 1: 00630 if (lps22hh_fifo_full_on_int_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { 00631 return 1; 00632 } 00633 break; 00634 case 2: 00635 if (lps22hh_fifo_ovr_on_int_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { 00636 return 1; 00637 } 00638 break; 00639 default: 00640 return 1; 00641 } 00642 00643 return 0; 00644 } 00645 00646 /** 00647 * @brief Set the FIFO mode 00648 * @param Mode the FIFO mode to be set 00649 * @retval 0 in case of success, an error code otherwise 00650 */ 00651 int LPS22HHSensor::set_fifo_mode(uint8_t mode) 00652 { 00653 /* Verify that the passed parameter contains one of the valid values */ 00654 switch ((lps22hh_f_mode_t)mode) { 00655 case LPS22HH_BYPASS_MODE: 00656 case LPS22HH_FIFO_MODE: 00657 case LPS22HH_STREAM_MODE: 00658 case LPS22HH_STREAM_TO_FIFO_MODE: 00659 case LPS22HH_BYPASS_TO_STREAM_MODE: 00660 case LPS22HH_BYPASS_TO_FIFO_MODE: 00661 break; 00662 default: 00663 return 1; 00664 } 00665 00666 if (lps22hh_fifo_mode_set(&_reg_ctx, (lps22hh_f_mode_t)mode) != 0) { 00667 return 1; 00668 } 00669 00670 return 0; 00671 } 00672 00673 /** 00674 * @brief Set the LPS22HH FIFO watermark level 00675 * @param watermark the FIFO watermark level to be set 00676 * @retval 0 in case of success, an error code otherwise 00677 */ 00678 int LPS22HHSensor::set_fifo_watermark_level(uint8_t watermark) 00679 { 00680 if (lps22hh_fifo_watermark_set(&_reg_ctx, watermark) != 0) { 00681 return 1; 00682 } 00683 00684 return 0; 00685 } 00686 00687 /** 00688 * @brief Set the LPS22HH stop on watermark function 00689 * @param stop the state of stop on watermark function 00690 * @retval 0 in case of success, an error code otherwise 00691 */ 00692 int LPS22HHSensor::stop_fifo_on_watermark(uint8_t stop) 00693 { 00694 if (lps22hh_fifo_stop_on_wtm_set(&_reg_ctx, stop) != 0) { 00695 return 1; 00696 } 00697 00698 return 0; 00699 } 00700 00701 /** 00702 * @brief Set the LPS22HH One Shot Mode 00703 * @retval 0 in case of success, an error code otherwise 00704 */ 00705 int LPS22HHSensor::set_one_shot() 00706 { 00707 /* Start One Shot Measurement */ 00708 if (lps22hh_data_rate_set(&_reg_ctx, LPS22HH_ONE_SHOOT) != 0) { 00709 return 1; 00710 } 00711 00712 return 0; 00713 } 00714 00715 /** 00716 * @brief Get the LPS22HH One Shot Status 00717 * @param status pointer to the one shot status (1 means measurements available, 0 means measurements not available yet) 00718 * @retval 0 in case of success, an error code otherwise 00719 */ 00720 int LPS22HHSensor::get_one_shot_status(uint8_t *status) 00721 { 00722 uint8_t p_da; 00723 uint8_t t_da; 00724 00725 /* Get DataReady for pressure */ 00726 if (lps22hh_press_flag_data_ready_get(&_reg_ctx, &p_da) != 0) { 00727 return 1; 00728 } 00729 00730 /* Get DataReady for temperature */ 00731 if (lps22hh_temp_flag_data_ready_get(&_reg_ctx, &t_da) != 0) { 00732 return 1; 00733 } 00734 00735 if (p_da && t_da) { 00736 *status = 1; 00737 } else { 00738 *status = 0; 00739 } 00740 00741 return 0; 00742 } 00743 00744 int32_t LPS22HH_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite) 00745 { 00746 return ((LPS22HHSensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite); 00747 } 00748 00749 int32_t LPS22HH_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead) 00750 { 00751 return ((LPS22HHSensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead); 00752 }
Generated on Wed Jul 13 2022 17:27:40 by
![doxygen](doxygen.png)