E&R S3 prime / BSP_DISCO_L476VG
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l476g_discovery_gyroscope.c Source File

stm32l476g_discovery_gyroscope.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l476g_discovery_gyroscope.c
00004   * @author  MCD Application Team
00005   * @brief   This file provides a set of functions needed to manage the L3GD20
00006   *          MEMS accelerometer available on STM32L476G-Discovery board.
00007   ******************************************************************************
00008   * @attention
00009   *
00010   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00011   * All rights reserved.</center></h2>
00012   *
00013   * This software component is licensed by ST under BSD 3-Clause license,
00014   * the "License"; You may not use this file except in compliance with the
00015   * License. You may obtain a copy of the License at:
00016   *                        opensource.org/licenses/BSD-3-Clause
00017   *
00018   ******************************************************************************
00019   */
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32l476g_discovery_gyroscope.h"
00023 
00024 /** @addtogroup BSP
00025   * @{
00026   */
00027 
00028 /** @addtogroup STM32L476G_DISCOVERY
00029   * @{
00030   */
00031 
00032 /** @defgroup STM32L476G_DISCOVERY_GYROSCOPE STM32L476G-DISCOVERY GYROSCOPE
00033   * @{
00034   */
00035 
00036 /* Private typedef -----------------------------------------------------------*/
00037 /** @defgroup STM32L476G_DISCOVERY_GYROSCOPE_Private_Types Private Types
00038   * @{
00039   */
00040 /**
00041   * @}
00042   */
00043 
00044 /* Private defines ------------------------------------------------------------*/
00045 /** @defgroup STM32L476G_DISCOVERY_GYROSCOPE_Private_Constants Private Constants
00046   * @{
00047   */
00048 /**
00049   * @}
00050   */
00051 
00052 /* Private macros ------------------------------------------------------------*/
00053 /** @defgroup STM32L476G_DISCOVERY_GYROSCOPE_Private_Macros Private Macros
00054   * @{
00055   */
00056 /**
00057   * @}
00058   */
00059 
00060 /* Private variables ---------------------------------------------------------*/
00061 /** @defgroup STM32L476G_DISCOVERY_GYROSCOPE_Private_Variables Private Variables
00062   * @{
00063   */
00064 static GYRO_DrvTypeDef *GyroscopeDrv;
00065 
00066 /**
00067   * @}
00068   */
00069 
00070 /* Private function prototypes -----------------------------------------------*/
00071 /** @defgroup STM32L476G_DISCOVERY_GYROSCOPE_Private_FunctionPrototypes Private Functions
00072   * @{
00073   */
00074 /**
00075   * @}
00076   */
00077 
00078 /* Exported functions --------------------------------------------------------*/
00079 /** @addtogroup STM32L476G_DISCOVERY_GYROSCOPE_Exported_Functions
00080   * @{
00081   */
00082 
00083 /**
00084   * @brief  Initialize Gyroscope.
00085   * @retval GYRO_OK or GYRO_ERROR
00086   */
00087 uint8_t BSP_GYRO_Init(void)
00088 {
00089   uint8_t ret = GYRO_ERROR;
00090   uint16_t ctrl = 0x0000;
00091   GYRO_InitTypeDef L3GD20_InitStructure;
00092   GYRO_FilterConfigTypeDef L3GD20_FilterStructure = {0, 0};
00093 
00094   if ((L3gd20Drv.ReadID() == I_AM_L3GD20) || (L3gd20Drv.ReadID() == I_AM_L3GD20_TR))
00095   {
00096     /* Initialize the gyroscope driver structure */
00097     GyroscopeDrv = &L3gd20Drv;
00098 
00099     /* Configure Mems : data rate, power mode, full scale and axes */
00100     L3GD20_InitStructure.Power_Mode = L3GD20_MODE_ACTIVE;
00101     L3GD20_InitStructure.Output_DataRate = L3GD20_OUTPUT_DATARATE_1;
00102     L3GD20_InitStructure.Axes_Enable = L3GD20_AXES_ENABLE;
00103     L3GD20_InitStructure.Band_Width = L3GD20_BANDWIDTH_4;
00104     L3GD20_InitStructure.BlockData_Update = L3GD20_BlockDataUpdate_Continous;
00105     L3GD20_InitStructure.Endianness = L3GD20_BLE_LSB;
00106     L3GD20_InitStructure.Full_Scale = L3GD20_FULLSCALE_2000;
00107     /* Configure MEMS: data rate, power mode, full scale and axes */
00108     ctrl = (uint16_t)(L3GD20_InitStructure.Power_Mode | L3GD20_InitStructure.Output_DataRate | \
00109                       L3GD20_InitStructure.Axes_Enable | L3GD20_InitStructure.Band_Width);
00110 
00111     ctrl |= (uint16_t)((L3GD20_InitStructure.BlockData_Update | L3GD20_InitStructure.Endianness | \
00112                         L3GD20_InitStructure.Full_Scale) << 8);
00113 
00114     /* Initialize component */
00115     GyroscopeDrv->Init(ctrl);
00116 
00117     L3GD20_FilterStructure.HighPassFilter_Mode_Selection = L3GD20_HPM_NORMAL_MODE_RES;
00118     L3GD20_FilterStructure.HighPassFilter_CutOff_Frequency = L3GD20_HPFCF_0;
00119 
00120     ctrl = (uint8_t)((L3GD20_FilterStructure.HighPassFilter_Mode_Selection | \
00121                       L3GD20_FilterStructure.HighPassFilter_CutOff_Frequency));
00122 
00123     /* Configure component filter */
00124     GyroscopeDrv->FilterConfig(ctrl) ;
00125 
00126     /* Enable component filter */
00127     GyroscopeDrv->FilterCmd(L3GD20_HIGHPASSFILTER_ENABLE);
00128 
00129     ret = GYRO_OK;
00130   }
00131   else
00132   {
00133     ret = GYRO_ERROR;
00134   }
00135 
00136   return ret;
00137 }
00138 
00139 
00140 /**
00141   * @brief  DeInitialize Gyroscope.
00142   * @retval None
00143   */
00144 void BSP_GYRO_DeInit(void)
00145 {
00146   GYRO_IO_DeInit();
00147 }
00148 
00149 
00150 /**
00151   * @brief  Put Gyroscope in low power mode.
00152   * @retval None
00153   */
00154 void BSP_GYRO_LowPower(void)
00155 {
00156   uint16_t ctrl = 0x0000;
00157   GYRO_InitTypeDef L3GD20_InitStructure;
00158 
00159   /* configure only Power_Mode field */
00160   L3GD20_InitStructure.Power_Mode = L3GD20_MODE_POWERDOWN;
00161 
00162   ctrl = (uint16_t)(L3GD20_InitStructure.Power_Mode);
00163 
00164   /* Set component in low-power mode */
00165   GyroscopeDrv->LowPower(ctrl);
00166 
00167 
00168 }
00169 
00170 /**
00171   * @brief  Read ID of Gyroscope component.
00172   * @retval ID
00173   */
00174 uint8_t BSP_GYRO_ReadID(void)
00175 {
00176   uint8_t id = 0x00;
00177 
00178   if (GyroscopeDrv->ReadID != NULL)
00179   {
00180     id = GyroscopeDrv->ReadID();
00181   }
00182   return id;
00183 }
00184 
00185 /**
00186   * @brief  Reboot memory content of Gyroscope.
00187   * @retval None
00188   */
00189 void BSP_GYRO_Reset(void)
00190 {
00191   if (GyroscopeDrv->Reset != NULL)
00192   {
00193     GyroscopeDrv->Reset();
00194   }
00195 }
00196 
00197 /**
00198   * @brief  Configure Gyroscope interrupts (INT1 or INT2).
00199   * @param  pIntConfig: pointer to a GYRO_InterruptConfigTypeDef
00200   *         structure that contains the configuration setting for the L3GD20 Interrupt.
00201   * @retval None
00202   */
00203 void BSP_GYRO_ITConfig(GYRO_InterruptConfigTypeDef *pIntConfig)
00204 {
00205   uint16_t interruptconfig = 0x0000;
00206 
00207   if (GyroscopeDrv->ConfigIT != NULL)
00208   {
00209     /* Configure latch Interrupt request and axe interrupts */
00210     interruptconfig |= ((uint8_t)(pIntConfig->Latch_Request | \
00211                                   pIntConfig->Interrupt_Axes) << 8);
00212 
00213     interruptconfig |= (uint8_t)(pIntConfig->Interrupt_ActiveEdge);
00214 
00215     GyroscopeDrv->ConfigIT(interruptconfig);
00216   }
00217 }
00218 
00219 /**
00220   * @brief  Enable Gyroscope interrupts (INT1 or INT2).
00221   * @param  IntPin: Interrupt pin
00222   *      This parameter can be:
00223   *        @arg L3GD20_INT1
00224   *        @arg L3GD20_INT2
00225   * @retval None
00226   */
00227 void BSP_GYRO_EnableIT(uint8_t IntPin)
00228 {
00229   if (GyroscopeDrv->EnableIT != NULL)
00230   {
00231     GyroscopeDrv->EnableIT(IntPin);
00232   }
00233 }
00234 
00235 /**
00236   * @brief  Disable Gyroscope interrupts (INT1 or INT2).
00237   * @param  IntPin: Interrupt pin
00238   *      This parameter can be:
00239   *        @arg L3GD20_INT1
00240   *        @arg L3GD20_INT2
00241   * @retval None
00242   */
00243 void BSP_GYRO_DisableIT(uint8_t IntPin)
00244 {
00245   if (GyroscopeDrv->DisableIT != NULL)
00246   {
00247     GyroscopeDrv->DisableIT(IntPin);
00248   }
00249 }
00250 
00251 /**
00252   * @brief  Get XYZ angular acceleration from the Gyroscope.
00253   * @param  pfData: pointer on floating array
00254   * @retval None
00255   */
00256 void BSP_GYRO_GetXYZ(float *pfData)
00257 {
00258   if (GyroscopeDrv->GetXYZ != NULL)
00259   {
00260     GyroscopeDrv->GetXYZ(pfData);
00261   }
00262 }
00263 
00264 /**
00265   * @}
00266   */
00267 
00268 /**
00269   * @}
00270   */
00271 
00272 /**
00273   * @}
00274   */
00275 
00276 /**
00277   * @}
00278   */
00279 
00280 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/