airquality5 2.0.0.0
airquality5.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 AIRQUALITY5_H
36#define AIRQUALITY5_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 AIRQUALITY5_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define AIRQUALITY5_RETVAL uint8_t
77
78#define AIRQUALITY5_OK 0x00
79#define AIRQUALITY5_INIT_ERROR 0xFF
86#define AIRQ5_DATA_CHANNEL_NO2 0x4000
87#define AIRQ5_DATA_CHANNEL_NH3 0x5000
88#define AIRQ5_DATA_CHANNEL_CO 0x6000
95#define AIRQ5_REG_POINTER_CONVERT 0x00
96#define AIRQ5_REG_POINTER_CONFIG 0x01
97#define AIRQ5_REG_POINTER_LOW_THRESH 0x02
98#define AIRQ5_REG_POINTER_HIGH_THRESH 0x03
105#define AIRQ5_CONFIG_OS_SINGLE 0x8000
106#define AIRQ5_CONFIG_OS_BUSY 0x0000
107#define AIRQ5_CONFIG_OS_NOTBUSY 0x8000
114#define AIRQ5_CONFIG_PGA_6_144V 0x0000
115#define AIRQ5_CONFIG_PGA_4_096V 0x0200
116#define AIRQ5_CONFIG_PGA_2_048V 0x0400
117#define AIRQ5_CONFIG_PGA_1_024V 0x0600
118#define AIRQ5_CONFIG_PGA_0_512V 0x0800
119#define AIRQ5_CONFIG_PGA_0_256V 0x0A00
126#define AIRQ5_CONFIG_CONTINUOUS_MODE 0x0000
127#define AIRQ5_CONFIG_SINGLE_MODE 0x0100
134#define AIRQ5_CONFIG_DATA_RATE_128SPS 0x0000
135#define AIRQ5_CONFIG_DATA_RATE_250SPS 0x0020
136#define AIRQ5_CONFIG_DATA_RATE_490SPS 0x0040
137#define AIRQ5_CONFIG_DATA_RATE_920SPS 0x0060
138#define AIRQ5_CONFIG_DATA_RATE_1600SPS 0x0080
139#define AIRQ5_CONFIG_DATA_RATE_2400SPS 0x00A0
140#define AIRQ5_CONFIG_DATA_RATE_3300SPS 0x00C0
147#define AIRQ5_CONFIG_COMP_MODE_TRADITIONAL 0x0000
148#define AIRQ5_CONFIG_COMP_MODE_WINDOW 0x0010
155#define AIRQ5_CONFIG_COMP_POL_ACTIVE_LOW 0x0000
156#define AIRQ5_CONFIG_COMP_POL_ACTIVE_HIGH 0x0008
163#define AIRQ5_CONFIG_COMP_LAT_NOT_LATCH 0x0000
164#define AIRQ5_CONFIG_COMP_LAT_LATCH 0x0004
171#define AIRQ5_CONFIG_COMP_QUE_1CONV 0x0000
172#define AIRQ5_CONFIG_COMP_QUE_2CONV 0x0001
173#define AIRQ5_CONFIG_COMP_QUE_4CONV 0x0002
174#define AIRQ5_CONFIG_COMP_QUE_0CONV 0x0003
177 // End group macro
178// --------------------------------------------------------------- PUBLIC TYPES
187typedef struct
188{
189
190 // Input pins
191
192 digital_in_t rdy;
193
194 // Modules
195
196 i2c_master_t i2c;
197
198 // ctx variable
199
201 uint16_t data_config;
202
204
208typedef struct
209{
210 // Communication gpio pins
211
212 pin_name_t scl;
213 pin_name_t sda;
214
215 // Additional gpio pins
216
217 pin_name_t rdy;
218
219 // static variable
220
221 uint32_t i2c_speed;
222 uint8_t i2c_address;
223
225
226 // End types group
227
228// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
229
235#ifdef __cplusplus
236extern "C"{
237#endif
238
248
258
267
278void airquality5_generic_write ( airquality5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
279
291void airquality5_generic_read ( airquality5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
292
304void airq5_write_data ( airquality5_t *ctx, uint8_t reg, uint16_t data_b );
305
315uint16_t airq5_read_data ( airquality5_t *ctx, uint8_t reg );
316
326void airq5_set_configuration ( airquality5_t *ctx, uint16_t config );
327
337uint16_t airq5_read_sensor_data( airquality5_t *ctx, uint16_t channel_data );
338
348#ifdef __cplusplus
349}
350#endif
351#endif // _AIRQUALITY5_H_
352
353 // End public_function group
355
356// ------------------------------------------------------------------------- END
#define AIRQUALITY5_RETVAL
Definition airquality5.h:76
void airquality5_cfg_setup(airquality5_cfg_t *cfg)
Config Object Initialization function.
uint8_t airq5_get_interrupt(airquality5_t *ctx)
Functions for reads interrupt pin.
void airquality5_generic_write(airquality5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint16_t airq5_read_data(airquality5_t *ctx, uint8_t reg)
Functions for read data from register.
uint16_t airq5_read_sensor_data(airquality5_t *ctx, uint16_t channel_data)
Functions for read sensor data.
void airq5_write_data(airquality5_t *ctx, uint8_t reg, uint16_t data_b)
Functions for write data in register.
AIRQUALITY5_RETVAL airquality5_init(airquality5_t *ctx, airquality5_cfg_t *cfg)
Initialization function.
void airquality5_default_cfg(airquality5_t *ctx)
Click Default Configuration function.
void airquality5_generic_read(airquality5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void airq5_set_configuration(airquality5_t *ctx, uint16_t config)
Functions for configuration.
Click configuration structure definition.
Definition airquality5.h:209
uint32_t i2c_speed
Definition airquality5.h:221
pin_name_t scl
Definition airquality5.h:212
pin_name_t rdy
Definition airquality5.h:217
pin_name_t sda
Definition airquality5.h:213
uint8_t i2c_address
Definition airquality5.h:222
Click ctx object definition.
Definition airquality5.h:188
i2c_master_t i2c
Definition airquality5.h:196
uint8_t slave_address
Definition airquality5.h:200
uint16_t data_config
Definition airquality5.h:201
digital_in_t rdy
Definition airquality5.h:192