co_2  2.0.0.0
co2.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 CO2_H
36 #define CO2_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 CO2_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.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
58 
64 #define CO2_RETVAL uint8_t
65 
66 #define CO2_OK 0x00
67 #define CO2_INIT_ERROR 0xFF
68 
74 #define CO2_STATUS_REG 0x00
75 #define CO2_LOCK_REG 0x01
76 #define CO2_TIACN_REG 0x10
77 #define CO2_REFCN_REG 0x11
78 #define CO2_MODECN_REG 0x12
79 
85 #define CO2_WRITE_MODE 0x00
86 #define CO2_READ_ONLY_MODE 0x01
87 
93 #define CO2_EXT_TIA_RES 0x00
94 #define CO2_2750_OHM_TIA_RES 0x04
95 #define CO2_3500_OHM_TIA_RES 0x08
96 #define CO2_7K_OHM_TIA_RES 0x0C
97 #define CO2_14K_OHM_TIA_RES 0x10
98 #define CO2_35K_OHM_TIA_RES 0x14
99 #define CO2_120K_OHM_TIA_RES 0x18
100 #define CO2_350K_OHM_TIA_RES 0x1C
101 #define CO2_10_OHM_LOAD_RES 0x00
102 #define CO2_33_OHM_LOAD_RES 0x01
103 #define CO2_50_OHM_LOAD_RES 0x02
104 #define CO2_100_OHM_LOAD_RES 0x03
105 
111 #define CO2_VREF_INT 0x00
112 #define CO2_VREF_EXT 0x80
113 #define CO2_20_PERCENTS_INT_ZERO 0x00
114 #define CO2_50_PERCENTS_INT_ZERO 0x20
115 #define CO2_67_PERCENTS_INT_ZERO 0x40
116 #define CO2_INT_ZERO_BYPASSED 0x60
117 #define CO2_BIAS_POL_NEGATIVE 0x00
118 #define CO2_BIAS_POL_POSITIVE 0x10
119 #define CO2_0_PERCENTS_BIAS 0x00
120 #define CO2_1_PERCENT_BIAS 0x01
121 #define CO2_2_PERCENTS_BIAS 0x02
122 #define CO2_4_PERCENTS_BIAS 0x03
123 #define CO2_6_PERCENTS_BIAS 0x04
124 #define CO2_8_PERCENTS_BIAS 0x05
125 #define CO2_10_PERCENTS_BIAS 0x06
126 #define CO2_12_PERCENTS_BIAS 0x07
127 #define CO2_14_PERCENTS_BIAS 0x08
128 #define CO2_16_PERCENTS_BIAS 0x09
129 #define CO2_18_PERCENTS_BIAS 0x0A
130 #define CO2_20_PERCENTS_BIAS 0x0B
131 #define CO2_22_PERCENTS_BIAS 0x0C
132 #define CO2_24_PERCENTS_BIAS 0x0D
133 
139 #define CO2_FET_DIS 0x00
140 #define CO2_FET_EN 0x80
141 #define CO2_DEEP_SLEEP_MODE 0x00
142 #define CO2_2_LEAD_MODE 0x01
143 #define CO2_STANDBY_MODE 0x02
144 #define CO2_3_LEAD_MODE 0x03
145 #define CO2_TEMP_MODE_TIA_OFF 0x06
146 #define CO2_TEMP_MODE_TIA_ON 0x07
147 
153 #define CO2_DEVICE_EN 0x00
154 #define CO2_DEVICE_DIS 0x01
155 
161 #define ADC_DEVICE_ADDR 0x4D
162  // End group macro
165 // --------------------------------------------------------------- PUBLIC TYPES
174 typedef struct
175 {
176  // Output pins
177 
178  digital_out_t rst;
179 
180  // Input pins
181 
182  digital_in_t an;
183 
184  // Modules
185 
186  i2c_master_t i2c;
187 
188  // ctx variable
189 
190  uint8_t slave_address;
191 
192 } co2_t;
193 
197 typedef struct
198 {
199  // Communication gpio pins
200 
201  pin_name_t scl;
202  pin_name_t sda;
203 
204  // Additional gpio pins
205 
206  pin_name_t an;
207  pin_name_t rst;
208 
209  // static variable
210 
211  uint32_t i2c_speed;
212  uint8_t i2c_address;
213 
214 } co2_cfg_t;
215  // End types group
217 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
218 
224 #ifdef __cplusplus
225 extern "C"{
226 #endif
227 
236 void co2_cfg_setup ( co2_cfg_t *cfg );
237 
245 CO2_RETVAL co2_init ( co2_t *ctx, co2_cfg_t *cfg );
246 
257 uint8_t co2_generic_write ( co2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
258 
270 uint8_t co2_generic_read ( co2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
271 
279 void co2_wait_i2c_ready ( co2_t *ctx );
280 
289 void co2_enable( co2_t *ctx, uint8_t state );
290 
299 void co2_read_adc( co2_t *ctx, uint16_t *data_out );
300 
309 void co2_get_co2_ppm( co2_t *ctx, float *co2_data );
310 
311 #ifdef __cplusplus
312 }
313 #endif
314 #endif // _CO2_H_
315  // End public_function group
318 
319 // ------------------------------------------------------------------------- END
CO2_RETVAL
#define CO2_RETVAL
Definition: co2.h:64
co2_get_co2_ppm
void co2_get_co2_ppm(co2_t *ctx, float *co2_data)
Get CO Data function.
co2_t::an
digital_in_t an
Definition: co2.h:182
co2_t::rst
digital_out_t rst
Definition: co2.h:178
co2_init
CO2_RETVAL co2_init(co2_t *ctx, co2_cfg_t *cfg)
Initialization function.
co2_cfg_t::scl
pin_name_t scl
Definition: co2.h:201
co2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: co2.h:211
co2_cfg_t::rst
pin_name_t rst
Definition: co2.h:207
co2_cfg_t::sda
pin_name_t sda
Definition: co2.h:202
co2_read_adc
void co2_read_adc(co2_t *ctx, uint16_t *data_out)
Read ADC Data function.
co2_cfg_t::i2c_address
uint8_t i2c_address
Definition: co2.h:212
co2_wait_i2c_ready
void co2_wait_i2c_ready(co2_t *ctx)
Generic read function.
co2_t::slave_address
uint8_t slave_address
Definition: co2.h:190
co2_t
Click ctx object definition.
Definition: co2.h:174
co2_t::i2c
i2c_master_t i2c
Definition: co2.h:186
co2_cfg_setup
void co2_cfg_setup(co2_cfg_t *cfg)
Config Object Initialization function.
co2_cfg_t::an
pin_name_t an
Definition: co2.h:206
co2_generic_read
uint8_t co2_generic_read(co2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
co2_generic_write
uint8_t co2_generic_write(co2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
co2_enable
void co2_enable(co2_t *ctx, uint8_t state)
Device Enable function.
co2_cfg_t
Click configuration structure definition.
Definition: co2.h:197