summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2012-11-20 16:32:02 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2012-11-21 02:07:35 +0100
commit92d1aba34bbe661b388e874fda0a41f477d3e30d (patch)
tree70988d7b6349c0c7af0ad4f553fefc352eca73c1
parent1859c4804d04b58ba15a316eb16035c6bbb611fe (diff)
downloadlibsigrokdecode-92d1aba34bbe661b388e874fda0a41f477d3e30d.tar.gz
libsigrokdecode-92d1aba34bbe661b388e874fda0a41f477d3e30d.zip
Initial TI TLC5620 (8-bit quad DAC) protocol decoder.
-rw-r--r--configure.ac1
-rw-r--r--decoders/Makefile.am1
-rw-r--r--decoders/tlc5620/Makefile.am26
-rw-r--r--decoders/tlc5620/__init__.py31
-rw-r--r--decoders/tlc5620/pd.py118
5 files changed, 177 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 935e832..7707dc4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -168,6 +168,7 @@ AC_CONFIG_FILES([Makefile
decoders/rtc8564/Makefile
decoders/sdcard_spi/Makefile
decoders/spi/Makefile
+ decoders/tlc5620/Makefile
decoders/transitioncounter/Makefile
decoders/uart/Makefile
decoders/uart_dump/Makefile
diff --git a/decoders/Makefile.am b/decoders/Makefile.am
index d5ebd7d..6291b37 100644
--- a/decoders/Makefile.am
+++ b/decoders/Makefile.am
@@ -39,6 +39,7 @@ SUBDIRS = \
rtc8564 \
sdcard_spi \
spi \
+ tlc5620 \
transitioncounter \
uart \
uart_dump \
diff --git a/decoders/tlc5620/Makefile.am b/decoders/tlc5620/Makefile.am
new file mode 100644
index 0000000..d246526
--- /dev/null
+++ b/decoders/tlc5620/Makefile.am
@@ -0,0 +1,26 @@
+##
+## This file is part of the sigrok project.
+##
+## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+##
+
+pkgdatadir = $(DECODERS_DIR)/tlc5620
+
+dist_pkgdata_DATA = __init__.py pd.py
+
+CLEANFILES = *.pyc
+
diff --git a/decoders/tlc5620/__init__.py b/decoders/tlc5620/__init__.py
new file mode 100644
index 0000000..da136b6
--- /dev/null
+++ b/decoders/tlc5620/__init__.py
@@ -0,0 +1,31 @@
+##
+## This file is part of the sigrok project.
+##
+## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+##
+
+'''
+Texas Instruments TLC5620 protocol decoder.
+
+TODO: Description.
+
+Details:
+TODO
+'''
+
+from .pd import *
+
diff --git a/decoders/tlc5620/pd.py b/decoders/tlc5620/pd.py
new file mode 100644
index 0000000..71bfb2c
--- /dev/null
+++ b/decoders/tlc5620/pd.py
@@ -0,0 +1,118 @@
+##
+## This file is part of the sigrok project.
+##
+## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+##
+
+# Texas Instruments TLC5620 protocol decoder
+
+import sigrokdecode as srd
+
+dacs = {
+ 0: 'DACA',
+ 1: 'DACB',
+ 2: 'DACC',
+ 3: 'DACD',
+}
+
+class Decoder(srd.Decoder):
+ api_version = 1
+ id = 'tlc5620'
+ name = 'TI TLC5620'
+ longname = 'Texas Instruments TLC5620'
+ desc = 'Texas Instruments TLC5620 8-bit quad DAC.'
+ license = 'gplv2+'
+ inputs = ['logic']
+ outputs = ['tlc5620']
+ probes = [
+ {'id': 'clk', 'name': 'CLK', 'desc': 'Serial interface clock'},
+ {'id': 'data', 'name': 'DATA', 'desc': 'Serial interface data'},
+ ]
+ optional_probes = [
+ {'id': 'load', 'name': 'LOAD', 'desc': 'Serial interface load control'},
+ {'id': 'ldac', 'name': 'LDAC', 'desc': 'Load DAC'},
+ ]
+ options = {}
+ annotations = [
+ ['Text', 'Human-readable text'],
+ ['Warnings', 'Human-readable warnings'],
+ ]
+
+ def __init__(self, **kwargs):
+ self.state = 'IDLE'
+ self.oldpins = None
+ self.oldclk = None
+ self.bits = []
+ self.ss_dac = self.es_dac = 0
+ self.ss_gain = self.es_gain = 0
+ self.ss_value = self.es_value = 0
+
+ def start(self, metadata):
+ # self.out_proto = self.add(srd.OUTPUT_PROTO, 'tlc5620')
+ self.out_ann = self.add(srd.OUTPUT_ANN, 'tlc5620')
+
+ def report(self):
+ pass
+
+ def handle_11bits(self):
+ s = "".join(str(i) for i in self.bits[:2])
+ self.put(self.ss_dac, self.es_dac, self.out_ann,
+ [0, ['DAC select: %s' % dacs[int(s, 2)]]])
+
+ self.put(self.ss_gain, self.es_gain, self.out_ann,
+ [0, ['Gain: x%d' % (1 + self.bits[2])]])
+
+ s = "".join(str(i) for i in self.bits[3:])
+ self.put(self.ss_value, self.es_value, self.out_ann,
+ [0, ['DAC value: %d' % int(s, 2)]])
+
+ self.bits = []
+
+ def decode(self, ss, es, data):
+ for (self.samplenum, pins) in data:
+
+ # Ignore identical samples early on (for performance reasons).
+ if self.oldpins == pins:
+ continue
+ self.oldpins, (clk, data, load, ldac) = pins, pins
+
+ # DATA is shifted in the DAC on the falling CLK edge (MSB-first).
+ # TODO: Handle various LOAD-/LDAC-controlled methods.
+ if not (self.oldclk == 1 and clk == 0):
+ self.oldclk = clk
+ continue
+
+ # The DAC has received a new bit, store it.
+ self.bits.append(data)
+
+ if self.state == 'IDLE':
+ # Wait until we have read 11 bits, then parse them.
+ l, s = len(self.bits), self.samplenum
+ if l == 1:
+ self.ss_dac = s
+ elif l == 2:
+ self.es_dac = self.ss_gain = s
+ elif l == 3:
+ self.es_gain = self.ss_value = s
+ elif l == 11:
+ self.es_value = s
+ self.handle_11bits()
+ else:
+ raise Exception('Invalid state: %s' % self.state)
+
+ self.oldclk = clk
+