summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2020-07-27 20:03:47 +0200
committerGerhard Sittig <gerhard.sittig@gmx.net>2020-08-30 07:23:58 +0200
commit5c47b179b3e1e90b79478a9feca18990c481d014 (patch)
treeea199c1da6eaf9dac0b9c3ccef941e94931bd89c
parent0411c41c5787da0e6fab7f31503fffb4fdddce1b (diff)
downloadlibsigrokdecode-5c47b179b3e1e90b79478a9feca18990c481d014.tar.gz
libsigrokdecode-5c47b179b3e1e90b79478a9feca18990c481d014.zip
sle44xx: use symbolic identifiers for pins and signal transitions
Eliminate magic numbers for input pins and signal transition conditions. Which dramatically improves readability and simplifies review.
-rw-r--r--decoders/sle44xx/pd.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/decoders/sle44xx/pd.py b/decoders/sle44xx/pd.py
index 0bc3ec7..1c0cdb4 100644
--- a/decoders/sle44xx/pd.py
+++ b/decoders/sle44xx/pd.py
@@ -19,6 +19,9 @@
import sigrokdecode as srd
+class Pin:
+ RST, CLK, IO, = range(3)
+
# CMD: [annotation-type-index, long annotation, short annotation]
proto = {
'RESET': [0, 'Reset', 'R'],
@@ -140,12 +143,24 @@ class Decoder(srd.Decoder):
def decode(self):
while True:
- pins = self.wait([{0: 'r'}, {0: 'l', 1: 'r'}, {1: 'h', 2: 'f'}, {1: 'h', 2: 'r'}])
- if self.matched[0]: # RESET condition (R): RST = rising
+ # Signal conditions tracked by the protocol decoder:
+ # - RESET condition (R): RST = rising
+ # - Incoming data (D): RST = low, CLK = rising.
+ # - Command mode START: CLK = high, I/O = falling.
+ # - Command mode STOP: CLK = high, I/O = rising.
+ (COND_RESET, COND_DATA, COND_CMD_START, COND_CMD_STOP,) = range(4)
+ conditions = [
+ {Pin.RST: 'r'},
+ {Pin.RST: 'l', Pin.CLK: 'r'},
+ {Pin.CLK: 'h', Pin.IO: 'f'},
+ {Pin.CLK: 'h', Pin.IO: 'r'},
+ ]
+ pins = self.wait(conditions)
+ if self.matched[COND_RESET]:
self.handle_reset(pins)
- elif self.matched[1]: # Incoming data (D): RST = low, CLK = rising.
+ elif self.matched[COND_DATA]:
self.handle_data(pins)
- elif self.matched[2]: # Command mode START: CLK = high, I/O = falling.
+ elif self.matched[COND_CMD_START]:
self.handle_command(pins)
- elif self.matched[3]: # Command mode STOP: CLK = high, I/O = rising.
+ elif self.matched[COND_CMD_STOP]:
self.handle_command(pins)