barometer4  2.0.0.0
barometer4.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 BAROMETER4_H
29 #define BAROMETER4_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_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define BAROMETER4_CMD_OP_MODE_T_FIRST_LOW_POWER 0x609C
70 #define BAROMETER4_CMD_OP_MODE_T_FIRST_NORMAL 0x6825
71 #define BAROMETER4_CMD_OP_MODE_T_FIRST_LOW_NOISE 0x70DF
72 #define BAROMETER4_CMD_OP_MODE_T_FIRST_ULTRA_LOW_NOISE 0x7866
73 #define BAROMETER4_CMD_OP_MODE_P_FIRST_LOW_POWER 0x401A
74 #define BAROMETER4_CMD_OP_MODE_P_FIRST_NORMAL 0x48A3
75 #define BAROMETER4_CMD_OP_MODE_P_FIRST_LOW_NOISE 0x5059
76 #define BAROMETER4_CMD_OP_MODE_P_FIRST_ULTRA_LOW_NOISE 0x58E0
77 #define BAROMETER4_CMD_SOFT_RESET 0x805D
78 #define BAROMETER4_CMD_DEVICE_ID 0xEFC8
79 #define BAROMETER4_CMD_READ_OTP 0xC7F7
80  // barometer4_cmd
82 
97 #define BAROMETER4_OP_MODE_LOW_POWER 0
98 #define BAROMETER4_OP_MODE_NORMAL 1
99 #define BAROMETER4_OP_MODE_LOW_NOISE 2
100 #define BAROMETER4_OP_MODE_ULTRA_LOW_NOISE 3
101 
107 #define BAROMETER4_SET_DEV_ADDR 0x63
108  // barometer4_set
110 
125 #define BAROMETER4_MAP_MIKROBUS( cfg, mikrobus ) \
126  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
127  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
128  // barometer4_map // barometer4
131 
136 typedef struct
137 {
138  // Modules
139  i2c_master_t i2c;
141  // I2C slave address
142  uint8_t slave_address;
144 } barometer4_t;
145 
150 typedef struct
151 {
152  pin_name_t scl;
153  pin_name_t sda;
155  uint32_t i2c_speed;
156  uint8_t i2c_address;
159 
166 typedef struct
167 {
168  uint16_t op_mode;
169  float sensor_constants[ 4 ];
170  float p_pa_calib[ 3 ];
171  float lut_lower;
172  float lut_upper;
175 
177 
182 typedef enum
183 {
185  BAROMETER4_ERROR = -1
186 
188 
205 
221 
236 
252 err_t barometer4_generic_write ( barometer4_t *ctx, uint16_t cmd, uint8_t *tx_buf, uint8_t tx_len );
253 
269 err_t barometer4_generic_read ( barometer4_t *ctx, uint16_t cmd, uint16_t *rx_buf, uint8_t rx_len );
270 
285 err_t barometer4_set_command ( barometer4_t *ctx, uint16_t cmd ) ;
286 
301 
316 err_t barometer4_get_device_id ( barometer4_t *ctx, uint16_t *device_id );
317 
332 
347 err_t barometer4_get_otp ( barometer4_t *ctx, uint16_t *otp_data );
348 
364 
381 err_t barometer4_get_raw_data ( barometer4_t *ctx, uint16_t measurement_comd, uint32_t *pressure, uint16_t *temperature );
382 
398 err_t barometer4_get_pressure_and_temperature ( barometer4_t *ctx, float *pressure, float *temperature );
399 
400 #ifdef __cplusplus
401 }
402 #endif
403 #endif // BAROMETER4_H
404  // barometer4
406 
407 // ------------------------------------------------------------------------ END
barometer4_cfg_t::sda
pin_name_t sda
Definition: barometer4.h:153
barometer4_t
Barometer 4 Click context object.
Definition: barometer4.h:137
barometer4_generic_write
err_t barometer4_generic_write(barometer4_t *ctx, uint16_t cmd, uint8_t *tx_buf, uint8_t tx_len)
Barometer 4 I2C writing function.
barometer4_soft_reset
err_t barometer4_soft_reset(barometer4_t *ctx)
Barometer 4 software reset function.
barometer4_cfg_t
Barometer 4 Click configuration object.
Definition: barometer4.h:151
barometer4_default_cfg
err_t barometer4_default_cfg(barometer4_t *ctx)
Barometer 4 default configuration function.
barometer4_inv_invpres_calibration
err_t barometer4_inv_invpres_calibration(barometer4_t *ctx, barometer4_invpres_t *cfg_data)
Barometer 4 inverse process data function.
barometer4_invpres_t::lut_lower
float lut_lower
Definition: barometer4.h:171
barometer4_return_value_t
barometer4_return_value_t
Barometer 4 Click return value data.
Definition: barometer4.h:183
barometer4_invpres_t::lut_upper
float lut_upper
Definition: barometer4.h:172
barometer4_get_device_id
err_t barometer4_get_device_id(barometer4_t *ctx, uint16_t *device_id)
Barometer 4 get device ID function.
barometer4_invpres_t::offst_factor
float offst_factor
Definition: barometer4.h:174
barometer4_t::slave_address
uint8_t slave_address
Definition: barometer4.h:142
barometer4_set_up_otp_read
err_t barometer4_set_up_otp_read(barometer4_t *ctx)
Barometer 4 set up OTP read function.
barometer4_invpres_t::quadr_factor
float quadr_factor
Definition: barometer4.h:173
BAROMETER4_OK
@ BAROMETER4_OK
Definition: barometer4.h:184
barometer4_get_otp
err_t barometer4_get_otp(barometer4_t *ctx, uint16_t *otp_data)
Barometer 4 get OTP function.
barometer4_init
err_t barometer4_init(barometer4_t *ctx, barometer4_cfg_t *cfg)
Barometer 4 initialization function.
barometer4_cfg_t::i2c_address
uint8_t i2c_address
Definition: barometer4.h:156
barometer4_invpres_t
Barometer 4 Click structure to hold pressure sensor related parameters object.
Definition: barometer4.h:167
barometer4_set_command
err_t barometer4_set_command(barometer4_t *ctx, uint16_t cmd)
Barometer 4 set command function.
barometer4_cfg_setup
void barometer4_cfg_setup(barometer4_cfg_t *cfg)
Barometer 4 configuration object setup function.
barometer4_get_raw_data
err_t barometer4_get_raw_data(barometer4_t *ctx, uint16_t measurement_comd, uint32_t *pressure, uint16_t *temperature)
Barometer 4 get RAW data function.
barometer4_t::i2c
i2c_master_t i2c
Definition: barometer4.h:139
barometer4_generic_read
err_t barometer4_generic_read(barometer4_t *ctx, uint16_t cmd, uint16_t *rx_buf, uint8_t rx_len)
Barometer 4 I2C reading function.
barometer4_get_pressure_and_temperature
err_t barometer4_get_pressure_and_temperature(barometer4_t *ctx, float *pressure, float *temperature)
Barometer 4 get pressure and temperature function.
BAROMETER4_ERROR
@ BAROMETER4_ERROR
Definition: barometer4.h:185
barometer4_invpres_t::op_mode
uint16_t op_mode
Definition: barometer4.h:168
barometer4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: barometer4.h:155
barometer4_cfg_t::scl
pin_name_t scl
Definition: barometer4.h:152