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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define NDIRCO2_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
66  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
67  cfg.bsy = MIKROBUS( mikrobus, MIKROBUS_RST ); \
68  cfg.cal = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
70 
76 #define NDIRCO2_RETVAL uint8_t
77 
78 #define NDIRCO2_OK 0x00
79 #define NDIRCO2_INIT_ERROR 0xFF
80 
86 #define NDIRCO2_SOFTWARE_RESET_REG 0x00
87 #define NDIRCO2_CONTROL_REG 0x01
88 #define NDIRCO2_STATUS_REG 0x02
89 #define NDIRCO2_DATA_LOW_REG 0x03
90 #define NDIRCO2_DATA_HIGH_REG 0x04
91 #define NDIRCO2_AVERAGING_COUNT_REG 0x07
92 #define NDIRCO2_HIGH_ALARM_THRESHOLD_REG 0x0C
93 #define NDIRCO2_LOW_ALARM_THRESHOLD_REG 0x0D
94 #define NDIRCO2_FUNCTION_REG 0x0F
95 
101 #define NDIRCO2_NORMAL_STATE 0x00
102 #define NDIRCO2_RESET 0x01
103 
109 #define NDIRCO2_MOVING_AVERAGE_SEL 0x00
110 #define NDIRCO2_IIR_DIGITAL_FILTER_SEL 0x04
111 
117 #define NDIRCO2_MIN_AVG_COUNT_1_TIME 0x00
118 #define NDIRCO2_MAX_AVG_COUNT_64_TIMES 0x3F
119 
125 #define NDIRCO2_PWM_PIN_DISABLE 0x00
126 #define NDIRCO2_PWM_PIN_ENABLE 0x01
127 #define NDIRCO2_PWM_HIGH_CONCENTRATION 0x00
128 #define NDIRCO2_PWM_LOW_CONCENTRATION 0x08
129 
135 #define NDIRCO2_CHECK_EACH_MEASURE 0x00
136 #define NDIRCO2_CHECK_AVG_COMPLETED 0x01
137 #define NDIRCO2_POWER_DOWN_MODE 0x00
138 #define NDIRCO2_CONTINUOUS_OP_MODE 0x01
139  // End group macro
142 // --------------------------------------------------------------- PUBLIC TYPES
151 typedef struct
152 {
153  // Input pins
154 
155  digital_in_t an;
156  digital_in_t bsy;
157  digital_in_t cal;
158  digital_in_t int_pin;
159 
160  // Modules
161 
162  i2c_master_t i2c;
163 
164  // ctx variable
165 
166  uint8_t slave_address;
167 
168 } ndirco2_t;
169 
173 typedef struct
174 {
175  // Communication gpio pins
176 
177  pin_name_t scl;
178  pin_name_t sda;
179 
180  // Additional gpio pins
181 
182  pin_name_t an;
183  pin_name_t bsy;
184  pin_name_t cal;
185  pin_name_t int_pin;
186 
187  // static variable
188 
189  uint32_t i2c_speed;
190  uint8_t i2c_address;
191 
192 } ndirco2_cfg_t;
193  // End types group
195 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
196 
202 #ifdef __cplusplus
203 extern "C"{
204 #endif
205 
215 
225 
236 void ndirco2_generic_write ( ndirco2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
237 
248 void ndirco2_generic_read ( ndirco2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
249 
261 uint8_t ndirco2_read_register ( ndirco2_t *ctx, uint8_t register_address, uint16_t *data_out );
262 
274 uint8_t ndirco2_write_register ( ndirco2_t *ctx, uint8_t register_address, uint8_t transfer_data );
275 
285 void ndirco2_read_current_address ( ndirco2_t *ctx, uint8_t *data_out, uint8_t n_bytes );
286 
298 void ndirco2_read_co2 ( ndirco2_t *ctx, uint8_t set_check_mode, uint16_t *output_data );
299 
309 uint8_t ndirco2_check_busy ( ndirco2_t *ctx );
310 
321 
330 void ndirco2_set_mode ( ndirco2_t *ctx, uint8_t select_mode );
331 
339 void ndirco2_reset ( ndirco2_t *ctx );
340 
352 
353 
354 #ifdef __cplusplus
355 }
356 #endif
357 #endif // _NDIRCO2_H_
358  // End public_function group
361 
362 // ------------------------------------------------------------------------- END
ndirco2_cfg_t::an
pin_name_t an
Definition: ndirco2.h:182
ndirco2_t::cal
digital_in_t cal
Definition: ndirco2.h:157
ndirco2_t::bsy
digital_in_t bsy
Definition: ndirco2.h:156
ndirco2_cfg_t::cal
pin_name_t cal
Definition: ndirco2.h:184
ndirco2_init
NDIRCO2_RETVAL ndirco2_init(ndirco2_t *ctx, ndirco2_cfg_t *cfg)
Initialization function.
ndirco2_t
Click ctx object definition.
Definition: ndirco2.h:152
ndirco2_cfg_t::i2c_address
uint8_t i2c_address
Definition: ndirco2.h:190
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:76
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:178
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:189
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:174
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:183
ndirco2_t::an
digital_in_t an
Definition: ndirco2.h:155
ndirco2_t::i2c
i2c_master_t i2c
Definition: ndirco2.h:162
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:185
ndirco2_t::slave_address
uint8_t slave_address
Definition: ndirco2.h:166
ndirco2_t::int_pin
digital_in_t int_pin
Definition: ndirco2.h:158
ndirco2_cfg_t::scl
pin_name_t scl
Definition: ndirco2.h:177