Example of pedometer for LSM6DSL in X-NUCLEO-IKS01A2

Dependencies:   X_NUCLEO_IKS01A2 mbed

Fork of Pedometer_IKS01A2 by ST Expansion SW Team

Pedometer Demo Application based on sensor expansion board X-NUCLEO-IKS01A2

Main function is to show how to count steps 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 to simulate the steps and then view the notification using an hyper terminal. When a new step is detected, the LED is switched on for a while.
- the user button can be used to reset the step counter.

Committer:
cparata
Date:
Fri Aug 19 12:29:08 2016 +0000
Revision:
2:67af0ad3ea2e
Add interfaces to all components

Who changed what in which revision?

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