press  2.1.0.0
press.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 PRESS_H
29 #define PRESS_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 PRESS_REG_INTERRUPT_CFG 0x0B
70 #define PRESS_REG_THS_P_L 0x0C
71 #define PRESS_REG_THS_P_H 0x0D
72 #define PRESS_REG_IF_CTRL 0x0E
73 #define PRESS_REG_WHO_AM_I 0x0F
74 #define PRESS_REG_CTRL_REG1 0x10
75 #define PRESS_REG_CTRL_REG2 0x11
76 #define PRESS_REG_CTRL_REG3 0x12
77 #define PRESS_REG_FIFO_CTRL 0x14
78 #define PRESS_REG_FIFO_WTM 0x15
79 #define PRESS_REG_REF_P_L 0x16
80 #define PRESS_REG_REF_P_H 0x17
81 #define PRESS_REG_I3C_IF_CTRL 0x19
82 #define PRESS_REG_RPDS_L 0x1A
83 #define PRESS_REG_RPDS_H 0x1B
84 #define PRESS_REG_INT_SOURCE 0x24
85 #define PRESS_REG_FIFO_STATUS1 0x25
86 #define PRESS_REG_FIFO_STATUS2 0x26
87 #define PRESS_REG_STATUS 0x27
88 #define PRESS_REG_PRESSURE_OUT_XL 0x28
89 #define PRESS_REG_PRESSURE_OUT_L 0x29
90 #define PRESS_REG_PRESSURE_OUT_H 0x2A
91 #define PRESS_REG_TEMP_OUT_L 0x2B
92 #define PRESS_REG_TEMP_OUT_H 0x2C
93 #define PRESS_REG_FIFO_DATA_OUT_PRESS_XL 0x78
94 #define PRESS_REG_FIFO_DATA_OUT_PRESS_L 0x79
95 #define PRESS_REG_FIFO_DATA_OUT_PRESS_H 0x7A
96  // press_reg
98 
113 #define PRESS_WHO_AM_I 0xB4
114 
119 #define PRESS_ODR_PWR_DOWN_ONE_SHOT 0x00
120 #define PRESS_ODR_1HZ 0x08
121 #define PRESS_ODR_4HZ 0x10
122 #define PRESS_ODR_10HZ 0x18
123 #define PRESS_ODR_25HZ 0x20
124 #define PRESS_ODR_50HZ 0x28
125 #define PRESS_ODR_75HZ 0x30
126 #define PRESS_ODR_100HZ 0x38
127 #define PRESS_ODR_200HZ 0x40
128 #define PRESS_ODR_BIT_MASK 0x78
129 #define PRESS_AVG_4 0x00
130 #define PRESS_AVG_8 0x01
131 #define PRESS_AVG_16 0x02
132 #define PRESS_AVG_32 0x03
133 #define PRESS_AVG_64 0x04
134 #define PRESS_AVG_128 0x05
135 #define PRESS_AVG_512 0x07
136 #define PRESS_AVG_BIT_MASK 0x07
137 
142 #define PRESS_BOOT_NORMAL_MODE 0x00
143 #define PRESS_REBOOT_MEMORY_CONTENT 0x80
144 #define PRESS_FS_MODE_1_1260HPA 0x00
145 #define PRESS_FS_MODE_2_4060HPA 0x40
146 #define PRESS_LFPF_CFG_ODR_4 0x00
147 #define PRESS_LFPF_CFG_ODR_9 0x20
148 #define PRESS_DISABLE_LPFP 0x00
149 #define PRESS_ENABLE_LPFP 0x10
150 #define PRESS_BDU_CONTINUOUS 0x00
151 #define PRESS_BDU_MSB_LSB_READ 0x08
152 #define PRESS_SW_RESET 0x04
153 #define PRESS_ONESHOT_IDLE 0x00
154 #define PRESS_ONESHOT_NEW_DATA 0x01
155 
160 #define PRESS_REBOOT_AH_QVAR_EN 0x80
161 #define PRESS_REBOOT_AH_QVAR_DIS 0x00
162 #define PRESS_REBOOT_AH_QVAR_P_AUTO_EN 0x20
163 #define PRESS_REBOOT_AH_QVAR_P_AUTO_DIS 0x00
164 #define PRESS_REBOOT_IF_ADD_INC_EN 0x01
165 #define PRESS_REBOOT_IF_ADD_INC_DIS 0x00
166 
171 #define PRESS_TRIG_F_MODE_BYPASS 0x00
172 #define PRESS_TRIG_F_MODE_FIFO 0x01
173 #define PRESS_TRIG_F_MODE_CONT 0x02
174 #define PRESS_TRIG_F_MODE_BYPASS_FIFO 0x05
175 #define PRESS_TRIG_F_MODE_BYPASS_CONT 0x06
176 #define PRESS_TRIG_F_MODE_CONT_FIFO 0x07
177 
182 #define PRESS_STATUS_TEMP_OVERRUN 0x20
183 #define PRESS_STATUS_PRESS_OVERRUN 0x10
184 #define PRESS_STATUS_TEMP_AVAILABLE 0x02
185 #define PRESS_STATUS_PRESS_AVAILABLE 0x01
186 
191 #define PRESS_AH_QVAR_DISABLE 0x00
192 #define PRESS_AH_QVAR_ENABLE 0x01
193 
198 #define PRESS_LSB_HPA_FS_MODE_4096 4096.0f
199 #define PRESS_LSB_HPA_FS_MODE_2048 2048.0f
200 #define PRESS_TEMP_SENS 100.0f
201 #define PRESS_QVAR_GAIN_LSB_MV 426000.0f
202 
208 #define PRESS_DEVICE_ADDRESS 0x5C
209  // press_set
211 
226 #define PRESS_MAP_MIKROBUS( cfg, mikrobus ) \
227  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
228  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
229  // press_map // press
232 
237 typedef struct
238 {
239 
240  // Modules
241  i2c_master_t i2c;
243  // I2C slave address
244  uint8_t slave_address;
246 } press_t;
247 
252 typedef struct
253 {
254  pin_name_t scl;
255  pin_name_t sda;
257  uint32_t i2c_speed;
258  uint8_t i2c_address;
260 } press_cfg_t;
261 
266 typedef enum
267 {
268  PRESS_OK = 0,
269  PRESS_ERROR = -1
270 
272 
289 
303 err_t press_init ( press_t *ctx, press_cfg_t *cfg );
304 
317 err_t press_default_cfg ( press_t *ctx );
318 
334 err_t press_generic_write ( press_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
335 
351 err_t press_generic_read ( press_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
352 
367 err_t press_reg_write ( press_t *ctx, uint8_t reg, uint8_t data_in );
368 
383 err_t press_reg_read ( press_t *ctx, uint8_t reg, uint8_t *data_out );
384 
398 err_t press_sw_reset ( press_t *ctx );
399 
416 err_t press_config_ah_qvar ( press_t *ctx, uint8_t ah_qvar_en );
417 
434 err_t press_get_raw_data ( press_t *ctx, uint32_t *press_data, uint32_t *qvar_data, uint16_t *temp_data );
435 
451 err_t press_get_measurement_data ( press_t *ctx, float *pressure, float *temperature );
452 
467 err_t press_get_ah_qvar_data ( press_t *ctx, float *ah_qvar );
468 
469 #ifdef __cplusplus
470 }
471 #endif
472 #endif // PRESS_H
473  // press
475 
476 // ------------------------------------------------------------------------ END
press_t::i2c
i2c_master_t i2c
Definition: press.h:241
press_cfg_t
PRESS Click configuration object.
Definition: press.h:253
press_reg_read
err_t press_reg_read(press_t *ctx, uint8_t reg, uint8_t *data_out)
PRESS I2C register reading function.
PRESS_ERROR
@ PRESS_ERROR
Definition: press.h:269
press_return_value_t
press_return_value_t
PRESS Click return value data.
Definition: press.h:267
press_cfg_t::sda
pin_name_t sda
Definition: press.h:255
press_get_raw_data
err_t press_get_raw_data(press_t *ctx, uint32_t *press_data, uint32_t *qvar_data, uint16_t *temp_data)
PRESS gets the raw data function.
press_generic_read
err_t press_generic_read(press_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
PRESS I2C reading function.
press_cfg_t::i2c_address
uint8_t i2c_address
Definition: press.h:258
press_sw_reset
err_t press_sw_reset(press_t *ctx)
PRESS software reset function.
press_generic_write
err_t press_generic_write(press_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
PRESS I2C writing function.
press_config_ah_qvar
err_t press_config_ah_qvar(press_t *ctx, uint8_t ah_qvar_en)
PRESS config AH and Qva function.
press_reg_write
err_t press_reg_write(press_t *ctx, uint8_t reg, uint8_t data_in)
PRESS I2C register writing function.
press_cfg_setup
void press_cfg_setup(press_cfg_t *cfg)
PRESS configuration object setup function.
press_get_ah_qvar_data
err_t press_get_ah_qvar_data(press_t *ctx, float *ah_qvar)
PRESS gets the AH/Qvar data function.
press_t::slave_address
uint8_t slave_address
Definition: press.h:244
press_get_measurement_data
err_t press_get_measurement_data(press_t *ctx, float *pressure, float *temperature)
PRESS gets the measurement data function.
PRESS_OK
@ PRESS_OK
Definition: press.h:268
press_t
PRESS Click context object.
Definition: press.h:238
press_cfg_t::scl
pin_name_t scl
Definition: press.h:254
press_init
err_t press_init(press_t *ctx, press_cfg_t *cfg)
PRESS initialization function.
press_default_cfg
err_t press_default_cfg(press_t *ctx)
PRESS default configuration function.
press_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: press.h:257