From: Uwe Hermann Date: Fri, 5 Jul 2019 06:12:23 +0000 (+0200) Subject: pca9571: Add initial OUTPUT_LOGIC support. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f22b1c7447e29573ca60a5a3c6d5b5dcb41282fe;p=libsigrokdecode.git pca9571: Add initial OUTPUT_LOGIC support. --- diff --git a/decoders/pca9571/pd.py b/decoders/pca9571/pd.py index e27f215..6000952 100644 --- a/decoders/pca9571/pd.py +++ b/decoders/pca9571/pd.py @@ -23,6 +23,12 @@ NUM_OUTPUT_CHANNELS = 8 # TODO: Other I²C functions: general call / reset address, device ID address. +def logic_channels(num_channels): + l = [] + for i in range(num_channels): + l.append(tuple(['p%d' % i, 'P%d' % i, 100000])) + return tuple(l) + class Decoder(srd.Decoder): api_version = 3 id = 'pca9571' @@ -38,6 +44,7 @@ class Decoder(srd.Decoder): ('value', 'Register value'), ('warning', 'Warning'), ) + logic_output_channels = logic_channels(NUM_OUTPUT_CHANNELS) annotation_rows = ( ('regs', 'Registers', (0, 1)), ('warnings', 'Warnings', (2,)), @@ -48,14 +55,19 @@ class Decoder(srd.Decoder): def reset(self): self.state = 'IDLE' + self.ss_logic = -1 self.last_write = 0xFF # Chip port default state is high. def start(self): self.out_ann = self.register(srd.OUTPUT_ANN) + self.out_logic = self.register(srd.OUTPUT_LOGIC) def putx(self, data): self.put(self.ss, self.es, self.out_ann, data) + def putl(self, data): + self.put(self.ss_logic, self.ss_logic, self.out_logic, data) + def handle_io(self, b): if self.state == 'READ DATA': operation = ['Outputs read', 'R'] @@ -67,6 +79,10 @@ class Decoder(srd.Decoder): self.last_write = b self.putx([1, [operation[0] + ': %02X' % b, operation[1] + ': %02X' % b]]) + self.ss_logic = self.ss + for i in range(NUM_OUTPUT_CHANNELS): + bit = (b & (1 << i)) != 0 + self.putl([i, bytes([bit])]) def check_correct_chip(self, addr): if addr != 0x25: