B-L475E-IOT01 BSP User Manual: stm32l475e_iot01_magneto.c Source File

B-L475E-IOT01 BSP Driver

stm32l475e_iot01_magneto.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l475e_iot01_magneto.c
00004   * @author  MCD Application Team
00005   * @version V1.0.0
00006   * @date    17-March-2017
00007   * @brief   This file provides a set of functions needed to manage the magnetometer sensor
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
00012   * All rights reserved.</center></h2>
00013   *
00014   * Redistribution and use in source and binary forms, with or without
00015   * modification, are permitted, provided that the following conditions are met:
00016   *
00017   * 1. Redistribution of source code must retain the above copyright notice,
00018   *    this list of conditions and the following disclaimer.
00019   * 2. Redistributions in binary form must reproduce the above copyright notice,
00020   *    this list of conditions and the following disclaimer in the documentation
00021   *    and/or other materials provided with the distribution.
00022   * 3. Neither the name of STMicroelectronics nor the names of other
00023   *    contributors to this software may be used to endorse or promote products
00024   *    derived from this software without specific written permission.
00025   * 4. This software, including modifications and/or derivative works of this
00026   *    software, must execute solely and exclusively on microcontroller or
00027   *    microprocessor devices manufactured by or for STMicroelectronics.
00028   * 5. Redistribution and use of this software other than as permitted under
00029   *    this license is void and will automatically terminate your rights under
00030   *    this license.
00031   *
00032   * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
00033   * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
00034   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
00035   * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
00036   * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
00037   * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00038   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00039   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00040   * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00041   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00042   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00043   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00044   *
00045   ******************************************************************************
00046   */
00047 
00048 /* Includes ------------------------------------------------------------------*/
00049 #include "stm32l475e_iot01_magneto.h"
00050 
00051 /** @addtogroup BSP
00052   * @{
00053   */
00054 
00055 /** @addtogroup STM32L475E_IOT01
00056   * @{
00057   */
00058       
00059 /** @defgroup STM32L475E_IOT01_MAGNETO MAGNETO
00060   * @{
00061   */ 
00062 
00063 /** @defgroup STM32L475E_IOT01_MAGNETO_Private_Variables MAGNETO Private Variables
00064   * @{
00065   */
00066 static MAGNETO_DrvTypeDef  *MagnetoDrv;
00067 /**
00068   * @}
00069   */
00070 
00071 
00072 /** @defgroup STM32L475E_IOT01_MAGNETO_Private_Functions MAGNETO Private Functions
00073   * @{
00074   */
00075 
00076 /**
00077  * @brief Initialize a magnetometer sensor
00078  * @retval COMPONENT_ERROR in case of failure
00079  */
00080 MAGNETO_StatusTypeDef BSP_MAGNETO_Init(void)
00081 {
00082   MAGNETO_StatusTypeDef ret = MAGNETO_OK;
00083   MAGNETO_InitTypeDef LIS3MDL_InitStructureMag;
00084 
00085   if(Lis3mdlMagDrv.ReadID() != I_AM_LIS3MDL)
00086   {
00087     ret = MAGNETO_ERROR;
00088   }
00089   else
00090   {
00091     /* Initialize the MAGNETO magnetometer driver structure */
00092     MagnetoDrv = &Lis3mdlMagDrv;
00093     
00094     /* MEMS configuration ------------------------------------------------------*/
00095     /* Fill the MAGNETO magnetometer structure */
00096     LIS3MDL_InitStructureMag.Register1 = LIS3MDL_MAG_TEMPSENSOR_DISABLE | LIS3MDL_MAG_OM_XY_HIGH | LIS3MDL_MAG_ODR_40_HZ;
00097     LIS3MDL_InitStructureMag.Register2 = LIS3MDL_MAG_FS_4_GA | LIS3MDL_MAG_REBOOT_DEFAULT | LIS3MDL_MAG_SOFT_RESET_DEFAULT;
00098     LIS3MDL_InitStructureMag.Register3 = LIS3MDL_MAG_CONFIG_NORMAL_MODE | LIS3MDL_MAG_CONTINUOUS_MODE;
00099     LIS3MDL_InitStructureMag.Register4 = LIS3MDL_MAG_OM_Z_HIGH | LIS3MDL_MAG_BLE_LSB;
00100     LIS3MDL_InitStructureMag.Register5 = LIS3MDL_MAG_BDU_MSBLSB;
00101     /* Configure the MAGNETO magnetometer main parameters */
00102     MagnetoDrv->Init(LIS3MDL_InitStructureMag);
00103   } 
00104 
00105   return ret;  
00106 }
00107 
00108 /**
00109   * @brief  DeInitialize the MAGNETO.
00110   */
00111 void BSP_MAGNETO_DeInit(void)
00112 {
00113   /* DeInitialize the  magnetometer IO interfaces */
00114   if(MagnetoDrv != NULL)
00115   {
00116     if(MagnetoDrv->DeInit != NULL)
00117     {
00118       MagnetoDrv->DeInit();
00119     }
00120   }
00121 }
00122 
00123 /**
00124   * @brief  Set/Unset the MAGNETO in low power mode.
00125   */
00126 void BSP_MAGNETO_LowPower(uint16_t status)
00127 {
00128   /* Put the magnetometer in low power mode */
00129   if(MagnetoDrv != NULL)
00130   {
00131     if(MagnetoDrv->LowPower != NULL)
00132     {
00133       MagnetoDrv->LowPower(status);
00134     }
00135   }
00136 }
00137 
00138 /**
00139   * @brief  Get XYZ magnetometer values.
00140   * @param  pDataXYZ Pointer on 3 magnetometer values table with
00141   *                  pDataXYZ[0] = X axis, pDataXYZ[1] = Y axis, pDataXYZ[2] = Z axis 
00142   */
00143 void BSP_MAGNETO_GetXYZ(int16_t *pDataXYZ)
00144 {
00145   if(MagnetoDrv != NULL)
00146   {
00147     if(MagnetoDrv->GetXYZ != NULL)
00148     {   
00149       MagnetoDrv->GetXYZ(pDataXYZ);
00150     }
00151   }
00152 }
00153 
00154 /**
00155   * @}
00156   */
00157 
00158 /**
00159   * @}
00160   */
00161 
00162 /**
00163   * @}
00164   */
00165 
00166 /**
00167   * @}
00168   */
00169 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Thu Mar 16 2017 10:38:32 for B-L475E-IOT01 BSP User Manual by   doxygen 1.7.6.1