2019-04-30 17:27:23 +01:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @file stm32f411e_discovery_accelerometer.c
|
|
|
|
* @author MCD Application Team
|
|
|
|
* @brief This file provides a set of functions needed to manage the
|
|
|
|
* MEMS accelerometer available on STM32F411E-Discovery Kit.
|
|
|
|
******************************************************************************
|
|
|
|
* @attention
|
|
|
|
*
|
|
|
|
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
******************************************************************************
|
2021-03-03 14:55:52 +01:00
|
|
|
*/
|
2019-04-30 17:27:23 +01:00
|
|
|
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
|
#include "stm32f411e_discovery_accelerometer.h"
|
|
|
|
|
|
|
|
/** @addtogroup BSP
|
|
|
|
* @{
|
2021-03-03 14:55:52 +01:00
|
|
|
*/
|
2019-04-30 17:27:23 +01:00
|
|
|
|
|
|
|
/** @addtogroup STM32F411E_DISCOVERY
|
|
|
|
* @{
|
2021-03-03 14:55:52 +01:00
|
|
|
*/
|
2019-04-30 17:27:23 +01:00
|
|
|
|
|
|
|
/** @defgroup STM32F411E_DISCOVERY_ACCELEROMETER STM32F411E DISCOVERY ACCELEROMETER
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @defgroup STM32F411E_DISCOVERY_ACCELEROMETER_Private_TypesDefinitions STM32F411E DISCOVERY ACCELEROMETER Private TypesDefinitions
|
|
|
|
* @{
|
2021-03-03 14:55:52 +01:00
|
|
|
*/
|
2019-04-30 17:27:23 +01:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @defgroup STM32F411E_DISCOVERY_ACCELEROMETER_Private_Defines STM32F411E DISCOVERY ACCELEROMETER Private Defines
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @defgroup STM32F411E_DISCOVERY_ACCELEROMETER_Private_Macros STM32F411E DISCOVERY ACCELEROMETER Private Macros
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @}
|
2021-03-03 14:55:52 +01:00
|
|
|
*/
|
|
|
|
|
2019-04-30 17:27:23 +01:00
|
|
|
/** @defgroup STM32F411E_DISCOVERY_ACCELEROMETER_Private_Variables STM32F411E DISCOVERY ACCELEROMETER Private Variables
|
|
|
|
* @{
|
2021-03-03 14:55:52 +01:00
|
|
|
*/
|
2019-04-30 17:27:23 +01:00
|
|
|
static ACCELERO_DrvTypeDef *AccelerometerDrv;
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @defgroup STM32F411E_DISCOVERY_ACCELEROMETER_Private_FunctionPrototypes STM32F411E DISCOVERY ACCELEROMETER Private FunctionPrototypes
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @defgroup STM32F411E_DISCOVERY_ACCELEROMETER_Private_Functions STM32F411E DISCOVERY ACCELEROMETER Private Functions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-03-03 14:55:52 +01:00
|
|
|
* @brief Set accelerometer Initialization.
|
2019-04-30 17:27:23 +01:00
|
|
|
* @retval ACCELERO_OK if no problem during initialization
|
|
|
|
*/
|
|
|
|
uint8_t BSP_ACCELERO_Init(void)
|
|
|
|
{
|
|
|
|
uint8_t ret = ACCELERO_ERROR;
|
|
|
|
uint16_t ctrl = 0x0000;
|
2021-03-03 14:55:52 +01:00
|
|
|
ACCELERO_InitTypeDef Accelero_InitStructure;
|
|
|
|
ACCELERO_FilterConfigTypeDef Accelero_FilterStructure = {0,0,0,0};
|
|
|
|
|
2019-04-30 17:27:23 +01:00
|
|
|
if(Lsm303dlhcDrv.ReadID() == I_AM_LMS303DLHC)
|
|
|
|
{
|
2021-03-03 14:55:52 +01:00
|
|
|
/* Initialize the accelerometer driver structure */
|
2019-04-30 17:27:23 +01:00
|
|
|
AccelerometerDrv = &Lsm303dlhcDrv;
|
|
|
|
|
|
|
|
/* MEMS configuration ----------------------------------------------------*/
|
2021-03-03 14:55:52 +01:00
|
|
|
/* Fill the accelerometer structure */
|
|
|
|
Accelero_InitStructure.Power_Mode = LSM303DLHC_NORMAL_MODE;
|
|
|
|
Accelero_InitStructure.AccOutput_DataRate = LSM303DLHC_ODR_50_HZ;
|
|
|
|
Accelero_InitStructure.Axes_Enable = LSM303DLHC_AXES_ENABLE;
|
|
|
|
Accelero_InitStructure.AccFull_Scale = LSM303DLHC_FULLSCALE_2G;
|
|
|
|
Accelero_InitStructure.BlockData_Update = LSM303DLHC_BlockUpdate_Continous;
|
|
|
|
Accelero_InitStructure.Endianness = LSM303DLHC_BLE_LSB;
|
|
|
|
Accelero_InitStructure.High_Resolution = LSM303DLHC_HR_ENABLE;
|
|
|
|
|
2019-04-30 17:27:23 +01:00
|
|
|
/* Configure MEMS: data rate, power mode, full scale and axes */
|
2021-03-03 14:55:52 +01:00
|
|
|
ctrl |= (Accelero_InitStructure.Power_Mode | Accelero_InitStructure.AccOutput_DataRate | \
|
|
|
|
Accelero_InitStructure.Axes_Enable);
|
|
|
|
|
|
|
|
ctrl |= ((Accelero_InitStructure.BlockData_Update | Accelero_InitStructure.Endianness | \
|
|
|
|
Accelero_InitStructure.AccFull_Scale | Accelero_InitStructure.High_Resolution) << 8);
|
|
|
|
|
|
|
|
/* Configure the accelerometer main parameters */
|
2019-04-30 17:27:23 +01:00
|
|
|
AccelerometerDrv->Init(ctrl);
|
2021-03-03 14:55:52 +01:00
|
|
|
|
|
|
|
/* Fill the accelerometer LPF structure */
|
|
|
|
Accelero_FilterStructure.HighPassFilter_Mode_Selection = LSM303DLHC_HPM_NORMAL_MODE;
|
|
|
|
Accelero_FilterStructure.HighPassFilter_CutOff_Frequency = LSM303DLHC_HPFCF_16;
|
|
|
|
Accelero_FilterStructure.HighPassFilter_AOI1 = LSM303DLHC_HPF_AOI1_DISABLE;
|
|
|
|
Accelero_FilterStructure.HighPassFilter_AOI2 = LSM303DLHC_HPF_AOI2_DISABLE;
|
|
|
|
|
2019-04-30 17:27:23 +01:00
|
|
|
/* Configure MEMS: mode, cutoff frquency, Filter status, Click, AOI1 and AOI2 */
|
2021-03-03 14:55:52 +01:00
|
|
|
ctrl = (uint8_t) (Accelero_FilterStructure.HighPassFilter_Mode_Selection |\
|
|
|
|
Accelero_FilterStructure.HighPassFilter_CutOff_Frequency |\
|
|
|
|
Accelero_FilterStructure.HighPassFilter_AOI1 |\
|
|
|
|
Accelero_FilterStructure.HighPassFilter_AOI2);
|
2019-04-30 17:27:23 +01:00
|
|
|
|
2021-03-03 14:55:52 +01:00
|
|
|
/* Configure the accelerometer LPF main parameters */
|
2019-04-30 17:27:23 +01:00
|
|
|
AccelerometerDrv->FilterConfig(ctrl);
|
|
|
|
|
|
|
|
ret = ACCELERO_OK;
|
|
|
|
}
|
2021-03-03 14:55:52 +01:00
|
|
|
else if(Lsm303agrDrv.ReadID() == I_AM_LSM303AGR)
|
2019-04-30 17:27:23 +01:00
|
|
|
{
|
2021-03-03 14:55:52 +01:00
|
|
|
/* Initialize the accelerometer driver structure */
|
|
|
|
AccelerometerDrv = &Lsm303agrDrv;
|
|
|
|
|
|
|
|
/* MEMS configuration ----------------------------------------------------*/
|
|
|
|
/* Fill the accelerometer structure */
|
|
|
|
Accelero_InitStructure.Power_Mode = LSM303AGR_NORMAL_MODE;
|
|
|
|
Accelero_InitStructure.AccOutput_DataRate = LSM303AGR_ODR_50_HZ;
|
|
|
|
Accelero_InitStructure.Axes_Enable = LSM303AGR_AXES_ENABLE;
|
|
|
|
Accelero_InitStructure.AccFull_Scale = LSM303AGR_FULLSCALE_2G;
|
|
|
|
Accelero_InitStructure.BlockData_Update = LSM303AGR_BlockUpdate_Continous;
|
|
|
|
Accelero_InitStructure.Endianness = LSM303AGR_BLE_LSB;
|
|
|
|
Accelero_InitStructure.High_Resolution = LSM303AGR_HR_ENABLE;
|
|
|
|
|
|
|
|
/* Configure MEMS: data rate, power mode, full scale and axes */
|
|
|
|
ctrl |= (Accelero_InitStructure.Power_Mode | Accelero_InitStructure.AccOutput_DataRate | \
|
|
|
|
Accelero_InitStructure.Axes_Enable);
|
|
|
|
|
|
|
|
ctrl |= ((Accelero_InitStructure.BlockData_Update | Accelero_InitStructure.Endianness | \
|
|
|
|
Accelero_InitStructure.AccFull_Scale | Accelero_InitStructure.High_Resolution) << 8);
|
|
|
|
|
|
|
|
/* Configure the accelerometer main parameters */
|
|
|
|
AccelerometerDrv->Init(ctrl);
|
|
|
|
|
|
|
|
/* Fill the accelerometer LPF structure */
|
|
|
|
Accelero_FilterStructure.HighPassFilter_Mode_Selection = LSM303AGR_HPM_NORMAL_MODE;
|
|
|
|
Accelero_FilterStructure.HighPassFilter_CutOff_Frequency = LSM303AGR_HPFCF_16;
|
|
|
|
Accelero_FilterStructure.HighPassFilter_AOI1 = LSM303AGR_HPF_AOI1_DISABLE;
|
|
|
|
Accelero_FilterStructure.HighPassFilter_AOI2 = LSM303AGR_HPF_AOI2_DISABLE;
|
|
|
|
|
|
|
|
/* Configure MEMS: mode, cutoff frquency, Filter status, Click, AOI1 and AOI2 */
|
|
|
|
ctrl = (uint8_t) (Accelero_FilterStructure.HighPassFilter_Mode_Selection |\
|
|
|
|
Accelero_FilterStructure.HighPassFilter_CutOff_Frequency |\
|
|
|
|
Accelero_FilterStructure.HighPassFilter_AOI1 |\
|
|
|
|
Accelero_FilterStructure.HighPassFilter_AOI2);
|
|
|
|
|
|
|
|
/* Configure the accelerometer LPF main parameters */
|
|
|
|
AccelerometerDrv->FilterConfig(ctrl);
|
|
|
|
|
|
|
|
ret = ACCELERO_OK;
|
2019-04-30 17:27:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reboot memory content of Accelerometer.
|
|
|
|
*/
|
|
|
|
void BSP_ACCELERO_Reset(void)
|
|
|
|
{
|
|
|
|
if(AccelerometerDrv->Reset != NULL)
|
|
|
|
{
|
|
|
|
AccelerometerDrv->Reset();
|
2021-03-03 14:55:52 +01:00
|
|
|
}
|
2019-04-30 17:27:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-03 14:55:52 +01:00
|
|
|
* @brief Configure accelerometer click IT.
|
2019-04-30 17:27:23 +01:00
|
|
|
*/
|
|
|
|
void BSP_ACCELERO_Click_ITConfig(void)
|
|
|
|
{
|
|
|
|
if(AccelerometerDrv->ConfigIT!= NULL)
|
|
|
|
{
|
|
|
|
AccelerometerDrv->ConfigIT();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get XYZ axes acceleration.
|
2021-03-03 14:55:52 +01:00
|
|
|
* @param pDataXYZ: Pointer to 3 angular acceleration axes.
|
2019-04-30 17:27:23 +01:00
|
|
|
* pDataXYZ[0] = X axis, pDataXYZ[1] = Y axis, pDataXYZ[2] = Z axis
|
|
|
|
*/
|
|
|
|
void BSP_ACCELERO_GetXYZ(int16_t *pDataXYZ)
|
|
|
|
{
|
|
|
|
int16_t SwitchXY = 0;
|
2021-03-03 14:55:52 +01:00
|
|
|
|
2019-04-30 17:27:23 +01:00
|
|
|
if(AccelerometerDrv->GetXYZ!= NULL)
|
|
|
|
{
|
|
|
|
AccelerometerDrv->GetXYZ(pDataXYZ);
|
2021-03-03 14:55:52 +01:00
|
|
|
|
2019-04-30 17:27:23 +01:00
|
|
|
/* Switch X and Y Axes in case of LSM303DLHC MEMS */
|
|
|
|
if(AccelerometerDrv == &Lsm303dlhcDrv)
|
2021-03-03 14:55:52 +01:00
|
|
|
{
|
2019-04-30 17:27:23 +01:00
|
|
|
SwitchXY = pDataXYZ[0];
|
|
|
|
pDataXYZ[0] = pDataXYZ[1];
|
2021-03-03 14:55:52 +01:00
|
|
|
|
2019-04-30 17:27:23 +01:00
|
|
|
/* Invert Y Axis to be conpliant with LIS3DSH */
|
|
|
|
pDataXYZ[1] = -SwitchXY;
|
2021-03-03 14:55:52 +01:00
|
|
|
}
|
2019-04-30 17:27:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
2021-03-03 14:55:52 +01:00
|
|
|
*/
|
2019-04-30 17:27:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
2021-03-03 14:55:52 +01:00
|
|
|
*/
|
|
|
|
|
2019-04-30 17:27:23 +01:00
|
|
|
/**
|
|
|
|
* @}
|
2021-03-03 14:55:52 +01:00
|
|
|
*/
|
2019-04-30 17:27:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
2021-03-03 14:55:52 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|