pin assignments for mDot
Dependents: iks01a1_acc LoRaWAN-demo-72_mdotIKS01A1 MTDOT-UDKDemo_Senet MTDOT-UDKDemo
Fork of X_NUCLEO_IKS01A1 by
Components/lps25h/lps25h_class.cpp@6:8d2abd695c52, 2015-04-15 (annotated)
- Committer:
- Wolfgang Betz
- Date:
- Wed Apr 15 13:45:30 2015 +0200
- Revision:
- 6:8d2abd695c52
- Child:
- 24:92cc9c6e4b2b
Added component LPS25H
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 |
6:8d2abd695c52 | 46 | X-CUBE-MEMS1/trunk/Drivers/BSP/Components/lps25h/lps25h.c: revision #184, |
Wolfgang Betz |
6:8d2abd695c52 | 47 | X-CUBE-MEMS1/trunk: revision #293 |
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 |
6:8d2abd695c52 | 55 | { |
Wolfgang Betz |
6:8d2abd695c52 | 56 | uint8_t tmp1 = 0x00; |
Wolfgang Betz |
6:8d2abd695c52 | 57 | |
Wolfgang Betz |
6:8d2abd695c52 | 58 | /* Configure the low level interface ---------------------------------------*/ |
Wolfgang Betz |
6:8d2abd695c52 | 59 | if(LPS25H_IO_Init() != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 60 | { |
Wolfgang Betz |
6:8d2abd695c52 | 61 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 62 | } |
Wolfgang Betz |
6:8d2abd695c52 | 63 | |
Wolfgang Betz |
6:8d2abd695c52 | 64 | if(LPS25H_PowerOn() != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 65 | { |
Wolfgang Betz |
6:8d2abd695c52 | 66 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 67 | } |
Wolfgang Betz |
6:8d2abd695c52 | 68 | |
Wolfgang Betz |
6:8d2abd695c52 | 69 | if(LPS25H_IO_Read(&tmp1, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 70 | { |
Wolfgang Betz |
6:8d2abd695c52 | 71 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 72 | } |
Wolfgang Betz |
6:8d2abd695c52 | 73 | |
Wolfgang Betz |
6:8d2abd695c52 | 74 | /* Output Data Rate selection */ |
Wolfgang Betz |
6:8d2abd695c52 | 75 | tmp1 &= ~(LPS25H_ODR_MASK); |
Wolfgang Betz |
6:8d2abd695c52 | 76 | tmp1 |= LPS25H_Init->OutputDataRate; |
Wolfgang Betz |
6:8d2abd695c52 | 77 | |
Wolfgang Betz |
6:8d2abd695c52 | 78 | /* Interrupt circuit selection */ |
Wolfgang Betz |
6:8d2abd695c52 | 79 | tmp1 &= ~(LPS25H_DIFF_EN_MASK); |
Wolfgang Betz |
6:8d2abd695c52 | 80 | tmp1 |= LPS25H_Init->DiffEnable; |
Wolfgang Betz |
6:8d2abd695c52 | 81 | |
Wolfgang Betz |
6:8d2abd695c52 | 82 | /* Block Data Update selection */ |
Wolfgang Betz |
6:8d2abd695c52 | 83 | tmp1 &= ~(LPS25H_BDU_MASK); |
Wolfgang Betz |
6:8d2abd695c52 | 84 | tmp1 |= LPS25H_Init->BlockDataUpdate; |
Wolfgang Betz |
6:8d2abd695c52 | 85 | |
Wolfgang Betz |
6:8d2abd695c52 | 86 | /* Serial Interface Mode selection */ |
Wolfgang Betz |
6:8d2abd695c52 | 87 | tmp1 &= ~(LPS25H_SPI_SIM_MASK); |
Wolfgang Betz |
6:8d2abd695c52 | 88 | tmp1 |= LPS25H_Init->SPIMode; |
Wolfgang Betz |
6:8d2abd695c52 | 89 | |
Wolfgang Betz |
6:8d2abd695c52 | 90 | if(LPS25H_IO_Write(&tmp1, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 91 | { |
Wolfgang Betz |
6:8d2abd695c52 | 92 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 93 | } |
Wolfgang Betz |
6:8d2abd695c52 | 94 | |
Wolfgang Betz |
6:8d2abd695c52 | 95 | if(LPS25H_IO_Read(&tmp1, LPS25H_RES_CONF_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 96 | { |
Wolfgang Betz |
6:8d2abd695c52 | 97 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 98 | } |
Wolfgang Betz |
6:8d2abd695c52 | 99 | |
Wolfgang Betz |
6:8d2abd695c52 | 100 | /* Serial Interface Mode selection */ |
Wolfgang Betz |
6:8d2abd695c52 | 101 | tmp1 &= ~(LPS25H_P_RES_MASK); |
Wolfgang Betz |
6:8d2abd695c52 | 102 | tmp1 |= LPS25H_Init->PressureResolution; |
Wolfgang Betz |
6:8d2abd695c52 | 103 | |
Wolfgang Betz |
6:8d2abd695c52 | 104 | /* Serial Interface Mode selection */ |
Wolfgang Betz |
6:8d2abd695c52 | 105 | tmp1 &= ~(LPS25H_T_RES_MASK); |
Wolfgang Betz |
6:8d2abd695c52 | 106 | tmp1 |= LPS25H_Init->TemperatureResolution; |
Wolfgang Betz |
6:8d2abd695c52 | 107 | |
Wolfgang Betz |
6:8d2abd695c52 | 108 | if(LPS25H_IO_Write(&tmp1, LPS25H_RES_CONF_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 109 | { |
Wolfgang Betz |
6:8d2abd695c52 | 110 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 111 | } |
Wolfgang Betz |
6:8d2abd695c52 | 112 | |
Wolfgang Betz |
6:8d2abd695c52 | 113 | LPS25H_IO_ITConfig(); |
Wolfgang Betz |
6:8d2abd695c52 | 114 | |
Wolfgang Betz |
6:8d2abd695c52 | 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 |
6:8d2abd695c52 | 125 | if(!p_id) |
Wolfgang Betz |
6:8d2abd695c52 | 126 | { |
Wolfgang Betz |
6:8d2abd695c52 | 127 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 128 | } |
Wolfgang Betz |
6:8d2abd695c52 | 129 | |
Wolfgang Betz |
6:8d2abd695c52 | 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 | * @param None |
Wolfgang Betz |
6:8d2abd695c52 | 136 | * @retval PRESSURE_OK in case of success, an error code otherwise |
Wolfgang Betz |
6:8d2abd695c52 | 137 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 138 | PRESSURE_StatusTypeDef LPS25H::LPS25H_RebootCmd(void) |
Wolfgang Betz |
6:8d2abd695c52 | 139 | { |
Wolfgang Betz |
6:8d2abd695c52 | 140 | uint8_t tmpreg; |
Wolfgang Betz |
6:8d2abd695c52 | 141 | |
Wolfgang Betz |
6:8d2abd695c52 | 142 | /* Read CTRL_REG5 register */ |
Wolfgang Betz |
6:8d2abd695c52 | 143 | if(LPS25H_IO_Read(&tmpreg, LPS25H_CTRL_REG2_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 144 | { |
Wolfgang Betz |
6:8d2abd695c52 | 145 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 146 | } |
Wolfgang Betz |
6:8d2abd695c52 | 147 | |
Wolfgang Betz |
6:8d2abd695c52 | 148 | /* Enable or Disable the reboot memory */ |
Wolfgang Betz |
6:8d2abd695c52 | 149 | tmpreg |= LPS25H_RESET_MEMORY; |
Wolfgang Betz |
6:8d2abd695c52 | 150 | |
Wolfgang Betz |
6:8d2abd695c52 | 151 | /* Write value to MEMS CTRL_REG5 regsister */ |
Wolfgang Betz |
6:8d2abd695c52 | 152 | if(LPS25H_IO_Write(&tmpreg, LPS25H_CTRL_REG2_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 153 | { |
Wolfgang Betz |
6:8d2abd695c52 | 154 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 155 | } |
Wolfgang Betz |
6:8d2abd695c52 | 156 | |
Wolfgang Betz |
6:8d2abd695c52 | 157 | return PRESSURE_OK; |
Wolfgang Betz |
6:8d2abd695c52 | 158 | } |
Wolfgang Betz |
6:8d2abd695c52 | 159 | |
Wolfgang Betz |
6:8d2abd695c52 | 160 | |
Wolfgang Betz |
6:8d2abd695c52 | 161 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 162 | * @brief Read LPS25H output register, and calculate the raw pressure |
Wolfgang Betz |
6:8d2abd695c52 | 163 | * @param raw_press the pressure raw value |
Wolfgang Betz |
6:8d2abd695c52 | 164 | * @retval PRESSURE_OK in case of success, an error code otherwise |
Wolfgang Betz |
6:8d2abd695c52 | 165 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 166 | PRESSURE_StatusTypeDef LPS25H::LPS25H_I2C_ReadRawPressure(uint32_t *raw_press) |
Wolfgang Betz |
6:8d2abd695c52 | 167 | { |
Wolfgang Betz |
6:8d2abd695c52 | 168 | uint8_t buffer[3], i; |
Wolfgang Betz |
6:8d2abd695c52 | 169 | uint32_t tempVal=0; |
Wolfgang Betz |
6:8d2abd695c52 | 170 | |
Wolfgang Betz |
6:8d2abd695c52 | 171 | /* Read the register content */ |
Wolfgang Betz |
6:8d2abd695c52 | 172 | |
Wolfgang Betz |
6:8d2abd695c52 | 173 | if(LPS25H_IO_Read(buffer, (LPS25H_PRESS_POUT_XL_ADDR | LPS25H_I2C_MULTIPLEBYTE_CMD), 3) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 174 | { |
Wolfgang Betz |
6:8d2abd695c52 | 175 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 176 | } |
Wolfgang Betz |
6:8d2abd695c52 | 177 | |
Wolfgang Betz |
6:8d2abd695c52 | 178 | /* Build the raw data */ |
Wolfgang Betz |
6:8d2abd695c52 | 179 | for (i = 0 ; i < 3 ; i++) |
Wolfgang Betz |
6:8d2abd695c52 | 180 | tempVal |= (((uint32_t) buffer[i]) << (8 * i)); |
Wolfgang Betz |
6:8d2abd695c52 | 181 | |
Wolfgang Betz |
6:8d2abd695c52 | 182 | /* convert the 2's complement 24 bit to 2's complement 32 bit */ |
Wolfgang Betz |
6:8d2abd695c52 | 183 | if (tempVal & 0x00800000) |
Wolfgang Betz |
6:8d2abd695c52 | 184 | tempVal |= 0xFF000000; |
Wolfgang Betz |
6:8d2abd695c52 | 185 | |
Wolfgang Betz |
6:8d2abd695c52 | 186 | /* return the built value */ |
Wolfgang Betz |
6:8d2abd695c52 | 187 | *raw_press = ((uint32_t) tempVal); |
Wolfgang Betz |
6:8d2abd695c52 | 188 | |
Wolfgang Betz |
6:8d2abd695c52 | 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 |
6:8d2abd695c52 | 199 | uint32_t raw_press = 0; |
Wolfgang Betz |
6:8d2abd695c52 | 200 | |
Wolfgang Betz |
6:8d2abd695c52 | 201 | if(LPS25H_I2C_ReadRawPressure(&raw_press) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 202 | { |
Wolfgang Betz |
6:8d2abd695c52 | 203 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 204 | } |
Wolfgang Betz |
6:8d2abd695c52 | 205 | |
Wolfgang Betz |
6:8d2abd695c52 | 206 | *pfData = (float)raw_press /4096.0f; |
Wolfgang Betz |
6:8d2abd695c52 | 207 | |
Wolfgang Betz |
6:8d2abd695c52 | 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 |
6:8d2abd695c52 | 218 | uint8_t buffer[2]; |
Wolfgang Betz |
6:8d2abd695c52 | 219 | uint16_t tempVal=0; |
Wolfgang Betz |
6:8d2abd695c52 | 220 | |
Wolfgang Betz |
6:8d2abd695c52 | 221 | /* Read the register content */ |
Wolfgang Betz |
6:8d2abd695c52 | 222 | if(LPS25H_IO_Read(buffer, (LPS25H_TEMP_OUT_L_ADDR | LPS25H_I2C_MULTIPLEBYTE_CMD), 2) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 223 | { |
Wolfgang Betz |
6:8d2abd695c52 | 224 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 225 | } |
Wolfgang Betz |
6:8d2abd695c52 | 226 | |
Wolfgang Betz |
6:8d2abd695c52 | 227 | /* Build the raw value */ |
Wolfgang Betz |
6:8d2abd695c52 | 228 | tempVal = (((uint16_t)buffer[1]) << 8)+(uint16_t)buffer[0]; |
Wolfgang Betz |
6:8d2abd695c52 | 229 | |
Wolfgang Betz |
6:8d2abd695c52 | 230 | /* Return it */ |
Wolfgang Betz |
6:8d2abd695c52 | 231 | *raw_data = ((int16_t)tempVal); |
Wolfgang Betz |
6:8d2abd695c52 | 232 | |
Wolfgang Betz |
6:8d2abd695c52 | 233 | return PRESSURE_OK; |
Wolfgang Betz |
6:8d2abd695c52 | 234 | } |
Wolfgang Betz |
6:8d2abd695c52 | 235 | |
Wolfgang Betz |
6:8d2abd695c52 | 236 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 237 | * @brief Read LPS25H output register, and calculate the temperature |
Wolfgang Betz |
6:8d2abd695c52 | 238 | * @param pfData the temperature value |
Wolfgang Betz |
6:8d2abd695c52 | 239 | * @retval PRESSURE_OK in case of success, an error code otherwise |
Wolfgang Betz |
6:8d2abd695c52 | 240 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 241 | PRESSURE_StatusTypeDef LPS25H::LPS25H_GetTemperature(float *pfData) |
Wolfgang Betz |
6:8d2abd695c52 | 242 | { |
Wolfgang Betz |
6:8d2abd695c52 | 243 | int16_t raw_data; |
Wolfgang Betz |
6:8d2abd695c52 | 244 | |
Wolfgang Betz |
6:8d2abd695c52 | 245 | if(LPS25H_I2C_ReadRawTemperature(&raw_data) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 246 | { |
Wolfgang Betz |
6:8d2abd695c52 | 247 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 248 | } |
Wolfgang Betz |
6:8d2abd695c52 | 249 | |
Wolfgang Betz |
6:8d2abd695c52 | 250 | *pfData = (float)((((float)raw_data/480.0f) + 42.5f)); |
Wolfgang Betz |
6:8d2abd695c52 | 251 | |
Wolfgang Betz |
6:8d2abd695c52 | 252 | return PRESSURE_OK; |
Wolfgang Betz |
6:8d2abd695c52 | 253 | } |
Wolfgang Betz |
6:8d2abd695c52 | 254 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 255 | * @brief Exit the shutdown mode for LPS25H |
Wolfgang Betz |
6:8d2abd695c52 | 256 | * @param None |
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 |
6:8d2abd695c52 | 261 | uint8_t tmpreg; |
Wolfgang Betz |
6:8d2abd695c52 | 262 | |
Wolfgang Betz |
6:8d2abd695c52 | 263 | /* Read the register content */ |
Wolfgang Betz |
6:8d2abd695c52 | 264 | if(LPS25H_IO_Read(&tmpreg, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 265 | { |
Wolfgang Betz |
6:8d2abd695c52 | 266 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 267 | } |
Wolfgang Betz |
6:8d2abd695c52 | 268 | |
Wolfgang Betz |
6:8d2abd695c52 | 269 | /* Set the power down bit */ |
Wolfgang Betz |
6:8d2abd695c52 | 270 | tmpreg |= LPS25H_MODE_ACTIVE; |
Wolfgang Betz |
6:8d2abd695c52 | 271 | |
Wolfgang Betz |
6:8d2abd695c52 | 272 | /* Write register */ |
Wolfgang Betz |
6:8d2abd695c52 | 273 | if(LPS25H_IO_Write(&tmpreg, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 274 | { |
Wolfgang Betz |
6:8d2abd695c52 | 275 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 276 | } |
Wolfgang Betz |
6:8d2abd695c52 | 277 | |
Wolfgang Betz |
6:8d2abd695c52 | 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 | * @param None |
Wolfgang Betz |
6:8d2abd695c52 | 285 | * @retval PRESSURE_OK in case of success, an error code otherwise |
Wolfgang Betz |
6:8d2abd695c52 | 286 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 287 | PRESSURE_StatusTypeDef LPS25H::LPS25H_PowerOff(void) |
Wolfgang Betz |
6:8d2abd695c52 | 288 | { |
Wolfgang Betz |
6:8d2abd695c52 | 289 | uint8_t tmpreg; |
Wolfgang Betz |
6:8d2abd695c52 | 290 | |
Wolfgang Betz |
6:8d2abd695c52 | 291 | /* Read the register content */ |
Wolfgang Betz |
6:8d2abd695c52 | 292 | if(LPS25H_IO_Read(&tmpreg, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 293 | { |
Wolfgang Betz |
6:8d2abd695c52 | 294 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 295 | } |
Wolfgang Betz |
6:8d2abd695c52 | 296 | |
Wolfgang Betz |
6:8d2abd695c52 | 297 | /* Reset the power down bit */ |
Wolfgang Betz |
6:8d2abd695c52 | 298 | tmpreg &= ~(LPS25H_MODE_ACTIVE); |
Wolfgang Betz |
6:8d2abd695c52 | 299 | |
Wolfgang Betz |
6:8d2abd695c52 | 300 | /* Write register */ |
Wolfgang Betz |
6:8d2abd695c52 | 301 | if(LPS25H_IO_Write(&tmpreg, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK) |
Wolfgang Betz |
6:8d2abd695c52 | 302 | { |
Wolfgang Betz |
6:8d2abd695c52 | 303 | return PRESSURE_ERROR; |
Wolfgang Betz |
6:8d2abd695c52 | 304 | } |
Wolfgang Betz |
6:8d2abd695c52 | 305 | |
Wolfgang Betz |
6:8d2abd695c52 | 306 | return PRESSURE_OK; |
Wolfgang Betz |
6:8d2abd695c52 | 307 | } |
Wolfgang Betz |
6:8d2abd695c52 | 308 | |
Wolfgang Betz |
6:8d2abd695c52 | 309 | /** |
Wolfgang Betz |
6:8d2abd695c52 | 310 | * @brief Set the slave address according to SA0 bit |
Wolfgang Betz |
6:8d2abd695c52 | 311 | * @param SA0_Bit_Status LPS25H_SA0_LOW or LPS25H_SA0_HIGH |
Wolfgang Betz |
6:8d2abd695c52 | 312 | * @retval None |
Wolfgang Betz |
6:8d2abd695c52 | 313 | */ |
Wolfgang Betz |
6:8d2abd695c52 | 314 | void LPS25H::LPS25H_SlaveAddrRemap(uint8_t SA0_Bit_Status) |
Wolfgang Betz |
6:8d2abd695c52 | 315 | { |
Wolfgang Betz |
6:8d2abd695c52 | 316 | LPS25H_SlaveAddress = (SA0_Bit_Status==LPS25H_SA0_LOW?LPS25H_ADDRESS_LOW:LPS25H_ADDRESS_HIGH); |
Wolfgang Betz |
6:8d2abd695c52 | 317 | } |