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 "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_in.h"
49 #include "drv_i2c_master.h"
50 
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define BAROMETER2_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
66 
72 #define BAROMETER2_RETVAL uint8_t
73 
74 #define BAROMETER2_OK 0x00
75 #define BAROMETER2_INIT_ERROR 0xFF
76 
82 #define BAROMETER2_REG_INTERRUPT_CONFIG 0x0B
83 #define BAROMETER2_REG_THRESHOLD_LSB 0x0C
84 #define BAROMETER2_REG_THRESHOLD_MSB 0x0D
85 #define BAROMETER2_REG_WHO_AM_I 0x0F
86 #define BAROMETER2_REG_CTRL_1 0x10
87 #define BAROMETER2_REG_CTRL_2 0x11
88 #define BAROMETER2_REG_CTRL_3 0x12
89 #define BAROMETER2_REG_FIFO_CTRL 0x14
90 #define BAROMETER2_REG_REF_P_XL 0x15
91 #define BAROMETER2_REG_REF_P_L 0x16
92 #define BAROMETER2_REG_REF_P_H 0x17
93 #define BAROMETER2_REG_RPDS_LSB 0x18
94 #define BAROMETER2_REG_RPDS_MSB 0x19
95 #define BAROMETER2_REG_RES_CONFIG 0x1A
96 #define BAROMETER2_REG_INT_SOURCE 0x25
97 #define BAROMETER2_REG_FIFO_STATUS 0x26
98 #define BAROMETER2_REG_STATUS 0x27
99 #define BAROMETER2_REG_PRESSURE_OUT_XL 0x28
100 #define BAROMETER2_REG_PRESSURE_OUT_L 0x29
101 #define BAROMETER2_REG_PRESSURE_OUT_H 0x2A
102 #define BAROMETER2_REG_TEMPERATURE_LSB 0x2B
103 #define BAROMETER2_REG_TEMPERATURE_MSB 0x2C
104 #define BAROMETER2_REG_LPFP_RES 0x33
105 
111 #define BAROMETER2_ICFG_AUTORIFP_DISABLE 0x00
112 #define BAROMETER2_ICFG_AUTORIFP_ENABLE 0x80
113 #define BAROMETER2_ICFG_AUTORIFP_NO_RESET 0x00
114 #define BAROMETER2_ICFG_AUTORIFP_RESET 0x40
115 #define BAROMETER2_ICFG_AUTOZERO_DISABLE 0x00
116 #define BAROMETER2_ICFG_AUTOZERO_ENABLE 0x20
117 #define BAROMETER2_ICFG_AUTOZERO_NO_RESET 0x00
118 #define BAROMETER2_ICFG_AUTOZERO_RESET 0x10
119 #define BAROMETER2_ICFG_INT_GENERATION_DISABLE 0x00
120 #define BAROMETER2_ICFG_INT_GENERATION_ENABLE 0x08
121 #define BAROMETER2_ICFG_INT_NOT_LATCHED 0x00
122 #define BAROMETER2_ICFG_INT_LATCHED 0x04
123 #define BAROMETER2_ICFG_INT_PLE_DISABLE 0x00
124 #define BAROMETER2_ICFG_INT_PLE_ENABLE 0x02
125 #define BAROMETER2_ICFG_INT_PHE_DISABLE 0x00
126 #define BAROMETER2_ICFG_INT_PHE_ENABLE 0x01
127 
133 #define BAROMETER2_CTRL1_ODR_1Hz 0x10
134 #define BAROMETER2_CTRL1_ODR_10Hz 0x20
135 #define BAROMETER2_CTRL1_ODR_25Hz 0x30
136 #define BAROMETER2_CTRL1_ODR_50Hz 0x40
137 #define BAROMETER2_CTRL1_ODR_75Hz 0x50
138 #define BAROMETER2_CTRL1_LPFP_DISABLE 0x00
139 #define BAROMETER2_CTRL1_LPFP_ENABLE 0x08
140 #define BAROMETER2_CTRL1_LPFP_CFG_ODR_2 0x00
141 #define BAROMETER2_CTRL1_LPFP_CFG_ODR_9 0x08
142 #define BAROMETER2_CTRL1_LPFP_CFG_ODR_10 0x0C
143 #define BAROMETER2_CTRL1_BDU_CONT_UPDATE 0x00
144 #define BAROMETER2_CTRL1_BDU_NOT_UPDATE 0x02
145 
151 #define BAROMETER2_CTRL2_BOOT_NORMAL_MODE 0x00
152 #define BAROMETER2_CTRL2_BOOT_REBOOT_MEMORY 0x80
153 #define BAROMETER2_CTRL2_FIFO_DISABLED 0x00
154 #define BAROMETER2_CTRL2_FIFO_ENABLED 0x40
155 #define BAROMETER2_CTRL2_FIFO_THR_DISABLED 0x00
156 #define BAROMETER2_CTRL2_FIFO_THR_ENABLED 0x20
157 #define BAROMETER2_CTRL2_ID_ADD_INC_DISABLED 0x00
158 #define BAROMETER2_CTRL2_ID_ADD_INC_ENABLED 0x10
159 #define BAROMETER2_CTRL2_SOFTWARE_RESET 0x04
160 #define BAROMETER2_CTRL2_MODE_IDLE 0x01
161 
167 #define BAROMETER2_CTRL3_INT_ACTIVE_HIGH 0x00
168 #define BAROMETER2_CTRL3_INT_ACTIVE_LOW 0x80
169 #define BAROMETER2_CTRL3_INT_PUSH_PULL 0x00
170 #define BAROMETER2_CTRL3_INT_OPEN_DRAIN 0x40
171 #define BAROMETER2_CTRL3_FIFO_FULL_DISABLED 0x00
172 #define BAROMETER2_CTRL3_FIFO_FULL_ENABLED 0x20
173 #define BAROMETER2_CTRL3_FIFO_WTM_DISABLED 0x00
174 #define BAROMETER2_CTRL3_FIFO_WTM_ENABLED 0x10
175 #define BAROMETER2_CTRL3_FIFO_OVERRUN_DISABLED 0x00
176 #define BAROMETER2_CTRL3_FIFO_OVERRUN_ENABLED 0x08
177 #define BAROMETER2_CTRL3_DRDY_DISABLED 0x00
178 #define BAROMETER2_CTRL3_DRDY_ENABLED 0x04
179 #define BAROMETER2_CTRL3_DRDY_STATUS_P_HIGH 0x01
180 #define BAROMETER2_CTRL3_DRDY_STATUS_P_LOW 0x02
181 
187 #define BAROMETER2_FIFO_CTRL_BYPASS_MODE 0x00
188 #define BAROMETER2_FIFO_CTRL_FIFO_MODE 0x20
189 #define BAROMETER2_FIFO_CTRL_STREAM_MODE 0x40
190 #define BAROMETER2_FIFO_CTRL_STREAM_TO_FIFO_MODE 0x60
191 #define BAROMETER2_FIFO_CTRL_BYPASS_TO_STREAM_MODE 0x80
192 #define BAROMETER2_FIFO_CTRL_DYNAMIC_STREAM_MODE 0xC0
193 #define BAROMETER2_FIFO_CTRL_BYPASS_TO_FIFO_MODE 0xE0
194 
200 #define BAROMETER2_RESCFG_NORMAL_MODE 0x00
201 #define BAROMETER2_RESCFG_LOW_CURRENT_MODE 0x01
202 
208 #define BAROMETER2_WHO_AM_I 0xB1
209 #define BAROMETER2_DEVICE_SLAVE_ADDR_GND 0x5C
210 #define BAROMETER2_DEVICE_SLAVE_ADDR_VCC 0x5D
211 
217 #define BAROMETER2_PRESSURE_DATA_IN_mBar 0
218 #define BAROMETER2_PRESSURE_DATA_IN_hPa 0
219 #define BAROMETER2_PRESSURE_DATA_IN_kPa 2
220 #define BAROMETER2_PRESSURE_DATA_IN_Torr 1
221 #define BAROMETER2_PRESSURE_DATA_IN_mmHg 1
222 #define BAROMETER2_PRESSURE_DATA_IN_Bar 3
223 
229 #define BAROMETER2_TEMPERATURE_IN_CELSIUS 0x00
230 #define BAROMETER2_TEMPERATURE_IN_KELVIN 0x01
231 #define BAROMETER2_TEMPERATURE_IN_FARENHAJT 0x02
232  // End group macro
235 // --------------------------------------------------------------- PUBLIC TYPES
244 typedef struct
245 {
246  // Input pins
247 
248  digital_in_t int_pin;
249 
250  // Modules
251 
252  i2c_master_t i2c;
253 
254  // ctx variable
255 
256  uint8_t slave_address;
257 
258 } barometer2_t;
259 
263 typedef struct
264 {
265  // Communication gpio pins
266 
267  pin_name_t scl;
268  pin_name_t sda;
269 
270  // Additional gpio pins
271 
272  pin_name_t int_pin;
273 
274  // static variable
275 
276  uint32_t i2c_speed;
277  uint8_t i2c_address;
278 
280  // End variable group
282 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
283 
289 #ifdef __cplusplus
290 extern "C"{
291 #endif
292 
302 
311 
320 
331 void barometer2_generic_write ( barometer2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
332 
343 void barometer2_generic_read ( barometer2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
344 
354 void barometer2_write_byte ( barometer2_t *ctx, uint8_t reg, uint8_t data_bytes );
355 
364 uint8_t barometer2_read_byte ( barometer2_t *ctx, uint8_t reg );
365 
374 float barometer2_get_temperature ( barometer2_t *ctx, uint8_t temp_format );
375 
384 
393 float barometer2_get_pressure ( barometer2_t *ctx, uint8_t press_format );
394 
403 
404 #ifdef __cplusplus
405 }
406 #endif
407 #endif // _BAROMETER2_H_
408  // End public_function group
411 
412 // ------------------------------------------------------------------------- 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:277
barometer2_cfg_t
Click configuration structure definition.
Definition: barometer2.h:264
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:72
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:276
barometer2_t::i2c
i2c_master_t i2c
Definition: barometer2.h:252
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:272
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:267
barometer2_cfg_t::sda
pin_name_t sda
Definition: barometer2.h:268
barometer2_t::slave_address
uint8_t slave_address
Definition: barometer2.h:256
barometer2_t::int_pin
digital_in_t int_pin
Definition: barometer2.h:248
barometer2_get_interrupt
uint8_t barometer2_get_interrupt(barometer2_t *ctx)
Gets interrupt.
barometer2_t
Click ctx object definition.
Definition: barometer2.h:245
barometer2_generic_read
void barometer2_generic_read(barometer2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.