]> sigrok.org Git - libsigrokdecode.git/blame - decoders/ad5626/pd.py
ntf905: Add/rename required self.reset() method.
[libsigrokdecode.git] / decoders / ad5626 / pd.py
CommitLineData
e4038b06
TP
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
20import sigrokdecode as srd
21
22class 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 = []
b2404fdf 31 tags = ['IC', 'Analog/digital']
e4038b06 32 annotations = (
c10beafe 33 ('voltage', 'Voltage'),
e4038b06 34 )
e4038b06
TP
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
e4038b06
TP
46 def decode(self, ss, es, data):
47 ptype = data[0]
48
49 if ptype == 'CS-CHANGE':
50 cs_old, cs_new = data[1:]
51 if cs_old is not None and cs_old == 0 and cs_new == 1:
52 self.data >>= 1
53 self.data /= 1000
d1b0d3a3 54 self.put(self.ss, es, self.out_ann, [0, ['%.3fV' % self.data]])
e4038b06
TP
55 self.data = 0
56 elif cs_old is not None and cs_old == 1 and cs_new == 0:
57 self.ss = ss
58 elif ptype == 'BITS':
59 mosi = data[1]
60 for bit in reversed(mosi):
61 self.data = self.data | bit[0]
62 self.data <<= 1