X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fuart%2Fpd.py;h=b8508a72c74b7338e7a1039ce6e265e84badda2c;hb=95d11271b46a46788d497481d03177e883c8554e;hp=fef3aa525fe3b0f32893a8a915cd6cd1b4e24bcd;hpb=35b380b1156434b73d4a976c68f5ab3604c8510a;p=libsigrokdecode.git diff --git a/decoders/uart/pd.py b/decoders/uart/pd.py index fef3aa5..b8508a7 100644 --- a/decoders/uart/pd.py +++ b/decoders/uart/pd.py @@ -70,6 +70,9 @@ def parity_ok(parity_type, parity_bit, data, num_data_bits): class SamplerateError(Exception): pass +class ChannelError(Exception): + pass + class Decoder(srd.Decoder): api_version = 2 id = 'uart' @@ -99,7 +102,10 @@ class Decoder(srd.Decoder): 'values': ('lsb-first', 'msb-first')}, {'id': 'format', 'desc': 'Data format', 'default': 'ascii', 'values': ('ascii', 'dec', 'hex', 'oct', 'bin')}, - # TODO: Options to invert the signal(s). + {'id': 'invert_rx', 'desc': 'Invert RX?', 'default': 'no', + 'values': ('yes', 'no')}, + {'id': 'invert_tx', 'desc': 'Invert TX?', 'default': 'no', + 'values': ('yes', 'no')}, ) annotations = ( ('rx-data', 'RX data'), @@ -333,10 +339,15 @@ class Decoder(srd.Decoder): # continue self.oldpins, (rx, tx) = pins, pins + if self.options['invert_rx'] == 'yes': + rx = not rx + if self.options['invert_tx'] == 'yes': + tx = not tx + # Either RX or TX (but not both) can be omitted. has_pin = [rx in (0, 1), tx in (0, 1)] if has_pin == [False, False]: - raise Exception('Either TX or RX (or both) pins required.') + raise ChannelError('Either TX or RX (or both) pins required.') # State machine. for rxtx in (RX, TX):