STILL DEBUGGING

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_IKS01A1 by ST

Committer:
barry210110
Date:
Thu Aug 02 15:30:11 2018 +0000
Revision:
93:e28893a46ce7
Parent:
57:04563dd74269
DEBUGGING_3

Who changed what in which revision?

UserRevisionLine numberNew 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>&copy; 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 "lps25h_class.h"
Wolfgang Betz 6:8d2abd695c52 40 #include "lps25h.h"
Wolfgang Betz 6:8d2abd695c52 41
Wolfgang Betz 6:8d2abd695c52 42 /* Methods -------------------------------------------------------------------*/
Wolfgang Betz 6:8d2abd695c52 43 /* betzw - based on:
Wolfgang Betz 24:92cc9c6e4b2b 44 X-CUBE-MEMS1/trunk/Drivers/BSP/Components/lps25h/lps25h.c: revision #400,
Wolfgang Betz 57:04563dd74269 45 X-CUBE-MEMS1/trunk: revision #416
Wolfgang Betz 6:8d2abd695c52 46 */
Wolfgang Betz 57:04563dd74269 47
Wolfgang Betz 6:8d2abd695c52 48 /**
Wolfgang Betz 6:8d2abd695c52 49 * @brief Set LPS25H Initialization
Wolfgang Betz 6:8d2abd695c52 50 * @param LPS25H_Init the configuration setting for the LPS25H
Wolfgang Betz 6:8d2abd695c52 51 * @retval PRESSURE_OK in case of success, an error code otherwise
Wolfgang Betz 6:8d2abd695c52 52 */
Wolfgang Betz 6:8d2abd695c52 53 PRESSURE_StatusTypeDef LPS25H::LPS25H_Init(PRESSURE_InitTypeDef *LPS25H_Init)
Wolfgang Betz 24:92cc9c6e4b2b 54 {
Wolfgang Betz 24:92cc9c6e4b2b 55 uint8_t tmp1 = 0x00;
Wolfgang Betz 24:92cc9c6e4b2b 56
Wolfgang Betz 24:92cc9c6e4b2b 57 /* Configure the low level interface ---------------------------------------*/
Wolfgang Betz 24:92cc9c6e4b2b 58 if(LPS25H_IO_Init() != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 59 {
Wolfgang Betz 24:92cc9c6e4b2b 60 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 61 }
Wolfgang Betz 24:92cc9c6e4b2b 62
Wolfgang Betz 24:92cc9c6e4b2b 63 if(LPS25H_PowerOn() != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 64 {
Wolfgang Betz 24:92cc9c6e4b2b 65 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 66 }
Wolfgang Betz 24:92cc9c6e4b2b 67
Wolfgang Betz 24:92cc9c6e4b2b 68 if(LPS25H_IO_Read(&tmp1, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 69 {
Wolfgang Betz 24:92cc9c6e4b2b 70 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 71 }
Wolfgang Betz 24:92cc9c6e4b2b 72
Wolfgang Betz 24:92cc9c6e4b2b 73 /* Output Data Rate selection */
Wolfgang Betz 24:92cc9c6e4b2b 74 tmp1 &= ~(LPS25H_ODR_MASK);
Wolfgang Betz 24:92cc9c6e4b2b 75 tmp1 |= LPS25H_Init->OutputDataRate;
Wolfgang Betz 24:92cc9c6e4b2b 76
Wolfgang Betz 24:92cc9c6e4b2b 77 /* Interrupt circuit selection */
Wolfgang Betz 24:92cc9c6e4b2b 78 tmp1 &= ~(LPS25H_DIFF_EN_MASK);
Wolfgang Betz 24:92cc9c6e4b2b 79 tmp1 |= LPS25H_Init->DiffEnable;
Wolfgang Betz 24:92cc9c6e4b2b 80
Wolfgang Betz 24:92cc9c6e4b2b 81 /* Block Data Update selection */
Wolfgang Betz 24:92cc9c6e4b2b 82 tmp1 &= ~(LPS25H_BDU_MASK);
Wolfgang Betz 24:92cc9c6e4b2b 83 tmp1 |= LPS25H_Init->BlockDataUpdate;
Wolfgang Betz 24:92cc9c6e4b2b 84
Wolfgang Betz 24:92cc9c6e4b2b 85 /* Serial Interface Mode selection */
Wolfgang Betz 24:92cc9c6e4b2b 86 tmp1 &= ~(LPS25H_SPI_SIM_MASK);
Wolfgang Betz 24:92cc9c6e4b2b 87 tmp1 |= LPS25H_Init->SPIMode;
Wolfgang Betz 24:92cc9c6e4b2b 88
Wolfgang Betz 24:92cc9c6e4b2b 89 if(LPS25H_IO_Write(&tmp1, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 90 {
Wolfgang Betz 24:92cc9c6e4b2b 91 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 92 }
Wolfgang Betz 24:92cc9c6e4b2b 93
Wolfgang Betz 24:92cc9c6e4b2b 94 if(LPS25H_IO_Read(&tmp1, LPS25H_RES_CONF_ADDR, 1) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 95 {
Wolfgang Betz 24:92cc9c6e4b2b 96 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 97 }
Wolfgang Betz 24:92cc9c6e4b2b 98
Wolfgang Betz 24:92cc9c6e4b2b 99 /* Serial Interface Mode selection */
Wolfgang Betz 24:92cc9c6e4b2b 100 tmp1 &= ~(LPS25H_P_RES_MASK);
Wolfgang Betz 24:92cc9c6e4b2b 101 tmp1 |= LPS25H_Init->PressureResolution;
Wolfgang Betz 24:92cc9c6e4b2b 102
Wolfgang Betz 24:92cc9c6e4b2b 103 /* Serial Interface Mode selection */
Wolfgang Betz 24:92cc9c6e4b2b 104 tmp1 &= ~(LPS25H_T_RES_MASK);
Wolfgang Betz 24:92cc9c6e4b2b 105 tmp1 |= LPS25H_Init->TemperatureResolution;
Wolfgang Betz 24:92cc9c6e4b2b 106
Wolfgang Betz 24:92cc9c6e4b2b 107 if(LPS25H_IO_Write(&tmp1, LPS25H_RES_CONF_ADDR, 1) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 108 {
Wolfgang Betz 24:92cc9c6e4b2b 109 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 110 }
Wolfgang Betz 24:92cc9c6e4b2b 111
Wolfgang Betz 24:92cc9c6e4b2b 112 LPS25H_IO_ITConfig();
Wolfgang Betz 24:92cc9c6e4b2b 113
Wolfgang Betz 24:92cc9c6e4b2b 114 return PRESSURE_OK;
Wolfgang Betz 6:8d2abd695c52 115 }
Wolfgang Betz 6:8d2abd695c52 116
Wolfgang Betz 6:8d2abd695c52 117 /**
Wolfgang Betz 6:8d2abd695c52 118 * @brief Read ID address of LPS25H
Wolfgang Betz 6:8d2abd695c52 119 * @param ht_id the pointer where the ID of the device is stored
Wolfgang Betz 6:8d2abd695c52 120 * @retval PRESSURE_OK in case of success, an error code otherwise
Wolfgang Betz 6:8d2abd695c52 121 */
Wolfgang Betz 6:8d2abd695c52 122 PRESSURE_StatusTypeDef LPS25H::LPS25H_ReadID(uint8_t *p_id)
Wolfgang Betz 6:8d2abd695c52 123 {
Wolfgang Betz 24:92cc9c6e4b2b 124 if(!p_id)
Wolfgang Betz 24:92cc9c6e4b2b 125 {
Wolfgang Betz 24:92cc9c6e4b2b 126 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 127 }
Wolfgang Betz 24:92cc9c6e4b2b 128
Wolfgang Betz 24:92cc9c6e4b2b 129 return LPS25H_IO_Read(p_id, LPS25H_WHO_AM_I_ADDR, 1);
Wolfgang Betz 6:8d2abd695c52 130 }
Wolfgang Betz 6:8d2abd695c52 131
Wolfgang Betz 6:8d2abd695c52 132 /**
Wolfgang Betz 6:8d2abd695c52 133 * @brief Reboot memory content of LPS25H
Wolfgang Betz 6:8d2abd695c52 134 * @retval PRESSURE_OK in case of success, an error code otherwise
Wolfgang Betz 6:8d2abd695c52 135 */
Wolfgang Betz 6:8d2abd695c52 136 PRESSURE_StatusTypeDef LPS25H::LPS25H_RebootCmd(void)
Wolfgang Betz 6:8d2abd695c52 137 {
Wolfgang Betz 24:92cc9c6e4b2b 138 uint8_t tmpreg;
Wolfgang Betz 24:92cc9c6e4b2b 139
Wolfgang Betz 24:92cc9c6e4b2b 140 /* Read CTRL_REG5 register */
Wolfgang Betz 24:92cc9c6e4b2b 141 if(LPS25H_IO_Read(&tmpreg, LPS25H_CTRL_REG2_ADDR, 1) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 142 {
Wolfgang Betz 24:92cc9c6e4b2b 143 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 144 }
Wolfgang Betz 24:92cc9c6e4b2b 145
Wolfgang Betz 24:92cc9c6e4b2b 146 /* Enable or Disable the reboot memory */
Wolfgang Betz 24:92cc9c6e4b2b 147 tmpreg |= LPS25H_RESET_MEMORY;
Wolfgang Betz 24:92cc9c6e4b2b 148
Wolfgang Betz 24:92cc9c6e4b2b 149 /* Write value to MEMS CTRL_REG5 regsister */
Wolfgang Betz 24:92cc9c6e4b2b 150 if(LPS25H_IO_Write(&tmpreg, LPS25H_CTRL_REG2_ADDR, 1) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 151 {
Wolfgang Betz 24:92cc9c6e4b2b 152 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 153 }
Wolfgang Betz 24:92cc9c6e4b2b 154
Wolfgang Betz 24:92cc9c6e4b2b 155 return PRESSURE_OK;
Wolfgang Betz 6:8d2abd695c52 156 }
Wolfgang Betz 6:8d2abd695c52 157
Wolfgang Betz 6:8d2abd695c52 158
Wolfgang Betz 6:8d2abd695c52 159 /**
Wolfgang Betz 6:8d2abd695c52 160 * @brief Read LPS25H output register, and calculate the raw pressure
Wolfgang Betz 6:8d2abd695c52 161 * @param raw_press the pressure raw value
Wolfgang Betz 6:8d2abd695c52 162 * @retval PRESSURE_OK in case of success, an error code otherwise
Wolfgang Betz 6:8d2abd695c52 163 */
Wolfgang Betz 24:92cc9c6e4b2b 164 PRESSURE_StatusTypeDef LPS25H::LPS25H_I2C_ReadRawPressure(int32_t *raw_press)
Wolfgang Betz 6:8d2abd695c52 165 {
Wolfgang Betz 24:92cc9c6e4b2b 166 uint8_t buffer[3], i;
Wolfgang Betz 24:92cc9c6e4b2b 167 uint32_t tempVal = 0;
Wolfgang Betz 24:92cc9c6e4b2b 168
Wolfgang Betz 24:92cc9c6e4b2b 169 /* Read the register content */
Wolfgang Betz 24:92cc9c6e4b2b 170
Wolfgang Betz 24:92cc9c6e4b2b 171 if(LPS25H_IO_Read(buffer, (LPS25H_PRESS_POUT_XL_ADDR | LPS25H_I2C_MULTIPLEBYTE_CMD),
Wolfgang Betz 24:92cc9c6e4b2b 172 3) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 173 {
Wolfgang Betz 24:92cc9c6e4b2b 174 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 175 }
Wolfgang Betz 24:92cc9c6e4b2b 176
Wolfgang Betz 24:92cc9c6e4b2b 177 /* Build the raw data */
Wolfgang Betz 24:92cc9c6e4b2b 178 for (i = 0 ; i < 3 ; i++)
Wolfgang Betz 24:92cc9c6e4b2b 179 tempVal |= (((uint32_t) buffer[i]) << (8 * i));
Wolfgang Betz 6:8d2abd695c52 180
Wolfgang Betz 24:92cc9c6e4b2b 181 /* convert the 2's complement 24 bit to 2's complement 32 bit */
Wolfgang Betz 24:92cc9c6e4b2b 182 if (tempVal & 0x00800000)
Wolfgang Betz 24:92cc9c6e4b2b 183 tempVal |= 0xFF000000;
Wolfgang Betz 24:92cc9c6e4b2b 184
Wolfgang Betz 24:92cc9c6e4b2b 185 /* return the built value */
Wolfgang Betz 24:92cc9c6e4b2b 186 *raw_press = ((int32_t) tempVal);
Wolfgang Betz 24:92cc9c6e4b2b 187
Wolfgang Betz 24:92cc9c6e4b2b 188 return PRESSURE_OK;
Wolfgang Betz 6:8d2abd695c52 189 }
Wolfgang Betz 6:8d2abd695c52 190
Wolfgang Betz 6:8d2abd695c52 191 /**
Wolfgang Betz 6:8d2abd695c52 192 * @brief Read LPS25H output register, and calculate the pressure in mbar
Wolfgang Betz 6:8d2abd695c52 193 * @param pfData the pressure value in mbar
Wolfgang Betz 6:8d2abd695c52 194 * @retval PRESSURE_OK in case of success, an error code otherwise
Wolfgang Betz 6:8d2abd695c52 195 */
Wolfgang Betz 6:8d2abd695c52 196 PRESSURE_StatusTypeDef LPS25H::LPS25H_GetPressure(float* pfData)
Wolfgang Betz 6:8d2abd695c52 197 {
Wolfgang Betz 24:92cc9c6e4b2b 198 int32_t raw_press = 0;
Wolfgang Betz 24:92cc9c6e4b2b 199
Wolfgang Betz 24:92cc9c6e4b2b 200 if(LPS25H_I2C_ReadRawPressure(&raw_press) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 201 {
Wolfgang Betz 24:92cc9c6e4b2b 202 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 203 }
Wolfgang Betz 24:92cc9c6e4b2b 204
Wolfgang Betz 24:92cc9c6e4b2b 205 *pfData = (float)raw_press / 4096.0f;
Wolfgang Betz 24:92cc9c6e4b2b 206
Wolfgang Betz 24:92cc9c6e4b2b 207 return PRESSURE_OK;
Wolfgang Betz 6:8d2abd695c52 208 }
Wolfgang Betz 6:8d2abd695c52 209
Wolfgang Betz 6:8d2abd695c52 210 /**
Wolfgang Betz 6:8d2abd695c52 211 * @brief Read LPS25H output register, and calculate the raw temperature
Wolfgang Betz 6:8d2abd695c52 212 * @param raw_data the temperature raw value
Wolfgang Betz 6:8d2abd695c52 213 * @retval PRESSURE_OK in case of success, an error code otherwise
Wolfgang Betz 6:8d2abd695c52 214 */
Wolfgang Betz 6:8d2abd695c52 215 PRESSURE_StatusTypeDef LPS25H::LPS25H_I2C_ReadRawTemperature(int16_t *raw_data)
Wolfgang Betz 6:8d2abd695c52 216 {
Wolfgang Betz 24:92cc9c6e4b2b 217 uint8_t buffer[2];
Wolfgang Betz 24:92cc9c6e4b2b 218 uint16_t tempVal = 0;
Wolfgang Betz 24:92cc9c6e4b2b 219
Wolfgang Betz 24:92cc9c6e4b2b 220 /* Read the register content */
Wolfgang Betz 24:92cc9c6e4b2b 221 if(LPS25H_IO_Read(buffer, (LPS25H_TEMP_OUT_L_ADDR | LPS25H_I2C_MULTIPLEBYTE_CMD),
Wolfgang Betz 24:92cc9c6e4b2b 222 2) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 223 {
Wolfgang Betz 24:92cc9c6e4b2b 224 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 225 }
Wolfgang Betz 24:92cc9c6e4b2b 226
Wolfgang Betz 24:92cc9c6e4b2b 227 /* Build the raw value */
Wolfgang Betz 24:92cc9c6e4b2b 228 tempVal = (((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0];
Wolfgang Betz 24:92cc9c6e4b2b 229
Wolfgang Betz 24:92cc9c6e4b2b 230 /* Return it */
Wolfgang Betz 24:92cc9c6e4b2b 231 *raw_data = ((int16_t)tempVal);
Wolfgang Betz 24:92cc9c6e4b2b 232
Wolfgang Betz 24:92cc9c6e4b2b 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 24:92cc9c6e4b2b 243 int16_t raw_data;
Wolfgang Betz 24:92cc9c6e4b2b 244
Wolfgang Betz 24:92cc9c6e4b2b 245 if(LPS25H_I2C_ReadRawTemperature(&raw_data) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 246 {
Wolfgang Betz 24:92cc9c6e4b2b 247 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 248 }
Wolfgang Betz 24:92cc9c6e4b2b 249
Wolfgang Betz 24:92cc9c6e4b2b 250 *pfData = (float)((((float)raw_data / 480.0f) + 42.5f));
Wolfgang Betz 24:92cc9c6e4b2b 251
Wolfgang Betz 24:92cc9c6e4b2b 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 * @retval PRESSURE_OK in case of success, an error code otherwise
Wolfgang Betz 6:8d2abd695c52 257 */
Wolfgang Betz 6:8d2abd695c52 258 PRESSURE_StatusTypeDef LPS25H::LPS25H_PowerOn(void)
Wolfgang Betz 6:8d2abd695c52 259 {
Wolfgang Betz 24:92cc9c6e4b2b 260 uint8_t tmpreg;
Wolfgang Betz 24:92cc9c6e4b2b 261
Wolfgang Betz 24:92cc9c6e4b2b 262 /* Read the register content */
Wolfgang Betz 24:92cc9c6e4b2b 263 if(LPS25H_IO_Read(&tmpreg, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 264 {
Wolfgang Betz 24:92cc9c6e4b2b 265 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 266 }
Wolfgang Betz 24:92cc9c6e4b2b 267
Wolfgang Betz 24:92cc9c6e4b2b 268 /* Set the power down bit */
Wolfgang Betz 24:92cc9c6e4b2b 269 tmpreg |= LPS25H_MODE_ACTIVE;
Wolfgang Betz 24:92cc9c6e4b2b 270
Wolfgang Betz 24:92cc9c6e4b2b 271 /* Write register */
Wolfgang Betz 24:92cc9c6e4b2b 272 if(LPS25H_IO_Write(&tmpreg, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 273 {
Wolfgang Betz 24:92cc9c6e4b2b 274 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 275 }
Wolfgang Betz 24:92cc9c6e4b2b 276
Wolfgang Betz 24:92cc9c6e4b2b 277 return PRESSURE_OK;
Wolfgang Betz 6:8d2abd695c52 278 }
Wolfgang Betz 6:8d2abd695c52 279
Wolfgang Betz 6:8d2abd695c52 280
Wolfgang Betz 6:8d2abd695c52 281 /**
Wolfgang Betz 6:8d2abd695c52 282 * @brief Enter the shutdown mode for LPS25H
Wolfgang Betz 6:8d2abd695c52 283 * @retval PRESSURE_OK in case of success, an error code otherwise
Wolfgang Betz 6:8d2abd695c52 284 */
Wolfgang Betz 6:8d2abd695c52 285 PRESSURE_StatusTypeDef LPS25H::LPS25H_PowerOff(void)
Wolfgang Betz 6:8d2abd695c52 286 {
Wolfgang Betz 24:92cc9c6e4b2b 287 uint8_t tmpreg;
Wolfgang Betz 24:92cc9c6e4b2b 288
Wolfgang Betz 24:92cc9c6e4b2b 289 /* Read the register content */
Wolfgang Betz 24:92cc9c6e4b2b 290 if(LPS25H_IO_Read(&tmpreg, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 291 {
Wolfgang Betz 24:92cc9c6e4b2b 292 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 293 }
Wolfgang Betz 24:92cc9c6e4b2b 294
Wolfgang Betz 24:92cc9c6e4b2b 295 /* Reset the power down bit */
Wolfgang Betz 24:92cc9c6e4b2b 296 tmpreg &= ~(LPS25H_MODE_ACTIVE);
Wolfgang Betz 24:92cc9c6e4b2b 297
Wolfgang Betz 24:92cc9c6e4b2b 298 /* Write register */
Wolfgang Betz 24:92cc9c6e4b2b 299 if(LPS25H_IO_Write(&tmpreg, LPS25H_CTRL_REG1_ADDR, 1) != PRESSURE_OK)
Wolfgang Betz 24:92cc9c6e4b2b 300 {
Wolfgang Betz 24:92cc9c6e4b2b 301 return PRESSURE_ERROR;
Wolfgang Betz 24:92cc9c6e4b2b 302 }
Wolfgang Betz 24:92cc9c6e4b2b 303
Wolfgang Betz 24:92cc9c6e4b2b 304 return PRESSURE_OK;
Wolfgang Betz 6:8d2abd695c52 305 }
Wolfgang Betz 6:8d2abd695c52 306
Wolfgang Betz 6:8d2abd695c52 307 /**
Wolfgang Betz 6:8d2abd695c52 308 * @brief Set the slave address according to SA0 bit
Wolfgang Betz 6:8d2abd695c52 309 * @param SA0_Bit_Status LPS25H_SA0_LOW or LPS25H_SA0_HIGH
Wolfgang Betz 6:8d2abd695c52 310 * @retval None
Wolfgang Betz 6:8d2abd695c52 311 */
Wolfgang Betz 6:8d2abd695c52 312 void LPS25H::LPS25H_SlaveAddrRemap(uint8_t SA0_Bit_Status)
Wolfgang Betz 6:8d2abd695c52 313 {
Wolfgang Betz 24:92cc9c6e4b2b 314 LPS25H_SlaveAddress = (SA0_Bit_Status == LPS25H_SA0_LOW ? LPS25H_ADDRESS_LOW : LPS25H_ADDRESS_HIGH);
Wolfgang Betz 6:8d2abd695c52 315 }
Wolfgang Betz 24:92cc9c6e4b2b 316
Wolfgang Betz 24:92cc9c6e4b2b 317 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/