barometer10  2.1.0.0
barometer10.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef BAROMETER10_H
29 #define BAROMETER10_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_in.h"
46 #include "drv_i2c_master.h"
47 
68 #define BAROMETER10_REG_INTERRUPT_CFG 0x0B
69 #define BAROMETER10_REG_THS_P_L 0x0C
70 #define BAROMETER10_REG_THS_P_H 0x0D
71 #define BAROMETER10_REG_IF_CTRL 0x0E
72 #define BAROMETER10_REG_WHO_AM_I 0x0F
73 #define BAROMETER10_REG_CTRL_REG1 0x10
74 #define BAROMETER10_REG_CTRL_REG2 0x11
75 #define BAROMETER10_REG_CTRL_REG3 0x12
76 #define BAROMETER10_REG_CTRL_REG4 0x13
77 #define BAROMETER10_REG_FIFO_CTRL 0x14
78 #define BAROMETER10_REG_FIFO_WTM 0x15
79 #define BAROMETER10_REG_REF_P_L 0x16
80 #define BAROMETER10_REG_REF_P_H 0x17
81 #define BAROMETER10_REG_I3C_IF_CTRL_ADD 0x19
82 #define BAROMETER10_REG_RPDS_L 0x1A
83 #define BAROMETER10_REG_RPDS_H 0x1B
84 #define BAROMETER10_REG_INT_SOURCE 0x24
85 #define BAROMETER10_REG_FIFO_STATUS1 0x25
86 #define BAROMETER10_REG_FIFO_STATUS2 0x26
87 #define BAROMETER10_REG_STATUS 0x27
88 #define BAROMETER10_REG_PRESS_OUT_XL 0x28
89 #define BAROMETER10_REG_PRESS_OUT_L 0x29
90 #define BAROMETER10_REG_PRESS_OUT_H 0x2A
91 #define BAROMETER10_REG_TEMP_OUT_L 0x2B
92 #define BAROMETER10_REG_TEMP_OUT_H 0x2C
93 #define BAROMETER10_REG_FIFO_DATA_OUT_PRESS_XL 0x78
94 #define BAROMETER10_REG_FIFO_DATA_OUT_PRESS_L 0x79
95 #define BAROMETER10_REG_FIFO_DATA_OUT_PRESS_H 0x7A
96  // barometer10_reg
98 
113 #define BAROMETER10_DEVICE_ID 0xB4
114 
119 #define BAROMETER10_ODR_ONE_SHOT 0x00
120 #define BAROMETER10_ODR_1_Hz 0x01
121 #define BAROMETER10_ODR_4_Hz 0x02
122 #define BAROMETER10_ODR_10_Hz 0x03
123 #define BAROMETER10_ODR_25_Hz 0x04
124 #define BAROMETER10_ODR_50_Hz 0x05
125 #define BAROMETER10_ODR_75_Hz 0x06
126 #define BAROMETER10_ODR_100_Hz 0x07
127 #define BAROMETER10_ODR_200_Hz 0x08
128 #define BAROMETER10_AVG_4 0x00
129 #define BAROMETER10_AVG_8 0x01
130 #define BAROMETER10_AVG_16 0x02
131 #define BAROMETER10_AVG_32 0x03
132 #define BAROMETER10_AVG_64 0x04
133 #define BAROMETER10_AVG_128 0x05
134 #define BAROMETER10_AVG_512 0x07
135 
140 #define BAROMETER10_FS_MODE_1260_hPa 0x00
141 #define BAROMETER10_FS_MODE_4060_hPa 0x01
142 #define BAROMETER10_LFPF_CFG_ODR4 0x00
143 #define BAROMETER10_LFPF_CFG_ODR9 0x01
144 #define BAROMETER10_EN_LPFP_DISABLE 0x00
145 #define BAROMETER10_EN_LPFP_ENABLE 0x01
146 #define BAROMETER10_BDU_CONTINUOUS_UPDATE 0x00
147 #define BAROMETER10_BDU_NO_UPDATE_UNTIL_READ 0x01
148 #define BAROMETER10_SWRESET_BIT_MASK 0x02
149 #define BAROMETER10_ONESHOT_IDLE_MODE 0x00
150 #define BAROMETER10_ONESHOT_NEW_SET_ACQUIRED 0x01
151 
156 #define BAROMETER10_INT_H_L_ACTIVE_HIGH 0x00
157 #define BAROMETER10_INT_H_L_ACTIVE_LOW 0x01
158 #define BAROMETER10_IF_ADD_INC_DISABLE 0x00
159 #define BAROMETER10_IF_ADD_INC_ENABLE 0x01
160 
165 #define BAROMETER10_DRDY_PLS_DISABLE 0x00
166 #define BAROMETER10_DRDY_PLS_ENABLE 0x01
167 #define BAROMETER10_DRDY_DISABLE 0x00
168 #define BAROMETER10_DRDY_ENABLE 0x01
169 #define BAROMETER10_INT_EN_DISABLE 0x00
170 #define BAROMETER10_INT_EN_ENABLE 0x01
171 
177 #define BAROMETER10_DEVICE_ADDRESS_GND 0x5C
178 #define BAROMETER10_DEVICE_ADDRESS_VCC 0x5D
179  // barometer10_set
181 
196 #define BAROMETER10_MAP_MIKROBUS( cfg, mikrobus ) \
197  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
198  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
199  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
200  // barometer10_map // barometer10
203 
208 typedef struct
209 {
210  // Input pins
211  digital_in_t int_pin;
213  // Modules
214  i2c_master_t i2c;
216  // I2C slave address
217  uint8_t slave_address;
219 } barometer10_t;
220 
225 typedef struct
226 {
227  pin_name_t scl;
228  pin_name_t sda;
230  pin_name_t int_pin;
232  uint32_t i2c_speed;
233  uint8_t i2c_address;
236 
241 typedef struct
242 {
243  uint8_t odr;
244  uint8_t avg;
245  uint8_t fs_mode;
246  uint8_t lfpf_cfg;
247  uint8_t en_lpfp;
248  uint8_t bdu;
249  uint8_t oneshot;
250  uint8_t int_h_l;
251  uint8_t if_add_inc;
252  uint8_t drdy_pls;
253  uint8_t drdy;
254  uint8_t int_en;
257 
262 typedef enum
263 {
265  BAROMETER10_ERROR = -1
266 
268 
285 
300 
314 
329 err_t barometer10_generic_write ( barometer10_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
330 
345 err_t barometer10_generic_read ( barometer10_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
346 
361 
376 err_t barometer10_get_device_id ( barometer10_t *ctx, uint8_t *device_id );
377 
394 
411 
426 
441 err_t barometer10_get_pressure_output ( barometer10_t *ctx, int32_t *pressure_raw );
442 
457 err_t barometer10_get_temperature_output ( barometer10_t *ctx, int16_t *temperature_raw );
458 
473 err_t barometer10_get_pressure ( barometer10_t *ctx, float *pressure );
474 
489 err_t barometer10_get_temperature ( barometer10_t *ctx, float *temperature );
490 
505 
506 #ifdef __cplusplus
507 }
508 #endif
509 #endif // BAROMETER10_H
510  // barometer10
512 
513 // ------------------------------------------------------------------------ END
barometer10_cfg_t::sda
pin_name_t sda
Definition: barometer10.h:228
barometer10_t::i2c
i2c_master_t i2c
Definition: barometer10.h:214
barometer10_sensor_cfg_t::drdy_pls
uint8_t drdy_pls
Definition: barometer10.h:252
barometer10_sensor_cfg_t::lfpf_cfg
uint8_t lfpf_cfg
Definition: barometer10.h:246
barometer10_get_temperature_output
err_t barometer10_get_temperature_output(barometer10_t *ctx, int16_t *temperature_raw)
Barometer 10 gets temperature output function.
barometer10_sensor_cfg_t::oneshot
uint8_t oneshot
Definition: barometer10.h:249
barometer10_cfg_t::i2c_address
uint8_t i2c_address
Definition: barometer10.h:233
barometer10_sensor_cfg_t::odr
uint8_t odr
Definition: barometer10.h:243
barometer10_sensor_cfg_t::fs_mode
uint8_t fs_mode
Definition: barometer10.h:245
barometer10_t::slave_address
uint8_t slave_address
Definition: barometer10.h:217
barometer10_set_config
err_t barometer10_set_config(barometer10_t *ctx, barometer10_sensor_cfg_t config)
Barometer 10 set configuration function.
barometer10_get_device_id
err_t barometer10_get_device_id(barometer10_t *ctx, uint8_t *device_id)
Barometer 10 gets device ID function.
barometer10_sensor_cfg_t::avg
uint8_t avg
Definition: barometer10.h:244
barometer10_sensor_cfg_t::drdy
uint8_t drdy
Definition: barometer10.h:253
barometer10_get_temperature
err_t barometer10_get_temperature(barometer10_t *ctx, float *temperature)
Barometer 10 gets temperature function.
barometer10_default_cfg
err_t barometer10_default_cfg(barometer10_t *ctx)
Barometer 10 default configuration function.
barometer10_cfg_t
Barometer 10 Click configuration object.
Definition: barometer10.h:226
barometer10_cfg_setup
void barometer10_cfg_setup(barometer10_cfg_t *cfg)
Barometer 10 configuration object setup function.
barometer10_get_pressure
err_t barometer10_get_pressure(barometer10_t *ctx, float *pressure)
Barometer 10 gets pressure function.
barometer10_return_value_t
barometer10_return_value_t
Barometer 10 Click return value data.
Definition: barometer10.h:263
barometer10_cfg_t::scl
pin_name_t scl
Definition: barometer10.h:227
barometer10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: barometer10.h:232
barometer10_sensor_cfg_t
Barometer 10 Click sensor configuration object.
Definition: barometer10.h:242
barometer10_get_pressure_output
err_t barometer10_get_pressure_output(barometer10_t *ctx, int32_t *pressure_raw)
Barometer 10 gets pressure output function.
barometer10_init
err_t barometer10_init(barometer10_t *ctx, barometer10_cfg_t *cfg)
Barometer 10 initialization function.
barometer10_sw_reset
err_t barometer10_sw_reset(barometer10_t *ctx)
Barometer 10 software reset function.
barometer10_sensor_cfg_t::int_en
uint8_t int_en
Definition: barometer10.h:254
BAROMETER10_OK
@ BAROMETER10_OK
Definition: barometer10.h:264
BAROMETER10_ERROR
@ BAROMETER10_ERROR
Definition: barometer10.h:265
barometer10_get_config
err_t barometer10_get_config(barometer10_t *ctx, barometer10_sensor_cfg_t *config)
Barometer 10 gets configuration function.
barometer10_t::int_pin
digital_in_t int_pin
Definition: barometer10.h:211
barometer10_sensor_cfg_t::bdu
uint8_t bdu
Definition: barometer10.h:248
barometer10_sensor_cfg_t::if_add_inc
uint8_t if_add_inc
Definition: barometer10.h:251
barometer10_cfg_t::int_pin
pin_name_t int_pin
Definition: barometer10.h:230
barometer10_sensor_cfg_t::en_lpfp
uint8_t en_lpfp
Definition: barometer10.h:247
barometer10_t
Barometer 10 Click context object.
Definition: barometer10.h:209
barometer10_get_int_pin
uint8_t barometer10_get_int_pin(barometer10_t *ctx)
Barometer 10 gets interrupt function.
barometer10_trigger_one_shot
err_t barometer10_trigger_one_shot(barometer10_t *ctx)
Barometer 10 trigger one-shot function.
barometer10_generic_write
err_t barometer10_generic_write(barometer10_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Barometer 10 I2C writing function.
barometer10_sensor_cfg_t::int_h_l
uint8_t int_h_l
Definition: barometer10.h:250
barometer10_generic_read
err_t barometer10_generic_read(barometer10_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Barometer 10 I2C reading function.