Library I2C pins modification to fit nucleo 32 pins modules
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Dependents: STM32_MagneticLight
Fork of X_NUCLEO_IKS01A1 by
Components/lps25h/lps25h_class.cpp@24:92cc9c6e4b2b, 2015-06-03 (annotated)
- Committer:
- Wolfgang Betz
- Date:
- Wed Jun 03 14:57:57 2015 +0200
- Revision:
- 24:92cc9c6e4b2b
- Parent:
- 6:8d2abd695c52
- Child:
- 57:04563dd74269
Upgrade to match X-CUBE-MEMS1/trunk, revision #402
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wolfgang Betz |
6:8d2abd695c52 | 1 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 2 | ****************************************************************************** |
Wolfgang Betz |
6:8d2abd695c52 | 3 | * @file lps25h_class.cpp |
Wolfgang Betz |
6:8d2abd695c52 | 4 | * @author AST / EST |
Wolfgang Betz |
6:8d2abd695c52 | 5 | * @version V0.0.1 |
Wolfgang Betz |
6:8d2abd695c52 | 6 | * @date 14-April-2015 |
Wolfgang Betz |
6:8d2abd695c52 | 7 | * @brief Implementation file for the LPS25H driver class |
Wolfgang Betz |
6:8d2abd695c52 | 8 | ****************************************************************************** |
Wolfgang Betz |
6:8d2abd695c52 | 9 | * @attention |
Wolfgang Betz |
6:8d2abd695c52 | 10 | * |
Wolfgang Betz |
6:8d2abd695c52 | 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
Wolfgang Betz |
6:8d2abd695c52 | 12 | * |
Wolfgang Betz |
6:8d2abd695c52 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
Wolfgang Betz |
6:8d2abd695c52 | 14 | * are permitted provided that the following conditions are met: |
Wolfgang Betz |
6:8d2abd695c52 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
Wolfgang Betz |
6:8d2abd695c52 | 16 | * this list of conditions and the following disclaimer. |
Wolfgang Betz |
6:8d2abd695c52 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Wolfgang Betz |
6:8d2abd695c52 | 18 | * this list of conditions and the following disclaimer in the documentation |
Wolfgang Betz |
6:8d2abd695c52 | 19 | * and/or other materials provided with the distribution. |
Wolfgang Betz |
6:8d2abd695c52 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Wolfgang Betz |
6:8d2abd695c52 | 21 | * may be used to endorse or promote products derived from this software |
Wolfgang Betz |
6:8d2abd695c52 | 22 | * without specific prior written permission. |
Wolfgang Betz |
6:8d2abd695c52 | 23 | * |
Wolfgang Betz |
6:8d2abd695c52 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Wolfgang Betz |
6:8d2abd695c52 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Wolfgang Betz |
6:8d2abd695c52 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Wolfgang Betz |
6:8d2abd695c52 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Wolfgang Betz |
6:8d2abd695c52 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Wolfgang Betz |
6:8d2abd695c52 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Wolfgang Betz |
6:8d2abd695c52 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Wolfgang Betz |
6:8d2abd695c52 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Wolfgang Betz |
6:8d2abd695c52 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Wolfgang Betz |
6:8d2abd695c52 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Wolfgang Betz |
6:8d2abd695c52 | 34 | * |
Wolfgang Betz |
6:8d2abd695c52 | 35 | ****************************************************************************** |
Wolfgang Betz |
6:8d2abd695c52 | 36 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 37 | |
Wolfgang Betz |
6:8d2abd695c52 | 38 | /* Includes ------------------------------------------------------------------*/ |
Wolfgang Betz |
6:8d2abd695c52 | 39 | #include "mbed.h" |
Wolfgang Betz |
6:8d2abd695c52 | 40 | #include "lps25h_class.h" |
Wolfgang Betz |
6:8d2abd695c52 | 41 | #include "lps25h.h" |
Wolfgang Betz |
6:8d2abd695c52 | 42 | #include "../../x_nucleo_iks01a1_targets.h" |
Wolfgang Betz |
6:8d2abd695c52 | 43 | |
Wolfgang Betz |
6:8d2abd695c52 | 44 | /* Methods -------------------------------------------------------------------*/ |
Wolfgang Betz |
6:8d2abd695c52 | 45 | /* betzw - based on: |
Wolfgang Betz |
24:92cc9c6e4b2b | 46 | X-CUBE-MEMS1/trunk/Drivers/BSP/Components/lps25h/lps25h.c: revision #400, |
Wolfgang Betz |
24:92cc9c6e4b2b | 47 | X-CUBE-MEMS1/trunk: revision #402 |
Wolfgang Betz |
6:8d2abd695c52 | 48 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 49 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 50 | * @brief Set LPS25H Initialization |
Wolfgang Betz |
6:8d2abd695c52 | 51 | * @param LPS25H_Init the configuration setting for the LPS25H |
Wolfgang Betz |
6:8d2abd695c52 | 52 | * @retval PRESSURE_OK in case of success, an error code otherwise |
Wolfgang Betz |
6:8d2abd695c52 | 53 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 54 | PRESSURE_StatusTypeDef LPS25H::LPS25H_Init(PRESSURE_InitTypeDef *LPS25H_Init) |
Wolfgang Betz |
24:92cc9c6e4b2b | 55 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 56 | uint8_t tmp1 = 0x00; |
Wolfgang Betz |
24:92cc9c6e4b2b | 57 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 58 | /* Configure the low level interface ---------------------------------------*/ |
Wolfgang Betz |
24:92cc9c6e4b2b | 59 | if(LPS25H_IO_Init() != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 60 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 61 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 62 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 63 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 64 | if(LPS25H_PowerOn() != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 65 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 66 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 67 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 68 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 69 | if(LPS25H_IO_Read(&tmp1, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 70 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 71 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 72 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 73 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 74 | /* Output Data Rate selection */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 75 | tmp1 &= ~(LPS25H_ODR_MASK); |
Wolfgang Betz |
24:92cc9c6e4b2b | 76 | tmp1 |= LPS25H_Init->OutputDataRate; |
Wolfgang Betz |
24:92cc9c6e4b2b | 77 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 78 | /* Interrupt circuit selection */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 79 | tmp1 &= ~(LPS25H_DIFF_EN_MASK); |
Wolfgang Betz |
24:92cc9c6e4b2b | 80 | tmp1 |= LPS25H_Init->DiffEnable; |
Wolfgang Betz |
24:92cc9c6e4b2b | 81 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 82 | /* Block Data Update selection */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 83 | tmp1 &= ~(LPS25H_BDU_MASK); |
Wolfgang Betz |
24:92cc9c6e4b2b | 84 | tmp1 |= LPS25H_Init->BlockDataUpdate; |
Wolfgang Betz |
24:92cc9c6e4b2b | 85 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 86 | /* Serial Interface Mode selection */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 87 | tmp1 &= ~(LPS25H_SPI_SIM_MASK); |
Wolfgang Betz |
24:92cc9c6e4b2b | 88 | tmp1 |= LPS25H_Init->SPIMode; |
Wolfgang Betz |
24:92cc9c6e4b2b | 89 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 90 | if(LPS25H_IO_Write(&tmp1, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 91 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 92 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 93 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 94 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 95 | if(LPS25H_IO_Read(&tmp1, LPS25H_RES_CONF_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 96 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 97 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 98 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 99 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 100 | /* Serial Interface Mode selection */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 101 | tmp1 &= ~(LPS25H_P_RES_MASK); |
Wolfgang Betz |
24:92cc9c6e4b2b | 102 | tmp1 |= LPS25H_Init->PressureResolution; |
Wolfgang Betz |
24:92cc9c6e4b2b | 103 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 104 | /* Serial Interface Mode selection */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 105 | tmp1 &= ~(LPS25H_T_RES_MASK); |
Wolfgang Betz |
24:92cc9c6e4b2b | 106 | tmp1 |= LPS25H_Init->TemperatureResolution; |
Wolfgang Betz |
24:92cc9c6e4b2b | 107 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 108 | if(LPS25H_IO_Write(&tmp1, LPS25H_RES_CONF_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 109 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 110 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 111 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 112 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 113 | LPS25H_IO_ITConfig(); |
Wolfgang Betz |
24:92cc9c6e4b2b | 114 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 115 | return PRESSURE_OK; |
Wolfgang Betz |
6:8d2abd695c52 | 116 | } |
Wolfgang Betz |
6:8d2abd695c52 | 117 | |
Wolfgang Betz |
6:8d2abd695c52 | 118 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 119 | * @brief Read ID address of LPS25H |
Wolfgang Betz |
6:8d2abd695c52 | 120 | * @param ht_id the pointer where the ID of the device is stored |
Wolfgang Betz |
6:8d2abd695c52 | 121 | * @retval PRESSURE_OK in case of success, an error code otherwise |
Wolfgang Betz |
6:8d2abd695c52 | 122 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 123 | PRESSURE_StatusTypeDef LPS25H::LPS25H_ReadID(uint8_t *p_id) |
Wolfgang Betz |
6:8d2abd695c52 | 124 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 125 | if(!p_id) |
Wolfgang Betz |
24:92cc9c6e4b2b | 126 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 127 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 128 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 129 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 130 | return LPS25H_IO_Read(p_id, LPS25H_WHO_AM_I_ADDR, 1); |
Wolfgang Betz |
6:8d2abd695c52 | 131 | } |
Wolfgang Betz |
6:8d2abd695c52 | 132 | |
Wolfgang Betz |
6:8d2abd695c52 | 133 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 134 | * @brief Reboot memory content of LPS25H |
Wolfgang Betz |
6:8d2abd695c52 | 135 | * @retval PRESSURE_OK in case of success, an error code otherwise |
Wolfgang Betz |
6:8d2abd695c52 | 136 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 137 | PRESSURE_StatusTypeDef LPS25H::LPS25H_RebootCmd(void) |
Wolfgang Betz |
6:8d2abd695c52 | 138 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 139 | uint8_t tmpreg; |
Wolfgang Betz |
24:92cc9c6e4b2b | 140 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 141 | /* Read CTRL_REG5 register */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 142 | if(LPS25H_IO_Read(&tmpreg, LPS25H_CTRL_REG2_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 143 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 144 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 145 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 146 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 147 | /* Enable or Disable the reboot memory */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 148 | tmpreg |= LPS25H_RESET_MEMORY; |
Wolfgang Betz |
24:92cc9c6e4b2b | 149 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 150 | /* Write value to MEMS CTRL_REG5 regsister */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 151 | if(LPS25H_IO_Write(&tmpreg, LPS25H_CTRL_REG2_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 152 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 153 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 154 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 155 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 156 | return PRESSURE_OK; |
Wolfgang Betz |
6:8d2abd695c52 | 157 | } |
Wolfgang Betz |
6:8d2abd695c52 | 158 | |
Wolfgang Betz |
6:8d2abd695c52 | 159 | |
Wolfgang Betz |
6:8d2abd695c52 | 160 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 161 | * @brief Read LPS25H output register, and calculate the raw pressure |
Wolfgang Betz |
6:8d2abd695c52 | 162 | * @param raw_press the pressure raw value |
Wolfgang Betz |
6:8d2abd695c52 | 163 | * @retval PRESSURE_OK in case of success, an error code otherwise |
Wolfgang Betz |
6:8d2abd695c52 | 164 | */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 165 | PRESSURE_StatusTypeDef LPS25H::LPS25H_I2C_ReadRawPressure(int32_t *raw_press) |
Wolfgang Betz |
6:8d2abd695c52 | 166 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 167 | uint8_t buffer[3], i; |
Wolfgang Betz |
24:92cc9c6e4b2b | 168 | uint32_t tempVal = 0; |
Wolfgang Betz |
24:92cc9c6e4b2b | 169 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 170 | /* Read the register content */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 171 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 172 | if(LPS25H_IO_Read(buffer, (LPS25H_PRESS_POUT_XL_ADDR | LPS25H_I2C_MULTIPLEBYTE_CMD), |
Wolfgang Betz |
24:92cc9c6e4b2b | 173 | 3) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 174 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 175 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 176 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 177 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 178 | /* Build the raw data */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 179 | for (i = 0 ; i < 3 ; i++) |
Wolfgang Betz |
24:92cc9c6e4b2b | 180 | tempVal |= (((uint32_t) buffer[i]) << (8 * i)); |
Wolfgang Betz |
6:8d2abd695c52 | 181 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 182 | /* convert the 2's complement 24 bit to 2's complement 32 bit */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 183 | if (tempVal & 0x00800000) |
Wolfgang Betz |
24:92cc9c6e4b2b | 184 | tempVal |= 0xFF000000; |
Wolfgang Betz |
24:92cc9c6e4b2b | 185 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 186 | /* return the built value */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 187 | *raw_press = ((int32_t) tempVal); |
Wolfgang Betz |
24:92cc9c6e4b2b | 188 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 189 | return PRESSURE_OK; |
Wolfgang Betz |
6:8d2abd695c52 | 190 | } |
Wolfgang Betz |
6:8d2abd695c52 | 191 | |
Wolfgang Betz |
6:8d2abd695c52 | 192 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 193 | * @brief Read LPS25H output register, and calculate the pressure in mbar |
Wolfgang Betz |
6:8d2abd695c52 | 194 | * @param pfData the pressure value in mbar |
Wolfgang Betz |
6:8d2abd695c52 | 195 | * @retval PRESSURE_OK in case of success, an error code otherwise |
Wolfgang Betz |
6:8d2abd695c52 | 196 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 197 | PRESSURE_StatusTypeDef LPS25H::LPS25H_GetPressure(float* pfData) |
Wolfgang Betz |
6:8d2abd695c52 | 198 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 199 | int32_t raw_press = 0; |
Wolfgang Betz |
24:92cc9c6e4b2b | 200 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 201 | if(LPS25H_I2C_ReadRawPressure(&raw_press) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 202 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 203 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 204 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 205 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 206 | *pfData = (float)raw_press / 4096.0f; |
Wolfgang Betz |
24:92cc9c6e4b2b | 207 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 208 | return PRESSURE_OK; |
Wolfgang Betz |
6:8d2abd695c52 | 209 | } |
Wolfgang Betz |
6:8d2abd695c52 | 210 | |
Wolfgang Betz |
6:8d2abd695c52 | 211 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 212 | * @brief Read LPS25H output register, and calculate the raw temperature |
Wolfgang Betz |
6:8d2abd695c52 | 213 | * @param raw_data the temperature raw value |
Wolfgang Betz |
6:8d2abd695c52 | 214 | * @retval PRESSURE_OK in case of success, an error code otherwise |
Wolfgang Betz |
6:8d2abd695c52 | 215 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 216 | PRESSURE_StatusTypeDef LPS25H::LPS25H_I2C_ReadRawTemperature(int16_t *raw_data) |
Wolfgang Betz |
6:8d2abd695c52 | 217 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 218 | uint8_t buffer[2]; |
Wolfgang Betz |
24:92cc9c6e4b2b | 219 | uint16_t tempVal = 0; |
Wolfgang Betz |
24:92cc9c6e4b2b | 220 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 221 | /* Read the register content */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 222 | if(LPS25H_IO_Read(buffer, (LPS25H_TEMP_OUT_L_ADDR | LPS25H_I2C_MULTIPLEBYTE_CMD), |
Wolfgang Betz |
24:92cc9c6e4b2b | 223 | 2) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 224 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 225 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 226 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 227 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 228 | /* Build the raw value */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 229 | tempVal = (((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0]; |
Wolfgang Betz |
24:92cc9c6e4b2b | 230 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 231 | /* Return it */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 232 | *raw_data = ((int16_t)tempVal); |
Wolfgang Betz |
24:92cc9c6e4b2b | 233 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 234 | return PRESSURE_OK; |
Wolfgang Betz |
6:8d2abd695c52 | 235 | } |
Wolfgang Betz |
6:8d2abd695c52 | 236 | |
Wolfgang Betz |
6:8d2abd695c52 | 237 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 238 | * @brief Read LPS25H output register, and calculate the temperature |
Wolfgang Betz |
6:8d2abd695c52 | 239 | * @param pfData the temperature value |
Wolfgang Betz |
6:8d2abd695c52 | 240 | * @retval PRESSURE_OK in case of success, an error code otherwise |
Wolfgang Betz |
6:8d2abd695c52 | 241 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 242 | PRESSURE_StatusTypeDef LPS25H::LPS25H_GetTemperature(float *pfData) |
Wolfgang Betz |
6:8d2abd695c52 | 243 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 244 | int16_t raw_data; |
Wolfgang Betz |
24:92cc9c6e4b2b | 245 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 246 | if(LPS25H_I2C_ReadRawTemperature(&raw_data) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 247 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 248 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 249 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 250 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 251 | *pfData = (float)((((float)raw_data / 480.0f) + 42.5f)); |
Wolfgang Betz |
24:92cc9c6e4b2b | 252 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 253 | return PRESSURE_OK; |
Wolfgang Betz |
6:8d2abd695c52 | 254 | } |
Wolfgang Betz |
6:8d2abd695c52 | 255 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 256 | * @brief Exit the shutdown mode for LPS25H |
Wolfgang Betz |
6:8d2abd695c52 | 257 | * @retval PRESSURE_OK in case of success, an error code otherwise |
Wolfgang Betz |
6:8d2abd695c52 | 258 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 259 | PRESSURE_StatusTypeDef LPS25H::LPS25H_PowerOn(void) |
Wolfgang Betz |
6:8d2abd695c52 | 260 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 261 | uint8_t tmpreg; |
Wolfgang Betz |
24:92cc9c6e4b2b | 262 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 263 | /* Read the register content */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 264 | if(LPS25H_IO_Read(&tmpreg, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 265 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 266 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 267 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 268 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 269 | /* Set the power down bit */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 270 | tmpreg |= LPS25H_MODE_ACTIVE; |
Wolfgang Betz |
24:92cc9c6e4b2b | 271 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 272 | /* Write register */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 273 | if(LPS25H_IO_Write(&tmpreg, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 274 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 275 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 276 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 277 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 278 | return PRESSURE_OK; |
Wolfgang Betz |
6:8d2abd695c52 | 279 | } |
Wolfgang Betz |
6:8d2abd695c52 | 280 | |
Wolfgang Betz |
6:8d2abd695c52 | 281 | |
Wolfgang Betz |
6:8d2abd695c52 | 282 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 283 | * @brief Enter the shutdown mode for LPS25H |
Wolfgang Betz |
6:8d2abd695c52 | 284 | * @retval PRESSURE_OK in case of success, an error code otherwise |
Wolfgang Betz |
6:8d2abd695c52 | 285 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 286 | PRESSURE_StatusTypeDef LPS25H::LPS25H_PowerOff(void) |
Wolfgang Betz |
6:8d2abd695c52 | 287 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 288 | uint8_t tmpreg; |
Wolfgang Betz |
24:92cc9c6e4b2b | 289 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 290 | /* Read the register content */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 291 | if(LPS25H_IO_Read(&tmpreg, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 292 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 293 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 294 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 295 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 296 | /* Reset the power down bit */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 297 | tmpreg &= ~(LPS25H_MODE_ACTIVE); |
Wolfgang Betz |
24:92cc9c6e4b2b | 298 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 299 | /* Write register */ |
Wolfgang Betz |
24:92cc9c6e4b2b | 300 | if(LPS25H_IO_Write(&tmpreg, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
24:92cc9c6e4b2b | 301 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 302 | return PRESSURE_ERROR; |
Wolfgang Betz |
24:92cc9c6e4b2b | 303 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 304 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 305 | return PRESSURE_OK; |
Wolfgang Betz |
6:8d2abd695c52 | 306 | } |
Wolfgang Betz |
6:8d2abd695c52 | 307 | |
Wolfgang Betz |
6:8d2abd695c52 | 308 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 309 | * @brief Set the slave address according to SA0 bit |
Wolfgang Betz |
6:8d2abd695c52 | 310 | * @param SA0_Bit_Status LPS25H_SA0_LOW or LPS25H_SA0_HIGH |
Wolfgang Betz |
6:8d2abd695c52 | 311 | * @retval None |
Wolfgang Betz |
6:8d2abd695c52 | 312 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 313 | void LPS25H::LPS25H_SlaveAddrRemap(uint8_t SA0_Bit_Status) |
Wolfgang Betz |
6:8d2abd695c52 | 314 | { |
Wolfgang Betz |
24:92cc9c6e4b2b | 315 | LPS25H_SlaveAddress = (SA0_Bit_Status == LPS25H_SA0_LOW ? LPS25H_ADDRESS_LOW : LPS25H_ADDRESS_HIGH); |
Wolfgang Betz |
6:8d2abd695c52 | 316 | } |
Wolfgang Betz |
24:92cc9c6e4b2b | 317 | |
Wolfgang Betz |
24:92cc9c6e4b2b | 318 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |