]>
Commit | Line | Data |
---|---|---|
1 | ## | |
2 | ## This file is part of the libsigrokdecode project. | |
3 | ## | |
4 | ## Copyright (C) 2015 Karl Palsson <karlp@tweak.net.au> | |
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, see <http://www.gnu.org/licenses/>. | |
18 | ## | |
19 | ||
20 | import sigrokdecode as srd | |
21 | ||
22 | regs = { | |
23 | 0: 'Product_ID', | |
24 | 1: 'Revision_ID', | |
25 | 2: 'Motion', | |
26 | 3: 'Delta_X', | |
27 | 4: 'Delta_Y', | |
28 | 5: 'SQUAL', | |
29 | 6: 'Shutter_Upper', | |
30 | 7: 'Shutter_Lower', | |
31 | 8: 'Maximum_Pixel', | |
32 | 9: 'Pixel_Sum', | |
33 | 0xa: 'Minimum_Pixel', | |
34 | 0xb: 'Pixel_Grab', | |
35 | 0xd: 'Mouse_Control', | |
36 | 0x3a: 'Chip_Reset', | |
37 | 0x3f: 'Inv_Rev_ID', | |
38 | 0x63: 'Motion_Burst', | |
39 | } | |
40 | ||
41 | class Decoder(srd.Decoder): | |
42 | api_version = 3 | |
43 | id = 'adns5020' | |
44 | name = 'ADNS-5020' | |
45 | longname = 'Avago ADNS-5020' | |
46 | desc = 'Bidirectional optical mouse sensor protocol.' | |
47 | license = 'gplv2+' | |
48 | inputs = ['spi'] | |
49 | outputs = [] | |
50 | tags = ['IC', 'PC', 'Sensor'] | |
51 | annotations = ( | |
52 | ('read', 'Register read'), | |
53 | ('write', 'Register write'), | |
54 | ('warning', 'Warning'), | |
55 | ) | |
56 | annotation_rows = ( | |
57 | ('reads', 'Reads', (0,)), | |
58 | ('writes', 'Writes', (1,)), | |
59 | ('warnings', 'Warnings', (2,)), | |
60 | ) | |
61 | ||
62 | def __init__(self): | |
63 | self.reset() | |
64 | ||
65 | def reset(self): | |
66 | self.ss_cmd, self.es_cmd = 0, 0 | |
67 | self.mosi_bytes = [] | |
68 | ||
69 | def start(self): | |
70 | self.out_ann = self.register(srd.OUTPUT_ANN) | |
71 | ||
72 | def putx(self, data): | |
73 | self.put(self.ss_cmd, self.es_cmd, self.out_ann, data) | |
74 | ||
75 | def put_warn(self, pos, msg): | |
76 | self.put(pos[0], pos[1], self.out_ann, [2, [msg]]) | |
77 | ||
78 | def decode(self, ss, es, data): | |
79 | ptype = data[0] | |
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#!') | |
86 | self.mosi_bytes = [] | |
87 | return | |
88 | ||
89 | # Don't care about anything else. | |
90 | if ptype != 'DATA': | |
91 | return | |
92 | mosi, miso = data[1:] | |
93 | ||
94 | self.ss, self.es = ss, es | |
95 | ||
96 | if len(self.mosi_bytes) == 0: | |
97 | self.ss_cmd = ss | |
98 | self.mosi_bytes.append(mosi) | |
99 | ||
100 | # Writes/reads are mostly two transfers (burst mode is different). | |
101 | if len(self.mosi_bytes) != 2: | |
102 | return | |
103 | ||
104 | self.es_cmd = es | |
105 | cmd, arg = self.mosi_bytes | |
106 | write = cmd & 0x80 | |
107 | reg = cmd & 0x7f | |
108 | reg_desc = regs.get(reg, 'Reserved %#x' % reg) | |
109 | if reg > 0x63: | |
110 | reg_desc = 'Unknown' | |
111 | if write: | |
112 | self.putx([1, ['%s: %#x' % (reg_desc, arg)]]) | |
113 | else: | |
114 | self.putx([0, ['%s: %d' % (reg_desc, arg)]]) | |
115 | ||
116 | self.mosi_bytes = [] |