Beta
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_IKS01A2 by
LSM303AGRAccSensor.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file LSM303AGRAccSensor.cpp 00004 * @author CLab 00005 * @version V1.0.0 00006 * @date 5 August 2016 00007 * @brief Implementation an LSM303AGR accelerometer sensor. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 00039 /* Includes ------------------------------------------------------------------*/ 00040 00041 #include "DevI2C.h" 00042 #include "LSM303AGRAccSensor.h" 00043 #include "LSM303AGR_acc_driver.h" 00044 00045 00046 /* Class Implementation ------------------------------------------------------*/ 00047 00048 /** Constructor 00049 * @param i2c object of an helper class which handles the I2C peripheral 00050 * @param address the address of the component's instance 00051 */ 00052 LSM303AGRAccSensor::LSM303AGRAccSensor(DevI2C &i2c) : _dev_i2c(i2c) 00053 { 00054 _address = LSM303AGR_ACC_I2C_ADDRESS; 00055 }; 00056 00057 /** Constructor 00058 * @param i2c object of an helper class which handles the I2C peripheral 00059 * @param address the address of the component's instance 00060 */ 00061 LSM303AGRAccSensor::LSM303AGRAccSensor(DevI2C &i2c, uint8_t address) : _dev_i2c(i2c), _address(address) 00062 { 00063 00064 }; 00065 00066 /** 00067 * @brief Initializing the component. 00068 * @param[in] init pointer to device specific initalization structure. 00069 * @retval "0" in case of success, an error code otherwise. 00070 */ 00071 int LSM303AGRAccSensor::init(void *init) 00072 { 00073 /* Enable BDU */ 00074 if ( LSM303AGR_ACC_W_BlockDataUpdate( (void *)this, LSM303AGR_ACC_BDU_ENABLED ) == MEMS_ERROR ) 00075 { 00076 return 1; 00077 } 00078 00079 /* FIFO mode selection */ 00080 if ( LSM303AGR_ACC_W_FifoMode( (void *)this, LSM303AGR_ACC_FM_BYPASS ) == MEMS_ERROR ) 00081 { 00082 return 1; 00083 } 00084 00085 /* Output data rate selection - power down. */ 00086 if ( LSM303AGR_ACC_W_ODR( (void *)this, LSM303AGR_ACC_ODR_DO_PWR_DOWN ) == MEMS_ERROR ) 00087 { 00088 return 1; 00089 } 00090 00091 /* Full scale selection. */ 00092 if ( set_x_fs( 2.0f ) == 1 ) 00093 { 00094 return 1; 00095 } 00096 00097 /* Enable axes. */ 00098 if ( LSM303AGR_ACC_W_XEN( (void *)this, LSM303AGR_ACC_XEN_ENABLED ) == MEMS_ERROR ) 00099 { 00100 return 1; 00101 } 00102 00103 if ( LSM303AGR_ACC_W_YEN ( (void *)this, LSM303AGR_ACC_YEN_ENABLED ) == MEMS_ERROR ) 00104 { 00105 return 1; 00106 } 00107 00108 if ( LSM303AGR_ACC_W_ZEN ( (void *)this, LSM303AGR_ACC_ZEN_ENABLED ) == MEMS_ERROR ) 00109 { 00110 return 1; 00111 } 00112 00113 /* Select default output data rate. */ 00114 _last_odr = 100.0f; 00115 00116 _is_enabled = 0; 00117 00118 return 0; 00119 } 00120 00121 /** 00122 * @brief Enable LSM303AGR Accelerator 00123 * @retval 0 in case of success, an error code otherwise 00124 */ 00125 int LSM303AGRAccSensor::enable(void) 00126 { 00127 /* Check if the component is already enabled */ 00128 if ( _is_enabled == 1 ) 00129 { 00130 return 0; 00131 } 00132 00133 /* Output data rate selection. */ 00134 if ( set_x_odr_when_enabled( _last_odr ) == 1 ) 00135 { 00136 return 1; 00137 } 00138 00139 _is_enabled = 1; 00140 00141 return 0; 00142 } 00143 00144 /** 00145 * @brief Disable LSM303AGR Accelerator 00146 * @retval 0 in case of success, an error code otherwise 00147 */ 00148 int LSM303AGRAccSensor::disable(void) 00149 { 00150 /* Check if the component is already disabled */ 00151 if ( _is_enabled == 0 ) 00152 { 00153 return 0; 00154 } 00155 00156 /* Store actual output data rate. */ 00157 if ( get_x_odr( &_last_odr ) == 1 ) 00158 { 00159 return 1; 00160 } 00161 00162 /* Output data rate selection - power down. */ 00163 if ( LSM303AGR_ACC_W_ODR( (void *)this, LSM303AGR_ACC_ODR_DO_PWR_DOWN ) == MEMS_ERROR ) 00164 { 00165 return 1; 00166 } 00167 00168 _is_enabled = 0; 00169 00170 return 0; 00171 } 00172 00173 /** 00174 * @brief Read ID of LSM303AGR Accelerometer 00175 * @param p_id the pointer where the ID of the device is stored 00176 * @retval 0 in case of success, an error code otherwise 00177 */ 00178 int LSM303AGRAccSensor::read_id(uint8_t *id) 00179 { 00180 if(!id) 00181 { 00182 return 1; 00183 } 00184 00185 /* Read WHO AM I register */ 00186 if ( LSM303AGR_ACC_R_WHO_AM_I( (void *)this, id ) == MEMS_ERROR ) 00187 { 00188 return 1; 00189 } 00190 00191 return 0; 00192 } 00193 00194 /** 00195 * @brief Read data from LSM303AGR Accelerometer 00196 * @param pData the pointer where the accelerometer data are stored 00197 * @retval 0 in case of success, an error code otherwise 00198 */ 00199 int LSM303AGRAccSensor::get_x_axes(int32_t *pData) 00200 { 00201 int data[3]; 00202 00203 /* Read data from LSM303AGR. */ 00204 if ( !LSM303AGR_ACC_Get_Acceleration((void *)this, data) ) 00205 { 00206 return 1; 00207 } 00208 00209 /* Calculate the data. */ 00210 pData[0] = (int32_t)data[0]; 00211 pData[1] = (int32_t)data[1]; 00212 pData[2] = (int32_t)data[2]; 00213 00214 return 0; 00215 } 00216 00217 /** 00218 * @brief Read Accelerometer Sensitivity 00219 * @param pfData the pointer where the accelerometer sensitivity is stored 00220 * @retval 0 in case of success, an error code otherwise 00221 */ 00222 int LSM303AGRAccSensor::get_x_sensitivity(float *pfData) 00223 { 00224 LSM303AGR_ACC_LPEN_t lp_value; 00225 LSM303AGR_ACC_HR_t hr_value; 00226 00227 /* Read low power flag */ 00228 if( LSM303AGR_ACC_R_LOWPWR_EN( (void *)this, &lp_value ) == MEMS_ERROR ) 00229 { 00230 return 1; 00231 } 00232 00233 /* Read high performance flag */ 00234 if( LSM303AGR_ACC_R_HiRes( (void *)this, &hr_value ) == MEMS_ERROR ) 00235 { 00236 return 1; 00237 } 00238 00239 if( lp_value == LSM303AGR_ACC_LPEN_DISABLED && hr_value == LSM303AGR_ACC_HR_DISABLED ) 00240 { 00241 /* Normal Mode */ 00242 return get_x_sensitivity_normal_mode( pfData ); 00243 } else if ( lp_value == LSM303AGR_ACC_LPEN_ENABLED && hr_value == LSM303AGR_ACC_HR_DISABLED ) 00244 { 00245 /* Low Power Mode */ 00246 return get_x_sensitivity_lp_mode( pfData ); 00247 } else if ( lp_value == LSM303AGR_ACC_LPEN_DISABLED && hr_value == LSM303AGR_ACC_HR_ENABLED ) 00248 { 00249 /* High Resolution Mode */ 00250 return get_x_sensitivity_hr_mode( pfData ); 00251 } else 00252 { 00253 /* Not allowed */ 00254 return 1; 00255 } 00256 } 00257 00258 /** 00259 * @brief Read Accelerometer Sensitivity in Normal Mode 00260 * @param sensitivity the pointer where the accelerometer sensitivity is stored 00261 * @retval 0 in case of success, an error code otherwise 00262 */ 00263 int LSM303AGRAccSensor::get_x_sensitivity_normal_mode( float *sensitivity ) 00264 { 00265 LSM303AGR_ACC_FS_t fullScale; 00266 00267 /* Read actual full scale selection from sensor. */ 00268 if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR ) 00269 { 00270 return 1; 00271 } 00272 00273 /* Store the sensitivity based on actual full scale. */ 00274 switch( fullScale ) 00275 { 00276 case LSM303AGR_ACC_FS_2G: 00277 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_NORMAL_MODE; 00278 break; 00279 case LSM303AGR_ACC_FS_4G: 00280 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_NORMAL_MODE; 00281 break; 00282 case LSM303AGR_ACC_FS_8G: 00283 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_NORMAL_MODE; 00284 break; 00285 case LSM303AGR_ACC_FS_16G: 00286 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_NORMAL_MODE; 00287 break; 00288 default: 00289 *sensitivity = -1.0f; 00290 return 1; 00291 } 00292 00293 return 0; 00294 } 00295 00296 /** 00297 * @brief Read Accelerometer Sensitivity in LP Mode 00298 * @param sensitivity the pointer where the accelerometer sensitivity is stored 00299 * @retval 0 in case of success, an error code otherwise 00300 */ 00301 int LSM303AGRAccSensor::get_x_sensitivity_lp_mode( float *sensitivity ) 00302 { 00303 LSM303AGR_ACC_FS_t fullScale; 00304 00305 /* Read actual full scale selection from sensor. */ 00306 if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR ) 00307 { 00308 return 1; 00309 } 00310 00311 /* Store the sensitivity based on actual full scale. */ 00312 switch( fullScale ) 00313 { 00314 case LSM303AGR_ACC_FS_2G: 00315 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_LOW_POWER_MODE; 00316 break; 00317 case LSM303AGR_ACC_FS_4G: 00318 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_LOW_POWER_MODE; 00319 break; 00320 case LSM303AGR_ACC_FS_8G: 00321 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_LOW_POWER_MODE; 00322 break; 00323 case LSM303AGR_ACC_FS_16G: 00324 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_LOW_POWER_MODE; 00325 break; 00326 default: 00327 *sensitivity = -1.0f; 00328 return 1; 00329 } 00330 00331 return 0; 00332 } 00333 00334 /** 00335 * @brief Read Accelerometer Sensitivity in HR Mode 00336 * @param sensitivity the pointer where the accelerometer sensitivity is stored 00337 * @retval 0 in case of success, an error code otherwise 00338 */ 00339 int LSM303AGRAccSensor::get_x_sensitivity_hr_mode( float *sensitivity ) 00340 { 00341 LSM303AGR_ACC_FS_t fullScale; 00342 00343 /* Read actual full scale selection from sensor. */ 00344 if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR ) 00345 { 00346 return 1; 00347 } 00348 00349 /* Store the sensitivity based on actual full scale. */ 00350 switch( fullScale ) 00351 { 00352 case LSM303AGR_ACC_FS_2G: 00353 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_HIGH_RESOLUTION_MODE; 00354 break; 00355 case LSM303AGR_ACC_FS_4G: 00356 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_HIGH_RESOLUTION_MODE; 00357 break; 00358 case LSM303AGR_ACC_FS_8G: 00359 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_HIGH_RESOLUTION_MODE; 00360 break; 00361 case LSM303AGR_ACC_FS_16G: 00362 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_HIGH_RESOLUTION_MODE; 00363 break; 00364 default: 00365 *sensitivity = -1.0f; 00366 return 1; 00367 } 00368 00369 return 0; 00370 } 00371 00372 /** 00373 * @brief Read raw data from LSM303AGR Accelerometer 00374 * @param pData the pointer where the accelerometer raw data are stored 00375 * @retval 0 in case of success, an error code otherwise 00376 */ 00377 int LSM303AGRAccSensor::get_x_axes_raw(int16_t *pData) 00378 { 00379 uint8_t regValue[6] = {0, 0, 0, 0, 0, 0}; 00380 u8_t shift = 0; 00381 LSM303AGR_ACC_LPEN_t lp; 00382 LSM303AGR_ACC_HR_t hr; 00383 00384 /* Determine which operational mode the acc is set */ 00385 if(!LSM303AGR_ACC_R_HiRes( (void *)this, &hr )) { 00386 return 1; 00387 } 00388 00389 if(!LSM303AGR_ACC_R_LOWPWR_EN( (void *)this, &lp )) { 00390 return 1; 00391 } 00392 00393 if (lp == LSM303AGR_ACC_LPEN_ENABLED && hr == LSM303AGR_ACC_HR_DISABLED) { 00394 /* op mode is LP 8-bit */ 00395 shift = 8; 00396 } else if (lp == LSM303AGR_ACC_LPEN_DISABLED && hr == LSM303AGR_ACC_HR_DISABLED) { 00397 /* op mode is Normal 10-bit */ 00398 shift = 6; 00399 } else if (lp == LSM303AGR_ACC_LPEN_DISABLED && hr == LSM303AGR_ACC_HR_ENABLED) { 00400 /* op mode is HR 12-bit */ 00401 shift = 4; 00402 } else { 00403 return 1; 00404 } 00405 00406 /* Read output registers from LSM303AGR_ACC_GYRO_OUTX_L_XL to LSM303AGR_ACC_GYRO_OUTZ_H_XL. */ 00407 if (!LSM303AGR_ACC_Get_Raw_Acceleration( (void *)this, ( uint8_t* )regValue )) 00408 { 00409 return 1; 00410 } 00411 00412 /* Format the data. */ 00413 pData[0] = ( ( ( ( ( int16_t )regValue[1] ) << 8 ) + ( int16_t )regValue[0] ) >> shift ); 00414 pData[1] = ( ( ( ( ( int16_t )regValue[3] ) << 8 ) + ( int16_t )regValue[2] ) >> shift ); 00415 pData[2] = ( ( ( ( ( int16_t )regValue[5] ) << 8 ) + ( int16_t )regValue[4] ) >> shift ); 00416 00417 return 0; 00418 } 00419 00420 /** 00421 * @brief Read LSM303AGR Accelerometer output data rate 00422 * @param odr the pointer to the output data rate 00423 * @retval 0 in case of success, an error code otherwise 00424 */ 00425 int LSM303AGRAccSensor::get_x_odr(float* odr) 00426 { 00427 LSM303AGR_ACC_ODR_t odr_low_level; 00428 00429 if ( LSM303AGR_ACC_R_ODR( (void *)this, &odr_low_level ) == MEMS_ERROR ) 00430 { 00431 return 1; 00432 } 00433 00434 switch( odr_low_level ) 00435 { 00436 case LSM303AGR_ACC_ODR_DO_PWR_DOWN: 00437 *odr = 0.0f; 00438 break; 00439 case LSM303AGR_ACC_ODR_DO_1Hz: 00440 *odr = 1.0f; 00441 break; 00442 case LSM303AGR_ACC_ODR_DO_10Hz: 00443 *odr = 10.0f; 00444 break; 00445 case LSM303AGR_ACC_ODR_DO_25Hz: 00446 *odr = 25.0f; 00447 break; 00448 case LSM303AGR_ACC_ODR_DO_50Hz: 00449 *odr = 50.0f; 00450 break; 00451 case LSM303AGR_ACC_ODR_DO_100Hz: 00452 *odr = 100.0f; 00453 break; 00454 case LSM303AGR_ACC_ODR_DO_200Hz: 00455 *odr = 200.0f; 00456 break; 00457 case LSM303AGR_ACC_ODR_DO_400Hz: 00458 *odr = 400.0f; 00459 break; 00460 default: 00461 *odr = -1.0f; 00462 return 1; 00463 } 00464 00465 return 0; 00466 } 00467 00468 /** 00469 * @brief Set ODR 00470 * @param odr the output data rate to be set 00471 * @retval 0 in case of success, an error code otherwise 00472 */ 00473 int LSM303AGRAccSensor::set_x_odr(float odr) 00474 { 00475 if(_is_enabled == 1) 00476 { 00477 if(set_x_odr_when_enabled(odr) == 1) 00478 { 00479 return 1; 00480 } 00481 } 00482 else 00483 { 00484 if(set_x_odr_when_disabled(odr) == 1) 00485 { 00486 return 1; 00487 } 00488 } 00489 00490 return 0; 00491 } 00492 00493 /** 00494 * @brief Set ODR when enabled 00495 * @param odr the output data rate to be set 00496 * @retval 0 in case of success, an error code otherwise 00497 */ 00498 int LSM303AGRAccSensor::set_x_odr_when_enabled(float odr) 00499 { 00500 LSM303AGR_ACC_ODR_t new_odr; 00501 00502 new_odr = ( odr <= 1.0f ) ? LSM303AGR_ACC_ODR_DO_1Hz 00503 : ( odr <= 10.0f ) ? LSM303AGR_ACC_ODR_DO_10Hz 00504 : ( odr <= 25.0f ) ? LSM303AGR_ACC_ODR_DO_25Hz 00505 : ( odr <= 50.0f ) ? LSM303AGR_ACC_ODR_DO_50Hz 00506 : ( odr <= 100.0f ) ? LSM303AGR_ACC_ODR_DO_100Hz 00507 : ( odr <= 200.0f ) ? LSM303AGR_ACC_ODR_DO_200Hz 00508 : LSM303AGR_ACC_ODR_DO_400Hz; 00509 00510 if ( LSM303AGR_ACC_W_ODR( (void *)this, new_odr ) == MEMS_ERROR ) 00511 { 00512 return 1; 00513 } 00514 00515 return 0; 00516 } 00517 00518 /** 00519 * @brief Set ODR when disabled 00520 * @param odr the output data rate to be set 00521 * @retval 0 in case of success, an error code otherwise 00522 */ 00523 int LSM303AGRAccSensor::set_x_odr_when_disabled(float odr) 00524 { 00525 _last_odr = ( odr <= 1.0f ) ? 1.0f 00526 : ( odr <= 10.0f ) ? 10.0f 00527 : ( odr <= 25.0f ) ? 25.0f 00528 : ( odr <= 50.0f ) ? 50.0f 00529 : ( odr <= 100.0f ) ? 100.0f 00530 : ( odr <= 200.0f ) ? 200.0f 00531 : 400.0f; 00532 00533 return 0; 00534 } 00535 00536 00537 /** 00538 * @brief Read LSM303AGR Accelerometer full scale 00539 * @param fullScale the pointer to the full scale 00540 * @retval 0 in case of success, an error code otherwise 00541 */ 00542 int LSM303AGRAccSensor::get_x_fs(float* fullScale) 00543 { 00544 LSM303AGR_ACC_FS_t fs_low_level; 00545 00546 if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fs_low_level ) == MEMS_ERROR ) 00547 { 00548 return 1; 00549 } 00550 00551 switch( fs_low_level ) 00552 { 00553 case LSM303AGR_ACC_FS_2G: 00554 *fullScale = 2.0f; 00555 break; 00556 case LSM303AGR_ACC_FS_4G: 00557 *fullScale = 4.0f; 00558 break; 00559 case LSM303AGR_ACC_FS_8G: 00560 *fullScale = 8.0f; 00561 break; 00562 case LSM303AGR_ACC_FS_16G: 00563 *fullScale = 16.0f; 00564 break; 00565 default: 00566 *fullScale = -1.0f; 00567 return 1; 00568 } 00569 00570 return 0; 00571 } 00572 00573 /** 00574 * @brief Set full scale 00575 * @param fullScale the full scale to be set 00576 * @retval 0 in case of success, an error code otherwise 00577 */ 00578 int LSM303AGRAccSensor::set_x_fs(float fullScale) 00579 { 00580 LSM303AGR_ACC_FS_t new_fs; 00581 00582 new_fs = ( fullScale <= 2.0f ) ? LSM303AGR_ACC_FS_2G 00583 : ( fullScale <= 4.0f ) ? LSM303AGR_ACC_FS_4G 00584 : ( fullScale <= 8.0f ) ? LSM303AGR_ACC_FS_8G 00585 : LSM303AGR_ACC_FS_16G; 00586 00587 if ( LSM303AGR_ACC_W_FullScale( (void *)this, new_fs ) == MEMS_ERROR ) 00588 { 00589 return 1; 00590 } 00591 00592 return 0; 00593 } 00594 00595 /** 00596 * @brief Read accelerometer data from register 00597 * @param reg register address 00598 * @param data register data 00599 * @retval 0 in case of success 00600 * @retval 1 in case of failure 00601 */ 00602 int LSM303AGRAccSensor::read_reg( uint8_t reg, uint8_t *data ) 00603 { 00604 00605 if ( LSM303AGR_ACC_read_reg( (void *)this, reg, data ) == MEMS_ERROR ) 00606 { 00607 return 1; 00608 } 00609 00610 return 0; 00611 } 00612 00613 /** 00614 * @brief Write accelerometer data to register 00615 * @param reg register address 00616 * @param data register data 00617 * @retval 0 in case of success 00618 * @retval 1 in case of failure 00619 */ 00620 int LSM303AGRAccSensor::write_reg( uint8_t reg, uint8_t data ) 00621 { 00622 00623 if ( LSM303AGR_ACC_write_reg( (void *)this, reg, data ) == MEMS_ERROR ) 00624 { 00625 return 1; 00626 } 00627 00628 return 0; 00629 } 00630 00631 uint8_t LSM303AGR_ACC_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ) 00632 { 00633 return ((LSM303AGRAccSensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite); 00634 } 00635 00636 uint8_t LSM303AGR_ACC_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ) 00637 { 00638 return ((LSM303AGRAccSensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead); 00639 }
Generated on Wed Jul 13 2022 13:21:41 by
1.7.2
