environment2  2.0.0.0
environment2.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 ENVIRONMENT2_H
29 #define ENVIRONMENT2_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define ENVIRONMENT2_SGP40_CMD_MEASURE_RAW 0x260F
60 #define ENVIRONMENT2_SGP40_CMD_MEASURE_TEST 0x280E
61 #define ENVIRONMENT2_SGP40_CMD_HEATER_OFF 0x3615
62 #define ENVIRONMENT2_SGP40_CMD_SOFT_RESET 0x0006
63 
68 #define ENVIRONMENT2_SHT40_CMD_MEASURE_T_RH_HIGH_PRECISION 0xFD
69 #define ENVIRONMENT2_SHT40_CMD_MEASURE_T_RH_MEDIUM_PRECISION 0xF6
70 #define ENVIRONMENT2_SHT40_CMD_MEASURE_T_RH_LOWEST_PRECISION 0xE0
71 #define ENVIRONMENT2_SHT40_CMD_READ_SERIAL 0x89
72 #define ENVIRONMENT2_SHT40_CMD_SOFT_RESET 0x94
73 #define ENVIRONMENT2_SHT40_CMD_ACTIVATE_HIGHEST_HEATER_1SEC 0x39
74 #define ENVIRONMENT2_SHT40_CMD_ACTIVATE_HIGHEST_HEATER_0_1SEC 0x32
75 #define ENVIRONMENT2_SHT40_CMD_ACTIVATE_MEDIUM_HEATER_1SEC 0x2F
76 #define ENVIRONMENT2_SHT40_CMD_ACTIVATE_MEDIUM_HEATER_0_1SEC 0x24
77 #define ENVIRONMENT2_SHT40_CMD_ACTIVATE_LOWEST_HEATER_1SEC 0x1E
78 #define ENVIRONMENT2_SHT40_CMD_ACTIVATE_LOWEST_HEATER_0_1SEC 0x15
79  // environment2_cmd
81 
97 #define ENVIRONMENT2_SGP40_SET_DEV_ADDR 0x59
98 #define ENVIRONMENT2_SHT40_SET_DEV_ADDR 0x44
99 
105 #define ENVIRONMENT2_SEL_SGP40 0x00
106 #define ENVIRONMENT2_SEL_SHT40 0x01
107  // environment2_set
109 
119 #define ENVIRONMENT2_SGP40_TEST_PASSED 0xD400
120 #define ENVIRONMENT2_SGP40_TEST_FAILED 0x4B00
121 
122  // environment2_get
124 
139 #define ENVIRONMENT2_MAP_MIKROBUS( cfg, mikrobus ) \
140  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
141  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
142  // environment2_map // environment2
145 
150 typedef struct
151 {
152  // Modules
153 
154  i2c_master_t i2c;
156  // I2C slave address
157 
158  uint8_t slave_address;
161 
166 typedef struct
167 {
168  pin_name_t scl;
169  pin_name_t sda;
171  uint32_t i2c_speed;
172  uint8_t i2c_address;
175 
180 typedef enum
181 {
183  ENVIRONMENT2_ERROR = -1
184 
186 
205 
223 
241 err_t environment2_generic_write ( environment2_t *ctx, uint8_t select_device, uint16_t cmd, uint8_t *tx_buf );
242 
260 err_t environment2_generic_read ( environment2_t *ctx, uint8_t select_device, uint16_t cmd, uint8_t *rx_buf );
261 
280 err_t environment2_get_temp_hum ( environment2_t *ctx, float *humidity, float *temperature );
281 
298 err_t environment2_get_air_quality ( environment2_t *ctx, uint16_t *air_quality );
299 
318 
335 
353 
354 #ifdef __cplusplus
355 }
356 #endif
357 #endif // ENVIRONMENT2_H
358  // environment2
360 
361 // ------------------------------------------------------------------------ END
environment2_return_value_t
environment2_return_value_t
Environment 2 Click return value data.
Definition: environment2.h:181
environment2_cfg_t::i2c_address
uint8_t i2c_address
Definition: environment2.h:172
environment2_cfg_setup
void environment2_cfg_setup(environment2_cfg_t *cfg)
Environment 2 configuration object setup function.
environment2_cfg_t::scl
pin_name_t scl
Definition: environment2.h:168
ENVIRONMENT2_OK
@ ENVIRONMENT2_OK
Definition: environment2.h:182
environment2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: environment2.h:171
ENVIRONMENT2_ERROR
@ ENVIRONMENT2_ERROR
Definition: environment2.h:183
environment2_get_air_quality
err_t environment2_get_air_quality(environment2_t *ctx, uint16_t *air_quality)
Environment 2 get air quality data function.
environment2_generic_read
err_t environment2_generic_read(environment2_t *ctx, uint8_t select_device, uint16_t cmd, uint8_t *rx_buf)
Environment 2 I2C reading function.
environment2_sgp40_measure_test
uint16_t environment2_sgp40_measure_test(environment2_t *ctx)
Environment 2 SGP40 measurement test function.
environment2_t
Environment 2 Click context object.
Definition: environment2.h:151
environment2_sgp40_soft_reset
err_t environment2_sgp40_soft_reset(environment2_t *ctx)
Environment 2 soft reset function.
environment2_sgp40_heater_off
err_t environment2_sgp40_heater_off(environment2_t *ctx)
Environment 2 heater off function.
environment2_get_temp_hum
err_t environment2_get_temp_hum(environment2_t *ctx, float *humidity, float *temperature)
Environment 2 get temperature and relative humidity function.
environment2_generic_write
err_t environment2_generic_write(environment2_t *ctx, uint8_t select_device, uint16_t cmd, uint8_t *tx_buf)
Environment 2 I2C writing function.
environment2_t::slave_address
uint8_t slave_address
Definition: environment2.h:158
environment2_cfg_t::sda
pin_name_t sda
Definition: environment2.h:169
environment2_t::i2c
i2c_master_t i2c
Definition: environment2.h:154
environment2_init
err_t environment2_init(environment2_t *ctx, environment2_cfg_t *cfg)
Environment 2 initialization function.
environment2_cfg_t
Environment 2 Click configuration object.
Definition: environment2.h:167