X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=decoders%2Fuart%2Fpd.py;h=d59c6c33fb3fd5738fc84479ae32df99d7c9fd89;hb=be42cffca100c00d0d5510b08dcb66655f8a5746;hp=fef3aa525fe3b0f32893a8a915cd6cd1b4e24bcd;hpb=35b380b1156434b73d4a976c68f5ab3604c8510a;p=libsigrokdecode.git diff --git a/decoders/uart/pd.py b/decoders/uart/pd.py index fef3aa5..d59c6c3 100644 --- a/decoders/uart/pd.py +++ b/decoders/uart/pd.py @@ -28,9 +28,10 @@ Packet: This is the list of s and their respective values: - 'STARTBIT': The data is the (integer) value of the start bit (0/1). - - 'DATA': The data is the (integer) value of the UART data. Valid values - range from 0 to 512 (as the data can be up to 9 bits in size). - - 'DATABITS': List of data bits and their ss/es numbers. + - 'DATA': This is always a tuple containing two items: + - 1st item: the (integer) value of the UART data. Valid values + range from 0 to 512 (as the data can be up to 9 bits in size). + - 2nd item: the list of individual data bits and their ss/es numbers. - 'PARITYBIT': The data is the (integer) value of the parity bit (0/1). - 'STOPBIT': The data is the (integer) value of the stop bit (0 or 1). - 'INVALID STARTBIT': The data is the (integer) value of the start bit (0/1). @@ -70,6 +71,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 +103,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'), @@ -257,8 +264,8 @@ class Decoder(srd.Decoder): self.state[rxtx] = 'GET PARITY BIT' - self.putpx(rxtx, ['DATABITS', rxtx, self.databits[rxtx]]) - self.putpx(rxtx, ['DATA', rxtx, self.databyte[rxtx]]) + self.putpx(rxtx, ['DATA', rxtx, + (self.databyte[rxtx], self.databits[rxtx])]) b, f = self.databyte[rxtx], self.options['format'] if f == 'ascii': @@ -333,10 +340,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):