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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
49 
70 #define OZONE3_REG_STATUS 0x00
71 #define OZONE3_REG_LOCK 0x01
72 #define OZONE3_REG_TIACN 0x10
73 #define OZONE3_REG_REFCN 0x11
74 #define OZONE3_REG_MODECN 0x12
75  // ozone3_reg
77 
97 #define OZONE3_WRITE_MODE 0x00
98 #define OZONE3_READ_ONLY_MODE 0x01
99 
104 #define OZONE3_RES_TIA_EXT 0x00
105 #define OZONE3_RES_TIA_2750_Ohm 0x04
106 #define OZONE3_RES_TIA_3500_Ohm 0x08
107 #define OZONE3_RES_TIA_7K_Ohm 0x0C
108 #define OZONE3_RES_TIA_14K_Ohm 0x10
109 #define OZONE3_RES_TIA_35K_Ohm 0x14
110 #define OZONE3_RES_TIA_120K_Ohm 0x18
111 #define OZONE3_RES_TIA_350K_Ohm 0x1C
112 #define OZONE3_RES_LOAD_10_Ohm 0x00
113 #define OZONE3_RES_LOAD_33_Ohm 0x01
114 #define OZONE3_RES_LOAD_50_Ohm 0x02
115 #define OZONE3_RES_LOAD_100_Ohm 0x03
116 
121 #define OZONE3_VREF_INT 0x00
122 #define OZONE3_VREF_EXT 0x80
123 #define OZONE3_PERCENTS_INT_ZERO_20 0x00
124 #define OZONE3_PERCENTS_INT_ZERO_50 0x20
125 #define OZONE3_PERCENTS_INT_ZERO_67 0x40
126 #define OZONE3_INT_ZERO_BYPASSED 0x60
127 #define OZONE3_BIAS_POL_NEGATIVE 0x00
128 #define OZONE3_BIAS_POL_POSITIVE 0x10
129 #define OZONE3_PERCENTS_BIAS_0 0x00
130 #define OZONE3_PERCENTS_BIAS_1 0x01
131 #define OZONE3_PERCENTS_BIAS_2 0x02
132 #define OZONE3_PERCENTS_BIAS_4 0x03
133 #define OZONE3_PERCENTS_BIAS_6 0x04
134 #define OZONE3_PERCENTS_BIAS_8 0x05
135 #define OZONE3_PERCENTS_BIAS_10 0x06
136 #define OZONE3_PERCENTS_BIAS_12 0x07
137 #define OZONE3_PERCENTS_BIAS_14 0x08
138 #define OZONE3_PERCENTS_BIAS_16 0x09
139 #define OZONE3_PERCENTS_BIAS_18 0x0A
140 #define OZONE3_PERCENTS_BIAS_20 0x0B
141 #define OZONE3_PERCENTS_BIAS_22 0x0C
142 #define OZONE3_PERCENTS_BIAS_24 0x0D
143 #define OZONE3_FET_DIS 0x00
144 #define OZONE3_FET_EN 0x80
145 #define OZONE3_DEEP_SLEEP_MODE 0x00
146 #define OZONE3_LEAD_MODE_2 0x01
147 #define OZONE3_STANDBY_MODE 0x02
148 #define OZONE3_LEAD_MODE_3 0x03
149 #define OZONE3_TEMP_MODE_TIA_OFF 0x06
150 #define OZONE3_TEMP_MODE_TIA_ON 0x07
151 #define OZONE3_DEVICE_ENABLE 0x00
152 #define OZONE3_DEVICE_DISABLE 0x01
153 
159 #define OZONE3_SET_DEV_ADDR 0x48
160 #define OZONE3_ADC_DEVICE_ADDR 0x4D
161  // ozone3_set
163 
178 #define OZONE3_MAP_MIKROBUS( cfg, mikrobus ) \
179  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
180  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
181  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
182  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
183  // ozone3_map // ozone3
186 
191 typedef struct
192 {
193  // Output pins
194 
195  digital_out_t rst;
197  // Input pins
198 
199  digital_in_t an;
201  // Modules
202 
203  i2c_master_t i2c;
205  // I2C slave address
206 
207  uint8_t slave_address;
209 } ozone3_t;
210 
215 typedef struct
216 {
217  pin_name_t scl;
218  pin_name_t sda;
220  pin_name_t an;
221  pin_name_t rst;
223  uint32_t i2c_speed;
224  uint8_t i2c_address;
226 } ozone3_cfg_t;
227 
232 typedef enum
233 {
235  OZONE3_ERROR = -1
236 
238 
257 
274 err_t ozone3_init ( ozone3_t *ctx, ozone3_cfg_t *cfg );
275 
292 
310 err_t ozone3_generic_write ( ozone3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
311 
329 err_t ozone3_generic_read ( ozone3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
330 
346 err_t ozone3_enable ( ozone3_t *ctx, uint8_t state );
347 
365 err_t ozone3_write_byte ( ozone3_t *ctx, uint8_t reg, uint8_t dev_data );
366 
382 uint8_t ozone3_read_byte ( ozone3_t *ctx, uint8_t reg );
383 
398 uint16_t ozone3_read_adc ( ozone3_t *ctx );
399 
414 
429 
430 #ifdef __cplusplus
431 }
432 #endif
433 #endif // OZONE3_H
434  // ozone3
436 
437 // ------------------------------------------------------------------------ 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:221
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:223
ozone3_cfg_t::scl
pin_name_t scl
Definition: ozone3.h:217
ozone3_cfg_t::i2c_address
uint8_t i2c_address
Definition: ozone3.h:224
ozone3_t::rst
digital_out_t rst
Definition: ozone3.h:195
ozone3_t::an
digital_in_t an
Definition: ozone3.h:199
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:207
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:233
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:192
ozone3_cfg_t::an
pin_name_t an
Definition: ozone3.h:220
ozone3_wait_ready
void ozone3_wait_ready(ozone3_t *ctx)
Ozone 3 wait ready function.
OZONE3_ERROR
@ OZONE3_ERROR
Definition: ozone3.h:235
ozone3_t::i2c
i2c_master_t i2c
Definition: ozone3.h:203
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:218
OZONE3_OK
@ OZONE3_OK
Definition: ozone3.h:234
ozone3_cfg_t
Ozone 3 Click configuration object.
Definition: ozone3.h:216
ozone3_read_byte
uint8_t ozone3_read_byte(ozone3_t *ctx, uint8_t reg)
Ozone 3 read byte function.