|
darius@8
|
1 |
/*
|
|
darius@32
|
2 |
* 1 wire header which defines functions and constants
|
|
darius@8
|
3 |
*
|
|
darius@8
|
4 |
* $Id$
|
|
darius@8
|
5 |
*
|
|
darius@8
|
6 |
* Copyright (c) 2004
|
|
darius@0
|
7 |
* Daniel O'Connor <darius@dons.net.au>. All rights reserved.
|
|
darius@0
|
8 |
*
|
|
darius@0
|
9 |
* Redistribution and use in source and binary forms, with or without
|
|
darius@0
|
10 |
* modification, are permitted provided that the following conditions
|
|
darius@0
|
11 |
* are met:
|
|
darius@0
|
12 |
* 1. Redistributions of source code must retain the above copyright
|
|
darius@0
|
13 |
* notice, this list of conditions and the following disclaimer.
|
|
darius@0
|
14 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
darius@0
|
15 |
* notice, this list of conditions and the following disclaimer in the
|
|
darius@0
|
16 |
* documentation and/or other materials provided with the distribution.
|
|
darius@0
|
17 |
*
|
|
darius@0
|
18 |
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
darius@0
|
19 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
darius@0
|
20 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
darius@0
|
21 |
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
darius@0
|
22 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
darius@0
|
23 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
darius@0
|
24 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
darius@0
|
25 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
darius@0
|
26 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
darius@0
|
27 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
darius@0
|
28 |
* SUCH DAMAGE.
|
|
darius@0
|
29 |
*/
|
|
darius@0
|
30 |
|
|
darius@32
|
31 |
void OWInit(void);
|
|
darius@12
|
32 |
uint8_t OWTouchReset(void);
|
|
darius@12
|
33 |
void OWWriteBit(uint8_t bit);
|
|
darius@12
|
34 |
uint8_t OWReadBit(void);
|
|
darius@0
|
35 |
void OWWriteByte(uint8_t data);
|
|
darius@12
|
36 |
uint8_t OWReadByte(void);
|
|
darius@12
|
37 |
uint8_t OWTouchByte(uint8_t data);
|
|
darius@0
|
38 |
void OWBlock(uint8_t *data, int len);
|
|
darius@12
|
39 |
uint8_t OWFirst(uint8_t *ROM, uint8_t do_reset, uint8_t alarm_only);
|
|
darius@12
|
40 |
uint8_t OWNext(uint8_t *ROM, uint8_t do_reset, uint8_t alarm_only);
|
|
darius@0
|
41 |
void OWCRC(uint8_t x, uint8_t *crc);
|
|
darius@0
|
42 |
void OWSendCmd(uint8_t *ROM, uint8_t cmd);
|
|
darius@33
|
43 |
uint8_t OWProgROM(uint8_t *ROM, uint8_t start, uint8_t len, uint8_t *data, uint8_t exact, uint8_t status);
|
|
darius@41
|
44 |
int16_t OWGetTemp(uint8_t *ROM);
|
|
darius@48
|
45 |
extern const PROGMEM char *OWProgROM_Status[];
|
|
darius@48
|
46 |
|
|
darius@0
|
47 |
|
|
darius@10
|
48 |
/* Return codes for OWFirst()/OWNext() */
|
|
darius@10
|
49 |
#define OW_BADWIRE -3
|
|
darius@10
|
50 |
#define OW_BADCRC -2
|
|
darius@10
|
51 |
#define OW_NOPRESENCE -1
|
|
darius@10
|
52 |
#define OW_NOMODULES 0
|
|
darius@10
|
53 |
#define OW_FOUND 1
|
|
darius@10
|
54 |
|
|
darius@0
|
55 |
/* General 1 wire commands */
|
|
darius@0
|
56 |
#define OW_OVRDRV_SKIP_CMD 0x3c
|
|
darius@0
|
57 |
#define OW_SEARCH_ALRM_CMD 0xec
|
|
darius@0
|
58 |
#define OW_SEARCH_ROM_CMD 0xf0
|
|
darius@0
|
59 |
#define OW_READ_ROM_CMD 0x33
|
|
darius@0
|
60 |
#define OW_MATCH_ROM_CMD 0x55
|
|
darius@0
|
61 |
#define OW_SKIP_ROM_CMD 0xcc
|
|
darius@0
|
62 |
|
|
darius@0
|
63 |
/* DS1820 commands */
|
|
darius@0
|
64 |
#define OW_CONVERTT_CMD 0x44
|
|
darius@0
|
65 |
#define OW_RD_SCR_CMD 0xbe
|
|
darius@0
|
66 |
#define OW_WR_SCR_CMD 0x4e
|
|
darius@0
|
67 |
#define OW_CPY_SCR_CMD 0x48
|
|
darius@0
|
68 |
#define OW_RECALL_CMD 0xb8
|
|
darius@0
|
69 |
#define OW_RD_PSU_CMD 0xb4
|
|
darius@0
|
70 |
|
|
darius@32
|
71 |
/* DS2502 commands */
|
|
darius@32
|
72 |
#define OW_READ_MEMORY 0xf0
|
|
darius@32
|
73 |
#define OW_READ_STATUS 0xaa
|
|
darius@32
|
74 |
#define OW_GEN_CRC 0xc3
|
|
darius@32
|
75 |
#define OW_WRITE_MEMORY 0x0f
|
|
darius@32
|
76 |
#define OW_WRITE_STATUS 0x55
|
|
darius@32
|
77 |
|
|
darius@0
|
78 |
/* Family codes */
|
|
darius@0
|
79 |
#define OW_FAMILY_ROM 0x09
|
|
darius@0
|
80 |
#define OW_FAMILY_TEMP 0x10
|
|
darius@41
|
81 |
|
|
darius@41
|
82 |
/* Return codes for OWGetTemp */
|
|
darius@65
|
83 |
/* XXX: make bigger otherwise we can't handle stuff below -10C */
|
|
darius@41
|
84 |
#define OW_TEMP_BADVAL -1000
|
|
darius@41
|
85 |
#define OW_TEMP_WRONG_FAM -1000
|
|
darius@41
|
86 |
#define OW_TEMP_CRC_ERR -1001
|
|
darius@41
|
87 |
#define OW_TEMP_NO_ROM -1002
|
|
darius@45
|
88 |
|
|
darius@45
|
89 |
/* Helpers for OWGetTemp's number system */
|
|
darius@45
|
90 |
#define GETWHOLE(x) ((x) / 100)
|
|
darius@65
|
91 |
#define GETFRAC(x) abs((x) - (GETWHOLE(x) * 100))
|