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
32 extern "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  // 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  // hvac_map // hvac
161 
166 typedef struct
167 {
168  uint16_t co2_concent;
169  float temperature;
170  float r_humidity;
174 
179 typedef struct
180 {
181  uint8_t product_type;
182  uint8_t platform_type;
186 
191 typedef struct
192 {
193  float mass_pm_1_0;
194  float mass_pm_2_5;
195  float mass_pm_4_0;
196  float mass_pm_10;
197  float num_pm_0_5;
198  float num_pm_1_0;
199  float num_pm_2_5;
200  float num_pm_4_0;
201  float num_pm_10;
204 
209 typedef struct
210 {
211  // Modules
212  i2c_master_t i2c;
213  uart_t uart;
215  // I2C slave address
216  uint8_t slave_address;
218 } hvac_t;
219 
224 typedef 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 
238 typedef enum
239 {
240  HVAC_OK = 0,
241  HVAC_ERROR = -1
242 
244 
261 
276 err_t hvac_init ( hvac_t *ctx, hvac_cfg_t *cfg );
277 
293 err_t hvac_generic_write ( hvac_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
294 
310 err_t hvac_generic_read ( hvac_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
311 
312 
327 err_t hvac_scd40_write_data ( hvac_t *ctx, uint16_t reg, uint16_t tx_data );
328 
343 err_t hvac_scd40_read_data ( hvac_t *ctx, uint16_t reg, uint16_t *rx_data );
353 void hvac_scd40_send_cmd ( hvac_t *ctx, uint16_t cmd );
354 
366 
377 void hvac_scd40_get_serial_number ( hvac_t *ctx, uint16_t *serial_number );
378 
390 
401 void hvac_scd40_set_temperature_offset ( hvac_t *ctx, float temp_offset );
402 
413 
429 err_t hvac_sps30_i2c_write_data ( hvac_t *ctx, uint16_t reg, uint16_t tx_data );
430 
446 err_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  // hvac
513 
514 // ------------------------------------------------------------------------ END
mass_and_num_cnt_data_t::mass_pm_10
float mass_pm_10
Definition: hvac.h:196
mass_and_num_cnt_data_t::mass_pm_2_5
float mass_pm_2_5
Definition: hvac.h:194
hvac_scd40_get_feature_set_version
void hvac_scd40_get_feature_set_version(hvac_t *ctx, feature_data_t *f_data)
SCD40 get feature set version function.
hvac_scd40_set_temperature_offset
void hvac_scd40_set_temperature_offset(hvac_t *ctx, float temp_offset)
SCD40 set temperature offset function.
hvac_sps30_stop_measurement
void hvac_sps30_stop_measurement(hvac_t *ctx)
SPS30 stop measurement command function.
hvac_sps30_i2c_write_data
err_t hvac_sps30_i2c_write_data(hvac_t *ctx, uint16_t reg, uint16_t tx_data)
SPS30 generic write data function.
hvac_t::i2c
i2c_master_t i2c
Definition: hvac.h:212
mass_and_num_cnt_data_t::num_pm_10
float num_pm_10
Definition: hvac.h:201
hvac_sps30_start_measurement
void hvac_sps30_start_measurement(hvac_t *ctx)
SPS30 start measurement command function.
hvac_cfg_t::i2c_address
uint8_t i2c_address
Definition: hvac.h:230
hvac_t
HVAC Click context object.
Definition: hvac.h:210
mass_and_num_cnt_data_t::num_pm_2_5
float num_pm_2_5
Definition: hvac.h:199
measuremen_data_t::asc_update_count
uint16_t asc_update_count
Definition: hvac.h:171
measuremen_data_t::asc_last_correction
uint16_t asc_last_correction
Definition: hvac.h:172
mass_and_num_cnt_data_t::mass_pm_1_0
float mass_pm_1_0
Definition: hvac.h:193
hvac_sps30_read_measured_data
void hvac_sps30_read_measured_data(hvac_t *ctx, mass_and_num_cnt_data_t *m_n_c_data)
SPS30 read measured data function.
hvac_generic_write
err_t hvac_generic_write(hvac_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
HVAC I2C writing function.
hvac_sps30_i2c_read_data
err_t hvac_sps30_i2c_read_data(hvac_t *ctx, uint16_t reg, uint16_t *rx_data)
SPS30 generic read data function.
hvac_t::uart
uart_t uart
Definition: hvac.h:213
hvac_scd40_get_temperature_offset
float hvac_scd40_get_temperature_offset(hvac_t *ctx)
SCD40 get temperature offset function.
hvac_cfg_t::sda
pin_name_t sda
Definition: hvac.h:227
hvac_sps30_device_reset
void hvac_sps30_device_reset(hvac_t *ctx)
SPS30 set device reset function.
hvac_scd40_write_data
err_t hvac_scd40_write_data(hvac_t *ctx, uint16_t reg, uint16_t tx_data)
SCD40 generic write data function.
mass_and_num_cnt_data_t::mass_pm_4_0
float mass_pm_4_0
Definition: hvac.h:195
hvac_scd40_read_measurement
void hvac_scd40_read_measurement(hvac_t *ctx, measuremen_data_t *m_data)
SCD40 read measurement function.
hvac_scd40_send_cmd
void hvac_scd40_send_cmd(hvac_t *ctx, uint16_t cmd)
SCD40 send command function.
hvac_cfg_setup
void hvac_cfg_setup(hvac_cfg_t *cfg)
HVAC configuration object setup function.
HVAC_ERROR
@ HVAC_ERROR
Definition: hvac.h:241
hvac_generic_read
err_t hvac_generic_read(hvac_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
HVAC I2C reading function.
hvac_scd40_read_data
err_t hvac_scd40_read_data(hvac_t *ctx, uint16_t reg, uint16_t *rx_data)
SCD40 generic read data function.
HVAC_OK
@ HVAC_OK
Definition: hvac.h:240
measuremen_data_t::temperature
float temperature
Definition: hvac.h:169
mass_and_num_cnt_data_t::num_pm_1_0
float num_pm_1_0
Definition: hvac.h:198
hvac_scd40_get_serial_number
void hvac_scd40_get_serial_number(hvac_t *ctx, uint16_t *serial_number)
SCD40 get serial number function.
hvac_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hvac.h:229
feature_data_t::product_major_version
uint8_t product_major_version
Definition: hvac.h:183
feature_data_t::platform_type
uint8_t platform_type
Definition: hvac.h:182
feature_data_t
HVAC Click feature data object.
Definition: hvac.h:180
hvac_return_value_t
hvac_return_value_t
HVAC Click return value data.
Definition: hvac.h:239
mass_and_num_cnt_data_t::num_pm_4_0
float num_pm_4_0
Definition: hvac.h:200
feature_data_t::product_type
uint8_t product_type
Definition: hvac.h:181
mass_and_num_cnt_data_t
HVAC Click mass and number of particles object.
Definition: hvac.h:192
hvac_init
err_t hvac_init(hvac_t *ctx, hvac_cfg_t *cfg)
HVAC initialization function.
measuremen_data_t::co2_concent
uint16_t co2_concent
Definition: hvac.h:168
hvac_sps30_get_ready_flag
uint8_t hvac_sps30_get_ready_flag(hvac_t *ctx)
SPS30 get ready flag function.
hvac_cfg_t::scl
pin_name_t scl
Definition: hvac.h:226
hvac_cfg_t
HVAC Click configuration object.
Definition: hvac.h:225
mass_and_num_cnt_data_t::num_pm_0_5
float num_pm_0_5
Definition: hvac.h:197
hvac_t::slave_address
uint8_t slave_address
Definition: hvac.h:216
feature_data_t::product_minor_version
uint8_t product_minor_version
Definition: hvac.h:184
mass_and_num_cnt_data_t::typ_ptcl_size
float typ_ptcl_size
Definition: hvac.h:202
measuremen_data_t
HVAC Click measurements object.
Definition: hvac.h:167
measuremen_data_t::r_humidity
float r_humidity
Definition: hvac.h:170