]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/cc1101/pd.py
cc1101: Shorten decode_register() to decode_reg().
[libsigrokdecode.git] / decoders / cc1101 / pd.py
index 24352f6232add525a9e1e9b6935e98e8dd61b751..8c4c63123041b7e446c4e23f84630d3fa34217a8 100644 (file)
@@ -108,7 +108,7 @@ class Decoder(srd.Decoder):
 
         self.cmd, self.dat, self.min, self.max = c
 
-        if self.cmd in ('STROBE_CMD',):
+        if self.cmd == 'Strobe':
             self.putp(pos, ANN_STROBE, self.format_command())
         else:
             # Don't output anything now, the command is merged with
@@ -117,24 +117,11 @@ class Decoder(srd.Decoder):
 
     def format_command(self):
         '''Returns the label for the current command.'''
-        if self.cmd == 'SINGLE_READ':
-            reg = regs[self.dat] if self.dat in regs else 'unknown register'
-            return 'Read'
-        if self.cmd == 'BURST_READ':
-            reg = regs[self.dat] if self.dat in regs else 'unknown register'
-            return 'Burst read'
-        if self.cmd == 'SINGLE_WRITE':
-            reg = regs[self.dat] if self.dat in regs else 'unknown register'
-            return 'Write'
-        if self.cmd == 'BURST_WRITE':
-            reg = regs[self.dat] if self.dat in regs else 'unknown register'
-            return 'Burst write'
-        if self.cmd == 'STATUS_READ':
-            reg = regs[self.dat] if self.dat in regs else 'unknown register'
-            return 'Status read'
-        if self.cmd == 'STROBE_CMD':
-            reg = strobes[self.dat] if self.dat in strobes else 'unknown strobe'
-            return 'STROBE "{}"'.format(reg)
+        if self.cmd in ('Read', 'Burst read', 'Write', 'Burst write', 'Status read'):
+            return self.cmd
+        if self.cmd == 'Strobe':
+            reg = strobes.get(self.dat, 'unknown strobe')
+            return '{} "{}"'.format(self.cmd, reg)
         else:
             return 'TODO Cmd {}'.format(self.cmd)
 
@@ -151,24 +138,24 @@ class Decoder(srd.Decoder):
         addr = b & 0x3F
         if (addr < 0x30) or (addr == 0x3E) or (addr == 0x3F):
             if (b & 0xC0) == 0x00:
-                return ('SINGLE_WRITE', addr, 1, 1)
+                return ('Write', addr, 1, 1)
             if (b & 0xC0) == 0x40:
-                return ('BURST_WRITE', addr, 1, 99999)
+                return ('Burst write', addr, 1, 99999)
             if (b & 0xC0) == 0x80:
-                return ('SINGLE_READ', addr, 1, 1)
+                return ('Read', addr, 1, 1)
             if (b & 0xC0) == 0xC0:
-                return ('BURST_READ', addr, 1, 99999)
+                return ('Burst read', addr, 1, 99999)
             else:
                 self.warn(pos, 'unknown address/command combination')
         else:
             if (b & 0x40) == 0x00:
-                return ('STROBE_CMD', addr, 0, 0)
+                return ('Strobe', addr, 0, 0)
             if (b & 0xC0) == 0xC0:
-                return ('STATUS_READ', addr, 1, 99999)
+                return ('Status read', addr, 1, 99999)
             else:
                 self.warn(pos, 'unknown address/command combination')
 
-    def decode_register(self, pos, ann, regid, data):
+    def decode_reg(self, pos, ann, regid, data):
         '''Decodes a register.
 
         pos   -- start and end sample numbers of the register
@@ -191,7 +178,7 @@ class Decoder(srd.Decoder):
             label = 'Status'
             self.decode_status_reg(pos, ann, data, label)
         else:
-            if self.cmd in ('SINGLE_WRITE', 'SINGLE_READ', 'STATUS_READ', 'BURST_READ', 'BURST_WRITE'):
+            if self.cmd in ('Write', 'Read', 'Status read', 'Burst read', 'Burst write'):
                 label = '{}: {}'.format(self.format_command(), name)
             else:
                 label = 'Reg ({}) {}'.format(self.cmd, name)
@@ -211,7 +198,7 @@ class Decoder(srd.Decoder):
         longtext_state = 'STATE is {}, '.format(status_reg_states[state])
         # bits 3:0 --> FIFO_BYTES_AVAILABLE
         fifo_bytes = status & 0x0F
-        if self.cmd in ('SINGLE_READ', 'STATUS_READ', 'BURST_READ'):
+        if self.cmd in ('Single read', 'Status read', 'Burst read'):
             longtext_fifo = '{} bytes available in RX FIFO'.format(fifo_bytes)
         else:
             longtext_fifo = '{} bytes free in TX FIFO'.format(fifo_bytes)
@@ -234,24 +221,18 @@ class Decoder(srd.Decoder):
     def finish_command(self, pos):
         '''Decodes the remaining data bytes at position 'pos'.'''
 
-        if self.cmd == 'SINGLE_WRITE':
-            self.decode_register(pos, ANN_SINGLE_WRITE,
-                                 self.dat, self.mosi_bytes())
-        elif self.cmd == 'BURST_WRITE':
-            self.decode_register(pos, ANN_BURST_WRITE,
-                                self.dat, self.mosi_bytes())
-        elif self.cmd == 'SINGLE_READ':
-            self.decode_register(pos, ANN_SINGLE_READ,
-                                 self.dat, self.miso_bytes())
-        elif self.cmd == 'BURST_READ':
-            self.decode_register(pos, ANN_BURST_READ,
-                                self.dat, self.miso_bytes())
-        elif self.cmd == 'STROBE_CMD':
-            self.decode_register(pos, ANN_STROBE,
-                                 self.dat, self.mosi_bytes())
-        elif self.cmd == 'STATUS_READ':
-            self.decode_register(pos, ANN_STATUS_READ,
-                                 self.dat, self.miso_bytes())
+        if self.cmd == 'Write':
+            self.decode_reg(pos, ANN_SINGLE_WRITE, self.dat, self.mosi_bytes())
+        elif self.cmd == 'Burst write':
+            self.decode_reg(pos, ANN_BURST_WRITE, self.dat, self.mosi_bytes())
+        elif self.cmd == 'Read':
+            self.decode_reg(pos, ANN_SINGLE_READ, self.dat, self.miso_bytes())
+        elif self.cmd == 'Burst read':
+            self.decode_reg(pos, ANN_BURST_READ, self.dat, self.miso_bytes())
+        elif self.cmd == 'Strobe':
+            self.decode_reg(pos, ANN_STROBE, self.dat, self.mosi_bytes())
+        elif self.cmd == 'Status read':
+            self.decode_reg(pos, ANN_STATUS_READ, self.dat, self.miso_bytes())
         else:
             self.warn(pos, 'unhandled command')
 
@@ -296,7 +277,7 @@ class Decoder(srd.Decoder):
                 # First MOSI byte is always the command.
                 self.decode_command(pos, mosi)
                 # First MISO byte is always the status register.
-                self.decode_register(pos, ANN_STATUS, 'STATUS', [miso])
+                self.decode_reg(pos, ANN_STATUS, 'STATUS', [miso])
             else:
                 if not self.cmd or len(self.mb) >= self.max:
                     self.warn(pos, 'excess byte')