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