]> sigrok.org Git - libsigrokdecode.git/blame - decoders/tlc5620/pd.py
s/out_proto/out_python/.
[libsigrokdecode.git] / decoders / tlc5620 / pd.py
CommitLineData
92d1aba3 1##
50bd5d25 2## This file is part of the libsigrokdecode project.
92d1aba3
UH
3##
4## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
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
17## along with this program; if not, write to the Free Software
18## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19##
20
92d1aba3
UH
21import sigrokdecode as srd
22
23dacs = {
24 0: 'DACA',
25 1: 'DACB',
26 2: 'DACC',
27 3: 'DACD',
28}
29
30class Decoder(srd.Decoder):
31 api_version = 1
32 id = 'tlc5620'
33 name = 'TI TLC5620'
34 longname = 'Texas Instruments TLC5620'
35 desc = 'Texas Instruments TLC5620 8-bit quad DAC.'
36 license = 'gplv2+'
37 inputs = ['logic']
38 outputs = ['tlc5620']
39 probes = [
40 {'id': 'clk', 'name': 'CLK', 'desc': 'Serial interface clock'},
41 {'id': 'data', 'name': 'DATA', 'desc': 'Serial interface data'},
42 ]
43 optional_probes = [
44 {'id': 'load', 'name': 'LOAD', 'desc': 'Serial interface load control'},
45 {'id': 'ldac', 'name': 'LDAC', 'desc': 'Load DAC'},
46 ]
47 options = {}
48 annotations = [
9f2f42c0 49 ['dac-select', 'DAC select'],
5f4de613
UH
50 ['gain', 'Gain'],
51 ['value', 'DAC value'],
9f2f42c0
UH
52 ['data-latch', 'Data latch point'],
53 ['ldac-fall', 'LDAC falling edge'],
92d1aba3
UH
54 ]
55
56 def __init__(self, **kwargs):
17db4008
UH
57 self.oldpins = self.oldclk = self.oldload = self.oldldac = None
58 self.datapin = None
92d1aba3
UH
59 self.bits = []
60 self.ss_dac = self.es_dac = 0
61 self.ss_gain = self.es_gain = 0
62 self.ss_value = self.es_value = 0
17db4008 63 self.dac_select = self.gain = self.dac_value = None
92d1aba3 64
8915b346 65 def start(self):
c515eed7 66 # self.out_python = self.register(srd.OUTPUT_PYTHON)
be465111 67 self.out_ann = self.register(srd.OUTPUT_ANN)
92d1aba3 68
92d1aba3
UH
69 def handle_11bits(self):
70 s = "".join(str(i) for i in self.bits[:2])
7fb4935e 71 self.dac_select = s = dacs[int(s, 2)]
92d1aba3 72 self.put(self.ss_dac, self.es_dac, self.out_ann,
7fb4935e
UH
73 [0, ['DAC select: %s' % s, 'DAC sel: %s' % s,
74 'DAC: %s' % s, 'D: %s' % s, s, s[3]]])
92d1aba3 75
7fb4935e 76 self.gain = g = 1 + self.bits[2]
92d1aba3 77 self.put(self.ss_gain, self.es_gain, self.out_ann,
7fb4935e 78 [1, ['Gain: x%d' % g, 'G: x%d' % g, 'x%d' % g]])
92d1aba3
UH
79
80 s = "".join(str(i) for i in self.bits[3:])
7fb4935e 81 self.dac_value = v = int(s, 2)
92d1aba3 82 self.put(self.ss_value, self.es_value, self.out_ann,
7fb4935e
UH
83 [2, ['DAC value: %d' % v, 'Value: %d' % v, 'Val: %d' % v,
84 'V: %d' % v, '%d' % v]])
17db4008
UH
85
86 def handle_falling_edge_load(self):
7fb4935e 87 s, v, g = self.dac_select, self.dac_value, self.gain
17db4008 88 self.put(self.samplenum, self.samplenum, self.out_ann,
7fb4935e
UH
89 [3, ['Setting %s value to %d (x%d gain)' % (s, v, g),
90 '%s=%d (x%d gain)' % (s, v, g)]])
17db4008
UH
91
92 def handle_falling_edge_ldac(self):
93 self.put(self.samplenum, self.samplenum, self.out_ann,
7fb4935e 94 [4, ['Falling edge on LDAC pin', 'LDAC fall', 'LDAC']])
17db4008
UH
95
96 def handle_new_dac_bit(self):
97 self.bits.append(self.datapin)
98
99 # Wait until we have read 11 bits, then parse them.
100 l, s = len(self.bits), self.samplenum
101 if l == 1:
102 self.ss_dac = s
103 elif l == 2:
104 self.es_dac = self.ss_gain = s
105 elif l == 3:
106 self.es_gain = self.ss_value = s
107 elif l == 11:
108 self.es_value = s
109 self.handle_11bits()
110 self.bits = []
92d1aba3
UH
111
112 def decode(self, ss, es, data):
113 for (self.samplenum, pins) in data:
114
115 # Ignore identical samples early on (for performance reasons).
116 if self.oldpins == pins:
117 continue
17db4008 118 self.oldpins, (clk, self.datapin, load, ldac) = pins, pins
92d1aba3
UH
119
120 # DATA is shifted in the DAC on the falling CLK edge (MSB-first).
17db4008 121 # A falling edge of LOAD will latch the data.
92d1aba3 122
17db4008
UH
123 if self.oldload == 1 and load == 0:
124 self.handle_falling_edge_load()
125 if self.oldldac == 1 and ldac == 0:
126 self.handle_falling_edge_ldac()
127 if self.oldclk == 1 and clk == 0:
128 self.handle_new_dac_bit()
92d1aba3
UH
129
130 self.oldclk = clk
17db4008
UH
131 self.oldload = load
132 self.oldldac = ldac
92d1aba3 133