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

https://os.mbed.com/platforms/ST-Discovery-L475E-IOT01A/

Committer:
bcostm
Date:
Tue May 02 16:56:17 2017 +0200
Revision:
5:0c70bc6d2dc0
Parent:
3:c6b5944187d5
Child:
6:9dfa42666f03
Update files to BSP driver V1.1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 3:c6b5944187d5 1 /**
bcostm 3:c6b5944187d5 2 ******************************************************************************
bcostm 3:c6b5944187d5 3 * @file stm32l475e_iot01_magneto.c
bcostm 3:c6b5944187d5 4 * @author MCD Application Team
bcostm 5:0c70bc6d2dc0 5 * @version V1.1.0
bcostm 5:0c70bc6d2dc0 6 * @date 21-April-2017
bcostm 3:c6b5944187d5 7 * @brief This file provides a set of functions needed to manage the magnetometer sensor
bcostm 3:c6b5944187d5 8 ******************************************************************************
bcostm 3:c6b5944187d5 9 * @attention
bcostm 3:c6b5944187d5 10 *
bcostm 3:c6b5944187d5 11 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
bcostm 3:c6b5944187d5 12 * All rights reserved.</center></h2>
bcostm 3:c6b5944187d5 13 *
bcostm 3:c6b5944187d5 14 * Redistribution and use in source and binary forms, with or without
bcostm 3:c6b5944187d5 15 * modification, are permitted, provided that the following conditions are met:
bcostm 3:c6b5944187d5 16 *
bcostm 3:c6b5944187d5 17 * 1. Redistribution of source code must retain the above copyright notice,
bcostm 3:c6b5944187d5 18 * this list of conditions and the following disclaimer.
bcostm 3:c6b5944187d5 19 * 2. Redistributions in binary form must reproduce the above copyright notice,
bcostm 3:c6b5944187d5 20 * this list of conditions and the following disclaimer in the documentation
bcostm 3:c6b5944187d5 21 * and/or other materials provided with the distribution.
bcostm 3:c6b5944187d5 22 * 3. Neither the name of STMicroelectronics nor the names of other
bcostm 3:c6b5944187d5 23 * contributors to this software may be used to endorse or promote products
bcostm 3:c6b5944187d5 24 * derived from this software without specific written permission.
bcostm 3:c6b5944187d5 25 * 4. This software, including modifications and/or derivative works of this
bcostm 3:c6b5944187d5 26 * software, must execute solely and exclusively on microcontroller or
bcostm 3:c6b5944187d5 27 * microprocessor devices manufactured by or for STMicroelectronics.
bcostm 3:c6b5944187d5 28 * 5. Redistribution and use of this software other than as permitted under
bcostm 3:c6b5944187d5 29 * this license is void and will automatically terminate your rights under
bcostm 3:c6b5944187d5 30 * this license.
bcostm 3:c6b5944187d5 31 *
bcostm 3:c6b5944187d5 32 * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
bcostm 3:c6b5944187d5 33 * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
bcostm 3:c6b5944187d5 34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
bcostm 3:c6b5944187d5 35 * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
bcostm 3:c6b5944187d5 36 * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
bcostm 3:c6b5944187d5 37 * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
bcostm 3:c6b5944187d5 38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
bcostm 3:c6b5944187d5 39 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
bcostm 3:c6b5944187d5 40 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
bcostm 3:c6b5944187d5 41 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
bcostm 3:c6b5944187d5 42 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
bcostm 3:c6b5944187d5 43 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bcostm 3:c6b5944187d5 44 *
bcostm 3:c6b5944187d5 45 ******************************************************************************
bcostm 3:c6b5944187d5 46 */
bcostm 3:c6b5944187d5 47
bcostm 3:c6b5944187d5 48 /* Includes ------------------------------------------------------------------*/
bcostm 3:c6b5944187d5 49 #include "stm32l475e_iot01_magneto.h"
bcostm 3:c6b5944187d5 50
bcostm 3:c6b5944187d5 51 /** @addtogroup BSP
bcostm 3:c6b5944187d5 52 * @{
bcostm 3:c6b5944187d5 53 */
bcostm 3:c6b5944187d5 54
bcostm 3:c6b5944187d5 55 /** @addtogroup STM32L475E_IOT01
bcostm 3:c6b5944187d5 56 * @{
bcostm 3:c6b5944187d5 57 */
bcostm 3:c6b5944187d5 58
bcostm 3:c6b5944187d5 59 /** @defgroup STM32L475E_IOT01_MAGNETO MAGNETO
bcostm 3:c6b5944187d5 60 * @{
bcostm 3:c6b5944187d5 61 */
bcostm 3:c6b5944187d5 62
bcostm 3:c6b5944187d5 63 /** @defgroup STM32L475E_IOT01_MAGNETO_Private_Variables MAGNETO Private Variables
bcostm 3:c6b5944187d5 64 * @{
bcostm 3:c6b5944187d5 65 */
bcostm 3:c6b5944187d5 66 static MAGNETO_DrvTypeDef *MagnetoDrv;
bcostm 3:c6b5944187d5 67 /**
bcostm 3:c6b5944187d5 68 * @}
bcostm 3:c6b5944187d5 69 */
bcostm 3:c6b5944187d5 70
bcostm 3:c6b5944187d5 71
bcostm 3:c6b5944187d5 72 /** @defgroup STM32L475E_IOT01_MAGNETO_Private_Functions MAGNETO Private Functions
bcostm 3:c6b5944187d5 73 * @{
bcostm 3:c6b5944187d5 74 */
bcostm 3:c6b5944187d5 75
bcostm 3:c6b5944187d5 76 /**
bcostm 3:c6b5944187d5 77 * @brief Initialize a magnetometer sensor
bcostm 3:c6b5944187d5 78 * @retval COMPONENT_ERROR in case of failure
bcostm 3:c6b5944187d5 79 */
bcostm 3:c6b5944187d5 80 MAGNETO_StatusTypeDef BSP_MAGNETO_Init(void)
bcostm 3:c6b5944187d5 81 {
bcostm 3:c6b5944187d5 82 MAGNETO_StatusTypeDef ret = MAGNETO_OK;
bcostm 3:c6b5944187d5 83 MAGNETO_InitTypeDef LIS3MDL_InitStructureMag;
bcostm 3:c6b5944187d5 84
bcostm 3:c6b5944187d5 85 if(Lis3mdlMagDrv.ReadID() != I_AM_LIS3MDL)
bcostm 3:c6b5944187d5 86 {
bcostm 3:c6b5944187d5 87 ret = MAGNETO_ERROR;
bcostm 3:c6b5944187d5 88 }
bcostm 3:c6b5944187d5 89 else
bcostm 3:c6b5944187d5 90 {
bcostm 3:c6b5944187d5 91 /* Initialize the MAGNETO magnetometer driver structure */
bcostm 3:c6b5944187d5 92 MagnetoDrv = &Lis3mdlMagDrv;
bcostm 3:c6b5944187d5 93
bcostm 3:c6b5944187d5 94 /* MEMS configuration ------------------------------------------------------*/
bcostm 3:c6b5944187d5 95 /* Fill the MAGNETO magnetometer structure */
bcostm 3:c6b5944187d5 96 LIS3MDL_InitStructureMag.Register1 = LIS3MDL_MAG_TEMPSENSOR_DISABLE | LIS3MDL_MAG_OM_XY_HIGH | LIS3MDL_MAG_ODR_40_HZ;
bcostm 3:c6b5944187d5 97 LIS3MDL_InitStructureMag.Register2 = LIS3MDL_MAG_FS_4_GA | LIS3MDL_MAG_REBOOT_DEFAULT | LIS3MDL_MAG_SOFT_RESET_DEFAULT;
bcostm 3:c6b5944187d5 98 LIS3MDL_InitStructureMag.Register3 = LIS3MDL_MAG_CONFIG_NORMAL_MODE | LIS3MDL_MAG_CONTINUOUS_MODE;
bcostm 3:c6b5944187d5 99 LIS3MDL_InitStructureMag.Register4 = LIS3MDL_MAG_OM_Z_HIGH | LIS3MDL_MAG_BLE_LSB;
bcostm 3:c6b5944187d5 100 LIS3MDL_InitStructureMag.Register5 = LIS3MDL_MAG_BDU_MSBLSB;
bcostm 3:c6b5944187d5 101 /* Configure the MAGNETO magnetometer main parameters */
bcostm 3:c6b5944187d5 102 MagnetoDrv->Init(LIS3MDL_InitStructureMag);
bcostm 3:c6b5944187d5 103 }
bcostm 3:c6b5944187d5 104
bcostm 3:c6b5944187d5 105 return ret;
bcostm 3:c6b5944187d5 106 }
bcostm 3:c6b5944187d5 107
bcostm 3:c6b5944187d5 108 /**
bcostm 3:c6b5944187d5 109 * @brief DeInitialize the MAGNETO.
bcostm 3:c6b5944187d5 110 */
bcostm 3:c6b5944187d5 111 void BSP_MAGNETO_DeInit(void)
bcostm 3:c6b5944187d5 112 {
bcostm 3:c6b5944187d5 113 /* DeInitialize the magnetometer IO interfaces */
bcostm 3:c6b5944187d5 114 if(MagnetoDrv != NULL)
bcostm 3:c6b5944187d5 115 {
bcostm 3:c6b5944187d5 116 if(MagnetoDrv->DeInit != NULL)
bcostm 3:c6b5944187d5 117 {
bcostm 3:c6b5944187d5 118 MagnetoDrv->DeInit();
bcostm 3:c6b5944187d5 119 }
bcostm 3:c6b5944187d5 120 }
bcostm 3:c6b5944187d5 121 }
bcostm 3:c6b5944187d5 122
bcostm 3:c6b5944187d5 123 /**
bcostm 3:c6b5944187d5 124 * @brief Set/Unset the MAGNETO in low power mode.
bcostm 3:c6b5944187d5 125 */
bcostm 3:c6b5944187d5 126 void BSP_MAGNETO_LowPower(uint16_t status)
bcostm 3:c6b5944187d5 127 {
bcostm 3:c6b5944187d5 128 /* Put the magnetometer in low power mode */
bcostm 3:c6b5944187d5 129 if(MagnetoDrv != NULL)
bcostm 3:c6b5944187d5 130 {
bcostm 3:c6b5944187d5 131 if(MagnetoDrv->LowPower != NULL)
bcostm 3:c6b5944187d5 132 {
bcostm 3:c6b5944187d5 133 MagnetoDrv->LowPower(status);
bcostm 3:c6b5944187d5 134 }
bcostm 3:c6b5944187d5 135 }
bcostm 3:c6b5944187d5 136 }
bcostm 3:c6b5944187d5 137
bcostm 3:c6b5944187d5 138 /**
bcostm 3:c6b5944187d5 139 * @brief Get XYZ magnetometer values.
bcostm 3:c6b5944187d5 140 * @param pDataXYZ Pointer on 3 magnetometer values table with
bcostm 3:c6b5944187d5 141 * pDataXYZ[0] = X axis, pDataXYZ[1] = Y axis, pDataXYZ[2] = Z axis
bcostm 3:c6b5944187d5 142 */
bcostm 3:c6b5944187d5 143 void BSP_MAGNETO_GetXYZ(int16_t *pDataXYZ)
bcostm 3:c6b5944187d5 144 {
bcostm 3:c6b5944187d5 145 if(MagnetoDrv != NULL)
bcostm 3:c6b5944187d5 146 {
bcostm 3:c6b5944187d5 147 if(MagnetoDrv->GetXYZ != NULL)
bcostm 3:c6b5944187d5 148 {
bcostm 3:c6b5944187d5 149 MagnetoDrv->GetXYZ(pDataXYZ);
bcostm 3:c6b5944187d5 150 }
bcostm 3:c6b5944187d5 151 }
bcostm 3:c6b5944187d5 152 }
bcostm 3:c6b5944187d5 153
bcostm 3:c6b5944187d5 154 /**
bcostm 3:c6b5944187d5 155 * @}
bcostm 3:c6b5944187d5 156 */
bcostm 3:c6b5944187d5 157
bcostm 3:c6b5944187d5 158 /**
bcostm 3:c6b5944187d5 159 * @}
bcostm 3:c6b5944187d5 160 */
bcostm 3:c6b5944187d5 161
bcostm 3:c6b5944187d5 162 /**
bcostm 3:c6b5944187d5 163 * @}
bcostm 3:c6b5944187d5 164 */
bcostm 3:c6b5944187d5 165
bcostm 3:c6b5944187d5 166 /**
bcostm 3:c6b5944187d5 167 * @}
bcostm 3:c6b5944187d5 168 */
bcostm 3:c6b5944187d5 169 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/