1 /*
2  * Copyright (c) 2021 Leonard Pollak
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_SENSOR_SGP40_SGP40_H_
8 #define ZEPHYR_DRIVERS_SENSOR_SGP40_SGP40_H_
9 
10 #include <zephyr/device.h>
11 
12 #define SGP40_CMD_MEASURE_RAW	0x260F
13 #define SGP40_CMD_MEASURE_TEST	0x280E
14 #define SGP40_CMD_HEATER_OFF	0x3615
15 
16 #define SGP40_TEST_OK		0xD400
17 #define SGP40_TEST_FAIL		0x4B00
18 
19 #define SGP40_RESET_WAIT_MS	10
20 #define SGP40_MEASURE_WAIT_MS	30
21 #define SGP40_TEST_WAIT_MS	250
22 
23 /*
24  * CRC parameters were taken from the
25  * "Checksum Calculation" section of the datasheet.
26  */
27 #define SGP40_CRC_POLY		0x31
28 #define SGP40_CRC_INIT		0xFF
29 
30 /*
31  * Value range of compensation data parameters
32  */
33 #define SGP40_COMP_MIN_RH	0
34 #define SGP40_COMP_MAX_RH	100
35 #define SGP40_COMP_MIN_T	-45
36 #define SGP40_COMP_MAX_T	130
37 #define SGP40_COMP_DEFAULT_T	25
38 #define SGP40_COMP_DEFAULT_RH	50
39 
40 struct sgp40_config {
41 	struct i2c_dt_spec bus;
42 	bool selftest;
43 };
44 
45 struct sgp40_data {
46 	uint16_t raw_sample;
47 	int8_t rh_param[3];
48 	int8_t t_param[3];
49 };
50 
51 #endif /* ZEPHYR_DRIVERS_SENSOR_SGP40_SGP40_H_ */
52