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 
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 
75 #define HVAC_START_PERIODIC_MEASUREMENT 0x21B1
76 #define HVAC_START_LOW_POWER_PERIODIC_MEASUREMENT 0x21AC
77 #define HVAC_START_ULTRA_LOW_POWER_PERIODIC_MEASUREMENT 0x21A7
78 #define HVAC_MEASURE_SINGLE_SHOT 0x219D
79 #define HVAC_MEASURE_SINGLE_SHOT_RHT_ONLY 0x2196
80 #define HVAC_READ_MEASUREMENT 0xEC05
81 #define HVAC_STOP_PERIODIC_MEASUREMENT 0x3F86
82 #define HVAC_GET_SERIAL_NUMBER 0x3682
83 #define HVAC_GET_FEATURE_SET_VERSION 0x202F
84 #define HVAC_GET_TEMPERATURE_OFFSET 0x2318
85 #define HVAC_SET_TEMPERATURE_OFFSET 0x241D
86 #define HVAC_PERFORM_FORCED_RECALIBRATION 0x362F
87 #define HVAC_GET_AUTOMATIC_SELF_CALIBRATION_ENABLED 0x2313
88 #define HVAC_SET_AUTOMATIC_SELF_CALIBRATION_ENABLED 0x2416
89 #define HVAC_GET_AUTOMATIC_SELF_CALIBRATION_INITIAL_PERIOD 0x2340
90 #define HVAC_SET_AUTOMATIC_SELF_CALIBRATION_INITIAL_PERIOD 0x2445
91 #define HVAC_GET_AUTOMATIC_SELF_CALIBRATION_STANDARD_PERIOD 0x234B
92 #define HVAC_SET_AUTOMATIC_SELF_CALIBRATION_STANDARD_PERIOD 0x244E
93 #define HVAC_PERSIST_SETTINGS 0x3615
94 #define HVAC_PERFORM_FACTORY_RESET 0x3632
95 #define HVAC_REINIT 0x3646
96 
101 #define HVAC_SPS30_I2C_START_MEASUREMENT 0x0010
102 #define HVAC_SPS30_I2C_STOP_MEASUREMENT 0x0104
103 #define HVAC_SPS30_I2C_READ_DATA_RDY_FLAG 0x0202
104 #define HVAC_SPS30_I2C_READ_MEASURED_VALUE 0x0300
105 #define HVAC_SPS30_I2C_SLEEP 0x1001
106 #define HVAC_SPS30_I2C_WAKEUP 0x1103
107 #define HVAC_SPS30_I2C_START_FAN_CLEANING 0x5607
108 #define HVAC_SPS30_I2C_AUTO_CLEANING_INTERVAL 0x8004
109 #define HVAC_SPS30_I2C_SET_AUTO_CLEANING_INTERVAL 0x8005
110 #define HVAC_SPS30_I2C_STOP_MEASUREMENT_DUMMY 0x0000
111 
112 #define HVAC_SPS30_I2C_READ_PRODUCT_TYPE 0xD002
113 #define HVAC_SPS30_I2C_READ_SERIAL_NUMBER 0xD033
114 #define HVAC_SPS30_I2C_READ_VERSION 0xD100
115 #define HVAC_SPS30_I2C_READ_STATUS_REGISTER 0xD206
116 #define HVAC_SPS30_I2C_CLEAR_STATUS_REGISTER 0xD210
117 #define HVAC_SPS30_I2C_RESET 0xD304
118 
123 #define HVAC_SPS30_NEW_DATA_NOT_READY 0x00
124 #define HVAC_SPS30_NEW_DATA_IS_READY 0x01
125 
131 #define HVAC_SPS30_SLAVE_ADDR 0x69
132 #define HVAC_SCD40_SLAVE_ADDR 0x62
133 
134  // hvac_set
136 
151 #define HVAC_MAP_MIKROBUS( cfg, mikrobus ) \
152  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
153  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
154  // hvac_map // hvac
157 
162 typedef struct
163 {
164  uint16_t co2_concent;
165  float temperature;
166  float r_humidity;
170 
175 typedef struct
176 {
177  uint8_t product_type;
178  uint8_t platform_type;
182 
187 typedef struct
188 {
189  float mass_pm_1_0;
190  float mass_pm_2_5;
191  float mass_pm_4_0;
192  float mass_pm_10;
193  float num_pm_0_5;
194  float num_pm_1_0;
195  float num_pm_2_5;
196  float num_pm_4_0;
197  float num_pm_10;
200 
205 typedef struct
206 {
207  // Modules
208  i2c_master_t i2c;
209  uart_t uart;
211  // I2C slave address
212  uint8_t slave_address;
214 } hvac_t;
215 
220 typedef struct
221 {
222  pin_name_t scl;
223  pin_name_t sda;
225  uint32_t i2c_speed;
226  uint8_t i2c_address;
228 } hvac_cfg_t;
229 
234 typedef enum
235 {
236  HVAC_OK = 0,
237  HVAC_ERROR = -1
238 
240 
257 
272 err_t hvac_init ( hvac_t *ctx, hvac_cfg_t *cfg );
273 
289 err_t hvac_generic_write ( hvac_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
290 
306 err_t hvac_generic_read ( hvac_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
307 
308 
323 err_t hvac_scd40_write_data ( hvac_t *ctx, uint16_t reg, uint16_t tx_data );
324 
339 err_t hvac_scd40_read_data ( hvac_t *ctx, uint16_t reg, uint16_t *rx_data );
349 void hvac_scd40_send_cmd ( hvac_t *ctx, uint16_t cmd );
350 
362 
373 void hvac_scd40_get_serial_number ( hvac_t *ctx, uint16_t *serial_number );
374 
386 
397 void hvac_scd40_set_temperature_offset ( hvac_t *ctx, float temp_offset );
398 
409 
425 err_t hvac_sps30_i2c_write_data ( hvac_t *ctx, uint16_t reg, uint16_t tx_data );
426 
442 err_t hvac_sps30_i2c_read_data ( hvac_t *ctx, uint16_t reg, uint16_t *rx_data );
443 
454 
465 
476 
490 
502 
503 #ifdef __cplusplus
504 }
505 #endif
506 #endif // HVAC_H
507  // hvac
509 
510 // ------------------------------------------------------------------------ END
mass_and_num_cnt_data_t::mass_pm_10
float mass_pm_10
Definition: hvac.h:192
mass_and_num_cnt_data_t::mass_pm_2_5
float mass_pm_2_5
Definition: hvac.h:190
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:208
mass_and_num_cnt_data_t::num_pm_10
float num_pm_10
Definition: hvac.h:197
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:226
hvac_t
HVAC Click context object.
Definition: hvac.h:206
mass_and_num_cnt_data_t::num_pm_2_5
float num_pm_2_5
Definition: hvac.h:195
measuremen_data_t::asc_update_count
uint16_t asc_update_count
Definition: hvac.h:167
measuremen_data_t::asc_last_correction
uint16_t asc_last_correction
Definition: hvac.h:168
mass_and_num_cnt_data_t::mass_pm_1_0
float mass_pm_1_0
Definition: hvac.h:189
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:209
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:223
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:191
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:237
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:236
measuremen_data_t::temperature
float temperature
Definition: hvac.h:165
mass_and_num_cnt_data_t::num_pm_1_0
float num_pm_1_0
Definition: hvac.h:194
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:225
feature_data_t::product_major_version
uint8_t product_major_version
Definition: hvac.h:179
feature_data_t::platform_type
uint8_t platform_type
Definition: hvac.h:178
feature_data_t
HVAC Click feature data object.
Definition: hvac.h:176
hvac_return_value_t
hvac_return_value_t
HVAC Click return value data.
Definition: hvac.h:235
mass_and_num_cnt_data_t::num_pm_4_0
float num_pm_4_0
Definition: hvac.h:196
feature_data_t::product_type
uint8_t product_type
Definition: hvac.h:177
mass_and_num_cnt_data_t
HVAC Click mass and number of particles object.
Definition: hvac.h:188
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:164
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:222
hvac_cfg_t
HVAC Click configuration object.
Definition: hvac.h:221
mass_and_num_cnt_data_t::num_pm_0_5
float num_pm_0_5
Definition: hvac.h:193
hvac_t::slave_address
uint8_t slave_address
Definition: hvac.h:212
feature_data_t::product_minor_version
uint8_t product_minor_version
Definition: hvac.h:180
mass_and_num_cnt_data_t::typ_ptcl_size
float typ_ptcl_size
Definition: hvac.h:198
measuremen_data_t
HVAC Click measurements object.
Definition: hvac.h:163
measuremen_data_t::r_humidity
float r_humidity
Definition: hvac.h:166