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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define AIRQUALITY2_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
65 
71 #define AIRQUALITY2_RETVAL uint8_t
72 
73 #define AIRQUALITY2_OK 0x00
74 #define AIRQUALITY2_INIT_ERROR 0xFF
75 
81 #define AIRQUALITY2_I2C_ADDRESS 0x5A
82 #define AIRQUALITY2_START_READING 0xB5
83 
89 #define AIRQUALITY2_TYPE_C 0x00
90 #define AIRQUALITY2_TYPE_P 0x01
91 #define AIRQUALITY2_MEASUREMENT_INTERVAL_TYPE_C 1000
92 #define AIRQUALITY2_MEASUREMENT_INTERVAL_TYPE_P 11000
93 
99 #define AIRQUALITY2_READ_CO2_AND_STATUS 3
100 #define AIRQUALITY2_READ_ALL 9
101 
107 #define AIRQUALITY2_STATUS_OK 0x00
108 #define AIRQUALITY2_STATUS_RUNIN 0x10
109 #define AIRQUALITY2_STATUS_BUSY 0x01
110 #define AIRQUALITY2_STATUS_ERROR 0x80
111 
117 #define AIRQUALITY2_STATUS_NOT_UPDATED_AT_ALL 0xf0
118 #define AIRQUALITY2_STATUS_UPDATING 0xf1
119 #define AIRQUALITY2_STATUS_I2C_REQ_FAILED 0xf2
120 
126 #define AIRQUALITY2_CO2_PREDICTION_MSB_OFFSET 0x00
127 #define AIRQUALITY2_CO2_PREDICTION_LSB_OFFSET 0x01
128 #define AIRQUALITY2_STATUS_OFFSET 0x02
129 #define AIRQUALITY2_RESISTANCE_NULL_BYTE 0x03
130 #define AIRQUALITY2_RESISTANCE_MSB_OFFSET 0x04
131 #define AIRQUALITY2_RESISTANCE_MID_OFFSET 0x05
132 #define AIRQUALITY2_RESISTANCE_LSB_OFFSET 0x06
133 #define AIRQUALITY2_TVOC_PREDICTION_MSB_OFFSET 0x07
134 #define AIRQUALITY2_TVOC_PREDICTION_LSB_OFFSET 0x08
135  // End group macro
138 // --------------------------------------------------------------- PUBLIC TYPES
147 typedef struct
148 {
149  // Modules
150 
151  i2c_master_t i2c;
152 
153  // ctx variable
154 
155  uint8_t slave_address;
156 
157 } airquality2_t;
158 
162 typedef struct
163 {
164  // Communication gpio pins
165 
166  pin_name_t scl;
167  pin_name_t sda;
168 
169  // static variable
170 
171  uint32_t i2c_speed;
172  uint8_t i2c_address;
173 
175  // End types group
177 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
178 
184 #ifdef __cplusplus
185 extern "C"{
186 #endif
187 
197 
207 
217 void airquality2_generic_read ( airquality2_t *ctx, uint8_t *data_buf, uint8_t len );
218 
229 uint8_t airquality2_get_all_data ( airquality2_t *ctx, uint16_t *value_co2, uint16_t *value_tvoc, int32_t *resistance );
230 
231 #ifdef __cplusplus
232 }
233 #endif
234 #endif // _AIRQUALITY2_H_
235  // End public_function group
238 
239 // ------------------------------------------------------------------------- END
airquality2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: airquality2.h:171
airquality2_generic_read
void airquality2_generic_read(airquality2_t *ctx, uint8_t *data_buf, uint8_t len)
Generic read function.
airquality2_t::i2c
i2c_master_t i2c
Definition: airquality2.h:151
airquality2_cfg_setup
void airquality2_cfg_setup(airquality2_cfg_t *cfg)
Config Object Initialization function.
airquality2_t
Click ctx object definition.
Definition: airquality2.h:148
airquality2_cfg_t::i2c_address
uint8_t i2c_address
Definition: airquality2.h:172
AIRQUALITY2_RETVAL
#define AIRQUALITY2_RETVAL
Definition: airquality2.h:71
airquality2_cfg_t::scl
pin_name_t scl
Definition: airquality2.h:166
airquality2_init
AIRQUALITY2_RETVAL airquality2_init(airquality2_t *ctx, airquality2_cfg_t *cfg)
Initialization function.
airquality2_cfg_t::sda
pin_name_t sda
Definition: airquality2.h:167
airquality2_cfg_t
Click configuration structure definition.
Definition: airquality2.h:163
airquality2_get_all_data
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_t::slave_address
uint8_t slave_address
Definition: airquality2.h:155