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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define AIRQUALITY2_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
55 
61 #define AIRQUALITY2_RETVAL uint8_t
62 
63 #define AIRQUALITY2_OK 0x00
64 #define AIRQUALITY2_INIT_ERROR 0xFF
65 
71 #define AIRQUALITY2_I2C_ADDRESS 0x5A
72 #define AIRQUALITY2_START_READING 0xB5
73 
79 #define AIRQUALITY2_TYPE_C 0x00
80 #define AIRQUALITY2_TYPE_P 0x01
81 #define AIRQUALITY2_MEASUREMENT_INTERVAL_TYPE_C 1000
82 #define AIRQUALITY2_MEASUREMENT_INTERVAL_TYPE_P 11000
83 
89 #define AIRQUALITY2_READ_CO2_AND_STATUS 3
90 #define AIRQUALITY2_READ_ALL 9
91 
97 #define AIRQUALITY2_STATUS_OK 0x00
98 #define AIRQUALITY2_STATUS_RUNIN 0x10
99 #define AIRQUALITY2_STATUS_BUSY 0x01
100 #define AIRQUALITY2_STATUS_ERROR 0x80
101 
107 #define AIRQUALITY2_STATUS_NOT_UPDATED_AT_ALL 0xf0
108 #define AIRQUALITY2_STATUS_UPDATING 0xf1
109 #define AIRQUALITY2_STATUS_I2C_REQ_FAILED 0xf2
110 
116 #define AIRQUALITY2_CO2_PREDICTION_MSB_OFFSET 0x00
117 #define AIRQUALITY2_CO2_PREDICTION_LSB_OFFSET 0x01
118 #define AIRQUALITY2_STATUS_OFFSET 0x02
119 #define AIRQUALITY2_RESISTANCE_NULL_BYTE 0x03
120 #define AIRQUALITY2_RESISTANCE_MSB_OFFSET 0x04
121 #define AIRQUALITY2_RESISTANCE_MID_OFFSET 0x05
122 #define AIRQUALITY2_RESISTANCE_LSB_OFFSET 0x06
123 #define AIRQUALITY2_TVOC_PREDICTION_MSB_OFFSET 0x07
124 #define AIRQUALITY2_TVOC_PREDICTION_LSB_OFFSET 0x08
125  // End group macro
128 // --------------------------------------------------------------- PUBLIC TYPES
137 typedef struct
138 {
139  // Modules
140 
141  i2c_master_t i2c;
142 
143  // ctx variable
144 
145  uint8_t slave_address;
146 
147 } airquality2_t;
148 
152 typedef struct
153 {
154  // Communication gpio pins
155 
156  pin_name_t scl;
157  pin_name_t sda;
158 
159  // static variable
160 
161  uint32_t i2c_speed;
162  uint8_t i2c_address;
163 
165  // End types group
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
174 #ifdef __cplusplus
175 extern "C"{
176 #endif
177 
187 
197 
207 void airquality2_generic_read ( airquality2_t *ctx, uint8_t *data_buf, uint8_t len );
208 
219 uint8_t airquality2_get_all_data ( airquality2_t *ctx, uint16_t *value_co2, uint16_t *value_tvoc, int32_t *resistance );
220 
221 #ifdef __cplusplus
222 }
223 #endif
224 #endif // _AIRQUALITY2_H_
225  // End public_function group
228 
229 // ------------------------------------------------------------------------- END
airquality2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: airquality2.h:161
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:141
airquality2_cfg_setup
void airquality2_cfg_setup(airquality2_cfg_t *cfg)
Config Object Initialization function.
airquality2_t
Click ctx object definition.
Definition: airquality2.h:138
airquality2_cfg_t::i2c_address
uint8_t i2c_address
Definition: airquality2.h:162
AIRQUALITY2_RETVAL
#define AIRQUALITY2_RETVAL
Definition: airquality2.h:61
airquality2_cfg_t::scl
pin_name_t scl
Definition: airquality2.h:156
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:157
airquality2_cfg_t
Click configuration structure definition.
Definition: airquality2.h:153
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:145