hytp14reg.h revision 1.2.12.1 1 /* $NetBSD: hytp14reg.h,v 1.2.12.1 2017/01/07 08:56:31 pgoyette Exp $ */
2
3 /*-
4 * Copyright (c) 2014 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_HYTP14REG_H_
41 #define _DEV_I2C_HYTP14REG_H_
42
43 #define HYTP14_DEFAULT_ADDR 0x28
44
45 #define HYTP14_CMD_START_NOM 0x80 /* end command mode (or power-off) */
46 #define HYTP14_CMD_START_CM 0xA0 /* start command mode (within 10ms after power-up) */
47 #define HYTP14_CMD_GET_REV 0xB0 /* get revison */
48
49 #define HYTP14_NUM_WORDS 32
50 #define HYTP14_READ_OFFSET 0x00 /* command offset to read EEPROM words */
51 #define HYTP14_WRITE_OFFSET 0x40 /* command offset to write EEPROM words */
52
53 #define HYTP14_READ_EEPROM(_X_) (HYTP14_READ_OFFSET + ((_X_) & (HYTP14_NUM_WORDS - 1)))
54 #define HYTP14_WRITE_EEPROM(_X_) (HYTP14_WRITE_OFFSET + ((_X_) & (HYTP14_NUM_WORDS - 1)))
55
56 #define HYTP14_EEADDR_I2CADDR 0x1C /* I2C address EEPROM word address */
57
58 #define HYTP14_RESP_CMDMODE 0x80 /* command mode response */
59 #define HYTP14_RESP_STALE 0x40 /* stale measurement data */
60
61 #define HYT_STATUS_FMT "\177\20b\7CM\0b\6STALE\0b\5ERR_CFG\0b\4ERR_RAM\0b\3ERR_UNCEEP\0"\
62 "b\2ERR_COREEP\0f\0\2RESP\0=\0BSY\0=\1ACK\0=\2NAK\0=\3INV\0\0"
63
64 #define HYTP14_DIAG_ERR_CFG 0x20 /* configuration error */
65 #define HYTP14_DIAG_ERR_RAMPRTY 0x10 /* RAM parity error */
66 #define HYTP14_DIAG_ERR_UNCEEP 0x08 /* uncorrectable EEPROM error */
67 #define HYTP14_DIAG_ERR_COREEP 0x04 /* correctable EEPROM error */
68
69 #define HYTP14_RESP_MASK 0x03
70 #define HYTP14_RESP_BUSY 0x00 /* device is busy */
71 #define HYTP14_RESP_ACK 0x01 /* positive acknowledge */
72 #define HYTP14_RESP_NACK 0x02 /* negative acknowledge */
73
74 #define HYTP14_ST_CMDMODE 0x8000 /* command mode */
75 #define HYTP14_ST_STALE 0x4000 /* stale measurement data */
76 #define HYTP14_HYG_RAWVAL(_X_) ((_X_) & 0x3FFF)
77 #define HYTP14_HYG_SCALE (1<<14)
78 #define HYTP14_TEMP_RAWVAL(_X_) (((_X_) >> 2) & 0x3FFF)
79 #define HYTP14_TEMP_SCALE (1<<14)
80 #define HYTP14_TEMP_FACTOR 165
81 #define HYTP14_TEMP_OFFSET (-40)
82
83 #endif
84