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
32 extern "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
80 
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  // 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  // 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  // airflow_map // airflow
145 
150 typedef enum
151 {
156 
161 typedef err_t ( *airflow_master_io_t )( struct airflow_s*, uint8_t, uint8_t*, uint8_t );
167 typedef struct airflow_s
168 {
169  digital_in_t rdy;
171  i2c_master_t i2c;
172  spi_master_t spi;
174  uint8_t slave_address;
175  pin_name_t chip_select;
181  uint8_t major_fw_ver;
182  uint8_t minor_fw_ver;
183  char part_number[ 12 ];
184  char lot_number[ 8 ];
185  uint16_t pressure_range;
187  uint16_t scale_factor;
188  char calibration_id[ 3 ];
189  uint8_t week;
190  uint8_t year;
191  uint16_t sequence_number;
192 
194 
199 typedef 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;
218 } airflow_cfg_t;
219 
224 typedef enum
225 {
227  AIRFLOW_ERROR = -1
228 
230 
247 
263 
278 err_t airflow_init ( airflow_t *ctx, airflow_cfg_t *cfg );
279 
294 
309 err_t airflow_generic_write ( airflow_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
310 
325 err_t airflow_generic_read ( airflow_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
326 
336 
346 
358 err_t airflow_get_differential_pressure ( airflow_t *ctx, float *pressure );
359 
372 err_t airflow_get_atmospheric_pressure ( airflow_t *ctx, float *pressure, float *temperature );
373 
386 err_t airflow_get_status ( airflow_t *ctx, uint8_t *status );
387 
388 #ifdef __cplusplus
389 }
390 #endif
391 #endif // AIRFLOW_H
392  // airflow
394 
395 // ------------------------------------------------------------------------ END
airflow_s
Air Flow Click context object.
Definition: airflow.h:168
airflow_s::calibration_id
char calibration_id[3]
Definition: airflow.h:188
AIRFLOW_DRV_SEL_SPI
@ AIRFLOW_DRV_SEL_SPI
Definition: airflow.h:152
airflow_cfg_t::miso
pin_name_t miso
Definition: airflow.h:203
airflow_cfg_t::sck
pin_name_t sck
Definition: airflow.h:205
airflow_generic_write
err_t airflow_generic_write(airflow_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Air Flow data writing function.
airflow_s::output_type
char output_type
Definition: airflow.h:186
airflow_s::pressure_range
uint16_t pressure_range
Definition: airflow.h:185
airflow_s::part_number
char part_number[12]
Definition: airflow.h:183
airflow_s::spi
spi_master_t spi
Definition: airflow.h:172
airflow_master_io_t
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_get_differential_pressure
err_t airflow_get_differential_pressure(airflow_t *ctx, float *pressure)
Reads differential pressure.
airflow_cfg_t::rdy
pin_name_t rdy
Definition: airflow.h:207
airflow_cfg_setup
void airflow_cfg_setup(airflow_cfg_t *cfg)
Air Flow configuration object setup function.
airflow_t
struct airflow_s airflow_t
Air Flow Click context object.
airflow_s::major_fw_ver
uint8_t major_fw_ver
Definition: airflow.h:181
airflow_s::year
uint8_t year
Definition: airflow.h:190
airflow_cfg_t::scl
pin_name_t scl
Definition: airflow.h:201
airflow_s::write_f
airflow_master_io_t write_f
Definition: airflow.h:178
airflow_s::scale_factor
uint16_t scale_factor
Definition: airflow.h:187
AIRFLOW_DRV_SEL_I2C
@ AIRFLOW_DRV_SEL_I2C
Definition: airflow.h:153
airflow_s::week
uint8_t week
Definition: airflow.h:189
airflow_s::slave_address
uint8_t slave_address
Definition: airflow.h:174
airflow_generic_read
err_t airflow_generic_read(airflow_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Air Flow data reading function.
airflow_cfg_t::spi_speed
uint32_t spi_speed
Definition: airflow.h:212
airflow_cfg_t
Air Flow Click configuration object.
Definition: airflow.h:200
airflow_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: airflow.h:213
airflow_s::lot_number
char lot_number[8]
Definition: airflow.h:184
airflow_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: airflow.h:209
AIRFLOW_ERROR
@ AIRFLOW_ERROR
Definition: airflow.h:227
AIRFLOW_OK
@ AIRFLOW_OK
Definition: airflow.h:226
airflow_drv_t
airflow_drv_t
Air Flow Click driver selector.
Definition: airflow.h:151
airflow_cfg_t::sda
pin_name_t sda
Definition: airflow.h:202
airflow_drv_interface_selection
void airflow_drv_interface_selection(airflow_cfg_t *cfg, airflow_drv_t drv_sel)
Air Flow driver interface setup function.
airflow_s::minor_fw_ver
uint8_t minor_fw_ver
Definition: airflow.h:182
airflow_cfg_t::mosi
pin_name_t mosi
Definition: airflow.h:204
airflow_get_status
err_t airflow_get_status(airflow_t *ctx, uint8_t *status)
Reads status data.
airflow_s::chip_select
pin_name_t chip_select
Definition: airflow.h:175
airflow_cfg_t::i2c_address
uint8_t i2c_address
Definition: airflow.h:210
airflow_s::i2c
i2c_master_t i2c
Definition: airflow.h:171
airflow_return_value_t
airflow_return_value_t
Air Flow Click return value data.
Definition: airflow.h:225
airflow_check_ready
uint8_t airflow_check_ready(airflow_t *ctx)
Reads ready pin state.
airflow_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: airflow.h:214
airflow_init
err_t airflow_init(airflow_t *ctx, airflow_cfg_t *cfg)
Air Flow initialization function.
airflow_default_cfg
err_t airflow_default_cfg(airflow_t *ctx)
Air Flow default configuration function.
airflow_cfg_t::drv_sel
airflow_drv_t drv_sel
Definition: airflow.h:216
airflow_s::sequence_number
uint16_t sequence_number
Definition: airflow.h:191
airflow_get_atmospheric_pressure
err_t airflow_get_atmospheric_pressure(airflow_t *ctx, float *pressure, float *temperature)
Reads atmospheric pressure and temperature.
airflow_reset_device
void airflow_reset_device(airflow_t *ctx)
Reset device.
airflow_s::rdy
digital_in_t rdy
Definition: airflow.h:169
airflow_cfg_t::cs
pin_name_t cs
Definition: airflow.h:206
airflow_s::read_f
airflow_master_io_t read_f
Definition: airflow.h:179
airflow_s::drv_sel
airflow_drv_t drv_sel
Definition: airflow.h:176