]>
Commit | Line | Data |
---|---|---|
1 | ## | |
2 | ## This file is part of the libsigrokdecode project. | |
3 | ## | |
4 | ## Copyright (C) 2012 Iztok Jeras <iztok.jeras@gmail.com> | |
5 | ## | |
6 | ## This program is free software; you can redistribute it and/or modify | |
7 | ## it under the terms of the GNU General Public License as published by | |
8 | ## the Free Software Foundation; either version 2 of the License, or | |
9 | ## (at your option) any later version. | |
10 | ## | |
11 | ## This program is distributed in the hope that it will be useful, | |
12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ## GNU General Public License for more details. | |
15 | ## | |
16 | ## You should have received a copy of the GNU General Public License | |
17 | ## along with this program; if not, see <http://www.gnu.org/licenses/>. | |
18 | ## | |
19 | ||
20 | import sigrokdecode as srd | |
21 | ||
22 | # Dictionary of FUNCTION commands and their names. | |
23 | command = { | |
24 | # Scratchpad | |
25 | 0x4e: 'Write scratchpad', | |
26 | 0xbe: 'Read scratchpad', | |
27 | 0x48: 'Copy scratchpad', | |
28 | # Thermometer | |
29 | 0x44: 'Convert temperature', | |
30 | 0xb4: 'Read power mode', | |
31 | 0xb8: 'Recall EEPROM', | |
32 | 0xf5: 'PIO access read', | |
33 | 0xA5: 'PIO access write', | |
34 | 0x99: 'Chain', | |
35 | } | |
36 | ||
37 | class Decoder(srd.Decoder): | |
38 | api_version = 3 | |
39 | id = 'ds28ea00' | |
40 | name = 'DS28EA00' | |
41 | longname = 'Maxim DS28EA00 1-Wire digital thermometer' | |
42 | desc = '1-Wire digital thermometer with Sequence Detect and PIO.' | |
43 | license = 'gplv2+' | |
44 | inputs = ['onewire_network'] | |
45 | outputs = [] | |
46 | tags = ['IC', 'Sensor'] | |
47 | annotations = ( | |
48 | ('text', 'Human-readable text'), | |
49 | ) | |
50 | ||
51 | def __init__(self): | |
52 | self.reset() | |
53 | ||
54 | def reset(self): | |
55 | self.trn_beg = 0 | |
56 | self.trn_end = 0 | |
57 | self.state = 'ROM' | |
58 | self.rom = 0x0000000000000000 | |
59 | ||
60 | def start(self): | |
61 | self.out_ann = self.register(srd.OUTPUT_ANN) | |
62 | ||
63 | def putx(self, data): | |
64 | self.put(self.ss, self.es, self.out_ann, data) | |
65 | ||
66 | def decode(self, ss, es, data): | |
67 | code, val = data | |
68 | ||
69 | self.ss, self.es = ss, es | |
70 | ||
71 | # State machine. | |
72 | if code == 'RESET/PRESENCE': | |
73 | self.putx([0, ['Reset/presence: %s' | |
74 | % ('true' if val else 'false')]]) | |
75 | self.state = 'ROM' | |
76 | elif code == 'ROM': | |
77 | self.rom = val | |
78 | self.putx([0, ['ROM: 0x%016x' % (val)]]) | |
79 | self.state = 'COMMAND' | |
80 | elif code == 'DATA': | |
81 | if self.state == 'COMMAND': | |
82 | if val not in command: | |
83 | self.putx([0, ['Unrecognized command: 0x%02x' % val]]) | |
84 | return | |
85 | self.putx([0, ['Function command: 0x%02x \'%s\'' | |
86 | % (val, command[val])]]) | |
87 | self.state = command[val].upper() | |
88 | elif self.state == 'READ SCRATCHPAD': | |
89 | self.putx([0, ['Scratchpad data: 0x%02x' % val]]) | |
90 | elif self.state == 'CONVERT TEMPERATURE': | |
91 | self.putx([0, ['Temperature conversion status: 0x%02x' % val]]) | |
92 | elif self.state in [s.upper() for s in command.values()]: | |
93 | self.putx([0, ['TODO \'%s\': 0x%02x' % (self.state, val)]]) |