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