Example for Bluetooth low energy interface
Dependencies: mbed HC_SR04_Ultrasonic_Library
Sensor_Shield/x_nucleo_iks01a1_pressure.c@3:829f081fde15, 2015-05-19 (annotated)
- Committer:
- julientiron
- Date:
- Tue May 19 20:42:25 2015 +0000
- Revision:
- 3:829f081fde15
- Parent:
- 1:bdbf36f8408d
hihi;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
julientiron | 1:bdbf36f8408d | 1 | /** |
julientiron | 1:bdbf36f8408d | 2 | ****************************************************************************** |
julientiron | 1:bdbf36f8408d | 3 | * @file x_nucleo_iks01a1_pressure.c |
julientiron | 1:bdbf36f8408d | 4 | * @author MEMS Application Team |
julientiron | 1:bdbf36f8408d | 5 | * @version V1.0.0 |
julientiron | 1:bdbf36f8408d | 6 | * @date 30-July-2014 |
julientiron | 1:bdbf36f8408d | 7 | * @brief This file provides a set of functions needed to manage the lps25h sensor. |
julientiron | 1:bdbf36f8408d | 8 | ****************************************************************************** |
julientiron | 1:bdbf36f8408d | 9 | * @attention |
julientiron | 1:bdbf36f8408d | 10 | * |
julientiron | 1:bdbf36f8408d | 11 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
julientiron | 1:bdbf36f8408d | 12 | * |
julientiron | 1:bdbf36f8408d | 13 | * Redistribution and use in source and binary forms, with or without modification, |
julientiron | 1:bdbf36f8408d | 14 | * are permitted provided that the following conditions are met: |
julientiron | 1:bdbf36f8408d | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
julientiron | 1:bdbf36f8408d | 16 | * this list of conditions and the following disclaimer. |
julientiron | 1:bdbf36f8408d | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
julientiron | 1:bdbf36f8408d | 18 | * this list of conditions and the following disclaimer in the documentation |
julientiron | 1:bdbf36f8408d | 19 | * and/or other materials provided with the distribution. |
julientiron | 1:bdbf36f8408d | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
julientiron | 1:bdbf36f8408d | 21 | * may be used to endorse or promote products derived from this software |
julientiron | 1:bdbf36f8408d | 22 | * without specific prior written permission. |
julientiron | 1:bdbf36f8408d | 23 | * |
julientiron | 1:bdbf36f8408d | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
julientiron | 1:bdbf36f8408d | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
julientiron | 1:bdbf36f8408d | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
julientiron | 1:bdbf36f8408d | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
julientiron | 1:bdbf36f8408d | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
julientiron | 1:bdbf36f8408d | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
julientiron | 1:bdbf36f8408d | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
julientiron | 1:bdbf36f8408d | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
julientiron | 1:bdbf36f8408d | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
julientiron | 1:bdbf36f8408d | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
julientiron | 1:bdbf36f8408d | 34 | * |
julientiron | 1:bdbf36f8408d | 35 | ****************************************************************************** |
julientiron | 1:bdbf36f8408d | 36 | */ |
julientiron | 1:bdbf36f8408d | 37 | /* Includes ------------------------------------------------------------------*/ |
julientiron | 1:bdbf36f8408d | 38 | #include "x_nucleo_iks01a1_pressure.h" |
julientiron | 1:bdbf36f8408d | 39 | |
julientiron | 1:bdbf36f8408d | 40 | /** @addtogroup BSP |
julientiron | 1:bdbf36f8408d | 41 | * @{ |
julientiron | 1:bdbf36f8408d | 42 | */ |
julientiron | 1:bdbf36f8408d | 43 | |
julientiron | 1:bdbf36f8408d | 44 | /** @addtogroup X_NUCLEO_IKS01A1 |
julientiron | 1:bdbf36f8408d | 45 | * @{ |
julientiron | 1:bdbf36f8408d | 46 | */ |
julientiron | 1:bdbf36f8408d | 47 | |
julientiron | 1:bdbf36f8408d | 48 | /** @addtogroup X_NUCLEO_IKS01A1_PRESSURE |
julientiron | 1:bdbf36f8408d | 49 | * @{ |
julientiron | 1:bdbf36f8408d | 50 | */ |
julientiron | 1:bdbf36f8408d | 51 | |
julientiron | 1:bdbf36f8408d | 52 | |
julientiron | 1:bdbf36f8408d | 53 | /** @defgroup X_NUCLEO_IKS01A1_PRESSURE_Private_TypesDefinitions |
julientiron | 1:bdbf36f8408d | 54 | * @{ |
julientiron | 1:bdbf36f8408d | 55 | */ |
julientiron | 1:bdbf36f8408d | 56 | |
julientiron | 1:bdbf36f8408d | 57 | /** |
julientiron | 1:bdbf36f8408d | 58 | * @} |
julientiron | 1:bdbf36f8408d | 59 | */ |
julientiron | 1:bdbf36f8408d | 60 | |
julientiron | 1:bdbf36f8408d | 61 | /** @defgroup X_NUCLEO_IKS01A1_PRESSURE_Private_Defines |
julientiron | 1:bdbf36f8408d | 62 | * @{ |
julientiron | 1:bdbf36f8408d | 63 | */ |
julientiron | 1:bdbf36f8408d | 64 | #ifndef NULL |
julientiron | 1:bdbf36f8408d | 65 | #define NULL (void *) 0 |
julientiron | 1:bdbf36f8408d | 66 | #endif |
julientiron | 1:bdbf36f8408d | 67 | /** |
julientiron | 1:bdbf36f8408d | 68 | * @} |
julientiron | 1:bdbf36f8408d | 69 | */ |
julientiron | 1:bdbf36f8408d | 70 | |
julientiron | 1:bdbf36f8408d | 71 | /** @defgroup X_NUCLEO_IKS01A1_PRESSURE_Private_Macros |
julientiron | 1:bdbf36f8408d | 72 | * @{ |
julientiron | 1:bdbf36f8408d | 73 | */ |
julientiron | 1:bdbf36f8408d | 74 | |
julientiron | 1:bdbf36f8408d | 75 | /** |
julientiron | 1:bdbf36f8408d | 76 | * @} |
julientiron | 1:bdbf36f8408d | 77 | */ |
julientiron | 1:bdbf36f8408d | 78 | |
julientiron | 1:bdbf36f8408d | 79 | /** @defgroup X_NUCLEO_IKS01A1_PRESSURE_Private_Variables |
julientiron | 1:bdbf36f8408d | 80 | * @{ |
julientiron | 1:bdbf36f8408d | 81 | */ |
julientiron | 1:bdbf36f8408d | 82 | static PRESSURE_DrvTypeDef *PressureDrv; |
julientiron | 1:bdbf36f8408d | 83 | static uint8_t PressureInitialized = 0; |
julientiron | 1:bdbf36f8408d | 84 | |
julientiron | 1:bdbf36f8408d | 85 | /** |
julientiron | 1:bdbf36f8408d | 86 | * @} |
julientiron | 1:bdbf36f8408d | 87 | */ |
julientiron | 1:bdbf36f8408d | 88 | |
julientiron | 1:bdbf36f8408d | 89 | /** @defgroup X_NUCLEO_IKS01A1_PRESSURE_Private_FunctionPrototypes |
julientiron | 1:bdbf36f8408d | 90 | * @{ |
julientiron | 1:bdbf36f8408d | 91 | */ |
julientiron | 1:bdbf36f8408d | 92 | |
julientiron | 1:bdbf36f8408d | 93 | /** |
julientiron | 1:bdbf36f8408d | 94 | * @} |
julientiron | 1:bdbf36f8408d | 95 | */ |
julientiron | 1:bdbf36f8408d | 96 | |
julientiron | 1:bdbf36f8408d | 97 | /** @defgroup X_NUCLEO_IKS01A1_PRESSURE_Private_Functions |
julientiron | 1:bdbf36f8408d | 98 | * @{ |
julientiron | 1:bdbf36f8408d | 99 | */ |
julientiron | 1:bdbf36f8408d | 100 | |
julientiron | 1:bdbf36f8408d | 101 | /** |
julientiron | 1:bdbf36f8408d | 102 | * @brief Initialization pressure sensor. |
julientiron | 1:bdbf36f8408d | 103 | * @param None |
julientiron | 1:bdbf36f8408d | 104 | * @retval PRESSURE_OK if no problem during initialization |
julientiron | 1:bdbf36f8408d | 105 | */ |
julientiron | 1:bdbf36f8408d | 106 | PRESSURE_StatusTypeDef BSP_PRESSURE_Init(void) |
julientiron | 1:bdbf36f8408d | 107 | { |
julientiron | 1:bdbf36f8408d | 108 | PRESSURE_StatusTypeDef ret = PRESSURE_ERROR; |
julientiron | 1:bdbf36f8408d | 109 | PRESSURE_InitTypeDef LPS25H_InitStructure; |
julientiron | 1:bdbf36f8408d | 110 | |
julientiron | 1:bdbf36f8408d | 111 | // LPS25H_SlaveAddrRemap(LPS25H_SA0_HIGH); |
julientiron | 1:bdbf36f8408d | 112 | |
julientiron | 1:bdbf36f8408d | 113 | /* Initialize the uv driver structure */ |
julientiron | 1:bdbf36f8408d | 114 | PressureDrv = &LPS25HDrv; |
julientiron | 1:bdbf36f8408d | 115 | |
julientiron | 1:bdbf36f8408d | 116 | /* Configure sensor */ |
julientiron | 1:bdbf36f8408d | 117 | LPS25H_InitStructure.OutputDataRate = LPS25H_ODR_1Hz; |
julientiron | 1:bdbf36f8408d | 118 | LPS25H_InitStructure.BlockDataUpdate = LPS25H_BDU_CONT; |
julientiron | 1:bdbf36f8408d | 119 | LPS25H_InitStructure.DiffEnable = LPS25H_DIFF_ENABLE; |
julientiron | 1:bdbf36f8408d | 120 | LPS25H_InitStructure.SPIMode = LPS25H_SPI_SIM_3W; |
julientiron | 1:bdbf36f8408d | 121 | LPS25H_InitStructure.PressureResolution = LPS25H_P_RES_AVG_32; |
julientiron | 1:bdbf36f8408d | 122 | LPS25H_InitStructure.TemperatureResolution = LPS25H_T_RES_AVG_16; |
julientiron | 1:bdbf36f8408d | 123 | |
julientiron | 1:bdbf36f8408d | 124 | /* Pressure sensor init */ |
julientiron | 1:bdbf36f8408d | 125 | PressureDrv->Init(&LPS25H_InitStructure); |
julientiron | 1:bdbf36f8408d | 126 | |
julientiron | 1:bdbf36f8408d | 127 | if(PressureDrv->ReadID() == I_AM_LPS25H) |
julientiron | 1:bdbf36f8408d | 128 | { |
julientiron | 1:bdbf36f8408d | 129 | PressureInitialized = 1; |
julientiron | 1:bdbf36f8408d | 130 | ret = PRESSURE_OK; |
julientiron | 1:bdbf36f8408d | 131 | } |
julientiron | 1:bdbf36f8408d | 132 | |
julientiron | 1:bdbf36f8408d | 133 | return ret; |
julientiron | 1:bdbf36f8408d | 134 | } |
julientiron | 1:bdbf36f8408d | 135 | |
julientiron | 1:bdbf36f8408d | 136 | uint8_t BSP_PRESSURE_isInitialized(void) |
julientiron | 1:bdbf36f8408d | 137 | { |
julientiron | 1:bdbf36f8408d | 138 | return PressureInitialized; |
julientiron | 1:bdbf36f8408d | 139 | } |
julientiron | 1:bdbf36f8408d | 140 | |
julientiron | 1:bdbf36f8408d | 141 | /** |
julientiron | 1:bdbf36f8408d | 142 | * @brief Read ID of Uv component |
julientiron | 1:bdbf36f8408d | 143 | * @param None |
julientiron | 1:bdbf36f8408d | 144 | * @retval ID |
julientiron | 1:bdbf36f8408d | 145 | */ |
julientiron | 1:bdbf36f8408d | 146 | uint8_t BSP_PRESSURE_ReadID(void) |
julientiron | 1:bdbf36f8408d | 147 | { |
julientiron | 1:bdbf36f8408d | 148 | uint8_t id = 0x00; |
julientiron | 1:bdbf36f8408d | 149 | |
julientiron | 1:bdbf36f8408d | 150 | if(PressureDrv->ReadID != NULL) |
julientiron | 1:bdbf36f8408d | 151 | { |
julientiron | 1:bdbf36f8408d | 152 | id = PressureDrv->ReadID(); |
julientiron | 1:bdbf36f8408d | 153 | } |
julientiron | 1:bdbf36f8408d | 154 | return id; |
julientiron | 1:bdbf36f8408d | 155 | } |
julientiron | 1:bdbf36f8408d | 156 | |
julientiron | 1:bdbf36f8408d | 157 | |
julientiron | 1:bdbf36f8408d | 158 | /** |
julientiron | 1:bdbf36f8408d | 159 | * @brief Check ID of LPS25H Pressure sensor |
julientiron | 1:bdbf36f8408d | 160 | * @param None |
julientiron | 1:bdbf36f8408d | 161 | * @retval Test status |
julientiron | 1:bdbf36f8408d | 162 | */ |
julientiron | 1:bdbf36f8408d | 163 | PRESSURE_StatusTypeDef BSP_PRESSURE_CheckID(void) { |
julientiron | 1:bdbf36f8408d | 164 | if (BSP_PRESSURE_ReadID() == I_AM_LPS25H) { |
julientiron | 1:bdbf36f8408d | 165 | return PRESSURE_OK; |
julientiron | 1:bdbf36f8408d | 166 | } else { |
julientiron | 1:bdbf36f8408d | 167 | return PRESSURE_ERROR; |
julientiron | 1:bdbf36f8408d | 168 | } |
julientiron | 1:bdbf36f8408d | 169 | } |
julientiron | 1:bdbf36f8408d | 170 | |
julientiron | 1:bdbf36f8408d | 171 | |
julientiron | 1:bdbf36f8408d | 172 | /** |
julientiron | 1:bdbf36f8408d | 173 | * @brief Reboot memory content of LPS25H Pressure sensor |
julientiron | 1:bdbf36f8408d | 174 | * @param None |
julientiron | 1:bdbf36f8408d | 175 | * @retval None |
julientiron | 1:bdbf36f8408d | 176 | */ |
julientiron | 1:bdbf36f8408d | 177 | void BSP_PRESSURE_Reset(void) |
julientiron | 1:bdbf36f8408d | 178 | { |
julientiron | 1:bdbf36f8408d | 179 | if(PressureDrv->Reset != NULL) |
julientiron | 1:bdbf36f8408d | 180 | { |
julientiron | 1:bdbf36f8408d | 181 | PressureDrv->Reset(); |
julientiron | 1:bdbf36f8408d | 182 | } |
julientiron | 1:bdbf36f8408d | 183 | } |
julientiron | 1:bdbf36f8408d | 184 | |
julientiron | 1:bdbf36f8408d | 185 | |
julientiron | 1:bdbf36f8408d | 186 | /** |
julientiron | 1:bdbf36f8408d | 187 | * @brief Get Pressure |
julientiron | 1:bdbf36f8408d | 188 | * @param pfData: pointer on floating data |
julientiron | 1:bdbf36f8408d | 189 | * @retval None |
julientiron | 1:bdbf36f8408d | 190 | */ |
julientiron | 1:bdbf36f8408d | 191 | void BSP_PRESSURE_GetPressure(float* pfData) |
julientiron | 1:bdbf36f8408d | 192 | { |
julientiron | 1:bdbf36f8408d | 193 | if(PressureDrv->GetPressure!= NULL) |
julientiron | 1:bdbf36f8408d | 194 | { |
julientiron | 1:bdbf36f8408d | 195 | PressureDrv->GetPressure(pfData); |
julientiron | 1:bdbf36f8408d | 196 | } |
julientiron | 1:bdbf36f8408d | 197 | } |
julientiron | 1:bdbf36f8408d | 198 | |
julientiron | 1:bdbf36f8408d | 199 | /** |
julientiron | 1:bdbf36f8408d | 200 | * @brief Get Temperature |
julientiron | 1:bdbf36f8408d | 201 | * @param pfData: pointer on floating data |
julientiron | 1:bdbf36f8408d | 202 | * @retval None |
julientiron | 1:bdbf36f8408d | 203 | */ |
julientiron | 1:bdbf36f8408d | 204 | void BSP_PRESSURE_GetTemperature(float* pfData) |
julientiron | 1:bdbf36f8408d | 205 | { |
julientiron | 1:bdbf36f8408d | 206 | if(PressureDrv->GetTemperature!= NULL) |
julientiron | 1:bdbf36f8408d | 207 | { |
julientiron | 1:bdbf36f8408d | 208 | PressureDrv->GetTemperature(pfData); |
julientiron | 1:bdbf36f8408d | 209 | } |
julientiron | 1:bdbf36f8408d | 210 | } |
julientiron | 1:bdbf36f8408d | 211 | |
julientiron | 1:bdbf36f8408d | 212 | /** |
julientiron | 1:bdbf36f8408d | 213 | * @} |
julientiron | 1:bdbf36f8408d | 214 | */ |
julientiron | 1:bdbf36f8408d | 215 | |
julientiron | 1:bdbf36f8408d | 216 | /** |
julientiron | 1:bdbf36f8408d | 217 | * @} |
julientiron | 1:bdbf36f8408d | 218 | */ |
julientiron | 1:bdbf36f8408d | 219 | |
julientiron | 1:bdbf36f8408d | 220 | /** |
julientiron | 1:bdbf36f8408d | 221 | * @} |
julientiron | 1:bdbf36f8408d | 222 | */ |
julientiron | 1:bdbf36f8408d | 223 | |
julientiron | 1:bdbf36f8408d | 224 | /** |
julientiron | 1:bdbf36f8408d | 225 | * @} |
julientiron | 1:bdbf36f8408d | 226 | */ |
julientiron | 1:bdbf36f8408d | 227 | |
julientiron | 1:bdbf36f8408d | 228 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
julientiron | 1:bdbf36f8408d | 229 |