barometer2  2.0.0.0
barometer2.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 BAROMETER2_H
36 #define BAROMETER2_H
37 
38 #include "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define BAROMETER2_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
56 
62 #define BAROMETER2_RETVAL uint8_t
63 
64 #define BAROMETER2_OK 0x00
65 #define BAROMETER2_INIT_ERROR 0xFF
66 
72 #define BAROMETER2_REG_INTERRUPT_CONFIG 0x0B
73 #define BAROMETER2_REG_THRESHOLD_LSB 0x0C
74 #define BAROMETER2_REG_THRESHOLD_MSB 0x0D
75 #define BAROMETER2_REG_WHO_AM_I 0x0F
76 #define BAROMETER2_REG_CTRL_1 0x10
77 #define BAROMETER2_REG_CTRL_2 0x11
78 #define BAROMETER2_REG_CTRL_3 0x12
79 #define BAROMETER2_REG_FIFO_CTRL 0x14
80 #define BAROMETER2_REG_REF_P_XL 0x15
81 #define BAROMETER2_REG_REF_P_L 0x16
82 #define BAROMETER2_REG_REF_P_H 0x17
83 #define BAROMETER2_REG_RPDS_LSB 0x18
84 #define BAROMETER2_REG_RPDS_MSB 0x19
85 #define BAROMETER2_REG_RES_CONFIG 0x1A
86 #define BAROMETER2_REG_INT_SOURCE 0x25
87 #define BAROMETER2_REG_FIFO_STATUS 0x26
88 #define BAROMETER2_REG_STATUS 0x27
89 #define BAROMETER2_REG_PRESSURE_OUT_XL 0x28
90 #define BAROMETER2_REG_PRESSURE_OUT_L 0x29
91 #define BAROMETER2_REG_PRESSURE_OUT_H 0x2A
92 #define BAROMETER2_REG_TEMPERATURE_LSB 0x2B
93 #define BAROMETER2_REG_TEMPERATURE_MSB 0x2C
94 #define BAROMETER2_REG_LPFP_RES 0x33
95 
101 #define BAROMETER2_ICFG_AUTORIFP_DISABLE 0x00
102 #define BAROMETER2_ICFG_AUTORIFP_ENABLE 0x80
103 #define BAROMETER2_ICFG_AUTORIFP_NO_RESET 0x00
104 #define BAROMETER2_ICFG_AUTORIFP_RESET 0x40
105 #define BAROMETER2_ICFG_AUTOZERO_DISABLE 0x00
106 #define BAROMETER2_ICFG_AUTOZERO_ENABLE 0x20
107 #define BAROMETER2_ICFG_AUTOZERO_NO_RESET 0x00
108 #define BAROMETER2_ICFG_AUTOZERO_RESET 0x10
109 #define BAROMETER2_ICFG_INT_GENERATION_DISABLE 0x00
110 #define BAROMETER2_ICFG_INT_GENERATION_ENABLE 0x08
111 #define BAROMETER2_ICFG_INT_NOT_LATCHED 0x00
112 #define BAROMETER2_ICFG_INT_LATCHED 0x04
113 #define BAROMETER2_ICFG_INT_PLE_DISABLE 0x00
114 #define BAROMETER2_ICFG_INT_PLE_ENABLE 0x02
115 #define BAROMETER2_ICFG_INT_PHE_DISABLE 0x00
116 #define BAROMETER2_ICFG_INT_PHE_ENABLE 0x01
117 
123 #define BAROMETER2_CTRL1_ODR_1Hz 0x10
124 #define BAROMETER2_CTRL1_ODR_10Hz 0x20
125 #define BAROMETER2_CTRL1_ODR_25Hz 0x30
126 #define BAROMETER2_CTRL1_ODR_50Hz 0x40
127 #define BAROMETER2_CTRL1_ODR_75Hz 0x50
128 #define BAROMETER2_CTRL1_LPFP_DISABLE 0x00
129 #define BAROMETER2_CTRL1_LPFP_ENABLE 0x08
130 #define BAROMETER2_CTRL1_LPFP_CFG_ODR_2 0x00
131 #define BAROMETER2_CTRL1_LPFP_CFG_ODR_9 0x08
132 #define BAROMETER2_CTRL1_LPFP_CFG_ODR_10 0x0C
133 #define BAROMETER2_CTRL1_BDU_CONT_UPDATE 0x00
134 #define BAROMETER2_CTRL1_BDU_NOT_UPDATE 0x02
135 
141 #define BAROMETER2_CTRL2_BOOT_NORMAL_MODE 0x00
142 #define BAROMETER2_CTRL2_BOOT_REBOOT_MEMORY 0x80
143 #define BAROMETER2_CTRL2_FIFO_DISABLED 0x00
144 #define BAROMETER2_CTRL2_FIFO_ENABLED 0x40
145 #define BAROMETER2_CTRL2_FIFO_THR_DISABLED 0x00
146 #define BAROMETER2_CTRL2_FIFO_THR_ENABLED 0x20
147 #define BAROMETER2_CTRL2_ID_ADD_INC_DISABLED 0x00
148 #define BAROMETER2_CTRL2_ID_ADD_INC_ENABLED 0x10
149 #define BAROMETER2_CTRL2_SOFTWARE_RESET 0x04
150 #define BAROMETER2_CTRL2_MODE_IDLE 0x01
151 
157 #define BAROMETER2_CTRL3_INT_ACTIVE_HIGH 0x00
158 #define BAROMETER2_CTRL3_INT_ACTIVE_LOW 0x80
159 #define BAROMETER2_CTRL3_INT_PUSH_PULL 0x00
160 #define BAROMETER2_CTRL3_INT_OPEN_DRAIN 0x40
161 #define BAROMETER2_CTRL3_FIFO_FULL_DISABLED 0x00
162 #define BAROMETER2_CTRL3_FIFO_FULL_ENABLED 0x20
163 #define BAROMETER2_CTRL3_FIFO_WTM_DISABLED 0x00
164 #define BAROMETER2_CTRL3_FIFO_WTM_ENABLED 0x10
165 #define BAROMETER2_CTRL3_FIFO_OVERRUN_DISABLED 0x00
166 #define BAROMETER2_CTRL3_FIFO_OVERRUN_ENABLED 0x08
167 #define BAROMETER2_CTRL3_DRDY_DISABLED 0x00
168 #define BAROMETER2_CTRL3_DRDY_ENABLED 0x04
169 #define BAROMETER2_CTRL3_DRDY_STATUS_P_HIGH 0x01
170 #define BAROMETER2_CTRL3_DRDY_STATUS_P_LOW 0x02
171 
177 #define BAROMETER2_FIFO_CTRL_BYPASS_MODE 0x00
178 #define BAROMETER2_FIFO_CTRL_FIFO_MODE 0x20
179 #define BAROMETER2_FIFO_CTRL_STREAM_MODE 0x40
180 #define BAROMETER2_FIFO_CTRL_STREAM_TO_FIFO_MODE 0x60
181 #define BAROMETER2_FIFO_CTRL_BYPASS_TO_STREAM_MODE 0x80
182 #define BAROMETER2_FIFO_CTRL_DYNAMIC_STREAM_MODE 0xC0
183 #define BAROMETER2_FIFO_CTRL_BYPASS_TO_FIFO_MODE 0xE0
184 
190 #define BAROMETER2_RESCFG_NORMAL_MODE 0x00
191 #define BAROMETER2_RESCFG_LOW_CURRENT_MODE 0x01
192 
198 #define BAROMETER2_WHO_AM_I 0xB1
199 #define BAROMETER2_DEVICE_SLAVE_ADDR_GND 0x5C
200 #define BAROMETER2_DEVICE_SLAVE_ADDR_VCC 0x5D
201 
207 #define BAROMETER2_PRESSURE_DATA_IN_mBar 0
208 #define BAROMETER2_PRESSURE_DATA_IN_hPa 0
209 #define BAROMETER2_PRESSURE_DATA_IN_kPa 2
210 #define BAROMETER2_PRESSURE_DATA_IN_Torr 1
211 #define BAROMETER2_PRESSURE_DATA_IN_mmHg 1
212 #define BAROMETER2_PRESSURE_DATA_IN_Bar 3
213 
219 #define BAROMETER2_TEMPERATURE_IN_CELSIUS 0x00
220 #define BAROMETER2_TEMPERATURE_IN_KELVIN 0x01
221 #define BAROMETER2_TEMPERATURE_IN_FARENHAJT 0x02
222  // End group macro
225 // --------------------------------------------------------------- PUBLIC TYPES
234 typedef struct
235 {
236  // Input pins
237 
238  digital_in_t int_pin;
239 
240  // Modules
241 
242  i2c_master_t i2c;
243 
244  // ctx variable
245 
246  uint8_t slave_address;
247 
248 } barometer2_t;
249 
253 typedef struct
254 {
255  // Communication gpio pins
256 
257  pin_name_t scl;
258  pin_name_t sda;
259 
260  // Additional gpio pins
261 
262  pin_name_t int_pin;
263 
264  // static variable
265 
266  uint32_t i2c_speed;
267  uint8_t i2c_address;
268 
270  // End variable group
272 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
273 
279 #ifdef __cplusplus
280 extern "C"{
281 #endif
282 
292 
301 
310 
321 void barometer2_generic_write ( barometer2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
322 
333 void barometer2_generic_read ( barometer2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
334 
344 void barometer2_write_byte ( barometer2_t *ctx, uint8_t reg, uint8_t data_bytes );
345 
354 uint8_t barometer2_read_byte ( barometer2_t *ctx, uint8_t reg );
355 
364 float barometer2_get_temperature ( barometer2_t *ctx, uint8_t temp_format );
365 
374 
383 float barometer2_get_pressure ( barometer2_t *ctx, uint8_t press_format );
384 
392 uint8_t barometer2_get_interrupt ( barometer2_t *ctx );
393 
394 #ifdef __cplusplus
395 }
396 #endif
397 #endif // _BAROMETER2_H_
398  // End public_function group
401 
402 // ------------------------------------------------------------------------- END
barometer2_write_byte
void barometer2_write_byte(barometer2_t *ctx, uint8_t reg, uint8_t data_bytes)
Write one byte function.
barometer2_get_pressure
float barometer2_get_pressure(barometer2_t *ctx, uint8_t press_format)
Read pressure function.
barometer2_cfg_t::i2c_address
uint8_t i2c_address
Definition: barometer2.h:267
barometer2_cfg_t
Click configuration structure definition.
Definition: barometer2.h:253
barometer2_read_byte
uint8_t barometer2_read_byte(barometer2_t *ctx, uint8_t reg)
Read one byte function.
BAROMETER2_RETVAL
#define BAROMETER2_RETVAL
Definition: barometer2.h:62
barometer2_software_reset
void barometer2_software_reset(barometer2_t *ctx)
Reset function.
barometer2_generic_write
void barometer2_generic_write(barometer2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
barometer2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: barometer2.h:266
barometer2_t::i2c
i2c_master_t i2c
Definition: barometer2.h:242
barometer2_get_temperature
float barometer2_get_temperature(barometer2_t *ctx, uint8_t temp_format)
Read temperature function.
barometer2_init
BAROMETER2_RETVAL barometer2_init(barometer2_t *ctx, barometer2_cfg_t *cfg)
Initialization function.
barometer2_cfg_setup
void barometer2_cfg_setup(barometer2_cfg_t *cfg)
Config Object Initialization function.
barometer2_cfg_t::int_pin
pin_name_t int_pin
Definition: barometer2.h:262
barometer2_default_cfg
void barometer2_default_cfg(barometer2_t *ctx)
Click Default Configuration function.
barometer2_cfg_t::scl
pin_name_t scl
Definition: barometer2.h:257
barometer2_cfg_t::sda
pin_name_t sda
Definition: barometer2.h:258
barometer2_t::slave_address
uint8_t slave_address
Definition: barometer2.h:246
barometer2_t::int_pin
digital_in_t int_pin
Definition: barometer2.h:238
barometer2_get_interrupt
uint8_t barometer2_get_interrupt(barometer2_t *ctx)
Gets interrupt.
barometer2_t
Click ctx object definition.
Definition: barometer2.h:234
barometer2_generic_read
void barometer2_generic_read(barometer2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.