]> sigrok.org Git - libsigrokdecode.git/blob - decoders/maxim_ds28ea00/maxim_ds28ea00.py
9801138e70ba88782e417b1cad94e05a5a189f66
[libsigrokdecode.git] / decoders / maxim_ds28ea00 / maxim_ds28ea00.py
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
21 # Maxim DS28EA00 protocol decoder
22
23 import sigrokdecode as srd
24
25 # a dictionary of FUNCTION commands and their names
26 command = {
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",
38     # memory
39     0xf0: "READ MEMORY",
40     0xa5: "EXTENDED READ MEMORY",
41     0x0f: "WRITE MEMORY",
42     0x55: "WRITE STATUS",
43     0xaa: "READ STATUS",
44     0xf5: "CHANNEL ACCESS"
45 }
46
47 class Decoder(srd.Decoder):
48     api_version = 1
49     id = 'maxim_ds28ea00'
50     name = 'Maxim DS28EA00'
51     longname = 'Maxim DS28EA00 1-Wire digital thermometer'
52     desc = '1-Wire digital thermometer with Sequence Detect and PIO'
53     license = 'gplv2+'
54     inputs = ['onewire_network']
55     outputs = ['maxim_ds28ea00']
56     probes = []
57     optional_probes = [
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'},
62     ]
63     options = {}
64     annotations = [
65         ['Text', 'Human-readable text'],
66     ]
67
68     def __init__(self, **kwargs):
69         # Event timing variables
70         self.trn_beg = 0
71         self.trn_end = 0
72         # Transport layer variables
73         self.state   = 'ROM'
74         self.rom     = 0x0000000000000000
75
76     def start(self, metadata):
77         self.out_ann   = self.add(srd.OUTPUT_ANN  , 'maxim_ds28ea00')
78
79     def report(self):
80         pass
81
82     def decode(self, ss, es, data):
83         [code, val] = data
84
85         # State machine.
86         if (code == "RESET/PRESENCE"):
87             self.put(ss, es, self.out_ann, [0, ['RESET/PRESENCE: %s' % ('True' if val else 'False')]])
88             self.state = "ROM"
89         elif (code == "ROM"):
90             self.rom = val
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"):
95                     if (val in command):
96                         self.put(ss, es, self.out_ann, [0, ['FUNCTION COMMAND: 0x%02x \'%s\'' % (val, command[val])]])
97                         self.state = command[val]
98                     else:
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)]])
109             else:
110                 raise Exception('Invalid state: %s' % self.state)