Contains the BSP driver for the B-L475E-IOT01 board.

Dependents:   mbed-os-example-ble-Thermometer DISCO_L475VG_IOT01-Telegram-BOT DISCO_L475VG_IOT01-sche_cheveux DISCO_L475VG_IOT01-QSPI_FLASH_FILE_SYSTEM ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l475e_iot01_magneto.c Source File

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   * @brief   This file provides a set of functions needed to manage the magnetometer sensor
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
00010   * All rights reserved.</center></h2>
00011   *
00012   * This software component is licensed by ST under BSD 3-Clause license,
00013   * the "License"; You may not use this file except in compliance with the
00014   * License. You may obtain a copy of the License at:
00015   *                        opensource.org/licenses/BSD-3-Clause
00016   *
00017   ******************************************************************************
00018   */
00019 
00020 /* Includes ------------------------------------------------------------------*/
00021 #include "stm32l475e_iot01_magneto.h"
00022 
00023 /** @addtogroup BSP
00024   * @{
00025   */
00026 
00027 /** @addtogroup STM32L475E_IOT01
00028   * @{
00029   */
00030       
00031 /** @defgroup STM32L475E_IOT01_MAGNETO MAGNETO
00032   * @{
00033   */ 
00034 
00035 /** @defgroup STM32L475E_IOT01_MAGNETO_Private_Variables MAGNETO Private Variables
00036   * @{
00037   */
00038 static MAGNETO_DrvTypeDef  *MagnetoDrv;
00039 /**
00040   * @}
00041   */
00042 
00043 
00044 /** @defgroup STM32L475E_IOT01_MAGNETO_Private_Functions MAGNETO Private Functions
00045   * @{
00046   */
00047 
00048 /**
00049  * @brief Initialize a magnetometer sensor
00050  * @retval COMPONENT_ERROR in case of failure
00051  */
00052 MAGNETO_StatusTypeDef BSP_MAGNETO_Init(void)
00053 {
00054   MAGNETO_StatusTypeDef ret = MAGNETO_OK;
00055   MAGNETO_InitTypeDef LIS3MDL_InitStructureMag;
00056 
00057   if(Lis3mdlMagDrv.ReadID() != I_AM_LIS3MDL)
00058   {
00059     ret = MAGNETO_ERROR;
00060   }
00061   else
00062   {
00063     /* Initialize the MAGNETO magnetometer driver structure */
00064     MagnetoDrv = &Lis3mdlMagDrv;
00065     
00066     /* MEMS configuration ------------------------------------------------------*/
00067     /* Fill the MAGNETO magnetometer structure */
00068     LIS3MDL_InitStructureMag.Register1 = LIS3MDL_MAG_TEMPSENSOR_DISABLE | LIS3MDL_MAG_OM_XY_HIGH | LIS3MDL_MAG_ODR_40_HZ;
00069     LIS3MDL_InitStructureMag.Register2 = LIS3MDL_MAG_FS_4_GA | LIS3MDL_MAG_REBOOT_DEFAULT | LIS3MDL_MAG_SOFT_RESET_DEFAULT;
00070     LIS3MDL_InitStructureMag.Register3 = LIS3MDL_MAG_CONFIG_NORMAL_MODE | LIS3MDL_MAG_CONTINUOUS_MODE;
00071     LIS3MDL_InitStructureMag.Register4 = LIS3MDL_MAG_OM_Z_HIGH | LIS3MDL_MAG_BLE_LSB;
00072     LIS3MDL_InitStructureMag.Register5 = LIS3MDL_MAG_BDU_MSBLSB;
00073     /* Configure the MAGNETO magnetometer main parameters */
00074     MagnetoDrv->Init(LIS3MDL_InitStructureMag);
00075   } 
00076 
00077   return ret;  
00078 }
00079 
00080 /**
00081   * @brief  DeInitialize the MAGNETO.
00082   */
00083 void BSP_MAGNETO_DeInit(void)
00084 {
00085   /* DeInitialize the  magnetometer IO interfaces */
00086   if(MagnetoDrv != NULL)
00087   {
00088     if(MagnetoDrv->DeInit != NULL)
00089     {
00090       MagnetoDrv->DeInit();
00091     }
00092   }
00093 }
00094 
00095 /**
00096   * @brief  Set/Unset the MAGNETO in low power mode.
00097   */
00098 void BSP_MAGNETO_LowPower(uint16_t status)
00099 {
00100   /* Put the magnetometer in low power mode */
00101   if(MagnetoDrv != NULL)
00102   {
00103     if(MagnetoDrv->LowPower != NULL)
00104     {
00105       MagnetoDrv->LowPower(status);
00106     }
00107   }
00108 }
00109 
00110 /**
00111   * @brief  Get XYZ magnetometer values.
00112   * @param  pDataXYZ Pointer on 3 magnetometer values table with
00113   *                  pDataXYZ[0] = X axis, pDataXYZ[1] = Y axis, pDataXYZ[2] = Z axis 
00114   */
00115 void BSP_MAGNETO_GetXYZ(int16_t *pDataXYZ)
00116 {
00117   if(MagnetoDrv != NULL)
00118   {
00119     if(MagnetoDrv->GetXYZ != NULL)
00120     {   
00121       MagnetoDrv->GetXYZ(pDataXYZ);
00122     }
00123   }
00124 }
00125 
00126 /**
00127   * @}
00128   */
00129 
00130 /**
00131   * @}
00132   */
00133 
00134 /**
00135   * @}
00136   */
00137 
00138 /**
00139   * @}
00140   */
00141 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/