sht3xvar.h revision 1.1 1 /* $NetBSD: sht3xvar.h,v 1.1 2021/11/06 13:34:40 brad Exp $ */
2
3 /*
4 * Copyright (c) 2021 Brad Spencer <brad (at) 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_SHT3XVAR_H_
20 #define _DEV_I2C_SHT3XVAR_H_
21
22 #define SHT3X_NUM_SENSORS 2
23 #define SHT3X_HUMIDITY_SENSOR 0
24 #define SHT3X_TEMP_SENSOR 1
25
26 #define SHT3X_MODE_NAME 12
27 #define SHT3X_REP_NAME 7
28 #define SHT3X_RATE_NAME 8
29
30 struct sht3x_sc {
31 int sc_sht3xdebug;
32 device_t sc_dev;
33 i2c_tag_t sc_tag;
34 i2c_addr_t sc_addr;
35 kmutex_t sc_dying_mutex; /* for cleaning up */
36 kmutex_t sc_threadmutex; /* for the measurement kthread */
37 kmutex_t sc_mutex; /* for reading the i2c bus */
38 kmutex_t sc_read_mutex; /* for from the data queue */
39 kcondvar_t sc_condvar; /* for shutting down the thread */
40 kcondvar_t sc_condreadready; /* when there is data to be read */
41 kcondvar_t sc_cond_dying; /* interlock when cleaning up */
42 struct lwp *sc_thread;
43 int sc_numsensors;
44 struct sysmon_envsys *sc_sme;
45 struct sysctllog *sc_sht3xlog;
46 envsys_data_t sc_sensors[SHT3X_NUM_SENSORS];
47 bool sc_ignorecrc;
48 char sc_mode[SHT3X_MODE_NAME];
49 bool sc_isperiodic;
50 char sc_repeatability[SHT3X_REP_NAME];
51 char sc_periodic_rate[SHT3X_RATE_NAME];
52 int sc_readattempts;
53 bool sc_heateron;
54 bool sc_stopping;
55 bool sc_initperiodic;
56 uint8_t sc_pbuffer[6];
57 bool sc_dying;
58 bool sc_opened;
59 bool sc_wassingleshot;
60 pool_cache_t sc_readpool;
61 char *sc_readpoolname;
62 SIMPLEQ_HEAD(,sht3x_read_q) sc_read_queue;
63 };
64
65 struct sht3x_read_q {
66 uint8_t measurement[6];
67 SIMPLEQ_ENTRY(sht3x_read_q) read_q;
68 };
69
70 struct sht3x_sensor {
71 const char *desc;
72 enum envsys_units type;
73 };
74
75 struct sht3x_timing {
76 uint16_t cmd;
77 int typicaldelay;
78 };
79
80 struct sht3x_periodic {
81 const char *repeatability;
82 const char *rate;
83 int sdelay;
84 uint16_t cmd;
85 };
86
87 struct sht3x_repeatability {
88 const char *text;
89 uint16_t cmd;
90 };
91
92 #endif
93