environment4 2.1.0.0
environment4.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 ENVIRONMENT4_H
29#define ENVIRONMENT4_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
73#define ENVIRONMENT4_SGP_CMD_EXE_CONDITIONING 0x2612u
74#define ENVIRONMENT4_SGP_CMD_MEAS_RAW_SIGNALS 0x2619u
75#define ENVIRONMENT4_SGP_CMD_EXE_SELF_TEST 0x280Eu
76#define ENVIRONMENT4_SGP_TURN_HEATER_OFF 0x3615u
77#define ENVIRONMENT4_SGP_GET_SERIAL_NUMBER 0x3682u
78
83#define ENVIRONMENT4_SHT_CMD_MEAS_TH_HIGH_PREC 0xFD
84#define ENVIRONMENT4_SHT_CMD_MEAS_TH_MED_PREC 0xF6
85#define ENVIRONMENT4_SHT_CMD_MEAS_TH_LOW_PREC 0xE0
86#define ENVIRONMENT4_SHT_CMD_READ_SERIAL_NUM 0x89
87#define ENVIRONMENT4_SHT_CMD_SOFT_RESET 0x94
88#define ENVIRONMENT4_SHT_CMD_ACT_HEATER_200mW_1S 0x39
89#define ENVIRONMENT4_SHT_CMD_ACT_HEATER_200mW_0p1S 0x32
90#define ENVIRONMENT4_SHT_CMD_ACT_HEATER_110mW_1S 0x2F
91#define ENVIRONMENT4_SHT_CMD_ACT_HEATER_110mW_0p1S 0x24
92#define ENVIRONMENT4_SHT_CMD_ACT_HEATER_20mW_1S 0x1E
93#define ENVIRONMENT4_SHT_CMD_ACT_HEATER_20mW_0p1S 0x15
94
95 // environment4_reg
96
111#define ENVIRONMENT4_SGP_SELF_TEST_OK 0x00
112#define ENVIRONMENT4_SGP_SELF_TEST_VOC_PIXEL 0x01
113#define ENVIRONMENT4_SGP_SELF_TEST_NOX_PIXEL 0x02
114#define ENVIRONMENT4_SGP_SELF_TEST_MASK 0x03
115
120#define ENVIRONMENT4_SHT_MAX_RH 100.0
121#define ENVIRONMENT4_SHT_MIN_RH 0.0
122#define ENVIRONMENT4_SHT_DATA_RESOLUTION 65535.0
123#define ENVIRONMENT4_SHT_ABS_MIN_TEMP ( -45.0 )
124#define ENVIRONMENT4_SHT_ABS_MAX_TEMP ( 130.0 )
125#define ENVIRONMENT4_SHT_ABS_MIN_HUM ( -6.0 )
126#define ENVIRONMENT4_SHT_ABS_MAX_HUM ( 119.0 )
127
133#define ENVIRONMENT4_SHT_DEVICE_ADDRESS 0x44
134#define ENVIRONMENT4_SGP_DEVICE_ADDRESS 0x59
135
136 // environment4_set
137
152#define ENVIRONMENT4_MAP_MIKROBUS( cfg, mikrobus ) \
153 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
154 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
155
156 // environment4_map
157 // environment4
158
163typedef struct
164{
165 // Modules
166 i2c_master_t i2c;
168 // I2C slave address
172
177typedef struct
178{
179 pin_name_t scl;
180 pin_name_t sda;
182 uint32_t i2c_speed;
183 uint8_t i2c_address;
186
197
214
229
250err_t environment4_sgp_exe_conditioning ( environment4_t *ctx, uint16_t comp_rh, uint16_t comp_t,
251 uint16_t *sraw_voc );
252
272err_t environment4_sgp_meas_raw_signals ( environment4_t *ctx, uint16_t comp_rh, uint16_t comp_t,
273 uint16_t *sraw_voc, uint16_t *sraw_nox );
274
290err_t environment4_sgp_exe_self_test ( environment4_t *ctx, uint8_t *test_result );
291
304
316err_t environment4_sgp_get_serial_num ( environment4_t *ctx, uint16_t *serial_num );
317
329err_t environment4_sht_send_cmd ( environment4_t *ctx, uint8_t cmd );
330
343err_t environment4_sht_read_response ( environment4_t *ctx, uint8_t *data_out );
344
356
368err_t environment4_sht_read_serial_num ( environment4_t *ctx, uint32_t *serial_num );
369
382err_t environment4_sht_read_meas_hp ( environment4_t *ctx, float *temp, float *hum );
383
384#ifdef __cplusplus
385}
386#endif
387#endif // ENVIRONMENT4_H
388
389 // environment4
390
391// ------------------------------------------------------------------------ END
environment4_return_value_t
Environment 4 Click return value data.
Definition environment4.h:192
@ ENVIRONMENT4_OK
Definition environment4.h:193
@ ENVIRONMENT4_ERROR
Definition environment4.h:194
err_t environment4_sht_read_meas_hp(environment4_t *ctx, float *temp, float *hum)
Environment 4 sht read meas hp function.
err_t environment4_sgp_turn_heater_off(environment4_t *ctx)
Environment 4 sgp turn heater off function.
err_t environment4_sgp_get_serial_num(environment4_t *ctx, uint16_t *serial_num)
Environment 4 sgp get serial num function.
void environment4_cfg_setup(environment4_cfg_t *cfg)
Environment 4 configuration object setup function.
err_t environment4_sgp_exe_self_test(environment4_t *ctx, uint8_t *test_result)
Environment 4 sgp exe self test function.
err_t environment4_sht_read_response(environment4_t *ctx, uint8_t *data_out)
Environment 4 sht read response function.
err_t environment4_sgp_exe_conditioning(environment4_t *ctx, uint16_t comp_rh, uint16_t comp_t, uint16_t *sraw_voc)
Environment 4 sgp exe conditioning function.
err_t environment4_init(environment4_t *ctx, environment4_cfg_t *cfg)
Environment 4 initialization function.
err_t environment4_sgp_meas_raw_signals(environment4_t *ctx, uint16_t comp_rh, uint16_t comp_t, uint16_t *sraw_voc, uint16_t *sraw_nox)
Environment 4 sgp meas raw signals function.
err_t environment4_sht_send_cmd(environment4_t *ctx, uint8_t cmd)
Environment 4 sht send cmd function.
err_t environment4_sht_read_serial_num(environment4_t *ctx, uint32_t *serial_num)
Environment 4 sht read serial num function.
err_t environment4_sht_soft_reset(environment4_t *ctx)
Environment 4 sht soft reset function.
Environment 4 Click configuration object.
Definition environment4.h:178
uint32_t i2c_speed
Definition environment4.h:182
pin_name_t scl
Definition environment4.h:179
pin_name_t sda
Definition environment4.h:180
uint8_t i2c_address
Definition environment4.h:183
Environment 4 Click context object.
Definition environment4.h:164
i2c_master_t i2c
Definition environment4.h:166
uint8_t slave_address
Definition environment4.h:169