2 ## This file is part of the libsigrokdecode project.
4 ## Copyright (C) 2020 Analog Devices Inc.
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.
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.
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/>.
20 import sigrokdecode as srd
22 input_voltage_format = ['%.6fV', '%.2fV']
24 class Decoder(srd.Decoder):
28 longname = 'Linear Technology LTC242x'
29 desc = 'Linear Technology LTC2421/LTC2422 1-/2-channel 20-bit ADC.'
33 tags = ['IC', 'Analog/digital']
35 ('ch0_voltage', 'CH0 voltage'),
36 ('ch1_voltage', 'CH1 voltage'),
39 ('ch0_voltages', 'CH0 voltages', (0,)),
40 ('ch1_voltages', 'CH1 voltages', (1,)),
43 {'id': 'vref', 'desc': 'Reference voltage (V)', 'default': 1.5},
51 self.ss, self.es = 0, 0
54 self.out_ann = self.register(srd.OUTPUT_ANN)
56 def handle_input_voltage(self, data):
57 input_voltage = data & 0x3FFFFF
58 input_voltage = -(2**21 - input_voltage)
59 input_voltage = (input_voltage / 0xfffff) * self.options['vref']
61 for format in input_voltage_format:
62 ann.append(format % input_voltage)
64 channel = (data & (1 << 22)) >> 22
65 self.put(self.ss, self.es, self.out_ann, [channel, ann])
67 def decode(self, ss, es, data):
70 if ptype == 'CS-CHANGE':
71 cs_old, cs_new = data[1:]
72 if cs_old is not None and cs_old == 0 and cs_new == 1:
75 self.handle_input_voltage(self.data)
78 elif cs_old is not None and cs_old == 1 and cs_new == 0:
83 for bit in reversed(miso):
84 self.data = self.data | bit[0]