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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 #include "drv_spi_master.h"
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define LPS22HB_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
66  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
67  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
68  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
69  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
70  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define LPS22HB_MASTER_I2C 0
79 #define LPS22HB_MASTER_SPI 1
80 
86 #define LPS22HB_RETVAL uint8_t
87 
88 #define LPS22HB_OK 0x00
89 #define LPS22HB_INIT_ERROR 0xFF
90 
96 #define LPS22HB_DEV_RES_PRES 4096.0
97 #define LPS22HB_DEV_RES_TEMP 100.0
98 
104 #define LPS22HB_I2C_ADDRESS_0 0x5C
105 #define LPS22HB_I2C_ADDRESS_1 0x5D
106 
112 #define LPS22HB_REG_INTERRUPT_CFG 0x0B
113 #define LPS22HB_REG_THS_P_L 0x0C
114 #define LPS22HB_REG_THS_P_H 0x0D
115 #define LPS22HB_REG_WHO_AM_I 0x0F
116 
117 #define LPS22HB_REG_REF_P_XL 0x15
118 #define LPS22HB_REG_REF_P_L 0x16
119 #define LPS22HB_REG_REF_P_H 0x17
120 #define LPS22HB_REG_RPDS_L 0x18
121 #define LPS22HB_REG_RPDS_H 0x19
122 #define LPS22HB_REG_RES_CONF 0x1A
123 #define LPS22HB_REG_INT_SOURCE 0x25
124 #define LPS22HB_REG_FIFO_STATUS 0x26
125 #define LPS22HB_REG_STATUS 0x27
126 #define LPS22HB_REG_PRESS_OUT_XL 0x28
127 #define LPS22HB_REG_PRESS_OUT_L 0x29
128 #define LPS22HB_REG_PRESS_OUT_H 0x2A
129 #define LPS22HB_REG_TEMP_OUT_L 0x2B
130 #define LPS22HB_REG_TEMP_OUT_H 0x2C
131 #define LPS22HB_REG_CLOCK_TREE_CONFIGURATION 0x43
132 
138 #define LPS22HB_RES_CONF_NORMAL_MODE 0x00
139 #define LPS22HB_RES_CONF_LOW_CURRENT_MODE 0x01
140 
146 #define LPS22HB_CTRL_REG_R1 0x10
147 #define LPS22HB_CTRL_REG_R2 0x11
148 #define LPS22HB_CTRL_REG_R3 0x12
149 #define LPS22HB_CTRL_REG_FIFO 0x14
150 
151 #define LPS22HB_CTRL_I2C 0x10
152 #define LPS22HB_CTRL_SPI 0x18
153 
159 #define LPS22HB_MASK_DATA 0x80
160 #define LPS22HB_MASK_DATA_RESET 0x02
161 #define LPS22HB_MASK_DATA_ODR 0x30
162 
163 #define LPS22HB_MASK_REG1_ODR 0x70
164 #define LPS22HB_MASK_REG1_LPFP 0x08
165 #define LPS22HB_MASK_REG1_LPFP_CUTOFF 0x04
166 #define LPS22HB_MASK_REG1_BDU 0x02
167 #define LPS22HB_MASK_REG1_SIM 0x01
168 
169 #define LPS22HB_MASK_REG2_FIFO_EN 0x40
170 #define LPS22HB_MASK_REG2_WTM_EN 0x20
171 #define LPS22HB_MASK_REG2_ADD_INC 0x10
172 #define LPS22HB_MASK_REG2_I2C 0x08
173 #define LPS22HB_MASK_REG2_ONE_SHOT 0x01
174 
175 #define LPS22HB_MASK_REG3_INT_H_L 0x80
176 #define LPS22HB_MASK_REG3_PP_OD 0x40
177 #define LPS22HB_MASK_REG3_FIFO_FULL 0x20
178 #define LPS22HB_MASK_REG3_FIFO_FTH 0x10
179 #define LPS22HB_MASK_REG3_FIFO_OVR 0x08
180 #define LPS22HB_MASK_REG3_DRDY 0x04
181 #define LPS22HB_MASK_REG3_INT_S12 0x03
182 
188 #define LPS22HB_INT_MASK_CFG_AUTORIFP 0x80
189 #define LPS22HB_INT_MASK_CFG_RESET_ARP 0x40
190 #define LPS22HB_INT_MASK_CFG_AUTOZERO 0x20
191 #define LPS22HB_INT_MASK_CFG_RESET_AZ 0x10
192 #define LPS22HB_INT_MASK_CFG_DIFF_EN 0x08
193 #define LPS22HB_INT_MASK_CFG_LIR 0x04
194 #define LPS22HB_INT_MASK_CFG_PLE 0x02
195 #define LPS22HB_INT_MASK_CFG_PHE 0x01
196 
197 #define LPS22HB_INT_MASK_SOURCE_BOOT_STATUS 0x80
198 #define LPS22HB_INT_MASK_SOURCE_IA 0x04
199 #define LPS22HB_INT_MASK_SOURCE_PL 0x02
200 #define LPS22HB_INT_MASK_SOURCE_PH 0x01
201 
202 #define LPS22HB_INT_MASK_SOURCE_TOR 0x20
203 #define LPS22HB_INT_MASK_SOURCE_POR 0x10
204 #define LPS22HB_INT_MASK_SOURCE_TDA 0x02
205 #define LPS22HB_INT_MASK_SOURCE_PDA 0x01
206 
212 #define LPS22HB_FIFO_MASK_CTRL_MODE 0xE0
213 #define LPS22HB_FIFO_MASK_CTRL_WTM_POINT 0x1F
214 
215 #define LPS22HB_FIFO_MASK_STATUS_FTH 0x80
216 #define LPS22HB_FIFO_MASK_STATUS_OVR 0x40
217 #define LPS22HB_FIFO_MASK_STATUS_LEVEL 0x3F
218 #define LPS22HB_FIFO_STATUS_EMPTY 0x00
219 #define LPS22HB_FIFO_STATUS_FULL 0x20
220  // End group macro
223 
224 // --------------------------------------------------------------- PUBLIC TYPES
233 typedef uint8_t lps22hb_select_t;
234 
238 typedef void ( *lps22hb_master_io_t )( struct lps22hb_s*, uint8_t, uint8_t*, uint8_t );
239 
243 typedef struct lps22hb_s
244 {
245  // Output pins
246 
247  digital_out_t cs;
248 
249  // Input pins
250 
251  digital_in_t int_pin;
252 
253  // Modules
254 
255  i2c_master_t i2c;
256  spi_master_t spi;
257 
258  // ctx variable
259 
260  uint8_t slave_address;
261  pin_name_t chip_select;
265 
267 
271 typedef struct
272 {
273  // Communication gpio pins
274 
275  pin_name_t scl;
276  pin_name_t sda;
277  pin_name_t miso;
278  pin_name_t mosi;
279  pin_name_t sck;
280  pin_name_t cs;
281 
282  // Additional gpio pins
283 
284  pin_name_t int_pin;
285 
286  // static variable
287 
288  uint32_t i2c_speed;
289  uint8_t i2c_address;
290 
291  uint32_t spi_speed;
292  spi_master_mode_t spi_mode;
293  spi_master_chip_select_polarity_t cs_polarity;
294 
296 
297 } lps22hb_cfg_t;
298  // End types group
300 
301 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
307 #ifdef __cplusplus
308 extern "C"{
309 #endif
310 
320 
330 
339 
350 void lps22hb_generic_write ( lps22hb_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
351 
362 void lps22hb_generic_read ( lps22hb_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
363 
373 
383 
393 void lps22hb_update_reg ( lps22hb_t *ctx, uint8_t reg_adr, uint8_t reg_val );
394 
410 
426 
436 void lps22hb_set_fifo_mode ( lps22hb_t *ctx, uint8_t mode_sel, uint8_t wm_lvl );
437 
452 uint8_t lps22hb_check_int ( lps22hb_t *ctx );
453 
454 #ifdef __cplusplus
455 }
456 #endif
457 #endif // _LPS22HB_H_
458  // End public_function group
461 
462 // ------------------------------------------------------------------------- END
lps22hb_master_io_t
void(* lps22hb_master_io_t)(struct lps22hb_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: lps22hb.h:238
lps22hb_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: lps22hb.h:292
lps22hb_cfg_t::mosi
pin_name_t mosi
Definition: lps22hb.h:278
LPS22HB_RETVAL
#define LPS22HB_RETVAL
Definition: lps22hb.h:86
lps22hb_cfg_t::scl
pin_name_t scl
Definition: lps22hb.h:275
lps22hb_s::spi
spi_master_t spi
Definition: lps22hb.h:256
lps22hb_s::i2c
i2c_master_t i2c
Definition: lps22hb.h:255
lps22hb_cfg_t::spi_speed
uint32_t spi_speed
Definition: lps22hb.h:291
lps22hb_default_cfg
void lps22hb_default_cfg(lps22hb_t *ctx, lps22hb_cfg_t *cfg)
Click Default Configuration function.
lps22hb_get_temp
float lps22hb_get_temp(lps22hb_t *ctx)
Get temperature value function.
lps22hb_cfg_t::int_pin
pin_name_t int_pin
Definition: lps22hb.h:284
lps22hb_cfg_t::cs
pin_name_t cs
Definition: lps22hb.h:280
lps22hb_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: lps22hb.h:288
lps22hb_soft_reset
void lps22hb_soft_reset(lps22hb_t *ctx)
Soft reset function.
lps22hb_s::cs
digital_out_t cs
Definition: lps22hb.h:247
lps22hb_s::read_f
lps22hb_master_io_t read_f
Definition: lps22hb.h:263
lps22hb_s::int_pin
digital_in_t int_pin
Definition: lps22hb.h:251
lps22hb_cfg_t::sda
pin_name_t sda
Definition: lps22hb.h:276
lps22hb_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: lps22hb.h:293
lps22hb_generic_write
void lps22hb_generic_write(lps22hb_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
lps22hb_cfg_t
Click configuration structure definition.
Definition: lps22hb.h:272
lps22hb_s::chip_select
pin_name_t chip_select
Definition: lps22hb.h:261
lps22hb_cfg_t::i2c_address
uint8_t i2c_address
Definition: lps22hb.h:289
lps22hb_check_int
uint8_t lps22hb_check_int(lps22hb_t *ctx)
Check Interrupt state function.
lps22hb_set_fifo_mode
void lps22hb_set_fifo_mode(lps22hb_t *ctx, uint8_t mode_sel, uint8_t wm_lvl)
Set FIFO control mode function.
lps22hb_t
struct lps22hb_s lps22hb_t
Click ctx object definition.
lps22hb_init
LPS22HB_RETVAL lps22hb_init(lps22hb_t *ctx, lps22hb_cfg_t *cfg)
Initialization function.
lps22hb_s::slave_address
uint8_t slave_address
Definition: lps22hb.h:260
lps22hb_generic_read
void lps22hb_generic_read(lps22hb_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
lps22hb_cfg_t::sel
lps22hb_select_t sel
Definition: lps22hb.h:295
lps22hb_cfg_setup
void lps22hb_cfg_setup(lps22hb_cfg_t *cfg)
Config Object Initialization function.
lps22hb_start_configuration
void lps22hb_start_configuration(lps22hb_t *ctx)
Set start configuration function.
lps22hb_s::write_f
lps22hb_master_io_t write_f
Definition: lps22hb.h:262
lps22hb_cfg_t::miso
pin_name_t miso
Definition: lps22hb.h:277
lps22hb_select_t
uint8_t lps22hb_select_t
Communication type.
Definition: lps22hb.h:233
lps22hb_update_reg
void lps22hb_update_reg(lps22hb_t *ctx, uint8_t reg_adr, uint8_t reg_val)
Update register function.
lps22hb_cfg_t::sck
pin_name_t sck
Definition: lps22hb.h:279
lps22hb_s
Click ctx object definition.
Definition: lps22hb.h:244
lps22hb_s::master_sel
lps22hb_select_t master_sel
Definition: lps22hb.h:264
lps22hb_get_pressure
float lps22hb_get_pressure(lps22hb_t *ctx)
Get pressure value function.