Example of wake up detection for LSM6DSL in X-NUCLEO-IKS01A2

Dependencies:   X_NUCLEO_IKS01A2 mbed

Fork of WakeUp_IKS01A2 by ST Expansion SW Team

Wake up Demo Application based on sensor expansion board X-NUCLEO-IKS01A2

Main function is to show how to detect the wake up event using the sensor expansion board and send a notification using UART to a connected PC or Desktop and display it on terminal applications like TeraTerm.
After connection has been established:
- the user can try to shake the board and then view the notification using an hyper terminal. When the wake up event is detected, the LED is switched on for a while.
- the user button can be used to enable/disable the wake up detection feature.

Committer:
cparata
Date:
Fri Aug 12 13:43:40 2016 +0000
Revision:
0:e7e920b85676
First release of Wake-Up Detection for LSM6DSL in IKS01A2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cparata 0:e7e920b85676 1 /**
cparata 0:e7e920b85676 2 ******************************************************************************
cparata 0:e7e920b85676 3 * @file LSM303AGR_ACC_Sensor.cpp
cparata 0:e7e920b85676 4 * @author AST
cparata 0:e7e920b85676 5 * @version V1.0.0
cparata 0:e7e920b85676 6 * @date 5 August 2016
cparata 0:e7e920b85676 7 * @brief Implementation an LSM303AGR accelerometer sensor.
cparata 0:e7e920b85676 8 ******************************************************************************
cparata 0:e7e920b85676 9 * @attention
cparata 0:e7e920b85676 10 *
cparata 0:e7e920b85676 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
cparata 0:e7e920b85676 12 *
cparata 0:e7e920b85676 13 * Redistribution and use in source and binary forms, with or without modification,
cparata 0:e7e920b85676 14 * are permitted provided that the following conditions are met:
cparata 0:e7e920b85676 15 * 1. Redistributions of source code must retain the above copyright notice,
cparata 0:e7e920b85676 16 * this list of conditions and the following disclaimer.
cparata 0:e7e920b85676 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
cparata 0:e7e920b85676 18 * this list of conditions and the following disclaimer in the documentation
cparata 0:e7e920b85676 19 * and/or other materials provided with the distribution.
cparata 0:e7e920b85676 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
cparata 0:e7e920b85676 21 * may be used to endorse or promote products derived from this software
cparata 0:e7e920b85676 22 * without specific prior written permission.
cparata 0:e7e920b85676 23 *
cparata 0:e7e920b85676 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cparata 0:e7e920b85676 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cparata 0:e7e920b85676 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
cparata 0:e7e920b85676 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
cparata 0:e7e920b85676 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
cparata 0:e7e920b85676 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
cparata 0:e7e920b85676 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
cparata 0:e7e920b85676 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
cparata 0:e7e920b85676 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
cparata 0:e7e920b85676 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cparata 0:e7e920b85676 34 *
cparata 0:e7e920b85676 35 ******************************************************************************
cparata 0:e7e920b85676 36 */
cparata 0:e7e920b85676 37
cparata 0:e7e920b85676 38
cparata 0:e7e920b85676 39 /* Includes ------------------------------------------------------------------*/
cparata 0:e7e920b85676 40
cparata 0:e7e920b85676 41 #include "DevI2C.h"
cparata 0:e7e920b85676 42 #include "LSM303AGR_ACC_Sensor.h"
cparata 0:e7e920b85676 43 #include "LSM303AGR_ACC_driver.h"
cparata 0:e7e920b85676 44
cparata 0:e7e920b85676 45
cparata 0:e7e920b85676 46 /* Class Implementation ------------------------------------------------------*/
cparata 0:e7e920b85676 47
cparata 0:e7e920b85676 48 /** Constructor
cparata 0:e7e920b85676 49 * @param i2c object of an helper class which handles the I2C peripheral
cparata 0:e7e920b85676 50 * @param address the address of the component's instance
cparata 0:e7e920b85676 51 */
cparata 0:e7e920b85676 52 LSM303AGR_ACC_Sensor::LSM303AGR_ACC_Sensor(DevI2C &i2c) : dev_i2c(i2c)
cparata 0:e7e920b85676 53 {
cparata 0:e7e920b85676 54 address = LSM303AGR_ACC_I2C_ADDRESS;
cparata 0:e7e920b85676 55
cparata 0:e7e920b85676 56 /* Enable BDU */
cparata 0:e7e920b85676 57 if ( LSM303AGR_ACC_W_BlockDataUpdate( (void *)this, LSM303AGR_ACC_BDU_ENABLED ) == MEMS_ERROR )
cparata 0:e7e920b85676 58 {
cparata 0:e7e920b85676 59 return;
cparata 0:e7e920b85676 60 }
cparata 0:e7e920b85676 61
cparata 0:e7e920b85676 62 /* FIFO mode selection */
cparata 0:e7e920b85676 63 if ( LSM303AGR_ACC_W_FifoMode( (void *)this, LSM303AGR_ACC_FM_BYPASS ) == MEMS_ERROR )
cparata 0:e7e920b85676 64 {
cparata 0:e7e920b85676 65 return;
cparata 0:e7e920b85676 66 }
cparata 0:e7e920b85676 67
cparata 0:e7e920b85676 68 /* Output data rate selection - power down. */
cparata 0:e7e920b85676 69 if ( LSM303AGR_ACC_W_ODR( (void *)this, LSM303AGR_ACC_ODR_DO_PWR_DOWN ) == MEMS_ERROR )
cparata 0:e7e920b85676 70 {
cparata 0:e7e920b85676 71 return;
cparata 0:e7e920b85676 72 }
cparata 0:e7e920b85676 73
cparata 0:e7e920b85676 74 /* Full scale selection. */
cparata 0:e7e920b85676 75 if ( SetFS( 2.0f ) == LSM303AGR_ACC_STATUS_ERROR )
cparata 0:e7e920b85676 76 {
cparata 0:e7e920b85676 77 return;
cparata 0:e7e920b85676 78 }
cparata 0:e7e920b85676 79
cparata 0:e7e920b85676 80 /* Enable axes. */
cparata 0:e7e920b85676 81 if ( LSM303AGR_ACC_W_XEN( (void *)this, LSM303AGR_ACC_XEN_ENABLED ) == MEMS_ERROR )
cparata 0:e7e920b85676 82 {
cparata 0:e7e920b85676 83 return;
cparata 0:e7e920b85676 84 }
cparata 0:e7e920b85676 85
cparata 0:e7e920b85676 86 if ( LSM303AGR_ACC_W_YEN ( (void *)this, LSM303AGR_ACC_YEN_ENABLED ) == MEMS_ERROR )
cparata 0:e7e920b85676 87 {
cparata 0:e7e920b85676 88 return;
cparata 0:e7e920b85676 89 }
cparata 0:e7e920b85676 90
cparata 0:e7e920b85676 91 if ( LSM303AGR_ACC_W_ZEN ( (void *)this, LSM303AGR_ACC_ZEN_ENABLED ) == MEMS_ERROR )
cparata 0:e7e920b85676 92 {
cparata 0:e7e920b85676 93 return;
cparata 0:e7e920b85676 94 }
cparata 0:e7e920b85676 95
cparata 0:e7e920b85676 96 /* Select default output data rate. */
cparata 0:e7e920b85676 97 Last_ODR = 100.0f;
cparata 0:e7e920b85676 98
cparata 0:e7e920b85676 99 isEnabled = 0;
cparata 0:e7e920b85676 100 };
cparata 0:e7e920b85676 101
cparata 0:e7e920b85676 102 /** Constructor
cparata 0:e7e920b85676 103 * @param i2c object of an helper class which handles the I2C peripheral
cparata 0:e7e920b85676 104 * @param address the address of the component's instance
cparata 0:e7e920b85676 105 */
cparata 0:e7e920b85676 106 LSM303AGR_ACC_Sensor::LSM303AGR_ACC_Sensor(DevI2C &i2c, uint8_t address) : dev_i2c(i2c), address(address)
cparata 0:e7e920b85676 107 {
cparata 0:e7e920b85676 108 /* Enable BDU */
cparata 0:e7e920b85676 109 if ( LSM303AGR_ACC_W_BlockDataUpdate( (void *)this, LSM303AGR_ACC_BDU_ENABLED ) == MEMS_ERROR )
cparata 0:e7e920b85676 110 {
cparata 0:e7e920b85676 111 return;
cparata 0:e7e920b85676 112 }
cparata 0:e7e920b85676 113
cparata 0:e7e920b85676 114 /* FIFO mode selection */
cparata 0:e7e920b85676 115 if ( LSM303AGR_ACC_W_FifoMode( (void *)this, LSM303AGR_ACC_FM_BYPASS ) == MEMS_ERROR )
cparata 0:e7e920b85676 116 {
cparata 0:e7e920b85676 117 return;
cparata 0:e7e920b85676 118 }
cparata 0:e7e920b85676 119
cparata 0:e7e920b85676 120 /* Output data rate selection - power down. */
cparata 0:e7e920b85676 121 if ( LSM303AGR_ACC_W_ODR( (void *)this, LSM303AGR_ACC_ODR_DO_PWR_DOWN ) == MEMS_ERROR )
cparata 0:e7e920b85676 122 {
cparata 0:e7e920b85676 123 return;
cparata 0:e7e920b85676 124 }
cparata 0:e7e920b85676 125
cparata 0:e7e920b85676 126 /* Full scale selection. */
cparata 0:e7e920b85676 127 if ( SetFS( 2.0f ) == LSM303AGR_ACC_STATUS_ERROR )
cparata 0:e7e920b85676 128 {
cparata 0:e7e920b85676 129 return;
cparata 0:e7e920b85676 130 }
cparata 0:e7e920b85676 131
cparata 0:e7e920b85676 132 /* Enable axes. */
cparata 0:e7e920b85676 133 if ( LSM303AGR_ACC_W_XEN( (void *)this, LSM303AGR_ACC_XEN_ENABLED ) == MEMS_ERROR )
cparata 0:e7e920b85676 134 {
cparata 0:e7e920b85676 135 return;
cparata 0:e7e920b85676 136 }
cparata 0:e7e920b85676 137
cparata 0:e7e920b85676 138 if ( LSM303AGR_ACC_W_YEN ( (void *)this, LSM303AGR_ACC_YEN_ENABLED ) == MEMS_ERROR )
cparata 0:e7e920b85676 139 {
cparata 0:e7e920b85676 140 return;
cparata 0:e7e920b85676 141 }
cparata 0:e7e920b85676 142
cparata 0:e7e920b85676 143 if ( LSM303AGR_ACC_W_ZEN ( (void *)this, LSM303AGR_ACC_ZEN_ENABLED ) == MEMS_ERROR )
cparata 0:e7e920b85676 144 {
cparata 0:e7e920b85676 145 return;
cparata 0:e7e920b85676 146 }
cparata 0:e7e920b85676 147
cparata 0:e7e920b85676 148 /* Select default output data rate. */
cparata 0:e7e920b85676 149 Last_ODR = 100.0f;
cparata 0:e7e920b85676 150
cparata 0:e7e920b85676 151 isEnabled = 0;
cparata 0:e7e920b85676 152 };
cparata 0:e7e920b85676 153
cparata 0:e7e920b85676 154 /**
cparata 0:e7e920b85676 155 * @brief Enable LSM303AGR Accelerator
cparata 0:e7e920b85676 156 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 157 */
cparata 0:e7e920b85676 158 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::Enable(void)
cparata 0:e7e920b85676 159 {
cparata 0:e7e920b85676 160 /* Check if the component is already enabled */
cparata 0:e7e920b85676 161 if ( isEnabled == 1 )
cparata 0:e7e920b85676 162 {
cparata 0:e7e920b85676 163 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 164 }
cparata 0:e7e920b85676 165
cparata 0:e7e920b85676 166 /* Output data rate selection. */
cparata 0:e7e920b85676 167 if ( SetODR_When_Enabled( Last_ODR ) == LSM303AGR_ACC_STATUS_ERROR )
cparata 0:e7e920b85676 168 {
cparata 0:e7e920b85676 169 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 170 }
cparata 0:e7e920b85676 171
cparata 0:e7e920b85676 172 isEnabled = 1;
cparata 0:e7e920b85676 173
cparata 0:e7e920b85676 174 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 175 }
cparata 0:e7e920b85676 176
cparata 0:e7e920b85676 177 /**
cparata 0:e7e920b85676 178 * @brief Disable LSM303AGR Accelerator
cparata 0:e7e920b85676 179 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 180 */
cparata 0:e7e920b85676 181 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::Disable(void)
cparata 0:e7e920b85676 182 {
cparata 0:e7e920b85676 183 /* Check if the component is already disabled */
cparata 0:e7e920b85676 184 if ( isEnabled == 0 )
cparata 0:e7e920b85676 185 {
cparata 0:e7e920b85676 186 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 187 }
cparata 0:e7e920b85676 188
cparata 0:e7e920b85676 189 /* Store actual output data rate. */
cparata 0:e7e920b85676 190 if ( GetODR( &Last_ODR ) == LSM303AGR_ACC_STATUS_ERROR )
cparata 0:e7e920b85676 191 {
cparata 0:e7e920b85676 192 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 193 }
cparata 0:e7e920b85676 194
cparata 0:e7e920b85676 195 /* Output data rate selection - power down. */
cparata 0:e7e920b85676 196 if ( LSM303AGR_ACC_W_ODR( (void *)this, LSM303AGR_ACC_ODR_DO_PWR_DOWN ) == MEMS_ERROR )
cparata 0:e7e920b85676 197 {
cparata 0:e7e920b85676 198 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 199 }
cparata 0:e7e920b85676 200
cparata 0:e7e920b85676 201 isEnabled = 0;
cparata 0:e7e920b85676 202
cparata 0:e7e920b85676 203 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 204 }
cparata 0:e7e920b85676 205
cparata 0:e7e920b85676 206 /**
cparata 0:e7e920b85676 207 * @brief Read ID of LSM303AGR Accelerometer
cparata 0:e7e920b85676 208 * @param p_id the pointer where the ID of the device is stored
cparata 0:e7e920b85676 209 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 210 */
cparata 0:e7e920b85676 211 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::ReadID(uint8_t *p_id)
cparata 0:e7e920b85676 212 {
cparata 0:e7e920b85676 213 if(!p_id)
cparata 0:e7e920b85676 214 {
cparata 0:e7e920b85676 215 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 216 }
cparata 0:e7e920b85676 217
cparata 0:e7e920b85676 218 /* Read WHO AM I register */
cparata 0:e7e920b85676 219 if ( LSM303AGR_ACC_R_WHO_AM_I( (void *)this, p_id ) == MEMS_ERROR )
cparata 0:e7e920b85676 220 {
cparata 0:e7e920b85676 221 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 222 }
cparata 0:e7e920b85676 223
cparata 0:e7e920b85676 224 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 225 }
cparata 0:e7e920b85676 226
cparata 0:e7e920b85676 227 /**
cparata 0:e7e920b85676 228 * @brief Read data from LSM303AGR Accelerometer
cparata 0:e7e920b85676 229 * @param pData the pointer where the accelerometer data are stored
cparata 0:e7e920b85676 230 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 231 */
cparata 0:e7e920b85676 232 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetAxes(int32_t *pData)
cparata 0:e7e920b85676 233 {
cparata 0:e7e920b85676 234 int data[3];
cparata 0:e7e920b85676 235
cparata 0:e7e920b85676 236 /* Read data from LSM303AGR. */
cparata 0:e7e920b85676 237 if ( !LSM303AGR_ACC_Get_Acceleration((void *)this, data) )
cparata 0:e7e920b85676 238 {
cparata 0:e7e920b85676 239 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 240 }
cparata 0:e7e920b85676 241
cparata 0:e7e920b85676 242 /* Calculate the data. */
cparata 0:e7e920b85676 243 pData[0] = (int32_t)data[0];
cparata 0:e7e920b85676 244 pData[1] = (int32_t)data[1];
cparata 0:e7e920b85676 245 pData[2] = (int32_t)data[2];
cparata 0:e7e920b85676 246
cparata 0:e7e920b85676 247 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 248 }
cparata 0:e7e920b85676 249
cparata 0:e7e920b85676 250 /**
cparata 0:e7e920b85676 251 * @brief Read Accelerometer Sensitivity
cparata 0:e7e920b85676 252 * @param pfData the pointer where the accelerometer sensitivity is stored
cparata 0:e7e920b85676 253 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 254 */
cparata 0:e7e920b85676 255 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetSensitivity(float *pfData)
cparata 0:e7e920b85676 256 {
cparata 0:e7e920b85676 257 LSM303AGR_ACC_LPEN_t lp_value;
cparata 0:e7e920b85676 258 LSM303AGR_ACC_HR_t hr_value;
cparata 0:e7e920b85676 259
cparata 0:e7e920b85676 260 /* Read low power flag */
cparata 0:e7e920b85676 261 if( LSM303AGR_ACC_R_LOWPWR_EN( (void *)this, &lp_value ) == MEMS_ERROR )
cparata 0:e7e920b85676 262 {
cparata 0:e7e920b85676 263 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 264 }
cparata 0:e7e920b85676 265
cparata 0:e7e920b85676 266 /* Read high performance flag */
cparata 0:e7e920b85676 267 if( LSM303AGR_ACC_R_HiRes( (void *)this, &hr_value ) == MEMS_ERROR )
cparata 0:e7e920b85676 268 {
cparata 0:e7e920b85676 269 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 270 }
cparata 0:e7e920b85676 271
cparata 0:e7e920b85676 272 if( lp_value == LSM303AGR_ACC_LPEN_DISABLED && hr_value == LSM303AGR_ACC_HR_DISABLED )
cparata 0:e7e920b85676 273 {
cparata 0:e7e920b85676 274 /* Normal Mode */
cparata 0:e7e920b85676 275 return GetSensitivity_Normal_Mode( pfData );
cparata 0:e7e920b85676 276 } else if ( lp_value == LSM303AGR_ACC_LPEN_ENABLED && hr_value == LSM303AGR_ACC_HR_DISABLED )
cparata 0:e7e920b85676 277 {
cparata 0:e7e920b85676 278 /* Low Power Mode */
cparata 0:e7e920b85676 279 return GetSensitivity_LP_Mode( pfData );
cparata 0:e7e920b85676 280 } else if ( lp_value == LSM303AGR_ACC_LPEN_DISABLED && hr_value == LSM303AGR_ACC_HR_ENABLED )
cparata 0:e7e920b85676 281 {
cparata 0:e7e920b85676 282 /* High Resolution Mode */
cparata 0:e7e920b85676 283 return GetSensitivity_HR_Mode( pfData );
cparata 0:e7e920b85676 284 } else
cparata 0:e7e920b85676 285 {
cparata 0:e7e920b85676 286 /* Not allowed */
cparata 0:e7e920b85676 287 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 288 }
cparata 0:e7e920b85676 289 }
cparata 0:e7e920b85676 290
cparata 0:e7e920b85676 291 /**
cparata 0:e7e920b85676 292 * @brief Read Accelerometer Sensitivity in Normal Mode
cparata 0:e7e920b85676 293 * @param sensitivity the pointer where the accelerometer sensitivity is stored
cparata 0:e7e920b85676 294 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 295 */
cparata 0:e7e920b85676 296 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetSensitivity_Normal_Mode( float *sensitivity )
cparata 0:e7e920b85676 297 {
cparata 0:e7e920b85676 298 LSM303AGR_ACC_FS_t fullScale;
cparata 0:e7e920b85676 299
cparata 0:e7e920b85676 300 /* Read actual full scale selection from sensor. */
cparata 0:e7e920b85676 301 if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR )
cparata 0:e7e920b85676 302 {
cparata 0:e7e920b85676 303 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 304 }
cparata 0:e7e920b85676 305
cparata 0:e7e920b85676 306 /* Store the sensitivity based on actual full scale. */
cparata 0:e7e920b85676 307 switch( fullScale )
cparata 0:e7e920b85676 308 {
cparata 0:e7e920b85676 309 case LSM303AGR_ACC_FS_2G:
cparata 0:e7e920b85676 310 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_NORMAL_MODE;
cparata 0:e7e920b85676 311 break;
cparata 0:e7e920b85676 312 case LSM303AGR_ACC_FS_4G:
cparata 0:e7e920b85676 313 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_NORMAL_MODE;
cparata 0:e7e920b85676 314 break;
cparata 0:e7e920b85676 315 case LSM303AGR_ACC_FS_8G:
cparata 0:e7e920b85676 316 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_NORMAL_MODE;
cparata 0:e7e920b85676 317 break;
cparata 0:e7e920b85676 318 case LSM303AGR_ACC_FS_16G:
cparata 0:e7e920b85676 319 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_NORMAL_MODE;
cparata 0:e7e920b85676 320 break;
cparata 0:e7e920b85676 321 default:
cparata 0:e7e920b85676 322 *sensitivity = -1.0f;
cparata 0:e7e920b85676 323 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 324 }
cparata 0:e7e920b85676 325
cparata 0:e7e920b85676 326 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 327 }
cparata 0:e7e920b85676 328
cparata 0:e7e920b85676 329 /**
cparata 0:e7e920b85676 330 * @brief Read Accelerometer Sensitivity in LP Mode
cparata 0:e7e920b85676 331 * @param sensitivity the pointer where the accelerometer sensitivity is stored
cparata 0:e7e920b85676 332 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 333 */
cparata 0:e7e920b85676 334 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetSensitivity_LP_Mode( float *sensitivity )
cparata 0:e7e920b85676 335 {
cparata 0:e7e920b85676 336 LSM303AGR_ACC_FS_t fullScale;
cparata 0:e7e920b85676 337
cparata 0:e7e920b85676 338 /* Read actual full scale selection from sensor. */
cparata 0:e7e920b85676 339 if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR )
cparata 0:e7e920b85676 340 {
cparata 0:e7e920b85676 341 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 342 }
cparata 0:e7e920b85676 343
cparata 0:e7e920b85676 344 /* Store the sensitivity based on actual full scale. */
cparata 0:e7e920b85676 345 switch( fullScale )
cparata 0:e7e920b85676 346 {
cparata 0:e7e920b85676 347 case LSM303AGR_ACC_FS_2G:
cparata 0:e7e920b85676 348 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_LOW_POWER_MODE;
cparata 0:e7e920b85676 349 break;
cparata 0:e7e920b85676 350 case LSM303AGR_ACC_FS_4G:
cparata 0:e7e920b85676 351 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_LOW_POWER_MODE;
cparata 0:e7e920b85676 352 break;
cparata 0:e7e920b85676 353 case LSM303AGR_ACC_FS_8G:
cparata 0:e7e920b85676 354 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_LOW_POWER_MODE;
cparata 0:e7e920b85676 355 break;
cparata 0:e7e920b85676 356 case LSM303AGR_ACC_FS_16G:
cparata 0:e7e920b85676 357 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_LOW_POWER_MODE;
cparata 0:e7e920b85676 358 break;
cparata 0:e7e920b85676 359 default:
cparata 0:e7e920b85676 360 *sensitivity = -1.0f;
cparata 0:e7e920b85676 361 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 362 }
cparata 0:e7e920b85676 363
cparata 0:e7e920b85676 364 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 365 }
cparata 0:e7e920b85676 366
cparata 0:e7e920b85676 367 /**
cparata 0:e7e920b85676 368 * @brief Read Accelerometer Sensitivity in HR Mode
cparata 0:e7e920b85676 369 * @param sensitivity the pointer where the accelerometer sensitivity is stored
cparata 0:e7e920b85676 370 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 371 */
cparata 0:e7e920b85676 372 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetSensitivity_HR_Mode( float *sensitivity )
cparata 0:e7e920b85676 373 {
cparata 0:e7e920b85676 374 LSM303AGR_ACC_FS_t fullScale;
cparata 0:e7e920b85676 375
cparata 0:e7e920b85676 376 /* Read actual full scale selection from sensor. */
cparata 0:e7e920b85676 377 if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR )
cparata 0:e7e920b85676 378 {
cparata 0:e7e920b85676 379 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 380 }
cparata 0:e7e920b85676 381
cparata 0:e7e920b85676 382 /* Store the sensitivity based on actual full scale. */
cparata 0:e7e920b85676 383 switch( fullScale )
cparata 0:e7e920b85676 384 {
cparata 0:e7e920b85676 385 case LSM303AGR_ACC_FS_2G:
cparata 0:e7e920b85676 386 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_HIGH_RESOLUTION_MODE;
cparata 0:e7e920b85676 387 break;
cparata 0:e7e920b85676 388 case LSM303AGR_ACC_FS_4G:
cparata 0:e7e920b85676 389 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_HIGH_RESOLUTION_MODE;
cparata 0:e7e920b85676 390 break;
cparata 0:e7e920b85676 391 case LSM303AGR_ACC_FS_8G:
cparata 0:e7e920b85676 392 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_HIGH_RESOLUTION_MODE;
cparata 0:e7e920b85676 393 break;
cparata 0:e7e920b85676 394 case LSM303AGR_ACC_FS_16G:
cparata 0:e7e920b85676 395 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_HIGH_RESOLUTION_MODE;
cparata 0:e7e920b85676 396 break;
cparata 0:e7e920b85676 397 default:
cparata 0:e7e920b85676 398 *sensitivity = -1.0f;
cparata 0:e7e920b85676 399 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 400 }
cparata 0:e7e920b85676 401
cparata 0:e7e920b85676 402 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 403 }
cparata 0:e7e920b85676 404
cparata 0:e7e920b85676 405 /**
cparata 0:e7e920b85676 406 * @brief Read raw data from LSM303AGR Accelerometer
cparata 0:e7e920b85676 407 * @param pData the pointer where the accelerometer raw data are stored
cparata 0:e7e920b85676 408 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 409 */
cparata 0:e7e920b85676 410 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetAxesRaw(int16_t *pData)
cparata 0:e7e920b85676 411 {
cparata 0:e7e920b85676 412 uint8_t regValue[6] = {0, 0, 0, 0, 0, 0};
cparata 0:e7e920b85676 413 u8_t shift = 0;
cparata 0:e7e920b85676 414 LSM303AGR_ACC_LPEN_t lp;
cparata 0:e7e920b85676 415 LSM303AGR_ACC_HR_t hr;
cparata 0:e7e920b85676 416
cparata 0:e7e920b85676 417 /* Determine which operational mode the acc is set */
cparata 0:e7e920b85676 418 if(!LSM303AGR_ACC_R_HiRes( (void *)this, &hr )) {
cparata 0:e7e920b85676 419 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 420 }
cparata 0:e7e920b85676 421
cparata 0:e7e920b85676 422 if(!LSM303AGR_ACC_R_LOWPWR_EN( (void *)this, &lp )) {
cparata 0:e7e920b85676 423 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 424 }
cparata 0:e7e920b85676 425
cparata 0:e7e920b85676 426 if (lp == LSM303AGR_ACC_LPEN_ENABLED && hr == LSM303AGR_ACC_HR_DISABLED) {
cparata 0:e7e920b85676 427 /* op mode is LP 8-bit */
cparata 0:e7e920b85676 428 shift = 8;
cparata 0:e7e920b85676 429 } else if (lp == LSM303AGR_ACC_LPEN_DISABLED && hr == LSM303AGR_ACC_HR_DISABLED) {
cparata 0:e7e920b85676 430 /* op mode is Normal 10-bit */
cparata 0:e7e920b85676 431 shift = 6;
cparata 0:e7e920b85676 432 } else if (lp == LSM303AGR_ACC_LPEN_DISABLED && hr == LSM303AGR_ACC_HR_ENABLED) {
cparata 0:e7e920b85676 433 /* op mode is HR 12-bit */
cparata 0:e7e920b85676 434 shift = 4;
cparata 0:e7e920b85676 435 } else {
cparata 0:e7e920b85676 436 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 437 }
cparata 0:e7e920b85676 438
cparata 0:e7e920b85676 439 /* Read output registers from LSM303AGR_ACC_GYRO_OUTX_L_XL to LSM303AGR_ACC_GYRO_OUTZ_H_XL. */
cparata 0:e7e920b85676 440 if (!LSM303AGR_ACC_Get_Raw_Acceleration( (void *)this, ( uint8_t* )regValue ))
cparata 0:e7e920b85676 441 {
cparata 0:e7e920b85676 442 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 443 }
cparata 0:e7e920b85676 444
cparata 0:e7e920b85676 445 /* Format the data. */
cparata 0:e7e920b85676 446 pData[0] = ( ( ( ( ( int16_t )regValue[1] ) << 8 ) + ( int16_t )regValue[0] ) >> shift );
cparata 0:e7e920b85676 447 pData[1] = ( ( ( ( ( int16_t )regValue[3] ) << 8 ) + ( int16_t )regValue[2] ) >> shift );
cparata 0:e7e920b85676 448 pData[2] = ( ( ( ( ( int16_t )regValue[5] ) << 8 ) + ( int16_t )regValue[4] ) >> shift );
cparata 0:e7e920b85676 449
cparata 0:e7e920b85676 450 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 451 }
cparata 0:e7e920b85676 452
cparata 0:e7e920b85676 453 /**
cparata 0:e7e920b85676 454 * @brief Read LSM303AGR Accelerometer output data rate
cparata 0:e7e920b85676 455 * @param odr the pointer to the output data rate
cparata 0:e7e920b85676 456 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 457 */
cparata 0:e7e920b85676 458 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetODR(float* odr)
cparata 0:e7e920b85676 459 {
cparata 0:e7e920b85676 460 LSM303AGR_ACC_ODR_t odr_low_level;
cparata 0:e7e920b85676 461
cparata 0:e7e920b85676 462 if ( LSM303AGR_ACC_R_ODR( (void *)this, &odr_low_level ) == MEMS_ERROR )
cparata 0:e7e920b85676 463 {
cparata 0:e7e920b85676 464 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 465 }
cparata 0:e7e920b85676 466
cparata 0:e7e920b85676 467 switch( odr_low_level )
cparata 0:e7e920b85676 468 {
cparata 0:e7e920b85676 469 case LSM303AGR_ACC_ODR_DO_PWR_DOWN:
cparata 0:e7e920b85676 470 *odr = 0.0f;
cparata 0:e7e920b85676 471 break;
cparata 0:e7e920b85676 472 case LSM303AGR_ACC_ODR_DO_1Hz:
cparata 0:e7e920b85676 473 *odr = 1.0f;
cparata 0:e7e920b85676 474 break;
cparata 0:e7e920b85676 475 case LSM303AGR_ACC_ODR_DO_10Hz:
cparata 0:e7e920b85676 476 *odr = 10.0f;
cparata 0:e7e920b85676 477 break;
cparata 0:e7e920b85676 478 case LSM303AGR_ACC_ODR_DO_25Hz:
cparata 0:e7e920b85676 479 *odr = 25.0f;
cparata 0:e7e920b85676 480 break;
cparata 0:e7e920b85676 481 case LSM303AGR_ACC_ODR_DO_50Hz:
cparata 0:e7e920b85676 482 *odr = 50.0f;
cparata 0:e7e920b85676 483 break;
cparata 0:e7e920b85676 484 case LSM303AGR_ACC_ODR_DO_100Hz:
cparata 0:e7e920b85676 485 *odr = 100.0f;
cparata 0:e7e920b85676 486 break;
cparata 0:e7e920b85676 487 case LSM303AGR_ACC_ODR_DO_200Hz:
cparata 0:e7e920b85676 488 *odr = 200.0f;
cparata 0:e7e920b85676 489 break;
cparata 0:e7e920b85676 490 case LSM303AGR_ACC_ODR_DO_400Hz:
cparata 0:e7e920b85676 491 *odr = 400.0f;
cparata 0:e7e920b85676 492 break;
cparata 0:e7e920b85676 493 default:
cparata 0:e7e920b85676 494 *odr = -1.0f;
cparata 0:e7e920b85676 495 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 496 }
cparata 0:e7e920b85676 497
cparata 0:e7e920b85676 498 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 499 }
cparata 0:e7e920b85676 500
cparata 0:e7e920b85676 501 /**
cparata 0:e7e920b85676 502 * @brief Set ODR
cparata 0:e7e920b85676 503 * @param odr the output data rate to be set
cparata 0:e7e920b85676 504 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 505 */
cparata 0:e7e920b85676 506 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::SetODR(float odr)
cparata 0:e7e920b85676 507 {
cparata 0:e7e920b85676 508 if(isEnabled == 1)
cparata 0:e7e920b85676 509 {
cparata 0:e7e920b85676 510 if(SetODR_When_Enabled(odr) == LSM303AGR_ACC_STATUS_ERROR)
cparata 0:e7e920b85676 511 {
cparata 0:e7e920b85676 512 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 513 }
cparata 0:e7e920b85676 514 }
cparata 0:e7e920b85676 515 else
cparata 0:e7e920b85676 516 {
cparata 0:e7e920b85676 517 if(SetODR_When_Disabled(odr) == LSM303AGR_ACC_STATUS_ERROR)
cparata 0:e7e920b85676 518 {
cparata 0:e7e920b85676 519 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 520 }
cparata 0:e7e920b85676 521 }
cparata 0:e7e920b85676 522
cparata 0:e7e920b85676 523 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 524 }
cparata 0:e7e920b85676 525
cparata 0:e7e920b85676 526 /**
cparata 0:e7e920b85676 527 * @brief Set ODR when enabled
cparata 0:e7e920b85676 528 * @param odr the output data rate to be set
cparata 0:e7e920b85676 529 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 530 */
cparata 0:e7e920b85676 531 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::SetODR_When_Enabled(float odr)
cparata 0:e7e920b85676 532 {
cparata 0:e7e920b85676 533 LSM303AGR_ACC_ODR_t new_odr;
cparata 0:e7e920b85676 534
cparata 0:e7e920b85676 535 new_odr = ( odr <= 1.0f ) ? LSM303AGR_ACC_ODR_DO_1Hz
cparata 0:e7e920b85676 536 : ( odr <= 10.0f ) ? LSM303AGR_ACC_ODR_DO_10Hz
cparata 0:e7e920b85676 537 : ( odr <= 25.0f ) ? LSM303AGR_ACC_ODR_DO_25Hz
cparata 0:e7e920b85676 538 : ( odr <= 50.0f ) ? LSM303AGR_ACC_ODR_DO_50Hz
cparata 0:e7e920b85676 539 : ( odr <= 100.0f ) ? LSM303AGR_ACC_ODR_DO_100Hz
cparata 0:e7e920b85676 540 : ( odr <= 200.0f ) ? LSM303AGR_ACC_ODR_DO_200Hz
cparata 0:e7e920b85676 541 : LSM303AGR_ACC_ODR_DO_400Hz;
cparata 0:e7e920b85676 542
cparata 0:e7e920b85676 543 if ( LSM303AGR_ACC_W_ODR( (void *)this, new_odr ) == MEMS_ERROR )
cparata 0:e7e920b85676 544 {
cparata 0:e7e920b85676 545 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 546 }
cparata 0:e7e920b85676 547
cparata 0:e7e920b85676 548 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 549 }
cparata 0:e7e920b85676 550
cparata 0:e7e920b85676 551 /**
cparata 0:e7e920b85676 552 * @brief Set ODR when disabled
cparata 0:e7e920b85676 553 * @param odr the output data rate to be set
cparata 0:e7e920b85676 554 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 555 */
cparata 0:e7e920b85676 556 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::SetODR_When_Disabled(float odr)
cparata 0:e7e920b85676 557 {
cparata 0:e7e920b85676 558 Last_ODR = ( odr <= 1.0f ) ? 1.0f
cparata 0:e7e920b85676 559 : ( odr <= 10.0f ) ? 10.0f
cparata 0:e7e920b85676 560 : ( odr <= 25.0f ) ? 25.0f
cparata 0:e7e920b85676 561 : ( odr <= 50.0f ) ? 50.0f
cparata 0:e7e920b85676 562 : ( odr <= 100.0f ) ? 100.0f
cparata 0:e7e920b85676 563 : ( odr <= 200.0f ) ? 200.0f
cparata 0:e7e920b85676 564 : 400.0f;
cparata 0:e7e920b85676 565
cparata 0:e7e920b85676 566 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 567 }
cparata 0:e7e920b85676 568
cparata 0:e7e920b85676 569
cparata 0:e7e920b85676 570 /**
cparata 0:e7e920b85676 571 * @brief Read LSM303AGR Accelerometer full scale
cparata 0:e7e920b85676 572 * @param fullScale the pointer to the full scale
cparata 0:e7e920b85676 573 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 574 */
cparata 0:e7e920b85676 575 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetFS(float* fullScale)
cparata 0:e7e920b85676 576 {
cparata 0:e7e920b85676 577 LSM303AGR_ACC_FS_t fs_low_level;
cparata 0:e7e920b85676 578
cparata 0:e7e920b85676 579 if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fs_low_level ) == MEMS_ERROR )
cparata 0:e7e920b85676 580 {
cparata 0:e7e920b85676 581 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 582 }
cparata 0:e7e920b85676 583
cparata 0:e7e920b85676 584 switch( fs_low_level )
cparata 0:e7e920b85676 585 {
cparata 0:e7e920b85676 586 case LSM303AGR_ACC_FS_2G:
cparata 0:e7e920b85676 587 *fullScale = 2.0f;
cparata 0:e7e920b85676 588 break;
cparata 0:e7e920b85676 589 case LSM303AGR_ACC_FS_4G:
cparata 0:e7e920b85676 590 *fullScale = 4.0f;
cparata 0:e7e920b85676 591 break;
cparata 0:e7e920b85676 592 case LSM303AGR_ACC_FS_8G:
cparata 0:e7e920b85676 593 *fullScale = 8.0f;
cparata 0:e7e920b85676 594 break;
cparata 0:e7e920b85676 595 case LSM303AGR_ACC_FS_16G:
cparata 0:e7e920b85676 596 *fullScale = 16.0f;
cparata 0:e7e920b85676 597 break;
cparata 0:e7e920b85676 598 default:
cparata 0:e7e920b85676 599 *fullScale = -1.0f;
cparata 0:e7e920b85676 600 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 601 }
cparata 0:e7e920b85676 602
cparata 0:e7e920b85676 603 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 604 }
cparata 0:e7e920b85676 605
cparata 0:e7e920b85676 606 /**
cparata 0:e7e920b85676 607 * @brief Set full scale
cparata 0:e7e920b85676 608 * @param fullScale the full scale to be set
cparata 0:e7e920b85676 609 * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 610 */
cparata 0:e7e920b85676 611 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::SetFS(float fullScale)
cparata 0:e7e920b85676 612 {
cparata 0:e7e920b85676 613 LSM303AGR_ACC_FS_t new_fs;
cparata 0:e7e920b85676 614
cparata 0:e7e920b85676 615 new_fs = ( fullScale <= 2.0f ) ? LSM303AGR_ACC_FS_2G
cparata 0:e7e920b85676 616 : ( fullScale <= 4.0f ) ? LSM303AGR_ACC_FS_4G
cparata 0:e7e920b85676 617 : ( fullScale <= 8.0f ) ? LSM303AGR_ACC_FS_8G
cparata 0:e7e920b85676 618 : LSM303AGR_ACC_FS_16G;
cparata 0:e7e920b85676 619
cparata 0:e7e920b85676 620 if ( LSM303AGR_ACC_W_FullScale( (void *)this, new_fs ) == MEMS_ERROR )
cparata 0:e7e920b85676 621 {
cparata 0:e7e920b85676 622 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 623 }
cparata 0:e7e920b85676 624
cparata 0:e7e920b85676 625 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 626 }
cparata 0:e7e920b85676 627
cparata 0:e7e920b85676 628 /**
cparata 0:e7e920b85676 629 * @brief Read accelerometer data from register
cparata 0:e7e920b85676 630 * @param reg register address
cparata 0:e7e920b85676 631 * @param data register data
cparata 0:e7e920b85676 632 * @retval LSM303AGR_ACC_STATUS_OK in case of success
cparata 0:e7e920b85676 633 * @retval LSM303AGR_ACC_STATUS_ERROR in case of failure
cparata 0:e7e920b85676 634 */
cparata 0:e7e920b85676 635 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::ReadReg( uint8_t reg, uint8_t *data )
cparata 0:e7e920b85676 636 {
cparata 0:e7e920b85676 637
cparata 0:e7e920b85676 638 if ( LSM303AGR_ACC_ReadReg( (void *)this, reg, data ) == MEMS_ERROR )
cparata 0:e7e920b85676 639 {
cparata 0:e7e920b85676 640 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 641 }
cparata 0:e7e920b85676 642
cparata 0:e7e920b85676 643 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 644 }
cparata 0:e7e920b85676 645
cparata 0:e7e920b85676 646 /**
cparata 0:e7e920b85676 647 * @brief Write accelerometer data to register
cparata 0:e7e920b85676 648 * @param reg register address
cparata 0:e7e920b85676 649 * @param data register data
cparata 0:e7e920b85676 650 * @retval LSM303AGR_ACC_STATUS_OK in case of success
cparata 0:e7e920b85676 651 * @retval LSM303AGR_ACC_STATUS_ERROR in case of failure
cparata 0:e7e920b85676 652 */
cparata 0:e7e920b85676 653 LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::WriteReg( uint8_t reg, uint8_t data )
cparata 0:e7e920b85676 654 {
cparata 0:e7e920b85676 655
cparata 0:e7e920b85676 656 if ( LSM303AGR_ACC_WriteReg( (void *)this, reg, data ) == MEMS_ERROR )
cparata 0:e7e920b85676 657 {
cparata 0:e7e920b85676 658 return LSM303AGR_ACC_STATUS_ERROR;
cparata 0:e7e920b85676 659 }
cparata 0:e7e920b85676 660
cparata 0:e7e920b85676 661 return LSM303AGR_ACC_STATUS_OK;
cparata 0:e7e920b85676 662 }
cparata 0:e7e920b85676 663
cparata 0:e7e920b85676 664 uint8_t LSM303AGR_ACC_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite )
cparata 0:e7e920b85676 665 {
cparata 0:e7e920b85676 666 return ((LSM303AGR_ACC_Sensor *)handle)->IO_Write(pBuffer, WriteAddr, nBytesToWrite);
cparata 0:e7e920b85676 667 }
cparata 0:e7e920b85676 668
cparata 0:e7e920b85676 669 uint8_t LSM303AGR_ACC_IO_Read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead )
cparata 0:e7e920b85676 670 {
cparata 0:e7e920b85676 671 return ((LSM303AGR_ACC_Sensor *)handle)->IO_Read(pBuffer, ReadAddr, nBytesToRead);
cparata 0:e7e920b85676 672 }