pyftdi icon indicating copy to clipboard operation
pyftdi copied to clipboard

Change BitSequence comparison to use int value & pad bytes in tobytes()

Open addinh opened this issue 4 years ago • 1 comments

This is a fix for issue #253 (BitSequence having erroneous comparison functions) as well as issue #245 (tobytes() should pad to byte length), since they both affect the test cases in tests/bits.py. A few more test cases have also been added.

Changes:

  • BitSequence and BitZSequence _cmp() now compares sequences based on their int value (more about this below)
  • BitSequence tobytes() appends 0 before the MSB so that the sequence length is a multiple of 8. tobytes() should now return bytes that can be used by int.from_bytes() to get the int value of the original sequence.

The comparison methods being changed to use int value worked fine for BitSequence, however BitZSequence also uses the same _cmp() function which did not work because they cannot be converted to int. I wasn't sure how to fix this, so I added a function to calculate "int" value of BitZSequences by treating them as ternary strings (they cannot be compared with another BitSequence if they have Z bits, however)

addinh avatar Jul 05 '21 15:07 addinh

Sorry, JTAG support had been unsupported for many years. It is now part of the PyJtagTools sub-project, and BitZSequence has been deprecated, as BitSequence management has been rewritten from scratch. If BitZSequence is still needed (?) I think we should rewrite it as a secondary BitSequence mask.

eblot avatar Nov 23 '24 23:11 eblot