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_MAG_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 magnetometer 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 "mbed.h"
cparata 0:e7e920b85676 42 #include "DevI2C.h"
cparata 0:e7e920b85676 43 #include "LSM303AGR_MAG_Sensor.h"
cparata 0:e7e920b85676 44 #include "LSM303AGR_MAG_driver.h"
cparata 0:e7e920b85676 45
cparata 0:e7e920b85676 46
cparata 0:e7e920b85676 47 /* Class Implementation ------------------------------------------------------*/
cparata 0:e7e920b85676 48
cparata 0:e7e920b85676 49 /** Constructor
cparata 0:e7e920b85676 50 * @param i2c object of an helper class which handles the I2C peripheral
cparata 0:e7e920b85676 51 * @param address the address of the component's instance
cparata 0:e7e920b85676 52 */
cparata 0:e7e920b85676 53 LSM303AGR_MAG_Sensor::LSM303AGR_MAG_Sensor(DevI2C &i2c) : dev_i2c(i2c)
cparata 0:e7e920b85676 54 {
cparata 0:e7e920b85676 55 address = LSM303AGR_MAG_I2C_ADDRESS;
cparata 0:e7e920b85676 56
cparata 0:e7e920b85676 57 /* Operating mode selection - power down */
cparata 0:e7e920b85676 58 if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR )
cparata 0:e7e920b85676 59 {
cparata 0:e7e920b85676 60 return;
cparata 0:e7e920b85676 61 }
cparata 0:e7e920b85676 62
cparata 0:e7e920b85676 63 /* Enable BDU */
cparata 0:e7e920b85676 64 if ( LSM303AGR_MAG_W_BDU( (void *)this, LSM303AGR_MAG_BDU_ENABLED ) == MEMS_ERROR )
cparata 0:e7e920b85676 65 {
cparata 0:e7e920b85676 66 return;
cparata 0:e7e920b85676 67 }
cparata 0:e7e920b85676 68
cparata 0:e7e920b85676 69 if ( SetODR( 100.0f ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:e7e920b85676 70 {
cparata 0:e7e920b85676 71 return;
cparata 0:e7e920b85676 72 }
cparata 0:e7e920b85676 73
cparata 0:e7e920b85676 74 if ( SetFS( 50.0f ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:e7e920b85676 75 {
cparata 0:e7e920b85676 76 return;
cparata 0:e7e920b85676 77 }
cparata 0:e7e920b85676 78
cparata 0:e7e920b85676 79 if ( LSM303AGR_MAG_W_ST( (void *)this, LSM303AGR_MAG_ST_DISABLED ) == MEMS_ERROR )
cparata 0:e7e920b85676 80 {
cparata 0:e7e920b85676 81 return;
cparata 0:e7e920b85676 82 }
cparata 0:e7e920b85676 83 };
cparata 0:e7e920b85676 84
cparata 0:e7e920b85676 85 /** Constructor
cparata 0:e7e920b85676 86 * @param i2c object of an helper class which handles the I2C peripheral
cparata 0:e7e920b85676 87 * @param address the address of the component's instance
cparata 0:e7e920b85676 88 */
cparata 0:e7e920b85676 89 LSM303AGR_MAG_Sensor::LSM303AGR_MAG_Sensor(DevI2C &i2c, uint8_t address) : dev_i2c(i2c), address(address)
cparata 0:e7e920b85676 90 {
cparata 0:e7e920b85676 91 /* Operating mode selection - power down */
cparata 0:e7e920b85676 92 if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR )
cparata 0:e7e920b85676 93 {
cparata 0:e7e920b85676 94 return;
cparata 0:e7e920b85676 95 }
cparata 0:e7e920b85676 96
cparata 0:e7e920b85676 97 /* Enable BDU */
cparata 0:e7e920b85676 98 if ( LSM303AGR_MAG_W_BDU( (void *)this, LSM303AGR_MAG_BDU_ENABLED ) == MEMS_ERROR )
cparata 0:e7e920b85676 99 {
cparata 0:e7e920b85676 100 return;
cparata 0:e7e920b85676 101 }
cparata 0:e7e920b85676 102
cparata 0:e7e920b85676 103 if ( SetODR( 100.0f ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:e7e920b85676 104 {
cparata 0:e7e920b85676 105 return;
cparata 0:e7e920b85676 106 }
cparata 0:e7e920b85676 107
cparata 0:e7e920b85676 108 if ( SetFS( 50.0f ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:e7e920b85676 109 {
cparata 0:e7e920b85676 110 return;
cparata 0:e7e920b85676 111 }
cparata 0:e7e920b85676 112
cparata 0:e7e920b85676 113 if ( LSM303AGR_MAG_W_ST( (void *)this, LSM303AGR_MAG_ST_DISABLED ) == MEMS_ERROR )
cparata 0:e7e920b85676 114 {
cparata 0:e7e920b85676 115 return;
cparata 0:e7e920b85676 116 }
cparata 0:e7e920b85676 117 };
cparata 0:e7e920b85676 118
cparata 0:e7e920b85676 119 /**
cparata 0:e7e920b85676 120 * @brief Enable LSM303AGR magnetometer
cparata 0:e7e920b85676 121 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 122 */
cparata 0:e7e920b85676 123 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::Enable(void)
cparata 0:e7e920b85676 124 {
cparata 0:e7e920b85676 125 /* Operating mode selection */
cparata 0:e7e920b85676 126 if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_CONTINUOS_MODE ) == MEMS_ERROR )
cparata 0:e7e920b85676 127 {
cparata 0:e7e920b85676 128 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:e7e920b85676 129 }
cparata 0:e7e920b85676 130
cparata 0:e7e920b85676 131 return LSM303AGR_MAG_STATUS_OK;
cparata 0:e7e920b85676 132 }
cparata 0:e7e920b85676 133
cparata 0:e7e920b85676 134 /**
cparata 0:e7e920b85676 135 * @brief Disable LSM303AGR magnetometer
cparata 0:e7e920b85676 136 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 137 */
cparata 0:e7e920b85676 138 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::Disable(void)
cparata 0:e7e920b85676 139 {
cparata 0:e7e920b85676 140 /* Operating mode selection - power down */
cparata 0:e7e920b85676 141 if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR )
cparata 0:e7e920b85676 142 {
cparata 0:e7e920b85676 143 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:e7e920b85676 144 }
cparata 0:e7e920b85676 145
cparata 0:e7e920b85676 146 return LSM303AGR_MAG_STATUS_OK;
cparata 0:e7e920b85676 147 }
cparata 0:e7e920b85676 148
cparata 0:e7e920b85676 149 /**
cparata 0:e7e920b85676 150 * @brief Read ID of LSM303AGR Magnetometer
cparata 0:e7e920b85676 151 * @param p_id the pointer where the ID of the device is stored
cparata 0:e7e920b85676 152 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 153 */
cparata 0:e7e920b85676 154 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::ReadID(uint8_t *p_id)
cparata 0:e7e920b85676 155 {
cparata 0:e7e920b85676 156 if(!p_id)
cparata 0:e7e920b85676 157 {
cparata 0:e7e920b85676 158 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:e7e920b85676 159 }
cparata 0:e7e920b85676 160
cparata 0:e7e920b85676 161 /* Read WHO AM I register */
cparata 0:e7e920b85676 162 if ( LSM303AGR_MAG_R_WHO_AM_I( (void *)this, p_id ) == MEMS_ERROR )
cparata 0:e7e920b85676 163 {
cparata 0:e7e920b85676 164 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:e7e920b85676 165 }
cparata 0:e7e920b85676 166
cparata 0:e7e920b85676 167 return LSM303AGR_MAG_STATUS_OK;
cparata 0:e7e920b85676 168 }
cparata 0:e7e920b85676 169
cparata 0:e7e920b85676 170 /**
cparata 0:e7e920b85676 171 * @brief Read data from LSM303AGR Magnetometer
cparata 0:e7e920b85676 172 * @param pData the pointer where the magnetometer data are stored
cparata 0:e7e920b85676 173 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 174 */
cparata 0:e7e920b85676 175 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetAxes(int32_t *pData)
cparata 0:e7e920b85676 176 {
cparata 0:e7e920b85676 177 int16_t pDataRaw[3];
cparata 0:e7e920b85676 178 float sensitivity = 0;
cparata 0:e7e920b85676 179
cparata 0:e7e920b85676 180 /* Read raw data from LSM303AGR output register. */
cparata 0:e7e920b85676 181 if ( GetAxesRaw( pDataRaw ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:e7e920b85676 182 {
cparata 0:e7e920b85676 183 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:e7e920b85676 184 }
cparata 0:e7e920b85676 185
cparata 0:e7e920b85676 186 /* Get LSM303AGR actual sensitivity. */
cparata 0:e7e920b85676 187 if ( GetSensitivity( &sensitivity ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:e7e920b85676 188 {
cparata 0:e7e920b85676 189 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:e7e920b85676 190 }
cparata 0:e7e920b85676 191
cparata 0:e7e920b85676 192 /* Calculate the data. */
cparata 0:e7e920b85676 193 pData[0] = ( int32_t )( pDataRaw[0] * sensitivity );
cparata 0:e7e920b85676 194 pData[1] = ( int32_t )( pDataRaw[1] * sensitivity );
cparata 0:e7e920b85676 195 pData[2] = ( int32_t )( pDataRaw[2] * sensitivity );
cparata 0:e7e920b85676 196
cparata 0:e7e920b85676 197 return LSM303AGR_MAG_STATUS_OK;
cparata 0:e7e920b85676 198 }
cparata 0:e7e920b85676 199
cparata 0:e7e920b85676 200 /**
cparata 0:e7e920b85676 201 * @brief Read Magnetometer Sensitivity
cparata 0:e7e920b85676 202 * @param pfData the pointer where the magnetometer sensitivity is stored
cparata 0:e7e920b85676 203 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 204 */
cparata 0:e7e920b85676 205 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetSensitivity(float *pfData)
cparata 0:e7e920b85676 206 {
cparata 0:e7e920b85676 207 *pfData = 1.5f;
cparata 0:e7e920b85676 208
cparata 0:e7e920b85676 209 return LSM303AGR_MAG_STATUS_OK;
cparata 0:e7e920b85676 210 }
cparata 0:e7e920b85676 211
cparata 0:e7e920b85676 212 /**
cparata 0:e7e920b85676 213 * @brief Read raw data from LSM303AGR Magnetometer
cparata 0:e7e920b85676 214 * @param pData the pointer where the magnetomer raw data are stored
cparata 0:e7e920b85676 215 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 216 */
cparata 0:e7e920b85676 217 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetAxesRaw(int16_t *pData)
cparata 0:e7e920b85676 218 {
cparata 0:e7e920b85676 219 uint8_t regValue[6] = {0, 0, 0, 0, 0, 0};
cparata 0:e7e920b85676 220 int16_t *regValueInt16;
cparata 0:e7e920b85676 221
cparata 0:e7e920b85676 222 /* Read output registers from LSM303AGR_MAG_OUTX_L to LSM303AGR_MAG_OUTZ_H. */
cparata 0:e7e920b85676 223 if ( LSM303AGR_MAG_Get_Raw_Magnetic( (void *)this, regValue ) == MEMS_ERROR )
cparata 0:e7e920b85676 224 {
cparata 0:e7e920b85676 225 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:e7e920b85676 226 }
cparata 0:e7e920b85676 227
cparata 0:e7e920b85676 228 regValueInt16 = (int16_t *)regValue;
cparata 0:e7e920b85676 229
cparata 0:e7e920b85676 230 /* Format the data. */
cparata 0:e7e920b85676 231 pData[0] = regValueInt16[0];
cparata 0:e7e920b85676 232 pData[1] = regValueInt16[1];
cparata 0:e7e920b85676 233 pData[2] = regValueInt16[2];
cparata 0:e7e920b85676 234
cparata 0:e7e920b85676 235 return LSM303AGR_MAG_STATUS_OK;
cparata 0:e7e920b85676 236 }
cparata 0:e7e920b85676 237
cparata 0:e7e920b85676 238 /**
cparata 0:e7e920b85676 239 * @brief Read LSM303AGR Magnetometer output data rate
cparata 0:e7e920b85676 240 * @param odr the pointer to the output data rate
cparata 0:e7e920b85676 241 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 242 */
cparata 0:e7e920b85676 243 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetODR(float* odr)
cparata 0:e7e920b85676 244 {
cparata 0:e7e920b85676 245 LSM303AGR_MAG_ODR_t odr_low_level;
cparata 0:e7e920b85676 246
cparata 0:e7e920b85676 247 if ( LSM303AGR_MAG_R_ODR( (void *)this, &odr_low_level ) == MEMS_ERROR )
cparata 0:e7e920b85676 248 {
cparata 0:e7e920b85676 249 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:e7e920b85676 250 }
cparata 0:e7e920b85676 251
cparata 0:e7e920b85676 252 switch( odr_low_level )
cparata 0:e7e920b85676 253 {
cparata 0:e7e920b85676 254 case LSM303AGR_MAG_ODR_10Hz:
cparata 0:e7e920b85676 255 *odr = 10.000f;
cparata 0:e7e920b85676 256 break;
cparata 0:e7e920b85676 257 case LSM303AGR_MAG_ODR_20Hz:
cparata 0:e7e920b85676 258 *odr = 20.000f;
cparata 0:e7e920b85676 259 break;
cparata 0:e7e920b85676 260 case LSM303AGR_MAG_ODR_50Hz:
cparata 0:e7e920b85676 261 *odr = 50.000f;
cparata 0:e7e920b85676 262 break;
cparata 0:e7e920b85676 263 case LSM303AGR_MAG_ODR_100Hz:
cparata 0:e7e920b85676 264 *odr = 100.000f;
cparata 0:e7e920b85676 265 break;
cparata 0:e7e920b85676 266 default:
cparata 0:e7e920b85676 267 *odr = -1.000f;
cparata 0:e7e920b85676 268 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:e7e920b85676 269 }
cparata 0:e7e920b85676 270 return LSM303AGR_MAG_STATUS_OK;
cparata 0:e7e920b85676 271 }
cparata 0:e7e920b85676 272
cparata 0:e7e920b85676 273 /**
cparata 0:e7e920b85676 274 * @brief Set ODR
cparata 0:e7e920b85676 275 * @param odr the output data rate to be set
cparata 0:e7e920b85676 276 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 277 */
cparata 0:e7e920b85676 278 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::SetODR(float odr)
cparata 0:e7e920b85676 279 {
cparata 0:e7e920b85676 280 LSM303AGR_MAG_ODR_t new_odr;
cparata 0:e7e920b85676 281
cparata 0:e7e920b85676 282 new_odr = ( odr <= 10.000f ) ? LSM303AGR_MAG_ODR_10Hz
cparata 0:e7e920b85676 283 : ( odr <= 20.000f ) ? LSM303AGR_MAG_ODR_20Hz
cparata 0:e7e920b85676 284 : ( odr <= 50.000f ) ? LSM303AGR_MAG_ODR_50Hz
cparata 0:e7e920b85676 285 : LSM303AGR_MAG_ODR_100Hz;
cparata 0:e7e920b85676 286
cparata 0:e7e920b85676 287 if ( LSM303AGR_MAG_W_ODR( (void *)this, new_odr ) == MEMS_ERROR )
cparata 0:e7e920b85676 288 {
cparata 0:e7e920b85676 289 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:e7e920b85676 290 }
cparata 0:e7e920b85676 291
cparata 0:e7e920b85676 292 return LSM303AGR_MAG_STATUS_OK;
cparata 0:e7e920b85676 293 }
cparata 0:e7e920b85676 294
cparata 0:e7e920b85676 295
cparata 0:e7e920b85676 296 /**
cparata 0:e7e920b85676 297 * @brief Read LSM303AGR Magnetometer full scale
cparata 0:e7e920b85676 298 * @param fullScale the pointer to the output data rate
cparata 0:e7e920b85676 299 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 300 */
cparata 0:e7e920b85676 301 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetFS(float* fullScale)
cparata 0:e7e920b85676 302 {
cparata 0:e7e920b85676 303 *fullScale = 50.0f;
cparata 0:e7e920b85676 304
cparata 0:e7e920b85676 305 return LSM303AGR_MAG_STATUS_OK;
cparata 0:e7e920b85676 306 }
cparata 0:e7e920b85676 307
cparata 0:e7e920b85676 308 /**
cparata 0:e7e920b85676 309 * @brief Set full scale
cparata 0:e7e920b85676 310 * @param fullScale the full scale to be set
cparata 0:e7e920b85676 311 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:e7e920b85676 312 */
cparata 0:e7e920b85676 313 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::SetFS(float fullScale)
cparata 0:e7e920b85676 314 {
cparata 0:e7e920b85676 315 return LSM303AGR_MAG_STATUS_OK;
cparata 0:e7e920b85676 316 }
cparata 0:e7e920b85676 317
cparata 0:e7e920b85676 318
cparata 0:e7e920b85676 319 /**
cparata 0:e7e920b85676 320 * @brief Read magnetometer data from register
cparata 0:e7e920b85676 321 * @param reg register address
cparata 0:e7e920b85676 322 * @param data register data
cparata 0:e7e920b85676 323 * @retval LSM303AGR_MAG_STATUS_OK in case of success
cparata 0:e7e920b85676 324 * @retval LSM303AGR_MAG_STATUS_ERROR in case of failure
cparata 0:e7e920b85676 325 */
cparata 0:e7e920b85676 326 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::ReadReg( uint8_t reg, uint8_t *data )
cparata 0:e7e920b85676 327 {
cparata 0:e7e920b85676 328 if ( LSM303AGR_MAG_ReadReg( (void *)this, reg, data ) == MEMS_ERROR )
cparata 0:e7e920b85676 329 {
cparata 0:e7e920b85676 330 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:e7e920b85676 331 }
cparata 0:e7e920b85676 332
cparata 0:e7e920b85676 333 return LSM303AGR_MAG_STATUS_OK;
cparata 0:e7e920b85676 334 }
cparata 0:e7e920b85676 335
cparata 0:e7e920b85676 336
cparata 0:e7e920b85676 337 /**
cparata 0:e7e920b85676 338 * @brief Write magnetometer data to register
cparata 0:e7e920b85676 339 * @param reg register address
cparata 0:e7e920b85676 340 * @param data register data
cparata 0:e7e920b85676 341 * @retval LSM303AGR_MAG_STATUS_OK in case of success
cparata 0:e7e920b85676 342 * @retval LSM303AGR_MAG_STATUS_ERROR in case of failure
cparata 0:e7e920b85676 343 */
cparata 0:e7e920b85676 344 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::WriteReg( uint8_t reg, uint8_t data )
cparata 0:e7e920b85676 345 {
cparata 0:e7e920b85676 346 if ( LSM303AGR_MAG_WriteReg( (void *)this, reg, data ) == MEMS_ERROR )
cparata 0:e7e920b85676 347 {
cparata 0:e7e920b85676 348 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:e7e920b85676 349 }
cparata 0:e7e920b85676 350
cparata 0:e7e920b85676 351 return LSM303AGR_MAG_STATUS_OK;
cparata 0:e7e920b85676 352 }
cparata 0:e7e920b85676 353
cparata 0:e7e920b85676 354 uint8_t LSM303AGR_MAG_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite )
cparata 0:e7e920b85676 355 {
cparata 0:e7e920b85676 356 return ((LSM303AGR_MAG_Sensor *)handle)->IO_Write(pBuffer, WriteAddr, nBytesToWrite);
cparata 0:e7e920b85676 357 }
cparata 0:e7e920b85676 358
cparata 0:e7e920b85676 359 uint8_t LSM303AGR_MAG_IO_Read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead )
cparata 0:e7e920b85676 360 {
cparata 0:e7e920b85676 361 return ((LSM303AGR_MAG_Sensor *)handle)->IO_Read(pBuffer, ReadAddr, nBytesToRead);
cparata 0:e7e920b85676 362 }