airquality3 2.0.0.0
airquality3.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 AIRQUALITY3_H
36#define AIRQUALITY3_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 AIRQUALITY3_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.wke = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
78#define AIRQUALITY3_RETVAL uint8_t
79
80#define AIRQUALITY3_OK 0x00
81#define AIRQUALITY3_INIT_ERROR 0xFF
88#define AIRQUALITY3_REG_ID 0x20
89#define AIRQUALITY3_REG_ERROR_ID 0xE0
90#define AIRQUALITY3_REG_STATUS 0x00
91#define AIRQUALITY3_REG_HW_VERSION 0x21
92#define AIRQUALITY3_REG_FW_BOOT_VERSION 0x23
93#define AIRQUALITY3_REG_FW_APP_VERSION 0x24
94#define AIRQUALITY3_REG_SW_RESET 0xFF
95#define AIRQUALITY3_REG_ALG_DATA 0x02
96#define AIRQUALITY3_REG_RAW_DATA 0x03
97#define AIRQUALITY3_REG_ENV_DATA 0x05
98#define AIRQUALITY3_REG_NTC 0x06
99#define AIRQUALITY3_REG_MEAS_MODE 0x01
100#define AIRQUALITY3_REG_BASELINE 0x11
107#define AIRQUALITY3_DRIVE_MODE_0 ( 0x00 << 4 )
108#define AIRQUALITY3_DRIVE_MODE_1 ( 0x01 << 4 )
109#define AIRQUALITY3_DRIVE_MODE_2 ( 0x02 << 4 )
110#define AIRQUALITY3_DRIVE_MODE_3 ( 0x03 << 4 )
111#define AIRQUALITY3_DRIVE_MODE_4 ( 0x04 << 4 )
112#define AIRQUALITY3_INT_DATARDY_0 ( 0x00 << 3 )
113#define AIRQUALITY3_INT_DATARDY_1 ( 0x01 << 3 )
114#define AIRQUALITY3_INT_THRESH_0 ( 0x00 << 2 )
115#define AIRQUALITY3_INT_THRESH_1 ( 0x01 << 2 )
122#define AIRQUALITY3_APP_START 0xF4
123#define AIRQUALITY3_APP_VERIFY 0xF3
124#define AIRQUALITY3_APP_DATA 0xF2
125#define AIRQUALITY3_APP_ERASE 0xF1
132#define AIRQUALITY3_DEVICE_SLAVE_ADDRESS 0x5A
139#define AIRQUALITY3_POWER_STATE_ON 0
140#define AIRQUALITY3_POWER_STATE_OFF 1
143 // End group macro
144// --------------------------------------------------------------- PUBLIC TYPES
153typedef struct
154{
155 // Output pins
156
157 digital_out_t rst;
158 digital_out_t wke;
159
160 // Input pins
161
162 digital_in_t int_pin;
163
164 // Modules
165
166 i2c_master_t i2c;
167
168 // ctx variable
169
171
173
177typedef struct
178{
179 // Communication gpio pins
180
181 pin_name_t scl;
182 pin_name_t sda;
183
184 // Additional gpio pins
185
186 pin_name_t rst;
187 pin_name_t wke;
188 pin_name_t int_pin;
189
190 // static variable
191
192 uint32_t i2c_speed;
193 uint8_t i2c_address;
194
196
200typedef struct
201{
202 uint8_t device_id;
203 uint8_t hw_ver;
204 uint8_t fw_boot_ver;
205 uint8_t fw_app_ver;
206
208
212typedef struct
213{
214 uint16_t co2;
215 uint16_t tvoc;
216 uint16_t raw_data;
217 uint8_t m_status;
218
220
221 // End types group
222
223// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
224
230#ifdef __cplusplus
231extern "C"{
232#endif
233
243
253
267
278void airquality3_generic_write ( airquality3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
279
290void airquality3_generic_read ( airquality3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
291
299
308
322void airquality3_software_reset ( airquality3_t *ctx, uint32_t reset ); // 0x11,0xE5,0x72,0x8A
323
339
340
347void airquality3_get_raw_data ( airquality3_t *ctx, uint16_t *raw_data );
348
362void airquality3_set_environment_data ( airquality3_t *ctx, uint32_t env_data ); // 0x11,0xE5,0x72,0x8A
363
377void airquality3_get_ntc_data ( airquality3_t *ctx, uint8_t *data_buf );
378
404
417void airquality3_set_baseline ( airquality3_t *ctx, uint16_t baseline );
418
432void airquality3_app_function ( airquality3_t *ctx, uint8_t app_task );
433
440void airquality3_set_power( airquality3_t *ctx, uint16_t pwr_state );
441
448
456
457#ifdef __cplusplus
458}
459#endif
460#endif // _AIRQUALITY3_H_
461
462 // End public_function group
464
465// ------------------------------------------------------------------------- END
#define AIRQUALITY3_RETVAL
Definition airquality3.h:78
void airquality3_get_device_info(airquality3_t *ctx, airguality3_info_t *info)
Get device info.
uint8_t airquality3_get_starus(airquality3_t *ctx)
Reads status.
uint8_t airquality3_get_co2_and_tvoc(airquality3_t *ctx, airquality3_air_data_t *air_data)
Get CO2 and TVOC data.
void airquality3_app_function(airquality3_t *ctx, uint8_t app_task)
function to start APP task
void airquality3_set_environment_data(airquality3_t *ctx, uint32_t env_data)
Temperature and humidity data settings.
void airquality3_software_reset(airquality3_t *ctx, uint32_t reset)
Software reset.
void airquality3_hardware_reset(airquality3_t *ctx)
Hardware reset.
void airquality3_default_cfg(airquality3_t *ctx)
Click Default Configuration function.
uint8_t airquality3_get_interrupt_state(airquality3_t *ctx)
Get interrupt state.
void airquality3_get_ntc_data(airquality3_t *ctx, uint8_t *data_buf)
Get NTC value.
void airquality3_set_measurement_mode(airquality3_t *ctx, uint8_t mode)
Function for settings sensor drive mode and interrupts.
AIRQUALITY3_RETVAL airquality3_init(airquality3_t *ctx, airquality3_cfg_t *cfg)
Initialization function.
void airquality3_get_raw_data(airquality3_t *ctx, uint16_t *raw_data)
Function reads raw ADC data values for resistance and current source used.
void airquality3_set_baseline(airquality3_t *ctx, uint16_t baseline)
Function for settings baseline value.
void airquality3_generic_write(airquality3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void airquality3_generic_read(airquality3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void airquality3_cfg_setup(airquality3_cfg_t *cfg)
Config Object Initialization function.
void airquality3_set_power(airquality3_t *ctx, uint16_t pwr_state)
Function for power ON/OFF chip.
Info structure definition.
Definition airquality3.h:201
uint8_t fw_app_ver
Definition airquality3.h:205
uint8_t hw_ver
Definition airquality3.h:203
uint8_t fw_boot_ver
Definition airquality3.h:204
uint8_t device_id
Definition airquality3.h:202
Air data structure definition.
Definition airquality3.h:213
uint16_t tvoc
Definition airquality3.h:215
uint8_t m_status
Definition airquality3.h:217
uint16_t raw_data
Definition airquality3.h:216
uint16_t co2
Definition airquality3.h:214
Click configuration structure definition.
Definition airquality3.h:178
uint32_t i2c_speed
Definition airquality3.h:192
pin_name_t wke
Definition airquality3.h:187
pin_name_t scl
Definition airquality3.h:181
pin_name_t int_pin
Definition airquality3.h:188
pin_name_t sda
Definition airquality3.h:182
pin_name_t rst
Definition airquality3.h:186
uint8_t i2c_address
Definition airquality3.h:193
Click ctx object definition.
Definition airquality3.h:154
digital_in_t int_pin
Definition airquality3.h:162
i2c_master_t i2c
Definition airquality3.h:166
digital_out_t wke
Definition airquality3.h:158
digital_out_t rst
Definition airquality3.h:157
uint8_t slave_address
Definition airquality3.h:170