Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: VL53L0X
Fork of BSP_B-L475E-IOT01 by
stm32l475e_iot01_accelero.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l475e_iot01_accelero.c 00004 * @author MCD 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) 2017 STMicroelectronics International N.V. 00010 * All rights reserved.</center></h2> 00011 * 00012 * Redistribution and use in source and binary forms, with or without 00013 * modification, are permitted, provided that the following conditions are met: 00014 * 00015 * 1. Redistribution of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of other 00021 * contributors to this software may be used to endorse or promote products 00022 * derived from this software without specific written permission. 00023 * 4. This software, including modifications and/or derivative works of this 00024 * software, must execute solely and exclusively on microcontroller or 00025 * microprocessor devices manufactured by or for STMicroelectronics. 00026 * 5. Redistribution and use of this software other than as permitted under 00027 * this license is void and will automatically terminate your rights under 00028 * this license. 00029 * 00030 * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 00031 * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 00032 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 00033 * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 00034 * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 00035 * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00036 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00037 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00038 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00039 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00040 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00041 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00042 * 00043 ****************************************************************************** 00044 */ 00045 00046 /* Includes ------------------------------------------------------------------*/ 00047 #include "stm32l475e_iot01_accelero.h" 00048 /** @addtogroup BSP 00049 * @{ 00050 */ 00051 00052 /** @addtogroup STM32L475E_IOT01 00053 * @{ 00054 */ 00055 00056 /** @defgroup STM32L475E_IOT01_ACCELERO ACCELERO 00057 * @{ 00058 */ 00059 00060 /** @defgroup STM32L475E_IOT01_ACCELERO_Private_Variables ACCELERO Private Variables 00061 * @{ 00062 */ 00063 static ACCELERO_DrvTypeDef *AccelerometerDrv; 00064 /** 00065 * @} 00066 */ 00067 00068 /** @defgroup STM32L475E_IOT01_ACCELERO_Private_Functions ACCELERO Private Functions 00069 * @{ 00070 */ 00071 /** 00072 * @brief Initialize the ACCELERO. 00073 * @retval ACCELERO_OK or ACCELERO_ERROR 00074 */ 00075 ACCELERO_StatusTypeDef BSP_ACCELERO_Init(void) 00076 { 00077 ACCELERO_StatusTypeDef ret = ACCELERO_OK; 00078 uint16_t ctrl = 0x0000; 00079 ACCELERO_InitTypeDef LSM6DSL_InitStructure; 00080 00081 if(Lsm6dslAccDrv.ReadID() != LSM6DSL_ACC_GYRO_WHO_AM_I) 00082 { 00083 ret = ACCELERO_ERROR; 00084 } 00085 else 00086 { 00087 /* Initialize the ACCELERO accelerometer driver structure */ 00088 AccelerometerDrv = &Lsm6dslAccDrv; 00089 00090 /* MEMS configuration ------------------------------------------------------*/ 00091 /* Fill the ACCELERO accelerometer structure */ 00092 LSM6DSL_InitStructure.AccOutput_DataRate = LSM6DSL_ODR_52Hz; 00093 LSM6DSL_InitStructure.Axes_Enable = 0; 00094 LSM6DSL_InitStructure.AccFull_Scale = LSM6DSL_ACC_FULLSCALE_2G; 00095 LSM6DSL_InitStructure.BlockData_Update = LSM6DSL_BDU_BLOCK_UPDATE; 00096 LSM6DSL_InitStructure.High_Resolution = 0; 00097 LSM6DSL_InitStructure.Communication_Mode = 0; 00098 00099 /* Configure MEMS: data rate, full scale */ 00100 ctrl = (LSM6DSL_InitStructure.AccOutput_DataRate | LSM6DSL_InitStructure.AccFull_Scale); 00101 00102 /* Configure MEMS: BDU and Auto-increment for multi read/write */ 00103 ctrl |= ((LSM6DSL_InitStructure.BlockData_Update | LSM6DSL_ACC_GYRO_IF_INC_ENABLED) << 8); 00104 00105 /* Configure the ACCELERO accelerometer main parameters */ 00106 AccelerometerDrv->Init(ctrl); 00107 } 00108 00109 return ret; 00110 } 00111 00112 /** 00113 * @brief DeInitialize the ACCELERO. 00114 * @retval None. 00115 */ 00116 void BSP_ACCELERO_DeInit(void) 00117 { 00118 /* DeInitialize the accelerometer IO interfaces */ 00119 if(AccelerometerDrv != NULL) 00120 { 00121 if(AccelerometerDrv->DeInit != NULL) 00122 { 00123 AccelerometerDrv->DeInit(); 00124 } 00125 } 00126 } 00127 00128 /** 00129 * @brief Set/Unset the ACCELERO in low power mode. 00130 * @param status 0 means disable Low Power Mode, otherwise Low Power Mode is enabled 00131 * @retval None 00132 */ 00133 void BSP_ACCELERO_LowPower(uint16_t status) 00134 { 00135 /* Set/Unset the ACCELERO in low power mode */ 00136 if(AccelerometerDrv != NULL) 00137 { 00138 if(AccelerometerDrv->LowPower != NULL) 00139 { 00140 AccelerometerDrv->LowPower(status); 00141 } 00142 } 00143 } 00144 00145 /** 00146 * @brief Get XYZ acceleration values. 00147 * @param pDataXYZ Pointer on 3 angular accelerations table with 00148 * pDataXYZ[0] = X axis, pDataXYZ[1] = Y axis, pDataXYZ[2] = Z axis 00149 * @retval None 00150 */ 00151 void BSP_ACCELERO_AccGetXYZ(int16_t *pDataXYZ) 00152 { 00153 if(AccelerometerDrv != NULL) 00154 { 00155 if(AccelerometerDrv->GetXYZ != NULL) 00156 { 00157 AccelerometerDrv->GetXYZ(pDataXYZ); 00158 } 00159 } 00160 } 00161 /** 00162 * @} 00163 */ 00164 00165 /** 00166 * @} 00167 */ 00168 00169 /** 00170 * @} 00171 */ 00172 00173 /** 00174 * @} 00175 */ 00176 00177 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 15:06:31 by
1.7.2
