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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55#include "drv_spi_master.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define LPS22HB_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
70 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
71 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
72 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
73 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
74 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
75 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
82#define LPS22HB_MASTER_I2C 0
83#define LPS22HB_MASTER_SPI 1
90#define LPS22HB_RETVAL uint8_t
91
92#define LPS22HB_OK 0x00
93#define LPS22HB_INIT_ERROR 0xFF
100#define LPS22HB_DEV_RES_PRES 4096.0
101#define LPS22HB_DEV_RES_TEMP 100.0
108#define LPS22HB_I2C_ADDRESS_0 0x5C
109#define LPS22HB_I2C_ADDRESS_1 0x5D
116#define LPS22HB_REG_INTERRUPT_CFG 0x0B
117#define LPS22HB_REG_THS_P_L 0x0C
118#define LPS22HB_REG_THS_P_H 0x0D
119#define LPS22HB_REG_WHO_AM_I 0x0F
120
121#define LPS22HB_REG_REF_P_XL 0x15
122#define LPS22HB_REG_REF_P_L 0x16
123#define LPS22HB_REG_REF_P_H 0x17
124#define LPS22HB_REG_RPDS_L 0x18
125#define LPS22HB_REG_RPDS_H 0x19
126#define LPS22HB_REG_RES_CONF 0x1A
127#define LPS22HB_REG_INT_SOURCE 0x25
128#define LPS22HB_REG_FIFO_STATUS 0x26
129#define LPS22HB_REG_STATUS 0x27
130#define LPS22HB_REG_PRESS_OUT_XL 0x28
131#define LPS22HB_REG_PRESS_OUT_L 0x29
132#define LPS22HB_REG_PRESS_OUT_H 0x2A
133#define LPS22HB_REG_TEMP_OUT_L 0x2B
134#define LPS22HB_REG_TEMP_OUT_H 0x2C
135#define LPS22HB_REG_CLOCK_TREE_CONFIGURATION 0x43
142#define LPS22HB_RES_CONF_NORMAL_MODE 0x00
143#define LPS22HB_RES_CONF_LOW_CURRENT_MODE 0x01
150#define LPS22HB_CTRL_REG_R1 0x10
151#define LPS22HB_CTRL_REG_R2 0x11
152#define LPS22HB_CTRL_REG_R3 0x12
153#define LPS22HB_CTRL_REG_FIFO 0x14
154
155#define LPS22HB_CTRL_I2C 0x10
156#define LPS22HB_CTRL_SPI 0x18
163#define LPS22HB_MASK_DATA 0x80
164#define LPS22HB_MASK_DATA_RESET 0x02
165#define LPS22HB_MASK_DATA_ODR 0x30
166
167#define LPS22HB_MASK_REG1_ODR 0x70
168#define LPS22HB_MASK_REG1_LPFP 0x08
169#define LPS22HB_MASK_REG1_LPFP_CUTOFF 0x04
170#define LPS22HB_MASK_REG1_BDU 0x02
171#define LPS22HB_MASK_REG1_SIM 0x01
172
173#define LPS22HB_MASK_REG2_FIFO_EN 0x40
174#define LPS22HB_MASK_REG2_WTM_EN 0x20
175#define LPS22HB_MASK_REG2_ADD_INC 0x10
176#define LPS22HB_MASK_REG2_I2C 0x08
177#define LPS22HB_MASK_REG2_ONE_SHOT 0x01
178
179#define LPS22HB_MASK_REG3_INT_H_L 0x80
180#define LPS22HB_MASK_REG3_PP_OD 0x40
181#define LPS22HB_MASK_REG3_FIFO_FULL 0x20
182#define LPS22HB_MASK_REG3_FIFO_FTH 0x10
183#define LPS22HB_MASK_REG3_FIFO_OVR 0x08
184#define LPS22HB_MASK_REG3_DRDY 0x04
185#define LPS22HB_MASK_REG3_INT_S12 0x03
192#define LPS22HB_INT_MASK_CFG_AUTORIFP 0x80
193#define LPS22HB_INT_MASK_CFG_RESET_ARP 0x40
194#define LPS22HB_INT_MASK_CFG_AUTOZERO 0x20
195#define LPS22HB_INT_MASK_CFG_RESET_AZ 0x10
196#define LPS22HB_INT_MASK_CFG_DIFF_EN 0x08
197#define LPS22HB_INT_MASK_CFG_LIR 0x04
198#define LPS22HB_INT_MASK_CFG_PLE 0x02
199#define LPS22HB_INT_MASK_CFG_PHE 0x01
200
201#define LPS22HB_INT_MASK_SOURCE_BOOT_STATUS 0x80
202#define LPS22HB_INT_MASK_SOURCE_IA 0x04
203#define LPS22HB_INT_MASK_SOURCE_PL 0x02
204#define LPS22HB_INT_MASK_SOURCE_PH 0x01
205
206#define LPS22HB_INT_MASK_SOURCE_TOR 0x20
207#define LPS22HB_INT_MASK_SOURCE_POR 0x10
208#define LPS22HB_INT_MASK_SOURCE_TDA 0x02
209#define LPS22HB_INT_MASK_SOURCE_PDA 0x01
216#define LPS22HB_FIFO_MASK_CTRL_MODE 0xE0
217#define LPS22HB_FIFO_MASK_CTRL_WTM_POINT 0x1F
218
219#define LPS22HB_FIFO_MASK_STATUS_FTH 0x80
220#define LPS22HB_FIFO_MASK_STATUS_OVR 0x40
221#define LPS22HB_FIFO_MASK_STATUS_LEVEL 0x3F
222#define LPS22HB_FIFO_STATUS_EMPTY 0x00
223#define LPS22HB_FIFO_STATUS_FULL 0x20
226 // End group macro
227
228// --------------------------------------------------------------- PUBLIC TYPES
237typedef uint8_t lps22hb_select_t;
238
242typedef void ( *lps22hb_master_io_t )( struct lps22hb_s*, uint8_t, uint8_t*, uint8_t );
243
247typedef struct lps22hb_s
248{
249 // Output pins
250
251 digital_out_t cs;
252
253 // Input pins
254
255 digital_in_t int_pin;
256
257 // Modules
258
259 i2c_master_t i2c;
260 spi_master_t spi;
261
262 // ctx variable
263
265 pin_name_t chip_select;
269
271
275typedef struct
276{
277 // Communication gpio pins
278
279 pin_name_t scl;
280 pin_name_t sda;
281 pin_name_t miso;
282 pin_name_t mosi;
283 pin_name_t sck;
284 pin_name_t cs;
285
286 // Additional gpio pins
287
288 pin_name_t int_pin;
289
290 // static variable
291
292 uint32_t i2c_speed;
293 uint8_t i2c_address;
294
295 uint32_t spi_speed;
296 spi_master_mode_t spi_mode;
297 spi_master_chip_select_polarity_t cs_polarity;
298
300
302
303 // End types group
304
305// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
311#ifdef __cplusplus
312extern "C"{
313#endif
314
324
334
343
354void lps22hb_generic_write ( lps22hb_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
355
366void lps22hb_generic_read ( lps22hb_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
367
377
387
397void lps22hb_update_reg ( lps22hb_t *ctx, uint8_t reg_adr, uint8_t reg_val );
398
414
430
440void lps22hb_set_fifo_mode ( lps22hb_t *ctx, uint8_t mode_sel, uint8_t wm_lvl );
441
457
458#ifdef __cplusplus
459}
460#endif
461#endif // _LPS22HB_H_
462
463 // End public_function group
465
466// ------------------------------------------------------------------------- END
#define LPS22HB_RETVAL
Definition lps22hb.h:90
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.
float lps22hb_get_temp(lps22hb_t *ctx)
Get temperature value function.
void lps22hb_start_configuration(lps22hb_t *ctx)
Set start configuration function.
void lps22hb_default_cfg(lps22hb_t *ctx, lps22hb_cfg_t *cfg)
Click Default Configuration function.
float lps22hb_get_pressure(lps22hb_t *ctx)
Get pressure value function.
void lps22hb_generic_read(lps22hb_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void lps22hb_set_fifo_mode(lps22hb_t *ctx, uint8_t mode_sel, uint8_t wm_lvl)
Set FIFO control mode function.
void lps22hb_cfg_setup(lps22hb_cfg_t *cfg)
Config Object Initialization function.
void lps22hb_soft_reset(lps22hb_t *ctx)
Soft reset function.
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.
void(* lps22hb_master_io_t)(struct lps22hb_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition lps22hb.h:242
struct lps22hb_s lps22hb_t
Click ctx object definition.
uint8_t lps22hb_select_t
Communication type.
Definition lps22hb.h:237
Click configuration structure definition.
Definition lps22hb.h:276
lps22hb_select_t sel
Definition lps22hb.h:299
uint32_t i2c_speed
Definition lps22hb.h:292
spi_master_chip_select_polarity_t cs_polarity
Definition lps22hb.h:297
pin_name_t sck
Definition lps22hb.h:283
spi_master_mode_t spi_mode
Definition lps22hb.h:296
pin_name_t mosi
Definition lps22hb.h:282
uint32_t spi_speed
Definition lps22hb.h:295
pin_name_t scl
Definition lps22hb.h:279
pin_name_t int_pin
Definition lps22hb.h:288
pin_name_t miso
Definition lps22hb.h:281
pin_name_t sda
Definition lps22hb.h:280
pin_name_t cs
Definition lps22hb.h:284
uint8_t i2c_address
Definition lps22hb.h:293
Click ctx object definition.
Definition lps22hb.h:248
lps22hb_master_io_t read_f
Definition lps22hb.h:267
digital_out_t cs
Definition lps22hb.h:251
spi_master_t spi
Definition lps22hb.h:260
lps22hb_master_io_t write_f
Definition lps22hb.h:266
lps22hb_select_t master_sel
Definition lps22hb.h:268
digital_in_t int_pin
Definition lps22hb.h:255
i2c_master_t i2c
Definition lps22hb.h:259
uint8_t slave_address
Definition lps22hb.h:264
pin_name_t chip_select
Definition lps22hb.h:265