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'
46 desc = 'Bidirectional optical mouse sensor protocol.'
50 tags = ['IC', 'PC', 'Sensor']
52 ('read', 'Register read'),
53 ('write', 'Register write'),
54 ('warning', 'Warning'),
57 ('reads', 'Reads', (0,)),
58 ('writes', 'Writes', (1,)),
59 ('warnings', 'Warnings', (2,)),
66 self.ss_cmd, self.es_cmd = 0, 0
70 self.out_ann = self.register(srd.OUTPUT_ANN)
73 self.put(self.ss_cmd, self.es_cmd, self.out_ann, data)
75 def put_warn(self, pos, msg):
76 self.put(pos[0], pos[1], self.out_ann, [2, [msg]])
78 def decode(self, ss, es, data):
80 if ptype == 'CS-CHANGE':
81 # If we transition high mid-stream, toss out our data and restart.
82 cs_old, cs_new = data[1:]
83 if cs_old is not None and cs_old == 0 and cs_new == 1:
84 if len(self.mosi_bytes) not in [0, 2]:
85 self.put_warn([self.ss_cmd, es], 'Misplaced CS#!')
89 # Don't care about anything else.
94 self.ss, self.es = ss, es
96 if len(self.mosi_bytes) == 0:
98 self.mosi_bytes.append(mosi)
100 # Writes/reads are mostly two transfers (burst mode is different).
101 if len(self.mosi_bytes) != 2:
105 cmd, arg = self.mosi_bytes
108 reg_desc = regs.get(reg, 'Reserved %#x' % reg)
112 self.putx([1, ['%s: %#x' % (reg_desc, arg)]])
114 self.putx([0, ['%s: %d' % (reg_desc, arg)]])