ozone3  2.0.0.0
ozone3.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef OZONE3_H
29 #define OZONE3_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
53 
74 #define OZONE3_REG_STATUS 0x00
75 #define OZONE3_REG_LOCK 0x01
76 #define OZONE3_REG_TIACN 0x10
77 #define OZONE3_REG_REFCN 0x11
78 #define OZONE3_REG_MODECN 0x12
79  // ozone3_reg
81 
101 #define OZONE3_WRITE_MODE 0x00
102 #define OZONE3_READ_ONLY_MODE 0x01
103 
108 #define OZONE3_RES_TIA_EXT 0x00
109 #define OZONE3_RES_TIA_2750_Ohm 0x04
110 #define OZONE3_RES_TIA_3500_Ohm 0x08
111 #define OZONE3_RES_TIA_7K_Ohm 0x0C
112 #define OZONE3_RES_TIA_14K_Ohm 0x10
113 #define OZONE3_RES_TIA_35K_Ohm 0x14
114 #define OZONE3_RES_TIA_120K_Ohm 0x18
115 #define OZONE3_RES_TIA_350K_Ohm 0x1C
116 #define OZONE3_RES_LOAD_10_Ohm 0x00
117 #define OZONE3_RES_LOAD_33_Ohm 0x01
118 #define OZONE3_RES_LOAD_50_Ohm 0x02
119 #define OZONE3_RES_LOAD_100_Ohm 0x03
120 
125 #define OZONE3_VREF_INT 0x00
126 #define OZONE3_VREF_EXT 0x80
127 #define OZONE3_PERCENTS_INT_ZERO_20 0x00
128 #define OZONE3_PERCENTS_INT_ZERO_50 0x20
129 #define OZONE3_PERCENTS_INT_ZERO_67 0x40
130 #define OZONE3_INT_ZERO_BYPASSED 0x60
131 #define OZONE3_BIAS_POL_NEGATIVE 0x00
132 #define OZONE3_BIAS_POL_POSITIVE 0x10
133 #define OZONE3_PERCENTS_BIAS_0 0x00
134 #define OZONE3_PERCENTS_BIAS_1 0x01
135 #define OZONE3_PERCENTS_BIAS_2 0x02
136 #define OZONE3_PERCENTS_BIAS_4 0x03
137 #define OZONE3_PERCENTS_BIAS_6 0x04
138 #define OZONE3_PERCENTS_BIAS_8 0x05
139 #define OZONE3_PERCENTS_BIAS_10 0x06
140 #define OZONE3_PERCENTS_BIAS_12 0x07
141 #define OZONE3_PERCENTS_BIAS_14 0x08
142 #define OZONE3_PERCENTS_BIAS_16 0x09
143 #define OZONE3_PERCENTS_BIAS_18 0x0A
144 #define OZONE3_PERCENTS_BIAS_20 0x0B
145 #define OZONE3_PERCENTS_BIAS_22 0x0C
146 #define OZONE3_PERCENTS_BIAS_24 0x0D
147 #define OZONE3_FET_DIS 0x00
148 #define OZONE3_FET_EN 0x80
149 #define OZONE3_DEEP_SLEEP_MODE 0x00
150 #define OZONE3_LEAD_MODE_2 0x01
151 #define OZONE3_STANDBY_MODE 0x02
152 #define OZONE3_LEAD_MODE_3 0x03
153 #define OZONE3_TEMP_MODE_TIA_OFF 0x06
154 #define OZONE3_TEMP_MODE_TIA_ON 0x07
155 #define OZONE3_DEVICE_ENABLE 0x00
156 #define OZONE3_DEVICE_DISABLE 0x01
157 
163 #define OZONE3_SET_DEV_ADDR 0x48
164 #define OZONE3_ADC_DEVICE_ADDR 0x4D
165  // ozone3_set
167 
182 #define OZONE3_MAP_MIKROBUS( cfg, mikrobus ) \
183  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
184  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
185  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
186  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
187  // ozone3_map // ozone3
190 
195 typedef struct
196 {
197  // Output pins
198 
199  digital_out_t rst;
201  // Input pins
202 
203  digital_in_t an;
205  // Modules
206 
207  i2c_master_t i2c;
209  // I2C slave address
210 
211  uint8_t slave_address;
213 } ozone3_t;
214 
219 typedef struct
220 {
221  pin_name_t scl;
222  pin_name_t sda;
224  pin_name_t an;
225  pin_name_t rst;
227  uint32_t i2c_speed;
228  uint8_t i2c_address;
230 } ozone3_cfg_t;
231 
236 typedef enum
237 {
239  OZONE3_ERROR = -1
240 
242 
261 
278 err_t ozone3_init ( ozone3_t *ctx, ozone3_cfg_t *cfg );
279 
296 
314 err_t ozone3_generic_write ( ozone3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
315 
333 err_t ozone3_generic_read ( ozone3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
334 
350 err_t ozone3_enable ( ozone3_t *ctx, uint8_t state );
351 
369 err_t ozone3_write_byte ( ozone3_t *ctx, uint8_t reg, uint8_t dev_data );
370 
386 uint8_t ozone3_read_byte ( ozone3_t *ctx, uint8_t reg );
387 
402 uint16_t ozone3_read_adc ( ozone3_t *ctx );
403 
418 
433 
434 #ifdef __cplusplus
435 }
436 #endif
437 #endif // OZONE3_H
438  // ozone3
440 
441 // ------------------------------------------------------------------------ END
ozone3_default_cfg
err_t ozone3_default_cfg(ozone3_t *ctx)
Ozone 3 default configuration function.
ozone3_get_o3_ppm
float ozone3_get_o3_ppm(ozone3_t *ctx)
Ozone 3 get O3 ppm function.
ozone3_cfg_t::rst
pin_name_t rst
Definition: ozone3.h:225
ozone3_cfg_setup
void ozone3_cfg_setup(ozone3_cfg_t *cfg)
Ozone 3 configuration object setup function.
ozone3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ozone3.h:227
ozone3_cfg_t::scl
pin_name_t scl
Definition: ozone3.h:221
ozone3_cfg_t::i2c_address
uint8_t i2c_address
Definition: ozone3.h:228
ozone3_t::rst
digital_out_t rst
Definition: ozone3.h:199
ozone3_t::an
digital_in_t an
Definition: ozone3.h:203
ozone3_init
err_t ozone3_init(ozone3_t *ctx, ozone3_cfg_t *cfg)
Ozone 3 initialization function.
ozone3_t::slave_address
uint8_t slave_address
Definition: ozone3.h:211
ozone3_write_byte
err_t ozone3_write_byte(ozone3_t *ctx, uint8_t reg, uint8_t dev_data)
Ozone 3 write byte function.
ozone3_return_value_t
ozone3_return_value_t
Ozone 3 Click return value data.
Definition: ozone3.h:237
ozone3_generic_read
err_t ozone3_generic_read(ozone3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Ozone 3 I2C reading function.
ozone3_enable
err_t ozone3_enable(ozone3_t *ctx, uint8_t state)
Ozone 3 enable function.
ozone3_t
Ozone 3 Click context object.
Definition: ozone3.h:196
ozone3_cfg_t::an
pin_name_t an
Definition: ozone3.h:224
ozone3_wait_ready
void ozone3_wait_ready(ozone3_t *ctx)
Ozone 3 wait ready function.
OZONE3_ERROR
@ OZONE3_ERROR
Definition: ozone3.h:239
ozone3_t::i2c
i2c_master_t i2c
Definition: ozone3.h:207
ozone3_generic_write
err_t ozone3_generic_write(ozone3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Ozone 3 I2C writing function.
ozone3_read_adc
uint16_t ozone3_read_adc(ozone3_t *ctx)
Ozone 3 read ADC function.
ozone3_cfg_t::sda
pin_name_t sda
Definition: ozone3.h:222
OZONE3_OK
@ OZONE3_OK
Definition: ozone3.h:238
ozone3_cfg_t
Ozone 3 Click configuration object.
Definition: ozone3.h:220
ozone3_read_byte
uint8_t ozone3_read_byte(ozone3_t *ctx, uint8_t reg)
Ozone 3 read byte function.