summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
Diffstat (limited to 'decoders')
-rw-r--r--decoders/Makefile.am3
-rw-r--r--decoders/ddc.py74
-rw-r--r--decoders/i2c.py70
3 files changed, 102 insertions, 45 deletions
diff --git a/decoders/Makefile.am b/decoders/Makefile.am
index 72987f4..c27d69f 100644
--- a/decoders/Makefile.am
+++ b/decoders/Makefile.am
@@ -28,7 +28,8 @@ dist_pkgdata_DATA = \
spi.py \
srd_usb.py \
transitioncounter.py \
- uart.py
+ uart.py \
+ ddc.py
CLEANFILES = *.pyc
diff --git a/decoders/ddc.py b/decoders/ddc.py
new file mode 100644
index 0000000..09f6844
--- /dev/null
+++ b/decoders/ddc.py
@@ -0,0 +1,74 @@
+##
+## This file is part of the sigrok project.
+##
+## Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
+##
+## 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 3 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, If not, see <http://www.gnu.org/licenses/>.
+##
+
+#
+# DDC protocol decoder
+#
+# This decoder extracts a DDC stream from an I2C session between a computer
+# and a display device. The stream is output as plain bytes.
+#
+
+import sigrokdecode
+
+
+class Decoder(sigrokdecode.Decoder):
+ id = 'ddc'
+ name = 'DDC'
+ longname = 'Display Data Channel'
+ desc = 'DDC is a protocol for communication between computers and displays.'
+ longdesc = ''
+ author = 'Bert Vermeulen <bert@biot.com>'
+ license = 'gplv3+'
+ inputs = ['i2c']
+ outputs = ['ddc']
+ annotation = [
+ ["Byte stream", "DDC byte stream as read from display."],
+ ]
+
+ def __init__(self, **kwargs):
+ self.state = None
+
+ def start(self, metadata):
+ self.output_annotation = self.add(sigrokdecode.SRD_OUTPUT_ANNOTATION, 'ddc')
+
+ def decode(self, start_sample, end_sample, i2c_data):
+ try:
+ cmd, data, ack_bit = i2c_data
+ except Exception as e:
+ raise Exception("malformed I2C input: %s" % str(e)) from e
+
+ if self.state is None:
+ # waiting for the DDC session to start
+ if cmd in ('START', 'START_REPEAT'):
+ self.state = 'start'
+ elif self.state == 'start':
+ if cmd == 'ADDRESS_READ' and data == 80:
+ # 80 is the I2C slave address of a connected display,
+ # so this marks the start of the DDC data transfer.
+ self.state = 'transfer'
+ elif cmd == 'STOP':
+ # back to idle
+ self.state = None
+ elif self.state == 'transfer':
+ if cmd == 'DATA_READ':
+ # there shouldn't be anything but data reads on this
+ # address, so ignore everything else
+ self.put(start_sample, end_sample, self.output_annotation,
+ [0, ["0x%.2x" % data]])
+
diff --git a/decoders/i2c.py b/decoders/i2c.py
index f098aff..08d0053 100644
--- a/decoders/i2c.py
+++ b/decoders/i2c.py
@@ -65,52 +65,41 @@
# TODO: Implement support for 7bit and 10bit slave addresses.
# TODO: Implement support for inverting SDA/SCL levels (0->1 and 1->0).
# TODO: Implement support for detecting various bus errors.
-
-#
-# I2C output format:
-#
-# The output consists of a (Python) list of I2C "packets", each of which
-# has an (implicit) index number (its index in the list).
-# Each packet consists of a Python dict with certain key/value pairs.
-#
-# TODO: Make this a list later instead of a dict?
-#
-# 'type': (string)
-# - 'S' (START condition)
-# - 'Sr' (Repeated START)
-# - 'AR' (Address, read)
-# - 'AW' (Address, write)
-# - 'DR' (Data, read)
-# - 'DW' (Data, write)
-# - 'P' (STOP condition)
-# 'range': (tuple of 2 integers, the min/max samplenumber of this range)
-# - (min, max)
-# - min/max can also be identical.
-# 'data': (actual data as integer ???) TODO: This can be very variable...
-# 'ann': (string; additional annotations / comments)
-#
# TODO: I2C address of slaves.
# TODO: Handle multiple different I2C devices on same bus
# -> we need to decode multiple protocols at the same time.
-#
#
-# I2C input format:
+# I2C protocol output format:
+#
+# The protocol output consists of a (Python) list of I2C "packets", each of
+# which is of the form
+#
+# [ _i2c_command_, _data_, _ack_bit_ ]
+#
+# _i2c_command_ is one of:
+# - 'START' (START condition)
+# - 'START_REPEAT' (Repeated START)
+# - 'ADDRESS_READ' (Address, read)
+# - 'ADDRESS_WRITE' (Address, write)
+# - 'DATA_READ' (Data, read)
+# - 'DATA_WRITE' (Data, write)
+# - 'STOP' (STOP condition)
#
-# signals:
-# [[id, channel, description], ...] # TODO
+# _data_ is the data or address byte associated with the ADDRESS_* and DATA_*
+# command. For START, START_REPEAT and STOP, this is None.
#
-# Example:
-# {'id': 'SCL', 'ch': 5, 'desc': 'Serial clock line'}
-# {'id': 'SDA', 'ch': 7, 'desc': 'Serial data line'}
-# ...
+# _ack_bit_ is either 'ACK' or 'NACK', but may also be None.
#
-# {'inbuf': [...],
-# 'signals': [{'SCL': }]}
#
import sigrokdecode
+# annotation feed formats
+ANN_SHIFTED = 0
+ANN_SHIFTED_SHORT = 1
+ANN_RAW = 2
+
# values are verbose and short annotation, respectively
protocol = {
'START': ['START', 'S'],
@@ -123,19 +112,12 @@ protocol = {
'DATA_READ': ['DATA READ', 'DR'],
'DATA_WRITE': ['DATA WRITE', 'DW'],
}
-# export protocol keys as symbols for i2c decoders up the stack
-EXPORT = [ protocol.keys() ]
# States
FIND_START = 0
FIND_ADDRESS = 1
FIND_DATA = 2
-# annotation feed formats
-ANN_SHIFTED = 0
-ANN_SHIFTED_SHORT = 1
-ANN_RAW = 2
-
class Decoder(sigrokdecode.Decoder):
id = 'i2c'
@@ -209,7 +191,7 @@ class Decoder(sigrokdecode.Decoder):
cmd = 'START_REPEAT'
else:
cmd = 'START'
- self.put(self.output_protocol, [ cmd ])
+ self.put(self.output_protocol, [ cmd, None, None ])
self.put(self.output_annotation, [ ANN_SHIFTED, [protocol[cmd][0]] ])
self.put(self.output_annotation, [ ANN_SHIFTED_SHORT, [protocol[cmd][1]] ])
@@ -269,7 +251,7 @@ class Decoder(sigrokdecode.Decoder):
cmd = 'DATA_WRITE'
elif self.state == FIND_DATA and self.wr == 0:
cmd = 'DATA_READ'
- self.put(self.output_protocol, [ [cmd, d], [ack_bit] ] )
+ self.put(self.output_protocol, [ cmd, d, ack_bit ] )
self.put(self.output_annotation, [ANN_SHIFTED, [
"%s" % protocol[cmd][0],
"0x%02x" % d,
@@ -292,7 +274,7 @@ class Decoder(sigrokdecode.Decoder):
pass
def found_stop(self, scl, sda):
- self.put(self.output_protocol, [ 'STOP' ])
+ self.put(self.output_protocol, [ 'STOP', None, None ])
self.put(self.output_annotation, [ ANN_SHIFTED, [protocol['STOP'][0]] ])
self.put(self.output_annotation, [ ANN_SHIFTED_SHORT, [protocol['STOP'][1]] ])