LPS22HH single file class Library for I2C
LPS22HH
#include "LPS22HH.h" LPS22HH BAROMETER(I2C_SDA,I2C_SCL); void main() { BAROMETER.begin(); BAROMETER.Enable(); while(1) { printf("%f hPa \r\n,BAROMETER.GetPressure()); } }
LPS22HH.h@0:b74c7741e608, 2021-04-14 (annotated)
- Committer:
- gpmbed
- Date:
- Wed Apr 14 16:15:25 2021 +0000
- Revision:
- 0:b74c7741e608
Single file LPS22HH class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gpmbed | 0:b74c7741e608 | 1 | #ifndef __LPS22HH_H__ |
gpmbed | 0:b74c7741e608 | 2 | #define __LPS22HH_H__ |
gpmbed | 0:b74c7741e608 | 3 | |
gpmbed | 0:b74c7741e608 | 4 | |
gpmbed | 0:b74c7741e608 | 5 | /* Includes ------------------------------------------------------------------*/ |
gpmbed | 0:b74c7741e608 | 6 | |
gpmbed | 0:b74c7741e608 | 7 | #include "mbed.h" |
gpmbed | 0:b74c7741e608 | 8 | /* Defines -------------------------------------------------------------------*/ |
gpmbed | 0:b74c7741e608 | 9 | /** I2C Device Address 8 bit format if SA0=0 -> B9 if SA0=1 -> BB **/ |
gpmbed | 0:b74c7741e608 | 10 | #define LPS22HH_I2C_ADD_H 0xBBU |
gpmbed | 0:b74c7741e608 | 11 | #define LPS22HH_I2C_ADD_L 0xB9U |
gpmbed | 0:b74c7741e608 | 12 | |
gpmbed | 0:b74c7741e608 | 13 | /** Device Identification (Who am I) **/ |
gpmbed | 0:b74c7741e608 | 14 | #define LPS22HH_ID 0xB3U |
gpmbed | 0:b74c7741e608 | 15 | |
gpmbed | 0:b74c7741e608 | 16 | /** |
gpmbed | 0:b74c7741e608 | 17 | * @} |
gpmbed | 0:b74c7741e608 | 18 | * |
gpmbed | 0:b74c7741e608 | 19 | */ |
gpmbed | 0:b74c7741e608 | 20 | |
gpmbed | 0:b74c7741e608 | 21 | /** |
gpmbed | 0:b74c7741e608 | 22 | * @addtogroup LPS22HH_Sensitivity |
gpmbed | 0:b74c7741e608 | 23 | * @brief These macro are maintained for back compatibility. |
gpmbed | 0:b74c7741e608 | 24 | * in order to convert data into engineering units please |
gpmbed | 0:b74c7741e608 | 25 | * use functions: |
gpmbed | 0:b74c7741e608 | 26 | * -> _from_lsb_to_hpa(int16_t lsb) |
gpmbed | 0:b74c7741e608 | 27 | * -> _from_lsb_to_celsius(int16_t lsb); |
gpmbed | 0:b74c7741e608 | 28 | * |
gpmbed | 0:b74c7741e608 | 29 | * REMOVING the MACRO you are compliant with: |
gpmbed | 0:b74c7741e608 | 30 | * MISRA-C 2012 [Dir 4.9] -> " avoid function-like macros " |
gpmbed | 0:b74c7741e608 | 31 | * @{ |
gpmbed | 0:b74c7741e608 | 32 | * |
gpmbed | 0:b74c7741e608 | 33 | */ |
gpmbed | 0:b74c7741e608 | 34 | |
gpmbed | 0:b74c7741e608 | 35 | #define LPS22HH_FROM_LSB_TO_hPa(lsb) (float)( lsb / 4096.0f ) |
gpmbed | 0:b74c7741e608 | 36 | #define LPS22HH_FROM_LSB_TO_degC(lsb) (float)( lsb / 100.0f ) |
gpmbed | 0:b74c7741e608 | 37 | |
gpmbed | 0:b74c7741e608 | 38 | #define LPS22HH_WHO_AM_I 0x0FU |
gpmbed | 0:b74c7741e608 | 39 | |
gpmbed | 0:b74c7741e608 | 40 | #define PROPERTY_DISABLE (0U) |
gpmbed | 0:b74c7741e608 | 41 | #define PROPERTY_ENABLE (1U) |
gpmbed | 0:b74c7741e608 | 42 | |
gpmbed | 0:b74c7741e608 | 43 | |
gpmbed | 0:b74c7741e608 | 44 | /* Typedefs ------------------------------------------------------------------*/ |
gpmbed | 0:b74c7741e608 | 45 | |
gpmbed | 0:b74c7741e608 | 46 | typedef enum |
gpmbed | 0:b74c7741e608 | 47 | { |
gpmbed | 0:b74c7741e608 | 48 | LPS22HH_OK = 0, |
gpmbed | 0:b74c7741e608 | 49 | LPS22HH_ERROR =-1 |
gpmbed | 0:b74c7741e608 | 50 | } LPS22HHStatusTypeDef; |
gpmbed | 0:b74c7741e608 | 51 | |
gpmbed | 0:b74c7741e608 | 52 | typedef enum { |
gpmbed | 0:b74c7741e608 | 53 | LPS22HH_POWER_DOWN = 0x00, |
gpmbed | 0:b74c7741e608 | 54 | LPS22HH_ONE_SHOOT = 0x08, |
gpmbed | 0:b74c7741e608 | 55 | LPS22HH_1_Hz = 0x01, |
gpmbed | 0:b74c7741e608 | 56 | LPS22HH_10_Hz = 0x02, |
gpmbed | 0:b74c7741e608 | 57 | LPS22HH_25_Hz = 0x03, |
gpmbed | 0:b74c7741e608 | 58 | LPS22HH_50_Hz = 0x04, |
gpmbed | 0:b74c7741e608 | 59 | LPS22HH_75_Hz = 0x05, |
gpmbed | 0:b74c7741e608 | 60 | LPS22HH_1_Hz_LOW_NOISE = 0x11, |
gpmbed | 0:b74c7741e608 | 61 | LPS22HH_10_Hz_LOW_NOISE = 0x12, |
gpmbed | 0:b74c7741e608 | 62 | LPS22HH_25_Hz_LOW_NOISE = 0x13, |
gpmbed | 0:b74c7741e608 | 63 | LPS22HH_50_Hz_LOW_NOISE = 0x14, |
gpmbed | 0:b74c7741e608 | 64 | LPS22HH_75_Hz_LOW_NOISE = 0x15, |
gpmbed | 0:b74c7741e608 | 65 | LPS22HH_100_Hz = 0x06, |
gpmbed | 0:b74c7741e608 | 66 | LPS22HH_200_Hz = 0x07, |
gpmbed | 0:b74c7741e608 | 67 | } lps22hh_odr_t; |
gpmbed | 0:b74c7741e608 | 68 | |
gpmbed | 0:b74c7741e608 | 69 | typedef int32_t (*lps22hh_write_ptr)(void *, uint8_t, uint8_t*, uint16_t); |
gpmbed | 0:b74c7741e608 | 70 | typedef int32_t (*lps22hh_read_ptr) (void *, uint8_t, uint8_t*, uint16_t); |
gpmbed | 0:b74c7741e608 | 71 | |
gpmbed | 0:b74c7741e608 | 72 | typedef struct { |
gpmbed | 0:b74c7741e608 | 73 | /** Component mandatory fields **/ |
gpmbed | 0:b74c7741e608 | 74 | lps22hh_write_ptr write_reg; |
gpmbed | 0:b74c7741e608 | 75 | lps22hh_read_ptr read_reg; |
gpmbed | 0:b74c7741e608 | 76 | /** Customizable optional pointer **/ |
gpmbed | 0:b74c7741e608 | 77 | void *handle; |
gpmbed | 0:b74c7741e608 | 78 | } lps22hh_ctx_t; |
gpmbed | 0:b74c7741e608 | 79 | |
gpmbed | 0:b74c7741e608 | 80 | typedef enum { |
gpmbed | 0:b74c7741e608 | 81 | LPS22HH_LPF_ODR_DIV_2 = 0, |
gpmbed | 0:b74c7741e608 | 82 | LPS22HH_LPF_ODR_DIV_9 = 2, |
gpmbed | 0:b74c7741e608 | 83 | LPS22HH_LPF_ODR_DIV_20 = 3, |
gpmbed | 0:b74c7741e608 | 84 | } lps22hh_lpfp_cfg_t; |
gpmbed | 0:b74c7741e608 | 85 | |
gpmbed | 0:b74c7741e608 | 86 | typedef union{ |
gpmbed | 0:b74c7741e608 | 87 | int16_t i16bit[3]; |
gpmbed | 0:b74c7741e608 | 88 | uint8_t u8bit[6]; |
gpmbed | 0:b74c7741e608 | 89 | } axis3bit16_t; |
gpmbed | 0:b74c7741e608 | 90 | |
gpmbed | 0:b74c7741e608 | 91 | typedef union{ |
gpmbed | 0:b74c7741e608 | 92 | int16_t i16bit; |
gpmbed | 0:b74c7741e608 | 93 | uint8_t u8bit[2]; |
gpmbed | 0:b74c7741e608 | 94 | } axis1bit16_t; |
gpmbed | 0:b74c7741e608 | 95 | |
gpmbed | 0:b74c7741e608 | 96 | typedef union{ |
gpmbed | 0:b74c7741e608 | 97 | int32_t i32bit[3]; |
gpmbed | 0:b74c7741e608 | 98 | uint8_t u8bit[12]; |
gpmbed | 0:b74c7741e608 | 99 | } axis3bit32_t; |
gpmbed | 0:b74c7741e608 | 100 | |
gpmbed | 0:b74c7741e608 | 101 | typedef union{ |
gpmbed | 0:b74c7741e608 | 102 | int32_t i32bit; |
gpmbed | 0:b74c7741e608 | 103 | uint8_t u8bit[4]; |
gpmbed | 0:b74c7741e608 | 104 | } axis1bit32_t; |
gpmbed | 0:b74c7741e608 | 105 | |
gpmbed | 0:b74c7741e608 | 106 | /** |
gpmbed | 0:b74c7741e608 | 107 | * @} |
gpmbed | 0:b74c7741e608 | 108 | * |
gpmbed | 0:b74c7741e608 | 109 | */ |
gpmbed | 0:b74c7741e608 | 110 | |
gpmbed | 0:b74c7741e608 | 111 | typedef struct{ |
gpmbed | 0:b74c7741e608 | 112 | uint8_t bit0 : 1; |
gpmbed | 0:b74c7741e608 | 113 | uint8_t bit1 : 1; |
gpmbed | 0:b74c7741e608 | 114 | uint8_t bit2 : 1; |
gpmbed | 0:b74c7741e608 | 115 | uint8_t bit3 : 1; |
gpmbed | 0:b74c7741e608 | 116 | uint8_t bit4 : 1; |
gpmbed | 0:b74c7741e608 | 117 | uint8_t bit5 : 1; |
gpmbed | 0:b74c7741e608 | 118 | uint8_t bit6 : 1; |
gpmbed | 0:b74c7741e608 | 119 | uint8_t bit7 : 1; |
gpmbed | 0:b74c7741e608 | 120 | } bitwise_t; |
gpmbed | 0:b74c7741e608 | 121 | |
gpmbed | 0:b74c7741e608 | 122 | #define PROPERTY_DISABLE (0U) |
gpmbed | 0:b74c7741e608 | 123 | #define PROPERTY_ENABLE (1U) |
gpmbed | 0:b74c7741e608 | 124 | |
gpmbed | 0:b74c7741e608 | 125 | |
gpmbed | 0:b74c7741e608 | 126 | |
gpmbed | 0:b74c7741e608 | 127 | /** |
gpmbed | 0:b74c7741e608 | 128 | * @} |
gpmbed | 0:b74c7741e608 | 129 | * |
gpmbed | 0:b74c7741e608 | 130 | */ |
gpmbed | 0:b74c7741e608 | 131 | |
gpmbed | 0:b74c7741e608 | 132 | /** @addtogroup LPS22HH_Interfaces_Functions |
gpmbed | 0:b74c7741e608 | 133 | * @brief This section provide a set of functions used to read and |
gpmbed | 0:b74c7741e608 | 134 | * write a generic register of the device. |
gpmbed | 0:b74c7741e608 | 135 | * MANDATORY: return 0 -> no Error. |
gpmbed | 0:b74c7741e608 | 136 | * @{ |
gpmbed | 0:b74c7741e608 | 137 | * |
gpmbed | 0:b74c7741e608 | 138 | */ |
gpmbed | 0:b74c7741e608 | 139 | |
gpmbed | 0:b74c7741e608 | 140 | typedef int32_t (*lps22hh_write_ptr)(void *, uint8_t, uint8_t*, uint16_t); |
gpmbed | 0:b74c7741e608 | 141 | typedef int32_t (*lps22hh_read_ptr) (void *, uint8_t, uint8_t*, uint16_t); |
gpmbed | 0:b74c7741e608 | 142 | |
gpmbed | 0:b74c7741e608 | 143 | |
gpmbed | 0:b74c7741e608 | 144 | /** |
gpmbed | 0:b74c7741e608 | 145 | * @} |
gpmbed | 0:b74c7741e608 | 146 | * |
gpmbed | 0:b74c7741e608 | 147 | */ |
gpmbed | 0:b74c7741e608 | 148 | |
gpmbed | 0:b74c7741e608 | 149 | /** @defgroup LPS22HH_Infos |
gpmbed | 0:b74c7741e608 | 150 | * @{ |
gpmbed | 0:b74c7741e608 | 151 | * |
gpmbed | 0:b74c7741e608 | 152 | */ |
gpmbed | 0:b74c7741e608 | 153 | |
gpmbed | 0:b74c7741e608 | 154 | /** I2C Device Address 8 bit format if SA0=0 -> B9 if SA0=1 -> BB **/ |
gpmbed | 0:b74c7741e608 | 155 | #define LPS22HH_I2C_ADD_H 0xBBU |
gpmbed | 0:b74c7741e608 | 156 | #define LPS22HH_I2C_ADD_L 0xB9U |
gpmbed | 0:b74c7741e608 | 157 | |
gpmbed | 0:b74c7741e608 | 158 | /** Device Identification (Who am I) **/ |
gpmbed | 0:b74c7741e608 | 159 | #define LPS22HH_ID 0xB3U |
gpmbed | 0:b74c7741e608 | 160 | |
gpmbed | 0:b74c7741e608 | 161 | /** |
gpmbed | 0:b74c7741e608 | 162 | * @} |
gpmbed | 0:b74c7741e608 | 163 | * |
gpmbed | 0:b74c7741e608 | 164 | */ |
gpmbed | 0:b74c7741e608 | 165 | |
gpmbed | 0:b74c7741e608 | 166 | /** |
gpmbed | 0:b74c7741e608 | 167 | * @addtogroup LPS22HH_Sensitivity |
gpmbed | 0:b74c7741e608 | 168 | * @brief These macro are maintained for back compatibility. |
gpmbed | 0:b74c7741e608 | 169 | * in order to convert data into engineering units please |
gpmbed | 0:b74c7741e608 | 170 | * use functions: |
gpmbed | 0:b74c7741e608 | 171 | * -> _from_lsb_to_hpa(int16_t lsb) |
gpmbed | 0:b74c7741e608 | 172 | * -> _from_lsb_to_celsius(int16_t lsb); |
gpmbed | 0:b74c7741e608 | 173 | * |
gpmbed | 0:b74c7741e608 | 174 | * REMOVING the MACRO you are compliant with: |
gpmbed | 0:b74c7741e608 | 175 | * MISRA-C 2012 [Dir 4.9] -> " avoid function-like macros " |
gpmbed | 0:b74c7741e608 | 176 | * @{ |
gpmbed | 0:b74c7741e608 | 177 | * |
gpmbed | 0:b74c7741e608 | 178 | */ |
gpmbed | 0:b74c7741e608 | 179 | |
gpmbed | 0:b74c7741e608 | 180 | #define LPS22HH_FROM_LSB_TO_hPa(lsb) (float)( lsb / 4096.0f ) |
gpmbed | 0:b74c7741e608 | 181 | #define LPS22HH_FROM_LSB_TO_degC(lsb) (float)( lsb / 100.0f ) |
gpmbed | 0:b74c7741e608 | 182 | |
gpmbed | 0:b74c7741e608 | 183 | /** |
gpmbed | 0:b74c7741e608 | 184 | * @} |
gpmbed | 0:b74c7741e608 | 185 | * |
gpmbed | 0:b74c7741e608 | 186 | */ |
gpmbed | 0:b74c7741e608 | 187 | |
gpmbed | 0:b74c7741e608 | 188 | #define LPS22HH_INTERRUPT_CFG 0x0BU |
gpmbed | 0:b74c7741e608 | 189 | typedef struct { |
gpmbed | 0:b74c7741e608 | 190 | uint8_t pe : 2; /* ple + phe */ |
gpmbed | 0:b74c7741e608 | 191 | uint8_t lir : 1; |
gpmbed | 0:b74c7741e608 | 192 | uint8_t diff_en : 1; |
gpmbed | 0:b74c7741e608 | 193 | uint8_t reset_az : 1; |
gpmbed | 0:b74c7741e608 | 194 | uint8_t autozero : 1; |
gpmbed | 0:b74c7741e608 | 195 | uint8_t reset_arp : 1; |
gpmbed | 0:b74c7741e608 | 196 | uint8_t autorefp : 1; |
gpmbed | 0:b74c7741e608 | 197 | } lps22hh_interrupt_cfg_t; |
gpmbed | 0:b74c7741e608 | 198 | |
gpmbed | 0:b74c7741e608 | 199 | #define LPS22HH_THS_P_L 0x0CU |
gpmbed | 0:b74c7741e608 | 200 | typedef struct { |
gpmbed | 0:b74c7741e608 | 201 | uint8_t ths : 8; |
gpmbed | 0:b74c7741e608 | 202 | } lps22hh_ths_p_l_t; |
gpmbed | 0:b74c7741e608 | 203 | |
gpmbed | 0:b74c7741e608 | 204 | #define LPS22HH_THS_P_H 0x0DU |
gpmbed | 0:b74c7741e608 | 205 | typedef struct { |
gpmbed | 0:b74c7741e608 | 206 | uint8_t ths : 7; |
gpmbed | 0:b74c7741e608 | 207 | uint8_t not_used_01 : 1; |
gpmbed | 0:b74c7741e608 | 208 | } lps22hh_ths_p_h_t; |
gpmbed | 0:b74c7741e608 | 209 | |
gpmbed | 0:b74c7741e608 | 210 | #define LPS22HH_IF_CTRL 0x0EU |
gpmbed | 0:b74c7741e608 | 211 | typedef struct { |
gpmbed | 0:b74c7741e608 | 212 | uint8_t i2c_disable : 1; |
gpmbed | 0:b74c7741e608 | 213 | uint8_t i3c_disable : 1; |
gpmbed | 0:b74c7741e608 | 214 | uint8_t pd_dis_int1 : 1; |
gpmbed | 0:b74c7741e608 | 215 | uint8_t sdo_pu_en : 1; |
gpmbed | 0:b74c7741e608 | 216 | uint8_t sda_pu_en : 1; |
gpmbed | 0:b74c7741e608 | 217 | uint8_t not_used_01 : 2; |
gpmbed | 0:b74c7741e608 | 218 | uint8_t int_en_i3c : 1; |
gpmbed | 0:b74c7741e608 | 219 | } lps22hh_if_ctrl_t; |
gpmbed | 0:b74c7741e608 | 220 | |
gpmbed | 0:b74c7741e608 | 221 | #define LPS22HH_WHO_AM_I 0x0FU |
gpmbed | 0:b74c7741e608 | 222 | #define LPS22HH_CTRL_REG1 0x10U |
gpmbed | 0:b74c7741e608 | 223 | typedef struct { |
gpmbed | 0:b74c7741e608 | 224 | uint8_t sim : 1; |
gpmbed | 0:b74c7741e608 | 225 | uint8_t bdu : 1; |
gpmbed | 0:b74c7741e608 | 226 | uint8_t lpfp_cfg : 2; /* en_lpfp + lpfp_cfg */ |
gpmbed | 0:b74c7741e608 | 227 | uint8_t odr : 3; |
gpmbed | 0:b74c7741e608 | 228 | uint8_t not_used_01 : 1; |
gpmbed | 0:b74c7741e608 | 229 | } lps22hh_ctrl_reg1_t; |
gpmbed | 0:b74c7741e608 | 230 | |
gpmbed | 0:b74c7741e608 | 231 | #define LPS22HH_CTRL_REG2 0x11U |
gpmbed | 0:b74c7741e608 | 232 | typedef struct { |
gpmbed | 0:b74c7741e608 | 233 | uint8_t one_shot : 1; |
gpmbed | 0:b74c7741e608 | 234 | uint8_t low_noise_en : 1; |
gpmbed | 0:b74c7741e608 | 235 | uint8_t swreset : 1; |
gpmbed | 0:b74c7741e608 | 236 | uint8_t not_used_01 : 1; |
gpmbed | 0:b74c7741e608 | 237 | uint8_t if_add_inc : 1; |
gpmbed | 0:b74c7741e608 | 238 | uint8_t pp_od : 1; |
gpmbed | 0:b74c7741e608 | 239 | uint8_t int_h_l : 1; |
gpmbed | 0:b74c7741e608 | 240 | uint8_t boot : 1; |
gpmbed | 0:b74c7741e608 | 241 | } lps22hh_ctrl_reg2_t; |
gpmbed | 0:b74c7741e608 | 242 | |
gpmbed | 0:b74c7741e608 | 243 | #define LPS22HH_CTRL_REG3 0x12U |
gpmbed | 0:b74c7741e608 | 244 | typedef struct { |
gpmbed | 0:b74c7741e608 | 245 | uint8_t int_s : 2; |
gpmbed | 0:b74c7741e608 | 246 | uint8_t drdy : 1; |
gpmbed | 0:b74c7741e608 | 247 | uint8_t int_f_ovr : 1; |
gpmbed | 0:b74c7741e608 | 248 | uint8_t int_f_wtm : 1; |
gpmbed | 0:b74c7741e608 | 249 | uint8_t int_f_full : 1; |
gpmbed | 0:b74c7741e608 | 250 | uint8_t not_used_01 : 2; |
gpmbed | 0:b74c7741e608 | 251 | } lps22hh_ctrl_reg3_t; |
gpmbed | 0:b74c7741e608 | 252 | |
gpmbed | 0:b74c7741e608 | 253 | #define LPS22HH_FIFO_CTRL 0x13U |
gpmbed | 0:b74c7741e608 | 254 | typedef struct { |
gpmbed | 0:b74c7741e608 | 255 | uint8_t f_mode : 3; /* f_mode + trig_modes */ |
gpmbed | 0:b74c7741e608 | 256 | uint8_t stop_on_wtm : 1; |
gpmbed | 0:b74c7741e608 | 257 | uint8_t not_used_01 : 4; |
gpmbed | 0:b74c7741e608 | 258 | } lps22hh_fifo_ctrl_t; |
gpmbed | 0:b74c7741e608 | 259 | |
gpmbed | 0:b74c7741e608 | 260 | #define LPS22HH_FIFO_WTM 0x14U |
gpmbed | 0:b74c7741e608 | 261 | typedef struct { |
gpmbed | 0:b74c7741e608 | 262 | uint8_t wtm : 7; |
gpmbed | 0:b74c7741e608 | 263 | uint8_t not_used_01 : 1; |
gpmbed | 0:b74c7741e608 | 264 | } lps22hh_fifo_wtm_t; |
gpmbed | 0:b74c7741e608 | 265 | |
gpmbed | 0:b74c7741e608 | 266 | #define LPS22HH_REF_P_XL 0x15U |
gpmbed | 0:b74c7741e608 | 267 | #define LPS22HH_REF_P_L 0x16U |
gpmbed | 0:b74c7741e608 | 268 | #define LPS22HH_RPDS_L 0x18U |
gpmbed | 0:b74c7741e608 | 269 | #define LPS22HH_RPDS_H 0x19U |
gpmbed | 0:b74c7741e608 | 270 | #define LPS22HH_INT_SOURCE 0x24U |
gpmbed | 0:b74c7741e608 | 271 | typedef struct { |
gpmbed | 0:b74c7741e608 | 272 | uint8_t ph : 1; |
gpmbed | 0:b74c7741e608 | 273 | uint8_t pl : 1; |
gpmbed | 0:b74c7741e608 | 274 | uint8_t ia : 1; |
gpmbed | 0:b74c7741e608 | 275 | uint8_t not_used_01 : 5; |
gpmbed | 0:b74c7741e608 | 276 | } lps22hh_int_source_t; |
gpmbed | 0:b74c7741e608 | 277 | |
gpmbed | 0:b74c7741e608 | 278 | #define LPS22HH_FIFO_STATUS1 0x25U |
gpmbed | 0:b74c7741e608 | 279 | #define LPS22HH_FIFO_STATUS2 0x26U |
gpmbed | 0:b74c7741e608 | 280 | typedef struct { |
gpmbed | 0:b74c7741e608 | 281 | uint8_t not_used_01 : 5; |
gpmbed | 0:b74c7741e608 | 282 | uint8_t fifo_full_ia : 1; |
gpmbed | 0:b74c7741e608 | 283 | uint8_t fifo_ovr_ia : 1; |
gpmbed | 0:b74c7741e608 | 284 | uint8_t fifo_wtm_ia : 1; |
gpmbed | 0:b74c7741e608 | 285 | } lps22hh_fifo_status2_t; |
gpmbed | 0:b74c7741e608 | 286 | |
gpmbed | 0:b74c7741e608 | 287 | #define LPS22HH_STATUS 0x27U |
gpmbed | 0:b74c7741e608 | 288 | typedef struct { |
gpmbed | 0:b74c7741e608 | 289 | uint8_t p_da : 1; |
gpmbed | 0:b74c7741e608 | 290 | uint8_t t_da : 1; |
gpmbed | 0:b74c7741e608 | 291 | uint8_t not_used_01 : 2; |
gpmbed | 0:b74c7741e608 | 292 | uint8_t p_or : 1; |
gpmbed | 0:b74c7741e608 | 293 | uint8_t t_or : 1; |
gpmbed | 0:b74c7741e608 | 294 | uint8_t not_used_02 : 2; |
gpmbed | 0:b74c7741e608 | 295 | } lps22hh_status_t; |
gpmbed | 0:b74c7741e608 | 296 | |
gpmbed | 0:b74c7741e608 | 297 | #define LPS22HH_PRESSURE_OUT_XL 0x28U |
gpmbed | 0:b74c7741e608 | 298 | #define LPS22HH_PRESSURE_OUT_L 0x29U |
gpmbed | 0:b74c7741e608 | 299 | #define LPS22HH_PRESSURE_OUT_H 0x2AU |
gpmbed | 0:b74c7741e608 | 300 | #define LPS22HH_TEMP_OUT_L 0x2BU |
gpmbed | 0:b74c7741e608 | 301 | #define LPS22HH_TEMP_OUT_H 0x2CU |
gpmbed | 0:b74c7741e608 | 302 | #define LPS22HH_FIFO_DATA_OUT_PRESS_XL 0x78U |
gpmbed | 0:b74c7741e608 | 303 | #define LPS22HH_FIFO_DATA_OUT_PRESS_L 0x79U |
gpmbed | 0:b74c7741e608 | 304 | #define LPS22HH_FIFO_DATA_OUT_PRESS_H 0x7AU |
gpmbed | 0:b74c7741e608 | 305 | #define LPS22HH_FIFO_DATA_OUT_TEMP_L 0x7BU |
gpmbed | 0:b74c7741e608 | 306 | #define LPS22HH_FIFO_DATA_OUT_TEMP_H 0x7CU |
gpmbed | 0:b74c7741e608 | 307 | |
gpmbed | 0:b74c7741e608 | 308 | /** |
gpmbed | 0:b74c7741e608 | 309 | * @defgroup LPS22HH_Register_Union |
gpmbed | 0:b74c7741e608 | 310 | * @brief This union group all the registers that has a bitfield |
gpmbed | 0:b74c7741e608 | 311 | * description. |
gpmbed | 0:b74c7741e608 | 312 | * This union is useful but not need by the driver. |
gpmbed | 0:b74c7741e608 | 313 | * |
gpmbed | 0:b74c7741e608 | 314 | * REMOVING this union you are compliant with: |
gpmbed | 0:b74c7741e608 | 315 | * MISRA-C 2012 [Rule 19.2] -> " Union are not allowed " |
gpmbed | 0:b74c7741e608 | 316 | * |
gpmbed | 0:b74c7741e608 | 317 | * @{ |
gpmbed | 0:b74c7741e608 | 318 | * |
gpmbed | 0:b74c7741e608 | 319 | */ |
gpmbed | 0:b74c7741e608 | 320 | typedef union{ |
gpmbed | 0:b74c7741e608 | 321 | lps22hh_interrupt_cfg_t interrupt_cfg; |
gpmbed | 0:b74c7741e608 | 322 | lps22hh_if_ctrl_t if_ctrl; |
gpmbed | 0:b74c7741e608 | 323 | lps22hh_ctrl_reg1_t ctrl_reg1; |
gpmbed | 0:b74c7741e608 | 324 | lps22hh_ctrl_reg2_t ctrl_reg2; |
gpmbed | 0:b74c7741e608 | 325 | lps22hh_ctrl_reg3_t ctrl_reg3; |
gpmbed | 0:b74c7741e608 | 326 | lps22hh_fifo_ctrl_t fifo_ctrl; |
gpmbed | 0:b74c7741e608 | 327 | lps22hh_fifo_wtm_t fifo_wtm; |
gpmbed | 0:b74c7741e608 | 328 | lps22hh_int_source_t int_source; |
gpmbed | 0:b74c7741e608 | 329 | lps22hh_fifo_status2_t fifo_status2; |
gpmbed | 0:b74c7741e608 | 330 | lps22hh_status_t status; |
gpmbed | 0:b74c7741e608 | 331 | bitwise_t bitwise; |
gpmbed | 0:b74c7741e608 | 332 | uint8_t byte; |
gpmbed | 0:b74c7741e608 | 333 | } lps22hh_reg_t; |
gpmbed | 0:b74c7741e608 | 334 | |
gpmbed | 0:b74c7741e608 | 335 | typedef enum { |
gpmbed | 0:b74c7741e608 | 336 | LPS22HH_BYPASS_MODE = 0, |
gpmbed | 0:b74c7741e608 | 337 | LPS22HH_FIFO_MODE = 1, |
gpmbed | 0:b74c7741e608 | 338 | LPS22HH_STREAM_MODE = 2, |
gpmbed | 0:b74c7741e608 | 339 | LPS22HH_DYNAMIC_STREAM_MODE = 3, |
gpmbed | 0:b74c7741e608 | 340 | LPS22HH_BYPASS_TO_FIFO_MODE = 5, |
gpmbed | 0:b74c7741e608 | 341 | LPS22HH_BYPASS_TO_STREAM_MODE = 6, |
gpmbed | 0:b74c7741e608 | 342 | LPS22HH_STREAM_TO_FIFO_MODE = 7, |
gpmbed | 0:b74c7741e608 | 343 | } lps22hh_f_mode_t; |
gpmbed | 0:b74c7741e608 | 344 | |
gpmbed | 0:b74c7741e608 | 345 | /** |
gpmbed | 0:b74c7741e608 | 346 | * @} |
gpmbed | 0:b74c7741e608 | 347 | * |
gpmbed | 0:b74c7741e608 | 348 | */ |
gpmbed | 0:b74c7741e608 | 349 | |
gpmbed | 0:b74c7741e608 | 350 | |
gpmbed | 0:b74c7741e608 | 351 | /* Class Declaration ---------------------------------------------------------*/ |
gpmbed | 0:b74c7741e608 | 352 | |
gpmbed | 0:b74c7741e608 | 353 | /** |
gpmbed | 0:b74c7741e608 | 354 | * Abstract class of a LPS22HH pressure sensor. |
gpmbed | 0:b74c7741e608 | 355 | */ |
gpmbed | 0:b74c7741e608 | 356 | class LPS22HH |
gpmbed | 0:b74c7741e608 | 357 | { |
gpmbed | 0:b74c7741e608 | 358 | public: |
gpmbed | 0:b74c7741e608 | 359 | LPS22HH(PinName sda, PinName scl); |
gpmbed | 0:b74c7741e608 | 360 | |
gpmbed | 0:b74c7741e608 | 361 | LPS22HHStatusTypeDef begin(); |
gpmbed | 0:b74c7741e608 | 362 | LPS22HHStatusTypeDef end(); |
gpmbed | 0:b74c7741e608 | 363 | LPS22HHStatusTypeDef ReadID(uint8_t *Id); |
gpmbed | 0:b74c7741e608 | 364 | LPS22HHStatusTypeDef Enable(); |
gpmbed | 0:b74c7741e608 | 365 | LPS22HHStatusTypeDef Disable(); |
gpmbed | 0:b74c7741e608 | 366 | LPS22HHStatusTypeDef GetOutputDataRate(float *Odr); |
gpmbed | 0:b74c7741e608 | 367 | LPS22HHStatusTypeDef SetOutputDataRate(float Odr); |
gpmbed | 0:b74c7741e608 | 368 | ////LPS22HHStatusTypeDef GetPressure(float *Value); |
gpmbed | 0:b74c7741e608 | 369 | float GetPressure(); |
gpmbed | 0:b74c7741e608 | 370 | LPS22HHStatusTypeDef Get_PRESS_DRDY_Status(uint8_t *Status); |
gpmbed | 0:b74c7741e608 | 371 | |
gpmbed | 0:b74c7741e608 | 372 | LPS22HHStatusTypeDef GetTemperature(float *Value); |
gpmbed | 0:b74c7741e608 | 373 | LPS22HHStatusTypeDef Get_TEMP_DRDY_Status(uint8_t *Status); |
gpmbed | 0:b74c7741e608 | 374 | |
gpmbed | 0:b74c7741e608 | 375 | LPS22HHStatusTypeDef Read_Reg(uint8_t reg, uint8_t *Data); |
gpmbed | 0:b74c7741e608 | 376 | LPS22HHStatusTypeDef Write_Reg(uint8_t reg, uint8_t Data); |
gpmbed | 0:b74c7741e608 | 377 | |
gpmbed | 0:b74c7741e608 | 378 | LPS22HHStatusTypeDef Get_FIFO_Data(float *Press, float *Temp); |
gpmbed | 0:b74c7741e608 | 379 | LPS22HHStatusTypeDef Get_FIFO_FTh_Status(uint8_t *Status); |
gpmbed | 0:b74c7741e608 | 380 | LPS22HHStatusTypeDef Get_FIFO_Full_Status(uint8_t *Status); |
gpmbed | 0:b74c7741e608 | 381 | LPS22HHStatusTypeDef Get_FIFO_Ovr_Status(uint8_t *Status); |
gpmbed | 0:b74c7741e608 | 382 | LPS22HHStatusTypeDef Get_FIFO_Level(uint8_t *Status); |
gpmbed | 0:b74c7741e608 | 383 | LPS22HHStatusTypeDef Reset_FIFO_Interrupt(uint8_t interrupt); |
gpmbed | 0:b74c7741e608 | 384 | LPS22HHStatusTypeDef Set_FIFO_Interrupt(uint8_t interrupt); |
gpmbed | 0:b74c7741e608 | 385 | LPS22HHStatusTypeDef Set_FIFO_Mode(uint8_t Mode); |
gpmbed | 0:b74c7741e608 | 386 | LPS22HHStatusTypeDef Set_FIFO_Watermark_Level(uint8_t Watermark); |
gpmbed | 0:b74c7741e608 | 387 | LPS22HHStatusTypeDef Stop_FIFO_On_Watermark(uint8_t Stop); |
gpmbed | 0:b74c7741e608 | 388 | |
gpmbed | 0:b74c7741e608 | 389 | LPS22HHStatusTypeDef Set_One_Shot(); |
gpmbed | 0:b74c7741e608 | 390 | LPS22HHStatusTypeDef Get_One_Shot_Status(uint8_t *Status); |
gpmbed | 0:b74c7741e608 | 391 | |
gpmbed | 0:b74c7741e608 | 392 | |
gpmbed | 0:b74c7741e608 | 393 | /** |
gpmbed | 0:b74c7741e608 | 394 | * @brief Utility function to read data. |
gpmbed | 0:b74c7741e608 | 395 | * @param pBuffer: pointer to data to be read. |
gpmbed | 0:b74c7741e608 | 396 | * @param RegisterAddr: specifies internal address register to be read. |
gpmbed | 0:b74c7741e608 | 397 | * @param NumByteToRead: number of bytes to be read. |
gpmbed | 0:b74c7741e608 | 398 | * @retval 0 if ok, an error code otherwise. |
gpmbed | 0:b74c7741e608 | 399 | */ |
gpmbed | 0:b74c7741e608 | 400 | uint8_t IO_Read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) |
gpmbed | 0:b74c7741e608 | 401 | { |
gpmbed | 0:b74c7741e608 | 402 | char tempBuff[NumByteToRead]; |
gpmbed | 0:b74c7741e608 | 403 | uint8_t devAddr = (uint8_t)(((address) >> 1) & 0x7F); |
gpmbed | 0:b74c7741e608 | 404 | char regAddr = (char)RegisterAddr; |
gpmbed | 0:b74c7741e608 | 405 | _i2c.write((int)devAddr, ®Addr, 1); |
gpmbed | 0:b74c7741e608 | 406 | //_i2c->beginTransmission(((uint8_t)(((address) >> 1) & 0x7F))); |
gpmbed | 0:b74c7741e608 | 407 | //dev_i2c->write(RegisterAddr); |
gpmbed | 0:b74c7741e608 | 408 | //dev_i2c->endTransmission(false); |
gpmbed | 0:b74c7741e608 | 409 | _i2c.read(devAddr,tempBuff,NumByteToRead); |
gpmbed | 0:b74c7741e608 | 410 | |
gpmbed | 0:b74c7741e608 | 411 | memcpy(pBuffer,tempBuff,NumByteToRead); |
gpmbed | 0:b74c7741e608 | 412 | //dev_i2c->requestFrom(((uint8_t)(((address) >> 1) & 0x7F)), (uint8_t) NumByteToRead); |
gpmbed | 0:b74c7741e608 | 413 | |
gpmbed | 0:b74c7741e608 | 414 | /* |
gpmbed | 0:b74c7741e608 | 415 | int i=0; |
gpmbed | 0:b74c7741e608 | 416 | while (dev_i2c->available()) { |
gpmbed | 0:b74c7741e608 | 417 | pBuffer[i] = dev_i2c->read(); |
gpmbed | 0:b74c7741e608 | 418 | i++; |
gpmbed | 0:b74c7741e608 | 419 | } |
gpmbed | 0:b74c7741e608 | 420 | */ |
gpmbed | 0:b74c7741e608 | 421 | return 0; |
gpmbed | 0:b74c7741e608 | 422 | |
gpmbed | 0:b74c7741e608 | 423 | |
gpmbed | 0:b74c7741e608 | 424 | |
gpmbed | 0:b74c7741e608 | 425 | } |
gpmbed | 0:b74c7741e608 | 426 | |
gpmbed | 0:b74c7741e608 | 427 | /** |
gpmbed | 0:b74c7741e608 | 428 | * @brief Utility function to write data. |
gpmbed | 0:b74c7741e608 | 429 | * @param pBuffer: pointer to data to be written. |
gpmbed | 0:b74c7741e608 | 430 | * @param RegisterAddr: specifies internal address register to be written. |
gpmbed | 0:b74c7741e608 | 431 | * @param NumByteToWrite: number of bytes to write. |
gpmbed | 0:b74c7741e608 | 432 | * @retval 0 if ok, an error code otherwise. |
gpmbed | 0:b74c7741e608 | 433 | */ |
gpmbed | 0:b74c7741e608 | 434 | uint8_t IO_Write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) |
gpmbed | 0:b74c7741e608 | 435 | { |
gpmbed | 0:b74c7741e608 | 436 | uint8_t devAddr = (uint8_t)(((address) >> 1) & 0x7F); |
gpmbed | 0:b74c7741e608 | 437 | char tData[NumByteToWrite+1]; |
gpmbed | 0:b74c7741e608 | 438 | tData[0] = RegisterAddr; |
gpmbed | 0:b74c7741e608 | 439 | memcpy(tData+1,pBuffer,NumByteToWrite); |
gpmbed | 0:b74c7741e608 | 440 | |
gpmbed | 0:b74c7741e608 | 441 | _i2c.write(devAddr,tData,NumByteToWrite+1); |
gpmbed | 0:b74c7741e608 | 442 | |
gpmbed | 0:b74c7741e608 | 443 | return 0; |
gpmbed | 0:b74c7741e608 | 444 | |
gpmbed | 0:b74c7741e608 | 445 | } |
gpmbed | 0:b74c7741e608 | 446 | |
gpmbed | 0:b74c7741e608 | 447 | private: |
gpmbed | 0:b74c7741e608 | 448 | LPS22HHStatusTypeDef SetOutputDataRate_When_Enabled(float Odr); |
gpmbed | 0:b74c7741e608 | 449 | LPS22HHStatusTypeDef SetOutputDataRate_When_Disabled(float Odr); |
gpmbed | 0:b74c7741e608 | 450 | |
gpmbed | 0:b74c7741e608 | 451 | /* Helper classes. */ |
gpmbed | 0:b74c7741e608 | 452 | I2C _i2c; |
gpmbed | 0:b74c7741e608 | 453 | |
gpmbed | 0:b74c7741e608 | 454 | /* Configuration */ |
gpmbed | 0:b74c7741e608 | 455 | uint8_t address; |
gpmbed | 0:b74c7741e608 | 456 | |
gpmbed | 0:b74c7741e608 | 457 | lps22hh_odr_t last_odr; |
gpmbed | 0:b74c7741e608 | 458 | uint8_t enabled; |
gpmbed | 0:b74c7741e608 | 459 | |
gpmbed | 0:b74c7741e608 | 460 | lps22hh_ctx_t reg_ctx; |
gpmbed | 0:b74c7741e608 | 461 | |
gpmbed | 0:b74c7741e608 | 462 | }; |
gpmbed | 0:b74c7741e608 | 463 | |
gpmbed | 0:b74c7741e608 | 464 | #ifdef __cplusplus |
gpmbed | 0:b74c7741e608 | 465 | extern "C" { |
gpmbed | 0:b74c7741e608 | 466 | #endif |
gpmbed | 0:b74c7741e608 | 467 | int32_t LPS22HH_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); |
gpmbed | 0:b74c7741e608 | 468 | int32_t LPS22HH_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); |
gpmbed | 0:b74c7741e608 | 469 | #ifdef __cplusplus |
gpmbed | 0:b74c7741e608 | 470 | } |
gpmbed | 0:b74c7741e608 | 471 | #endif |
gpmbed | 0:b74c7741e608 | 472 | |
gpmbed | 0:b74c7741e608 | 473 | #endif |