]> sigrok.org Git - libsigrokdecode.git/blame - decoders/ds28ea00/pd.py
cfp: Fix incorrect copy-paste description.
[libsigrokdecode.git] / decoders / ds28ea00 / pd.py
CommitLineData
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
4539e9ca 17## along with this program; if not, see <http://www.gnu.org/licenses/>.
a81787f6
IJ
18##
19
a81787f6
IJ
20import sigrokdecode as srd
21
c07cbb92 22# Dictionary of FUNCTION commands and their names.
758d2ea9 23command = {
c07cbb92
UH
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',
758d2ea9 35}
a81787f6
IJ
36
37class Decoder(srd.Decoder):
b197383c 38 api_version = 3
0c931451 39 id = 'ds28ea00'
9e1437a0 40 name = 'DS28EA00'
0afa64ae 41 longname = 'Maxim DS28EA00 1-Wire digital thermometer'
9e1437a0 42 desc = '1-Wire digital thermometer with Sequence Detect and PIO.'
a81787f6
IJ
43 license = 'gplv2+'
44 inputs = ['onewire_network']
0c931451 45 outputs = ['ds28ea00']
da9bcbd9
BV
46 annotations = (
47 ('text', 'Human-readable text'),
48 )
a81787f6 49
92b7b49f 50 def __init__(self):
10aeb8ea
GS
51 self.reset()
52
53 def reset(self):
a81787f6
IJ
54 self.trn_beg = 0
55 self.trn_end = 0
c07cbb92
UH
56 self.state = 'ROM'
57 self.rom = 0x0000000000000000
a81787f6 58
8915b346 59 def start(self):
be465111 60 self.out_ann = self.register(srd.OUTPUT_ANN)
a81787f6 61
500560a1
UH
62 def putx(self, data):
63 self.put(self.ss, self.es, self.out_ann, data)
64
a81787f6 65 def decode(self, ss, es, data):
c07cbb92 66 code, val = data
a81787f6 67
500560a1
UH
68 self.ss, self.es = ss, es
69
a81787f6 70 # State machine.
c07cbb92 71 if code == 'RESET/PRESENCE':
500560a1
UH
72 self.putx([0, ['Reset/presence: %s'
73 % ('true' if val else 'false')]])
c07cbb92
UH
74 self.state = 'ROM'
75 elif code == 'ROM':
a81787f6 76 self.rom = val
500560a1 77 self.putx([0, ['ROM: 0x%016x' % (val)]])
c07cbb92
UH
78 self.state = 'COMMAND'
79 elif code == 'DATA':
80 if self.state == 'COMMAND':
500560a1
UH
81 if val not in command:
82 self.putx([0, ['Unrecognized command: 0x%02x' % val]])
83 return
84 self.putx([0, ['Function command: 0x%02x \'%s\''
85 % (val, command[val])]])
86 self.state = command[val].upper()
c07cbb92 87 elif self.state == 'READ SCRATCHPAD':
500560a1 88 self.putx([0, ['Scratchpad data: 0x%02x' % val]])
c07cbb92 89 elif self.state == 'CONVERT TEMPERATURE':
500560a1 90 self.putx([0, ['Temperature conversion status: 0x%02x' % val]])
c07cbb92 91 elif self.state in [s.upper() for s in command.values()]:
500560a1 92 self.putx([0, ['TODO \'%s\': 0x%02x' % (self.state, val)]])