hvac 2.0.0.0
hvac.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 HVAC_H
29#define HVAC_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
79#define HVAC_START_PERIODIC_MEASUREMENT 0x21B1
80#define HVAC_START_LOW_POWER_PERIODIC_MEASUREMENT 0x21AC
81#define HVAC_START_ULTRA_LOW_POWER_PERIODIC_MEASUREMENT 0x21A7
82#define HVAC_MEASURE_SINGLE_SHOT 0x219D
83#define HVAC_MEASURE_SINGLE_SHOT_RHT_ONLY 0x2196
84#define HVAC_READ_MEASUREMENT 0xEC05
85#define HVAC_STOP_PERIODIC_MEASUREMENT 0x3F86
86#define HVAC_GET_SERIAL_NUMBER 0x3682
87#define HVAC_GET_FEATURE_SET_VERSION 0x202F
88#define HVAC_GET_TEMPERATURE_OFFSET 0x2318
89#define HVAC_SET_TEMPERATURE_OFFSET 0x241D
90#define HVAC_PERFORM_FORCED_RECALIBRATION 0x362F
91#define HVAC_GET_AUTOMATIC_SELF_CALIBRATION_ENABLED 0x2313
92#define HVAC_SET_AUTOMATIC_SELF_CALIBRATION_ENABLED 0x2416
93#define HVAC_GET_AUTOMATIC_SELF_CALIBRATION_INITIAL_PERIOD 0x2340
94#define HVAC_SET_AUTOMATIC_SELF_CALIBRATION_INITIAL_PERIOD 0x2445
95#define HVAC_GET_AUTOMATIC_SELF_CALIBRATION_STANDARD_PERIOD 0x234B
96#define HVAC_SET_AUTOMATIC_SELF_CALIBRATION_STANDARD_PERIOD 0x244E
97#define HVAC_PERSIST_SETTINGS 0x3615
98#define HVAC_PERFORM_FACTORY_RESET 0x3632
99#define HVAC_REINIT 0x3646
100
105#define HVAC_SPS30_I2C_START_MEASUREMENT 0x0010
106#define HVAC_SPS30_I2C_STOP_MEASUREMENT 0x0104
107#define HVAC_SPS30_I2C_READ_DATA_RDY_FLAG 0x0202
108#define HVAC_SPS30_I2C_READ_MEASURED_VALUE 0x0300
109#define HVAC_SPS30_I2C_SLEEP 0x1001
110#define HVAC_SPS30_I2C_WAKEUP 0x1103
111#define HVAC_SPS30_I2C_START_FAN_CLEANING 0x5607
112#define HVAC_SPS30_I2C_AUTO_CLEANING_INTERVAL 0x8004
113#define HVAC_SPS30_I2C_SET_AUTO_CLEANING_INTERVAL 0x8005
114#define HVAC_SPS30_I2C_STOP_MEASUREMENT_DUMMY 0x0000
115
116#define HVAC_SPS30_I2C_READ_PRODUCT_TYPE 0xD002
117#define HVAC_SPS30_I2C_READ_SERIAL_NUMBER 0xD033
118#define HVAC_SPS30_I2C_READ_VERSION 0xD100
119#define HVAC_SPS30_I2C_READ_STATUS_REGISTER 0xD206
120#define HVAC_SPS30_I2C_CLEAR_STATUS_REGISTER 0xD210
121#define HVAC_SPS30_I2C_RESET 0xD304
122
127#define HVAC_SPS30_NEW_DATA_NOT_READY 0x00
128#define HVAC_SPS30_NEW_DATA_IS_READY 0x01
129
135#define HVAC_SPS30_SLAVE_ADDR 0x69
136#define HVAC_SCD40_SLAVE_ADDR 0x62
137
138
139 // hvac_set
140
155#define HVAC_MAP_MIKROBUS( cfg, mikrobus ) \
156 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
157 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
158
159 // hvac_map
160 // hvac
161
166typedef struct
167{
168 uint16_t co2_concent;
174
186
204
209typedef struct
210{
211 // Modules
212 i2c_master_t i2c;
213 uart_t uart;
215 // I2C slave address
218} hvac_t;
219
224typedef struct
225{
226 pin_name_t scl;
227 pin_name_t sda;
229 uint32_t i2c_speed;
230 uint8_t i2c_address;
232} hvac_cfg_t;
233
238typedef enum
239{
241 HVAC_ERROR = -1
242
244
261
276err_t hvac_init ( hvac_t *ctx, hvac_cfg_t *cfg );
277
293err_t hvac_generic_write ( hvac_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
294
310err_t hvac_generic_read ( hvac_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
311
312
327err_t hvac_scd40_write_data ( hvac_t *ctx, uint16_t reg, uint16_t tx_data );
328
343err_t hvac_scd40_read_data ( hvac_t *ctx, uint16_t reg, uint16_t *rx_data );
353void hvac_scd40_send_cmd ( hvac_t *ctx, uint16_t cmd );
354
366
377void hvac_scd40_get_serial_number ( hvac_t *ctx, uint16_t *serial_number );
378
390
401void hvac_scd40_set_temperature_offset ( hvac_t *ctx, float temp_offset );
402
413
429err_t hvac_sps30_i2c_write_data ( hvac_t *ctx, uint16_t reg, uint16_t tx_data );
430
446err_t hvac_sps30_i2c_read_data ( hvac_t *ctx, uint16_t reg, uint16_t *rx_data );
447
458
469
480
494
506
507#ifdef __cplusplus
508}
509#endif
510#endif // HVAC_H
511
512 // hvac
513
514// ------------------------------------------------------------------------ END
err_t hvac_sps30_i2c_read_data(hvac_t *ctx, uint16_t reg, uint16_t *rx_data)
SPS30 generic read data function.
err_t hvac_generic_write(hvac_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
HVAC I2C writing function.
void hvac_sps30_read_measured_data(hvac_t *ctx, mass_and_num_cnt_data_t *m_n_c_data)
SPS30 read measured data function.
uint8_t hvac_sps30_get_ready_flag(hvac_t *ctx)
SPS30 get ready flag function.
void hvac_sps30_device_reset(hvac_t *ctx)
SPS30 set device reset function.
err_t hvac_init(hvac_t *ctx, hvac_cfg_t *cfg)
HVAC initialization function.
void hvac_scd40_get_feature_set_version(hvac_t *ctx, feature_data_t *f_data)
SCD40 get feature set version function.
void hvac_scd40_read_measurement(hvac_t *ctx, measuremen_data_t *m_data)
SCD40 read measurement function.
float hvac_scd40_get_temperature_offset(hvac_t *ctx)
SCD40 get temperature offset function.
void hvac_scd40_get_serial_number(hvac_t *ctx, uint16_t *serial_number)
SCD40 get serial number function.
err_t hvac_scd40_write_data(hvac_t *ctx, uint16_t reg, uint16_t tx_data)
SCD40 generic write data function.
void hvac_scd40_send_cmd(hvac_t *ctx, uint16_t cmd)
SCD40 send command function.
err_t hvac_generic_read(hvac_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
HVAC I2C reading function.
err_t hvac_scd40_read_data(hvac_t *ctx, uint16_t reg, uint16_t *rx_data)
SCD40 generic read data function.
err_t hvac_sps30_i2c_write_data(hvac_t *ctx, uint16_t reg, uint16_t tx_data)
SPS30 generic write data function.
void hvac_sps30_start_measurement(hvac_t *ctx)
SPS30 start measurement command function.
void hvac_sps30_stop_measurement(hvac_t *ctx)
SPS30 stop measurement command function.
void hvac_cfg_setup(hvac_cfg_t *cfg)
HVAC configuration object setup function.
void hvac_scd40_set_temperature_offset(hvac_t *ctx, float temp_offset)
SCD40 set temperature offset function.
hvac_return_value_t
HVAC Click return value data.
Definition hvac.h:239
@ HVAC_ERROR
Definition hvac.h:241
@ HVAC_OK
Definition hvac.h:240
HVAC Click feature data object.
Definition hvac.h:180
uint8_t product_minor_version
Definition hvac.h:184
uint8_t product_major_version
Definition hvac.h:183
uint8_t product_type
Definition hvac.h:181
uint8_t platform_type
Definition hvac.h:182
HVAC Click configuration object.
Definition hvac.h:225
uint32_t i2c_speed
Definition hvac.h:229
pin_name_t scl
Definition hvac.h:226
pin_name_t sda
Definition hvac.h:227
uint8_t i2c_address
Definition hvac.h:230
HVAC Click context object.
Definition hvac.h:210
uart_t uart
Definition hvac.h:213
i2c_master_t i2c
Definition hvac.h:212
uint8_t slave_address
Definition hvac.h:216
HVAC Click mass and number of particles object.
Definition hvac.h:192
float num_pm_10
Definition hvac.h:201
float num_pm_1_0
Definition hvac.h:198
float mass_pm_10
Definition hvac.h:196
float num_pm_4_0
Definition hvac.h:200
float mass_pm_4_0
Definition hvac.h:195
float mass_pm_2_5
Definition hvac.h:194
float num_pm_2_5
Definition hvac.h:199
float mass_pm_1_0
Definition hvac.h:193
float typ_ptcl_size
Definition hvac.h:202
float num_pm_0_5
Definition hvac.h:197
HVAC Click measurements object.
Definition hvac.h:167
uint16_t co2_concent
Definition hvac.h:168
uint16_t asc_last_correction
Definition hvac.h:172
uint16_t asc_update_count
Definition hvac.h:171
float r_humidity
Definition hvac.h:170
float temperature
Definition hvac.h:169