diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2012-01-15 15:36:01 +0100 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2012-01-15 18:18:23 +0100 |
commit | 64c29e28e0efa184319f7831b3eca18c7f73f7d0 (patch) | |
tree | 16b7c84aa9edefb61e01f70384ff280edb3f3483 /decoders/ddc | |
parent | d0a0ed032e0120140a28e93ac42753786bf0087b (diff) | |
download | libsigrokdecode-64c29e28e0efa184319f7831b3eca18c7f73f7d0.tar.gz libsigrokdecode-64c29e28e0efa184319f7831b3eca18c7f73f7d0.zip |
srd: Each PD now has its own subdirectory.
Diffstat (limited to 'decoders/ddc')
-rw-r--r-- | decoders/ddc/Makefile.am | 26 | ||||
-rw-r--r-- | decoders/ddc/__init__.py | 22 | ||||
-rw-r--r-- | decoders/ddc/ddc.py | 74 |
3 files changed, 122 insertions, 0 deletions
diff --git a/decoders/ddc/Makefile.am b/decoders/ddc/Makefile.am new file mode 100644 index 0000000..59c2c69 --- /dev/null +++ b/decoders/ddc/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)/ddc + +dist_pkgdata_DATA = __init__.py ddc.py + +CLEANFILES = *.pyc + diff --git a/decoders/ddc/__init__.py b/decoders/ddc/__init__.py new file mode 100644 index 0000000..95cf31e --- /dev/null +++ b/decoders/ddc/__init__.py @@ -0,0 +1,22 @@ +## +## 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 +## + +from .ddc import * + diff --git a/decoders/ddc/ddc.py b/decoders/ddc/ddc.py new file mode 100644 index 0000000..f839093 --- /dev/null +++ b/decoders/ddc/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/>. +## + +''' +This decoder extracts a DDC stream from an I2C session between a computer +and a display device. The stream is output as plain bytes. + +Details: +https://en.wikipedia.org/wiki/Display_Data_Channel +''' + +import sigrokdecode as srd + +class Decoder(srd.Decoder): + id = 'ddc' + name = 'DDC' + longname = 'Display Data Channel' + desc = 'A protocol for communication between computers and displays.' + longdesc = '' + license = 'gplv3+' + inputs = ['i2c'] + outputs = ['ddc'] + probes = [] + options = {} + annotations = [ + ['Byte stream', 'DDC byte stream as read from display.'], + ] + + def __init__(self, **kwargs): + self.state = None + + def start(self, metadata): + self.out_ann = self.add(srd.OUTPUT_ANN, 'ddc') + + def decode(self, ss, es, data): + try: + cmd, data, ack_bit = data + except Exception as e: + raise Exception('malformed I2C input: %s' % str(e)) from e + + if self.state is None: + # Wait 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': + # Got back to the idle state. + 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(ss, es, self.out_ann, [0, ['0x%.2x' % data]]) + |