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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 #include "drv_uart.h"
39 
60 #define CO23_REG_PROD_ID 0x00
61 #define CO23_REG_SENS_STS 0x01
62 #define CO23_REG_MEAS_RATE_H 0x02
63 #define CO23_REG_MEAS_RATE_L 0x03
64 #define CO23_REG_MEAS_CFG 0x04
65 #define CO23_REG_CO2PPM_H 0x05
66 #define CO23_REG_CO2PPM_L 0x06
67 #define CO23_REG_MEAS_STS 0x07
68 #define CO23_REG_INT_CFG 0x08
69 #define CO23_REG_ALARM_TH_H 0x09
70 #define CO23_REG_ALARM_TH_L 0x0A
71 #define CO23_REG_PRESS_REF_H 0x0B
72 #define CO23_REG_PRESS_REF_L 0x0C
73 #define CO23_REG_CALIB_REF_H 0x0D
74 #define CO23_REG_CALIB_REF_L 0x0E
75 #define CO23_REG_SCRATCH_PAD 0x0F
76 #define CO23_REG_SENS_RST 0x10
77  // co23_reg
79 
94 #define CO23_OP_MODE_IDLE 0x00
95 #define CO23_OP_MODE_SINGLE 0x01
96 #define CO23_OP_MODE_CONTINUOUS 0x02
97 #define CO23_OP_BOC_CFG_DISABLE 0x00
98 #define CO23_OP_BOC_CFG_AUTOMATIC 0x01
99 #define CO23_OP_BOC_CFG_FORCED 0x02
100 #define CO23_PWM_MODE_SINGLE_PULSE 0x00
101 #define CO23_PWM_MODE_TRAIN_PULSE 0x01
102 
108 #define CO23_TX_DRV_BUFFER_SIZE 100
109 #define CO23_RX_DRV_BUFFER_SIZE 300
110 
116 #define CO23_DEVICE_ADDRESS 0x28
117  // co23_set
119 
134 #define CO23_MAP_MIKROBUS( cfg, mikrobus ) \
135  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
136  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
137  cfg.pwo = MIKROBUS( mikrobus, MIKROBUS_AN ); \
138  cfg.pws = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
139  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
140  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
141  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
142  // co23_map // co23
145 
150 typedef enum
151 {
156 
161 typedef err_t ( *co23_master_io_t )( struct co23_s*, uint8_t, uint8_t*, uint8_t );
167 typedef struct co23_s
168 {
169  // Output pins
170  digital_out_t pws;
172  // Input pins
173  digital_in_t pwo;
174  digital_in_t int_pin;
176  // Modules
177  i2c_master_t i2c;
178  uart_t uart;
180  // I2C slave address
181  uint8_t slave_address;
183  // Buffers
192 
197 typedef struct
198 {
199  // Communication gpio pins
200  pin_name_t rx_pin;
201  pin_name_t tx_pin;
203  pin_name_t scl;
204  pin_name_t sda;
206  pin_name_t pwo;
207  pin_name_t pws;
208  pin_name_t int_pin;
210  // Static variable
211  uint32_t baud_rate;
213  uart_data_bits_t data_bit;
214  uart_parity_t parity_bit;
215  uart_stop_bits_t stop_bit;
217  uint32_t i2c_speed;
218  uint8_t i2c_address;
222 } co23_cfg_t;
223 
228 typedef struct
229 {
230  uint8_t sen_rdy;
231  uint8_t pwm_dis_st;
232  uint8_t ortmp;
233  uint8_t orvs;
234  uint8_t iccer;
235  uint8_t ortmp_clr;
236  uint8_t orvs_clr;
237  uint8_t iccer_clr;
238 
240 
245 typedef struct
246 {
247  uint8_t pwm_outen;
248  uint8_t pwm_mode;
249  uint8_t boc_cfg;
250  uint8_t op_mode;
251 
253 
258 typedef struct
259 {
260  uint8_t drdy;
261  uint8_t int_sts;
262  uint8_t alarm;
263  uint8_t int_sts_clr;
264  uint8_t alarm_clr;
265 
267 
272 typedef struct
273 {
274  uint8_t int_typ;
275  uint8_t int_func;
276  uint8_t alarm_typ;
277 
279 
284 typedef enum
285 {
292 
294 
299 typedef enum
300 {
301  CO23_OK = 0,
302  CO23_ERROR = -1
303 
305 
322 
338 
352 err_t co23_init ( co23_t *ctx, co23_cfg_t *cfg );
353 
366 err_t co23_default_cfg ( co23_t *ctx );
367 
382 err_t co23_generic_write ( co23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
383 
398 err_t co23_generic_read ( co23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
399 
413 err_t co23_get_device_id ( co23_t *ctx, uint8_t *prod, uint8_t *rev );
414 
428 err_t co23_get_sens_status ( co23_t *ctx, co23_sens_status_t *sens_status );
429 
442 err_t co23_set_meas_rate ( co23_t *ctx, uint16_t meas_rate_sec );
443 
457 err_t co23_get_meas_cfg ( co23_t *ctx, co23_meas_cfg_t *meas_cfg );
458 
473 err_t co23_set_meas_cfg ( co23_t *ctx, co23_meas_cfg_t meas_cfg );
474 
487 err_t co23_get_co2_ppm ( co23_t *ctx, uint16_t *co2_ppm );
488 
502 err_t co23_get_meas_status ( co23_t *ctx, co23_meas_status_t *meas_status );
503 
517 err_t co23_get_int_cfg ( co23_t *ctx, co23_int_cfg_t *int_cfg );
518 
533 err_t co23_set_int_cfg ( co23_t *ctx, co23_int_cfg_t int_cfg );
534 
547 err_t co23_set_alarm_threshold ( co23_t *ctx, uint16_t alarm_th_ppm );
548 
561 err_t co23_set_pressure_ref ( co23_t *ctx, uint16_t pressure_mbar );
562 
575 err_t co23_set_calib_ref ( co23_t *ctx, uint16_t calib_ppm );
576 
591 
602 uint8_t co23_get_pwo_pin ( co23_t *ctx );
603 
614 uint8_t co23_get_int_pin ( co23_t *ctx );
615 
616 #ifdef __cplusplus
617 }
618 #endif
619 #endif // CO23_H
620  // co23
622 
623 // ------------------------------------------------------------------------ END
co23_cfg_t::tx_pin
pin_name_t tx_pin
Definition: co23.h:201
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:177
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:273
co23_cfg_t::drv_sel
co23_drv_t drv_sel
Definition: co23.h:220
CO23_OK
@ CO23_OK
Definition: co23.h:301
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:275
co23_s::drv_sel
co23_drv_t drv_sel
Definition: co23.h:187
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:108
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:236
co23_soft_reset_value_t
co23_soft_reset_value_t
CO2 3 Click soft reset command value data.
Definition: co23.h:285
co23_cfg_t::uart_blocking
bool uart_blocking
Definition: co23.h:212
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:207
co23_meas_cfg_t::pwm_mode
uint8_t pwm_mode
Definition: co23.h:248
co23_cfg_t::rx_pin
pin_name_t rx_pin
Definition: co23.h:200
co23_meas_cfg_t::op_mode
uint8_t op_mode
Definition: co23.h:250
co23_sens_status_t
CO2 3 Click sens status object.
Definition: co23.h:229
CO23_DRV_SEL_I2C
@ CO23_DRV_SEL_I2C
Definition: co23.h:152
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:289
co23_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: co23.h:215
co23_s::pws
digital_out_t pws
Definition: co23.h:170
co23_meas_status_t::int_sts
uint8_t int_sts
Definition: co23.h:261
co23_drv_t
co23_drv_t
CO2 3 Click driver selector.
Definition: co23.h:151
co23_int_cfg_t::int_typ
uint8_t int_typ
Definition: co23.h:274
co23_cfg_t::pwo
pin_name_t pwo
Definition: co23.h:206
co23_s::read_f
co23_master_io_t read_f
Definition: co23.h:189
co23_cfg_t::i2c_address
uint8_t i2c_address
Definition: co23.h:218
co23_meas_status_t::int_sts_clr
uint8_t int_sts_clr
Definition: co23.h:263
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:302
co23_int_cfg_t::alarm_typ
uint8_t alarm_typ
Definition: co23.h:276
co23_s::uart_rx_buffer
char uart_rx_buffer[CO23_RX_DRV_BUFFER_SIZE]
Definition: co23.h:184
co23_meas_status_t::alarm_clr
uint8_t alarm_clr
Definition: co23.h:264
CO23_CMD_RESET_FCS
@ CO23_CMD_RESET_FCS
Definition: co23.h:290
co23_s::uart_tx_buffer
char uart_tx_buffer[CO23_TX_DRV_BUFFER_SIZE]
Definition: co23.h:185
co23_s::pwo
digital_in_t pwo
Definition: co23.h:173
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:291
co23_meas_cfg_t::boc_cfg
uint8_t boc_cfg
Definition: co23.h:249
co23_s
CO2 3 Click context object.
Definition: co23.h:168
co23_sens_status_t::iccer
uint8_t iccer
Definition: co23.h:234
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:161
co23_sens_status_t::sen_rdy
uint8_t sen_rdy
Definition: co23.h:230
co23_s::int_pin
digital_in_t int_pin
Definition: co23.h:174
co23_meas_status_t::alarm
uint8_t alarm
Definition: co23.h:262
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:288
co23_cfg_t::int_pin
pin_name_t int_pin
Definition: co23.h:208
co23_s::uart
uart_t uart
Definition: co23.h:178
co23_meas_cfg_t::pwm_outen
uint8_t pwm_outen
Definition: co23.h:247
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:259
CO23_RX_DRV_BUFFER_SIZE
#define CO23_RX_DRV_BUFFER_SIZE
Definition: co23.h:109
co23_cfg_t::sda
pin_name_t sda
Definition: co23.h:204
co23_sens_status_t::pwm_dis_st
uint8_t pwm_dis_st
Definition: co23.h:231
CO23_CMD_RESET_ABOC
@ CO23_CMD_RESET_ABOC
Definition: co23.h:287
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:198
co23_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: co23.h:213
co23_sens_status_t::orvs
uint8_t orvs
Definition: co23.h:233
co23_return_value_t
co23_return_value_t
CO2 3 Click return value data.
Definition: co23.h:300
co23_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: co23.h:214
co23_s::slave_address
uint8_t slave_address
Definition: co23.h:181
co23_sens_status_t::ortmp_clr
uint8_t ortmp_clr
Definition: co23.h:235
co23_sens_status_t::ortmp
uint8_t ortmp
Definition: co23.h:232
co23_meas_status_t::drdy
uint8_t drdy
Definition: co23.h:260
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:153
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:246
co23_sens_status_t::iccer_clr
uint8_t iccer_clr
Definition: co23.h:237
co23_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: co23.h:217
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:203
CO23_CMD_SOFT_RESET
@ CO23_CMD_SOFT_RESET
Definition: co23.h:286
co23_s::write_f
co23_master_io_t write_f
Definition: co23.h:188
co23_cfg_t::baud_rate
uint32_t baud_rate
Definition: co23.h:211