Pierre Bizouard / BSP_DISCO_F429ZI

Dependents:   DISCO-F429ZI_LCDTS_demo_richard

Fork of BSP_DISCO_F429ZI by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f429i_discovery_gyroscope.c Source File

stm32f429i_discovery_gyroscope.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f429i_discovery_gyroscope.c
00004   * @author  MCD Application Team
00005   * @brief   This file provides a set of functions needed to manage the
00006   *          MEMS gyroscope available on STM32F429I-Discovery Kit.
00007   ******************************************************************************
00008   * @attention
00009   *
00010   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00011   *
00012   * Redistribution and use in source and binary forms, with or without modification,
00013   * are permitted provided that the following conditions are met:
00014   *   1. Redistributions of source code must retain the above copyright notice,
00015   *      this list of conditions and the following disclaimer.
00016   *   2. Redistributions in binary form must reproduce the above copyright notice,
00017   *      this list of conditions and the following disclaimer in the documentation
00018   *      and/or other materials provided with the distribution.
00019   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00020   *      may be used to endorse or promote products derived from this software
00021   *      without specific prior written permission.
00022   *
00023   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00026   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00027   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00029   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00031   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00032   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033   *
00034   ******************************************************************************
00035   */
00036 /* Includes ------------------------------------------------------------------*/
00037 #include "stm32f429i_discovery_gyroscope.h"
00038 
00039 /** @addtogroup BSP
00040   * @{
00041   */ 
00042 
00043 /** @addtogroup STM32F429I_DISCOVERY
00044   * @{
00045   */ 
00046 
00047 /** @defgroup STM32F429I_DISCOVERY_GYROSCOPE STM32F429I DISCOVERY GYROSCOPE
00048   * @{
00049   */
00050 
00051 /** @defgroup STM32F429I_DISCOVERY_GYROSCOPE_Private_TypesDefinitions STM32F429I DISCOVERY GYROSCOPE Private TypesDefinitions
00052   * @{
00053   */
00054 /**
00055   * @}
00056   */
00057 
00058 /** @defgroup STM32F429I_DISCOVERY_GYROSCOPE_Private_Defines STM32F429I DISCOVERY GYROSCOPE Private Defines
00059   * @{
00060   */
00061 /**
00062   * @}
00063   */
00064 
00065 /** @defgroup STM32F429I_DISCOVERY_GYROSCOPE_Private_Macros STM32F429I DISCOVERY GYROSCOPE Private Macros
00066   * @{
00067   */
00068 /**
00069   * @}
00070   */ 
00071   
00072 /** @defgroup STM32F429I_DISCOVERY_GYROSCOPE_Private_Variables STM32F429I DISCOVERY GYROSCOPE Private Variables
00073   * @{
00074   */ 
00075 static GYRO_DrvTypeDef *GyroscopeDrv;
00076 
00077 /**
00078   * @}
00079   */
00080 
00081 /** @defgroup STM32F429I_DISCOVERY_GYROSCOPE_Private_FunctionPrototypes STM32F429I DISCOVERY GYROSCOPE Private FunctionPrototypes
00082   * @{
00083   */
00084 /**
00085   * @}
00086   */
00087 
00088 /** @defgroup STM32F429I_DISCOVERY_GYROSCOPE_Private_Functions STM32F429I DISCOVERY GYROSCOPE Private Functions
00089   * @{
00090   */
00091   
00092 /**
00093   * @brief  Set Gyroscope Initialization.
00094   * @retval GYRO_OK if no problem during initialization
00095   */
00096 uint8_t BSP_GYRO_Init(void)
00097 {  
00098   uint8_t ret = GYRO_ERROR;
00099   uint16_t ctrl = 0x0000;
00100   GYRO_InitTypeDef L3GD20_InitStructure;
00101   GYRO_FilterConfigTypeDef L3GD20_FilterStructure={0,0};
00102 
00103   if((L3gd20Drv.ReadID() == I_AM_L3GD20) || (L3gd20Drv.ReadID() == I_AM_L3GD20_TR))
00104   { 
00105     /* Initialize the Gyroscope driver structure */
00106     GyroscopeDrv = &L3gd20Drv;
00107 
00108     /* MEMS configuration ----------------------------------------------------*/
00109     /* Fill the Gyroscope structure */
00110     L3GD20_InitStructure.Power_Mode = L3GD20_MODE_ACTIVE;
00111     L3GD20_InitStructure.Output_DataRate = L3GD20_OUTPUT_DATARATE_1;
00112     L3GD20_InitStructure.Axes_Enable = L3GD20_AXES_ENABLE;
00113     L3GD20_InitStructure.Band_Width = L3GD20_BANDWIDTH_4;
00114     L3GD20_InitStructure.BlockData_Update = L3GD20_BlockDataUpdate_Continous;
00115     L3GD20_InitStructure.Endianness = L3GD20_BLE_LSB;
00116     L3GD20_InitStructure.Full_Scale = L3GD20_FULLSCALE_500; 
00117 
00118     /* Configure MEMS: data rate, power mode, full scale and axes */
00119     ctrl = (uint16_t) (L3GD20_InitStructure.Power_Mode | L3GD20_InitStructure.Output_DataRate | \
00120                        L3GD20_InitStructure.Axes_Enable | L3GD20_InitStructure.Band_Width);
00121 
00122     ctrl |= (uint16_t) ((L3GD20_InitStructure.BlockData_Update | L3GD20_InitStructure.Endianness | \
00123                          L3GD20_InitStructure.Full_Scale) << 8);
00124     
00125     /* Configure the Gyroscope main parameters */    
00126     GyroscopeDrv->Init(ctrl);
00127 
00128     L3GD20_FilterStructure.HighPassFilter_Mode_Selection = L3GD20_HPM_NORMAL_MODE_RES;
00129     L3GD20_FilterStructure.HighPassFilter_CutOff_Frequency = L3GD20_HPFCF_0;
00130 
00131     ctrl = (uint8_t) ((L3GD20_FilterStructure.HighPassFilter_Mode_Selection |\
00132                        L3GD20_FilterStructure.HighPassFilter_CutOff_Frequency));
00133 
00134     /* Configure the Gyroscope main parameters */
00135     GyroscopeDrv->FilterConfig(ctrl) ;
00136 
00137     GyroscopeDrv->FilterCmd(L3GD20_HIGHPASSFILTER_ENABLE);
00138 
00139     ret = GYRO_OK;
00140   }
00141   else
00142   {
00143     ret = GYRO_ERROR;
00144   }
00145   return ret;
00146 }
00147 
00148 /**
00149   * @brief  Read ID of Gyroscope component.
00150   * @retval ID
00151   */
00152 uint8_t BSP_GYRO_ReadID(void)
00153 {
00154   uint8_t id = 0x00;
00155   
00156   if(GyroscopeDrv->ReadID != NULL)
00157   {
00158     id = GyroscopeDrv->ReadID();
00159   }  
00160   return id;
00161 }
00162 
00163 /**
00164   * @brief  Reboot memory content of Gyroscope.
00165   */
00166 void BSP_GYRO_Reset(void)
00167 {
00168   if(GyroscopeDrv->Reset != NULL)
00169   {
00170     GyroscopeDrv->Reset();
00171   }
00172 }
00173 
00174 /**
00175   * @brief  Configures INT1 interrupt.
00176   * @param  pIntConfig: pointer to a L3GD20_InterruptConfig_TypeDef 
00177   *         structure that contains the configuration setting for the L3GD20 Interrupt.
00178   */
00179 void BSP_GYRO_ITConfig(GYRO_InterruptConfigTypeDef *pIntConfig)
00180 {  
00181   uint16_t interruptconfig = 0x0000;
00182   
00183   if(GyroscopeDrv->ConfigIT != NULL)
00184   {
00185     /* Configure latch Interrupt request and axe interrupts */                   
00186     interruptconfig |= ((uint8_t)(pIntConfig->Latch_Request| \
00187                                   pIntConfig->Interrupt_Axes) << 8);
00188     
00189     interruptconfig |= (uint8_t)(pIntConfig->Interrupt_ActiveEdge);
00190     
00191     GyroscopeDrv->ConfigIT(interruptconfig);
00192   }  
00193 }
00194 
00195 /**
00196   * @brief  Enables INT1 or INT2 interrupt.
00197   * @param  IntPin: Interrupt pin 
00198   *      This parameter can be: 
00199   *        @arg L3GD20_INT1
00200   *        @arg L3GD20_INT2
00201   */
00202 void BSP_GYRO_EnableIT(uint8_t IntPin)
00203 {  
00204   if(GyroscopeDrv->EnableIT != NULL)
00205   {
00206     GyroscopeDrv->EnableIT(IntPin);
00207   }
00208 }
00209 
00210 /**
00211   * @brief  Disables INT1 or INT2 interrupt.
00212   * @param  IntPin: Interrupt pin 
00213   *      This parameter can be: 
00214   *        @arg L3GD20_INT1
00215   *        @arg L3GD20_INT2
00216   */
00217 void BSP_GYRO_DisableIT(uint8_t IntPin)
00218 {  
00219   if(GyroscopeDrv->DisableIT != NULL)
00220   {
00221     GyroscopeDrv->DisableIT(IntPin);
00222   }
00223 }
00224 
00225 /**
00226   * @brief  Gets XYZ angular acceleration/
00227   * @param  pfData: pointer on floating array         
00228   */
00229 void BSP_GYRO_GetXYZ(float *pfData)
00230 {
00231   if(GyroscopeDrv->GetXYZ!= NULL)
00232   {
00233     GyroscopeDrv->GetXYZ(pfData);
00234   }
00235 }
00236 
00237 /**
00238   * @}
00239   */ 
00240 
00241 /**
00242   * @}
00243   */ 
00244   
00245 /**
00246   * @}
00247   */ 
00248 
00249 /**
00250   * @}
00251   */ 
00252 
00253 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/