wayne roberts
/
CB-LORA-MR_utility
test sending sensor results over lora radio. Accelerometer and temp/pressure.
Embed:
(wiki syntax)
Show/hide line numbers
x_nucleo_iks01a2_accelero.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file x_nucleo_iks01a2_accelero.c 00004 * @author MEMS Application Team 00005 * @brief This file provides a set of functions needed to manage the accelerometer sensor 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© COPYRIGHT(c) 2018 STMicroelectronics</center></h2> 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00030 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 ****************************************************************************** 00034 */ 00035 00036 /* Includes ------------------------------------------------------------------*/ 00037 00038 #include "x_nucleo_iks01a2_accelero.h" 00039 00040 /** @addtogroup BSP BSP 00041 * @{ 00042 */ 00043 00044 /** @addtogroup X_NUCLEO_IKS01A2 X_NUCLEO_IKS01A2 00045 * @{ 00046 */ 00047 00048 /** @addtogroup X_NUCLEO_IKS01A2_ACCELERO Accelerometer 00049 * @{ 00050 */ 00051 00052 /** @addtogroup X_NUCLEO_IKS01A2_ACCELERO_Extern_Variables Extern variables 00053 * @{ 00054 */ 00055 00056 extern void *LSM303AGR_X_handle; /* Needed for testing LSM303AGR onboard presence. */ 00057 00058 /** 00059 * @} 00060 */ 00061 00062 /** @addtogroup X_NUCLEO_IKS01A2_ACCELERO_Private_Variables Private variables 00063 * @{ 00064 */ 00065 00066 static DrvContextTypeDef ACCELERO_SensorHandle[ ACCELERO_SENSORS_MAX_NUM ]; 00067 static ACCELERO_Data_t ACCELERO_Data[ ACCELERO_SENSORS_MAX_NUM ]; /* Accelerometer - all */ 00068 static LIS2DH12_Data_t LIS2DH12_0_Data; /* Accelerometer - sensor 3 */ 00069 00070 /** 00071 * @} 00072 */ 00073 00074 /** @addtogroup X_NUCLEO_IKS01A2_ACCELERO_Private_FunctionPrototypes Private function prototypes 00075 * @{ 00076 */ 00077 00078 static DrvStatusTypeDef BSP_LIS2DH12_ACCELERO_Init(void **handle); 00079 00080 /** 00081 * @} 00082 */ 00083 00084 /** @addtogroup X_NUCLEO_IKS01A2_ACCELERO_Public_Functions Public functions 00085 * @{ 00086 */ 00087 00088 /** 00089 * @brief Initialize an accelerometer sensor 00090 * @param id the accelerometer sensor identifier 00091 * @param handle the device handle 00092 * @retval COMPONENT_OK in case of success 00093 * @retval COMPONENT_ERROR in case of failure 00094 */ 00095 DrvStatusTypeDef BSP_ACCELERO_Init(ACCELERO_ID_t id, void **handle) 00096 { 00097 *handle = NULL; 00098 00099 switch (id) 00100 { 00101 default: 00102 case ACCELERO_SENSORS_AUTO: /* Try to init accelerometer sensors with following priority order: */ 00103 /* Special init needed for future testing onboard LSM303AGR magnetometer presence in sensor_commands.c. 00104 * This init has to be placed here in the very first place without any return. */ 00105 if (BSP_LIS2DH12_ACCELERO_Init(handle) == COMPONENT_OK) 00106 { 00107 return COMPONENT_OK; 00108 } 00109 break; 00110 00111 00112 case LIS2DH12_0: 00113 return BSP_LIS2DH12_ACCELERO_Init(handle); 00114 00115 } 00116 00117 return COMPONENT_ERROR; 00118 } 00119 00120 00121 /** 00122 * @brief Deinitialize accelerometer sensor 00123 * @param handle the device handle 00124 * @retval COMPONENT_OK in case of success 00125 * @retval COMPONENT_ERROR in case of failure 00126 */ 00127 DrvStatusTypeDef BSP_ACCELERO_DeInit(void **handle) 00128 { 00129 00130 DrvContextTypeDef *ctx = (DrvContextTypeDef *)(*handle); 00131 ACCELERO_Drv_t *driver = NULL; 00132 00133 if (ctx == NULL) 00134 { 00135 return COMPONENT_ERROR; 00136 } 00137 00138 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00139 00140 if (driver->DeInit == NULL) 00141 { 00142 return COMPONENT_ERROR; 00143 } 00144 00145 if (driver->DeInit(ctx) == COMPONENT_ERROR) 00146 { 00147 return COMPONENT_ERROR; 00148 } 00149 00150 memset(ctx, 0, sizeof(DrvContextTypeDef)); 00151 00152 *handle = NULL; 00153 00154 return COMPONENT_OK; 00155 } 00156 00157 00158 00159 /** 00160 * @brief Enable accelerometer sensor 00161 * @param handle the device handle 00162 * @retval COMPONENT_OK in case of success 00163 * @retval COMPONENT_ERROR in case of failure 00164 */ 00165 DrvStatusTypeDef BSP_ACCELERO_Sensor_Enable(void *handle) 00166 { 00167 00168 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00169 ACCELERO_Drv_t *driver = NULL; 00170 00171 if (ctx == NULL) 00172 { 00173 return COMPONENT_ERROR; 00174 } 00175 00176 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00177 00178 if (driver->Sensor_Enable == NULL) 00179 { 00180 return COMPONENT_ERROR; 00181 } 00182 00183 if (driver->Sensor_Enable(ctx) == COMPONENT_ERROR) 00184 { 00185 return COMPONENT_ERROR; 00186 } 00187 00188 return COMPONENT_OK; 00189 } 00190 00191 00192 00193 /** 00194 * @brief Disable accelerometer sensor 00195 * @param handle the device handle 00196 * @retval COMPONENT_OK in case of success 00197 * @retval COMPONENT_ERROR in case of failure 00198 */ 00199 DrvStatusTypeDef BSP_ACCELERO_Sensor_Disable(void *handle) 00200 { 00201 00202 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00203 ACCELERO_Drv_t *driver = NULL; 00204 00205 if (ctx == NULL) 00206 { 00207 return COMPONENT_ERROR; 00208 } 00209 00210 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00211 00212 if (driver->Sensor_Disable == NULL) 00213 { 00214 return COMPONENT_ERROR; 00215 } 00216 00217 if (driver->Sensor_Disable(ctx) == COMPONENT_ERROR) 00218 { 00219 return COMPONENT_ERROR; 00220 } 00221 00222 return COMPONENT_OK; 00223 } 00224 00225 00226 /** 00227 * @brief Check if the accelerometer sensor is initialized 00228 * @param handle the device handle 00229 * @param status the pointer to the initialization status 00230 * @retval COMPONENT_OK in case of success 00231 * @retval COMPONENT_ERROR in case of failure 00232 */ 00233 DrvStatusTypeDef BSP_ACCELERO_IsInitialized(void *handle, uint8_t *status) 00234 { 00235 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00236 00237 if (ctx == NULL) 00238 { 00239 return COMPONENT_ERROR; 00240 } 00241 00242 if (status == NULL) 00243 { 00244 return COMPONENT_ERROR; 00245 } 00246 00247 *status = ctx->isInitialized; 00248 00249 return COMPONENT_OK; 00250 } 00251 00252 00253 /** 00254 * @brief Check if the accelerometer sensor is enabled 00255 * @param handle the device handle 00256 * @param status the pointer to the enable status 00257 * @retval COMPONENT_OK in case of success 00258 * @retval COMPONENT_ERROR in case of failure 00259 */ 00260 DrvStatusTypeDef BSP_ACCELERO_IsEnabled(void *handle, uint8_t *status) 00261 { 00262 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00263 00264 if (ctx == NULL) 00265 { 00266 return COMPONENT_ERROR; 00267 } 00268 00269 if (status == NULL) 00270 { 00271 return COMPONENT_ERROR; 00272 } 00273 00274 *status = ctx->isEnabled; 00275 00276 return COMPONENT_OK; 00277 } 00278 00279 00280 /** 00281 * @brief Check if the accelerometer sensor is combo 00282 * @param handle the device handle 00283 * @param status the pointer to the combo status 00284 * @retval COMPONENT_OK in case of success 00285 * @retval COMPONENT_ERROR in case of failure 00286 */ 00287 DrvStatusTypeDef BSP_ACCELERO_IsCombo(void *handle, uint8_t *status) 00288 { 00289 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00290 00291 if (ctx == NULL) 00292 { 00293 return COMPONENT_ERROR; 00294 } 00295 00296 if (status == NULL) 00297 { 00298 return COMPONENT_ERROR; 00299 } 00300 00301 *status = ctx->isCombo; 00302 00303 return COMPONENT_OK; 00304 } 00305 00306 00307 /** 00308 * @brief Get the accelerometer sensor instance 00309 * @param handle the device handle 00310 * @param instance the pointer to the device instance 00311 * @retval COMPONENT_OK in case of success 00312 * @retval COMPONENT_ERROR in case of failure 00313 */ 00314 DrvStatusTypeDef BSP_ACCELERO_Get_Instance(void *handle, uint8_t *instance) 00315 { 00316 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00317 00318 if (ctx == NULL) 00319 { 00320 return COMPONENT_ERROR; 00321 } 00322 00323 if (instance == NULL) 00324 { 00325 return COMPONENT_ERROR; 00326 } 00327 00328 *instance = ctx->instance; 00329 00330 return COMPONENT_OK; 00331 } 00332 00333 00334 00335 /** 00336 * @brief Get the WHO_AM_I ID of the accelerometer sensor 00337 * @param handle the device handle 00338 * @param who_am_i pointer to the value of WHO_AM_I register 00339 * @retval COMPONENT_OK in case of success 00340 * @retval COMPONENT_ERROR in case of failure 00341 */ 00342 DrvStatusTypeDef BSP_ACCELERO_Get_WhoAmI(void *handle, uint8_t *who_am_i) 00343 { 00344 00345 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00346 ACCELERO_Drv_t *driver = NULL; 00347 00348 if (ctx == NULL) 00349 { 00350 return COMPONENT_ERROR; 00351 } 00352 00353 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00354 00355 if (driver->Get_WhoAmI == NULL) 00356 { 00357 return COMPONENT_ERROR; 00358 } 00359 00360 if (driver->Get_WhoAmI(ctx, who_am_i) == COMPONENT_ERROR) 00361 { 00362 return COMPONENT_ERROR; 00363 } 00364 00365 return COMPONENT_OK; 00366 } 00367 00368 00369 00370 /** 00371 * @brief Check the WHO_AM_I ID of the accelerometer sensor 00372 * @param handle the device handle 00373 * @retval COMPONENT_OK in case of success 00374 * @retval COMPONENT_ERROR in case of failure 00375 */ 00376 DrvStatusTypeDef BSP_ACCELERO_Check_WhoAmI(void *handle) 00377 { 00378 00379 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00380 ACCELERO_Drv_t *driver = NULL; 00381 00382 if (ctx == NULL) 00383 { 00384 return COMPONENT_ERROR; 00385 } 00386 00387 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00388 00389 if (driver->Check_WhoAmI == NULL) 00390 { 00391 return COMPONENT_ERROR; 00392 } 00393 00394 if (driver->Check_WhoAmI(ctx) == COMPONENT_ERROR) 00395 { 00396 return COMPONENT_ERROR; 00397 } 00398 00399 return COMPONENT_OK; 00400 } 00401 00402 00403 00404 /** 00405 * @brief Get the accelerometer sensor axes 00406 * @param handle the device handle 00407 * @param acceleration pointer where the values of the axes are written [mg] 00408 * @retval COMPONENT_OK in case of success 00409 * @retval COMPONENT_ERROR in case of failure 00410 */ 00411 DrvStatusTypeDef BSP_ACCELERO_Get_Axes(void *handle, SensorAxes_t *acceleration) 00412 { 00413 00414 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00415 ACCELERO_Drv_t *driver = NULL; 00416 00417 if (ctx == NULL) 00418 { 00419 return COMPONENT_ERROR; 00420 } 00421 00422 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00423 00424 if (acceleration == NULL) 00425 { 00426 return COMPONENT_ERROR; 00427 } 00428 00429 if (driver->Get_Axes == NULL) 00430 { 00431 return COMPONENT_ERROR; 00432 } 00433 00434 if (driver->Get_Axes(ctx, acceleration) == COMPONENT_ERROR) 00435 { 00436 return COMPONENT_ERROR; 00437 } 00438 00439 return COMPONENT_OK; 00440 } 00441 00442 00443 00444 /** 00445 * @brief Get the accelerometer sensor raw axes 00446 * @param handle the device handle 00447 * @param value pointer where the raw values of the axes are written 00448 * @retval COMPONENT_OK in case of success 00449 * @retval COMPONENT_ERROR in case of failure 00450 */ 00451 DrvStatusTypeDef BSP_ACCELERO_Get_AxesRaw(void *handle, SensorAxesRaw_t *value) 00452 { 00453 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00454 ACCELERO_Drv_t *driver = NULL; 00455 00456 if (ctx == NULL) 00457 { 00458 return COMPONENT_ERROR; 00459 } 00460 00461 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00462 00463 if (value == NULL) 00464 { 00465 return COMPONENT_ERROR; 00466 } 00467 00468 if (driver->Get_AxesRaw == NULL) 00469 { 00470 return COMPONENT_ERROR; 00471 } 00472 00473 if (driver->Get_AxesRaw(ctx, value) == COMPONENT_ERROR) 00474 { 00475 return COMPONENT_ERROR; 00476 } 00477 00478 return COMPONENT_OK; 00479 } 00480 00481 00482 /** 00483 * @brief Get the accelerometer sensor sensitivity 00484 * @param handle the device handle 00485 * @param sensitivity pointer where the sensitivity value is written [mg/LSB] 00486 * @retval COMPONENT_OK in case of success 00487 * @retval COMPONENT_ERROR in case of failure 00488 */ 00489 DrvStatusTypeDef BSP_ACCELERO_Get_Sensitivity(void *handle, float *sensitivity) 00490 { 00491 00492 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00493 ACCELERO_Drv_t *driver = NULL; 00494 00495 if (ctx == NULL) 00496 { 00497 return COMPONENT_ERROR; 00498 } 00499 00500 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00501 00502 if (sensitivity == NULL) 00503 { 00504 return COMPONENT_ERROR; 00505 } 00506 00507 if (driver->Get_Sensitivity == NULL) 00508 { 00509 return COMPONENT_ERROR; 00510 } 00511 00512 if (driver->Get_Sensitivity(ctx, sensitivity) == COMPONENT_ERROR) 00513 { 00514 return COMPONENT_ERROR; 00515 } 00516 00517 return COMPONENT_OK; 00518 } 00519 00520 00521 00522 /** 00523 * @brief Get the accelerometer sensor output data rate 00524 * @param handle the device handle 00525 * @param odr pointer where the output data rate is written 00526 * @retval COMPONENT_OK in case of success 00527 * @retval COMPONENT_ERROR in case of failure 00528 */ 00529 DrvStatusTypeDef BSP_ACCELERO_Get_ODR(void *handle, float *odr) 00530 { 00531 00532 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00533 ACCELERO_Drv_t *driver = NULL; 00534 00535 if (ctx == NULL) 00536 { 00537 return COMPONENT_ERROR; 00538 } 00539 00540 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00541 00542 if (odr == NULL) 00543 { 00544 return COMPONENT_ERROR; 00545 } 00546 00547 if (driver->Get_ODR == NULL) 00548 { 00549 return COMPONENT_ERROR; 00550 } 00551 00552 if (driver->Get_ODR(ctx, odr) == COMPONENT_ERROR) 00553 { 00554 return COMPONENT_ERROR; 00555 } 00556 00557 return COMPONENT_OK; 00558 } 00559 00560 00561 00562 /** 00563 * @brief Set the accelerometer sensor output data rate 00564 * @param handle the device handle 00565 * @param odr the functional output data rate to be set 00566 * @retval COMPONENT_OK in case of success 00567 * @retval COMPONENT_ERROR in case of failure 00568 */ 00569 DrvStatusTypeDef BSP_ACCELERO_Set_ODR(void *handle, SensorOdr_t odr) 00570 { 00571 00572 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00573 ACCELERO_Drv_t *driver = NULL; 00574 00575 if (ctx == NULL) 00576 { 00577 return COMPONENT_ERROR; 00578 } 00579 00580 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00581 00582 if (driver->Set_ODR == NULL) 00583 { 00584 return COMPONENT_ERROR; 00585 } 00586 if (driver->Set_ODR(ctx, odr) == COMPONENT_ERROR) 00587 { 00588 return COMPONENT_ERROR; 00589 } 00590 00591 return COMPONENT_OK; 00592 } 00593 00594 00595 00596 /** 00597 * @brief Set the accelerometer sensor output data rate 00598 * @param handle the device handle 00599 * @param odr the output data rate value to be set 00600 * @retval COMPONENT_OK in case of success 00601 * @retval COMPONENT_ERROR in case of failure 00602 */ 00603 DrvStatusTypeDef BSP_ACCELERO_Set_ODR_Value(void *handle, float odr) 00604 { 00605 00606 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00607 ACCELERO_Drv_t *driver = NULL; 00608 00609 if (ctx == NULL) 00610 { 00611 return COMPONENT_ERROR; 00612 } 00613 00614 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00615 00616 if (driver->Set_ODR_Value == NULL) 00617 { 00618 return COMPONENT_ERROR; 00619 } 00620 if (driver->Set_ODR_Value(ctx, odr) == COMPONENT_ERROR) 00621 { 00622 return COMPONENT_ERROR; 00623 } 00624 00625 return COMPONENT_OK; 00626 } 00627 00628 00629 00630 /** 00631 * @brief Get the accelerometer sensor full scale 00632 * @param handle the device handle 00633 * @param fullScale pointer where the full scale is written 00634 * @retval COMPONENT_OK in case of success 00635 * @retval COMPONENT_ERROR in case of failure 00636 */ 00637 DrvStatusTypeDef BSP_ACCELERO_Get_FS(void *handle, float *fullScale) 00638 { 00639 00640 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00641 ACCELERO_Drv_t *driver = NULL; 00642 00643 if (ctx == NULL) 00644 { 00645 return COMPONENT_ERROR; 00646 } 00647 00648 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00649 00650 if (fullScale == NULL) 00651 { 00652 return COMPONENT_ERROR; 00653 } 00654 00655 if (driver->Get_FS == NULL) 00656 { 00657 return COMPONENT_ERROR; 00658 } 00659 00660 if (driver->Get_FS(ctx, fullScale) == COMPONENT_ERROR) 00661 { 00662 return COMPONENT_ERROR; 00663 } 00664 00665 return COMPONENT_OK; 00666 } 00667 00668 00669 00670 /** 00671 * @brief Set the accelerometer sensor full scale 00672 * @param handle the device handle 00673 * @param fullScale the functional full scale to be set 00674 * @retval COMPONENT_OK in case of success 00675 * @retval COMPONENT_ERROR in case of failure 00676 */ 00677 DrvStatusTypeDef BSP_ACCELERO_Set_FS(void *handle, SensorFs_t fullScale) 00678 { 00679 00680 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00681 ACCELERO_Drv_t *driver = NULL; 00682 00683 if (ctx == NULL) 00684 { 00685 return COMPONENT_ERROR; 00686 } 00687 00688 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00689 00690 if (driver->Set_FS == NULL) 00691 { 00692 return COMPONENT_ERROR; 00693 } 00694 if (driver->Set_FS(ctx, fullScale) == COMPONENT_ERROR) 00695 { 00696 return COMPONENT_ERROR; 00697 } 00698 00699 return COMPONENT_OK; 00700 } 00701 00702 00703 00704 /** 00705 * @brief Set the accelerometer sensor full scale 00706 * @param handle the device handle 00707 * @param fullScale the full scale value to be set 00708 * @retval COMPONENT_OK in case of success 00709 * @retval COMPONENT_ERROR in case of failure 00710 */ 00711 DrvStatusTypeDef BSP_ACCELERO_Set_FS_Value(void *handle, float fullScale) 00712 { 00713 00714 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00715 ACCELERO_Drv_t *driver = NULL; 00716 00717 if (ctx == NULL) 00718 { 00719 return COMPONENT_ERROR; 00720 } 00721 00722 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00723 00724 if (driver->Set_FS_Value == NULL) 00725 { 00726 return COMPONENT_ERROR; 00727 } 00728 if (driver->Set_FS_Value(ctx, fullScale) == COMPONENT_ERROR) 00729 { 00730 return COMPONENT_ERROR; 00731 } 00732 00733 return COMPONENT_OK; 00734 } 00735 00736 00737 00738 /** 00739 * @brief Get the accelerometer sensor axes status 00740 * @param handle the device handle 00741 * @param xyz_enabled the pointer to the axes enabled/disabled status 00742 * @retval COMPONENT_OK in case of success 00743 * @retval COMPONENT_ERROR in case of failure 00744 */ 00745 DrvStatusTypeDef BSP_ACCELERO_Get_Axes_Status(void *handle, uint8_t *xyz_enabled) 00746 { 00747 00748 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00749 ACCELERO_Drv_t *driver = NULL; 00750 00751 if (ctx == NULL) 00752 { 00753 return COMPONENT_ERROR; 00754 } 00755 00756 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00757 00758 if (xyz_enabled == NULL) 00759 { 00760 return COMPONENT_ERROR; 00761 } 00762 00763 if (driver->Get_Axes_Status == NULL) 00764 { 00765 return COMPONENT_ERROR; 00766 } 00767 00768 if (driver->Get_Axes_Status(ctx, xyz_enabled) == COMPONENT_ERROR) 00769 { 00770 return COMPONENT_ERROR; 00771 } 00772 00773 return COMPONENT_OK; 00774 } 00775 00776 00777 00778 /** 00779 * @brief Set the enabled/disabled status of the accelerometer sensor axes 00780 * @param handle the device handle 00781 * @param enable_xyz vector of the axes enabled/disabled status 00782 * @retval COMPONENT_OK in case of success 00783 * @retval COMPONENT_ERROR in case of failure 00784 */ 00785 DrvStatusTypeDef BSP_ACCELERO_Set_Axes_Status(void *handle, uint8_t *enable_xyz) 00786 { 00787 00788 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00789 ACCELERO_Drv_t *driver = NULL; 00790 00791 if (ctx == NULL) 00792 { 00793 return COMPONENT_ERROR; 00794 } 00795 00796 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00797 00798 if (enable_xyz == NULL) 00799 { 00800 return COMPONENT_ERROR; 00801 } 00802 00803 if (driver->Set_Axes_Status == NULL) 00804 { 00805 return COMPONENT_ERROR; 00806 } 00807 00808 if (driver->Set_Axes_Status(ctx, enable_xyz) == COMPONENT_ERROR) 00809 { 00810 return COMPONENT_ERROR; 00811 } 00812 00813 return COMPONENT_OK; 00814 } 00815 00816 00817 00818 /** 00819 * @brief Read the data from register 00820 * @param handle the device handle 00821 * @param reg register address 00822 * @param data register data 00823 * @retval COMPONENT_OK in case of success 00824 * @retval COMPONENT_ERROR in case of failure 00825 */ 00826 DrvStatusTypeDef BSP_ACCELERO_Read_Reg(void *handle, uint8_t reg, uint8_t *data) 00827 { 00828 00829 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00830 ACCELERO_Drv_t *driver = NULL; 00831 00832 if (ctx == NULL) 00833 { 00834 return COMPONENT_ERROR; 00835 } 00836 00837 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00838 00839 if (data == NULL) 00840 { 00841 return COMPONENT_ERROR; 00842 } 00843 00844 if (driver->Read_Reg == NULL) 00845 { 00846 return COMPONENT_ERROR; 00847 } 00848 00849 if (driver->Read_Reg(ctx, reg, data) == COMPONENT_ERROR) 00850 { 00851 return COMPONENT_ERROR; 00852 } 00853 00854 return COMPONENT_OK; 00855 } 00856 00857 00858 00859 /** 00860 * @brief Write the data to register 00861 * @param handle the device handle 00862 * @param reg register address 00863 * @param data register data 00864 * @retval COMPONENT_OK in case of success 00865 * @retval COMPONENT_ERROR in case of failure 00866 */ 00867 DrvStatusTypeDef BSP_ACCELERO_Write_Reg(void *handle, uint8_t reg, uint8_t data) 00868 { 00869 00870 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00871 ACCELERO_Drv_t *driver = NULL; 00872 00873 if (ctx == NULL) 00874 { 00875 return COMPONENT_ERROR; 00876 } 00877 00878 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00879 00880 if (driver->Write_Reg == NULL) 00881 { 00882 return COMPONENT_ERROR; 00883 } 00884 00885 if (driver->Write_Reg(ctx, reg, data) == COMPONENT_ERROR) 00886 { 00887 return COMPONENT_ERROR; 00888 } 00889 00890 return COMPONENT_OK; 00891 } 00892 00893 00894 00895 /** 00896 * @brief Get accelerometer data ready status 00897 * @param handle the device handle 00898 * @param status the data ready status 00899 * @retval COMPONENT_OK in case of success 00900 * @retval COMPONENT_ERROR in case of failure 00901 */ 00902 DrvStatusTypeDef BSP_ACCELERO_Get_DRDY_Status(void *handle, uint8_t *status) 00903 { 00904 00905 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00906 ACCELERO_Drv_t *driver = NULL; 00907 00908 if (ctx == NULL) 00909 { 00910 return COMPONENT_ERROR; 00911 } 00912 00913 driver = (ACCELERO_Drv_t *)ctx->pVTable; 00914 00915 if (driver->Get_DRDY_Status == NULL) 00916 { 00917 return COMPONENT_ERROR; 00918 } 00919 00920 if (driver->Get_DRDY_Status(ctx, status) == COMPONENT_ERROR) 00921 { 00922 return COMPONENT_ERROR; 00923 } 00924 00925 return COMPONENT_OK; 00926 } 00927 00928 #if 0 00929 /** 00930 * @} 00931 */ 00932 00933 /** @addtogroup X_NUCLEO_IKS01A2_ACCELERO_Public_Functions_Ext Public functions for extended features 00934 * @{ 00935 */ 00936 00937 /** 00938 * @brief Enable the free fall detection (available only for LSM6DSL sensor) 00939 * @param handle the device handle 00940 * @param int_pin the interrupt pin to be used 00941 * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g 00942 * @retval COMPONENT_OK in case of success 00943 * @retval COMPONENT_ERROR in case of failure 00944 */ 00945 DrvStatusTypeDef BSP_ACCELERO_Enable_Free_Fall_Detection_Ext(void *handle, SensorIntPin_t int_pin) 00946 { 00947 00948 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00949 00950 if (ctx == NULL) 00951 { 00952 return COMPONENT_ERROR; 00953 } 00954 00955 if (ctx->pExtVTable == NULL) 00956 { 00957 return COMPONENT_ERROR; 00958 } 00959 00960 /* At the moment this feature is only implemented for LSM6DSL */ 00961 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 00962 { 00963 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 00964 00965 if (extDriver->Enable_Free_Fall_Detection == NULL) 00966 { 00967 return COMPONENT_ERROR; 00968 } 00969 00970 else 00971 { 00972 return extDriver->Enable_Free_Fall_Detection(ctx, int_pin); 00973 } 00974 } 00975 00976 else 00977 { 00978 return COMPONENT_ERROR; 00979 } 00980 } 00981 00982 /** 00983 * @brief Disable the free fall detection (available only for LSM6DSL sensor) 00984 * @param handle the device handle 00985 * @retval COMPONENT_OK in case of success 00986 * @retval COMPONENT_ERROR in case of failure 00987 */ 00988 DrvStatusTypeDef BSP_ACCELERO_Disable_Free_Fall_Detection_Ext(void *handle) 00989 { 00990 00991 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 00992 00993 if (ctx == NULL) 00994 { 00995 return COMPONENT_ERROR; 00996 } 00997 00998 if (ctx->pExtVTable == NULL) 00999 { 01000 return COMPONENT_ERROR; 01001 } 01002 01003 /* At the moment this feature is only implemented for LSM6DSL */ 01004 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01005 { 01006 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01007 01008 if (extDriver->Disable_Free_Fall_Detection == NULL) 01009 { 01010 return COMPONENT_ERROR; 01011 } 01012 01013 else 01014 { 01015 return extDriver->Disable_Free_Fall_Detection(ctx); 01016 } 01017 } 01018 01019 else 01020 { 01021 return COMPONENT_ERROR; 01022 } 01023 } 01024 01025 /** 01026 * @brief Get the status of the free fall detection (available only for LSM6DSL sensor) 01027 * @param handle the device handle 01028 * @param status the pointer to the status of free fall detection: 0 means no detection, 1 means detection happened 01029 * @note This function is deprecated and has been replaced by BSP_ACCELERO_Get_Event_Status_Ext 01030 * @retval COMPONENT_OK in case of success 01031 * @retval COMPONENT_ERROR in case of failure 01032 */ 01033 DrvStatusTypeDef BSP_ACCELERO_Get_Free_Fall_Detection_Status_Ext(void *handle, uint8_t *status) 01034 { 01035 01036 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01037 01038 if (ctx == NULL) 01039 { 01040 return COMPONENT_ERROR; 01041 } 01042 01043 if (ctx->pExtVTable == NULL) 01044 { 01045 return COMPONENT_ERROR; 01046 } 01047 01048 if (status == NULL) 01049 { 01050 return COMPONENT_ERROR; 01051 } 01052 01053 /* At the moment this feature is only implemented for LSM6DSL */ 01054 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01055 { 01056 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01057 01058 if (extDriver->Get_Free_Fall_Detection_Status == NULL) 01059 { 01060 return COMPONENT_ERROR; 01061 } 01062 01063 else 01064 { 01065 return extDriver->Get_Free_Fall_Detection_Status(ctx, status); 01066 } 01067 } 01068 01069 else 01070 { 01071 return COMPONENT_ERROR; 01072 } 01073 } 01074 01075 01076 /** 01077 * @brief Set the free fall detection threshold (available only for LSM6DSL sensor) 01078 * @param handle the device handle 01079 * @param thr the threshold to be set 01080 * @retval COMPONENT_OK in case of success 01081 * @retval COMPONENT_ERROR in case of failure 01082 */ 01083 DrvStatusTypeDef BSP_ACCELERO_Set_Free_Fall_Threshold_Ext(void *handle, uint8_t thr) 01084 { 01085 01086 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01087 01088 if (ctx == NULL) 01089 { 01090 return COMPONENT_ERROR; 01091 } 01092 01093 if (ctx->pExtVTable == NULL) 01094 { 01095 return COMPONENT_ERROR; 01096 } 01097 01098 /* At the moment this feature is only implemented for LSM6DSL */ 01099 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01100 { 01101 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01102 01103 if (extDriver->Set_Free_Fall_Threshold == NULL) 01104 { 01105 return COMPONENT_ERROR; 01106 } 01107 01108 else 01109 { 01110 return extDriver->Set_Free_Fall_Threshold(ctx, thr); 01111 } 01112 } 01113 01114 else 01115 { 01116 return COMPONENT_ERROR; 01117 } 01118 } 01119 01120 01121 01122 /** 01123 * @brief Enable the pedometer feature (available only for LSM6DSL sensor) 01124 * @param handle the device handle 01125 * @note This function sets the LSM6DSL accelerometer ODR to 26Hz and the LSM6DSL accelerometer full scale to 2g 01126 * @retval COMPONENT_OK in case of success 01127 * @retval COMPONENT_ERROR in case of failure 01128 */ 01129 DrvStatusTypeDef BSP_ACCELERO_Enable_Pedometer_Ext(void *handle) 01130 { 01131 01132 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01133 01134 if (ctx == NULL) 01135 { 01136 return COMPONENT_ERROR; 01137 } 01138 01139 if (ctx->pExtVTable == NULL) 01140 { 01141 return COMPONENT_ERROR; 01142 } 01143 01144 /* At the moment this feature is only implemented for LSM6DSL */ 01145 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01146 { 01147 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01148 01149 if (extDriver->Enable_Pedometer == NULL) 01150 { 01151 return COMPONENT_ERROR; 01152 } 01153 01154 else 01155 { 01156 return extDriver->Enable_Pedometer(ctx); 01157 } 01158 } 01159 01160 else 01161 { 01162 return COMPONENT_ERROR; 01163 } 01164 } 01165 01166 /** 01167 * @brief Disable the pedometer feature (available only for LSM6DSL sensor) 01168 * @param handle the device handle 01169 * @retval COMPONENT_OK in case of success 01170 * @retval COMPONENT_ERROR in case of failure 01171 */ 01172 DrvStatusTypeDef BSP_ACCELERO_Disable_Pedometer_Ext(void *handle) 01173 { 01174 01175 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01176 01177 if (ctx == NULL) 01178 { 01179 return COMPONENT_ERROR; 01180 } 01181 01182 if (ctx->pExtVTable == NULL) 01183 { 01184 return COMPONENT_ERROR; 01185 } 01186 01187 /* At the moment this feature is only implemented for LSM6DSL */ 01188 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01189 { 01190 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01191 01192 if (extDriver->Disable_Pedometer == NULL) 01193 { 01194 return COMPONENT_ERROR; 01195 } 01196 01197 else 01198 { 01199 return extDriver->Disable_Pedometer(ctx); 01200 } 01201 } 01202 01203 else 01204 { 01205 return COMPONENT_ERROR; 01206 } 01207 } 01208 01209 /** 01210 * @brief Get the pedometer status (available only for LSM6DSL sensor) 01211 * @param handle the device handle 01212 * @param status the pointer to the pedometer status: 0 means no step detected, 1 means step detected 01213 * @note This function is deprecated and has been replaced by BSP_ACCELERO_Get_Event_Status_Ext 01214 * @retval COMPONENT_OK in case of success 01215 * @retval COMPONENT_ERROR in case of failure 01216 */ 01217 DrvStatusTypeDef BSP_ACCELERO_Get_Pedometer_Status_Ext(void *handle, uint8_t *status) 01218 { 01219 01220 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01221 01222 if (ctx == NULL) 01223 { 01224 return COMPONENT_ERROR; 01225 } 01226 01227 if (ctx->pExtVTable == NULL) 01228 { 01229 return COMPONENT_ERROR; 01230 } 01231 01232 if (status == NULL) 01233 { 01234 return COMPONENT_ERROR; 01235 } 01236 01237 /* At the moment this feature is only implemented for LSM6DSL */ 01238 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01239 { 01240 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01241 01242 if (extDriver->Get_Pedometer_Status == NULL) 01243 { 01244 return COMPONENT_ERROR; 01245 } 01246 01247 else 01248 { 01249 return extDriver->Get_Pedometer_Status(ctx, status); 01250 } 01251 } 01252 01253 else 01254 { 01255 return COMPONENT_ERROR; 01256 } 01257 } 01258 01259 01260 /** 01261 * @brief Get the step counter (available only for LSM6DSL sensor) 01262 * @param handle the device handle 01263 * @param step_count the pointer to the step counter 01264 * @retval COMPONENT_OK in case of success 01265 * @retval COMPONENT_ERROR in case of failure 01266 */ 01267 DrvStatusTypeDef BSP_ACCELERO_Get_Step_Count_Ext(void *handle, uint16_t *step_count) 01268 { 01269 01270 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01271 01272 if (ctx == NULL) 01273 { 01274 return COMPONENT_ERROR; 01275 } 01276 01277 if (ctx->pExtVTable == NULL) 01278 { 01279 return COMPONENT_ERROR; 01280 } 01281 01282 if (step_count == NULL) 01283 { 01284 return COMPONENT_ERROR; 01285 } 01286 01287 /* At the moment this feature is only implemented for LSM6DSL */ 01288 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01289 { 01290 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01291 01292 if (extDriver->Get_Step_Count == NULL) 01293 { 01294 return COMPONENT_ERROR; 01295 } 01296 01297 else 01298 { 01299 return extDriver->Get_Step_Count(ctx, step_count); 01300 } 01301 } 01302 01303 else 01304 { 01305 return COMPONENT_ERROR; 01306 } 01307 } 01308 01309 01310 /** 01311 * @brief Reset of the step counter (available only for LSM6DSL sensor) 01312 * @param handle the device handle 01313 * @retval COMPONENT_OK in case of success 01314 * @retval COMPONENT_ERROR in case of failure 01315 */ 01316 DrvStatusTypeDef BSP_ACCELERO_Reset_Step_Counter_Ext(void *handle) 01317 { 01318 01319 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01320 01321 if (ctx == NULL) 01322 { 01323 return COMPONENT_ERROR; 01324 } 01325 01326 if (ctx->pExtVTable == NULL) 01327 { 01328 return COMPONENT_ERROR; 01329 } 01330 01331 /* At the moment this feature is only implemented for LSM6DSL */ 01332 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01333 { 01334 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01335 01336 if (extDriver->Enable_Step_Counter_Reset == NULL || extDriver->Disable_Step_Counter_Reset == NULL) 01337 { 01338 return COMPONENT_ERROR; 01339 } 01340 01341 else 01342 { 01343 if (extDriver->Enable_Step_Counter_Reset(ctx) == COMPONENT_ERROR) 01344 { 01345 return COMPONENT_ERROR; 01346 } 01347 01348 HAL_Delay(10); 01349 01350 if (extDriver->Disable_Step_Counter_Reset(ctx) == COMPONENT_ERROR) 01351 { 01352 return COMPONENT_ERROR; 01353 } 01354 } 01355 } 01356 01357 else 01358 { 01359 return COMPONENT_ERROR; 01360 } 01361 01362 return COMPONENT_OK; 01363 } 01364 01365 /** 01366 * @brief Set the pedometer threshold (available only for LSM6DSL sensor) 01367 * @param handle the device handle 01368 * @param thr the threshold to be set 01369 * @retval COMPONENT_OK in case of success 01370 * @retval COMPONENT_ERROR in case of failure 01371 */ 01372 DrvStatusTypeDef BSP_ACCELERO_Set_Pedometer_Threshold_Ext(void *handle, uint8_t thr) 01373 { 01374 01375 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01376 01377 if (ctx == NULL) 01378 { 01379 return COMPONENT_ERROR; 01380 } 01381 01382 if (ctx->pExtVTable == NULL) 01383 { 01384 return COMPONENT_ERROR; 01385 } 01386 01387 /* At the moment this feature is only implemented for LSM6DSL */ 01388 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01389 { 01390 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01391 01392 if (extDriver->Set_Pedometer_Threshold == NULL) 01393 { 01394 return COMPONENT_ERROR; 01395 } 01396 01397 else 01398 { 01399 return extDriver->Set_Pedometer_Threshold(ctx, thr); 01400 } 01401 } 01402 01403 else 01404 { 01405 return COMPONENT_ERROR; 01406 } 01407 } 01408 01409 01410 01411 /** 01412 * @brief Enable the tilt detection (available only for LSM6DSL sensor) 01413 * @param handle the device handle 01414 * @param int_pin the interrupt pin to be used 01415 * @note This function sets the LSM6DSL accelerometer ODR to 26Hz and the LSM6DSL accelerometer full scale to 2g 01416 * @retval COMPONENT_OK in case of success 01417 * @retval COMPONENT_ERROR in case of failure 01418 */ 01419 DrvStatusTypeDef BSP_ACCELERO_Enable_Tilt_Detection_Ext(void *handle, SensorIntPin_t int_pin) 01420 { 01421 01422 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01423 01424 if (ctx == NULL) 01425 { 01426 return COMPONENT_ERROR; 01427 } 01428 01429 if (ctx->pExtVTable == NULL) 01430 { 01431 return COMPONENT_ERROR; 01432 } 01433 01434 /* At the moment this feature is only implemented for LSM6DSL */ 01435 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01436 { 01437 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01438 01439 if (extDriver->Enable_Tilt_Detection == NULL) 01440 { 01441 return COMPONENT_ERROR; 01442 } 01443 01444 else 01445 { 01446 return extDriver->Enable_Tilt_Detection(ctx, int_pin); 01447 } 01448 } 01449 01450 else 01451 { 01452 return COMPONENT_ERROR; 01453 } 01454 } 01455 01456 01457 01458 /** 01459 * @brief Disable the tilt detection (available only for LSM6DSL sensor) 01460 * @param handle the device handle 01461 * @retval COMPONENT_OK in case of success 01462 * @retval COMPONENT_ERROR in case of failure 01463 */ 01464 DrvStatusTypeDef BSP_ACCELERO_Disable_Tilt_Detection_Ext(void *handle) 01465 { 01466 01467 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01468 01469 if (ctx == NULL) 01470 { 01471 return COMPONENT_ERROR; 01472 } 01473 01474 if (ctx->pExtVTable == NULL) 01475 { 01476 return COMPONENT_ERROR; 01477 } 01478 01479 /* At the moment this feature is only implemented for LSM6DSL */ 01480 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01481 { 01482 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01483 01484 if (extDriver->Disable_Tilt_Detection == NULL) 01485 { 01486 return COMPONENT_ERROR; 01487 } 01488 01489 else 01490 { 01491 return extDriver->Disable_Tilt_Detection(ctx); 01492 } 01493 } 01494 01495 else 01496 { 01497 return COMPONENT_ERROR; 01498 } 01499 } 01500 01501 01502 01503 /** 01504 * @brief Get the tilt detection status (available only for LSM6DSL sensor) 01505 * @param handle the device handle 01506 * @param status the pointer to the tilt detection status: 0 means no tilt detected, 1 means tilt detected 01507 * @note This function is deprecated and has been replaced by BSP_ACCELERO_Get_Event_Status_Ext 01508 * @retval COMPONENT_OK in case of success 01509 * @retval COMPONENT_ERROR in case of failure 01510 */ 01511 DrvStatusTypeDef BSP_ACCELERO_Get_Tilt_Detection_Status_Ext(void *handle, uint8_t *status) 01512 { 01513 01514 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01515 01516 if (ctx == NULL) 01517 { 01518 return COMPONENT_ERROR; 01519 } 01520 01521 if (ctx->pExtVTable == NULL) 01522 { 01523 return COMPONENT_ERROR; 01524 } 01525 01526 if (status == NULL) 01527 { 01528 return COMPONENT_ERROR; 01529 } 01530 01531 /* At the moment this feature is only implemented for LSM6DSL */ 01532 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01533 { 01534 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01535 01536 if (extDriver->Get_Tilt_Detection_Status == NULL) 01537 { 01538 return COMPONENT_ERROR; 01539 } 01540 01541 else 01542 { 01543 return extDriver->Get_Tilt_Detection_Status(ctx, status); 01544 } 01545 } 01546 01547 else 01548 { 01549 return COMPONENT_ERROR; 01550 } 01551 } 01552 01553 01554 01555 /** 01556 * @brief Enable the wake up detection (available only for LSM6DSL sensor) 01557 * @param handle the device handle 01558 * @param int_pin the interrupt pin to be used 01559 * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g 01560 * @retval COMPONENT_OK in case of success 01561 * @retval COMPONENT_ERROR in case of failure 01562 */ 01563 DrvStatusTypeDef BSP_ACCELERO_Enable_Wake_Up_Detection_Ext(void *handle, SensorIntPin_t int_pin) 01564 { 01565 01566 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01567 01568 if (ctx == NULL) 01569 { 01570 return COMPONENT_ERROR; 01571 } 01572 01573 if (ctx->pExtVTable == NULL) 01574 { 01575 return COMPONENT_ERROR; 01576 } 01577 01578 /* At the moment this feature is only implemented for LSM6DSL */ 01579 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01580 { 01581 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01582 01583 if (extDriver->Enable_Wake_Up_Detection == NULL) 01584 { 01585 return COMPONENT_ERROR; 01586 } 01587 01588 else 01589 { 01590 return extDriver->Enable_Wake_Up_Detection(ctx, int_pin); 01591 } 01592 } 01593 01594 else 01595 { 01596 return COMPONENT_ERROR; 01597 } 01598 } 01599 01600 01601 01602 /** 01603 * @brief Disable the wake up detection (available only for LSM6DSL sensor) 01604 * @param handle the device handle 01605 * @retval COMPONENT_OK in case of success 01606 * @retval COMPONENT_ERROR in case of failure 01607 */ 01608 DrvStatusTypeDef BSP_ACCELERO_Disable_Wake_Up_Detection_Ext(void *handle) 01609 { 01610 01611 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01612 01613 if (ctx == NULL) 01614 { 01615 return COMPONENT_ERROR; 01616 } 01617 01618 if (ctx->pExtVTable == NULL) 01619 { 01620 return COMPONENT_ERROR; 01621 } 01622 01623 /* At the moment this feature is only implemented for LSM6DSL */ 01624 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01625 { 01626 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01627 01628 if (extDriver->Disable_Wake_Up_Detection == NULL) 01629 { 01630 return COMPONENT_ERROR; 01631 } 01632 01633 else 01634 { 01635 return extDriver->Disable_Wake_Up_Detection(ctx); 01636 } 01637 } 01638 01639 else 01640 { 01641 return COMPONENT_ERROR; 01642 } 01643 } 01644 01645 01646 01647 /** 01648 * @brief Get the status of the wake up detection (available only for LSM6DSL sensor) 01649 * @param handle the device handle 01650 * @param status the pointer to the status of the wake up detection: 0 means no detection, 1 means detection happened 01651 * @note This function is deprecated and has been replaced by BSP_ACCELERO_Get_Event_Status_Ext 01652 * @retval COMPONENT_OK in case of success 01653 * @retval COMPONENT_ERROR in case of failure 01654 */ 01655 DrvStatusTypeDef BSP_ACCELERO_Get_Wake_Up_Detection_Status_Ext(void *handle, uint8_t *status) 01656 { 01657 01658 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01659 01660 if (ctx == NULL) 01661 { 01662 return COMPONENT_ERROR; 01663 } 01664 01665 if (ctx->pExtVTable == NULL) 01666 { 01667 return COMPONENT_ERROR; 01668 } 01669 01670 if (status == NULL) 01671 { 01672 return COMPONENT_ERROR; 01673 } 01674 01675 /* At the moment this feature is only implemented for LSM6DSL */ 01676 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01677 { 01678 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01679 01680 if (extDriver->Get_Wake_Up_Detection_Status == NULL) 01681 { 01682 return COMPONENT_ERROR; 01683 } 01684 01685 else 01686 { 01687 return extDriver->Get_Wake_Up_Detection_Status(ctx, status); 01688 } 01689 } 01690 01691 else 01692 { 01693 return COMPONENT_ERROR; 01694 } 01695 } 01696 01697 01698 01699 /** 01700 * @brief Set the wake up threshold (available only for LSM6DSL sensor) 01701 * @param handle the device handle 01702 * @param thr the threshold to be set 01703 * @retval COMPONENT_OK in case of success 01704 * @retval COMPONENT_ERROR in case of failure 01705 */ 01706 DrvStatusTypeDef BSP_ACCELERO_Set_Wake_Up_Threshold_Ext(void *handle, uint8_t thr) 01707 { 01708 01709 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01710 01711 if (ctx == NULL) 01712 { 01713 return COMPONENT_ERROR; 01714 } 01715 01716 if (ctx->pExtVTable == NULL) 01717 { 01718 return COMPONENT_ERROR; 01719 } 01720 01721 /* At the moment this feature is only implemented for LSM6DSL */ 01722 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01723 { 01724 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01725 01726 if (extDriver->Set_Wake_Up_Threshold == NULL) 01727 { 01728 return COMPONENT_ERROR; 01729 } 01730 01731 else 01732 { 01733 return extDriver->Set_Wake_Up_Threshold(ctx, thr); 01734 } 01735 } 01736 01737 else 01738 { 01739 return COMPONENT_ERROR; 01740 } 01741 } 01742 01743 01744 01745 /** 01746 * @brief Enable the single tap detection (available only for LSM6DSL sensor) 01747 * @param handle the device handle 01748 * @param int_pin the interrupt pin to be used 01749 * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g 01750 * @retval COMPONENT_OK in case of success 01751 * @retval COMPONENT_ERROR in case of failure 01752 */ 01753 DrvStatusTypeDef BSP_ACCELERO_Enable_Single_Tap_Detection_Ext(void *handle, SensorIntPin_t int_pin) 01754 { 01755 01756 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01757 01758 if (ctx == NULL) 01759 { 01760 return COMPONENT_ERROR; 01761 } 01762 01763 if (ctx->pExtVTable == NULL) 01764 { 01765 return COMPONENT_ERROR; 01766 } 01767 01768 /* At the moment this feature is only implemented for LSM6DSL */ 01769 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01770 { 01771 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01772 01773 if (extDriver->Enable_Single_Tap_Detection == NULL) 01774 { 01775 return COMPONENT_ERROR; 01776 } 01777 01778 else 01779 { 01780 return extDriver->Enable_Single_Tap_Detection(ctx, int_pin); 01781 } 01782 } 01783 01784 else 01785 { 01786 return COMPONENT_ERROR; 01787 } 01788 } 01789 01790 01791 01792 /** 01793 * @brief Disable the single tap detection (available only for LSM6DSL sensor) 01794 * @param handle the device handle 01795 * @retval COMPONENT_OK in case of success 01796 * @retval COMPONENT_ERROR in case of failure 01797 */ 01798 DrvStatusTypeDef BSP_ACCELERO_Disable_Single_Tap_Detection_Ext(void *handle) 01799 { 01800 01801 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01802 01803 if (ctx == NULL) 01804 { 01805 return COMPONENT_ERROR; 01806 } 01807 01808 if (ctx->pExtVTable == NULL) 01809 { 01810 return COMPONENT_ERROR; 01811 } 01812 01813 /* At the moment this feature is only implemented for LSM6DSL */ 01814 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01815 { 01816 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01817 01818 if (extDriver->Disable_Single_Tap_Detection == NULL) 01819 { 01820 return COMPONENT_ERROR; 01821 } 01822 01823 else 01824 { 01825 return extDriver->Disable_Single_Tap_Detection(ctx); 01826 } 01827 } 01828 01829 else 01830 { 01831 return COMPONENT_ERROR; 01832 } 01833 } 01834 01835 01836 01837 /** 01838 * @brief Get the single tap detection status (available only for LSM6DSL sensor) 01839 * @param handle the device handle 01840 * @param status the pointer to the single tap detection status: 0 means no single tap detected, 1 means single tap detected 01841 * @note This function is deprecated and has been replaced by BSP_ACCELERO_Get_Event_Status_Ext 01842 * @retval COMPONENT_OK in case of success 01843 * @retval COMPONENT_ERROR in case of failure 01844 */ 01845 DrvStatusTypeDef BSP_ACCELERO_Get_Single_Tap_Detection_Status_Ext(void *handle, uint8_t *status) 01846 { 01847 01848 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01849 01850 if (ctx == NULL) 01851 { 01852 return COMPONENT_ERROR; 01853 } 01854 01855 if (ctx->pExtVTable == NULL) 01856 { 01857 return COMPONENT_ERROR; 01858 } 01859 01860 if (status == NULL) 01861 { 01862 return COMPONENT_ERROR; 01863 } 01864 01865 /* At the moment this feature is only implemented for LSM6DSL */ 01866 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01867 { 01868 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01869 01870 if (extDriver->Get_Single_Tap_Detection_Status == NULL) 01871 { 01872 return COMPONENT_ERROR; 01873 } 01874 01875 else 01876 { 01877 return extDriver->Get_Single_Tap_Detection_Status(ctx, status); 01878 } 01879 } 01880 01881 else 01882 { 01883 return COMPONENT_ERROR; 01884 } 01885 } 01886 01887 01888 01889 /** 01890 * @brief Enable the double tap detection (available only for LSM6DSL sensor) 01891 * @param handle the device handle 01892 * @param int_pin the interrupt pin to be used 01893 * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g 01894 * @retval COMPONENT_OK in case of success 01895 * @retval COMPONENT_ERROR in case of failure 01896 */ 01897 DrvStatusTypeDef BSP_ACCELERO_Enable_Double_Tap_Detection_Ext(void *handle, SensorIntPin_t int_pin) 01898 { 01899 01900 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01901 01902 if (ctx == NULL) 01903 { 01904 return COMPONENT_ERROR; 01905 } 01906 01907 if (ctx->pExtVTable == NULL) 01908 { 01909 return COMPONENT_ERROR; 01910 } 01911 01912 /* At the moment this feature is only implemented for LSM6DSL */ 01913 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01914 { 01915 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01916 01917 if (extDriver->Enable_Double_Tap_Detection == NULL) 01918 { 01919 return COMPONENT_ERROR; 01920 } 01921 01922 else 01923 { 01924 return extDriver->Enable_Double_Tap_Detection(ctx, int_pin); 01925 } 01926 } 01927 01928 else 01929 { 01930 return COMPONENT_ERROR; 01931 } 01932 } 01933 01934 01935 01936 /** 01937 * @brief Disable the double tap detection (available only for LSM6DSL sensor) 01938 * @param handle the device handle 01939 * @retval COMPONENT_OK in case of success 01940 * @retval COMPONENT_ERROR in case of failure 01941 */ 01942 DrvStatusTypeDef BSP_ACCELERO_Disable_Double_Tap_Detection_Ext(void *handle) 01943 { 01944 01945 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01946 01947 if (ctx == NULL) 01948 { 01949 return COMPONENT_ERROR; 01950 } 01951 01952 if (ctx->pExtVTable == NULL) 01953 { 01954 return COMPONENT_ERROR; 01955 } 01956 01957 /* At the moment this feature is only implemented for LSM6DSL */ 01958 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 01959 { 01960 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 01961 01962 if (extDriver->Disable_Double_Tap_Detection == NULL) 01963 { 01964 return COMPONENT_ERROR; 01965 } 01966 01967 else 01968 { 01969 return extDriver->Disable_Double_Tap_Detection(ctx); 01970 } 01971 } 01972 01973 else 01974 { 01975 return COMPONENT_ERROR; 01976 } 01977 } 01978 01979 01980 01981 /** 01982 * @brief Get the double tap detection status (available only for LSM6DSL sensor) 01983 * @param handle the device handle 01984 * @param status the pointer to the double tap detection status: 0 means no double tap detected, 1 means double tap detected 01985 * @note This function is deprecated and has been replaced by BSP_ACCELERO_Get_Event_Status_Ext 01986 * @retval COMPONENT_OK in case of success 01987 * @retval COMPONENT_ERROR in case of failure 01988 */ 01989 DrvStatusTypeDef BSP_ACCELERO_Get_Double_Tap_Detection_Status_Ext(void *handle, uint8_t *status) 01990 { 01991 01992 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 01993 01994 if (ctx == NULL) 01995 { 01996 return COMPONENT_ERROR; 01997 } 01998 01999 if (ctx->pExtVTable == NULL) 02000 { 02001 return COMPONENT_ERROR; 02002 } 02003 02004 if (status == NULL) 02005 { 02006 return COMPONENT_ERROR; 02007 } 02008 02009 /* At the moment this feature is only implemented for LSM6DSL */ 02010 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02011 { 02012 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02013 02014 if (extDriver->Get_Double_Tap_Detection_Status == NULL) 02015 { 02016 return COMPONENT_ERROR; 02017 } 02018 02019 else 02020 { 02021 return extDriver->Get_Double_Tap_Detection_Status(ctx, status); 02022 } 02023 } 02024 02025 else 02026 { 02027 return COMPONENT_ERROR; 02028 } 02029 } 02030 02031 02032 02033 /** 02034 * @brief Set the tap threshold (available only for LSM6DSL sensor) 02035 * @param handle the device handle 02036 * @param thr the threshold to be set 02037 * @retval COMPONENT_OK in case of success 02038 * @retval COMPONENT_ERROR in case of failure 02039 */ 02040 DrvStatusTypeDef BSP_ACCELERO_Set_Tap_Threshold_Ext(void *handle, uint8_t thr) 02041 { 02042 02043 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02044 02045 if (ctx == NULL) 02046 { 02047 return COMPONENT_ERROR; 02048 } 02049 02050 if (ctx->pExtVTable == NULL) 02051 { 02052 return COMPONENT_ERROR; 02053 } 02054 02055 /* At the moment this feature is only implemented for LSM6DSL */ 02056 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02057 { 02058 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02059 02060 if (extDriver->Set_Tap_Threshold == NULL) 02061 { 02062 return COMPONENT_ERROR; 02063 } 02064 02065 else 02066 { 02067 return extDriver->Set_Tap_Threshold(ctx, thr); 02068 } 02069 } 02070 02071 else 02072 { 02073 return COMPONENT_ERROR; 02074 } 02075 } 02076 02077 02078 02079 /** 02080 * @brief Set the tap shock time window (available only for LSM6DSL sensor) 02081 * @param handle the device handle 02082 * @param time the shock time window to be set 02083 * @retval COMPONENT_OK in case of success 02084 * @retval COMPONENT_ERROR in case of failure 02085 */ 02086 DrvStatusTypeDef BSP_ACCELERO_Set_Tap_Shock_Time_Ext(void *handle, uint8_t time) 02087 { 02088 02089 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02090 02091 if (ctx == NULL) 02092 { 02093 return COMPONENT_ERROR; 02094 } 02095 02096 if (ctx->pExtVTable == NULL) 02097 { 02098 return COMPONENT_ERROR; 02099 } 02100 02101 /* At the moment this feature is only implemented for LSM6DSL */ 02102 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02103 { 02104 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02105 02106 if (extDriver->Set_Tap_Shock_Time == NULL) 02107 { 02108 return COMPONENT_ERROR; 02109 } 02110 02111 else 02112 { 02113 return extDriver->Set_Tap_Shock_Time(ctx, time); 02114 } 02115 } 02116 02117 else 02118 { 02119 return COMPONENT_ERROR; 02120 } 02121 } 02122 02123 02124 02125 /** 02126 * @brief Set the tap quiet time window (available only for LSM6DSL sensor) 02127 * @param handle the device handle 02128 * @param time the quiet time window to be set 02129 * @retval COMPONENT_OK in case of success 02130 * @retval COMPONENT_ERROR in case of failure 02131 */ 02132 DrvStatusTypeDef BSP_ACCELERO_Set_Tap_Quiet_Time_Ext(void *handle, uint8_t time) 02133 { 02134 02135 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02136 02137 if (ctx == NULL) 02138 { 02139 return COMPONENT_ERROR; 02140 } 02141 02142 if (ctx->pExtVTable == NULL) 02143 { 02144 return COMPONENT_ERROR; 02145 } 02146 02147 /* At the moment this feature is only implemented for LSM6DSL */ 02148 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02149 { 02150 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02151 02152 if (extDriver->Set_Tap_Quiet_Time == NULL) 02153 { 02154 return COMPONENT_ERROR; 02155 } 02156 02157 else 02158 { 02159 return extDriver->Set_Tap_Quiet_Time(ctx, time); 02160 } 02161 } 02162 02163 else 02164 { 02165 return COMPONENT_ERROR; 02166 } 02167 } 02168 02169 02170 02171 /** 02172 * @brief Set the tap duration of the time window (available only for LSM6DSL sensor) 02173 * @param handle the device handle 02174 * @param time the duration of the time window to be set 02175 * @retval COMPONENT_OK in case of success 02176 * @retval COMPONENT_ERROR in case of failure 02177 */ 02178 DrvStatusTypeDef BSP_ACCELERO_Set_Tap_Duration_Time_Ext(void *handle, uint8_t time) 02179 { 02180 02181 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02182 02183 if (ctx == NULL) 02184 { 02185 return COMPONENT_ERROR; 02186 } 02187 02188 if (ctx->pExtVTable == NULL) 02189 { 02190 return COMPONENT_ERROR; 02191 } 02192 02193 /* At the moment this feature is only implemented for LSM6DSL */ 02194 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02195 { 02196 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02197 02198 if (extDriver->Set_Tap_Duration_Time == NULL) 02199 { 02200 return COMPONENT_ERROR; 02201 } 02202 02203 else 02204 { 02205 return extDriver->Set_Tap_Duration_Time(ctx, time); 02206 } 02207 } 02208 02209 else 02210 { 02211 return COMPONENT_ERROR; 02212 } 02213 } 02214 02215 02216 02217 /** 02218 * @brief Enable the 6D orientation detection (available only for LSM6DSL sensor) 02219 * @param handle the device handle 02220 * @param int_pin the interrupt pin to be used 02221 * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g 02222 * @retval COMPONENT_OK in case of success 02223 * @retval COMPONENT_ERROR in case of failure 02224 */ 02225 DrvStatusTypeDef BSP_ACCELERO_Enable_6D_Orientation_Ext(void *handle, SensorIntPin_t int_pin) 02226 { 02227 02228 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02229 02230 if (ctx == NULL) 02231 { 02232 return COMPONENT_ERROR; 02233 } 02234 02235 if (ctx->pExtVTable == NULL) 02236 { 02237 return COMPONENT_ERROR; 02238 } 02239 02240 /* At the moment this feature is only implemented for LSM6DSL */ 02241 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02242 { 02243 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02244 02245 if (extDriver->Enable_6D_Orientation == NULL) 02246 { 02247 return COMPONENT_ERROR; 02248 } 02249 02250 else 02251 { 02252 return extDriver->Enable_6D_Orientation(ctx, int_pin); 02253 } 02254 } 02255 02256 else 02257 { 02258 return COMPONENT_ERROR; 02259 } 02260 } 02261 02262 02263 02264 /** 02265 * @brief Disable the 6D orientation detection (available only for LSM6DSL sensor) 02266 * @param handle the device handle 02267 * @retval COMPONENT_OK in case of success 02268 * @retval COMPONENT_ERROR in case of failure 02269 */ 02270 DrvStatusTypeDef BSP_ACCELERO_Disable_6D_Orientation_Ext(void *handle) 02271 { 02272 02273 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02274 02275 if (ctx == NULL) 02276 { 02277 return COMPONENT_ERROR; 02278 } 02279 02280 if (ctx->pExtVTable == NULL) 02281 { 02282 return COMPONENT_ERROR; 02283 } 02284 02285 /* At the moment this feature is only implemented for LSM6DSL */ 02286 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02287 { 02288 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02289 02290 if (extDriver->Disable_6D_Orientation == NULL) 02291 { 02292 return COMPONENT_ERROR; 02293 } 02294 02295 else 02296 { 02297 return extDriver->Disable_6D_Orientation(ctx); 02298 } 02299 } 02300 02301 else 02302 { 02303 return COMPONENT_ERROR; 02304 } 02305 } 02306 02307 02308 02309 /** 02310 * @brief Get the status of the 6D orientation detection (available only for LSM6DSL sensor) 02311 * @param handle the device handle 02312 * @param status the pointer to the status of the 6D orientation detection: 0 means no detection, 1 means detection happened 02313 * @note This function is deprecated and has been replaced by BSP_ACCELERO_Get_Event_Status_Ext 02314 * @retval COMPONENT_OK in case of success 02315 * @retval COMPONENT_ERROR in case of failure 02316 */ 02317 DrvStatusTypeDef BSP_ACCELERO_Get_6D_Orientation_Status_Ext(void *handle, uint8_t *status) 02318 { 02319 02320 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02321 02322 if (ctx == NULL) 02323 { 02324 return COMPONENT_ERROR; 02325 } 02326 02327 if (ctx->pExtVTable == NULL) 02328 { 02329 return COMPONENT_ERROR; 02330 } 02331 02332 if (status == NULL) 02333 { 02334 return COMPONENT_ERROR; 02335 } 02336 02337 /* At the moment this feature is only implemented for LSM6DSL */ 02338 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02339 { 02340 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02341 02342 if (extDriver->Get_6D_Orientation_Status == NULL) 02343 { 02344 return COMPONENT_ERROR; 02345 } 02346 02347 else 02348 { 02349 return extDriver->Get_6D_Orientation_Status(ctx, status); 02350 } 02351 } 02352 02353 else 02354 { 02355 return COMPONENT_ERROR; 02356 } 02357 } 02358 02359 /** 02360 * @brief Get the 6D orientation XL axis (available only for LSM6DSL sensor) 02361 * @param handle the device handle 02362 * @param xl the pointer to the 6D orientation XL axis 02363 * @retval COMPONENT_OK in case of success 02364 * @retval COMPONENT_ERROR in case of failure 02365 */ 02366 DrvStatusTypeDef BSP_ACCELERO_Get_6D_Orientation_XL_Ext(void *handle, uint8_t *xl) 02367 { 02368 02369 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02370 02371 if (ctx == NULL) 02372 { 02373 return COMPONENT_ERROR; 02374 } 02375 02376 if (ctx->pExtVTable == NULL) 02377 { 02378 return COMPONENT_ERROR; 02379 } 02380 02381 if (xl == NULL) 02382 { 02383 return COMPONENT_ERROR; 02384 } 02385 02386 /* At the moment this feature is only implemented for LSM6DSL */ 02387 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02388 { 02389 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02390 02391 if (extDriver->Get_6D_Orientation_XL == NULL) 02392 { 02393 return COMPONENT_ERROR; 02394 } 02395 02396 else 02397 { 02398 return extDriver->Get_6D_Orientation_XL(ctx, xl); 02399 } 02400 } 02401 02402 else 02403 { 02404 return COMPONENT_ERROR; 02405 } 02406 } 02407 02408 02409 02410 /** 02411 * @brief Get the 6D orientation XH axis (available only for LSM6DSL sensor) 02412 * @param handle the device handle 02413 * @param xh the pointer to the 6D orientation XH axis 02414 * @retval COMPONENT_OK in case of success 02415 * @retval COMPONENT_ERROR in case of failure 02416 */ 02417 DrvStatusTypeDef BSP_ACCELERO_Get_6D_Orientation_XH_Ext(void *handle, uint8_t *xh) 02418 { 02419 02420 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02421 02422 if (ctx == NULL) 02423 { 02424 return COMPONENT_ERROR; 02425 } 02426 02427 if (ctx->pExtVTable == NULL) 02428 { 02429 return COMPONENT_ERROR; 02430 } 02431 02432 if (xh == NULL) 02433 { 02434 return COMPONENT_ERROR; 02435 } 02436 02437 /* At the moment this feature is only implemented for LSM6DSL */ 02438 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02439 { 02440 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02441 02442 if (extDriver->Get_6D_Orientation_XH == NULL) 02443 { 02444 return COMPONENT_ERROR; 02445 } 02446 02447 else 02448 { 02449 return extDriver->Get_6D_Orientation_XH(ctx, xh); 02450 } 02451 } 02452 02453 else 02454 { 02455 return COMPONENT_ERROR; 02456 } 02457 } 02458 02459 02460 02461 /** 02462 * @brief Get the 6D orientation YL axis (available only for LSM6DSL sensor) 02463 * @param handle the device handle 02464 * @param yl the pointer to the 6D orientation YL axis 02465 * @retval COMPONENT_OK in case of success 02466 * @retval COMPONENT_ERROR in case of failure 02467 */ 02468 DrvStatusTypeDef BSP_ACCELERO_Get_6D_Orientation_YL_Ext(void *handle, uint8_t *yl) 02469 { 02470 02471 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02472 02473 if (ctx == NULL) 02474 { 02475 return COMPONENT_ERROR; 02476 } 02477 02478 if (ctx->pExtVTable == NULL) 02479 { 02480 return COMPONENT_ERROR; 02481 } 02482 02483 if (yl == NULL) 02484 { 02485 return COMPONENT_ERROR; 02486 } 02487 02488 /* At the moment this feature is only implemented for LSM6DSL */ 02489 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02490 { 02491 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02492 02493 if (extDriver->Get_6D_Orientation_YL == NULL) 02494 { 02495 return COMPONENT_ERROR; 02496 } 02497 02498 else 02499 { 02500 return extDriver->Get_6D_Orientation_YL(ctx, yl); 02501 } 02502 } 02503 02504 else 02505 { 02506 return COMPONENT_ERROR; 02507 } 02508 } 02509 02510 02511 02512 /** 02513 * @brief Get the 6D orientation YH axis (available only for LSM6DSL sensor) 02514 * @param handle the device handle 02515 * @param yh the pointer to the 6D orientation YH axis 02516 * @retval COMPONENT_OK in case of success 02517 * @retval COMPONENT_ERROR in case of failure 02518 */ 02519 DrvStatusTypeDef BSP_ACCELERO_Get_6D_Orientation_YH_Ext(void *handle, uint8_t *yh) 02520 { 02521 02522 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02523 02524 if (ctx == NULL) 02525 { 02526 return COMPONENT_ERROR; 02527 } 02528 02529 if (ctx->pExtVTable == NULL) 02530 { 02531 return COMPONENT_ERROR; 02532 } 02533 02534 if (yh == NULL) 02535 { 02536 return COMPONENT_ERROR; 02537 } 02538 02539 /* At the moment this feature is only implemented for LSM6DSL */ 02540 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02541 { 02542 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02543 02544 if (extDriver->Get_6D_Orientation_YH == NULL) 02545 { 02546 return COMPONENT_ERROR; 02547 } 02548 02549 else 02550 { 02551 return extDriver->Get_6D_Orientation_YH(ctx, yh); 02552 } 02553 } 02554 02555 else 02556 { 02557 return COMPONENT_ERROR; 02558 } 02559 } 02560 02561 02562 02563 /** 02564 * @brief Get the 6D orientation ZL axis (available only for LSM6DSL sensor) 02565 * @param handle the device handle 02566 * @param zl the pointer to the 6D orientation ZL axis 02567 * @retval COMPONENT_OK in case of success 02568 * @retval COMPONENT_ERROR in case of failure 02569 */ 02570 DrvStatusTypeDef BSP_ACCELERO_Get_6D_Orientation_ZL_Ext(void *handle, uint8_t *zl) 02571 { 02572 02573 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02574 02575 if (ctx == NULL) 02576 { 02577 return COMPONENT_ERROR; 02578 } 02579 02580 if (ctx->pExtVTable == NULL) 02581 { 02582 return COMPONENT_ERROR; 02583 } 02584 02585 if (zl == NULL) 02586 { 02587 return COMPONENT_ERROR; 02588 } 02589 02590 /* At the moment this feature is only implemented for LSM6DSL */ 02591 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02592 { 02593 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02594 02595 if (extDriver->Get_6D_Orientation_ZL == NULL) 02596 { 02597 return COMPONENT_ERROR; 02598 } 02599 02600 else 02601 { 02602 return extDriver->Get_6D_Orientation_ZL(ctx, zl); 02603 } 02604 } 02605 02606 else 02607 { 02608 return COMPONENT_ERROR; 02609 } 02610 } 02611 02612 02613 02614 /** 02615 * @brief Get the 6D orientation ZH axis (available only for LSM6DSL sensor) 02616 * @param handle the device handle 02617 * @param zh the pointer to the 6D orientation ZH axis 02618 * @retval COMPONENT_OK in case of success 02619 * @retval COMPONENT_ERROR in case of failure 02620 */ 02621 DrvStatusTypeDef BSP_ACCELERO_Get_6D_Orientation_ZH_Ext(void *handle, uint8_t *zh) 02622 { 02623 02624 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02625 02626 if (ctx == NULL) 02627 { 02628 return COMPONENT_ERROR; 02629 } 02630 02631 if (ctx->pExtVTable == NULL) 02632 { 02633 return COMPONENT_ERROR; 02634 } 02635 02636 if (zh == NULL) 02637 { 02638 return COMPONENT_ERROR; 02639 } 02640 02641 /* At the moment this feature is only implemented for LSM6DSL */ 02642 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02643 { 02644 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02645 02646 if (extDriver->Get_6D_Orientation_ZH == NULL) 02647 { 02648 return COMPONENT_ERROR; 02649 } 02650 02651 else 02652 { 02653 return extDriver->Get_6D_Orientation_ZH(ctx, zh); 02654 } 02655 } 02656 02657 else 02658 { 02659 return COMPONENT_ERROR; 02660 } 02661 } 02662 02663 02664 /** 02665 * @brief Get the status of all hardware events (available only for LSM6DSL sensor) 02666 * @param handle the device handle 02667 * @param status the pointer to the status of all hardware events 02668 * @retval COMPONENT_OK in case of success 02669 * @retval COMPONENT_ERROR in case of failure 02670 */ 02671 DrvStatusTypeDef BSP_ACCELERO_Get_Event_Status_Ext(void *handle, ACCELERO_Event_Status_t *status) 02672 { 02673 02674 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02675 02676 if (ctx == NULL) 02677 { 02678 return COMPONENT_ERROR; 02679 } 02680 02681 if (ctx->pExtVTable == NULL) 02682 { 02683 return COMPONENT_ERROR; 02684 } 02685 02686 if (status == NULL) 02687 { 02688 return COMPONENT_ERROR; 02689 } 02690 02691 /* At the moment this feature is only implemented for LSM6DSL */ 02692 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02693 { 02694 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02695 02696 if (extDriver->Get_Event_Status == NULL) 02697 { 02698 return COMPONENT_ERROR; 02699 } 02700 02701 else 02702 { 02703 return extDriver->Get_Event_Status(ctx, status); 02704 } 02705 } 02706 02707 else 02708 { 02709 return COMPONENT_ERROR; 02710 } 02711 } 02712 02713 02714 /** 02715 * @brief Set FIFO output data rate (available only for LSM6DSL sensor) 02716 * @param handle the device handle 02717 * @param odr the output data rate 02718 * @retval COMPONENT_OK in case of success 02719 * @retval COMPONENT_ERROR in case of failure 02720 */ 02721 DrvStatusTypeDef BSP_ACCELERO_FIFO_Set_ODR_Value_Ext(void *handle, float odr) 02722 { 02723 02724 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02725 02726 if (ctx == NULL) 02727 { 02728 return COMPONENT_ERROR; 02729 } 02730 02731 if (ctx->pExtVTable == NULL) 02732 { 02733 return COMPONENT_ERROR; 02734 } 02735 02736 /* At the moment this feature is only implemented for LSM6DSL */ 02737 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02738 { 02739 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02740 02741 if (extDriver->FIFO_Set_ODR_Value == NULL) 02742 { 02743 return COMPONENT_ERROR; 02744 } 02745 02746 else 02747 { 02748 return extDriver->FIFO_Set_ODR_Value(handle, odr); 02749 } 02750 } 02751 02752 else 02753 { 02754 return COMPONENT_ERROR; 02755 } 02756 } 02757 02758 02759 /** 02760 * @brief Get FIFO full status (available only for LSM6DSL sensor) 02761 * @param handle the device handle 02762 * @param *status FIFO full status 02763 * @retval COMPONENT_OK in case of success 02764 * @retval COMPONENT_ERROR in case of failure 02765 */ 02766 DrvStatusTypeDef BSP_ACCELERO_FIFO_Get_Full_Status_Ext(void *handle, uint8_t *status) 02767 { 02768 02769 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02770 02771 if (ctx == NULL) 02772 { 02773 return COMPONENT_ERROR; 02774 } 02775 02776 if (ctx->pExtVTable == NULL) 02777 { 02778 return COMPONENT_ERROR; 02779 } 02780 02781 if (status == NULL) 02782 { 02783 return COMPONENT_ERROR; 02784 } 02785 02786 /* At the moment this feature is only implemented for LSM6DSL */ 02787 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02788 { 02789 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02790 02791 if (extDriver->FIFO_Get_Full_Status == NULL) 02792 { 02793 return COMPONENT_ERROR; 02794 } 02795 02796 else 02797 { 02798 return extDriver->FIFO_Get_Full_Status(handle, status); 02799 } 02800 } 02801 02802 else 02803 { 02804 return COMPONENT_ERROR; 02805 } 02806 } 02807 02808 02809 /** 02810 * @brief Get FIFO empty status (available only for LSM6DSL sensor) 02811 * @param handle the device handle 02812 * @param *status FIFO empty status 02813 * @retval COMPONENT_OK in case of success 02814 * @retval COMPONENT_ERROR in case of failure 02815 */ 02816 DrvStatusTypeDef BSP_ACCELERO_FIFO_Get_Empty_Status_Ext(void *handle, uint8_t *status) 02817 { 02818 02819 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02820 02821 if (ctx == NULL) 02822 { 02823 return COMPONENT_ERROR; 02824 } 02825 02826 if (ctx->pExtVTable == NULL) 02827 { 02828 return COMPONENT_ERROR; 02829 } 02830 02831 if (status == NULL) 02832 { 02833 return COMPONENT_ERROR; 02834 } 02835 02836 /* At the moment this feature is only implemented for LSM6DSL */ 02837 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02838 { 02839 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02840 02841 if (extDriver->FIFO_Get_Empty_Status == NULL) 02842 { 02843 return COMPONENT_ERROR; 02844 } 02845 02846 else 02847 { 02848 return extDriver->FIFO_Get_Empty_Status(handle, status); 02849 } 02850 } 02851 02852 else 02853 { 02854 return COMPONENT_ERROR; 02855 } 02856 } 02857 #endif /* if 0 */ 02858 02859 02860 /** 02861 * @brief Get FIFO_OVR bit status (available only for LSM6DSL sensor) 02862 * @param handle the device handle 02863 * @param *status FIFO_OVR bit status 02864 * @retval COMPONENT_OK in case of success 02865 * @retval COMPONENT_ERROR in case of failure 02866 */ 02867 DrvStatusTypeDef BSP_ACCELERO_FIFO_Get_Overrun_Status_Ext(void *handle, uint8_t *status) 02868 { 02869 02870 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02871 void *extDriver = ctx->pExtVTable; 02872 02873 if (ctx == NULL) 02874 { 02875 return COMPONENT_ERROR; 02876 } 02877 02878 if (ctx->pExtVTable == NULL) 02879 { 02880 return COMPONENT_ERROR; 02881 } 02882 02883 if (status == NULL) 02884 { 02885 return COMPONENT_ERROR; 02886 } 02887 02888 #if 0 02889 /* At the moment this feature is only implemented for LSM6DSL and LIS2DH12 */ 02890 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02891 { 02892 if (((LSM6DSL_X_ExtDrv_t *)extDriver)->FIFO_Get_Overrun_Status == NULL) 02893 { 02894 return COMPONENT_ERROR; 02895 } 02896 02897 else 02898 { 02899 return ((LSM6DSL_X_ExtDrv_t *)extDriver)->FIFO_Get_Overrun_Status(handle, status); 02900 } 02901 } 02902 02903 else 02904 #endif /* if 0 */ 02905 if (ctx->who_am_i == LIS2DH12_WHO_AM_I) 02906 { 02907 if (((LIS2DH12_ExtDrv_t *)extDriver)->FIFO_Get_Overrun_Status == NULL) 02908 { 02909 return COMPONENT_ERROR; 02910 } 02911 02912 else 02913 { 02914 return ((LIS2DH12_ExtDrv_t *)extDriver)->FIFO_Get_Overrun_Status(handle, status); 02915 } 02916 } 02917 02918 else 02919 { 02920 return COMPONENT_ERROR; 02921 } 02922 } 02923 02924 02925 #if 0 02926 /** 02927 * @brief Get FIFO pattern (available only for LSM6DSL sensor) 02928 * @param handle the device handle 02929 * @param *pattern FIFO pattern 02930 * @retval COMPONENT_OK in case of success 02931 * @retval COMPONENT_ERROR in case of failure 02932 */ 02933 DrvStatusTypeDef BSP_ACCELERO_FIFO_Get_Pattern_Ext(void *handle, uint16_t *pattern) 02934 { 02935 02936 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02937 02938 if (ctx == NULL) 02939 { 02940 return COMPONENT_ERROR; 02941 } 02942 02943 if (ctx->pExtVTable == NULL) 02944 { 02945 return COMPONENT_ERROR; 02946 } 02947 02948 if (pattern == NULL) 02949 { 02950 return COMPONENT_ERROR; 02951 } 02952 02953 /* At the moment this feature is only implemented for LSM6DSL */ 02954 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 02955 { 02956 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 02957 02958 if (extDriver->FIFO_Get_Pattern == NULL) 02959 { 02960 return COMPONENT_ERROR; 02961 } 02962 02963 else 02964 { 02965 return extDriver->FIFO_Get_Pattern(handle, pattern); 02966 } 02967 } 02968 02969 else 02970 { 02971 return COMPONENT_ERROR; 02972 } 02973 } 02974 02975 02976 02977 /** 02978 * @brief Get FIFO data (available only for LSM6DSL sensor) 02979 * @param handle the device handle 02980 * @param *aData FIFO data array 02981 * @retval COMPONENT_OK in case of success 02982 * @retval COMPONENT_ERROR in case of failure 02983 */ 02984 DrvStatusTypeDef BSP_ACCELERO_FIFO_Get_Data_Ext(void *handle, uint8_t *aData) 02985 { 02986 02987 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 02988 02989 if (ctx == NULL) 02990 { 02991 return COMPONENT_ERROR; 02992 } 02993 02994 if (ctx->pExtVTable == NULL) 02995 { 02996 return COMPONENT_ERROR; 02997 } 02998 02999 if (aData == NULL) 03000 { 03001 return COMPONENT_ERROR; 03002 } 03003 03004 /* At the moment this feature is only implemented for LSM6DSL */ 03005 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 03006 { 03007 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 03008 03009 if (extDriver->FIFO_Get_Data == NULL) 03010 { 03011 return COMPONENT_ERROR; 03012 } 03013 03014 else 03015 { 03016 return extDriver->FIFO_Get_Data(handle, aData); 03017 } 03018 } 03019 03020 else 03021 { 03022 return COMPONENT_ERROR; 03023 } 03024 } 03025 #endif /* if 0 */ 03026 03027 /** 03028 * @brief Get number of unread FIFO samples (available only for LSM6DSL sensor) 03029 * @param handle the device handle 03030 * @param *nSamples Number of unread FIFO samples 03031 * @retval COMPONENT_OK in case of success 03032 * @retval COMPONENT_ERROR in case of failure 03033 */ 03034 DrvStatusTypeDef BSP_ACCELERO_FIFO_Get_Num_Of_Samples_Ext(void *handle, uint16_t *nSamples) 03035 { 03036 03037 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03038 void *extDriver = ctx->pExtVTable; 03039 03040 if (ctx == NULL) 03041 { 03042 return COMPONENT_ERROR; 03043 } 03044 03045 if (ctx->pExtVTable == NULL) 03046 { 03047 return COMPONENT_ERROR; 03048 } 03049 03050 if (nSamples == NULL) 03051 { 03052 return COMPONENT_ERROR; 03053 } 03054 03055 #if 0 03056 /* At the moment this feature is only implemented for LSM6DSL and LIS2DH12 */ 03057 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 03058 { 03059 if (((LSM6DSL_X_ExtDrv_t *)extDriver)->FIFO_Get_Num_Of_Samples == NULL) 03060 { 03061 return COMPONENT_ERROR; 03062 } 03063 03064 else 03065 { 03066 return ((LSM6DSL_X_ExtDrv_t *)extDriver)->FIFO_Get_Num_Of_Samples(handle, nSamples); 03067 } 03068 } 03069 03070 else 03071 #endif /* if 0 */ 03072 if (ctx->who_am_i == LIS2DH12_WHO_AM_I) 03073 { 03074 if (((LIS2DH12_ExtDrv_t *)extDriver)->FIFO_Get_Num_Of_Samples == NULL) 03075 { 03076 return COMPONENT_ERROR; 03077 } 03078 03079 else 03080 { 03081 return ((LIS2DH12_ExtDrv_t *)extDriver)->FIFO_Get_Num_Of_Samples(handle, nSamples); 03082 } 03083 } 03084 03085 else 03086 { 03087 return COMPONENT_ERROR; 03088 } 03089 } 03090 03091 #if 0 03092 /** 03093 * @brief Set FIFO decimation for accelerometer (available only for LSM6DSL sensor) 03094 * @param handle the device handle 03095 * @param decimation FIFO decimation for accelerometer 03096 * @retval COMPONENT_OK in case of success 03097 * @retval COMPONENT_ERROR in case of failure 03098 */ 03099 DrvStatusTypeDef BSP_ACCELERO_FIFO_Set_Decimation_Ext(void *handle, uint8_t decimation) 03100 { 03101 03102 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03103 03104 if (ctx == NULL) 03105 { 03106 return COMPONENT_ERROR; 03107 } 03108 03109 if (ctx->pExtVTable == NULL) 03110 { 03111 return COMPONENT_ERROR; 03112 } 03113 03114 /* At the moment this feature is only implemented for LSM6DSL */ 03115 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 03116 { 03117 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 03118 03119 if (extDriver->FIFO_X_Set_Decimation == NULL) 03120 { 03121 return COMPONENT_ERROR; 03122 } 03123 03124 else 03125 { 03126 return extDriver->FIFO_X_Set_Decimation(handle, decimation); 03127 } 03128 } 03129 03130 else 03131 { 03132 return COMPONENT_ERROR; 03133 } 03134 } 03135 03136 03137 03138 /** 03139 * @brief Get single accelero axis from the FIFO (available only for LSM6DSL sensor) 03140 * @param handle the device handle 03141 * @param acceleration the pointer to the acceleration value 03142 * @retval COMPONENT_OK in case of success 03143 * @retval COMPONENT_ERROR in case of failure 03144 */ 03145 DrvStatusTypeDef BSP_ACCELERO_FIFO_Get_Axis_Ext(void *handle, int32_t *acceleration) 03146 { 03147 03148 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03149 03150 if (ctx == NULL) 03151 { 03152 return COMPONENT_ERROR; 03153 } 03154 03155 if (ctx->pExtVTable == NULL) 03156 { 03157 return COMPONENT_ERROR; 03158 } 03159 03160 if (acceleration == NULL) 03161 { 03162 return COMPONENT_ERROR; 03163 } 03164 03165 /* At the moment this feature is only implemented for LSM6DSL */ 03166 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 03167 { 03168 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 03169 03170 if (extDriver->FIFO_X_Get_Axis == NULL) 03171 { 03172 return COMPONENT_ERROR; 03173 } 03174 03175 else 03176 { 03177 return extDriver->FIFO_X_Get_Axis(handle, acceleration); 03178 } 03179 } 03180 03181 else 03182 { 03183 return COMPONENT_ERROR; 03184 } 03185 } 03186 #endif /* if 0 */ 03187 03188 /** 03189 * @brief Set FIFO mode 03190 * @param handle the device handle 03191 * @param mode FIFO mode 03192 * @retval COMPONENT_OK in case of success 03193 * @retval COMPONENT_ERROR in case of failure 03194 */ 03195 DrvStatusTypeDef BSP_ACCELERO_FIFO_Set_Mode_Ext(void *handle, uint8_t mode) 03196 { 03197 03198 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03199 void *extDriver = ctx->pExtVTable; 03200 03201 if (ctx == NULL) 03202 { 03203 return COMPONENT_ERROR; 03204 } 03205 03206 if (ctx->pExtVTable == NULL) 03207 { 03208 return COMPONENT_ERROR; 03209 } 03210 03211 #if 0 03212 /* At the moment this feature is only implemented for LSM6DSL and LIS2DH12 */ 03213 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 03214 { 03215 if (((LSM6DSL_X_ExtDrv_t *)extDriver)->FIFO_Set_Mode == NULL) 03216 { 03217 return COMPONENT_ERROR; 03218 } 03219 03220 else 03221 { 03222 return ((LSM6DSL_X_ExtDrv_t *)extDriver)->FIFO_Set_Mode(handle, mode); 03223 } 03224 } 03225 03226 else 03227 #endif /* if 0 */ 03228 if (ctx->who_am_i == LIS2DH12_WHO_AM_I) 03229 { 03230 if (((LIS2DH12_ExtDrv_t *)extDriver)->FIFO_Set_Mode == NULL) 03231 { 03232 return COMPONENT_ERROR; 03233 } 03234 03235 else 03236 { 03237 return ((LIS2DH12_ExtDrv_t *)extDriver)->FIFO_Set_Mode(handle, mode); 03238 } 03239 } 03240 03241 else 03242 { 03243 return COMPONENT_ERROR; 03244 } 03245 } 03246 03247 #if 0 03248 /** 03249 * @brief Set FIFO_FULL interrupt on INT1 pin 03250 * @param handle the device handle 03251 * @param status FIFO_FULL interrupt on INT1 pin enable/disable 03252 * @retval COMPONENT_OK in case of success 03253 * @retval COMPONENT_ERROR in case of failure 03254 */ 03255 DrvStatusTypeDef BSP_ACCELERO_FIFO_Set_INT1_FIFO_Full_Ext(void *handle, uint8_t status) 03256 { 03257 03258 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03259 03260 if (ctx == NULL) 03261 { 03262 return COMPONENT_ERROR; 03263 } 03264 03265 if (ctx->pExtVTable == NULL) 03266 { 03267 return COMPONENT_ERROR; 03268 } 03269 03270 /* At the moment this feature is only implemented for LSM6DSL */ 03271 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 03272 { 03273 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 03274 03275 if (extDriver->FIFO_Set_INT1_FIFO_Full == NULL) 03276 { 03277 return COMPONENT_ERROR; 03278 } 03279 03280 else 03281 { 03282 return extDriver->FIFO_Set_INT1_FIFO_Full(handle, status); 03283 } 03284 } 03285 03286 else 03287 { 03288 return COMPONENT_ERROR; 03289 } 03290 } 03291 #endif /* if 0 */ 03292 03293 03294 /** 03295 * @brief Set FIFO_OVR interrupt on INT1 pin 03296 * @param handle the device handle 03297 * @param status FIFO_OVR interrupt on INT1 pin enable/disable 03298 * @retval COMPONENT_OK in case of success 03299 * @retval COMPONENT_ERROR in case of failure 03300 */ 03301 DrvStatusTypeDef BSP_ACCELERO_FIFO_Set_INT1_FIFO_Overrun_Ext(void *handle, uint8_t status) 03302 { 03303 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03304 03305 if (ctx == NULL) 03306 { 03307 return COMPONENT_ERROR; 03308 } 03309 03310 if (ctx->pExtVTable == NULL) 03311 { 03312 return COMPONENT_ERROR; 03313 } 03314 03315 /* At the moment this feature is only implemented for LIS2DH12 */ 03316 if (ctx->who_am_i == LIS2DH12_WHO_AM_I) 03317 { 03318 LIS2DH12_ExtDrv_t *extDriver = (LIS2DH12_ExtDrv_t *)ctx->pExtVTable; 03319 03320 if (extDriver->FIFO_Set_INT1_FIFO_Overrun == NULL) 03321 { 03322 return COMPONENT_ERROR; 03323 } 03324 03325 else 03326 { 03327 return extDriver->FIFO_Set_INT1_FIFO_Overrun(handle, status); 03328 } 03329 } 03330 03331 else 03332 { 03333 return COMPONENT_ERROR; 03334 } 03335 } 03336 03337 #if 0 03338 /** 03339 * @brief Set FIFO watermark level 03340 * @param handle the device handle 03341 * @param watermark FIFO watermark level 03342 * @retval COMPONENT_OK in case of success 03343 * @retval COMPONENT_ERROR in case of failure 03344 */ 03345 DrvStatusTypeDef BSP_ACCELERO_FIFO_Set_Watermark_Level_Ext(void *handle, uint16_t watermark) 03346 { 03347 03348 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03349 03350 if (ctx == NULL) 03351 { 03352 return COMPONENT_ERROR; 03353 } 03354 03355 if (ctx->pExtVTable == NULL) 03356 { 03357 return COMPONENT_ERROR; 03358 } 03359 03360 /* At the moment this feature is only implemented for LSM6DSL */ 03361 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 03362 { 03363 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 03364 03365 if (extDriver->FIFO_Set_Watermark_Level == NULL) 03366 { 03367 return COMPONENT_ERROR; 03368 } 03369 03370 else 03371 { 03372 return extDriver->FIFO_Set_Watermark_Level(handle, watermark); 03373 } 03374 } 03375 03376 else 03377 { 03378 return COMPONENT_ERROR; 03379 } 03380 } 03381 03382 03383 03384 /** 03385 * @brief Set FIFO to stop on FTH interrupt 03386 * @param handle the device handle 03387 * @param status FIFO stop on FTH interrupt enable/disable 03388 * @retval COMPONENT_OK in case of success 03389 * @retval COMPONENT_ERROR in case of failure 03390 */ 03391 DrvStatusTypeDef BSP_ACCELERO_FIFO_Set_Stop_On_Fth_Ext(void *handle, uint8_t status) 03392 { 03393 03394 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03395 03396 if (ctx == NULL) 03397 { 03398 return COMPONENT_ERROR; 03399 } 03400 03401 if (ctx->pExtVTable == NULL) 03402 { 03403 return COMPONENT_ERROR; 03404 } 03405 03406 /* At the moment this feature is only implemented for LSM6DSL */ 03407 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 03408 { 03409 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 03410 03411 if (extDriver->FIFO_Set_Stop_On_Fth == NULL) 03412 { 03413 return COMPONENT_ERROR; 03414 } 03415 03416 else 03417 { 03418 return extDriver->FIFO_Set_Stop_On_Fth(handle, status); 03419 } 03420 } 03421 03422 else 03423 { 03424 return COMPONENT_ERROR; 03425 } 03426 } 03427 03428 03429 03430 /** 03431 * @brief Set interrupt latch 03432 * @param handle the device handle 03433 * @param status interrupt latch enable/disable 03434 * @retval COMPONENT_OK in case of success 03435 * @retval COMPONENT_ERROR in case of failure 03436 */ 03437 DrvStatusTypeDef BSP_ACCELERO_Set_Interrupt_Latch_Ext(void *handle, uint8_t status) 03438 { 03439 03440 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03441 03442 if (ctx == NULL) 03443 { 03444 return COMPONENT_ERROR; 03445 } 03446 03447 if (ctx->pExtVTable == NULL) 03448 { 03449 return COMPONENT_ERROR; 03450 } 03451 03452 /* At the moment this feature is only implemented for LSM6DSL */ 03453 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 03454 { 03455 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 03456 03457 if (extDriver->Set_Interrupt_Latch == NULL) 03458 { 03459 return COMPONENT_ERROR; 03460 } 03461 03462 else 03463 { 03464 return extDriver->Set_Interrupt_Latch(handle, status); 03465 } 03466 } 03467 03468 else 03469 { 03470 return COMPONENT_ERROR; 03471 } 03472 } 03473 03474 03475 03476 /** 03477 * @brief Set accelero self-test 03478 * @param handle the device handle 03479 * @param status self-test enable/disable 03480 * @retval COMPONENT_OK in case of success 03481 * @retval COMPONENT_ERROR in case of failure 03482 */ 03483 DrvStatusTypeDef BSP_ACCELERO_Set_SelfTest_Ext(void *handle, uint8_t status) 03484 { 03485 03486 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03487 03488 if (ctx == NULL) 03489 { 03490 return COMPONENT_ERROR; 03491 } 03492 03493 if (ctx->pExtVTable == NULL) 03494 { 03495 return COMPONENT_ERROR; 03496 } 03497 03498 /* At the moment this feature is only implemented for LSM6DSL */ 03499 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 03500 { 03501 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 03502 03503 if (extDriver->Set_SelfTest == NULL) 03504 { 03505 return COMPONENT_ERROR; 03506 } 03507 03508 else 03509 { 03510 return extDriver->Set_SelfTest(handle, status); 03511 } 03512 } 03513 03514 else 03515 { 03516 return COMPONENT_ERROR; 03517 } 03518 } 03519 03520 03521 03522 /** 03523 * @brief Get the accelerometer sensor super raw data from one axis 03524 * @param handle the device handle 03525 * @param acceleration pointer where the super raw value of the axis is written 03526 * @param axis axis to be read 03527 * @retval COMPONENT_OK in case of success 03528 * @retval COMPONENT_ERROR in case of failure 03529 */ 03530 DrvStatusTypeDef BSP_ACCELERO_Get_SuperRawAxes_Ext(void *handle, int16_t *acceleration, ACTIVE_AXIS_t axis) 03531 { 03532 03533 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03534 03535 if (ctx == NULL) 03536 { 03537 return COMPONENT_ERROR; 03538 } 03539 03540 if (ctx->pExtVTable == NULL) 03541 { 03542 return COMPONENT_ERROR; 03543 } 03544 03545 if (ctx->instance == LIS2DH12_0) 03546 { 03547 if (ctx->who_am_i == LIS2DH12_WHO_AM_I) 03548 { 03549 LIS2DH12_ExtDrv_t *extDriver = (LIS2DH12_ExtDrv_t *)ctx->pExtVTable; 03550 03551 if (extDriver->Get_AxesSuperRaw == NULL) 03552 { 03553 return COMPONENT_ERROR; 03554 } 03555 03556 if (extDriver->Get_AxesSuperRaw(ctx, acceleration, axis) == COMPONENT_ERROR) 03557 { 03558 return COMPONENT_ERROR; 03559 } 03560 03561 return COMPONENT_OK; 03562 } 03563 } 03564 #if 0 03565 else if (ctx->instance == LSM303AGR_X_0) 03566 { 03567 if (ctx->who_am_i == LSM303AGR_ACC_WHO_AM_I) 03568 { 03569 LSM303AGR_X_ExtDrv_t *extDriver = (LSM303AGR_X_ExtDrv_t *)ctx->pExtVTable; 03570 03571 if (extDriver->Get_AxesSuperRaw == NULL) 03572 { 03573 return COMPONENT_ERROR; 03574 } 03575 03576 if (extDriver->Get_AxesSuperRaw(ctx, acceleration, axis) == COMPONENT_ERROR) 03577 { 03578 return COMPONENT_ERROR; 03579 } 03580 03581 return COMPONENT_OK; 03582 } 03583 } 03584 #endif /* if 0 */ 03585 03586 return COMPONENT_ERROR; 03587 } 03588 03589 03590 03591 /** 03592 * @brief Get the accelerometer sensor operating mode 03593 * @param handle the device handle 03594 * @param opMode pointer where the operating mode value is stored 03595 * @retval COMPONENT_OK in case of success 03596 * @retval COMPONENT_ERROR in case of failure 03597 */ 03598 DrvStatusTypeDef BSP_ACCELERO_Get_OpMode_Ext(void *handle, OP_MODE_t *opMode) 03599 { 03600 03601 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03602 03603 if (ctx == NULL) 03604 { 03605 return COMPONENT_ERROR; 03606 } 03607 03608 if (ctx->pExtVTable == NULL) 03609 { 03610 return COMPONENT_ERROR; 03611 } 03612 03613 if (ctx->instance == LIS2DH12_0) 03614 { 03615 if (ctx->who_am_i == LIS2DH12_WHO_AM_I) 03616 { 03617 LIS2DH12_ExtDrv_t *extDriver = (LIS2DH12_ExtDrv_t *)ctx->pExtVTable; 03618 03619 if (extDriver->Get_OpMode == NULL) 03620 { 03621 return COMPONENT_ERROR; 03622 } 03623 03624 if (extDriver->Get_OpMode(ctx, opMode) == COMPONENT_ERROR) 03625 { 03626 return COMPONENT_ERROR; 03627 } 03628 03629 return COMPONENT_OK; 03630 } 03631 } 03632 #if 0 03633 else if (ctx->instance == LSM303AGR_X_0) 03634 { 03635 if (ctx->who_am_i == LSM303AGR_ACC_WHO_AM_I) 03636 { 03637 LSM303AGR_X_ExtDrv_t *extDriver = (LSM303AGR_X_ExtDrv_t *)ctx->pExtVTable; 03638 03639 if (extDriver->Get_OpMode == NULL) 03640 { 03641 return COMPONENT_ERROR; 03642 } 03643 03644 if (extDriver->Get_OpMode(ctx, opMode) == COMPONENT_ERROR) 03645 { 03646 return COMPONENT_ERROR; 03647 } 03648 03649 return COMPONENT_OK; 03650 } 03651 } 03652 #endif /* if 0 */ 03653 03654 return COMPONENT_ERROR; 03655 } 03656 03657 03658 03659 /** 03660 * @brief Set the accelerometer sensor operating mode 03661 * @param handle the device handle 03662 * @param opMode the value of operating mode to be set 03663 * @retval COMPONENT_OK in case of success 03664 * @retval COMPONENT_ERROR in case of failure 03665 */ 03666 DrvStatusTypeDef BSP_ACCELERO_Set_OpMode_Ext(void *handle, OP_MODE_t opMode) 03667 { 03668 03669 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03670 03671 if (ctx == NULL) 03672 { 03673 return COMPONENT_ERROR; 03674 } 03675 03676 if (ctx->pExtVTable == NULL) 03677 { 03678 return COMPONENT_ERROR; 03679 } 03680 03681 if (ctx->instance == LIS2DH12_0) 03682 { 03683 if (ctx->who_am_i == LIS2DH12_WHO_AM_I) 03684 { 03685 LIS2DH12_ExtDrv_t *extDriver = (LIS2DH12_ExtDrv_t *)ctx->pExtVTable; 03686 03687 if (extDriver->Set_OpMode == NULL) 03688 { 03689 return COMPONENT_ERROR; 03690 } 03691 03692 if (extDriver->Set_OpMode(ctx, opMode) == COMPONENT_ERROR) 03693 { 03694 return COMPONENT_ERROR; 03695 } 03696 03697 return COMPONENT_OK; 03698 } 03699 } 03700 #if 0 03701 else if (ctx->instance == LSM303AGR_X_0) 03702 { 03703 if (ctx->who_am_i == LSM303AGR_ACC_WHO_AM_I) 03704 { 03705 LSM303AGR_X_ExtDrv_t *extDriver = (LSM303AGR_X_ExtDrv_t *)ctx->pExtVTable; 03706 03707 if (extDriver->Set_OpMode == NULL) 03708 { 03709 return COMPONENT_ERROR; 03710 } 03711 03712 if (extDriver->Set_OpMode(ctx, opMode) == COMPONENT_ERROR) 03713 { 03714 return COMPONENT_ERROR; 03715 } 03716 03717 return COMPONENT_OK; 03718 } 03719 } 03720 #endif /* if 0 */ 03721 03722 return COMPONENT_ERROR; 03723 } 03724 03725 03726 03727 /** 03728 * @brief Set the accelerometer sensor active axis 03729 * @param handle the device handle 03730 * @param axis pointer where the active axis value is stored 03731 * @retval COMPONENT_OK in case of success 03732 * @retval COMPONENT_ERROR in case of failure 03733 */ 03734 DrvStatusTypeDef BSP_ACCELERO_Get_Active_Axis_Ext(void *handle, ACTIVE_AXIS_t *axis) 03735 { 03736 03737 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03738 03739 if (ctx == NULL) 03740 { 03741 return COMPONENT_ERROR; 03742 } 03743 03744 if (ctx->pExtVTable == NULL) 03745 { 03746 return COMPONENT_ERROR; 03747 } 03748 03749 if (ctx->instance == LIS2DH12_0) 03750 { 03751 if (ctx->who_am_i == LIS2DH12_WHO_AM_I) 03752 { 03753 LIS2DH12_ExtDrv_t *extDriver = (LIS2DH12_ExtDrv_t *)ctx->pExtVTable; 03754 03755 if (extDriver->Get_Active_Axis == NULL) 03756 { 03757 return COMPONENT_ERROR; 03758 } 03759 03760 if (extDriver->Get_Active_Axis(ctx, axis) == COMPONENT_ERROR) 03761 { 03762 return COMPONENT_ERROR; 03763 } 03764 03765 return COMPONENT_OK; 03766 } 03767 } 03768 #if 0 03769 else if (ctx->instance == LSM303AGR_X_0) 03770 { 03771 if (ctx->who_am_i == LSM303AGR_ACC_WHO_AM_I) 03772 { 03773 LSM303AGR_X_ExtDrv_t *extDriver = (LSM303AGR_X_ExtDrv_t *)ctx->pExtVTable; 03774 03775 if (extDriver->Get_Active_Axis == NULL) 03776 { 03777 return COMPONENT_ERROR; 03778 } 03779 03780 if (extDriver->Get_Active_Axis(ctx, axis) == COMPONENT_ERROR) 03781 { 03782 return COMPONENT_ERROR; 03783 } 03784 03785 return COMPONENT_OK; 03786 } 03787 } 03788 #endif /* if 0 */ 03789 #if 0 03790 else if (ctx->instance == LSM6DSL_X_0 || ctx->instance == LSM6DSL_X_1) 03791 { 03792 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 03793 { 03794 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 03795 03796 if (extDriver->Get_Active_Axis == NULL) 03797 { 03798 return COMPONENT_ERROR; 03799 } 03800 03801 if (extDriver->Get_Active_Axis(ctx, axis) == COMPONENT_ERROR) 03802 { 03803 return COMPONENT_ERROR; 03804 } 03805 03806 return COMPONENT_OK; 03807 } 03808 } 03809 #endif /* if 0 */ 03810 03811 return COMPONENT_ERROR; 03812 } 03813 03814 03815 03816 /** 03817 * @brief Set the accelerometer sensor active axis 03818 * @param handle the device handle 03819 * @param axis the value of active axis to be set 03820 * @retval COMPONENT_OK in case of success 03821 * @retval COMPONENT_ERROR in case of failure 03822 */ 03823 DrvStatusTypeDef BSP_ACCELERO_Set_Active_Axis_Ext(void *handle, ACTIVE_AXIS_t axis) 03824 { 03825 03826 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03827 03828 if (ctx == NULL) 03829 { 03830 return COMPONENT_ERROR; 03831 } 03832 03833 if (ctx->pExtVTable == NULL) 03834 { 03835 return COMPONENT_ERROR; 03836 } 03837 03838 if (ctx->instance == LIS2DH12_0) 03839 { 03840 if (ctx->who_am_i == LIS2DH12_WHO_AM_I) 03841 { 03842 LIS2DH12_ExtDrv_t *extDriver = (LIS2DH12_ExtDrv_t *)ctx->pExtVTable; 03843 03844 if (extDriver->Set_Active_Axis == NULL) 03845 { 03846 return COMPONENT_ERROR; 03847 } 03848 03849 if (extDriver->Set_Active_Axis(ctx, axis) == COMPONENT_ERROR) 03850 { 03851 return COMPONENT_ERROR; 03852 } 03853 03854 return COMPONENT_OK; 03855 } 03856 } 03857 #if 0 03858 else if (ctx->instance == LSM303AGR_X_0) 03859 { 03860 if (ctx->who_am_i == LSM303AGR_ACC_WHO_AM_I) 03861 { 03862 LSM303AGR_X_ExtDrv_t *extDriver = (LSM303AGR_X_ExtDrv_t *)ctx->pExtVTable; 03863 03864 if (extDriver->Set_Active_Axis == NULL) 03865 { 03866 return COMPONENT_ERROR; 03867 } 03868 03869 if (extDriver->Set_Active_Axis(ctx, axis) == COMPONENT_ERROR) 03870 { 03871 return COMPONENT_ERROR; 03872 } 03873 03874 return COMPONENT_OK; 03875 } 03876 } 03877 #endif /* if 0 */ 03878 #if 0 03879 else if (ctx->instance == LSM6DSL_X_0 || ctx->instance == LSM6DSL_X_1) 03880 { 03881 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 03882 { 03883 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 03884 03885 if (extDriver->Set_Active_Axis == NULL) 03886 { 03887 return COMPONENT_ERROR; 03888 } 03889 03890 if (extDriver->Set_Active_Axis(ctx, axis) == COMPONENT_ERROR) 03891 { 03892 return COMPONENT_ERROR; 03893 } 03894 03895 return COMPONENT_OK; 03896 } 03897 } 03898 #endif /* if 0 */ 03899 03900 return COMPONENT_ERROR; 03901 } 03902 03903 03904 03905 /** 03906 * @brief Enable the accelerometer sensor HP Filter 03907 * @param handle the device handle 03908 * @param mode the value of HP Filter mode to be set 03909 * @param cutoff the value of HP Filter cutoff to be set 03910 * @retval COMPONENT_OK in case of success 03911 * @retval COMPONENT_ERROR in case of failure 03912 */ 03913 DrvStatusTypeDef BSP_ACCELERO_Enable_HP_Filter_Ext(void *handle) 03914 { 03915 03916 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 03917 03918 if (ctx == NULL) 03919 { 03920 return COMPONENT_ERROR; 03921 } 03922 03923 if (ctx->pExtVTable == NULL) 03924 { 03925 return COMPONENT_ERROR; 03926 } 03927 03928 if (ctx->instance == LIS2DH12_0) 03929 { 03930 if (ctx->who_am_i == LIS2DH12_WHO_AM_I) 03931 { 03932 LIS2DH12_ExtDrv_t *extDriver = (LIS2DH12_ExtDrv_t *)ctx->pExtVTable; 03933 03934 if (extDriver->Enable_HP_Filter == NULL) 03935 { 03936 return COMPONENT_ERROR; 03937 } 03938 03939 if (extDriver->Enable_HP_Filter(ctx) == COMPONENT_ERROR) 03940 { 03941 return COMPONENT_ERROR; 03942 } 03943 03944 return COMPONENT_OK; 03945 } 03946 } 03947 #if 0 03948 else if (ctx->instance == LSM303AGR_X_0) 03949 { 03950 if (ctx->who_am_i == LSM303AGR_ACC_WHO_AM_I) 03951 { 03952 LSM303AGR_X_ExtDrv_t *extDriver = (LSM303AGR_X_ExtDrv_t *)ctx->pExtVTable; 03953 03954 if (extDriver->Enable_HP_Filter == NULL) 03955 { 03956 return COMPONENT_ERROR; 03957 } 03958 03959 if (extDriver->Enable_HP_Filter(ctx) == COMPONENT_ERROR) 03960 { 03961 return COMPONENT_ERROR; 03962 } 03963 03964 return COMPONENT_OK; 03965 } 03966 } 03967 #endif /* if 0 */ 03968 #if 0 03969 else if (ctx->instance == LSM6DSL_X_0 || ctx->instance == LSM6DSL_X_1) 03970 { 03971 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 03972 { 03973 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 03974 03975 if (extDriver->Enable_HP_Filter == NULL) 03976 { 03977 return COMPONENT_ERROR; 03978 } 03979 03980 if (extDriver->Enable_HP_Filter(ctx) == COMPONENT_ERROR) 03981 { 03982 return COMPONENT_ERROR; 03983 } 03984 03985 return COMPONENT_OK; 03986 } 03987 } 03988 #endif /* if 0 */ 03989 03990 return COMPONENT_ERROR; 03991 } 03992 03993 03994 03995 /** 03996 * @brief Disable the accelerometer sensor HP Filter 03997 * @param handle the device handle 03998 * @retval COMPONENT_OK in case of success 03999 * @retval COMPONENT_ERROR in case of failure 04000 */ 04001 DrvStatusTypeDef BSP_ACCELERO_Disable_HP_Filter_Ext(void *handle) 04002 { 04003 04004 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 04005 04006 if (ctx == NULL) 04007 { 04008 return COMPONENT_ERROR; 04009 } 04010 04011 if (ctx->pExtVTable == NULL) 04012 { 04013 return COMPONENT_ERROR; 04014 } 04015 04016 if (ctx->instance == LIS2DH12_0) 04017 { 04018 if (ctx->who_am_i == LIS2DH12_WHO_AM_I) 04019 { 04020 LIS2DH12_ExtDrv_t *extDriver = (LIS2DH12_ExtDrv_t *)ctx->pExtVTable; 04021 04022 if (extDriver->Disable_HP_Filter == NULL) 04023 { 04024 return COMPONENT_ERROR; 04025 } 04026 04027 if (extDriver->Disable_HP_Filter(ctx) == COMPONENT_ERROR) 04028 { 04029 return COMPONENT_ERROR; 04030 } 04031 04032 return COMPONENT_OK; 04033 } 04034 } 04035 #if 0 04036 else if (ctx->instance == LSM303AGR_X_0) 04037 { 04038 if (ctx->who_am_i == LSM303AGR_ACC_WHO_AM_I) 04039 { 04040 LSM303AGR_X_ExtDrv_t *extDriver = (LSM303AGR_X_ExtDrv_t *)ctx->pExtVTable; 04041 04042 if (extDriver->Disable_HP_Filter == NULL) 04043 { 04044 return COMPONENT_ERROR; 04045 } 04046 04047 if (extDriver->Disable_HP_Filter(ctx) == COMPONENT_ERROR) 04048 { 04049 return COMPONENT_ERROR; 04050 } 04051 04052 return COMPONENT_OK; 04053 } 04054 } 04055 #endif /* if 0 */ 04056 #if 0 04057 else if (ctx->instance == LSM6DSL_X_0 || ctx->instance == LSM6DSL_X_1) 04058 { 04059 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 04060 { 04061 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 04062 04063 if (extDriver->Disable_HP_Filter == NULL) 04064 { 04065 return COMPONENT_ERROR; 04066 } 04067 04068 if (extDriver->Disable_HP_Filter(ctx) == COMPONENT_ERROR) 04069 { 04070 return COMPONENT_ERROR; 04071 } 04072 04073 return COMPONENT_OK; 04074 } 04075 } 04076 #endif /* if 0 */ 04077 04078 return COMPONENT_ERROR; 04079 } 04080 04081 04082 04083 /** 04084 * @brief Clear the accelerometer sensor DRDY 04085 * @param handle the device handle 04086 * @retval COMPONENT_OK in case of success 04087 * @retval COMPONENT_ERROR in case of failure 04088 */ 04089 DrvStatusTypeDef BSP_ACCELERO_ClearDRDY_Ext(void *handle, ACTIVE_AXIS_t axisActive) 04090 { 04091 04092 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 04093 04094 if (ctx == NULL) 04095 { 04096 return COMPONENT_ERROR; 04097 } 04098 04099 if (ctx->pExtVTable == NULL) 04100 { 04101 return COMPONENT_ERROR; 04102 } 04103 04104 if (ctx->instance == LIS2DH12_0) 04105 { 04106 if (ctx->who_am_i == LIS2DH12_WHO_AM_I) 04107 { 04108 LIS2DH12_ExtDrv_t *extDriver = (LIS2DH12_ExtDrv_t *)ctx->pExtVTable; 04109 04110 if (extDriver->ClearDRDY == NULL) 04111 { 04112 return COMPONENT_ERROR; 04113 } 04114 04115 if (extDriver->ClearDRDY(ctx, axisActive) == COMPONENT_ERROR) 04116 { 04117 return COMPONENT_ERROR; 04118 } 04119 04120 return COMPONENT_OK; 04121 } 04122 } 04123 #if 0 04124 else if (ctx->instance == LSM303AGR_X_0) 04125 { 04126 if (ctx->who_am_i == LSM303AGR_ACC_WHO_AM_I) 04127 { 04128 LSM303AGR_X_ExtDrv_t *extDriver = (LSM303AGR_X_ExtDrv_t *)ctx->pExtVTable; 04129 04130 if (extDriver->ClearDRDY == NULL) 04131 { 04132 return COMPONENT_ERROR; 04133 } 04134 04135 if (extDriver->ClearDRDY(ctx, axisActive) == COMPONENT_ERROR) 04136 { 04137 return COMPONENT_ERROR; 04138 } 04139 04140 return COMPONENT_OK; 04141 } 04142 } 04143 #endif /* if 0 */ 04144 #if 0 04145 else if (ctx->instance == LSM6DSL_X_0 || ctx->instance == LSM6DSL_X_1) 04146 { 04147 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 04148 { 04149 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 04150 04151 if (extDriver->ClearDRDY == NULL) 04152 { 04153 return COMPONENT_ERROR; 04154 } 04155 04156 if (extDriver->ClearDRDY(ctx, axisActive) == COMPONENT_ERROR) 04157 { 04158 return COMPONENT_ERROR; 04159 } 04160 04161 return COMPONENT_OK; 04162 } 04163 } 04164 #endif /* if 0 */ 04165 04166 return COMPONENT_ERROR; 04167 } 04168 04169 04170 04171 /** 04172 * @brief Set the accelerometer sensor DRDY on INT1 04173 * @param handle the device handle 04174 * @param drdyStatus enable/disable DRDY on INT1 value 04175 * @retval COMPONENT_OK in case of success 04176 * @retval COMPONENT_ERROR in case of failure 04177 */ 04178 DrvStatusTypeDef BSP_ACCELERO_Set_INT1_DRDY_Ext(void *handle, INT1_DRDY_CONFIG_t drdyStatus) 04179 { 04180 04181 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle; 04182 04183 if (ctx == NULL) 04184 { 04185 return COMPONENT_ERROR; 04186 } 04187 04188 if (ctx->pExtVTable == NULL) 04189 { 04190 return COMPONENT_ERROR; 04191 } 04192 04193 if (ctx->instance == LIS2DH12_0) 04194 { 04195 if (ctx->who_am_i == LIS2DH12_WHO_AM_I) 04196 { 04197 LIS2DH12_ExtDrv_t *extDriver = (LIS2DH12_ExtDrv_t *)ctx->pExtVTable; 04198 04199 if (extDriver->Set_INT1_DRDY == NULL) 04200 { 04201 return COMPONENT_ERROR; 04202 } 04203 04204 if (extDriver->Set_INT1_DRDY(ctx, drdyStatus) == COMPONENT_ERROR) 04205 { 04206 return COMPONENT_ERROR; 04207 } 04208 04209 return COMPONENT_OK; 04210 } 04211 } 04212 #if 0 04213 else if (ctx->instance == LSM303AGR_X_0) 04214 { 04215 if (ctx->who_am_i == LSM303AGR_ACC_WHO_AM_I) 04216 { 04217 LSM303AGR_X_ExtDrv_t *extDriver = (LSM303AGR_X_ExtDrv_t *)ctx->pExtVTable; 04218 04219 if (extDriver->Set_INT1_DRDY == NULL) 04220 { 04221 return COMPONENT_ERROR; 04222 } 04223 04224 if (extDriver->Set_INT1_DRDY(ctx, drdyStatus) == COMPONENT_ERROR) 04225 { 04226 return COMPONENT_ERROR; 04227 } 04228 04229 return COMPONENT_OK; 04230 } 04231 } 04232 #endif /* if 0 */ 04233 #if 0 04234 else if (ctx->instance == LSM6DSL_X_0 || ctx->instance == LSM6DSL_X_1) 04235 { 04236 if (ctx->who_am_i == LSM6DSL_ACC_GYRO_WHO_AM_I) 04237 { 04238 LSM6DSL_X_ExtDrv_t *extDriver = (LSM6DSL_X_ExtDrv_t *)ctx->pExtVTable; 04239 04240 if (extDriver->Set_INT1_DRDY == NULL) 04241 { 04242 return COMPONENT_ERROR; 04243 } 04244 04245 if (extDriver->Set_INT1_DRDY(ctx, drdyStatus) == COMPONENT_ERROR) 04246 { 04247 return COMPONENT_ERROR; 04248 } 04249 04250 return COMPONENT_OK; 04251 } 04252 } 04253 #endif /* if 0 */ 04254 04255 return COMPONENT_ERROR; 04256 } 04257 04258 04259 /** 04260 * @brief Check if LIS2DH12 sensor is available 04261 * @param handle the device handle 04262 * @retval COMPONENT_OK in case of success 04263 * @retval COMPONENT_ERROR in case of failure 04264 */ 04265 DrvStatusTypeDef BSP_LIS2DH12_AVAIL_Ext(void **handle) 04266 { 04267 ACCELERO_Drv_t *driver = NULL; 04268 04269 if (Sensor_IO_Init() == COMPONENT_ERROR) 04270 { 04271 return COMPONENT_ERROR; 04272 } 04273 04274 /* Setup sensor handle. */ 04275 ACCELERO_SensorHandle[ TEST_X_0 ].who_am_i = LIS2DH12_WHO_AM_I; 04276 ACCELERO_SensorHandle[ TEST_X_0 ].address = LIS2DH12_I2C_ADDRESS_LOW; 04277 ACCELERO_SensorHandle[ TEST_X_0 ].instance = LIS2DH12_0; 04278 ACCELERO_SensorHandle[ TEST_X_0 ].isInitialized = 0; 04279 ACCELERO_SensorHandle[ TEST_X_0 ].isEnabled = 0; 04280 ACCELERO_SensorHandle[ TEST_X_0 ].isCombo = 0; 04281 ACCELERO_SensorHandle[ TEST_X_0 ].pData = (void *)&ACCELERO_Data[ LIS2DH12_0 ]; 04282 ACCELERO_SensorHandle[ TEST_X_0 ].pVTable = (void *)&LIS2DH12_Drv; 04283 ACCELERO_SensorHandle[ TEST_X_0 ].pExtVTable = (void *)&LIS2DH12_ExtDrv; 04284 ACCELERO_Data[ TEST_X_0 ].pComponentData = (void *)&LIS2DH12_0_Data; 04285 ACCELERO_Data[ TEST_X_0 ].pExtData = 0; 04286 04287 *handle = (void *)&ACCELERO_SensorHandle[ TEST_X_0 ]; 04288 driver = (ACCELERO_Drv_t *)((DrvContextTypeDef *)(*handle))->pVTable; 04289 04290 if (driver->Check_WhoAmI((DrvContextTypeDef *)(*handle)) == COMPONENT_ERROR) 04291 { 04292 return COMPONENT_ERROR; 04293 } 04294 04295 memset((*handle), 0, sizeof(DrvContextTypeDef)); 04296 *handle = NULL; 04297 04298 return COMPONENT_OK; 04299 } 04300 04301 /** 04302 * @} 04303 */ 04304 04305 /** @addtogroup X_NUCLEO_IKS01A2_ACCELERO_Private_Functions Private functions 04306 * @{ 04307 */ 04308 04309 #endif /* if 0 */ 04310 04311 /** 04312 * @brief Initialize an LIS2DH12 accelerometer sensor 04313 * @param handle the device handle 04314 * @retval COMPONENT_OK in case of success 04315 * @retval COMPONENT_ERROR in case of failure 04316 */ 04317 static DrvStatusTypeDef BSP_LIS2DH12_ACCELERO_Init(void **handle) 04318 { 04319 ACCELERO_Drv_t *driver = NULL; 04320 04321 if (Sensor_IO_Init() == COMPONENT_ERROR) 04322 { 04323 return COMPONENT_ERROR; 04324 } 04325 04326 /* Setup sensor handle. */ 04327 ACCELERO_SensorHandle[ LIS2DH12_0 ].who_am_i = LIS2DH12_WHO_AM_I; 04328 ACCELERO_SensorHandle[ LIS2DH12_0 ].ifType = 0; /* I2C interface */ 04329 ACCELERO_SensorHandle[ LIS2DH12_0 ].address = LIS2DH12_I2C_ADDRESS_HIGH; //LIS2DH12_I2C_ADDRESS_LOW; 04330 ACCELERO_SensorHandle[ LIS2DH12_0 ].instance = LIS2DH12_0; 04331 ACCELERO_SensorHandle[ LIS2DH12_0 ].isInitialized = 0; 04332 ACCELERO_SensorHandle[ LIS2DH12_0 ].isEnabled = 0; 04333 ACCELERO_SensorHandle[ LIS2DH12_0 ].isCombo = 0; 04334 ACCELERO_SensorHandle[ LIS2DH12_0 ].pData = (void *)&ACCELERO_Data[ LIS2DH12_0 ]; 04335 ACCELERO_SensorHandle[ LIS2DH12_0 ].pVTable = (void *)&LIS2DH12_Drv; 04336 ACCELERO_SensorHandle[ LIS2DH12_0 ].pExtVTable = (void *)&LIS2DH12_ExtDrv; 04337 04338 ACCELERO_Data[ LIS2DH12_0 ].pComponentData = (void *)&LIS2DH12_0_Data; 04339 ACCELERO_Data[ LIS2DH12_0 ].pExtData = 0; 04340 04341 *handle = (void *)&ACCELERO_SensorHandle[ LIS2DH12_0 ]; 04342 04343 driver = (ACCELERO_Drv_t *)((DrvContextTypeDef *)(*handle))->pVTable; 04344 04345 if (driver->Init == NULL) 04346 { 04347 memset((*handle), 0, sizeof(DrvContextTypeDef)); 04348 *handle = NULL; 04349 return COMPONENT_ERROR; 04350 } 04351 04352 if (driver->Init((DrvContextTypeDef *)(*handle)) == COMPONENT_ERROR) 04353 { 04354 memset((*handle), 0, sizeof(DrvContextTypeDef)); 04355 *handle = NULL; 04356 return COMPONENT_ERROR; 04357 } 04358 04359 /* Configure interrupt lines common for all sensors in DIL24 socket */ 04360 DIL24_Sensor_IO_ITConfig(); 04361 04362 return COMPONENT_OK; 04363 } 04364 04365 /** 04366 * @} 04367 */ 04368 04369 /** 04370 * @} 04371 */ 04372 04373 /** 04374 * @} 04375 */ 04376 04377 /** 04378 * @} 04379 */ 04380 04381 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 16:29:50 by 1.7.2