airquality2 2.0.0.0
airquality2.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef AIRQUALITY2_H
36#define AIRQUALITY2_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define AIRQUALITY2_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
75#define AIRQUALITY2_RETVAL uint8_t
76
77#define AIRQUALITY2_OK 0x00
78#define AIRQUALITY2_INIT_ERROR 0xFF
85#define AIRQUALITY2_I2C_ADDRESS 0x5A
86#define AIRQUALITY2_START_READING 0xB5
93#define AIRQUALITY2_TYPE_C 0x00
94#define AIRQUALITY2_TYPE_P 0x01
95#define AIRQUALITY2_MEASUREMENT_INTERVAL_TYPE_C 1000
96#define AIRQUALITY2_MEASUREMENT_INTERVAL_TYPE_P 11000
103#define AIRQUALITY2_READ_CO2_AND_STATUS 3
104#define AIRQUALITY2_READ_ALL 9
111#define AIRQUALITY2_STATUS_OK 0x00
112#define AIRQUALITY2_STATUS_RUNIN 0x10
113#define AIRQUALITY2_STATUS_BUSY 0x01
114#define AIRQUALITY2_STATUS_ERROR 0x80
121#define AIRQUALITY2_STATUS_NOT_UPDATED_AT_ALL 0xf0
122#define AIRQUALITY2_STATUS_UPDATING 0xf1
123#define AIRQUALITY2_STATUS_I2C_REQ_FAILED 0xf2
130#define AIRQUALITY2_CO2_PREDICTION_MSB_OFFSET 0x00
131#define AIRQUALITY2_CO2_PREDICTION_LSB_OFFSET 0x01
132#define AIRQUALITY2_STATUS_OFFSET 0x02
133#define AIRQUALITY2_RESISTANCE_NULL_BYTE 0x03
134#define AIRQUALITY2_RESISTANCE_MSB_OFFSET 0x04
135#define AIRQUALITY2_RESISTANCE_MID_OFFSET 0x05
136#define AIRQUALITY2_RESISTANCE_LSB_OFFSET 0x06
137#define AIRQUALITY2_TVOC_PREDICTION_MSB_OFFSET 0x07
138#define AIRQUALITY2_TVOC_PREDICTION_LSB_OFFSET 0x08
141 // End group macro
142// --------------------------------------------------------------- PUBLIC TYPES
151typedef struct
152{
153 // Modules
154
155 i2c_master_t i2c;
156
157 // ctx variable
158
160
162
166typedef struct
167{
168 // Communication gpio pins
169
170 pin_name_t scl;
171 pin_name_t sda;
172
173 // static variable
174
175 uint32_t i2c_speed;
176 uint8_t i2c_address;
177
179
180 // End types group
181// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
182
188#ifdef __cplusplus
189extern "C"{
190#endif
191
201
211
221void airquality2_generic_read ( airquality2_t *ctx, uint8_t *data_buf, uint8_t len );
222
233uint8_t airquality2_get_all_data ( airquality2_t *ctx, uint16_t *value_co2, uint16_t *value_tvoc, int32_t *resistance );
234
235#ifdef __cplusplus
236}
237#endif
238#endif // _AIRQUALITY2_H_
239
240 // End public_function group
242
243// ------------------------------------------------------------------------- END
#define AIRQUALITY2_RETVAL
Definition airquality2.h:75
void airquality2_generic_read(airquality2_t *ctx, uint8_t *data_buf, uint8_t len)
Generic read function.
void airquality2_cfg_setup(airquality2_cfg_t *cfg)
Config Object Initialization function.
uint8_t airquality2_get_all_data(airquality2_t *ctx, uint16_t *value_co2, uint16_t *value_tvoc, int32_t *resistance)
Read all data info function.
AIRQUALITY2_RETVAL airquality2_init(airquality2_t *ctx, airquality2_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition airquality2.h:167
uint32_t i2c_speed
Definition airquality2.h:175
pin_name_t scl
Definition airquality2.h:170
pin_name_t sda
Definition airquality2.h:171
uint8_t i2c_address
Definition airquality2.h:176
Click ctx object definition.
Definition airquality2.h:152
i2c_master_t i2c
Definition airquality2.h:155
uint8_t slave_address
Definition airquality2.h:159