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 );
60 
66 #define NDIRCO2_RETVAL uint8_t
67 
68 #define NDIRCO2_OK 0x00
69 #define NDIRCO2_INIT_ERROR 0xFF
70 
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
85 
91 #define NDIRCO2_NORMAL_STATE 0x00
92 #define NDIRCO2_RESET 0x01
93 
99 #define NDIRCO2_MOVING_AVERAGE_SEL 0x00
100 #define NDIRCO2_IIR_DIGITAL_FILTER_SEL 0x04
101 
107 #define NDIRCO2_MIN_AVG_COUNT_1_TIME 0x00
108 #define NDIRCO2_MAX_AVG_COUNT_64_TIMES 0x3F
109 
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
119 
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
129  // End group macro
132 // --------------------------------------------------------------- PUBLIC TYPES
141 typedef 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 
156  uint8_t slave_address;
157 
158 } ndirco2_t;
159 
163 typedef 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 
182 } ndirco2_cfg_t;
183  // End types group
185 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
186 
192 #ifdef __cplusplus
193 extern "C"{
194 #endif
195 
204 void ndirco2_cfg_setup ( ndirco2_cfg_t *cfg );
205 
215 
226 void ndirco2_generic_write ( ndirco2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
227 
238 void ndirco2_generic_read ( ndirco2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
239 
251 uint8_t ndirco2_read_register ( ndirco2_t *ctx, uint8_t register_address, uint16_t *data_out );
252 
264 uint8_t ndirco2_write_register ( ndirco2_t *ctx, uint8_t register_address, uint8_t transfer_data );
265 
275 void ndirco2_read_current_address ( ndirco2_t *ctx, uint8_t *data_out, uint8_t n_bytes );
276 
288 void ndirco2_read_co2 ( ndirco2_t *ctx, uint8_t set_check_mode, uint16_t *output_data );
289 
299 uint8_t ndirco2_check_busy ( ndirco2_t *ctx );
300 
311 
320 void ndirco2_set_mode ( ndirco2_t *ctx, uint8_t select_mode );
321 
329 void ndirco2_reset ( ndirco2_t *ctx );
330 
341 uint8_t ndirco2_check_alarm( ndirco2_t *ctx );
342 
343 
344 #ifdef __cplusplus
345 }
346 #endif
347 #endif // _NDIRCO2_H_
348  // End public_function group
351 
352 // ------------------------------------------------------------------------- END
ndirco2_cfg_t::an
pin_name_t an
Definition: ndirco2.h:172
ndirco2_t::cal
digital_in_t cal
Definition: ndirco2.h:147
ndirco2_t::bsy
digital_in_t bsy
Definition: ndirco2.h:146
ndirco2_cfg_t::cal
pin_name_t cal
Definition: ndirco2.h:174
ndirco2_init
NDIRCO2_RETVAL ndirco2_init(ndirco2_t *ctx, ndirco2_cfg_t *cfg)
Initialization function.
ndirco2_t
Click ctx object definition.
Definition: ndirco2.h:141
ndirco2_cfg_t::i2c_address
uint8_t i2c_address
Definition: ndirco2.h:180
ndirco2_write_register
uint8_t ndirco2_write_register(ndirco2_t *ctx, uint8_t register_address, uint8_t transfer_data)
Generic Write function.
NDIRCO2_RETVAL
#define NDIRCO2_RETVAL
Definition: ndirco2.h:66
ndirco2_reset
void ndirco2_reset(ndirco2_t *ctx)
Software Reset function.
ndirco2_read_register
uint8_t ndirco2_read_register(ndirco2_t *ctx, uint8_t register_address, uint16_t *data_out)
Generic Read function.
ndirco2_check_busy
uint8_t ndirco2_check_busy(ndirco2_t *ctx)
Data Ready Check function.
ndirco2_cfg_t::sda
pin_name_t sda
Definition: ndirco2.h:168
ndirco2_set_mode
void ndirco2_set_mode(ndirco2_t *ctx, uint8_t select_mode)
Mode Set function.
ndirco2_read_co2
void ndirco2_read_co2(ndirco2_t *ctx, uint8_t set_check_mode, uint16_t *output_data)
CO2 Concentration Read function.
ndirco2_check_average_complete
uint8_t ndirco2_check_average_complete(ndirco2_t *ctx)
Average Complete Check function.
ndirco2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ndirco2.h:179
ndirco2_cfg_setup
void ndirco2_cfg_setup(ndirco2_cfg_t *cfg)
Config Object Initialization function.
ndirco2_generic_write
void ndirco2_generic_write(ndirco2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
ndirco2_cfg_t
Click configuration structure definition.
Definition: ndirco2.h:163
ndirco2_generic_read
void ndirco2_generic_read(ndirco2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
ndirco2_check_alarm
uint8_t ndirco2_check_alarm(ndirco2_t *ctx)
CO2 Concentration Limit Check function.
ndirco2_cfg_t::bsy
pin_name_t bsy
Definition: ndirco2.h:173
ndirco2_t::an
digital_in_t an
Definition: ndirco2.h:145
ndirco2_t::i2c
i2c_master_t i2c
Definition: ndirco2.h:152
ndirco2_read_current_address
void ndirco2_read_current_address(ndirco2_t *ctx, uint8_t *data_out, uint8_t n_bytes)
Current Address Read function.
ndirco2_cfg_t::int_pin
pin_name_t int_pin
Definition: ndirco2.h:175
ndirco2_t::slave_address
uint8_t slave_address
Definition: ndirco2.h:156
ndirco2_t::int_pin
digital_in_t int_pin
Definition: ndirco2.h:148
ndirco2_cfg_t::scl
pin_name_t scl
Definition: ndirco2.h:167