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
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_i2c_master.h"
41
42
43// -------------------------------------------------------------- PUBLIC MACROS
53#define NDIRCO2_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
57 cfg.bsy = MIKROBUS( mikrobus, MIKROBUS_RST ); \
58 cfg.cal = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
66#define NDIRCO2_RETVAL uint8_t
67
68#define NDIRCO2_OK 0x00
69#define NDIRCO2_INIT_ERROR 0xFF
76#define NDIRCO2_SOFTWARE_RESET_REG 0x00
77#define NDIRCO2_CONTROL_REG 0x01
78#define NDIRCO2_STATUS_REG 0x02
79#define NDIRCO2_DATA_LOW_REG 0x03
80#define NDIRCO2_DATA_HIGH_REG 0x04
81#define NDIRCO2_AVERAGING_COUNT_REG 0x07
82#define NDIRCO2_HIGH_ALARM_THRESHOLD_REG 0x0C
83#define NDIRCO2_LOW_ALARM_THRESHOLD_REG 0x0D
84#define NDIRCO2_FUNCTION_REG 0x0F
91#define NDIRCO2_NORMAL_STATE 0x00
92#define NDIRCO2_RESET 0x01
99#define NDIRCO2_MOVING_AVERAGE_SEL 0x00
100#define NDIRCO2_IIR_DIGITAL_FILTER_SEL 0x04
107#define NDIRCO2_MIN_AVG_COUNT_1_TIME 0x00
108#define NDIRCO2_MAX_AVG_COUNT_64_TIMES 0x3F
115#define NDIRCO2_PWM_PIN_DISABLE 0x00
116#define NDIRCO2_PWM_PIN_ENABLE 0x01
117#define NDIRCO2_PWM_HIGH_CONCENTRATION 0x00
118#define NDIRCO2_PWM_LOW_CONCENTRATION 0x08
125#define NDIRCO2_CHECK_EACH_MEASURE 0x00
126#define NDIRCO2_CHECK_AVG_COMPLETED 0x01
127#define NDIRCO2_POWER_DOWN_MODE 0x00
128#define NDIRCO2_CONTINUOUS_OP_MODE 0x01 // End group macro
132// --------------------------------------------------------------- PUBLIC TYPES
141typedef struct
142{
143 // Input pins
144
145 digital_in_t an;
146 digital_in_t bsy;
147 digital_in_t cal;
148 digital_in_t int_pin;
149
150 // Modules
151
152 i2c_master_t i2c;
153
154 // ctx variable
155
157
158} ndirco2_t;
159
163typedef struct
164{
165 // Communication gpio pins
166
167 pin_name_t scl;
168 pin_name_t sda;
169
170 // Additional gpio pins
171
172 pin_name_t an;
173 pin_name_t bsy;
174 pin_name_t cal;
175 pin_name_t int_pin;
176
177 // static variable
178
179 uint32_t i2c_speed;
180 uint8_t i2c_address;
181
183 // End types group
185// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
186
192#ifdef __cplusplus
193extern "C"{
194#endif
195
205
215
226void ndirco2_generic_write ( ndirco2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
227
238void ndirco2_generic_read ( ndirco2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
239
251uint8_t ndirco2_read_register ( ndirco2_t *ctx, uint8_t register_address, uint16_t *data_out );
252
264uint8_t ndirco2_write_register ( ndirco2_t *ctx, uint8_t register_address, uint8_t transfer_data );
265
275void ndirco2_read_current_address ( ndirco2_t *ctx, uint8_t *data_out, uint8_t n_bytes );
276
288void ndirco2_read_co2 ( ndirco2_t *ctx, uint8_t set_check_mode, uint16_t *output_data );
289
300
311
320void ndirco2_set_mode ( ndirco2_t *ctx, uint8_t select_mode );
321
330
342
343
344#ifdef __cplusplus
345}
346#endif
347#endif // _NDIRCO2_H_
348 // End public_function group
351
352// ------------------------------------------------------------------------- END
#define NDIRCO2_RETVAL
Definition: ndirco2.h:66
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:164
pin_name_t cal
Definition: ndirco2.h:174
uint32_t i2c_speed
Definition: ndirco2.h:179
pin_name_t bsy
Definition: ndirco2.h:173
pin_name_t scl
Definition: ndirco2.h:167
pin_name_t int_pin
Definition: ndirco2.h:175
pin_name_t sda
Definition: ndirco2.h:168
pin_name_t an
Definition: ndirco2.h:172
uint8_t i2c_address
Definition: ndirco2.h:180
Click ctx object definition.
Definition: ndirco2.h:142
digital_in_t int_pin
Definition: ndirco2.h:148
i2c_master_t i2c
Definition: ndirco2.h:152
digital_in_t an
Definition: ndirco2.h:145
digital_in_t bsy
Definition: ndirco2.h:146
digital_in_t cal
Definition: ndirco2.h:147
uint8_t slave_address
Definition: ndirco2.h:156