]>
Commit | Line | Data |
---|---|---|
2c173272 MR |
1 | ## |
2 | ## This file is part of the libsigrokdecode project. | |
3 | ## | |
4 | ## Copyright (C) 2014 Matt Ranostay <mranostay@gmail.com> | |
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, write to the Free Software | |
18 | ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | ## | |
20 | ||
21 | import sigrokdecode as srd | |
22 | ||
23 | class Decoder(srd.Decoder): | |
12851357 | 24 | api_version = 2 |
ae036d34 | 25 | id = 'rgb_led_spi' |
e85b0440 UH |
26 | name = 'RGB LED (SPI)' |
27 | longname = 'RGB LED string decoder (SPI)' | |
8967e839 | 28 | desc = 'Generic RGB LED string protocol (RGB values clocked over SPI).' |
2c173272 MR |
29 | license = 'gplv2' |
30 | inputs = ['spi'] | |
ae036d34 | 31 | outputs = ['rgb_led_spi'] |
da9bcbd9 BV |
32 | annotations = ( |
33 | ('rgb', 'RGB values'), | |
34 | ) | |
2c173272 MR |
35 | |
36 | def __init__(self, **kwargs): | |
37 | self.cmd_ss, self.cmd_es = 0, 0 | |
38 | self.mosi_bytes = [] | |
39 | ||
40 | def start(self): | |
41 | self.out_ann = self.register(srd.OUTPUT_ANN) | |
42 | ||
43 | def putx(self, data): | |
44 | self.put(self.cmd_ss, self.cmd_es, self.out_ann, data) | |
45 | ||
46 | def decode(self, ss, es, data): | |
47 | ptype, mosi, miso = data | |
48 | ||
8967e839 | 49 | # Only care about data packets. |
2c173272 MR |
50 | if ptype != 'DATA': |
51 | return | |
52 | self.ss, self.es = ss, es | |
53 | ||
54 | if len(self.mosi_bytes) == 0: | |
55 | self.cmd_ss = ss | |
56 | self.mosi_bytes.append(mosi) | |
57 | ||
58 | # RGB value == 3 bytes | |
59 | if len(self.mosi_bytes) != 3: | |
60 | return | |
61 | ||
8967e839 | 62 | red, green, blue = self.mosi_bytes |
35b380b1 | 63 | rgb_value = int(red) << 16 | int(green) << 8 | int(blue) |
2c173272 | 64 | |
83d792a4 | 65 | self.cmd_es = es |
21b39043 | 66 | self.putx([0, ['#%.6x' % rgb_value]]) |
2c173272 | 67 | self.mosi_bytes = [] |