1/* $NetBSD: hytp14var.h,v 1.4 2016/07/03 12:26:55 kardel Exp $ */
2
3/*-
4 * Copyright (c) 2014,2016 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Frank Kardel.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/*
33 * IST-AG P14 calibrated Hygro-/Temperature sensor module
34 * Devices: HYT-271, HYT-221 and HYT-939
35 *
36 * see:
37 * http://www.ist-ag.com/eh/ist-ag/resource.nsf/imgref/Download_AHHYTM_E2.1.pdf/
38 *      $FILE/AHHYTM_E2.1.pdf
39 */
40#ifndef _DEV_I2C_HYTP14VAR_H_
41#define _DEV_I2C_HYTP14VAR_H_
42
43#define HYTP14_DEFAULT_ADDR	0x28
44
45#define HYTP14_NUM_SENSORS	2
46
47/* the default measurement interval is 50 seconds */
48#define HYTP14_MR_INTERVAL	50
49
50#define HYTP14_THR_INIT		0
51#define HYTP14_THR_RUN		1
52#define HYTP14_THR_STOP		2
53
54struct hytp14_sc {
55	device_t	sc_dev;
56	i2c_tag_t	sc_tag;
57	i2c_addr_t	sc_addr;
58
59	kmutex_t	sc_mutex;
60	kcondvar_t	sc_condvar;
61	struct lwp     *sc_thread;  /* measurement poll thread */
62	int		sc_state;   /* thread communication */
63
64	int		sc_valid;   /* ENVSYS validity state for this sensor */
65	uint8_t		sc_data[4]; /* current sensor data */
66	uint8_t		sc_last[4]; /* last sensor data, before MR */
67
68	int		sc_numsensors;
69
70	int32_t		sc_mrinterval;
71
72	struct sysmon_envsys *sc_sme;
73	envsys_data_t sc_sensors[HYTP14_NUM_SENSORS];
74};
75
76struct hytp14_sensor {
77	const char	  *desc;
78	enum envsys_units  type;
79	void		 (*refresh)(struct hytp14_sc *, envsys_data_t *);
80};
81
82#endif
83