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/
Drivers/BSP/Components/lps22hb/lps22hb.c@7:bfe8272ced90, 2019-09-24 (annotated)
- Committer:
- jeromecoutant
- Date:
- Tue Sep 24 15:30:09 2019 +0200
- Revision:
- 7:bfe8272ced90
- Parent:
- 4:137bb367ba50
Update BSP files with STM32Cube L4 V1.14.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 4:137bb367ba50 | 1 | /** |
bcostm | 4:137bb367ba50 | 2 | ****************************************************************************** |
bcostm | 4:137bb367ba50 | 3 | * @file lps22hb.c |
bcostm | 4:137bb367ba50 | 4 | * @author MCD Application Team |
bcostm | 4:137bb367ba50 | 5 | * @brief This file provides a set of functions needed to manage the LPS22HB |
bcostm | 4:137bb367ba50 | 6 | * pressure and temperature devices |
bcostm | 4:137bb367ba50 | 7 | ****************************************************************************** |
bcostm | 4:137bb367ba50 | 8 | * @attention |
bcostm | 4:137bb367ba50 | 9 | * |
jeromecoutant | 7:bfe8272ced90 | 10 | * <h2><center>© Copyright (c) 2017 STMicroelectronics. |
jeromecoutant | 7:bfe8272ced90 | 11 | * All rights reserved.</center></h2> |
bcostm | 4:137bb367ba50 | 12 | * |
jeromecoutant | 7:bfe8272ced90 | 13 | * This software component is licensed by ST under BSD 3-Clause license, |
jeromecoutant | 7:bfe8272ced90 | 14 | * the "License"; You may not use this file except in compliance with the |
jeromecoutant | 7:bfe8272ced90 | 15 | * License. You may obtain a copy of the License at: |
jeromecoutant | 7:bfe8272ced90 | 16 | * opensource.org/licenses/BSD-3-Clause |
bcostm | 4:137bb367ba50 | 17 | * |
bcostm | 4:137bb367ba50 | 18 | ****************************************************************************** |
bcostm | 4:137bb367ba50 | 19 | */ |
bcostm | 4:137bb367ba50 | 20 | |
bcostm | 4:137bb367ba50 | 21 | /* Includes ------------------------------------------------------------------*/ |
bcostm | 4:137bb367ba50 | 22 | #include "lps22hb.h" |
bcostm | 4:137bb367ba50 | 23 | |
bcostm | 4:137bb367ba50 | 24 | /** @addtogroup BSP |
bcostm | 4:137bb367ba50 | 25 | * @{ |
bcostm | 4:137bb367ba50 | 26 | */ |
bcostm | 4:137bb367ba50 | 27 | |
bcostm | 4:137bb367ba50 | 28 | /** @addtogroup Component |
bcostm | 4:137bb367ba50 | 29 | * @{ |
bcostm | 4:137bb367ba50 | 30 | */ |
bcostm | 4:137bb367ba50 | 31 | |
bcostm | 4:137bb367ba50 | 32 | /** @defgroup LPS22HB LPS22HB |
bcostm | 4:137bb367ba50 | 33 | * @{ |
bcostm | 4:137bb367ba50 | 34 | */ |
bcostm | 4:137bb367ba50 | 35 | |
bcostm | 4:137bb367ba50 | 36 | /** @defgroup LPS22HB_Private_FunctionsPrototypes LPS22HB Private Functions Prototypes |
bcostm | 4:137bb367ba50 | 37 | * @{ |
bcostm | 4:137bb367ba50 | 38 | */ |
bcostm | 4:137bb367ba50 | 39 | static void LPS22HB_Init(uint16_t DeviceAddr); |
bcostm | 4:137bb367ba50 | 40 | /** |
bcostm | 4:137bb367ba50 | 41 | * @} |
bcostm | 4:137bb367ba50 | 42 | */ |
bcostm | 4:137bb367ba50 | 43 | |
bcostm | 4:137bb367ba50 | 44 | /** @defgroup LPS22HB_Private_Variables LPS22HB Private Variables |
bcostm | 4:137bb367ba50 | 45 | * @{ |
bcostm | 4:137bb367ba50 | 46 | */ |
bcostm | 4:137bb367ba50 | 47 | /* Pressure Private Variables */ |
bcostm | 4:137bb367ba50 | 48 | PSENSOR_DrvTypeDef LPS22HB_P_Drv = |
bcostm | 4:137bb367ba50 | 49 | { |
bcostm | 4:137bb367ba50 | 50 | LPS22HB_P_Init, |
bcostm | 4:137bb367ba50 | 51 | LPS22HB_P_ReadID, |
bcostm | 4:137bb367ba50 | 52 | LPS22HB_P_ReadPressure |
bcostm | 4:137bb367ba50 | 53 | }; |
bcostm | 4:137bb367ba50 | 54 | |
bcostm | 4:137bb367ba50 | 55 | /* Temperature Private Variables */ |
bcostm | 4:137bb367ba50 | 56 | TSENSOR_DrvTypeDef LPS22HB_T_Drv = |
bcostm | 4:137bb367ba50 | 57 | { |
bcostm | 4:137bb367ba50 | 58 | LPS22HB_T_Init, |
bcostm | 4:137bb367ba50 | 59 | 0, |
bcostm | 4:137bb367ba50 | 60 | 0, |
bcostm | 4:137bb367ba50 | 61 | LPS22HB_T_ReadTemp |
bcostm | 4:137bb367ba50 | 62 | }; |
bcostm | 4:137bb367ba50 | 63 | /** |
bcostm | 4:137bb367ba50 | 64 | * @} |
bcostm | 4:137bb367ba50 | 65 | */ |
bcostm | 4:137bb367ba50 | 66 | |
bcostm | 4:137bb367ba50 | 67 | /** @defgroup LPS22HB_Pressure_Private_Functions LPS22HB Pressure Private Functions |
bcostm | 4:137bb367ba50 | 68 | * @{ |
bcostm | 4:137bb367ba50 | 69 | */ |
bcostm | 4:137bb367ba50 | 70 | /** |
bcostm | 4:137bb367ba50 | 71 | * @brief Set LPS22HB pressure sensor Initialization. |
bcostm | 4:137bb367ba50 | 72 | */ |
bcostm | 4:137bb367ba50 | 73 | void LPS22HB_P_Init(uint16_t DeviceAddr) |
bcostm | 4:137bb367ba50 | 74 | { |
bcostm | 4:137bb367ba50 | 75 | LPS22HB_Init(DeviceAddr); |
bcostm | 4:137bb367ba50 | 76 | } |
bcostm | 4:137bb367ba50 | 77 | |
bcostm | 4:137bb367ba50 | 78 | /** |
bcostm | 4:137bb367ba50 | 79 | * @brief Read LPS22HB ID. |
bcostm | 4:137bb367ba50 | 80 | * @retval ID |
bcostm | 4:137bb367ba50 | 81 | */ |
bcostm | 4:137bb367ba50 | 82 | uint8_t LPS22HB_P_ReadID(uint16_t DeviceAddr) |
bcostm | 4:137bb367ba50 | 83 | { |
bcostm | 4:137bb367ba50 | 84 | uint8_t ctrl = 0x00; |
bcostm | 4:137bb367ba50 | 85 | |
bcostm | 4:137bb367ba50 | 86 | /* IO interface initialization */ |
bcostm | 4:137bb367ba50 | 87 | SENSOR_IO_Init(); |
bcostm | 4:137bb367ba50 | 88 | |
bcostm | 4:137bb367ba50 | 89 | /* Read value at Who am I register address */ |
bcostm | 4:137bb367ba50 | 90 | ctrl = SENSOR_IO_Read(DeviceAddr, LPS22HB_WHO_AM_I_REG); |
bcostm | 4:137bb367ba50 | 91 | |
bcostm | 4:137bb367ba50 | 92 | return ctrl; |
bcostm | 4:137bb367ba50 | 93 | } |
bcostm | 4:137bb367ba50 | 94 | |
bcostm | 4:137bb367ba50 | 95 | /** |
bcostm | 4:137bb367ba50 | 96 | * @brief Read pressure value of LPS22HB |
bcostm | 4:137bb367ba50 | 97 | * @retval pressure value |
bcostm | 4:137bb367ba50 | 98 | */ |
bcostm | 4:137bb367ba50 | 99 | float LPS22HB_P_ReadPressure(uint16_t DeviceAddr) |
bcostm | 4:137bb367ba50 | 100 | { |
bcostm | 4:137bb367ba50 | 101 | int32_t raw_press; |
bcostm | 4:137bb367ba50 | 102 | uint8_t buffer[3]; |
bcostm | 4:137bb367ba50 | 103 | uint32_t tmp = 0; |
bcostm | 4:137bb367ba50 | 104 | uint8_t i; |
bcostm | 4:137bb367ba50 | 105 | |
bcostm | 4:137bb367ba50 | 106 | for(i = 0; i < 3; i++) |
bcostm | 4:137bb367ba50 | 107 | { |
bcostm | 4:137bb367ba50 | 108 | buffer[i] = SENSOR_IO_Read(DeviceAddr, (LPS22HB_PRESS_OUT_XL_REG + i)); |
bcostm | 4:137bb367ba50 | 109 | } |
bcostm | 4:137bb367ba50 | 110 | |
bcostm | 4:137bb367ba50 | 111 | /* Build the raw data */ |
bcostm | 4:137bb367ba50 | 112 | for(i = 0; i < 3; i++) |
bcostm | 4:137bb367ba50 | 113 | tmp |= (((uint32_t)buffer[i]) << (8 * i)); |
bcostm | 4:137bb367ba50 | 114 | |
bcostm | 4:137bb367ba50 | 115 | /* convert the 2's complement 24 bit to 2's complement 32 bit */ |
bcostm | 4:137bb367ba50 | 116 | if(tmp & 0x00800000) |
bcostm | 4:137bb367ba50 | 117 | tmp |= 0xFF000000; |
bcostm | 4:137bb367ba50 | 118 | |
bcostm | 4:137bb367ba50 | 119 | raw_press = ((int32_t)tmp); |
bcostm | 4:137bb367ba50 | 120 | |
bcostm | 4:137bb367ba50 | 121 | raw_press = (raw_press * 100) / 4096; |
bcostm | 4:137bb367ba50 | 122 | |
bcostm | 4:137bb367ba50 | 123 | return (float)((float)raw_press / 100.0f); |
bcostm | 4:137bb367ba50 | 124 | } |
bcostm | 4:137bb367ba50 | 125 | |
bcostm | 4:137bb367ba50 | 126 | |
bcostm | 4:137bb367ba50 | 127 | /** |
bcostm | 4:137bb367ba50 | 128 | * @} |
bcostm | 4:137bb367ba50 | 129 | */ |
bcostm | 4:137bb367ba50 | 130 | |
bcostm | 4:137bb367ba50 | 131 | /** @defgroup LPS22HB_Temperature_Private_Functions LPS22HB Temperature Private Functions |
bcostm | 4:137bb367ba50 | 132 | * @{ |
bcostm | 4:137bb367ba50 | 133 | */ |
bcostm | 4:137bb367ba50 | 134 | |
bcostm | 4:137bb367ba50 | 135 | /** |
bcostm | 4:137bb367ba50 | 136 | * @brief Set LPS22HB temperature sensor Initialization. |
bcostm | 4:137bb367ba50 | 137 | * @param DeviceAddr: I2C device address |
bcostm | 4:137bb367ba50 | 138 | * @param InitStruct: pointer to a TSENSOR_InitTypeDef structure |
bcostm | 4:137bb367ba50 | 139 | * that contains the configuration setting for the HTS221. |
bcostm | 4:137bb367ba50 | 140 | * @retval None |
bcostm | 4:137bb367ba50 | 141 | */ |
bcostm | 4:137bb367ba50 | 142 | void LPS22HB_T_Init(uint16_t DeviceAddr, TSENSOR_InitTypeDef *pInitStruct) |
bcostm | 4:137bb367ba50 | 143 | { |
bcostm | 4:137bb367ba50 | 144 | LPS22HB_Init(DeviceAddr); |
bcostm | 4:137bb367ba50 | 145 | } |
bcostm | 4:137bb367ba50 | 146 | |
bcostm | 4:137bb367ba50 | 147 | /** |
bcostm | 4:137bb367ba50 | 148 | * @brief Read temperature value of LPS22HB |
bcostm | 4:137bb367ba50 | 149 | * @param DeviceAddr: I2C device address |
bcostm | 4:137bb367ba50 | 150 | * @retval temperature value |
bcostm | 4:137bb367ba50 | 151 | */ |
bcostm | 4:137bb367ba50 | 152 | float LPS22HB_T_ReadTemp(uint16_t DeviceAddr) |
bcostm | 4:137bb367ba50 | 153 | { |
bcostm | 4:137bb367ba50 | 154 | int16_t raw_data; |
bcostm | 4:137bb367ba50 | 155 | uint8_t buffer[2]; |
bcostm | 4:137bb367ba50 | 156 | uint16_t tmp; |
bcostm | 4:137bb367ba50 | 157 | uint8_t i; |
bcostm | 4:137bb367ba50 | 158 | |
bcostm | 4:137bb367ba50 | 159 | for(i = 0; i < 2; i++) |
bcostm | 4:137bb367ba50 | 160 | { |
bcostm | 4:137bb367ba50 | 161 | buffer[i] = SENSOR_IO_Read(DeviceAddr, (LPS22HB_TEMP_OUT_L_REG + i)); |
bcostm | 4:137bb367ba50 | 162 | } |
bcostm | 4:137bb367ba50 | 163 | |
bcostm | 4:137bb367ba50 | 164 | /* Build the raw tmp */ |
bcostm | 4:137bb367ba50 | 165 | tmp = (((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0]; |
bcostm | 4:137bb367ba50 | 166 | |
bcostm | 4:137bb367ba50 | 167 | raw_data = (tmp * 10) / 100; |
bcostm | 4:137bb367ba50 | 168 | |
bcostm | 4:137bb367ba50 | 169 | return ((float)(raw_data / 10.0f)); |
bcostm | 4:137bb367ba50 | 170 | } |
bcostm | 4:137bb367ba50 | 171 | |
bcostm | 4:137bb367ba50 | 172 | /** |
bcostm | 4:137bb367ba50 | 173 | * @} |
bcostm | 4:137bb367ba50 | 174 | */ |
bcostm | 4:137bb367ba50 | 175 | |
bcostm | 4:137bb367ba50 | 176 | /** @addtogroup LPS22HB_Private_Functions LPS22HB Private functions |
bcostm | 4:137bb367ba50 | 177 | * @{ |
bcostm | 4:137bb367ba50 | 178 | */ |
bcostm | 4:137bb367ba50 | 179 | |
bcostm | 4:137bb367ba50 | 180 | /** |
bcostm | 4:137bb367ba50 | 181 | * @brief Set LPS22HB Initialization. |
bcostm | 4:137bb367ba50 | 182 | * @param DeviceAddr: I2C device address |
bcostm | 4:137bb367ba50 | 183 | * @retval None |
bcostm | 4:137bb367ba50 | 184 | */ |
bcostm | 4:137bb367ba50 | 185 | static void LPS22HB_Init(uint16_t DeviceAddr) |
bcostm | 4:137bb367ba50 | 186 | { |
bcostm | 4:137bb367ba50 | 187 | uint8_t tmp; |
bcostm | 4:137bb367ba50 | 188 | |
bcostm | 4:137bb367ba50 | 189 | /* Set Power mode */ |
bcostm | 4:137bb367ba50 | 190 | tmp = SENSOR_IO_Read(DeviceAddr, LPS22HB_RES_CONF_REG); |
bcostm | 4:137bb367ba50 | 191 | |
bcostm | 4:137bb367ba50 | 192 | tmp &= ~LPS22HB_LCEN_MASK; |
bcostm | 4:137bb367ba50 | 193 | tmp |= (uint8_t)0x01; /* Set low current mode */ |
bcostm | 4:137bb367ba50 | 194 | |
bcostm | 4:137bb367ba50 | 195 | SENSOR_IO_Write(DeviceAddr, LPS22HB_RES_CONF_REG, tmp); |
bcostm | 4:137bb367ba50 | 196 | |
bcostm | 4:137bb367ba50 | 197 | /* Read CTRL_REG1 */ |
bcostm | 4:137bb367ba50 | 198 | tmp = SENSOR_IO_Read(DeviceAddr, LPS22HB_CTRL_REG1); |
bcostm | 4:137bb367ba50 | 199 | |
bcostm | 4:137bb367ba50 | 200 | /* Set default ODR */ |
bcostm | 4:137bb367ba50 | 201 | tmp &= ~LPS22HB_ODR_MASK; |
bcostm | 4:137bb367ba50 | 202 | tmp |= (uint8_t)0x30; /* Set ODR to 25Hz */ |
bcostm | 4:137bb367ba50 | 203 | |
bcostm | 4:137bb367ba50 | 204 | /* Enable BDU */ |
bcostm | 4:137bb367ba50 | 205 | tmp &= ~LPS22HB_BDU_MASK; |
bcostm | 4:137bb367ba50 | 206 | tmp |= ((uint8_t)0x02); |
bcostm | 4:137bb367ba50 | 207 | |
bcostm | 4:137bb367ba50 | 208 | /* Apply settings to CTRL_REG1 */ |
bcostm | 4:137bb367ba50 | 209 | SENSOR_IO_Write(DeviceAddr, LPS22HB_CTRL_REG1, tmp); |
bcostm | 4:137bb367ba50 | 210 | } |
bcostm | 4:137bb367ba50 | 211 | |
bcostm | 4:137bb367ba50 | 212 | /** |
bcostm | 4:137bb367ba50 | 213 | * @} |
bcostm | 4:137bb367ba50 | 214 | */ |
bcostm | 4:137bb367ba50 | 215 | |
bcostm | 4:137bb367ba50 | 216 | /** |
bcostm | 4:137bb367ba50 | 217 | * @} |
bcostm | 4:137bb367ba50 | 218 | */ |
bcostm | 4:137bb367ba50 | 219 | |
bcostm | 4:137bb367ba50 | 220 | /** |
bcostm | 4:137bb367ba50 | 221 | * @} |
bcostm | 4:137bb367ba50 | 222 | */ |
bcostm | 4:137bb367ba50 | 223 | |
bcostm | 4:137bb367ba50 | 224 | /** |
bcostm | 4:137bb367ba50 | 225 | * @} |
bcostm | 4:137bb367ba50 | 226 | */ |
bcostm | 4:137bb367ba50 | 227 | |
bcostm | 4:137bb367ba50 | 228 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |