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
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_in.h"
53#include "drv_i2c_master.h"
54
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define BAROMETER2_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
76#define BAROMETER2_RETVAL uint8_t
77
78#define BAROMETER2_OK 0x00
79#define BAROMETER2_INIT_ERROR 0xFF
86#define BAROMETER2_REG_INTERRUPT_CONFIG 0x0B
87#define BAROMETER2_REG_THRESHOLD_LSB 0x0C
88#define BAROMETER2_REG_THRESHOLD_MSB 0x0D
89#define BAROMETER2_REG_WHO_AM_I 0x0F
90#define BAROMETER2_REG_CTRL_1 0x10
91#define BAROMETER2_REG_CTRL_2 0x11
92#define BAROMETER2_REG_CTRL_3 0x12
93#define BAROMETER2_REG_FIFO_CTRL 0x14
94#define BAROMETER2_REG_REF_P_XL 0x15
95#define BAROMETER2_REG_REF_P_L 0x16
96#define BAROMETER2_REG_REF_P_H 0x17
97#define BAROMETER2_REG_RPDS_LSB 0x18
98#define BAROMETER2_REG_RPDS_MSB 0x19
99#define BAROMETER2_REG_RES_CONFIG 0x1A
100#define BAROMETER2_REG_INT_SOURCE 0x25
101#define BAROMETER2_REG_FIFO_STATUS 0x26
102#define BAROMETER2_REG_STATUS 0x27
103#define BAROMETER2_REG_PRESSURE_OUT_XL 0x28
104#define BAROMETER2_REG_PRESSURE_OUT_L 0x29
105#define BAROMETER2_REG_PRESSURE_OUT_H 0x2A
106#define BAROMETER2_REG_TEMPERATURE_LSB 0x2B
107#define BAROMETER2_REG_TEMPERATURE_MSB 0x2C
108#define BAROMETER2_REG_LPFP_RES 0x33
115#define BAROMETER2_ICFG_AUTORIFP_DISABLE 0x00
116#define BAROMETER2_ICFG_AUTORIFP_ENABLE 0x80
117#define BAROMETER2_ICFG_AUTORIFP_NO_RESET 0x00
118#define BAROMETER2_ICFG_AUTORIFP_RESET 0x40
119#define BAROMETER2_ICFG_AUTOZERO_DISABLE 0x00
120#define BAROMETER2_ICFG_AUTOZERO_ENABLE 0x20
121#define BAROMETER2_ICFG_AUTOZERO_NO_RESET 0x00
122#define BAROMETER2_ICFG_AUTOZERO_RESET 0x10
123#define BAROMETER2_ICFG_INT_GENERATION_DISABLE 0x00
124#define BAROMETER2_ICFG_INT_GENERATION_ENABLE 0x08
125#define BAROMETER2_ICFG_INT_NOT_LATCHED 0x00
126#define BAROMETER2_ICFG_INT_LATCHED 0x04
127#define BAROMETER2_ICFG_INT_PLE_DISABLE 0x00
128#define BAROMETER2_ICFG_INT_PLE_ENABLE 0x02
129#define BAROMETER2_ICFG_INT_PHE_DISABLE 0x00
130#define BAROMETER2_ICFG_INT_PHE_ENABLE 0x01
137#define BAROMETER2_CTRL1_ODR_1Hz 0x10
138#define BAROMETER2_CTRL1_ODR_10Hz 0x20
139#define BAROMETER2_CTRL1_ODR_25Hz 0x30
140#define BAROMETER2_CTRL1_ODR_50Hz 0x40
141#define BAROMETER2_CTRL1_ODR_75Hz 0x50
142#define BAROMETER2_CTRL1_LPFP_DISABLE 0x00
143#define BAROMETER2_CTRL1_LPFP_ENABLE 0x08
144#define BAROMETER2_CTRL1_LPFP_CFG_ODR_2 0x00
145#define BAROMETER2_CTRL1_LPFP_CFG_ODR_9 0x08
146#define BAROMETER2_CTRL1_LPFP_CFG_ODR_10 0x0C
147#define BAROMETER2_CTRL1_BDU_CONT_UPDATE 0x00
148#define BAROMETER2_CTRL1_BDU_NOT_UPDATE 0x02
155#define BAROMETER2_CTRL2_BOOT_NORMAL_MODE 0x00
156#define BAROMETER2_CTRL2_BOOT_REBOOT_MEMORY 0x80
157#define BAROMETER2_CTRL2_FIFO_DISABLED 0x00
158#define BAROMETER2_CTRL2_FIFO_ENABLED 0x40
159#define BAROMETER2_CTRL2_FIFO_THR_DISABLED 0x00
160#define BAROMETER2_CTRL2_FIFO_THR_ENABLED 0x20
161#define BAROMETER2_CTRL2_ID_ADD_INC_DISABLED 0x00
162#define BAROMETER2_CTRL2_ID_ADD_INC_ENABLED 0x10
163#define BAROMETER2_CTRL2_SOFTWARE_RESET 0x04
164#define BAROMETER2_CTRL2_MODE_IDLE 0x01
171#define BAROMETER2_CTRL3_INT_ACTIVE_HIGH 0x00
172#define BAROMETER2_CTRL3_INT_ACTIVE_LOW 0x80
173#define BAROMETER2_CTRL3_INT_PUSH_PULL 0x00
174#define BAROMETER2_CTRL3_INT_OPEN_DRAIN 0x40
175#define BAROMETER2_CTRL3_FIFO_FULL_DISABLED 0x00
176#define BAROMETER2_CTRL3_FIFO_FULL_ENABLED 0x20
177#define BAROMETER2_CTRL3_FIFO_WTM_DISABLED 0x00
178#define BAROMETER2_CTRL3_FIFO_WTM_ENABLED 0x10
179#define BAROMETER2_CTRL3_FIFO_OVERRUN_DISABLED 0x00
180#define BAROMETER2_CTRL3_FIFO_OVERRUN_ENABLED 0x08
181#define BAROMETER2_CTRL3_DRDY_DISABLED 0x00
182#define BAROMETER2_CTRL3_DRDY_ENABLED 0x04
183#define BAROMETER2_CTRL3_DRDY_STATUS_P_HIGH 0x01
184#define BAROMETER2_CTRL3_DRDY_STATUS_P_LOW 0x02
191#define BAROMETER2_FIFO_CTRL_BYPASS_MODE 0x00
192#define BAROMETER2_FIFO_CTRL_FIFO_MODE 0x20
193#define BAROMETER2_FIFO_CTRL_STREAM_MODE 0x40
194#define BAROMETER2_FIFO_CTRL_STREAM_TO_FIFO_MODE 0x60
195#define BAROMETER2_FIFO_CTRL_BYPASS_TO_STREAM_MODE 0x80
196#define BAROMETER2_FIFO_CTRL_DYNAMIC_STREAM_MODE 0xC0
197#define BAROMETER2_FIFO_CTRL_BYPASS_TO_FIFO_MODE 0xE0
204#define BAROMETER2_RESCFG_NORMAL_MODE 0x00
205#define BAROMETER2_RESCFG_LOW_CURRENT_MODE 0x01
212#define BAROMETER2_WHO_AM_I 0xB1
213#define BAROMETER2_DEVICE_SLAVE_ADDR_GND 0x5C
214#define BAROMETER2_DEVICE_SLAVE_ADDR_VCC 0x5D
221#define BAROMETER2_PRESSURE_DATA_IN_mBar 0
222#define BAROMETER2_PRESSURE_DATA_IN_hPa 0
223#define BAROMETER2_PRESSURE_DATA_IN_kPa 2
224#define BAROMETER2_PRESSURE_DATA_IN_Torr 1
225#define BAROMETER2_PRESSURE_DATA_IN_mmHg 1
226#define BAROMETER2_PRESSURE_DATA_IN_Bar 3
233#define BAROMETER2_TEMPERATURE_IN_CELSIUS 0x00
234#define BAROMETER2_TEMPERATURE_IN_KELVIN 0x01
235#define BAROMETER2_TEMPERATURE_IN_FARENHAJT 0x02
238 // End group macro
239// --------------------------------------------------------------- PUBLIC TYPES
248typedef struct
249{
250 // Input pins
251
252 digital_in_t int_pin;
253
254 // Modules
255
256 i2c_master_t i2c;
257
258 // ctx variable
259
261
263
267typedef struct
268{
269 // Communication gpio pins
270
271 pin_name_t scl;
272 pin_name_t sda;
273
274 // Additional gpio pins
275
276 pin_name_t int_pin;
277
278 // static variable
279
280 uint32_t i2c_speed;
281 uint8_t i2c_address;
282
284
285 // End variable group
286// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
287
293#ifdef __cplusplus
294extern "C"{
295#endif
296
306
315
324
335void barometer2_generic_write ( barometer2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
336
347void barometer2_generic_read ( barometer2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
348
358void barometer2_write_byte ( barometer2_t *ctx, uint8_t reg, uint8_t data_bytes );
359
368uint8_t barometer2_read_byte ( barometer2_t *ctx, uint8_t reg );
369
378float barometer2_get_temperature ( barometer2_t *ctx, uint8_t temp_format );
379
388
397float barometer2_get_pressure ( barometer2_t *ctx, uint8_t press_format );
398
407
408#ifdef __cplusplus
409}
410#endif
411#endif // _BAROMETER2_H_
412
413 // End public_function group
415
416// ------------------------------------------------------------------------- END
#define BAROMETER2_RETVAL
Definition barometer2.h:76
void barometer2_generic_read(barometer2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
float barometer2_get_pressure(barometer2_t *ctx, uint8_t press_format)
Read pressure function.
void barometer2_default_cfg(barometer2_t *ctx)
Click Default Configuration function.
void barometer2_cfg_setup(barometer2_cfg_t *cfg)
Config Object Initialization function.
void barometer2_generic_write(barometer2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
BAROMETER2_RETVAL barometer2_init(barometer2_t *ctx, barometer2_cfg_t *cfg)
Initialization function.
uint8_t barometer2_get_interrupt(barometer2_t *ctx)
Gets interrupt.
float barometer2_get_temperature(barometer2_t *ctx, uint8_t temp_format)
Read temperature function.
void barometer2_software_reset(barometer2_t *ctx)
Reset function.
uint8_t barometer2_read_byte(barometer2_t *ctx, uint8_t reg)
Read one byte function.
void barometer2_write_byte(barometer2_t *ctx, uint8_t reg, uint8_t data_bytes)
Write one byte function.
Click configuration structure definition.
Definition barometer2.h:268
uint32_t i2c_speed
Definition barometer2.h:280
pin_name_t scl
Definition barometer2.h:271
pin_name_t int_pin
Definition barometer2.h:276
pin_name_t sda
Definition barometer2.h:272
uint8_t i2c_address
Definition barometer2.h:281
Click ctx object definition.
Definition barometer2.h:249
digital_in_t int_pin
Definition barometer2.h:252
i2c_master_t i2c
Definition barometer2.h:256
uint8_t slave_address
Definition barometer2.h:260