co23  2.1.0.0
co23.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 CO23_H
29 #define CO23_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 #include "drv_uart.h"
49 
70 #define CO23_REG_PROD_ID 0x00
71 #define CO23_REG_SENS_STS 0x01
72 #define CO23_REG_MEAS_RATE_H 0x02
73 #define CO23_REG_MEAS_RATE_L 0x03
74 #define CO23_REG_MEAS_CFG 0x04
75 #define CO23_REG_CO2PPM_H 0x05
76 #define CO23_REG_CO2PPM_L 0x06
77 #define CO23_REG_MEAS_STS 0x07
78 #define CO23_REG_INT_CFG 0x08
79 #define CO23_REG_ALARM_TH_H 0x09
80 #define CO23_REG_ALARM_TH_L 0x0A
81 #define CO23_REG_PRESS_REF_H 0x0B
82 #define CO23_REG_PRESS_REF_L 0x0C
83 #define CO23_REG_CALIB_REF_H 0x0D
84 #define CO23_REG_CALIB_REF_L 0x0E
85 #define CO23_REG_SCRATCH_PAD 0x0F
86 #define CO23_REG_SENS_RST 0x10
87  // co23_reg
89 
104 #define CO23_OP_MODE_IDLE 0x00
105 #define CO23_OP_MODE_SINGLE 0x01
106 #define CO23_OP_MODE_CONTINUOUS 0x02
107 #define CO23_OP_BOC_CFG_DISABLE 0x00
108 #define CO23_OP_BOC_CFG_AUTOMATIC 0x01
109 #define CO23_OP_BOC_CFG_FORCED 0x02
110 #define CO23_PWM_MODE_SINGLE_PULSE 0x00
111 #define CO23_PWM_MODE_TRAIN_PULSE 0x01
112 
118 #define CO23_TX_DRV_BUFFER_SIZE 100
119 #define CO23_RX_DRV_BUFFER_SIZE 300
120 
126 #define CO23_DEVICE_ADDRESS 0x28
127  // co23_set
129 
144 #define CO23_MAP_MIKROBUS( cfg, mikrobus ) \
145  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
146  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
147  cfg.pwo = MIKROBUS( mikrobus, MIKROBUS_AN ); \
148  cfg.pws = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
149  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
150  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
151  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
152  // co23_map // co23
155 
160 typedef enum
161 {
166 
171 typedef err_t ( *co23_master_io_t )( struct co23_s*, uint8_t, uint8_t*, uint8_t );
177 typedef struct co23_s
178 {
179  // Output pins
180  digital_out_t pws;
182  // Input pins
183  digital_in_t pwo;
184  digital_in_t int_pin;
186  // Modules
187  i2c_master_t i2c;
188  uart_t uart;
190  // I2C slave address
191  uint8_t slave_address;
193  // Buffers
202 
207 typedef struct
208 {
209  // Communication gpio pins
210  pin_name_t rx_pin;
211  pin_name_t tx_pin;
213  pin_name_t scl;
214  pin_name_t sda;
216  pin_name_t pwo;
217  pin_name_t pws;
218  pin_name_t int_pin;
220  // Static variable
221  uint32_t baud_rate;
223  uart_data_bits_t data_bit;
224  uart_parity_t parity_bit;
225  uart_stop_bits_t stop_bit;
227  uint32_t i2c_speed;
228  uint8_t i2c_address;
232 } co23_cfg_t;
233 
238 typedef struct
239 {
240  uint8_t sen_rdy;
241  uint8_t pwm_dis_st;
242  uint8_t ortmp;
243  uint8_t orvs;
244  uint8_t iccer;
245  uint8_t ortmp_clr;
246  uint8_t orvs_clr;
247  uint8_t iccer_clr;
248 
250 
255 typedef struct
256 {
257  uint8_t pwm_outen;
258  uint8_t pwm_mode;
259  uint8_t boc_cfg;
260  uint8_t op_mode;
261 
263 
268 typedef struct
269 {
270  uint8_t drdy;
271  uint8_t int_sts;
272  uint8_t alarm;
273  uint8_t int_sts_clr;
274  uint8_t alarm_clr;
275 
277 
282 typedef struct
283 {
284  uint8_t int_typ;
285  uint8_t int_func;
286  uint8_t alarm_typ;
287 
289 
294 typedef enum
295 {
302 
304 
309 typedef enum
310 {
311  CO23_OK = 0,
312  CO23_ERROR = -1
313 
315 
332 
348 
362 err_t co23_init ( co23_t *ctx, co23_cfg_t *cfg );
363 
376 err_t co23_default_cfg ( co23_t *ctx );
377 
392 err_t co23_generic_write ( co23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
393 
408 err_t co23_generic_read ( co23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
409 
423 err_t co23_get_device_id ( co23_t *ctx, uint8_t *prod, uint8_t *rev );
424 
438 err_t co23_get_sens_status ( co23_t *ctx, co23_sens_status_t *sens_status );
439 
452 err_t co23_set_meas_rate ( co23_t *ctx, uint16_t meas_rate_sec );
453 
467 err_t co23_get_meas_cfg ( co23_t *ctx, co23_meas_cfg_t *meas_cfg );
468 
483 err_t co23_set_meas_cfg ( co23_t *ctx, co23_meas_cfg_t meas_cfg );
484 
497 err_t co23_get_co2_ppm ( co23_t *ctx, uint16_t *co2_ppm );
498 
512 err_t co23_get_meas_status ( co23_t *ctx, co23_meas_status_t *meas_status );
513 
527 err_t co23_get_int_cfg ( co23_t *ctx, co23_int_cfg_t *int_cfg );
528 
543 err_t co23_set_int_cfg ( co23_t *ctx, co23_int_cfg_t int_cfg );
544 
557 err_t co23_set_alarm_threshold ( co23_t *ctx, uint16_t alarm_th_ppm );
558 
571 err_t co23_set_pressure_ref ( co23_t *ctx, uint16_t pressure_mbar );
572 
585 err_t co23_set_calib_ref ( co23_t *ctx, uint16_t calib_ppm );
586 
601 
612 uint8_t co23_get_pwo_pin ( co23_t *ctx );
613 
624 uint8_t co23_get_int_pin ( co23_t *ctx );
625 
626 #ifdef __cplusplus
627 }
628 #endif
629 #endif // CO23_H
630  // co23
632 
633 // ------------------------------------------------------------------------ END
co23_cfg_t::tx_pin
pin_name_t tx_pin
Definition: co23.h:211
co23_get_meas_status
err_t co23_get_meas_status(co23_t *ctx, co23_meas_status_t *meas_status)
CO2 3 get measurement status function.
co23_s::i2c
i2c_master_t i2c
Definition: co23.h:187
co23_get_int_cfg
err_t co23_get_int_cfg(co23_t *ctx, co23_int_cfg_t *int_cfg)
CO2 3 get interrupt pin configuration function.
co23_get_pwo_pin
uint8_t co23_get_pwo_pin(co23_t *ctx)
CO2 3 get PWM output function.
co23_int_cfg_t
CO2 3 Click interrupt configuration object.
Definition: co23.h:283
co23_cfg_t::drv_sel
co23_drv_t drv_sel
Definition: co23.h:230
CO23_OK
@ CO23_OK
Definition: co23.h:311
co23_get_meas_cfg
err_t co23_get_meas_cfg(co23_t *ctx, co23_meas_cfg_t *meas_cfg)
CO2 3 get measurement configuration function.
co23_int_cfg_t::int_func
uint8_t int_func
Definition: co23.h:285
co23_s::drv_sel
co23_drv_t drv_sel
Definition: co23.h:197
co23_cfg_setup
void co23_cfg_setup(co23_cfg_t *cfg)
CO2 3 configuration object setup function.
CO23_TX_DRV_BUFFER_SIZE
#define CO23_TX_DRV_BUFFER_SIZE
CO2 3 driver buffer size.
Definition: co23.h:118
co23_set_pressure_ref
err_t co23_set_pressure_ref(co23_t *ctx, uint16_t pressure_mbar)
CO2 3 set alarm threshold function.
co23_set_meas_rate
err_t co23_set_meas_rate(co23_t *ctx, uint16_t meas_rate_sec)
CO2 3 set measurement rate function.
co23_sens_status_t::orvs_clr
uint8_t orvs_clr
Definition: co23.h:246
co23_soft_reset_value_t
co23_soft_reset_value_t
CO2 3 Click soft reset command value data.
Definition: co23.h:295
co23_cfg_t::uart_blocking
bool uart_blocking
Definition: co23.h:222
co23_set_alarm_threshold
err_t co23_set_alarm_threshold(co23_t *ctx, uint16_t alarm_th_ppm)
CO2 3 set alarm threshold function.
co23_cfg_t::pws
pin_name_t pws
Definition: co23.h:217
co23_meas_cfg_t::pwm_mode
uint8_t pwm_mode
Definition: co23.h:258
co23_cfg_t::rx_pin
pin_name_t rx_pin
Definition: co23.h:210
co23_meas_cfg_t::op_mode
uint8_t op_mode
Definition: co23.h:260
co23_sens_status_t
CO2 3 Click sens status object.
Definition: co23.h:239
CO23_DRV_SEL_I2C
@ CO23_DRV_SEL_I2C
Definition: co23.h:162
co23_get_int_pin
uint8_t co23_get_int_pin(co23_t *ctx)
CO2 3 get interrupt function.
co23_generic_read
err_t co23_generic_read(co23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
CO2 3 I2C reading function.
CO23_CMD_SAVE_FCS_CALIB_OFFSET
@ CO23_CMD_SAVE_FCS_CALIB_OFFSET
Definition: co23.h:299
co23_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: co23.h:225
co23_s::pws
digital_out_t pws
Definition: co23.h:180
co23_meas_status_t::int_sts
uint8_t int_sts
Definition: co23.h:271
co23_drv_t
co23_drv_t
CO2 3 Click driver selector.
Definition: co23.h:161
co23_int_cfg_t::int_typ
uint8_t int_typ
Definition: co23.h:284
co23_cfg_t::pwo
pin_name_t pwo
Definition: co23.h:216
co23_s::read_f
co23_master_io_t read_f
Definition: co23.h:199
co23_cfg_t::i2c_address
uint8_t i2c_address
Definition: co23.h:228
co23_meas_status_t::int_sts_clr
uint8_t int_sts_clr
Definition: co23.h:273
co23_default_cfg
err_t co23_default_cfg(co23_t *ctx)
CO2 3 default configuration function.
co23_set_calib_ref
err_t co23_set_calib_ref(co23_t *ctx, uint16_t calib_ppm)
CO2 3 set calibration function.
CO23_ERROR
@ CO23_ERROR
Definition: co23.h:312
co23_int_cfg_t::alarm_typ
uint8_t alarm_typ
Definition: co23.h:286
co23_s::uart_rx_buffer
char uart_rx_buffer[CO23_RX_DRV_BUFFER_SIZE]
Definition: co23.h:194
co23_meas_status_t::alarm_clr
uint8_t alarm_clr
Definition: co23.h:274
CO23_CMD_RESET_FCS
@ CO23_CMD_RESET_FCS
Definition: co23.h:300
co23_s::uart_tx_buffer
char uart_tx_buffer[CO23_TX_DRV_BUFFER_SIZE]
Definition: co23.h:195
co23_s::pwo
digital_in_t pwo
Definition: co23.h:183
co23_set_meas_cfg
err_t co23_set_meas_cfg(co23_t *ctx, co23_meas_cfg_t meas_cfg)
CO2 3 set measurement configuration function.
co23_drv_interface_selection
void co23_drv_interface_selection(co23_cfg_t *cfg, co23_drv_t drv_sel)
CO2 3 driver interface setup function.
CO23_CMD_STEPWISE_FILTER_EN
@ CO23_CMD_STEPWISE_FILTER_EN
Definition: co23.h:301
co23_meas_cfg_t::boc_cfg
uint8_t boc_cfg
Definition: co23.h:259
co23_s
CO2 3 Click context object.
Definition: co23.h:178
co23_sens_status_t::iccer
uint8_t iccer
Definition: co23.h:244
co23_master_io_t
err_t(* co23_master_io_t)(struct co23_s *, uint8_t, uint8_t *, uint8_t)
CO2 3 Click driver interface.
Definition: co23.h:171
co23_sens_status_t::sen_rdy
uint8_t sen_rdy
Definition: co23.h:240
co23_s::int_pin
digital_in_t int_pin
Definition: co23.h:184
co23_meas_status_t::alarm
uint8_t alarm
Definition: co23.h:272
co23_get_device_id
err_t co23_get_device_id(co23_t *ctx, uint8_t *prod, uint8_t *rev)
CO2 3 get device ID function.
CO23_CMD_STEPWISE_FILTER_DIS
@ CO23_CMD_STEPWISE_FILTER_DIS
Definition: co23.h:298
co23_cfg_t::int_pin
pin_name_t int_pin
Definition: co23.h:218
co23_s::uart
uart_t uart
Definition: co23.h:188
co23_meas_cfg_t::pwm_outen
uint8_t pwm_outen
Definition: co23.h:257
co23_get_sens_status
err_t co23_get_sens_status(co23_t *ctx, co23_sens_status_t *sens_status)
CO2 3 get sensor status function.
co23_t
struct co23_s co23_t
CO2 3 Click context object.
co23_get_co2_ppm
err_t co23_get_co2_ppm(co23_t *ctx, uint16_t *co2_ppm)
CO2 3 get CO2 concentration function.
co23_meas_status_t
CO2 3 Click measurement status object.
Definition: co23.h:269
CO23_RX_DRV_BUFFER_SIZE
#define CO23_RX_DRV_BUFFER_SIZE
Definition: co23.h:119
co23_cfg_t::sda
pin_name_t sda
Definition: co23.h:214
co23_sens_status_t::pwm_dis_st
uint8_t pwm_dis_st
Definition: co23.h:241
CO23_CMD_RESET_ABOC
@ CO23_CMD_RESET_ABOC
Definition: co23.h:297
co23_set_int_cfg
err_t co23_set_int_cfg(co23_t *ctx, co23_int_cfg_t int_cfg)
CO2 3 set interrupt pin configuration function.
co23_cfg_t
CO2 3 Click configuration object.
Definition: co23.h:208
co23_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: co23.h:223
co23_sens_status_t::orvs
uint8_t orvs
Definition: co23.h:243
co23_return_value_t
co23_return_value_t
CO2 3 Click return value data.
Definition: co23.h:310
co23_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: co23.h:224
co23_s::slave_address
uint8_t slave_address
Definition: co23.h:191
co23_sens_status_t::ortmp_clr
uint8_t ortmp_clr
Definition: co23.h:245
co23_sens_status_t::ortmp
uint8_t ortmp
Definition: co23.h:242
co23_meas_status_t::drdy
uint8_t drdy
Definition: co23.h:270
co23_init
err_t co23_init(co23_t *ctx, co23_cfg_t *cfg)
CO2 3 initialization function.
CO23_DRV_SEL_UART
@ CO23_DRV_SEL_UART
Definition: co23.h:163
co23_generic_write
err_t co23_generic_write(co23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
CO2 3 I2C writing function.
co23_meas_cfg_t
CO2 3 Click measurement configuration object.
Definition: co23.h:256
co23_sens_status_t::iccer_clr
uint8_t iccer_clr
Definition: co23.h:247
co23_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: co23.h:227
co23_soft_reset_trigger
err_t co23_soft_reset_trigger(co23_t *ctx, co23_soft_reset_value_t reset_cmd)
CO2 3 soft reset trigger function.
co23_cfg_t::scl
pin_name_t scl
Definition: co23.h:213
CO23_CMD_SOFT_RESET
@ CO23_CMD_SOFT_RESET
Definition: co23.h:296
co23_s::write_f
co23_master_io_t write_f
Definition: co23.h:198
co23_cfg_t::baud_rate
uint32_t baud_rate
Definition: co23.h:221