]>
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 | |
4539e9ca | 17 | ## along with this program; if not, see <http://www.gnu.org/licenses/>. |
2c173272 MR |
18 | ## |
19 | ||
20 | import sigrokdecode as srd | |
21 | ||
22 | class Decoder(srd.Decoder): | |
b197383c | 23 | api_version = 3 |
ae036d34 | 24 | id = 'rgb_led_spi' |
e85b0440 UH |
25 | name = 'RGB LED (SPI)' |
26 | longname = 'RGB LED string decoder (SPI)' | |
a7c8dc5e | 27 | desc = 'RGB LED string protocol (RGB values clocked over SPI).' |
9eac0fe3 | 28 | license = 'gplv2+' |
2c173272 | 29 | inputs = ['spi'] |
ae036d34 | 30 | outputs = ['rgb_led_spi'] |
da9bcbd9 BV |
31 | annotations = ( |
32 | ('rgb', 'RGB values'), | |
33 | ) | |
2c173272 | 34 | |
92b7b49f | 35 | def __init__(self): |
10aeb8ea GS |
36 | self.reset() |
37 | ||
38 | def reset(self): | |
486b19ce | 39 | self.ss_cmd, self.es_cmd = 0, 0 |
2c173272 MR |
40 | self.mosi_bytes = [] |
41 | ||
42 | def start(self): | |
43 | self.out_ann = self.register(srd.OUTPUT_ANN) | |
44 | ||
45 | def putx(self, data): | |
486b19ce | 46 | self.put(self.ss_cmd, self.es_cmd, self.out_ann, data) |
2c173272 MR |
47 | |
48 | def decode(self, ss, es, data): | |
49 | ptype, mosi, miso = data | |
50 | ||
8967e839 | 51 | # Only care about data packets. |
2c173272 MR |
52 | if ptype != 'DATA': |
53 | return | |
54 | self.ss, self.es = ss, es | |
55 | ||
56 | if len(self.mosi_bytes) == 0: | |
486b19ce | 57 | self.ss_cmd = ss |
2c173272 MR |
58 | self.mosi_bytes.append(mosi) |
59 | ||
60 | # RGB value == 3 bytes | |
61 | if len(self.mosi_bytes) != 3: | |
62 | return | |
63 | ||
8967e839 | 64 | red, green, blue = self.mosi_bytes |
35b380b1 | 65 | rgb_value = int(red) << 16 | int(green) << 8 | int(blue) |
2c173272 | 66 | |
486b19ce | 67 | self.es_cmd = es |
21b39043 | 68 | self.putx([0, ['#%.6x' % rgb_value]]) |
2c173272 | 69 | self.mosi_bytes = [] |