]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/ddc/ddc.py
ddc: add protocol output
[libsigrokdecode.git] / decoders / ddc / ddc.py
index f83909323b8b2a70d6d894f6e0db1a2ef22d91d4..2cb4552dc9ab6392c54261c44568c81a77a7db99 100644 (file)
@@ -14,7 +14,7 @@
 ## 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/>.
+## along with this program; if not, see <http://www.gnu.org/licenses/>.
 ##
 
 '''
@@ -28,31 +28,32 @@ https://en.wikipedia.org/wiki/Display_Data_Channel
 import sigrokdecode as srd
 
 class Decoder(srd.Decoder):
+    api_version = 1
     id = 'ddc'
-    name = 'DDC'
+    name = 'DDC2'
     longname = 'Display Data Channel'
     desc = 'A protocol for communication between computers and displays.'
     longdesc = ''
     license = 'gplv3+'
     inputs = ['i2c']
-    outputs = ['ddc']
-    probes = []
+    outputs = ['ddc2']
     options = {}
     annotations = [
-        ['Byte stream', 'DDC byte stream as read from display.'],
+        ['Byte stream', 'DDC2B 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')
+        self.out_proto = self.add(srd.OUTPUT_PROTO, 'ddc2')
+        self.out_ann = self.add(srd.OUTPUT_ANN, 'ddc2')
 
     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
+            raise Exception('Malformed I2C input: %s' % str(e)) from e
 
         if self.state is None:
             # Wait for the DDC session to start.
@@ -70,5 +71,8 @@ class Decoder(srd.Decoder):
             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_proto, data)
                 self.put(ss, es, self.out_ann, [0, ['0x%.2x' % data]])
+        else:
+            raise Exception('Invalid state: %s' % self.state)