-
Notifications
You must be signed in to change notification settings - Fork 21
/
scd4x_i2c.h
378 lines (348 loc) · 13.2 KB
/
scd4x_i2c.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/*
* THIS FILE IS AUTOMATICALLY GENERATED AND MUST NOT BE EDITED MANUALLY!
*
* I2C-Generator: 0.2.0
* Yaml Version: 0.1.0
* Template Version: 0.2.1
*/
/*
* Copyright (c) 2021, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Sensirion AG nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SCD4X_I2C_H
#define SCD4X_I2C_H
#ifdef __cplusplus
extern "C" {
#endif
#include "sensirion_config.h"
/**
* scd4x_start_periodic_measurement() - start periodic measurement, signal
* update interval is 5 seconds.
*
* @note This command is only available in idle mode.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_start_periodic_measurement(void);
/**
* scd4x_read_measurement_ticks() - read sensor output. The measurement data can
* only be read out once per signal update interval as the buffer is emptied
* upon read-out. If no data is available in the buffer, the sensor returns a
* NACK. To avoid a NACK response the get_data_ready_flag can be issued to
* check data status. The I2C master can abort the read transfer with a NACK
* followed by a STOP condition after any data byte if the user is not
* interested in subsequent data.
*
* @note This command is only available in measurement mode. The firmware
* updates the measurement values depending on the measurement mode.
*
* @param co2 CO₂ concentration in ppm
*
* @param temperature Convert value to °C by: -45 °C + 175 °C * value/2^16
*
* @param humidity Convert value to %RH by: 100%RH * value/2^16
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_read_measurement_ticks(uint16_t* co2, uint16_t* temperature,
uint16_t* humidity);
/**
* scd4x_read_measurement() - read sensor output and convert.
* See @ref scd4x_read_measurement_ticks() for more details.
*
* @note This command is only available in measurement mode. The firmware
* updates the measurement values depending on the measurement mode.
*
* @param co2 CO₂ concentration in ppm
*
* @param temperature_m_deg_c Temperature in milli degrees celsius (°C * 1000)
*
* @param humidity_m_percent_rh Relative humidity in milli percent RH
* (%RH * 1000)
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_read_measurement(uint16_t* co2, int32_t* temperature_m_deg_c,
int32_t* humidity_m_percent_rh);
/**
* scd4x_stop_periodic_measurement() - Stop periodic measurement and return to
* idle mode for sensor configuration or to safe energy.
*
* @note This command is only available in measurement mode.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_stop_periodic_measurement(void);
/**
* scd4x_get_temperature_offset_ticks() - The temperature offset represents the
* difference between the measured temperature by the SCD4x and the actual
* ambient temperature. Per default, the temperature offset is set to 4°C.
*
* @note Only available in idle mode.
*
* @param t_offset Temperature offset. Convert value to °C by: 175 * value /
* 2^16
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_get_temperature_offset_ticks(uint16_t* t_offset);
/**
* scd4x_get_temperature_offset() - The temperature offset represents the
* difference between the measured temperature by the SCD4x and the actual
* ambient temperature. Per default, the temperature offset is set to 4°C.
*
* @note Only available in idle mode.
*
* @param t_offset_m_deg_c Temperature offset in milli degrees Celsius.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_get_temperature_offset(int32_t* t_offset_m_deg_c);
/**
* scd4x_set_temperature_offset_ticks() - Setting the temperature offset of the
* SCD4x inside the customer device correctly allows the user to leverage the RH
* and T output signal. Note that the temperature offset can depend on various
* factors such as the SCD4x measurement mode, self-heating of close components,
* the ambient temperature and air flow. Thus, the SCD4x temperature offset
* should be determined inside the customer device under its typical operation
* and in thermal equilibrium.
*
* @note Only available in idle mode.
*
* @param t_offset Temperature offset. Convert °C to value by: T * 2^16 / 175.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_set_temperature_offset_ticks(uint16_t t_offset);
/**
* scd4x_set_temperature_offset() - Setting the temperature offset of the SCD4x
* inside the customer device correctly allows the user to leverage the RH and T
* output signal. Note that the temperature offset can depend on various factors
* such as the SCD4x measurement mode, self-heating of close components, the
* ambient temperature and air flow. Thus, the SCD4x temperature offset should
* be determined inside the customer device under its typical operation and in
* thermal equilibrium.
*
* @note Only available in idle mode.
*
* @param t_offset_m_deg_c Temperature offset in milli degrees Celsius.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_set_temperature_offset(int32_t t_offset_m_deg_c);
/**
* scd4x_get_sensor_altitude() - Get configured sensor altitude in meters above
* sea level. Per default, the sensor altitude is set to 0 meter above
* sea-level.
*
* @note Only available in idle mode.
*
* @param sensor_altitude Sensor altitude in meters.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_get_sensor_altitude(uint16_t* sensor_altitude);
/**
* scd4x_set_sensor_altitude() - Set sensor altitude in meters above sea level.
* Note that setting a sensor altitude to the sensor overrides any pressure
* compensation based on a previously set ambient pressure.
*
* @note Only available in idle mode.
*
* @param sensor_altitude Sensor altitude in meters.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_set_sensor_altitude(uint16_t sensor_altitude);
/**
* scd4x_set_ambient_pressure() - The set_ambient_pressure command can be sent
* during periodic measurements to enable continuous pressure compensation. Note
* that setting an ambient pressure to the sensor overrides any pressure
* compensation based on a previously set sensor altitude.
*
* @note Available during measurements.
*
* @param ambient_pressure Ambient pressure in hPa. Convert value to Pa by:
* value * 100.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_set_ambient_pressure(uint16_t ambient_pressure);
/**
* scd4x_perform_forced_recalibration() - To successfully conduct an accurate
forced recalibration, the following steps need to be carried out:
1. Operate the SCD4x in a periodic measurement mode for > 3 minutes in an
environment with homogenous and constant CO₂ concentration.
2. Stop periodic measurement. Wait 500 ms.
3. Subsequently issue the perform_forced_recalibration command and optionally
read out the baseline correction. A return value of 0xffff indicates that the
forced recalibration failed.
*
* @param target_co2_concentration Target CO₂ concentration in ppm.
*
* @param frc_correction FRC correction value in CO₂ ppm or 0xFFFF if the
command failed. Convert value to CO₂ ppm with: value - 0x8000
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_perform_forced_recalibration(uint16_t target_co2_concentration,
uint16_t* frc_correction);
/**
* scd4x_get_automatic_self_calibration() - By default, the ASC is enabled.
*
* @param asc_enabled 1 if ASC is enabled, 0 if ASC is disabled
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_get_automatic_self_calibration(uint16_t* asc_enabled);
/**
* scd4x_set_automatic_self_calibration() - By default, the ASC is enabled.
*
* @param asc_enabled 1 to enable ASC, 0 to disable ASC
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_set_automatic_self_calibration(uint16_t asc_enabled);
/**
* scd4x_start_low_power_periodic_measurement() - Start low power periodic
* measurement, signal update interval is 30 seconds.
*
* @note This command is only available in idle mode.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_start_low_power_periodic_measurement(void);
/**
* scd4x_get_data_ready_flag() - Check whether new measurement data is
* available for read-out.
*
* @param data_ready_flag True if data available, otherwise false.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_get_data_ready_flag(bool* data_ready_flag);
/**
* scd4x_persist_settings() - Configuration settings such as the temperature
* offset, sensor altitude and the ASC enabled/disabled parameter are by default
* stored in the volatile memory (RAM) only and will be lost after a
* power-cycle. The persist_settings command stores the current configuration in
* the EEPROM of the SCD4x, making them resistant to power-cycling. To avoid
* unnecessary wear of the EEPROM, the persist_settings command should only be
* sent when persistence is required and if actual changes to the configuration
* have been made. Note that field calibration history (i.e. FRC and ASC) is
* stored in the EEPROM automatically.
*
* @note
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_persist_settings(void);
/**
* scd4x_get_serial_number() - Reading out the serial number can be used to
* identify the chip and to verify the presence of the sensor. The get serial
* number command returns 3 words. Together, the 3 words constitute a unique
* serial number with a length of 48 bits (big endian format).
*
* @param serial_0 First word of the 48 bit serial number
*
* @param serial_1 Second word of the 48 bit serial number
*
* @param serial_2 Third word of the 48 bit serial number
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_get_serial_number(uint16_t* serial_0, uint16_t* serial_1,
uint16_t* serial_2);
/**
* scd4x_perform_self_test() - The perform_self_test feature can be used as an
* end-of-line test to confirm sensor functionality.
*
* @param sensor_status 0 means no malfunction detected
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_perform_self_test(uint16_t* sensor_status);
/**
* scd4x_perform_factory_reset() - Initiates the reset of all configurations
* stored in the EEPROM and erases the FRC and ASC algorithm history.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_perform_factory_reset(void);
/**
* scd4x_reinit() - The reinit command reinitializes the sensor by reloading
* user settings from EEPROM. Before sending the reinit command, the stop
* measurement command must be issued. If reinit command does not trigger the
* desired re-initialization, a power-cycle should be applied to the SCD4x.
*
* @note Only available in idle mode.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_reinit(void);
/**
* scd4x_measure_single_shot() - On-demand measurement of CO₂ concentration,
* relative humidity and temperature. The sensor output is read with the
* read_measurement command.
*
* @note Only available in idle mode.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_measure_single_shot(void);
/**
* scd4x_measure_single_shot_rht_only() - On-demand measurement of relative
* humidity and temperature only.
*
* @note Only available in idle mode.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_measure_single_shot_rht_only(void);
/**
* scd4x_power_down() - Put the sensor from idle to sleep mode to reduce current
* consumption.
*
* @note Only available in idle mode.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_power_down(void);
/**
* scd4x_wake_up() - Wake up sensor from sleep mode to idle mode.
*
* @note Only available in sleep mode.
*
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_wake_up(void);
#ifdef __cplusplus
}
#endif
#endif /* SCD4X_I2C_H */