no2  2.0.0.0
no2.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 NO2_H
36 #define NO2_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 // -------------------------------------------------------------- PUBLIC MACROS
66 #define NO2_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
71 
77 #define NO2_RETVAL uint8_t
78 
79 #define NO2_OK 0x00
80 #define NO2_INIT_ERROR 0xFF
81 
87 #define NO2_STATUS_REG 0x00
88 #define NO2_LOCK_REG 0x01
89 #define NO2_TIACN_REG 0x10
90 #define NO2_REFCN_REG 0x11
91 #define NO2_MODECN_REG 0x12
92 
98 #define NO2_WRITE_MODE 0x00
99 #define NO2_READ_ONLY_MODE 0x01
100 
106 #define NO2_EXT_TIA_RES 0x00
107 #define NO2_2750_OHM_TIA_RES 0x04
108 #define NO2_3500_OHM_TIA_RES 0x08
109 #define NO2_7K_OHM_TIA_RES 0x0C
110 #define NO2_14K_OHM_TIA_RES 0x10
111 #define NO2_35K_OHM_TIA_RES 0x14
112 #define NO2_120K_OHM_TIA_RES 0x18
113 #define NO2_350K_OHM_TIA_RES 0x1C
114 #define NO2_10_OHM_LOAD_RES 0x00
115 #define NO2_33_OHM_LOAD_RES 0x01
116 #define NO2_50_OHM_LOAD_RES 0x02
117 #define NO2_100_OHM_LOAD_RES 0x03
118 
124 #define NO2_VREF_INT 0x00
125 #define NO2_VREF_EXT 0x80
126 #define NO2_20_PERCENTS_INT_ZERO 0x00
127 #define NO2_50_PERCENTS_INT_ZERO 0x20
128 #define NO2_67_PERCENTS_INT_ZERO 0x40
129 #define NO2_INT_ZERO_BYPASSED 0x60
130 #define NO2_BIAS_POL_NEGATIVE 0x00
131 #define NO2_BIAS_POL_POSITIVE 0x10
132 #define NO2_0_PERCENTS_BIAS 0x00
133 #define NO2_1_PERCENT_BIAS 0x01
134 #define NO2_2_PERCENTS_BIAS 0x02
135 #define NO2_4_PERCENTS_BIAS 0x03
136 #define NO2_6_PERCENTS_BIAS 0x04
137 #define NO2_8_PERCENTS_BIAS 0x05
138 #define NO2_10_PERCENTS_BIAS 0x06
139 #define NO2_12_PERCENTS_BIAS 0x07
140 #define NO2_14_PERCENTS_BIAS 0x08
141 #define NO2_16_PERCENTS_BIAS 0x09
142 #define NO2_18_PERCENTS_BIAS 0x0A
143 #define NO2_20_PERCENTS_BIAS 0x0B
144 #define NO2_22_PERCENTS_BIAS 0x0C
145 #define NO2_24_PERCENTS_BIAS 0x0D
146 
152 #define NO2_FET_DIS 0x00
153 #define NO2_FET_EN 0x80
154 #define NO2_DEEP_SLEEP_MODE 0x00
155 #define NO2_2_LEAD_MODE 0x01
156 #define NO2_STANDBY_MODE 0x02
157 #define NO2_3_LEAD_MODE 0x03
158 #define NO2_TEMP_MODE_TIA_OFF 0x06
159 #define NO2_TEMP_MODE_TIA_ON 0x07
160 
166 #define NO2_DEVICE_EN 0x00
167 #define NO2_DEVICE_DIS 0x01
168 
174 #define ADC_DEVICE_ADDR 0x4D
175  // End group macro
178 // --------------------------------------------------------------- PUBLIC TYPES
187 typedef struct
188 {
189  // Output pins
190 
191  digital_out_t rst;
192 
193  // Input pins
194 
195  digital_in_t an;
196 
197  // Modules
198 
199  i2c_master_t i2c;
200 
201  // ctx variable
202 
203  uint8_t slave_address;
204 
205 } no2_t;
206 
210 typedef struct
211 {
212  // Communication gpio pins
213 
214  pin_name_t scl;
215  pin_name_t sda;
216 
217  // Additional gpio pins
218 
219  pin_name_t an;
220  pin_name_t rst;
221 
222  // static variable
223 
224  uint32_t i2c_speed;
225  uint8_t i2c_address;
226 
227 } no2_cfg_t;
228  // End types group
230 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
231 
237 #ifdef __cplusplus
238 extern "C"{
239 #endif
240 
249 void no2_cfg_setup ( no2_cfg_t *cfg );
250 
260 
284 void no2_default_cfg ( no2_t *ctx );
285 
296 void no2_generic_write ( no2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
297 
309 void no2_generic_read ( no2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
310 
318 void no2_write_byte ( no2_t *ctx, uint8_t reg, uint8_t dev_data );
319 
328 uint8_t no2_read_byte ( no2_t *ctx, uint8_t reg );
329 
337 void no2_enable ( no2_t *ctx, uint8_t state );
338 
346 uint16_t no2_read_adc ( no2_t *ctx );
347 
355 float no2_get_no_2_ppm ( no2_t *ctx );
356 
362 void no2_wait_ready ( no2_t *ctx );
363 
364 #ifdef __cplusplus
365 }
366 #endif
367 #endif // _NO2_H_
368  // End public_function group
371 
372 // ------------------------------------------------------------------------- END
no2_read_byte
uint8_t no2_read_byte(no2_t *ctx, uint8_t reg)
Function reads one byte from the register.
no2_cfg_t::scl
pin_name_t scl
Definition: no2.h:214
no2_enable
void no2_enable(no2_t *ctx, uint8_t state)
Device Enable function.
no2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: no2.h:224
no2_generic_read
void no2_generic_read(no2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
no2_default_cfg
void no2_default_cfg(no2_t *ctx)
Click Default Configuration function.
no2_cfg_t::rst
pin_name_t rst
Definition: no2.h:220
no2_read_adc
uint16_t no2_read_adc(no2_t *ctx)
Function for read ADC sensor data.
no2_t::rst
digital_out_t rst
Definition: no2.h:191
no2_cfg_t::sda
pin_name_t sda
Definition: no2.h:215
no2_init
NO2_RETVAL no2_init(no2_t *ctx, no2_cfg_t *cfg)
Initialization function.
no2_cfg_t
Click configuration structure definition.
Definition: no2.h:211
no2_cfg_setup
void no2_cfg_setup(no2_cfg_t *cfg)
Config Object Initialization function.
no2_t::i2c
i2c_master_t i2c
Definition: no2.h:199
no2_wait_ready
void no2_wait_ready(no2_t *ctx)
Function waits until I2C is ready for the next command.
no2_cfg_t::i2c_address
uint8_t i2c_address
Definition: no2.h:225
NO2_RETVAL
#define NO2_RETVAL
Definition: no2.h:77
no2_write_byte
void no2_write_byte(no2_t *ctx, uint8_t reg, uint8_t dev_data)
Function writes one byte to the register.
no2_t::slave_address
uint8_t slave_address
Definition: no2.h:203
no2_get_no_2_ppm
float no2_get_no_2_ppm(no2_t *ctx)
Get NO2 Data function.
no2_t
Click ctx object definition.
Definition: no2.h:188
no2_t::an
digital_in_t an
Definition: no2.h:195
no2_cfg_t::an
pin_name_t an
Definition: no2.h:219
no2_generic_write
void no2_generic_write(no2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.