Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
environment2_drv.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_DRV_H
29 #define ENVIRONMENT2_DRV_H
30 
31 #include "drv_digital_in.h"
32 #include "drv_digital_out.h"
33 #include "drv_i2c_master.h"
34 
35 /* added for tvoc sampling interval */
36 extern uint32_t sgp40_sampling_interval;
37 
42 #define ENVIRONMENT2_SGP40_CMD_MEASURE_RAW 0x260F
43 #define ENVIRONMENT2_SGP40_CMD_MEASURE_TEST 0x280E
44 #define ENVIRONMENT2_SGP40_CMD_HEATER_OFF 0x3615
45 #define ENVIRONMENT2_SGP40_CMD_SOFT_RESET 0x0006
46 
51 #define ENVIRONMENT2_SHT40_CMD_MEASURE_T_RH_HIGH_PRECISION 0xFD
52 #define ENVIRONMENT2_SHT40_CMD_MEASURE_T_RH_MEDIUM_PRECISION 0xF6
53 #define ENVIRONMENT2_SHT40_CMD_MEASURE_T_RH_LOWEST_PRECISION 0xE0
54 #define ENVIRONMENT2_SHT40_CMD_READ_SERIAL 0x89
55 #define ENVIRONMENT2_SHT40_CMD_SOFT_RESET 0x94
56 #define ENVIRONMENT2_SHT40_CMD_ACTIVATE_HIGHEST_HEATER_1SEC 0x39
57 #define ENVIRONMENT2_SHT40_CMD_ACTIVATE_HIGHEST_HEATER_0_1SEC 0x32
58 #define ENVIRONMENT2_SHT40_CMD_ACTIVATE_MEDIUM_HEATER_1SEC 0x2F
59 #define ENVIRONMENT2_SHT40_CMD_ACTIVATE_MEDIUM_HEATER_0_1SEC 0x24
60 #define ENVIRONMENT2_SHT40_CMD_ACTIVATE_LOWEST_HEATER_1SEC 0x1E
61 #define ENVIRONMENT2_SHT40_CMD_ACTIVATE_LOWEST_HEATER_0_1SEC 0x15
62 
68 #define ENVIRONMENT2_SGP40_SET_DEV_ADDR 0x59
69 #define ENVIRONMENT2_SHT40_SET_DEV_ADDR 0x44
70 
76 #define ENVIRONMENT2_SEL_SGP40 0x00
77 #define ENVIRONMENT2_SEL_SHT40 0x01
78 
84 #define F16(x) ((fix16_t)(((x) >= 0) ? ((x)*65536.0 + 0.5) : ((x)*65536.0 - 0.5)))
85 // MODIFIED: replaced
86 // #define VocAlgorithm_SAMPLING_INTERVAL (5.) // MODIFIED: (1.)
87 #define VocAlgorithm_SAMPLING_INTERVAL ((float)(sgp40_sampling_interval) / 1000.0)
88 #define VocAlgorithm_INITIAL_BLACKOUT (45.) // MODIFIED: (45.)
89 #define VocAlgorithm_VOC_INDEX_GAIN (230.)
90 #define VocAlgorithm_SRAW_STD_INITIAL (50.)
91 #define VocAlgorithm_SRAW_STD_BONUS (220.)
92 #define VocAlgorithm_TAU_MEAN_VARIANCE_HOURS (12.)
93 #define VocAlgorithm_TAU_INITIAL_MEAN (20.)
94 #define VocAlgorithm_INIT_DURATION_MEAN ((3600. * 0.75))
95 #define VocAlgorithm_INIT_TRANSITION_MEAN (0.01)
96 #define VocAlgorithm_TAU_INITIAL_VARIANCE (2500.)
97 #define VocAlgorithm_INIT_DURATION_VARIANCE ((3600. * 1.45))
98 #define VocAlgorithm_INIT_TRANSITION_VARIANCE (0.01)
99 #define VocAlgorithm_GATING_THRESHOLD (340.)
100 #define VocAlgorithm_GATING_THRESHOLD_INITIAL (510.)
101 #define VocAlgorithm_GATING_THRESHOLD_TRANSITION (0.09)
102 #define VocAlgorithm_GATING_MAX_DURATION_MINUTES ((60. * 3.))
103 #define VocAlgorithm_GATING_MAX_RATIO (0.3)
104 #define VocAlgorithm_SIGMOID_L (500.)
105 #define VocAlgorithm_SIGMOID_K (-0.0065)
106 #define VocAlgorithm_SIGMOID_X0 (213.)
107 #define VocAlgorithm_VOC_INDEX_OFFSET_DEFAULT (100.)
108 #define VocAlgorithm_LP_TAU_FAST (20.0)
109 #define VocAlgorithm_LP_TAU_SLOW (500.0)
110 #define VocAlgorithm_LP_ALPHA (-0.2)
111 #define VocAlgorithm_PERSISTENCE_UPTIME_GAMMA ((3. * 3600.))
112 #define VocAlgorithm_MEAN_VARIANCE_ESTIMATOR__GAMMA_SCALING (64.)
113 #define VocAlgorithm_MEAN_VARIANCE_ESTIMATOR__FIX16_MAX (32767.)
114 
119 #define ENVIRONMENT2_SGP40_TEST_PASSED 0xD400
120 #define ENVIRONMENT2_SGP40_TEST_FAILED 0x4B00
121 
126 typedef struct
127 {
128  // Modules
129 
130  i2c_master_t i2c;
132  // I2C slave address
133 
134  uint8_t slave_address;
137 
142 typedef struct
143 {
144  pin_name_t scl;
145  pin_name_t sda;
147  uint32_t i2c_speed;
148  uint8_t i2c_address;
151 
152 typedef int32_t fix16_t;
153 
158 typedef struct
159 {
193 
194 /* voc functions */
195 void environment2_voc_config(void);
196 void environment2_voc_algorithm(int32_t sraw, int32_t *voc_index);
197 
198 #endif // ENVIRONMENT2_DRV_H
199  // environment2
201 
202 // ------------------------------------------------------------------------ END
void environment2_voc_algorithm(int32_t sraw, int32_t *voc_index)
Definition: environment2_voc.c:227
uint32_t sgp40_sampling_interval
Definition: devboard_app_click.c:158
void environment2_voc_config(void)
Definition: environment2_voc.c:181
int32_t fix16_t
Definition: environment2_drv.h:152
Environment 2 Click configuration object.
Definition: environment2_drv.h:143
uint32_t i2c_speed
I2C serial speed.
Definition: environment2_drv.h:147
pin_name_t scl
Clock pin descriptor for I2C driver.
Definition: environment2_drv.h:144
pin_name_t sda
Bidirectional data pin descriptor for I2C driver.
Definition: environment2_drv.h:145
uint8_t i2c_address
I2C slave address.
Definition: environment2_drv.h:148
Environment 2 Click context object.
Definition: environment2_drv.h:127
i2c_master_t i2c
I2C driver object.
Definition: environment2_drv.h:130
uint8_t slave_address
Device slave address (used for I2C driver).
Definition: environment2_drv.h:134
Environment 2 Click VOC algorithm object.
Definition: environment2_drv.h:159
fix16_t m_Mean_Variance_Estimator___Sigmoid__L
Definition: environment2_drv.h:180
fix16_t m_Adaptive_Lowpass___X3
Definition: environment2_drv.h:191
bool m_Mean_Variance_Estimator___Initialized
Definition: environment2_drv.h:168
fix16_t m_Mean_Variance_Estimator___Sigmoid__X0
Definition: environment2_drv.h:182
fix16_t m_Mean_Variance_Estimator__Gating_Max_Duration_Minutes
Definition: environment2_drv.h:167
fix16_t mUptime
Definition: environment2_drv.h:164
fix16_t m_Mean_Variance_Estimator___Gamma
Definition: environment2_drv.h:172
fix16_t m_Sigmoid_Scaled__Offset
Definition: environment2_drv.h:185
fix16_t mGating_Max_Duration_Minutes
Definition: environment2_drv.h:162
fix16_t m_Mean_Variance_Estimator___Mean
Definition: environment2_drv.h:169
fix16_t m_Mean_Variance_Estimator__Gamma_Variance
Definition: environment2_drv.h:176
fix16_t m_Adaptive_Lowpass__A2
Definition: environment2_drv.h:187
fix16_t m_Mox_Model__Sraw_Mean
Definition: environment2_drv.h:184
fix16_t m_Mox_Model__Sraw_Std
Definition: environment2_drv.h:183
fix16_t m_Mean_Variance_Estimator___Gamma_Initial_Variance
Definition: environment2_drv.h:174
fix16_t m_Mean_Variance_Estimator__Gamma_Mean
Definition: environment2_drv.h:175
fix16_t m_Mean_Variance_Estimator___Sraw_Offset
Definition: environment2_drv.h:170
fix16_t m_Adaptive_Lowpass___X1
Definition: environment2_drv.h:189
bool m_Adaptive_Lowpass___Initialized
Definition: environment2_drv.h:188
fix16_t m_Mean_Variance_Estimator___Gamma_Initial_Mean
Definition: environment2_drv.h:173
fix16_t m_Adaptive_Lowpass__A1
Definition: environment2_drv.h:186
fix16_t mSraw
Definition: environment2_drv.h:165
fix16_t m_Mean_Variance_Estimator___Std
Definition: environment2_drv.h:171
fix16_t m_Mean_Variance_Estimator___Sigmoid__K
Definition: environment2_drv.h:181
fix16_t m_Adaptive_Lowpass___X2
Definition: environment2_drv.h:190
fix16_t mSraw_Std_Initial
Definition: environment2_drv.h:163
fix16_t mVoc_Index
Definition: environment2_drv.h:166
fix16_t mTau_Mean_Variance_Hours
Definition: environment2_drv.h:161
fix16_t m_Mean_Variance_Estimator___Uptime_Gamma
Definition: environment2_drv.h:177
fix16_t mVoc_Index_Offset
Definition: environment2_drv.h:160
fix16_t m_Mean_Variance_Estimator___Uptime_Gating
Definition: environment2_drv.h:178
fix16_t m_Mean_Variance_Estimator___Gating_Duration_Minutes
Definition: environment2_drv.h:179