1 /*        $NetBSD: sht3xvar.h,v 1.2 2025/01/23 19:14: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_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           bool                sc_clockstretch;
61           pool_cache_t        sc_readpool;
62           char                *sc_readpoolname;
63           SIMPLEQ_HEAD(,sht3x_read_q)  sc_read_queue;
64 };
65 
66 struct sht3x_read_q {
67           uint8_t             measurement[6];
68           SIMPLEQ_ENTRY(sht3x_read_q) read_q;
69 };
70 
71 struct sht3x_sensor {
72           const char     *desc;
73           enum envsys_units type;
74 };
75 
76 struct sht3x_timing {
77           uint16_t cmd;
78           int     typicaldelay;
79 };
80 
81 struct sht3x_periodic {
82           const char          *repeatability;
83           const char          *rate;
84           int                 sdelay;
85           uint16_t        cmd;
86 };
87 
88 struct sht3x_repeatability {
89           const char     *text;
90           uint16_t        cmd;
91           uint16_t        cscmd;
92 };
93 
94 #endif
95