]> sigrok.org Git - libsigrokdecode.git/blob - decoders/ad5626/pd.py
ad5626: Rename an annotation class.
[libsigrokdecode.git] / decoders / ad5626 / pd.py
1 ##
2 ## This file is part of the libsigrokdecode project.
3 ##
4 ## Copyright (C) 2020 Analog Devices Inc.
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 3 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 class Decoder(srd.Decoder):
23     api_version = 3
24     id = 'ad5626'
25     name = 'AD5626'
26     longname = 'Analog Devices AD5626'
27     desc = 'Analog Devices AD5626 12-bit nanoDAC.'
28     license = 'gplv2+'
29     inputs = ['spi']
30     outputs = []
31     tags = ['IC', 'Analog/digital']
32     annotations = (
33         ('voltage', 'Voltage'),
34     )
35
36     def __init__(self,):
37         self.reset()
38
39     def reset(self):
40         self.data = 0
41         self.ss = 0
42
43     def start(self):
44         self.out_ann = self.register(srd.OUTPUT_ANN)
45
46     def put_data(self, pos, data):
47         self.put(pos[0], pos[1], self.out_ann, [0, [str(data) + 'V']])
48
49     def decode(self, ss, es, data):
50         ptype = data[0]
51
52         if ptype == 'CS-CHANGE':
53             cs_old, cs_new = data[1:]
54             if cs_old is not None and cs_old == 0 and cs_new == 1:
55                 self.data >>= 1
56                 self.data /= 1000
57                 self.put_data([self.ss, es], self.data)
58                 self.data = 0
59             elif cs_old is not None and cs_old == 1 and cs_new == 0:
60                 self.ss = ss
61         elif ptype == 'BITS':
62             mosi = data[1]
63             for bit in reversed(mosi):
64                 self.data = self.data | bit[0]
65                 self.data <<= 1