Example of hello world for X-NUCLEO-IKS01A2

Dependencies:   X_NUCLEO_IKS01A2 mbed

Fork of HelloWorld_IKS01A2 by ST Expansion SW Team

Hello World Demo Application based on sensor expansion board X-NUCLEO-IKS01A2

Main function is to show how to get humidity, temperature, pressure, accelerometer, magnetomer and gyroscope data using the sensor expansion board and send them using UART to a connected PC or Desktop and display it on terminal applications like TeraTerm.

Committer:
cparata
Date:
Fri Aug 12 13:40:12 2016 +0000
Revision:
0:69566eea0fba
Child:
2:f23b144da50a
First release of Hello World for IKS01A2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cparata 0:69566eea0fba 1 /**
cparata 0:69566eea0fba 2 ******************************************************************************
cparata 0:69566eea0fba 3 * @file LSM303AGR_MAG_Sensor.cpp
cparata 0:69566eea0fba 4 * @author AST
cparata 0:69566eea0fba 5 * @version V1.0.0
cparata 0:69566eea0fba 6 * @date 5 August 2016
cparata 0:69566eea0fba 7 * @brief Implementation an LSM303AGR magnetometer sensor.
cparata 0:69566eea0fba 8 ******************************************************************************
cparata 0:69566eea0fba 9 * @attention
cparata 0:69566eea0fba 10 *
cparata 0:69566eea0fba 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
cparata 0:69566eea0fba 12 *
cparata 0:69566eea0fba 13 * Redistribution and use in source and binary forms, with or without modification,
cparata 0:69566eea0fba 14 * are permitted provided that the following conditions are met:
cparata 0:69566eea0fba 15 * 1. Redistributions of source code must retain the above copyright notice,
cparata 0:69566eea0fba 16 * this list of conditions and the following disclaimer.
cparata 0:69566eea0fba 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
cparata 0:69566eea0fba 18 * this list of conditions and the following disclaimer in the documentation
cparata 0:69566eea0fba 19 * and/or other materials provided with the distribution.
cparata 0:69566eea0fba 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
cparata 0:69566eea0fba 21 * may be used to endorse or promote products derived from this software
cparata 0:69566eea0fba 22 * without specific prior written permission.
cparata 0:69566eea0fba 23 *
cparata 0:69566eea0fba 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cparata 0:69566eea0fba 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cparata 0:69566eea0fba 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
cparata 0:69566eea0fba 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
cparata 0:69566eea0fba 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
cparata 0:69566eea0fba 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
cparata 0:69566eea0fba 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
cparata 0:69566eea0fba 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
cparata 0:69566eea0fba 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
cparata 0:69566eea0fba 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cparata 0:69566eea0fba 34 *
cparata 0:69566eea0fba 35 ******************************************************************************
cparata 0:69566eea0fba 36 */
cparata 0:69566eea0fba 37
cparata 0:69566eea0fba 38
cparata 0:69566eea0fba 39 /* Includes ------------------------------------------------------------------*/
cparata 0:69566eea0fba 40
cparata 0:69566eea0fba 41 #include "mbed.h"
cparata 0:69566eea0fba 42 #include "DevI2C.h"
cparata 0:69566eea0fba 43 #include "LSM303AGR_MAG_Sensor.h"
cparata 0:69566eea0fba 44 #include "LSM303AGR_MAG_driver.h"
cparata 0:69566eea0fba 45
cparata 0:69566eea0fba 46
cparata 0:69566eea0fba 47 /* Class Implementation ------------------------------------------------------*/
cparata 0:69566eea0fba 48
cparata 0:69566eea0fba 49 /** Constructor
cparata 0:69566eea0fba 50 * @param i2c object of an helper class which handles the I2C peripheral
cparata 0:69566eea0fba 51 * @param address the address of the component's instance
cparata 0:69566eea0fba 52 */
cparata 0:69566eea0fba 53 LSM303AGR_MAG_Sensor::LSM303AGR_MAG_Sensor(DevI2C &i2c) : dev_i2c(i2c)
cparata 0:69566eea0fba 54 {
cparata 0:69566eea0fba 55 address = LSM303AGR_MAG_I2C_ADDRESS;
cparata 0:69566eea0fba 56
cparata 0:69566eea0fba 57 /* Operating mode selection - power down */
cparata 0:69566eea0fba 58 if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR )
cparata 0:69566eea0fba 59 {
cparata 0:69566eea0fba 60 return;
cparata 0:69566eea0fba 61 }
cparata 0:69566eea0fba 62
cparata 0:69566eea0fba 63 /* Enable BDU */
cparata 0:69566eea0fba 64 if ( LSM303AGR_MAG_W_BDU( (void *)this, LSM303AGR_MAG_BDU_ENABLED ) == MEMS_ERROR )
cparata 0:69566eea0fba 65 {
cparata 0:69566eea0fba 66 return;
cparata 0:69566eea0fba 67 }
cparata 0:69566eea0fba 68
cparata 0:69566eea0fba 69 if ( SetODR( 100.0f ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:69566eea0fba 70 {
cparata 0:69566eea0fba 71 return;
cparata 0:69566eea0fba 72 }
cparata 0:69566eea0fba 73
cparata 0:69566eea0fba 74 if ( SetFS( 50.0f ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:69566eea0fba 75 {
cparata 0:69566eea0fba 76 return;
cparata 0:69566eea0fba 77 }
cparata 0:69566eea0fba 78
cparata 0:69566eea0fba 79 if ( LSM303AGR_MAG_W_ST( (void *)this, LSM303AGR_MAG_ST_DISABLED ) == MEMS_ERROR )
cparata 0:69566eea0fba 80 {
cparata 0:69566eea0fba 81 return;
cparata 0:69566eea0fba 82 }
cparata 0:69566eea0fba 83 };
cparata 0:69566eea0fba 84
cparata 0:69566eea0fba 85 /** Constructor
cparata 0:69566eea0fba 86 * @param i2c object of an helper class which handles the I2C peripheral
cparata 0:69566eea0fba 87 * @param address the address of the component's instance
cparata 0:69566eea0fba 88 */
cparata 0:69566eea0fba 89 LSM303AGR_MAG_Sensor::LSM303AGR_MAG_Sensor(DevI2C &i2c, uint8_t address) : dev_i2c(i2c), address(address)
cparata 0:69566eea0fba 90 {
cparata 0:69566eea0fba 91 /* Operating mode selection - power down */
cparata 0:69566eea0fba 92 if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR )
cparata 0:69566eea0fba 93 {
cparata 0:69566eea0fba 94 return;
cparata 0:69566eea0fba 95 }
cparata 0:69566eea0fba 96
cparata 0:69566eea0fba 97 /* Enable BDU */
cparata 0:69566eea0fba 98 if ( LSM303AGR_MAG_W_BDU( (void *)this, LSM303AGR_MAG_BDU_ENABLED ) == MEMS_ERROR )
cparata 0:69566eea0fba 99 {
cparata 0:69566eea0fba 100 return;
cparata 0:69566eea0fba 101 }
cparata 0:69566eea0fba 102
cparata 0:69566eea0fba 103 if ( SetODR( 100.0f ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:69566eea0fba 104 {
cparata 0:69566eea0fba 105 return;
cparata 0:69566eea0fba 106 }
cparata 0:69566eea0fba 107
cparata 0:69566eea0fba 108 if ( SetFS( 50.0f ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:69566eea0fba 109 {
cparata 0:69566eea0fba 110 return;
cparata 0:69566eea0fba 111 }
cparata 0:69566eea0fba 112
cparata 0:69566eea0fba 113 if ( LSM303AGR_MAG_W_ST( (void *)this, LSM303AGR_MAG_ST_DISABLED ) == MEMS_ERROR )
cparata 0:69566eea0fba 114 {
cparata 0:69566eea0fba 115 return;
cparata 0:69566eea0fba 116 }
cparata 0:69566eea0fba 117 };
cparata 0:69566eea0fba 118
cparata 0:69566eea0fba 119 /**
cparata 0:69566eea0fba 120 * @brief Enable LSM303AGR magnetometer
cparata 0:69566eea0fba 121 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:69566eea0fba 122 */
cparata 0:69566eea0fba 123 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::Enable(void)
cparata 0:69566eea0fba 124 {
cparata 0:69566eea0fba 125 /* Operating mode selection */
cparata 0:69566eea0fba 126 if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_CONTINUOS_MODE ) == MEMS_ERROR )
cparata 0:69566eea0fba 127 {
cparata 0:69566eea0fba 128 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:69566eea0fba 129 }
cparata 0:69566eea0fba 130
cparata 0:69566eea0fba 131 return LSM303AGR_MAG_STATUS_OK;
cparata 0:69566eea0fba 132 }
cparata 0:69566eea0fba 133
cparata 0:69566eea0fba 134 /**
cparata 0:69566eea0fba 135 * @brief Disable LSM303AGR magnetometer
cparata 0:69566eea0fba 136 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:69566eea0fba 137 */
cparata 0:69566eea0fba 138 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::Disable(void)
cparata 0:69566eea0fba 139 {
cparata 0:69566eea0fba 140 /* Operating mode selection - power down */
cparata 0:69566eea0fba 141 if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR )
cparata 0:69566eea0fba 142 {
cparata 0:69566eea0fba 143 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:69566eea0fba 144 }
cparata 0:69566eea0fba 145
cparata 0:69566eea0fba 146 return LSM303AGR_MAG_STATUS_OK;
cparata 0:69566eea0fba 147 }
cparata 0:69566eea0fba 148
cparata 0:69566eea0fba 149 /**
cparata 0:69566eea0fba 150 * @brief Read ID of LSM303AGR Magnetometer
cparata 0:69566eea0fba 151 * @param p_id the pointer where the ID of the device is stored
cparata 0:69566eea0fba 152 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:69566eea0fba 153 */
cparata 0:69566eea0fba 154 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::ReadID(uint8_t *p_id)
cparata 0:69566eea0fba 155 {
cparata 0:69566eea0fba 156 if(!p_id)
cparata 0:69566eea0fba 157 {
cparata 0:69566eea0fba 158 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:69566eea0fba 159 }
cparata 0:69566eea0fba 160
cparata 0:69566eea0fba 161 /* Read WHO AM I register */
cparata 0:69566eea0fba 162 if ( LSM303AGR_MAG_R_WHO_AM_I( (void *)this, p_id ) == MEMS_ERROR )
cparata 0:69566eea0fba 163 {
cparata 0:69566eea0fba 164 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:69566eea0fba 165 }
cparata 0:69566eea0fba 166
cparata 0:69566eea0fba 167 return LSM303AGR_MAG_STATUS_OK;
cparata 0:69566eea0fba 168 }
cparata 0:69566eea0fba 169
cparata 0:69566eea0fba 170 /**
cparata 0:69566eea0fba 171 * @brief Read data from LSM303AGR Magnetometer
cparata 0:69566eea0fba 172 * @param pData the pointer where the magnetometer data are stored
cparata 0:69566eea0fba 173 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:69566eea0fba 174 */
cparata 0:69566eea0fba 175 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetAxes(int32_t *pData)
cparata 0:69566eea0fba 176 {
cparata 0:69566eea0fba 177 int16_t pDataRaw[3];
cparata 0:69566eea0fba 178 float sensitivity = 0;
cparata 0:69566eea0fba 179
cparata 0:69566eea0fba 180 /* Read raw data from LSM303AGR output register. */
cparata 0:69566eea0fba 181 if ( GetAxesRaw( pDataRaw ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:69566eea0fba 182 {
cparata 0:69566eea0fba 183 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:69566eea0fba 184 }
cparata 0:69566eea0fba 185
cparata 0:69566eea0fba 186 /* Get LSM303AGR actual sensitivity. */
cparata 0:69566eea0fba 187 if ( GetSensitivity( &sensitivity ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:69566eea0fba 188 {
cparata 0:69566eea0fba 189 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:69566eea0fba 190 }
cparata 0:69566eea0fba 191
cparata 0:69566eea0fba 192 /* Calculate the data. */
cparata 0:69566eea0fba 193 pData[0] = ( int32_t )( pDataRaw[0] * sensitivity );
cparata 0:69566eea0fba 194 pData[1] = ( int32_t )( pDataRaw[1] * sensitivity );
cparata 0:69566eea0fba 195 pData[2] = ( int32_t )( pDataRaw[2] * sensitivity );
cparata 0:69566eea0fba 196
cparata 0:69566eea0fba 197 return LSM303AGR_MAG_STATUS_OK;
cparata 0:69566eea0fba 198 }
cparata 0:69566eea0fba 199
cparata 0:69566eea0fba 200 /**
cparata 0:69566eea0fba 201 * @brief Read Magnetometer Sensitivity
cparata 0:69566eea0fba 202 * @param pfData the pointer where the magnetometer sensitivity is stored
cparata 0:69566eea0fba 203 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:69566eea0fba 204 */
cparata 0:69566eea0fba 205 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetSensitivity(float *pfData)
cparata 0:69566eea0fba 206 {
cparata 0:69566eea0fba 207 *pfData = 1.5f;
cparata 0:69566eea0fba 208
cparata 0:69566eea0fba 209 return LSM303AGR_MAG_STATUS_OK;
cparata 0:69566eea0fba 210 }
cparata 0:69566eea0fba 211
cparata 0:69566eea0fba 212 /**
cparata 0:69566eea0fba 213 * @brief Read raw data from LSM303AGR Magnetometer
cparata 0:69566eea0fba 214 * @param pData the pointer where the magnetomer raw data are stored
cparata 0:69566eea0fba 215 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:69566eea0fba 216 */
cparata 0:69566eea0fba 217 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetAxesRaw(int16_t *pData)
cparata 0:69566eea0fba 218 {
cparata 0:69566eea0fba 219 uint8_t regValue[6] = {0, 0, 0, 0, 0, 0};
cparata 0:69566eea0fba 220 int16_t *regValueInt16;
cparata 0:69566eea0fba 221
cparata 0:69566eea0fba 222 /* Read output registers from LSM303AGR_MAG_OUTX_L to LSM303AGR_MAG_OUTZ_H. */
cparata 0:69566eea0fba 223 if ( LSM303AGR_MAG_Get_Raw_Magnetic( (void *)this, regValue ) == MEMS_ERROR )
cparata 0:69566eea0fba 224 {
cparata 0:69566eea0fba 225 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:69566eea0fba 226 }
cparata 0:69566eea0fba 227
cparata 0:69566eea0fba 228 regValueInt16 = (int16_t *)regValue;
cparata 0:69566eea0fba 229
cparata 0:69566eea0fba 230 /* Format the data. */
cparata 0:69566eea0fba 231 pData[0] = regValueInt16[0];
cparata 0:69566eea0fba 232 pData[1] = regValueInt16[1];
cparata 0:69566eea0fba 233 pData[2] = regValueInt16[2];
cparata 0:69566eea0fba 234
cparata 0:69566eea0fba 235 return LSM303AGR_MAG_STATUS_OK;
cparata 0:69566eea0fba 236 }
cparata 0:69566eea0fba 237
cparata 0:69566eea0fba 238 /**
cparata 0:69566eea0fba 239 * @brief Read LSM303AGR Magnetometer output data rate
cparata 0:69566eea0fba 240 * @param odr the pointer to the output data rate
cparata 0:69566eea0fba 241 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:69566eea0fba 242 */
cparata 0:69566eea0fba 243 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetODR(float* odr)
cparata 0:69566eea0fba 244 {
cparata 0:69566eea0fba 245 LSM303AGR_MAG_ODR_t odr_low_level;
cparata 0:69566eea0fba 246
cparata 0:69566eea0fba 247 if ( LSM303AGR_MAG_R_ODR( (void *)this, &odr_low_level ) == MEMS_ERROR )
cparata 0:69566eea0fba 248 {
cparata 0:69566eea0fba 249 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:69566eea0fba 250 }
cparata 0:69566eea0fba 251
cparata 0:69566eea0fba 252 switch( odr_low_level )
cparata 0:69566eea0fba 253 {
cparata 0:69566eea0fba 254 case LSM303AGR_MAG_ODR_10Hz:
cparata 0:69566eea0fba 255 *odr = 10.000f;
cparata 0:69566eea0fba 256 break;
cparata 0:69566eea0fba 257 case LSM303AGR_MAG_ODR_20Hz:
cparata 0:69566eea0fba 258 *odr = 20.000f;
cparata 0:69566eea0fba 259 break;
cparata 0:69566eea0fba 260 case LSM303AGR_MAG_ODR_50Hz:
cparata 0:69566eea0fba 261 *odr = 50.000f;
cparata 0:69566eea0fba 262 break;
cparata 0:69566eea0fba 263 case LSM303AGR_MAG_ODR_100Hz:
cparata 0:69566eea0fba 264 *odr = 100.000f;
cparata 0:69566eea0fba 265 break;
cparata 0:69566eea0fba 266 default:
cparata 0:69566eea0fba 267 *odr = -1.000f;
cparata 0:69566eea0fba 268 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:69566eea0fba 269 }
cparata 0:69566eea0fba 270 return LSM303AGR_MAG_STATUS_OK;
cparata 0:69566eea0fba 271 }
cparata 0:69566eea0fba 272
cparata 0:69566eea0fba 273 /**
cparata 0:69566eea0fba 274 * @brief Set ODR
cparata 0:69566eea0fba 275 * @param odr the output data rate to be set
cparata 0:69566eea0fba 276 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:69566eea0fba 277 */
cparata 0:69566eea0fba 278 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::SetODR(float odr)
cparata 0:69566eea0fba 279 {
cparata 0:69566eea0fba 280 LSM303AGR_MAG_ODR_t new_odr;
cparata 0:69566eea0fba 281
cparata 0:69566eea0fba 282 new_odr = ( odr <= 10.000f ) ? LSM303AGR_MAG_ODR_10Hz
cparata 0:69566eea0fba 283 : ( odr <= 20.000f ) ? LSM303AGR_MAG_ODR_20Hz
cparata 0:69566eea0fba 284 : ( odr <= 50.000f ) ? LSM303AGR_MAG_ODR_50Hz
cparata 0:69566eea0fba 285 : LSM303AGR_MAG_ODR_100Hz;
cparata 0:69566eea0fba 286
cparata 0:69566eea0fba 287 if ( LSM303AGR_MAG_W_ODR( (void *)this, new_odr ) == MEMS_ERROR )
cparata 0:69566eea0fba 288 {
cparata 0:69566eea0fba 289 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:69566eea0fba 290 }
cparata 0:69566eea0fba 291
cparata 0:69566eea0fba 292 return LSM303AGR_MAG_STATUS_OK;
cparata 0:69566eea0fba 293 }
cparata 0:69566eea0fba 294
cparata 0:69566eea0fba 295
cparata 0:69566eea0fba 296 /**
cparata 0:69566eea0fba 297 * @brief Read LSM303AGR Magnetometer full scale
cparata 0:69566eea0fba 298 * @param fullScale the pointer to the output data rate
cparata 0:69566eea0fba 299 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:69566eea0fba 300 */
cparata 0:69566eea0fba 301 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetFS(float* fullScale)
cparata 0:69566eea0fba 302 {
cparata 0:69566eea0fba 303 *fullScale = 50.0f;
cparata 0:69566eea0fba 304
cparata 0:69566eea0fba 305 return LSM303AGR_MAG_STATUS_OK;
cparata 0:69566eea0fba 306 }
cparata 0:69566eea0fba 307
cparata 0:69566eea0fba 308 /**
cparata 0:69566eea0fba 309 * @brief Set full scale
cparata 0:69566eea0fba 310 * @param fullScale the full scale to be set
cparata 0:69566eea0fba 311 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:69566eea0fba 312 */
cparata 0:69566eea0fba 313 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::SetFS(float fullScale)
cparata 0:69566eea0fba 314 {
cparata 0:69566eea0fba 315 return LSM303AGR_MAG_STATUS_OK;
cparata 0:69566eea0fba 316 }
cparata 0:69566eea0fba 317
cparata 0:69566eea0fba 318
cparata 0:69566eea0fba 319 /**
cparata 0:69566eea0fba 320 * @brief Read magnetometer data from register
cparata 0:69566eea0fba 321 * @param reg register address
cparata 0:69566eea0fba 322 * @param data register data
cparata 0:69566eea0fba 323 * @retval LSM303AGR_MAG_STATUS_OK in case of success
cparata 0:69566eea0fba 324 * @retval LSM303AGR_MAG_STATUS_ERROR in case of failure
cparata 0:69566eea0fba 325 */
cparata 0:69566eea0fba 326 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::ReadReg( uint8_t reg, uint8_t *data )
cparata 0:69566eea0fba 327 {
cparata 0:69566eea0fba 328 if ( LSM303AGR_MAG_ReadReg( (void *)this, reg, data ) == MEMS_ERROR )
cparata 0:69566eea0fba 329 {
cparata 0:69566eea0fba 330 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:69566eea0fba 331 }
cparata 0:69566eea0fba 332
cparata 0:69566eea0fba 333 return LSM303AGR_MAG_STATUS_OK;
cparata 0:69566eea0fba 334 }
cparata 0:69566eea0fba 335
cparata 0:69566eea0fba 336
cparata 0:69566eea0fba 337 /**
cparata 0:69566eea0fba 338 * @brief Write magnetometer data to register
cparata 0:69566eea0fba 339 * @param reg register address
cparata 0:69566eea0fba 340 * @param data register data
cparata 0:69566eea0fba 341 * @retval LSM303AGR_MAG_STATUS_OK in case of success
cparata 0:69566eea0fba 342 * @retval LSM303AGR_MAG_STATUS_ERROR in case of failure
cparata 0:69566eea0fba 343 */
cparata 0:69566eea0fba 344 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::WriteReg( uint8_t reg, uint8_t data )
cparata 0:69566eea0fba 345 {
cparata 0:69566eea0fba 346 if ( LSM303AGR_MAG_WriteReg( (void *)this, reg, data ) == MEMS_ERROR )
cparata 0:69566eea0fba 347 {
cparata 0:69566eea0fba 348 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:69566eea0fba 349 }
cparata 0:69566eea0fba 350
cparata 0:69566eea0fba 351 return LSM303AGR_MAG_STATUS_OK;
cparata 0:69566eea0fba 352 }
cparata 0:69566eea0fba 353
cparata 0:69566eea0fba 354 uint8_t LSM303AGR_MAG_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite )
cparata 0:69566eea0fba 355 {
cparata 0:69566eea0fba 356 return ((LSM303AGR_MAG_Sensor *)handle)->IO_Write(pBuffer, WriteAddr, nBytesToWrite);
cparata 0:69566eea0fba 357 }
cparata 0:69566eea0fba 358
cparata 0:69566eea0fba 359 uint8_t LSM303AGR_MAG_IO_Read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead )
cparata 0:69566eea0fba 360 {
cparata 0:69566eea0fba 361 return ((LSM303AGR_MAG_Sensor *)handle)->IO_Read(pBuffer, ReadAddr, nBytesToRead);
cparata 0:69566eea0fba 362 }