2 ## This file is part of the libsigrokdecode project.
4 ## Copyright (C) 2015 Karl Palsson <karlp@tweak.net.au>
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, see <http://www.gnu.org/licenses/>.
20 import sigrokdecode as srd
41 class Decoder(srd.Decoder):
45 longname = 'Avago ADNS-5020 optical mouse sensor'
46 desc = 'Bidirectional command and data over an SPI-like protocol.'
49 outputs = ['adns5020']
51 ('read', 'Register read commands'),
52 ('write', 'Register write commands'),
53 ('warning', 'Warnings'),
56 ('read', 'Read', (0,)),
57 ('write', 'Write', (1,)),
58 ('warnings', 'Warnings', (2,)),
62 self.ss_cmd, self.es_cmd = 0, 0
66 self.out_ann = self.register(srd.OUTPUT_ANN)
69 self.put(self.ss_cmd, self.es_cmd, self.out_ann, data)
71 def put_warn(self, pos, msg):
72 self.put(pos[0], pos[1], self.out_ann, [2, [msg]])
74 def decode(self, ss, es, data):
76 if ptype == 'CS-CHANGE':
77 # If we transition high mid-stream, toss out our data and restart.
78 cs_old, cs_new = data[1:]
79 if cs_old is not None and cs_old == 0 and cs_new == 1:
80 if len(self.mosi_bytes) not in [0, 2]:
81 self.put_warn([self.ss_cmd, es], 'Misplaced CS#!')
85 # Don't care about anything else.
90 self.ss, self.es = ss, es
92 if len(self.mosi_bytes) == 0:
94 self.mosi_bytes.append(mosi)
96 # Writes/reads are mostly two transfers (burst mode is different).
97 if len(self.mosi_bytes) != 2:
101 cmd, arg = self.mosi_bytes
104 reg_desc = regs.get(reg, 'Reserved %#x' % reg)
108 self.putx([1, ['%s: %#x' % (reg_desc, arg)]])
110 self.putx([0, ['%s: %d' % (reg_desc, arg)]])