airquality8 2.0.0.0
airquality8.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 AIRQUALITY8_H
29#define AIRQUALITY8_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
62#define AIRQUALITY8_REG_PID 0x00
63#define AIRQUALITY8_REG_CONF 0x20
64#define AIRQUALITY8_REG_PROD_DATA 0x26
65#define AIRQUALITY8_REG_CMD 0x93
66#define AIRQUALITY8_REG_STATUS 0x94
67#define AIRQUALITY8_REG_TRACKING 0x3A
68
69#define AIRQUALITY8_REG_CFG_H 0x40
70#define AIRQUALITY8_REG_CFG_D 0x50
71#define AIRQUALITY8_REG_CFG_M 0x60
72#define AIRQUALITY8_REG_CFG_S 0x68
73#define AIRQUALITY8_REG_CFG_R 0x97
74
75 // airquality8_reg
76
91#define AIRQUALITY8_PRODUCT_ID 0x6320
92
97#define AIRQUALITY8_GAS_DETECTION_STRATEGY_AUTO 0
98#define AIRQUALITY8_GAS_DETECTION_STRATEGY_FORCE_O3 1
99#define AIRQUALITY8_GAS_DETECTION_STRATEGY_FORCE_NO2 2
100
105#define AIRQUALITY8_RCDA_STRATEGY_FIX 0
106#define AIRQUALITY8_RCDA_STRATEGY_SET 1
107#define AIRQUALITY8_RCDA_STRATEGY_ADJ 2
108
113#define AIRQUALITY8_STATUS_SEQUENCER_RUNNING_MASK 0x80
114#define AIRQUALITY8_STATUS_SLEEP_TIMER_ENABLED_MASK 0x40
115#define AIRQUALITY8_STATUS_ALARM_MASK 0x20
116#define AIRQUALITY8_STATUS_LAST_SEQ_STEP_MASK 0x1F
117#define AIRQUALITY8_STATUS_POR_EVENT_MASK 0x80
118#define AIRQUALITY8_STATUS_ACCESS_CONFLICT_MASK 0x40
119
125#define AIRQUALITY8_SET_DEV_ADDR 0x33
126
127 // airquality8_set
128
143#define AIRQUALITY8_MAP_MIKROBUS( cfg, mikrobus ) \
144 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
145 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
146 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
147
148 // airquality8_map
149 // airquality8
150
155typedef struct
156{
157 // Output pins
158 digital_out_t rst;
160 // Input pins
161 digital_in_t int_pin;
163 // Modules
164 i2c_master_t i2c;
166 // I2C slave address
170
175typedef struct
176{
177 pin_name_t scl;
178 pin_name_t sda;
180 pin_name_t rst;
181 pin_name_t int_pin;
183 uint32_t i2c_speed;
184 uint8_t i2c_address;
187
206
223
239
254
270err_t airquality8_generic_write ( airquality8_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
271
287err_t airquality8_generic_read ( airquality8_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
288
301
316err_t airquality8_get_status ( airquality8_t *ctx, uint8_t *status );
317
342err_t airquality8_get_sensor_info ( airquality8_t *ctx, uint8_t *cfg_data, uint8_t *prod_data, uint16_t *pid );
343
367err_t airquality8_init_sensor ( airquality8_t *ctx, uint16_t *mox_lr, uint16_t *mox_er );
368
391
406
431err_t airquality8_read_rmox ( airquality8_t *ctx, float *rmox, uint16_t mox_lr, uint16_t mox_er );
432
451float airquality8_calc_oaq ( float *rmox, uint8_t rcda_strategy, uint8_t gas_detection_strategy );
452
466
467#ifdef __cplusplus
468}
469#endif
470#endif // AIRQUALITY8_H
471
472 // airquality8
473
474// ------------------------------------------------------------------------ END
airquality8_return_value_t
Air Quality 8 Click return value data.
Definition airquality8.h:193
@ AIRQUALITY8_ERROR_GAS_TIMEOUT
Definition airquality8.h:197
@ AIRQUALITY8_ERROR
Definition airquality8.h:195
@ AIRQUALITY8_ERROR_POR_EVENT
Definition airquality8.h:203
@ AIRQUALITY8_ERROR_SENSOR_UNSUPPORTED
Definition airquality8.h:199
@ AIRQUALITY8_ERROR_INIT_OUT_OF_RANGE
Definition airquality8.h:196
@ AIRQUALITY8_ERROR_CONFIG_MISSING
Definition airquality8.h:200
@ AIRQUALITY8_ERROR_ACCESS_CONFLICT
Definition airquality8.h:202
@ AIRQUALITY8_ERROR_I2C
Definition airquality8.h:198
@ AIRQUALITY8_OK
Definition airquality8.h:194
@ AIRQUALITY8_ERROR_SENSOR
Definition airquality8.h:201
float airquality8_calc_oaq(float *rmox, uint8_t rcda_strategy, uint8_t gas_detection_strategy)
Air Quality 8 calculates AQI function.
err_t airquality8_read_rmox(airquality8_t *ctx, float *rmox, uint16_t mox_lr, uint16_t mox_er)
Air Quality 8 calculate rmox resistance function.
err_t airquality8_default_cfg(airquality8_t *ctx)
Air Quality 8 default configuration function.
err_t airquality8_generic_write(airquality8_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Air Quality 8 I2C writing function.
err_t airquality8_start_measurement(airquality8_t *ctx)
Air Quality 8 start measurement function.
err_t airquality8_get_sensor_info(airquality8_t *ctx, uint8_t *cfg_data, uint8_t *prod_data, uint16_t *pid)
Air Quality 8 get sensor info function.
err_t airquality8_init_measurement(airquality8_t *ctx)
Air Quality 8 init measurement function.
void airquality8_hw_reset(airquality8_t *ctx)
Air Quality 8 reset function.
err_t airquality8_get_status(airquality8_t *ctx, uint8_t *status)
Air Quality 8 get status function.
err_t airquality8_init_sensor(airquality8_t *ctx, uint16_t *mox_lr, uint16_t *mox_er)
Air Quality 8 init sensor function.
void airquality8_cfg_setup(airquality8_cfg_t *cfg)
Air Quality 8 configuration object setup function.
err_t airquality8_generic_read(airquality8_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Air Quality 8 I2C reading function.
err_t airquality8_init(airquality8_t *ctx, airquality8_cfg_t *cfg)
Air Quality 8 initialization function.
uint8_t raq_check_interrupt(airquality8_t *ctx)
Air Quality 8 check interrupt function.
Air Quality 8 Click configuration object.
Definition airquality8.h:176
uint32_t i2c_speed
Definition airquality8.h:183
pin_name_t scl
Definition airquality8.h:177
pin_name_t int_pin
Definition airquality8.h:181
pin_name_t sda
Definition airquality8.h:178
pin_name_t rst
Definition airquality8.h:180
uint8_t i2c_address
Definition airquality8.h:184
Air Quality 8 Click context object.
Definition airquality8.h:156
digital_in_t int_pin
Definition airquality8.h:161
i2c_master_t i2c
Definition airquality8.h:164
digital_out_t rst
Definition airquality8.h:158
uint8_t slave_address
Definition airquality8.h:167