airflow 2.0.0.0
airflow.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 AIRFLOW_H
29#define AIRFLOW_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
53
74#define AIRFLOW_I2C_CMD_RESET 0x11
75#define AIRFLOW_I2C_CMD_GET_SIG 0x23
76#define AIRFLOW_I2C_CMD_GET_DATA 0x26
77#define AIRFLOW_I2C_CMD_CONV 0x27
78#define AIRFLOW_I2C_CMD_GET_NON_BAR 0x50
79#define AIRFLOW_I2C_CMD_GET_NON_BLOCK_BAR 0x51
84#define AIRFLOW_SPI_CMD_NONE 0x00
85#define AIRFLOW_SPI_CMD_RESET 0x01
86#define AIRFLOW_SPI_CMD_CONV 0x04
87#define AIRFLOW_SPI_CMD_STOP 0x05
88#define AIRFLOW_SPI_CMD_GET_DATA 0x06
89#define AIRFLOW_SPI_CMD_GET_BAR 0x07
90#define AIRFLOW_SPI_CMD_GET_SIG 0x0C
91
92 // airflow_reg
93
108#define AIRFLOW_NO_BAROMETRIC_CORRECTION 0x01
109#define AIRFLOW_BAROMETRIC_CORRECTION 0x03
110
116#define AIRFLOW_SET_DEV_ADDR 0x5B
117
118 // airflow_set
119
134#define AIRFLOW_MAP_MIKROBUS( cfg, mikrobus ) \
135 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
136 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
137 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
138 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
139 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
140 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
141 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
142
143 // airflow_map
144 // airflow
145
156
161typedef err_t ( *airflow_master_io_t )( struct airflow_s*, uint8_t, uint8_t*, uint8_t );
167typedef struct airflow_s
168{
169 digital_in_t rdy;
171 i2c_master_t i2c;
172 spi_master_t spi;
175 pin_name_t chip_select;
183 char part_number[ 12 ];
184 char lot_number[ 8 ];
187 uint16_t scale_factor;
188 char calibration_id[ 3 ];
189 uint8_t week;
190 uint8_t year;
192
194
199typedef struct
200{
201 pin_name_t scl;
202 pin_name_t sda;
203 pin_name_t miso;
204 pin_name_t mosi;
205 pin_name_t sck;
206 pin_name_t cs;
207 pin_name_t rdy;
209 uint32_t i2c_speed;
210 uint8_t i2c_address;
212 uint32_t spi_speed;
213 spi_master_mode_t spi_mode;
214 spi_master_chip_select_polarity_t cs_polarity;
219
224typedef enum
225{
227 AIRFLOW_ERROR = -1
228
230
247
263
279
294
309err_t airflow_generic_write ( airflow_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
310
325err_t airflow_generic_read ( airflow_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
326
336
346
358err_t airflow_get_differential_pressure ( airflow_t *ctx, float *pressure );
359
372err_t airflow_get_atmospheric_pressure ( airflow_t *ctx, float *pressure, float *temperature );
373
386err_t airflow_get_status ( airflow_t *ctx, uint8_t *status );
387
388#ifdef __cplusplus
389}
390#endif
391#endif // AIRFLOW_H
392
393 // airflow
394
395// ------------------------------------------------------------------------ END
airflow_drv_t
Air Flow Click driver selector.
Definition airflow.h:151
@ AIRFLOW_DRV_SEL_I2C
Definition airflow.h:153
@ AIRFLOW_DRV_SEL_SPI
Definition airflow.h:152
err_t(* airflow_master_io_t)(struct airflow_s *, uint8_t, uint8_t *, uint8_t)
Air Flow Click driver interface.
Definition airflow.h:161
airflow_return_value_t
Air Flow Click return value data.
Definition airflow.h:225
@ AIRFLOW_OK
Definition airflow.h:226
@ AIRFLOW_ERROR
Definition airflow.h:227
struct airflow_s airflow_t
Air Flow Click context object.
void airflow_reset_device(airflow_t *ctx)
Reset device.
err_t airflow_get_status(airflow_t *ctx, uint8_t *status)
Reads status data.
err_t airflow_generic_write(airflow_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Air Flow data writing function.
err_t airflow_get_differential_pressure(airflow_t *ctx, float *pressure)
Reads differential pressure.
err_t airflow_default_cfg(airflow_t *ctx)
Air Flow default configuration function.
void airflow_drv_interface_selection(airflow_cfg_t *cfg, airflow_drv_t drv_sel)
Air Flow driver interface setup function.
err_t airflow_init(airflow_t *ctx, airflow_cfg_t *cfg)
Air Flow initialization function.
err_t airflow_get_atmospheric_pressure(airflow_t *ctx, float *pressure, float *temperature)
Reads atmospheric pressure and temperature.
uint8_t airflow_check_ready(airflow_t *ctx)
Reads ready pin state.
void airflow_cfg_setup(airflow_cfg_t *cfg)
Air Flow configuration object setup function.
err_t airflow_generic_read(airflow_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Air Flow data reading function.
Air Flow Click configuration object.
Definition airflow.h:200
uint32_t i2c_speed
Definition airflow.h:209
airflow_drv_t drv_sel
Definition airflow.h:216
spi_master_chip_select_polarity_t cs_polarity
Definition airflow.h:214
pin_name_t sck
Definition airflow.h:205
spi_master_mode_t spi_mode
Definition airflow.h:213
pin_name_t mosi
Definition airflow.h:204
uint32_t spi_speed
Definition airflow.h:212
pin_name_t scl
Definition airflow.h:201
pin_name_t rdy
Definition airflow.h:207
pin_name_t miso
Definition airflow.h:203
pin_name_t sda
Definition airflow.h:202
pin_name_t cs
Definition airflow.h:206
uint8_t i2c_address
Definition airflow.h:210
Air Flow Click context object.
Definition airflow.h:168
spi_master_t spi
Definition airflow.h:172
uint8_t major_fw_ver
Definition airflow.h:181
char output_type
Definition airflow.h:186
uint16_t pressure_range
Definition airflow.h:185
uint8_t minor_fw_ver
Definition airflow.h:182
uint8_t week
Definition airflow.h:189
airflow_drv_t drv_sel
Definition airflow.h:176
char lot_number[8]
Definition airflow.h:184
uint8_t year
Definition airflow.h:190
char calibration_id[3]
Definition airflow.h:188
char part_number[12]
Definition airflow.h:183
i2c_master_t i2c
Definition airflow.h:171
airflow_master_io_t write_f
Definition airflow.h:178
uint16_t scale_factor
Definition airflow.h:187
airflow_master_io_t read_f
Definition airflow.h:179
uint8_t slave_address
Definition airflow.h:174
uint16_t sequence_number
Definition airflow.h:191
pin_name_t chip_select
Definition airflow.h:175
digital_in_t rdy
Definition airflow.h:169