Remove the redundant .itemcount variable, which exactly corresponds to
the length of the .items array.
Arrange retrieval of options and their evaluation closer to each other
for improved readability.
Use common logic to construct "words" from several multi-bit "items".
Arrange for endianess support by optionally reversing the array before
traversal.
def reset(self):
self.items = []
def reset(self):
self.items = []
self.saved_item = None
self.ss_item = self.es_item = None
self.first = True
self.saved_item = None
self.ss_item = self.es_item = None
self.first = True
self.put(self.ss_word, self.es_word, self.out_ann, data)
def handle_bits(self, datapins):
self.put(self.ss_word, self.es_word, self.out_ann, data)
def handle_bits(self, datapins):
- # If this is the first item in a word, save its sample number.
- if self.itemcount == 0:
- self.ss_word = self.samplenum
-
# Get the bits for this item.
item, used_pins = 0, datapins.count(1) + datapins.count(0)
for i in range(used_pins):
item |= datapins[i] << i
# Get the bits for this item.
item, used_pins = 0, datapins.count(1) + datapins.count(0)
for i in range(used_pins):
item |= datapins[i] << i
+ # Save the item, and its sample number if it's the first part of a word.
+ if not self.items:
+ self.ss_word = self.samplenum
if self.first:
# Save the start sample and item for later (no output yet).
if self.first:
# Save the start sample and item for later (no output yet).
self.ss_item = self.samplenum
self.saved_item = item
self.ss_item = self.samplenum
self.saved_item = item
- endian, ws = self.options['endianness'], self.options['wordsize']
-
# Get as many items as the configured wordsize says.
# Get as many items as the configured wordsize says.
- if self.itemcount < ws:
+ ws = self.options['wordsize']
+ if len(self.items) < ws:
return
# Output annotations/python for a word (a collection of items).
return
# Output annotations/python for a word (a collection of items).
+ # NOTE that this feature is currently not effective. The emission
+ # of Python annotations is commented out.
+ endian = self.options['endianness']
+ if endian == 'little':
+ self.items.reverse()
word = 0
for i in range(ws):
word = 0
for i in range(ws):
- if endian == 'little':
- word |= self.items[i] << ((ws - 1 - i) * used_pins)
- elif endian == 'big':
- word |= self.items[i] << (i * used_pins)
+ word |= self.items[i] << (i * used_pins)
self.es_word = self.samplenum
# self.putpw(['WORD', word])
# self.putw([1, ['%X' % word]])
self.ss_word = self.samplenum
self.es_word = self.samplenum
# self.putpw(['WORD', word])
# self.putw([1, ['%X' % word]])
self.ss_word = self.samplenum
- self.itemcount, self.items = 0, []
def decode(self):
for i in range(len(self.optional_channels)):
def decode(self):
for i in range(len(self.optional_channels)):