]>
Commit | Line | Data |
---|---|---|
a81787f6 | 1 | ## |
50bd5d25 | 2 | ## This file is part of the libsigrokdecode project. |
a81787f6 IJ |
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, write to the Free Software | |
18 | ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | ## | |
20 | ||
a81787f6 IJ |
21 | import sigrokdecode as srd |
22 | ||
c07cbb92 | 23 | # Dictionary of FUNCTION commands and their names. |
758d2ea9 | 24 | command = { |
c07cbb92 UH |
25 | # Scratchpad |
26 | 0x4e: 'Write scratchpad', | |
27 | 0xbe: 'Read scratchpad', | |
28 | 0x48: 'Copy scratchpad', | |
29 | # Thermometer | |
30 | 0x44: 'Convert temperature', | |
31 | 0xb4: 'Read power mode', | |
32 | 0xb8: 'Recall EEPROM', | |
33 | 0xf5: 'PIO access read', | |
34 | 0xA5: 'PIO access write', | |
35 | 0x99: 'Chain', | |
758d2ea9 | 36 | } |
a81787f6 IJ |
37 | |
38 | class Decoder(srd.Decoder): | |
39 | api_version = 1 | |
19dd61ef | 40 | id = 'maxim_ds28ea00' |
9e1437a0 | 41 | name = 'DS28EA00' |
0afa64ae | 42 | longname = 'Maxim DS28EA00 1-Wire digital thermometer' |
9e1437a0 | 43 | desc = '1-Wire digital thermometer with Sequence Detect and PIO.' |
a81787f6 IJ |
44 | license = 'gplv2+' |
45 | inputs = ['onewire_network'] | |
0afa64ae | 46 | outputs = ['maxim_ds28ea00'] |
a81787f6 | 47 | probes = [] |
0afa64ae UH |
48 | optional_probes = [ |
49 | {'id': 'pioa', 'name': 'PIOA/DONE#', | |
50 | 'desc': 'PIOA channel and chain output'}, | |
51 | {'id': 'piob', 'name': 'PIOB/EN#', | |
52 | 'desc': 'PIOB channel and chain output'}, | |
53 | ] | |
a81787f6 IJ |
54 | options = {} |
55 | annotations = [ | |
9f2f42c0 | 56 | ['text', 'Human-readable text'], |
a81787f6 IJ |
57 | ] |
58 | ||
59 | def __init__(self, **kwargs): | |
a81787f6 IJ |
60 | self.trn_beg = 0 |
61 | self.trn_end = 0 | |
c07cbb92 UH |
62 | self.state = 'ROM' |
63 | self.rom = 0x0000000000000000 | |
a81787f6 | 64 | |
8915b346 | 65 | def start(self): |
be465111 | 66 | self.out_ann = self.register(srd.OUTPUT_ANN) |
a81787f6 | 67 | |
500560a1 UH |
68 | def putx(self, data): |
69 | self.put(self.ss, self.es, self.out_ann, data) | |
70 | ||
a81787f6 | 71 | def decode(self, ss, es, data): |
c07cbb92 | 72 | code, val = data |
a81787f6 | 73 | |
500560a1 UH |
74 | self.ss, self.es = ss, es |
75 | ||
a81787f6 | 76 | # State machine. |
c07cbb92 | 77 | if code == 'RESET/PRESENCE': |
500560a1 UH |
78 | self.putx([0, ['Reset/presence: %s' |
79 | % ('true' if val else 'false')]]) | |
c07cbb92 UH |
80 | self.state = 'ROM' |
81 | elif code == 'ROM': | |
a81787f6 | 82 | self.rom = val |
500560a1 | 83 | self.putx([0, ['ROM: 0x%016x' % (val)]]) |
c07cbb92 UH |
84 | self.state = 'COMMAND' |
85 | elif code == 'DATA': | |
86 | if self.state == 'COMMAND': | |
500560a1 UH |
87 | if val not in command: |
88 | self.putx([0, ['Unrecognized command: 0x%02x' % val]]) | |
89 | return | |
90 | self.putx([0, ['Function command: 0x%02x \'%s\'' | |
91 | % (val, command[val])]]) | |
92 | self.state = command[val].upper() | |
c07cbb92 | 93 | elif self.state == 'READ SCRATCHPAD': |
500560a1 | 94 | self.putx([0, ['Scratchpad data: 0x%02x' % val]]) |
c07cbb92 | 95 | elif self.state == 'CONVERT TEMPERATURE': |
500560a1 | 96 | self.putx([0, ['Temperature conversion status: 0x%02x' % val]]) |
c07cbb92 | 97 | elif self.state in [s.upper() for s in command.values()]: |
500560a1 | 98 | self.putx([0, ['TODO \'%s\': 0x%02x' % (self.state, val)]]) |
a81787f6 IJ |
99 | else: |
100 | raise Exception('Invalid state: %s' % self.state) | |
c07cbb92 | 101 |