lps22hb  2.0.0.0
lps22hb.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef LPS22HB_H
36 #define LPS22HB_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 #include "drv_spi_master.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define LPS22HB_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
56  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
57  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
58  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
59  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
60  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
61  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
62 
68 #define LPS22HB_MASTER_I2C 0
69 #define LPS22HB_MASTER_SPI 1
70 
76 #define LPS22HB_RETVAL uint8_t
77 
78 #define LPS22HB_OK 0x00
79 #define LPS22HB_INIT_ERROR 0xFF
80 
86 #define LPS22HB_DEV_RES_PRES 4096.0
87 #define LPS22HB_DEV_RES_TEMP 100.0
88 
94 #define LPS22HB_I2C_ADDRESS_0 0x5C
95 #define LPS22HB_I2C_ADDRESS_1 0x5D
96 
102 #define LPS22HB_REG_INTERRUPT_CFG 0x0B
103 #define LPS22HB_REG_THS_P_L 0x0C
104 #define LPS22HB_REG_THS_P_H 0x0D
105 #define LPS22HB_REG_WHO_AM_I 0x0F
106 
107 #define LPS22HB_REG_REF_P_XL 0x15
108 #define LPS22HB_REG_REF_P_L 0x16
109 #define LPS22HB_REG_REF_P_H 0x17
110 #define LPS22HB_REG_RPDS_L 0x18
111 #define LPS22HB_REG_RPDS_H 0x19
112 #define LPS22HB_REG_RES_CONF 0x1A
113 #define LPS22HB_REG_INT_SOURCE 0x25
114 #define LPS22HB_REG_FIFO_STATUS 0x26
115 #define LPS22HB_REG_STATUS 0x27
116 #define LPS22HB_REG_PRESS_OUT_XL 0x28
117 #define LPS22HB_REG_PRESS_OUT_L 0x29
118 #define LPS22HB_REG_PRESS_OUT_H 0x2A
119 #define LPS22HB_REG_TEMP_OUT_L 0x2B
120 #define LPS22HB_REG_TEMP_OUT_H 0x2C
121 #define LPS22HB_REG_CLOCK_TREE_CONFIGURATION 0x43
122 
128 #define LPS22HB_RES_CONF_NORMAL_MODE 0x00
129 #define LPS22HB_RES_CONF_LOW_CURRENT_MODE 0x01
130 
136 #define LPS22HB_CTRL_REG_R1 0x10
137 #define LPS22HB_CTRL_REG_R2 0x11
138 #define LPS22HB_CTRL_REG_R3 0x12
139 #define LPS22HB_CTRL_REG_FIFO 0x14
140 
141 #define LPS22HB_CTRL_I2C 0x10
142 #define LPS22HB_CTRL_SPI 0x18
143 
149 #define LPS22HB_MASK_DATA 0x80
150 #define LPS22HB_MASK_DATA_RESET 0x02
151 #define LPS22HB_MASK_DATA_ODR 0x30
152 
153 #define LPS22HB_MASK_REG1_ODR 0x70
154 #define LPS22HB_MASK_REG1_LPFP 0x08
155 #define LPS22HB_MASK_REG1_LPFP_CUTOFF 0x04
156 #define LPS22HB_MASK_REG1_BDU 0x02
157 #define LPS22HB_MASK_REG1_SIM 0x01
158 
159 #define LPS22HB_MASK_REG2_FIFO_EN 0x40
160 #define LPS22HB_MASK_REG2_WTM_EN 0x20
161 #define LPS22HB_MASK_REG2_ADD_INC 0x10
162 #define LPS22HB_MASK_REG2_I2C 0x08
163 #define LPS22HB_MASK_REG2_ONE_SHOT 0x01
164 
165 #define LPS22HB_MASK_REG3_INT_H_L 0x80
166 #define LPS22HB_MASK_REG3_PP_OD 0x40
167 #define LPS22HB_MASK_REG3_FIFO_FULL 0x20
168 #define LPS22HB_MASK_REG3_FIFO_FTH 0x10
169 #define LPS22HB_MASK_REG3_FIFO_OVR 0x08
170 #define LPS22HB_MASK_REG3_DRDY 0x04
171 #define LPS22HB_MASK_REG3_INT_S12 0x03
172 
178 #define LPS22HB_INT_MASK_CFG_AUTORIFP 0x80
179 #define LPS22HB_INT_MASK_CFG_RESET_ARP 0x40
180 #define LPS22HB_INT_MASK_CFG_AUTOZERO 0x20
181 #define LPS22HB_INT_MASK_CFG_RESET_AZ 0x10
182 #define LPS22HB_INT_MASK_CFG_DIFF_EN 0x08
183 #define LPS22HB_INT_MASK_CFG_LIR 0x04
184 #define LPS22HB_INT_MASK_CFG_PLE 0x02
185 #define LPS22HB_INT_MASK_CFG_PHE 0x01
186 
187 #define LPS22HB_INT_MASK_SOURCE_BOOT_STATUS 0x80
188 #define LPS22HB_INT_MASK_SOURCE_IA 0x04
189 #define LPS22HB_INT_MASK_SOURCE_PL 0x02
190 #define LPS22HB_INT_MASK_SOURCE_PH 0x01
191 
192 #define LPS22HB_INT_MASK_SOURCE_TOR 0x20
193 #define LPS22HB_INT_MASK_SOURCE_POR 0x10
194 #define LPS22HB_INT_MASK_SOURCE_TDA 0x02
195 #define LPS22HB_INT_MASK_SOURCE_PDA 0x01
196 
202 #define LPS22HB_FIFO_MASK_CTRL_MODE 0xE0
203 #define LPS22HB_FIFO_MASK_CTRL_WTM_POINT 0x1F
204 
205 #define LPS22HB_FIFO_MASK_STATUS_FTH 0x80
206 #define LPS22HB_FIFO_MASK_STATUS_OVR 0x40
207 #define LPS22HB_FIFO_MASK_STATUS_LEVEL 0x3F
208 #define LPS22HB_FIFO_STATUS_EMPTY 0x00
209 #define LPS22HB_FIFO_STATUS_FULL 0x20
210  // End group macro
213 
214 // --------------------------------------------------------------- PUBLIC TYPES
223 typedef uint8_t lps22hb_select_t;
224 
228 typedef void ( *lps22hb_master_io_t )( struct lps22hb_s*, uint8_t, uint8_t*, uint8_t );
229 
233 typedef struct lps22hb_s
234 {
235  // Output pins
236 
237  digital_out_t cs;
238 
239  // Input pins
240 
241  digital_in_t int_pin;
242 
243  // Modules
244 
245  i2c_master_t i2c;
246  spi_master_t spi;
247 
248  // ctx variable
249 
250  uint8_t slave_address;
251  pin_name_t chip_select;
255 
256 } lps22hb_t;
257 
261 typedef struct
262 {
263  // Communication gpio pins
264 
265  pin_name_t scl;
266  pin_name_t sda;
267  pin_name_t miso;
268  pin_name_t mosi;
269  pin_name_t sck;
270  pin_name_t cs;
271 
272  // Additional gpio pins
273 
274  pin_name_t int_pin;
275 
276  // static variable
277 
278  uint32_t i2c_speed;
279  uint8_t i2c_address;
280 
281  uint32_t spi_speed;
282  spi_master_mode_t spi_mode;
283  spi_master_chip_select_polarity_t cs_polarity;
284 
286 
287 } lps22hb_cfg_t;
288  // End types group
290 
291 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
297 #ifdef __cplusplus
298 extern "C"{
299 #endif
300 
309 void lps22hb_cfg_setup ( lps22hb_cfg_t *cfg );
310 
320 
328 void lps22hb_default_cfg ( lps22hb_t *ctx, lps22hb_cfg_t *cfg );
329 
340 void lps22hb_generic_write ( lps22hb_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
341 
352 void lps22hb_generic_read ( lps22hb_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
353 
362 void lps22hb_soft_reset ( lps22hb_t *ctx );
363 
373 
383 void lps22hb_update_reg ( lps22hb_t *ctx, uint8_t reg_adr, uint8_t reg_val );
384 
399 float lps22hb_get_pressure ( lps22hb_t *ctx );
400 
415 float lps22hb_get_temp ( lps22hb_t *ctx );
416 
426 void lps22hb_set_fifo_mode ( lps22hb_t *ctx, uint8_t mode_sel, uint8_t wm_lvl );
427 
442 uint8_t lps22hb_check_int ( lps22hb_t *ctx );
443 
444 #ifdef __cplusplus
445 }
446 #endif
447 #endif // _LPS22HB_H_
448  // End public_function group
451 
452 // ------------------------------------------------------------------------- END
#define LPS22HB_RETVAL
Definition: lps22hb.h:76
spi_master_chip_select_polarity_t cs_polarity
Definition: lps22hb.h:283
pin_name_t sda
Definition: lps22hb.h:266
lps22hb_select_t sel
Definition: lps22hb.h:285
Click configuration structure definition.
Definition: lps22hb.h:261
void lps22hb_default_cfg(lps22hb_t *ctx, lps22hb_cfg_t *cfg)
Click Default Configuration function.
void lps22hb_cfg_setup(lps22hb_cfg_t *cfg)
Config Object Initialization function.
void lps22hb_generic_read(lps22hb_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void lps22hb_update_reg(lps22hb_t *ctx, uint8_t reg_adr, uint8_t reg_val)
Update register function.
uint8_t lps22hb_check_int(lps22hb_t *ctx)
Check Interrupt state function.
void lps22hb_set_fifo_mode(lps22hb_t *ctx, uint8_t mode_sel, uint8_t wm_lvl)
Set FIFO control mode function.
spi_master_t spi
Definition: lps22hb.h:246
uint8_t i2c_address
Definition: lps22hb.h:279
void lps22hb_start_configuration(lps22hb_t *ctx)
Set start configuration function.
void lps22hb_soft_reset(lps22hb_t *ctx)
Soft reset function.
spi_master_mode_t spi_mode
Definition: lps22hb.h:282
i2c_master_t i2c
Definition: lps22hb.h:245
digital_in_t int_pin
Definition: lps22hb.h:241
float lps22hb_get_pressure(lps22hb_t *ctx)
Get pressure value function.
pin_name_t miso
Definition: lps22hb.h:267
pin_name_t scl
Definition: lps22hb.h:265
struct lps22hb_s lps22hb_t
Click ctx object definition.
void(* lps22hb_master_io_t)(struct lps22hb_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: lps22hb.h:228
lps22hb_master_io_t read_f
Definition: lps22hb.h:253
pin_name_t sck
Definition: lps22hb.h:269
Click ctx object definition.
Definition: lps22hb.h:233
digital_out_t cs
Definition: lps22hb.h:237
pin_name_t chip_select
Definition: lps22hb.h:251
LPS22HB_RETVAL lps22hb_init(lps22hb_t *ctx, lps22hb_cfg_t *cfg)
Initialization function.
void lps22hb_generic_write(lps22hb_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
pin_name_t mosi
Definition: lps22hb.h:268
pin_name_t cs
Definition: lps22hb.h:270
uint8_t lps22hb_select_t
Communication type.
Definition: lps22hb.h:223
uint8_t slave_address
Definition: lps22hb.h:250
pin_name_t int_pin
Definition: lps22hb.h:274
lps22hb_select_t master_sel
Definition: lps22hb.h:254
uint32_t spi_speed
Definition: lps22hb.h:281
float lps22hb_get_temp(lps22hb_t *ctx)
Get temperature value function.
lps22hb_master_io_t write_f
Definition: lps22hb.h:252
uint32_t i2c_speed
Definition: lps22hb.h:278