2 ## This file is part of the sigrok project.
4 ## Copyright (C) 2012 Iztok Jeras <iztok.jeras@gmail.com>
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.
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.
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
21 # Maxim DS28EA00 protocol decoder
23 import sigrokdecode as srd
25 # a dictionary of FUNCTION commands and their names
28 0x4e: "WRITE SCRATCHPAD",
29 0xbe: "READ SCRATCHPAD",
30 0x48: "COPY SCRATCHPAD",
32 0x44: "CONVERT TEMPERATURE",
33 0xb4: "READ POWER MODE",
34 0xb8: "RECALL EEPROM",
35 0xf5: "PIO ACCESS READ",
36 0xA5: "PIO ACCESS WRITE",
40 0xa5: "EXTENDED READ MEMORY",
44 0xf5: "CHANNEL ACCESS"
47 class Decoder(srd.Decoder):
50 name = 'Maxim DS28EA00'
51 longname = 'Maxim DS28EA00 1-Wire digital thermometer'
52 desc = '1-Wire digital thermometer with Sequence Detect and PIO'
54 inputs = ['onewire_network']
55 outputs = ['maxim_ds28ea00']
58 {'id': 'pioa', 'name': 'PIOA/DONE#',
59 'desc': 'PIOA channel and chain output'},
60 {'id': 'piob', 'name': 'PIOB/EN#',
61 'desc': 'PIOB channel and chain output'},
65 ['Text', 'Human-readable text'],
68 def __init__(self, **kwargs):
69 # Event timing variables
72 # Transport layer variables
74 self.rom = 0x0000000000000000
76 def start(self, metadata):
77 self.out_ann = self.add(srd.OUTPUT_ANN , 'maxim_ds28ea00')
82 def decode(self, ss, es, data):
86 if (code == "RESET/PRESENCE"):
87 self.put(ss, es, self.out_ann, [0, ['RESET/PRESENCE: %s' % ('True' if val else 'False')]])
91 self.put(ss, es, self.out_ann, [0, ['ROM: 0x%016x' % (val)]])
92 self.state = "COMMAND"
93 elif (code == "DATA"):
94 if (self.state == "COMMAND"):
96 self.put(ss, es, self.out_ann, [0, ['FUNCTION COMMAND: 0x%02x \'%s\'' % (val, command[val])]])
97 self.state = command[val]
99 self.put(ss, es, self.out_ann, [0, ['FUNCTION COMMAND: 0x%02x \'%s\'' % (val, 'UNRECOGNIZED')]])
100 self.state = "UNRECOGNIZED"
101 elif (self.state == "READ SCRATCHPAD"):
102 self.put(ss, es, self.out_ann, [0, ['SCRATCHPAD DATA: 0x%02x' % (val)]])
103 elif (self.state == "CONVERT TEMPERATURE"):
104 self.put(ss, es, self.out_ann, [0, ['TEMPERATURE CONVERSION STATUS: 0x%02x' % (val)]])
105 elif (self.state in command.values()):
106 self.put(ss, es, self.out_ann, [0, ['TODO "%s": 0x%02x' % (self.state, val)]])
107 elif (self.state == "UNRECOGNIZED"):
108 self.put(ss, es, self.out_ann, [0, ['UNRECOGNIZED COMMAND: 0x%02x' % (val)]])
110 raise Exception('Invalid state: %s' % self.state)