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,)),
65 self.ss_cmd, self.es_cmd = 0, 0
69 self.out_ann = self.register(srd.OUTPUT_ANN)
72 self.put(self.ss_cmd, self.es_cmd, self.out_ann, data)
74 def put_warn(self, pos, msg):
75 self.put(pos[0], pos[1], self.out_ann, [2, [msg]])
77 def decode(self, ss, es, data):
79 if ptype == 'CS-CHANGE':
80 # If we transition high mid-stream, toss out our data and restart.
81 cs_old, cs_new = data[1:]
82 if cs_old is not None and cs_old == 0 and cs_new == 1:
83 if len(self.mosi_bytes) not in [0, 2]:
84 self.put_warn([self.ss_cmd, es], 'Misplaced CS#!')
88 # Don't care about anything else.
93 self.ss, self.es = ss, es
95 if len(self.mosi_bytes) == 0:
97 self.mosi_bytes.append(mosi)
99 # Writes/reads are mostly two transfers (burst mode is different).
100 if len(self.mosi_bytes) != 2:
104 cmd, arg = self.mosi_bytes
107 reg_desc = regs.get(reg, 'Reserved %#x' % reg)
111 self.putx([1, ['%s: %#x' % (reg_desc, arg)]])
113 self.putx([0, ['%s: %d' % (reg_desc, arg)]])