xref: /netbsd-src/sys/dev/i2c/sgp40var.h (revision ea034c40cb6c6eb4c994e07e761084ee05973c97)
1 /*	$NetBSD: sgp40var.h,v 1.1 2021/10/14 13:54:46 brad Exp $	*/
2 
3 /*
4  * Copyright (c) 2021 Brad Spencer <brad@anduin.eldar.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _DEV_I2C_SGP40VAR_H_
20 #define _DEV_I2C_SGP40VAR_H_
21 
22 #define SGP40_NUM_SENSORS	1
23 #define SGP40_VOC_SENSOR 0
24 
25 #define SGP40_DEFAULT_TEMP_COMP 25
26 #define SGP40_DEFAULT_RH_COMP 50
27 
28 
29 struct sgp40_sc {
30 	int 		sc_sgp40debug;
31 	device_t 	sc_dev;
32 	i2c_tag_t 	sc_tag;
33 	i2c_addr_t 	sc_addr;
34 	kmutex_t        sc_threadmutex; /* for the measurement kthread */
35 	kmutex_t 	sc_mutex; /* for reading the i2c bus */
36 	kcondvar_t	sc_condvar;
37 	struct lwp      *sc_thread;
38 	int 		sc_numsensors;
39 	struct sysmon_envsys *sc_sme;
40 	struct sysctllog *sc_sgp40log;
41 	envsys_data_t 	sc_sensors[SGP40_NUM_SENSORS];
42 	uint16_t        sc_voc;
43 	bool            sc_vocvalid;
44 	bool 		sc_ignorecrc;
45 	int 		sc_readattempts;
46 	bool            sc_stopping;
47 	int             sc_tempcomp;
48 	int             sc_rhcomp;
49 };
50 
51 struct sgp40_sensor {
52 	const char     *desc;
53 	enum envsys_units type;
54 };
55 
56 struct sgp40_timing {
57 	uint16_t cmd;
58 	int     typicaldelay;
59 };
60 
61 #endif
62