Beta

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_IKS01A2 by ST

Committer:
Davidroid
Date:
Tue Mar 14 13:30:55 2017 +0000
Revision:
9:038121268b07
Parent:
6:671fd10a51b7
Updated with the new version of the ST_INTERFACES library, and other typos corrected.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nikapov 0:cad5dab2b21d 1 /**
nikapov 0:cad5dab2b21d 2 ******************************************************************************
nikapov 0:cad5dab2b21d 3 * @file LPS22HBSensor.cpp
cparata 1:bd2a01e81e6f 4 * @author CLab
nikapov 0:cad5dab2b21d 5 * @version V1.0.0
nikapov 0:cad5dab2b21d 6 * @date 5 August 2016
nikapov 0:cad5dab2b21d 7 * @brief Implementation of an LPS22HB Pressure sensor.
nikapov 0:cad5dab2b21d 8 ******************************************************************************
nikapov 0:cad5dab2b21d 9 * @attention
nikapov 0:cad5dab2b21d 10 *
nikapov 0:cad5dab2b21d 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
nikapov 0:cad5dab2b21d 12 *
nikapov 0:cad5dab2b21d 13 * Redistribution and use in source and binary forms, with or without modification,
nikapov 0:cad5dab2b21d 14 * are permitted provided that the following conditions are met:
nikapov 0:cad5dab2b21d 15 * 1. Redistributions of source code must retain the above copyright notice,
nikapov 0:cad5dab2b21d 16 * this list of conditions and the following disclaimer.
nikapov 0:cad5dab2b21d 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
nikapov 0:cad5dab2b21d 18 * this list of conditions and the following disclaimer in the documentation
nikapov 0:cad5dab2b21d 19 * and/or other materials provided with the distribution.
nikapov 0:cad5dab2b21d 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
nikapov 0:cad5dab2b21d 21 * may be used to endorse or promote products derived from this software
nikapov 0:cad5dab2b21d 22 * without specific prior written permission.
nikapov 0:cad5dab2b21d 23 *
nikapov 0:cad5dab2b21d 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
nikapov 0:cad5dab2b21d 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
nikapov 0:cad5dab2b21d 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
nikapov 0:cad5dab2b21d 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
nikapov 0:cad5dab2b21d 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
nikapov 0:cad5dab2b21d 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
nikapov 0:cad5dab2b21d 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
nikapov 0:cad5dab2b21d 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
nikapov 0:cad5dab2b21d 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nikapov 0:cad5dab2b21d 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nikapov 0:cad5dab2b21d 34 *
nikapov 0:cad5dab2b21d 35 ******************************************************************************
nikapov 0:cad5dab2b21d 36 */
nikapov 0:cad5dab2b21d 37
nikapov 0:cad5dab2b21d 38
nikapov 0:cad5dab2b21d 39 /* Includes ------------------------------------------------------------------*/
nikapov 0:cad5dab2b21d 40
nikapov 0:cad5dab2b21d 41 #include "mbed.h"
nikapov 0:cad5dab2b21d 42 #include "DevI2C.h"
nikapov 0:cad5dab2b21d 43 #include "LPS22HBSensor.h"
davide.aliprandi@st.com 6:671fd10a51b7 44 #include "LPS22HB_driver.h"
nikapov 0:cad5dab2b21d 45
nikapov 0:cad5dab2b21d 46
nikapov 0:cad5dab2b21d 47 /* Class Implementation ------------------------------------------------------*/
nikapov 0:cad5dab2b21d 48
nikapov 0:cad5dab2b21d 49 /** Constructor
nikapov 0:cad5dab2b21d 50 * @param i2c object of an helper class which handles the I2C peripheral
nikapov 0:cad5dab2b21d 51 * @param address the address of the component's instance
nikapov 0:cad5dab2b21d 52 */
Davidroid 9:038121268b07 53 LPS22HBSensor::LPS22HBSensor(DevI2C &i2c) : _dev_i2c(i2c)
nikapov 0:cad5dab2b21d 54 {
Davidroid 9:038121268b07 55 _address = LPS22HB_ADDRESS_HIGH;
nikapov 0:cad5dab2b21d 56 };
nikapov 0:cad5dab2b21d 57
nikapov 0:cad5dab2b21d 58
nikapov 0:cad5dab2b21d 59 /** Constructor
nikapov 0:cad5dab2b21d 60 * @param i2c object of an helper class which handles the I2C peripheral
nikapov 0:cad5dab2b21d 61 * @param address the address of the component's instance
nikapov 0:cad5dab2b21d 62 */
Davidroid 9:038121268b07 63 LPS22HBSensor::LPS22HBSensor(DevI2C &i2c, uint8_t address) : _dev_i2c(i2c), _address(address)
nikapov 0:cad5dab2b21d 64 {
nikapov 0:cad5dab2b21d 65
nikapov 0:cad5dab2b21d 66 };
nikapov 0:cad5dab2b21d 67
nikapov 0:cad5dab2b21d 68 /**
nikapov 0:cad5dab2b21d 69 * @brief Initializing the component.
nikapov 0:cad5dab2b21d 70 * @param[in] init pointer to device specific initalization structure.
nikapov 0:cad5dab2b21d 71 * @retval "0" in case of success, an error code otherwise.
nikapov 0:cad5dab2b21d 72 */
davide.aliprandi@st.com 6:671fd10a51b7 73 int LPS22HBSensor::init(void *init)
nikapov 0:cad5dab2b21d 74 {
nikapov 0:cad5dab2b21d 75 if ( LPS22HB_Set_PowerMode( (void *)this, LPS22HB_LowPower) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 76 {
nikapov 0:cad5dab2b21d 77 return 1;
nikapov 0:cad5dab2b21d 78 }
nikapov 0:cad5dab2b21d 79
nikapov 0:cad5dab2b21d 80 /* Power down the device */
nikapov 0:cad5dab2b21d 81 if ( LPS22HB_Set_Odr( (void *)this, LPS22HB_ODR_ONE_SHOT ) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 82 {
nikapov 0:cad5dab2b21d 83 return 1;
nikapov 0:cad5dab2b21d 84 }
nikapov 0:cad5dab2b21d 85
nikapov 0:cad5dab2b21d 86 /* Disable low-pass filter on LPS22HB pressure data */
nikapov 0:cad5dab2b21d 87 if( LPS22HB_Set_LowPassFilter( (void *)this, LPS22HB_DISABLE) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 88 {
nikapov 0:cad5dab2b21d 89 return 1;
nikapov 0:cad5dab2b21d 90 }
nikapov 0:cad5dab2b21d 91
nikapov 0:cad5dab2b21d 92 /* Set low-pass filter cutoff configuration*/
nikapov 0:cad5dab2b21d 93 if( LPS22HB_Set_LowPassFilterCutoff( (void *)this, LPS22HB_ODR_9) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 94 {
nikapov 0:cad5dab2b21d 95 return 1;
nikapov 0:cad5dab2b21d 96 }
nikapov 0:cad5dab2b21d 97
nikapov 0:cad5dab2b21d 98 /* Set block data update mode */
nikapov 0:cad5dab2b21d 99 if ( LPS22HB_Set_Bdu( (void *)this, LPS22HB_BDU_NO_UPDATE ) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 100 {
nikapov 0:cad5dab2b21d 101 return 1;
nikapov 0:cad5dab2b21d 102 }
nikapov 0:cad5dab2b21d 103
nikapov 0:cad5dab2b21d 104 /* Set automatic increment for multi-byte read/write */
nikapov 0:cad5dab2b21d 105 if( LPS22HB_Set_AutomaticIncrementRegAddress( (void *)this, LPS22HB_ENABLE) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 106 {
nikapov 0:cad5dab2b21d 107 return 1;
nikapov 0:cad5dab2b21d 108 }
nikapov 0:cad5dab2b21d 109
Davidroid 9:038121268b07 110 _is_enabled = 0;
Davidroid 9:038121268b07 111 _last_odr = 25.0f;
nikapov 0:cad5dab2b21d 112
nikapov 0:cad5dab2b21d 113 return 0;
nikapov 0:cad5dab2b21d 114 }
nikapov 0:cad5dab2b21d 115
nikapov 0:cad5dab2b21d 116
nikapov 0:cad5dab2b21d 117 /**
nikapov 0:cad5dab2b21d 118 * @brief Enable LPS22HB
nikapov 0:cad5dab2b21d 119 * @retval 0 in case of success, an error code otherwise
nikapov 0:cad5dab2b21d 120 */
Davidroid 9:038121268b07 121 int LPS22HBSensor::enable(void)
nikapov 0:cad5dab2b21d 122 {
nikapov 0:cad5dab2b21d 123 /* Check if the component is already enabled */
Davidroid 9:038121268b07 124 if ( _is_enabled == 1 )
nikapov 0:cad5dab2b21d 125 {
nikapov 0:cad5dab2b21d 126 return 0;
nikapov 0:cad5dab2b21d 127 }
nikapov 0:cad5dab2b21d 128
Davidroid 9:038121268b07 129 if(Set_ODR_When_Enabled(_last_odr) == 1)
nikapov 0:cad5dab2b21d 130 {
nikapov 0:cad5dab2b21d 131 return 1;
nikapov 0:cad5dab2b21d 132 }
nikapov 0:cad5dab2b21d 133
Davidroid 9:038121268b07 134 _is_enabled = 1;
nikapov 0:cad5dab2b21d 135
nikapov 0:cad5dab2b21d 136 return 0;
nikapov 0:cad5dab2b21d 137 }
nikapov 0:cad5dab2b21d 138
nikapov 0:cad5dab2b21d 139 /**
nikapov 0:cad5dab2b21d 140 * @brief Disable LPS22HB
nikapov 0:cad5dab2b21d 141 * @retval 0 in case of success, an error code otherwise
nikapov 0:cad5dab2b21d 142 */
Davidroid 9:038121268b07 143 int LPS22HBSensor::disable(void)
nikapov 0:cad5dab2b21d 144 {
nikapov 0:cad5dab2b21d 145 /* Check if the component is already disabled */
Davidroid 9:038121268b07 146 if ( _is_enabled == 0 )
nikapov 0:cad5dab2b21d 147 {
nikapov 0:cad5dab2b21d 148 return 0;
nikapov 0:cad5dab2b21d 149 }
nikapov 0:cad5dab2b21d 150
nikapov 0:cad5dab2b21d 151 /* Power down the device */
nikapov 0:cad5dab2b21d 152 if ( LPS22HB_Set_Odr( (void *)this, LPS22HB_ODR_ONE_SHOT ) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 153 {
nikapov 0:cad5dab2b21d 154 return 1;
nikapov 0:cad5dab2b21d 155 }
nikapov 0:cad5dab2b21d 156
Davidroid 9:038121268b07 157 _is_enabled = 0;
nikapov 0:cad5dab2b21d 158
nikapov 0:cad5dab2b21d 159 return 0;
nikapov 0:cad5dab2b21d 160 }
nikapov 0:cad5dab2b21d 161
nikapov 0:cad5dab2b21d 162 /**
nikapov 0:cad5dab2b21d 163 * @brief Read ID address of LPS22HB
nikapov 0:cad5dab2b21d 164 * @param id the pointer where the ID of the device is stored
nikapov 0:cad5dab2b21d 165 * @retval 0 in case of success, an error code otherwise
nikapov 0:cad5dab2b21d 166 */
davide.aliprandi@st.com 6:671fd10a51b7 167 int LPS22HBSensor::read_id(uint8_t *id)
nikapov 0:cad5dab2b21d 168 {
nikapov 0:cad5dab2b21d 169 if(!id)
nikapov 0:cad5dab2b21d 170 {
nikapov 0:cad5dab2b21d 171 return 1;
nikapov 0:cad5dab2b21d 172 }
nikapov 0:cad5dab2b21d 173
nikapov 0:cad5dab2b21d 174 /* Read WHO AM I register */
nikapov 0:cad5dab2b21d 175 if ( LPS22HB_Get_DeviceID( (void *)this, id ) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 176 {
nikapov 0:cad5dab2b21d 177 return 1;
nikapov 0:cad5dab2b21d 178 }
nikapov 0:cad5dab2b21d 179
nikapov 0:cad5dab2b21d 180 return 0;
nikapov 0:cad5dab2b21d 181 }
nikapov 0:cad5dab2b21d 182
nikapov 0:cad5dab2b21d 183 /**
nikapov 0:cad5dab2b21d 184 * @brief Reboot memory content of LPS22HB
nikapov 0:cad5dab2b21d 185 * @param None
nikapov 0:cad5dab2b21d 186 * @retval 0 in case of success, an error code otherwise
nikapov 0:cad5dab2b21d 187 */
Davidroid 9:038121268b07 188 int LPS22HBSensor::reset(void)
nikapov 0:cad5dab2b21d 189 {
nikapov 0:cad5dab2b21d 190 /* Read WHO AM I register */
nikapov 0:cad5dab2b21d 191 if ( LPS22HB_MemoryBoot((void *)this) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 192 {
nikapov 0:cad5dab2b21d 193 return 1;
nikapov 0:cad5dab2b21d 194 }
nikapov 0:cad5dab2b21d 195
nikapov 0:cad5dab2b21d 196 return 0;
nikapov 0:cad5dab2b21d 197 }
nikapov 0:cad5dab2b21d 198
nikapov 0:cad5dab2b21d 199 /**
nikapov 0:cad5dab2b21d 200 * @brief Read LPS22HB output register, and calculate the pressure in mbar
nikapov 0:cad5dab2b21d 201 * @param pfData the pressure value in mbar
nikapov 0:cad5dab2b21d 202 * @retval 0 in case of success, an error code otherwise
nikapov 0:cad5dab2b21d 203 */
Davidroid 9:038121268b07 204 int LPS22HBSensor::get_pressure(float* pfData)
nikapov 0:cad5dab2b21d 205 {
nikapov 0:cad5dab2b21d 206 int32_t int32data = 0;
nikapov 0:cad5dab2b21d 207
nikapov 0:cad5dab2b21d 208 /* Read data from LPS22HB. */
nikapov 0:cad5dab2b21d 209 if ( LPS22HB_Get_Pressure( (void *)this, &int32data ) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 210 {
nikapov 0:cad5dab2b21d 211 return 1;
nikapov 0:cad5dab2b21d 212 }
nikapov 0:cad5dab2b21d 213
nikapov 0:cad5dab2b21d 214 *pfData = ( float )int32data / 100.0f;
nikapov 0:cad5dab2b21d 215
nikapov 0:cad5dab2b21d 216 return 0;
nikapov 0:cad5dab2b21d 217 }
nikapov 0:cad5dab2b21d 218
nikapov 0:cad5dab2b21d 219 /**
nikapov 0:cad5dab2b21d 220 * @brief Read LPS22HB output register, and calculate the temperature
nikapov 0:cad5dab2b21d 221 * @param pfData the temperature value
nikapov 0:cad5dab2b21d 222 * @retval 0 in case of success, an error code otherwise
nikapov 0:cad5dab2b21d 223 */
Davidroid 9:038121268b07 224 int LPS22HBSensor::get_temperature(float *pfData)
nikapov 0:cad5dab2b21d 225 {
nikapov 0:cad5dab2b21d 226 int16_t int16data = 0;
nikapov 0:cad5dab2b21d 227
nikapov 0:cad5dab2b21d 228 /* Read data from LPS22HB. */
nikapov 0:cad5dab2b21d 229 if ( LPS22HB_Get_Temperature( (void *)this, &int16data ) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 230 {
nikapov 0:cad5dab2b21d 231 return 1;
nikapov 0:cad5dab2b21d 232 }
nikapov 0:cad5dab2b21d 233
nikapov 0:cad5dab2b21d 234 *pfData = ( float )int16data / 10.0f;
nikapov 0:cad5dab2b21d 235
nikapov 0:cad5dab2b21d 236 return 0;
nikapov 0:cad5dab2b21d 237 }
nikapov 0:cad5dab2b21d 238
nikapov 0:cad5dab2b21d 239 /**
nikapov 0:cad5dab2b21d 240 * @brief Read LPS22HB output data rate
nikapov 0:cad5dab2b21d 241 * @param odr the pointer to the output data rate
nikapov 0:cad5dab2b21d 242 * @retval 0 in case of success, an error code otherwise
nikapov 0:cad5dab2b21d 243 */
Davidroid 9:038121268b07 244 int LPS22HBSensor::get_odr(float* odr)
nikapov 0:cad5dab2b21d 245 {
nikapov 0:cad5dab2b21d 246 LPS22HB_Odr_et odr_low_level;
nikapov 0:cad5dab2b21d 247
nikapov 0:cad5dab2b21d 248 if ( LPS22HB_Get_Odr( (void *)this, &odr_low_level ) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 249 {
nikapov 0:cad5dab2b21d 250 return 1;
nikapov 0:cad5dab2b21d 251 }
nikapov 0:cad5dab2b21d 252
nikapov 0:cad5dab2b21d 253 switch( odr_low_level )
nikapov 0:cad5dab2b21d 254 {
nikapov 0:cad5dab2b21d 255 case LPS22HB_ODR_ONE_SHOT:
nikapov 0:cad5dab2b21d 256 *odr = 0.0f;
nikapov 0:cad5dab2b21d 257 break;
nikapov 0:cad5dab2b21d 258 case LPS22HB_ODR_1HZ:
nikapov 0:cad5dab2b21d 259 *odr = 1.0f;
nikapov 0:cad5dab2b21d 260 break;
nikapov 0:cad5dab2b21d 261 case LPS22HB_ODR_10HZ:
nikapov 0:cad5dab2b21d 262 *odr = 10.0f;
nikapov 0:cad5dab2b21d 263 break;
nikapov 0:cad5dab2b21d 264 case LPS22HB_ODR_25HZ:
nikapov 0:cad5dab2b21d 265 *odr = 25.0f;
nikapov 0:cad5dab2b21d 266 break;
nikapov 0:cad5dab2b21d 267 case LPS22HB_ODR_50HZ:
nikapov 0:cad5dab2b21d 268 *odr = 50.0f;
nikapov 0:cad5dab2b21d 269 break;
nikapov 0:cad5dab2b21d 270 case LPS22HB_ODR_75HZ:
nikapov 0:cad5dab2b21d 271 *odr = 75.0f;
nikapov 0:cad5dab2b21d 272 break;
nikapov 0:cad5dab2b21d 273 default:
nikapov 0:cad5dab2b21d 274 *odr = -1.0f;
nikapov 0:cad5dab2b21d 275 return 1;
nikapov 0:cad5dab2b21d 276 }
nikapov 0:cad5dab2b21d 277
nikapov 0:cad5dab2b21d 278 return 0;
nikapov 0:cad5dab2b21d 279 }
nikapov 0:cad5dab2b21d 280
nikapov 0:cad5dab2b21d 281 /**
nikapov 0:cad5dab2b21d 282 * @brief Set ODR
nikapov 0:cad5dab2b21d 283 * @param odr the output data rate to be set
nikapov 0:cad5dab2b21d 284 * @retval 0 in case of success, an error code otherwise
nikapov 0:cad5dab2b21d 285 */
Davidroid 9:038121268b07 286 int LPS22HBSensor::set_odr(float odr)
nikapov 0:cad5dab2b21d 287 {
Davidroid 9:038121268b07 288 if(_is_enabled == 1)
nikapov 0:cad5dab2b21d 289 {
nikapov 0:cad5dab2b21d 290 if(Set_ODR_When_Enabled(odr) == 1)
nikapov 0:cad5dab2b21d 291 {
nikapov 0:cad5dab2b21d 292 return 1;
nikapov 0:cad5dab2b21d 293 }
nikapov 0:cad5dab2b21d 294 }
nikapov 0:cad5dab2b21d 295 else
nikapov 0:cad5dab2b21d 296 {
nikapov 0:cad5dab2b21d 297 if(Set_ODR_When_Disabled(odr) == 1)
nikapov 0:cad5dab2b21d 298 {
nikapov 0:cad5dab2b21d 299 return 1;
nikapov 0:cad5dab2b21d 300 }
nikapov 0:cad5dab2b21d 301 }
nikapov 0:cad5dab2b21d 302
nikapov 0:cad5dab2b21d 303 return 0;
nikapov 0:cad5dab2b21d 304 }
nikapov 0:cad5dab2b21d 305
nikapov 0:cad5dab2b21d 306
nikapov 0:cad5dab2b21d 307 /**
nikapov 0:cad5dab2b21d 308 * @brief Set the LPS22HB sensor output data rate when enabled
nikapov 0:cad5dab2b21d 309 * @param odr the functional output data rate to be set
nikapov 0:cad5dab2b21d 310 * @retval 0 in case of success
nikapov 0:cad5dab2b21d 311 * @retval 1 in case of failure
nikapov 0:cad5dab2b21d 312 */
nikapov 0:cad5dab2b21d 313 int LPS22HBSensor::Set_ODR_When_Enabled( float odr )
nikapov 0:cad5dab2b21d 314 {
nikapov 0:cad5dab2b21d 315 LPS22HB_Odr_et new_odr;
nikapov 0:cad5dab2b21d 316
nikapov 0:cad5dab2b21d 317 new_odr = ( odr <= 1.0f ) ? LPS22HB_ODR_1HZ
nikapov 0:cad5dab2b21d 318 : ( odr <= 10.0f ) ? LPS22HB_ODR_10HZ
nikapov 0:cad5dab2b21d 319 : ( odr <= 25.0f ) ? LPS22HB_ODR_25HZ
nikapov 0:cad5dab2b21d 320 : ( odr <= 50.0f ) ? LPS22HB_ODR_50HZ
nikapov 0:cad5dab2b21d 321 : LPS22HB_ODR_75HZ;
nikapov 0:cad5dab2b21d 322
nikapov 0:cad5dab2b21d 323 if ( LPS22HB_Set_Odr( (void *)this, new_odr ) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 324 {
nikapov 0:cad5dab2b21d 325 return 1;
nikapov 0:cad5dab2b21d 326 }
nikapov 0:cad5dab2b21d 327
Davidroid 9:038121268b07 328 if ( get_odr( &_last_odr ) == 1 )
nikapov 0:cad5dab2b21d 329 {
nikapov 0:cad5dab2b21d 330 return 1;
nikapov 0:cad5dab2b21d 331 }
nikapov 0:cad5dab2b21d 332
nikapov 0:cad5dab2b21d 333 return 0;
nikapov 0:cad5dab2b21d 334 }
nikapov 0:cad5dab2b21d 335
nikapov 0:cad5dab2b21d 336 /**
nikapov 0:cad5dab2b21d 337 * @brief Set the LPS22HB sensor output data rate when disabled
nikapov 0:cad5dab2b21d 338 * @param odr the functional output data rate to be set
nikapov 0:cad5dab2b21d 339 * @retval 0 in case of success
nikapov 0:cad5dab2b21d 340 * @retval 1 in case of failure
nikapov 0:cad5dab2b21d 341 */
nikapov 0:cad5dab2b21d 342 int LPS22HBSensor::Set_ODR_When_Disabled( float odr )
nikapov 0:cad5dab2b21d 343 {
Davidroid 9:038121268b07 344 _last_odr = ( odr <= 1.0f ) ? 1.0f
nikapov 0:cad5dab2b21d 345 : ( odr <= 10.0f ) ? 10.0f
nikapov 0:cad5dab2b21d 346 : ( odr <= 25.0f ) ? 25.0f
nikapov 0:cad5dab2b21d 347 : ( odr <= 50.0f ) ? 50.0f
nikapov 0:cad5dab2b21d 348 : 75.0f;
nikapov 0:cad5dab2b21d 349
nikapov 0:cad5dab2b21d 350 return 0;
nikapov 0:cad5dab2b21d 351 }
nikapov 0:cad5dab2b21d 352
nikapov 0:cad5dab2b21d 353
nikapov 0:cad5dab2b21d 354 /**
nikapov 0:cad5dab2b21d 355 * @brief Read the data from register
nikapov 0:cad5dab2b21d 356 * @param reg register address
nikapov 0:cad5dab2b21d 357 * @param data register data
nikapov 0:cad5dab2b21d 358 * @retval 0 in case of success
nikapov 0:cad5dab2b21d 359 * @retval 1 in case of failure
nikapov 0:cad5dab2b21d 360 */
davide.aliprandi@st.com 6:671fd10a51b7 361 int LPS22HBSensor::read_reg( uint8_t reg, uint8_t *data )
nikapov 0:cad5dab2b21d 362 {
nikapov 0:cad5dab2b21d 363
davide.aliprandi@st.com 6:671fd10a51b7 364 if ( LPS22HB_read_reg( (void *)this, reg, 1, data ) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 365 {
nikapov 0:cad5dab2b21d 366 return 1;
nikapov 0:cad5dab2b21d 367 }
nikapov 0:cad5dab2b21d 368
nikapov 0:cad5dab2b21d 369 return 0;
nikapov 0:cad5dab2b21d 370 }
nikapov 0:cad5dab2b21d 371
nikapov 0:cad5dab2b21d 372 /**
nikapov 0:cad5dab2b21d 373 * @brief Write the data to register
nikapov 0:cad5dab2b21d 374 * @param reg register address
nikapov 0:cad5dab2b21d 375 * @param data register data
nikapov 0:cad5dab2b21d 376 * @retval 0 in case of success
nikapov 0:cad5dab2b21d 377 * @retval 1 in case of failure
nikapov 0:cad5dab2b21d 378 */
davide.aliprandi@st.com 6:671fd10a51b7 379 int LPS22HBSensor::write_reg( uint8_t reg, uint8_t data )
nikapov 0:cad5dab2b21d 380 {
nikapov 0:cad5dab2b21d 381
davide.aliprandi@st.com 6:671fd10a51b7 382 if ( LPS22HB_write_reg( (void *)this, reg, 1, &data ) == LPS22HB_ERROR )
nikapov 0:cad5dab2b21d 383 {
nikapov 0:cad5dab2b21d 384 return 1;
nikapov 0:cad5dab2b21d 385 }
nikapov 0:cad5dab2b21d 386
nikapov 0:cad5dab2b21d 387 return 0;
nikapov 0:cad5dab2b21d 388 }
nikapov 0:cad5dab2b21d 389
nikapov 0:cad5dab2b21d 390
davide.aliprandi@st.com 6:671fd10a51b7 391 uint8_t LPS22HB_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite )
nikapov 0:cad5dab2b21d 392 {
davide.aliprandi@st.com 6:671fd10a51b7 393 return ((LPS22HBSensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite);
nikapov 0:cad5dab2b21d 394 }
nikapov 0:cad5dab2b21d 395
davide.aliprandi@st.com 6:671fd10a51b7 396 uint8_t LPS22HB_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead )
nikapov 0:cad5dab2b21d 397 {
davide.aliprandi@st.com 6:671fd10a51b7 398 return ((LPS22HBSensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead);
nikapov 0:cad5dab2b21d 399 }