1 1.2 brad /* $NetBSD: sht3xvar.h,v 1.2 2025/01/23 19:14:46 brad Exp $ */ 2 1.1 brad 3 1.1 brad /* 4 1.1 brad * Copyright (c) 2021 Brad Spencer <brad (at) anduin.eldar.org> 5 1.1 brad * 6 1.1 brad * Permission to use, copy, modify, and distribute this software for any 7 1.1 brad * purpose with or without fee is hereby granted, provided that the above 8 1.1 brad * copyright notice and this permission notice appear in all copies. 9 1.1 brad * 10 1.1 brad * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 1.1 brad * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 1.1 brad * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 1.1 brad * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 1.1 brad * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 1.1 brad * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 1.1 brad * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 1.1 brad */ 18 1.1 brad 19 1.1 brad #ifndef _DEV_I2C_SHT3XVAR_H_ 20 1.1 brad #define _DEV_I2C_SHT3XVAR_H_ 21 1.1 brad 22 1.1 brad #define SHT3X_NUM_SENSORS 2 23 1.1 brad #define SHT3X_HUMIDITY_SENSOR 0 24 1.1 brad #define SHT3X_TEMP_SENSOR 1 25 1.1 brad 26 1.1 brad #define SHT3X_MODE_NAME 12 27 1.1 brad #define SHT3X_REP_NAME 7 28 1.1 brad #define SHT3X_RATE_NAME 8 29 1.1 brad 30 1.1 brad struct sht3x_sc { 31 1.1 brad int sc_sht3xdebug; 32 1.1 brad device_t sc_dev; 33 1.1 brad i2c_tag_t sc_tag; 34 1.1 brad i2c_addr_t sc_addr; 35 1.1 brad kmutex_t sc_dying_mutex; /* for cleaning up */ 36 1.1 brad kmutex_t sc_threadmutex; /* for the measurement kthread */ 37 1.1 brad kmutex_t sc_mutex; /* for reading the i2c bus */ 38 1.1 brad kmutex_t sc_read_mutex; /* for from the data queue */ 39 1.1 brad kcondvar_t sc_condvar; /* for shutting down the thread */ 40 1.1 brad kcondvar_t sc_condreadready; /* when there is data to be read */ 41 1.1 brad kcondvar_t sc_cond_dying; /* interlock when cleaning up */ 42 1.1 brad struct lwp *sc_thread; 43 1.1 brad int sc_numsensors; 44 1.1 brad struct sysmon_envsys *sc_sme; 45 1.1 brad struct sysctllog *sc_sht3xlog; 46 1.1 brad envsys_data_t sc_sensors[SHT3X_NUM_SENSORS]; 47 1.1 brad bool sc_ignorecrc; 48 1.1 brad char sc_mode[SHT3X_MODE_NAME]; 49 1.1 brad bool sc_isperiodic; 50 1.1 brad char sc_repeatability[SHT3X_REP_NAME]; 51 1.1 brad char sc_periodic_rate[SHT3X_RATE_NAME]; 52 1.1 brad int sc_readattempts; 53 1.1 brad bool sc_heateron; 54 1.1 brad bool sc_stopping; 55 1.1 brad bool sc_initperiodic; 56 1.1 brad uint8_t sc_pbuffer[6]; 57 1.1 brad bool sc_dying; 58 1.1 brad bool sc_opened; 59 1.1 brad bool sc_wassingleshot; 60 1.2 brad bool sc_clockstretch; 61 1.1 brad pool_cache_t sc_readpool; 62 1.1 brad char *sc_readpoolname; 63 1.1 brad SIMPLEQ_HEAD(,sht3x_read_q) sc_read_queue; 64 1.1 brad }; 65 1.1 brad 66 1.1 brad struct sht3x_read_q { 67 1.1 brad uint8_t measurement[6]; 68 1.1 brad SIMPLEQ_ENTRY(sht3x_read_q) read_q; 69 1.1 brad }; 70 1.1 brad 71 1.1 brad struct sht3x_sensor { 72 1.1 brad const char *desc; 73 1.1 brad enum envsys_units type; 74 1.1 brad }; 75 1.1 brad 76 1.1 brad struct sht3x_timing { 77 1.1 brad uint16_t cmd; 78 1.1 brad int typicaldelay; 79 1.1 brad }; 80 1.1 brad 81 1.1 brad struct sht3x_periodic { 82 1.1 brad const char *repeatability; 83 1.1 brad const char *rate; 84 1.1 brad int sdelay; 85 1.1 brad uint16_t cmd; 86 1.1 brad }; 87 1.1 brad 88 1.1 brad struct sht3x_repeatability { 89 1.1 brad const char *text; 90 1.1 brad uint16_t cmd; 91 1.2 brad uint16_t cscmd; 92 1.1 brad }; 93 1.1 brad 94 1.1 brad #endif 95