ndirco2 2.0.0.0
ndirco2.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 NDIRCO2_H
36#define NDIRCO2_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
57// -------------------------------------------------------------- PUBLIC MACROS
67#define NDIRCO2_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71 cfg.bsy = MIKROBUS( mikrobus, MIKROBUS_RST ); \
72 cfg.cal = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
80#define NDIRCO2_RETVAL uint8_t
81
82#define NDIRCO2_OK 0x00
83#define NDIRCO2_INIT_ERROR 0xFF
90#define NDIRCO2_SOFTWARE_RESET_REG 0x00
91#define NDIRCO2_CONTROL_REG 0x01
92#define NDIRCO2_STATUS_REG 0x02
93#define NDIRCO2_DATA_LOW_REG 0x03
94#define NDIRCO2_DATA_HIGH_REG 0x04
95#define NDIRCO2_AVERAGING_COUNT_REG 0x07
96#define NDIRCO2_HIGH_ALARM_THRESHOLD_REG 0x0C
97#define NDIRCO2_LOW_ALARM_THRESHOLD_REG 0x0D
98#define NDIRCO2_FUNCTION_REG 0x0F
105#define NDIRCO2_NORMAL_STATE 0x00
106#define NDIRCO2_RESET 0x01
113#define NDIRCO2_MOVING_AVERAGE_SEL 0x00
114#define NDIRCO2_IIR_DIGITAL_FILTER_SEL 0x04
121#define NDIRCO2_MIN_AVG_COUNT_1_TIME 0x00
122#define NDIRCO2_MAX_AVG_COUNT_64_TIMES 0x3F
129#define NDIRCO2_PWM_PIN_DISABLE 0x00
130#define NDIRCO2_PWM_PIN_ENABLE 0x01
131#define NDIRCO2_PWM_HIGH_CONCENTRATION 0x00
132#define NDIRCO2_PWM_LOW_CONCENTRATION 0x08
139#define NDIRCO2_CHECK_EACH_MEASURE 0x00
140#define NDIRCO2_CHECK_AVG_COMPLETED 0x01
141#define NDIRCO2_POWER_DOWN_MODE 0x00
142#define NDIRCO2_CONTINUOUS_OP_MODE 0x01
145 // End group macro
146// --------------------------------------------------------------- PUBLIC TYPES
155typedef struct
156{
157 // Input pins
158
159 digital_in_t an;
160 digital_in_t bsy;
161 digital_in_t cal;
162 digital_in_t int_pin;
163
164 // Modules
165
166 i2c_master_t i2c;
167
168 // ctx variable
169
171
172} ndirco2_t;
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 an;
187 pin_name_t bsy;
188 pin_name_t cal;
189 pin_name_t int_pin;
190
191 // static variable
192
193 uint32_t i2c_speed;
194 uint8_t i2c_address;
195
197
198 // End types group
199// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
200
206#ifdef __cplusplus
207extern "C"{
208#endif
209
219
229
240void ndirco2_generic_write ( ndirco2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
241
252void ndirco2_generic_read ( ndirco2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
253
265uint8_t ndirco2_read_register ( ndirco2_t *ctx, uint8_t register_address, uint16_t *data_out );
266
278uint8_t ndirco2_write_register ( ndirco2_t *ctx, uint8_t register_address, uint8_t transfer_data );
279
289void ndirco2_read_current_address ( ndirco2_t *ctx, uint8_t *data_out, uint8_t n_bytes );
290
302void ndirco2_read_co2 ( ndirco2_t *ctx, uint8_t set_check_mode, uint16_t *output_data );
303
314
325
334void ndirco2_set_mode ( ndirco2_t *ctx, uint8_t select_mode );
335
344
356
357
358#ifdef __cplusplus
359}
360#endif
361#endif // _NDIRCO2_H_
362
363 // End public_function group
365
366// ------------------------------------------------------------------------- END
#define NDIRCO2_RETVAL
Definition ndirco2.h:80
NDIRCO2_RETVAL ndirco2_init(ndirco2_t *ctx, ndirco2_cfg_t *cfg)
Initialization function.
uint8_t ndirco2_read_register(ndirco2_t *ctx, uint8_t register_address, uint16_t *data_out)
Generic Read function.
void ndirco2_read_co2(ndirco2_t *ctx, uint8_t set_check_mode, uint16_t *output_data)
CO2 Concentration Read function.
void ndirco2_set_mode(ndirco2_t *ctx, uint8_t select_mode)
Mode Set function.
void ndirco2_generic_read(ndirco2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void ndirco2_read_current_address(ndirco2_t *ctx, uint8_t *data_out, uint8_t n_bytes)
Current Address Read function.
void ndirco2_generic_write(ndirco2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void ndirco2_reset(ndirco2_t *ctx)
Software Reset function.
uint8_t ndirco2_check_average_complete(ndirco2_t *ctx)
Average Complete Check function.
uint8_t ndirco2_write_register(ndirco2_t *ctx, uint8_t register_address, uint8_t transfer_data)
Generic Write function.
void ndirco2_cfg_setup(ndirco2_cfg_t *cfg)
Config Object Initialization function.
uint8_t ndirco2_check_busy(ndirco2_t *ctx)
Data Ready Check function.
uint8_t ndirco2_check_alarm(ndirco2_t *ctx)
CO2 Concentration Limit Check function.
Click configuration structure definition.
Definition ndirco2.h:178
pin_name_t cal
Definition ndirco2.h:188
uint32_t i2c_speed
Definition ndirco2.h:193
pin_name_t bsy
Definition ndirco2.h:187
pin_name_t scl
Definition ndirco2.h:181
pin_name_t int_pin
Definition ndirco2.h:189
pin_name_t sda
Definition ndirco2.h:182
pin_name_t an
Definition ndirco2.h:186
uint8_t i2c_address
Definition ndirco2.h:194
Click ctx object definition.
Definition ndirco2.h:156
digital_in_t int_pin
Definition ndirco2.h:162
i2c_master_t i2c
Definition ndirco2.h:166
digital_in_t an
Definition ndirco2.h:159
digital_in_t bsy
Definition ndirco2.h:160
digital_in_t cal
Definition ndirco2.h:161
uint8_t slave_address
Definition ndirco2.h:170