airquality9 2.0.0.0
airquality9.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 AIRQUALITY9_H
29#define AIRQUALITY9_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#include "spi_specifics.h"
54
75#define AIRQUALITY9_REG_PART_ID 0x00
76#define AIRQUALITY9_REG_OPMODE 0x10
77#define AIRQUALITY9_REG_CONFIG 0x11
78#define AIRQUALITY9_REG_COMMAND 0x12
79#define AIRQUALITY9_REG_TEMP_IN 0x13
80#define AIRQUALITY9_REG_RH_IN 0x15
81#define AIRQUALITY9_REG_DATA_STATUS 0x20
82#define AIRQUALITY9_REG_DATA_AQI 0x21
83#define AIRQUALITY9_REG_DATA_TVOC 0x22
84#define AIRQUALITY9_REG_DATA_ECO2 0x24
85#define AIRQUALITY9_REG_DATA_T 0x30
86#define AIRQUALITY9_REG_DATA_RH 0x32
87#define AIRQUALITY9_REG_DATA_MISR 0x38
88#define AIRQUALITY9_REG_GPR_WRITE 0x40
89#define AIRQUALITY9_REG_GPR_READ 0x48
90
91 // airquality9_reg
92
107#define AIRQUALITY9_OPMODE_DEEP_SLEEP 0x00
108#define AIRQUALITY9_OPMODE_IDLE 0x01
109#define AIRQUALITY9_OPMODE_STANDARD 0x02
110#define AIRQUALITY9_OPMODE_RESET 0xF0
111
116#define AIRQUALITY_CONFIG_INTPOL_LOW 0x00
117#define AIRQUALITY_CONFIG_INTPOL_HIGH 0x40
118#define AIRQUALITY_CONFIG_INTCFG_OPEN_DRAIN 0x00
119#define AIRQUALITY_CONFIG_INTCFG_PUSH_PULL 0x20
120#define AIRQUALITY_CONFIG_INTGPR_BIT 0x08
121#define AIRQUALITY_CONFIG_INTDAT_BIT 0x02
122#define AIRQUALITY_CONFIG_INTEN_BIT 0x01
123
128#define AIRQUALITY_STATUS_OPMODE_RUNNING 0x80
129#define AIRQUALITY_STATUS_ERROR_DETECTED 0x40
130#define AIRQUALITY_STATUS_VALID_NORMAL_OP 0x00
131#define AIRQUALITY_STATUS_VALID_WARM_UP 0x04
132#define AIRQUALITY_STATUS_VALID_INIT_START_UP 0x08
133#define AIRQUALITY_STATUS_VALID_INVALID 0x0C
134#define AIRQUALITY_STATUS_VALID_FLAG_BITS 0x0C
135#define AIRQUALITY_STATUS_NEW_DATA 0x02
136#define AIRQUALITY_STATUS_NEW_GPR 0x01
137
142#define AIRQUALITY9_PART_ID_LSB 0x60
143#define AIRQUALITY9_PART_ID_MSB 0x01
144
149#define AIRQUALITY9_AQI_UBA_EXELLENT 1
150#define AIRQUALITY9_AQI_UBA_GOOD 2
151#define AIRQUALITY9_AQI_UBA_MODERATE 3
152#define AIRQUALITY9_AQI_UBA_POOR 4
153#define AIRQUALITY9_AQI_UBA_UNHEALTHY 5
154
160#define AIRQUALITY9_DEVICE_ADDRESS_0 0x52
161#define AIRQUALITY9_DEVICE_ADDRESS_1 0x53
162
171#define AIRQUALITY9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
172#define AIRQUALITY9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
173
174 // airquality9_set
175
190#define AIRQUALITY9_MAP_MIKROBUS( cfg, mikrobus ) \
191 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
192 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
193 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
194 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
195 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
196 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
197 cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
198 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
199
200 // airquality9_map
201 // airquality9
202
213
218typedef err_t ( *airquality9_master_io_t )( struct airquality9_s*, uint8_t, uint8_t*, uint8_t );
241
246typedef struct
247{
248 pin_name_t scl;
249 pin_name_t sda;
250 pin_name_t miso;
251 pin_name_t mosi;
252 pin_name_t sck;
253 pin_name_t cs;
254 pin_name_t en;
255 pin_name_t int_pin;
257 uint32_t i2c_speed;
258 uint8_t i2c_address;
260 uint32_t spi_speed;
261 spi_master_mode_t spi_mode;
262 spi_master_chip_select_polarity_t cs_polarity;
267
278
295
311
327
342
357err_t airquality9_generic_write ( airquality9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
358
373err_t airquality9_generic_read ( airquality9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
374
384
394
404
416
431err_t airquality9_set_operating_mode ( airquality9_t *ctx, uint8_t opmode );
432
444err_t airquality9_set_interrupt_config ( airquality9_t *ctx, uint8_t int_cfg );
445
457err_t airquality9_read_status ( airquality9_t *ctx, uint8_t *status );
458
470err_t airquality9_read_aqi_uba ( airquality9_t *ctx, uint8_t *aqi_uba );
471
484err_t airquality9_read_tvoc ( airquality9_t *ctx, uint16_t *tvoc );
485
497err_t airquality9_read_eco2 ( airquality9_t *ctx, uint16_t *eco2 );
498
499#ifdef __cplusplus
500}
501#endif
502#endif // AIRQUALITY9_H
503
504 // airquality9
505
506// ------------------------------------------------------------------------ END
struct airquality9_s airquality9_t
Air Quality 9 Click context object.
airquality9_return_value_t
Air Quality 9 Click return value data.
Definition airquality9.h:273
@ AIRQUALITY9_ERROR
Definition airquality9.h:275
@ AIRQUALITY9_OK
Definition airquality9.h:274
err_t(* airquality9_master_io_t)(struct airquality9_s *, uint8_t, uint8_t *, uint8_t)
Air Quality 9 Click driver interface.
Definition airquality9.h:218
airquality9_drv_t
Air Quality 9 Click driver selector.
Definition airquality9.h:208
@ AIRQUALITY9_DRV_SEL_SPI
Definition airquality9.h:209
@ AIRQUALITY9_DRV_SEL_I2C
Definition airquality9.h:210
err_t airquality9_init(airquality9_t *ctx, airquality9_cfg_t *cfg)
Air Quality 9 initialization function.
err_t airquality9_generic_write(airquality9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Air Quality 9 data writing function.
err_t airquality9_read_tvoc(airquality9_t *ctx, uint16_t *tvoc)
Air Quality 9 read tvoc function.
err_t airquality9_set_operating_mode(airquality9_t *ctx, uint8_t opmode)
Air Quality 9 set operating mode function.
void airquality9_enable_device(airquality9_t *ctx)
Air Quality 9 enable device function.
err_t airquality9_read_status(airquality9_t *ctx, uint8_t *status)
Air Quality 9 read status function.
err_t airquality9_read_eco2(airquality9_t *ctx, uint16_t *eco2)
Air Quality 9 read eco2 function.
void airquality9_cfg_setup(airquality9_cfg_t *cfg)
Air Quality 9 configuration object setup function.
err_t airquality9_read_aqi_uba(airquality9_t *ctx, uint8_t *aqi_uba)
Air Quality 9 read aqi uba function.
err_t airquality9_set_interrupt_config(airquality9_t *ctx, uint8_t int_cfg)
Air Quality 9 set interrupt config function.
void airquality9_disable_device(airquality9_t *ctx)
Air Quality 9 disable device function.
err_t airquality9_default_cfg(airquality9_t *ctx)
Air Quality 9 default configuration function.
err_t airquality9_check_communication(airquality9_t *ctx)
Air Quality 9 check communication function.
err_t airquality9_generic_read(airquality9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Air Quality 9 data reading function.
void airquality9_drv_interface_selection(airquality9_cfg_t *cfg, airquality9_drv_t drv_sel)
Air Quality 9 driver interface setup function.
uint8_t airquality9_get_int_pin(airquality9_t *ctx)
Air Quality 9 get int pin function.
This file contains SPI specific macros, functions, etc.
Air Quality 9 Click configuration object.
Definition airquality9.h:247
uint32_t i2c_speed
Definition airquality9.h:257
spi_master_chip_select_polarity_t cs_polarity
Definition airquality9.h:262
pin_name_t sck
Definition airquality9.h:252
airquality9_drv_t drv_sel
Definition airquality9.h:264
spi_master_mode_t spi_mode
Definition airquality9.h:261
pin_name_t mosi
Definition airquality9.h:251
uint32_t spi_speed
Definition airquality9.h:260
pin_name_t scl
Definition airquality9.h:248
pin_name_t en
Definition airquality9.h:254
pin_name_t int_pin
Definition airquality9.h:255
pin_name_t miso
Definition airquality9.h:250
pin_name_t sda
Definition airquality9.h:249
pin_name_t cs
Definition airquality9.h:253
uint8_t i2c_address
Definition airquality9.h:258
Air Quality 9 Click context object.
Definition airquality9.h:225
spi_master_t spi
Definition airquality9.h:231
airquality9_master_io_t write_f
Definition airquality9.h:237
airquality9_master_io_t read_f
Definition airquality9.h:238
airquality9_drv_t drv_sel
Definition airquality9.h:235
digital_in_t int_pin
Definition airquality9.h:228
i2c_master_t i2c
Definition airquality9.h:230
digital_out_t en
Definition airquality9.h:226
uint8_t slave_address
Definition airquality9.h:233
pin_name_t chip_select
Definition airquality9.h:234