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
32extern "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#include "drv_uart.h"
53
74#define CO23_REG_PROD_ID 0x00
75#define CO23_REG_SENS_STS 0x01
76#define CO23_REG_MEAS_RATE_H 0x02
77#define CO23_REG_MEAS_RATE_L 0x03
78#define CO23_REG_MEAS_CFG 0x04
79#define CO23_REG_CO2PPM_H 0x05
80#define CO23_REG_CO2PPM_L 0x06
81#define CO23_REG_MEAS_STS 0x07
82#define CO23_REG_INT_CFG 0x08
83#define CO23_REG_ALARM_TH_H 0x09
84#define CO23_REG_ALARM_TH_L 0x0A
85#define CO23_REG_PRESS_REF_H 0x0B
86#define CO23_REG_PRESS_REF_L 0x0C
87#define CO23_REG_CALIB_REF_H 0x0D
88#define CO23_REG_CALIB_REF_L 0x0E
89#define CO23_REG_SCRATCH_PAD 0x0F
90#define CO23_REG_SENS_RST 0x10
91
92 // co23_reg
93
108#define CO23_OP_MODE_IDLE 0x00
109#define CO23_OP_MODE_SINGLE 0x01
110#define CO23_OP_MODE_CONTINUOUS 0x02
111#define CO23_OP_BOC_CFG_DISABLE 0x00
112#define CO23_OP_BOC_CFG_AUTOMATIC 0x01
113#define CO23_OP_BOC_CFG_FORCED 0x02
114#define CO23_PWM_MODE_SINGLE_PULSE 0x00
115#define CO23_PWM_MODE_TRAIN_PULSE 0x01
116
122#define CO23_TX_DRV_BUFFER_SIZE 100
123#define CO23_RX_DRV_BUFFER_SIZE 300
124
130#define CO23_DEVICE_ADDRESS 0x28
131
132 // co23_set
133
148#define CO23_MAP_MIKROBUS( cfg, mikrobus ) \
149 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
150 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
151 cfg.pwo = MIKROBUS( mikrobus, MIKROBUS_AN ); \
152 cfg.pws = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
153 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
154 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
155 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
156
157 // co23_map
158 // co23
159
170
175typedef err_t ( *co23_master_io_t )( struct co23_s*, uint8_t, uint8_t*, uint8_t );
181typedef struct co23_s
182{
183 // Output pins
184 digital_out_t pws;
186 // Input pins
187 digital_in_t pwo;
188 digital_in_t int_pin;
190 // Modules
191 i2c_master_t i2c;
192 uart_t uart;
194 // I2C slave address
197 // Buffers
206
211typedef struct
212{
213 // Communication gpio pins
214 pin_name_t rx_pin;
215 pin_name_t tx_pin;
217 pin_name_t scl;
218 pin_name_t sda;
220 pin_name_t pwo;
221 pin_name_t pws;
222 pin_name_t int_pin;
224 // Static variable
225 uint32_t baud_rate;
227 uart_data_bits_t data_bit;
228 uart_parity_t parity_bit;
229 uart_stop_bits_t stop_bit;
231 uint32_t i2c_speed;
232 uint8_t i2c_address;
236} co23_cfg_t;
237
242typedef struct
243{
244 uint8_t sen_rdy;
245 uint8_t pwm_dis_st;
246 uint8_t ortmp;
247 uint8_t orvs;
248 uint8_t iccer;
249 uint8_t ortmp_clr;
250 uint8_t orvs_clr;
251 uint8_t iccer_clr;
252
254
259typedef struct
260{
261 uint8_t pwm_outen;
262 uint8_t pwm_mode;
263 uint8_t boc_cfg;
264 uint8_t op_mode;
265
267
272typedef struct
273{
274 uint8_t drdy;
275 uint8_t int_sts;
276 uint8_t alarm;
277 uint8_t int_sts_clr;
278 uint8_t alarm_clr;
279
281
286typedef struct
287{
288 uint8_t int_typ;
289 uint8_t int_func;
290 uint8_t alarm_typ;
291
293
308
313typedef enum
314{
316 CO23_ERROR = -1
317
319
336
352
366err_t co23_init ( co23_t *ctx, co23_cfg_t *cfg );
367
381
396err_t co23_generic_write ( co23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
397
412err_t co23_generic_read ( co23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
413
427err_t co23_get_device_id ( co23_t *ctx, uint8_t *prod, uint8_t *rev );
428
442err_t co23_get_sens_status ( co23_t *ctx, co23_sens_status_t *sens_status );
443
456err_t co23_set_meas_rate ( co23_t *ctx, uint16_t meas_rate_sec );
457
471err_t co23_get_meas_cfg ( co23_t *ctx, co23_meas_cfg_t *meas_cfg );
472
487err_t co23_set_meas_cfg ( co23_t *ctx, co23_meas_cfg_t meas_cfg );
488
501err_t co23_get_co2_ppm ( co23_t *ctx, uint16_t *co2_ppm );
502
516err_t co23_get_meas_status ( co23_t *ctx, co23_meas_status_t *meas_status );
517
531err_t co23_get_int_cfg ( co23_t *ctx, co23_int_cfg_t *int_cfg );
532
547err_t co23_set_int_cfg ( co23_t *ctx, co23_int_cfg_t int_cfg );
548
561err_t co23_set_alarm_threshold ( co23_t *ctx, uint16_t alarm_th_ppm );
562
575err_t co23_set_pressure_ref ( co23_t *ctx, uint16_t pressure_mbar );
576
589err_t co23_set_calib_ref ( co23_t *ctx, uint16_t calib_ppm );
590
605
616uint8_t co23_get_pwo_pin ( co23_t *ctx );
617
628uint8_t co23_get_int_pin ( co23_t *ctx );
629
630#ifdef __cplusplus
631}
632#endif
633#endif // CO23_H
634
635 // co23
636
637// ------------------------------------------------------------------------ END
co23_soft_reset_value_t
CO2 3 Click soft reset command value data.
Definition co23.h:299
@ CO23_CMD_SOFT_RESET
Definition co23.h:300
@ CO23_CMD_RESET_FCS
Definition co23.h:304
@ CO23_CMD_SAVE_FCS_CALIB_OFFSET
Definition co23.h:303
@ CO23_CMD_RESET_ABOC
Definition co23.h:301
@ CO23_CMD_STEPWISE_FILTER_DIS
Definition co23.h:302
@ CO23_CMD_STEPWISE_FILTER_EN
Definition co23.h:305
err_t(* co23_master_io_t)(struct co23_s *, uint8_t, uint8_t *, uint8_t)
CO2 3 Click driver interface.
Definition co23.h:175
co23_return_value_t
CO2 3 Click return value data.
Definition co23.h:314
@ CO23_ERROR
Definition co23.h:316
@ CO23_OK
Definition co23.h:315
struct co23_s co23_t
CO2 3 Click context object.
co23_drv_t
CO2 3 Click driver selector.
Definition co23.h:165
@ CO23_DRV_SEL_UART
Definition co23.h:167
@ CO23_DRV_SEL_I2C
Definition co23.h:166
#define CO23_RX_DRV_BUFFER_SIZE
Definition co23.h:123
#define CO23_TX_DRV_BUFFER_SIZE
CO2 3 driver buffer size.
Definition co23.h:122
uint8_t co23_get_pwo_pin(co23_t *ctx)
CO2 3 get PWM output function.
err_t co23_get_meas_status(co23_t *ctx, co23_meas_status_t *meas_status)
CO2 3 get measurement status function.
err_t co23_get_co2_ppm(co23_t *ctx, uint16_t *co2_ppm)
CO2 3 get CO2 concentration function.
err_t co23_generic_write(co23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
CO2 3 I2C writing function.
err_t co23_get_device_id(co23_t *ctx, uint8_t *prod, uint8_t *rev)
CO2 3 get device ID function.
err_t co23_get_int_cfg(co23_t *ctx, co23_int_cfg_t *int_cfg)
CO2 3 get interrupt pin configuration function.
void co23_drv_interface_selection(co23_cfg_t *cfg, co23_drv_t drv_sel)
CO2 3 driver interface setup function.
err_t co23_soft_reset_trigger(co23_t *ctx, co23_soft_reset_value_t reset_cmd)
CO2 3 soft reset trigger function.
err_t co23_set_meas_cfg(co23_t *ctx, co23_meas_cfg_t meas_cfg)
CO2 3 set measurement configuration function.
err_t co23_set_alarm_threshold(co23_t *ctx, uint16_t alarm_th_ppm)
CO2 3 set alarm threshold function.
err_t co23_generic_read(co23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
CO2 3 I2C reading function.
err_t co23_set_calib_ref(co23_t *ctx, uint16_t calib_ppm)
CO2 3 set calibration function.
err_t co23_default_cfg(co23_t *ctx)
CO2 3 default configuration function.
void co23_cfg_setup(co23_cfg_t *cfg)
CO2 3 configuration object setup function.
uint8_t co23_get_int_pin(co23_t *ctx)
CO2 3 get interrupt function.
err_t co23_set_pressure_ref(co23_t *ctx, uint16_t pressure_mbar)
CO2 3 set alarm threshold function.
err_t co23_set_int_cfg(co23_t *ctx, co23_int_cfg_t int_cfg)
CO2 3 set interrupt pin configuration function.
err_t co23_set_meas_rate(co23_t *ctx, uint16_t meas_rate_sec)
CO2 3 set measurement rate function.
err_t co23_init(co23_t *ctx, co23_cfg_t *cfg)
CO2 3 initialization function.
err_t co23_get_sens_status(co23_t *ctx, co23_sens_status_t *sens_status)
CO2 3 get sensor status function.
err_t co23_get_meas_cfg(co23_t *ctx, co23_meas_cfg_t *meas_cfg)
CO2 3 get measurement configuration function.
CO2 3 Click configuration object.
Definition co23.h:212
uint32_t baud_rate
Definition co23.h:225
pin_name_t pws
Definition co23.h:221
co23_drv_t drv_sel
Definition co23.h:234
uint32_t i2c_speed
Definition co23.h:231
bool uart_blocking
Definition co23.h:226
uart_data_bits_t data_bit
Definition co23.h:227
pin_name_t tx_pin
Definition co23.h:215
pin_name_t pwo
Definition co23.h:220
pin_name_t rx_pin
Definition co23.h:214
uart_stop_bits_t stop_bit
Definition co23.h:229
pin_name_t scl
Definition co23.h:217
pin_name_t int_pin
Definition co23.h:222
uart_parity_t parity_bit
Definition co23.h:228
pin_name_t sda
Definition co23.h:218
uint8_t i2c_address
Definition co23.h:232
CO2 3 Click interrupt configuration object.
Definition co23.h:287
uint8_t alarm_typ
Definition co23.h:290
uint8_t int_func
Definition co23.h:289
uint8_t int_typ
Definition co23.h:288
CO2 3 Click measurement configuration object.
Definition co23.h:260
uint8_t boc_cfg
Definition co23.h:263
uint8_t pwm_mode
Definition co23.h:262
uint8_t pwm_outen
Definition co23.h:261
uint8_t op_mode
Definition co23.h:264
CO2 3 Click measurement status object.
Definition co23.h:273
uint8_t int_sts_clr
Definition co23.h:277
uint8_t alarm
Definition co23.h:276
uint8_t drdy
Definition co23.h:274
uint8_t alarm_clr
Definition co23.h:278
uint8_t int_sts
Definition co23.h:275
CO2 3 Click context object.
Definition co23.h:182
char uart_tx_buffer[CO23_TX_DRV_BUFFER_SIZE]
Definition co23.h:199
co23_drv_t drv_sel
Definition co23.h:201
co23_master_io_t write_f
Definition co23.h:202
co23_master_io_t read_f
Definition co23.h:203
uart_t uart
Definition co23.h:192
digital_in_t int_pin
Definition co23.h:188
i2c_master_t i2c
Definition co23.h:191
char uart_rx_buffer[CO23_RX_DRV_BUFFER_SIZE]
Definition co23.h:198
digital_in_t pwo
Definition co23.h:187
uint8_t slave_address
Definition co23.h:195
digital_out_t pws
Definition co23.h:184
CO2 3 Click sens status object.
Definition co23.h:243
uint8_t pwm_dis_st
Definition co23.h:245
uint8_t ortmp_clr
Definition co23.h:249
uint8_t orvs_clr
Definition co23.h:250
uint8_t iccer_clr
Definition co23.h:251
uint8_t sen_rdy
Definition co23.h:244
uint8_t orvs
Definition co23.h:247
uint8_t iccer
Definition co23.h:248
uint8_t ortmp
Definition co23.h:246