'''
OUTPUT_PYTHON format:
-I²C packet:
-[<cmd>, <data>]
+Packet:
+[<ptype>, <pdata>]
-<cmd> is one of:
+<ptype>:
- 'START' (START condition)
- 'START REPEAT' (Repeated START condition)
- 'ADDRESS READ' (Slave address, read)
- 'STOP' (STOP condition)
- 'ACK' (ACK bit)
- 'NACK' (NACK bit)
- - 'BITS' (<data>: list of data/address bits and their ss/es numbers)
+ - 'BITS' (<pdata>: list of data/address bits and their ss/es numbers)
-<data> is the data or address byte associated with the 'ADDRESS*' and 'DATA*'
+<pdata> is the data or address byte associated with the 'ADDRESS*' and 'DATA*'
command. Slave addresses do not include bit 0 (the READ/WRITE indication bit).
For example, a slave address field could be 0x51 (instead of 0xa2).
-For 'START', 'START REPEAT', 'STOP', 'ACK', and 'NACK' <data> is None.
+For 'START', 'START REPEAT', 'STOP', 'ACK', and 'NACK' <pdata> is None.
'''
# CMD: [annotation-type-index, long annotation, short annotation]
'DATA WRITE': [9, 'Data write', 'DW'],
}
+class SamplerateError(Exception):
+ pass
+
class Decoder(srd.Decoder):
- api_version = 1
+ api_version = 2
id = 'i2c'
name = 'I²C'
longname = 'Inter-Integrated Circuit'
license = 'gplv2+'
inputs = ['logic']
outputs = ['i2c']
- probes = (
+ channels = (
{'id': 'scl', 'name': 'SCL', 'desc': 'Serial clock line'},
{'id': 'sda', 'name': 'SDA', 'desc': 'Serial data line'},
)
self.bits = []
def decode(self, ss, es, data):
- if self.samplerate is None:
- raise Exception("Cannot decode without samplerate.")
+ if not self.samplerate:
+ raise SamplerateError("Cannot decode without samplerate.")
for (self.samplenum, pins) in data:
# Ignore identical samples early on (for performance reasons).
elif self.state == 'FIND ACK':
if self.is_data_bit(scl, sda):
self.get_ack(scl, sda)
- else:
- raise Exception('Invalid state: %s' % self.state)
# Save current SDA/SCL values for the next round.
self.oldscl, self.oldsda = scl, sda