]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/eeprom93xx/pd.py
eeprom93xx: Add ascii format support
[libsigrokdecode.git] / decoders / eeprom93xx / pd.py
index 5ae789f3f5c1fa103046eacfbbb21eb80d78f764..68649b5cfba1283cbc70c3314574d0a9428eefb4 100644 (file)
 import sigrokdecode as srd
 
 class Decoder(srd.Decoder):
-    api_version = 2
+    api_version = 3
     id = 'eeprom93xx'
     name = '93xx EEPROM'
     longname = '93xx Microwire EEPROM'
     desc = '93xx series Microwire EEPROM protocol.'
     license = 'gplv2+'
     inputs = ['microwire']
-    outputs = ['eeprom93xx']
+    outputs = []
+    tags = ['IC', 'Memory']
     options = (
         {'id': 'addresssize', 'desc': 'Address size', 'default': 8},
         {'id': 'wordsize', 'desc': 'Word size', 'default': 16},
+        {'id': 'format', 'desc': 'Data format', 'default': 'hex',
+            'values': ('ascii', 'hex')},
     )
     annotations = (
         ('si-data', 'SI data'),
@@ -43,6 +46,9 @@ class Decoder(srd.Decoder):
     )
 
     def __init__(self):
+        self.reset()
+
+    def reset(self):
         self.frame = []
 
     def start(self):
@@ -65,8 +71,20 @@ class Decoder(srd.Decoder):
             d = data[b].si if si else data[b].so
             word += (d << (len(data) - b - 1))
         idx = 0 if si else 1
-        self.put(data[0].ss, data[-1].es,
-                 self.out_ann, [idx, ['Data: 0x%x' % word, '0x%x' % word]])
+
+        if self.options['format'] == 'ascii':
+            word_str = ''
+            for s in range(0, len(data), 8):
+                c = 0xff & (word >> s)
+                if c in range(32, 126 + 1):
+                    word_str = chr(c) + word_str
+                else:
+                    word_str = '[{:02X}]'.format(c) + word_str
+            self.put(data[0].ss, data[-1].es,
+                    self.out_ann, [idx, ['Data: %s' % word_str, '%s' % word_str]])
+        else:
+            self.put(data[0].ss, data[-1].es,
+                    self.out_ann, [idx, ['Data: 0x%x' % word, '0x%x' % word]])
 
     def decode(self, ss, es, data):
         if len(data) < (2 + self.addresssize):