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, write to the Free Software
18 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 import sigrokdecode as srd
42 class Decoder(srd.Decoder):
46 longname = 'Avago ADNS-5020 optical mouse sensor'
47 desc = 'Bidirectional command and data over an SPI-like protocol.'
50 outputs = ['adns5020']
52 ('read', 'Register read commands'),
53 ('write', 'Register write commands'),
54 ('warning', 'Warnings'),
57 ('read', 'Read', (0,)),
58 ('write', 'Write', (1,)),
59 ('warnings', 'Warnings', (2,)),
62 def __init__(self, **kwargs):
63 self.ss_cmd, self.es_cmd = 0, 0
67 self.out_ann = self.register(srd.OUTPUT_ANN)
70 self.put(self.ss_cmd, self.es_cmd, self.out_ann, data)
72 def put_warn(self, pos, msg):
73 self.put(pos[0], pos[1], self.out_ann, [2, [msg]])
75 def decode(self, ss, es, data):
77 if ptype == 'CS-CHANGE':
78 # If we transition high mid-stream, toss out our data and restart.
79 cs_old, cs_new = data[1:]
80 if cs_old is not None and cs_old == 0 and cs_new == 1:
81 if len(self.mosi_bytes) not in [0, 2]:
82 self.put_warn([self.ss_cmd, es], 'Misplaced CS#!')
86 # Don't care about anything else.
91 self.ss, self.es = ss, es
93 if len(self.mosi_bytes) == 0:
95 self.mosi_bytes.append(mosi)
97 # Writes/reads are mostly two transfers (burst mode is different).
98 if len(self.mosi_bytes) != 2:
102 cmd, arg = self.mosi_bytes
105 reg_desc = regs.get(reg, 'Reserved %#x' % reg)
109 self.putx([1, ['%s: %#x' % (reg_desc, arg)]])
111 self.putx([0, ['%s: %d' % (reg_desc, arg)]])