]> sigrok.org Git - libsigrokdecode.git/blame - decoders/ad5626/pd.py
ad5626: Fix the tags metadata item.
[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
TP
32 annotations = (
33 ('data', 'Data'),
34 )
35 annotation_rows = (
36 ('data', 'Data', (0,)),
37 )
38
39 def __init__(self,):
40 self.reset()
41
42 def reset(self):
43 self.data = 0
44 self.ss = 0
45
46 def start(self):
47 self.out_ann = self.register(srd.OUTPUT_ANN)
48
49 def put_data(self, pos, data):
50 self.put(pos[0], pos[1], self.out_ann, [0, [str(data) + 'V']])
51
52 def decode(self, ss, es, data):
53 ptype = data[0]
54
55 if ptype == 'CS-CHANGE':
56 cs_old, cs_new = data[1:]
57 if cs_old is not None and cs_old == 0 and cs_new == 1:
58 self.data >>= 1
59 self.data /= 1000
60 self.put_data([self.ss, es], self.data)
61 self.data = 0
62 elif cs_old is not None and cs_old == 1 and cs_new == 0:
63 self.ss = ss
64 elif ptype == 'BITS':
65 mosi = data[1]
66 for bit in reversed(mosi):
67 self.data = self.data | bit[0]
68 self.data <<= 1