New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Have start and end kwargs respect element size #7444
Conversation
The comment says it is `buffer[start:end]` but it assumed elements were a single byte long. Now it correctly does multibyte elements from array.array. Fixes micropython#4988
I am unfamiliar with the workflow here. Is the compiled version (for this unmerged change) in the main downloads directory at Or do pull-request generated artifacts go somewhere else? |
Build artifacts are: go to "checks" (at the top here) > "Build CI" (on the left) and scroll to the list of artifacts. |
Summary: Reading into arrays of 16,32 bit values with There is also a regression in that the
Details: ✓ The previous workaround ✓ The correct call: ❌ Reading into a slice of the array ❌ Even if the slice starts at zero ❌ If the slice is shorter than the FIFO ❌ If the full-array slice is used, but the start and end arguments are used, ✓ If the array is uint16 |
Thank you for the thorough testing!
Slices of arrays are copies. In order to pre-slice it, you'll need to wrap the array in a memoryview(), which will ignore the type iirc.
Thanks for finding this! I've fixed it now. It is a regression from another recent PR #7437 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the None
regression! Sorry - oops!
Here is my test script for SPI.readinto(): import array
import busio
import board
import bitbangio
import time
# Wait for usb
time.sleep(10)
for sck in dir(board):
if not sck.startswith("G"):
continue
sck = getattr(board, sck)
for miso in dir(board):
if not miso.startswith("G"):
continue
miso = getattr(board, miso)
try:
spi = busio.SPI(clock=sck, MISO=miso)
break
except ValueError:
pass
spi.try_lock()
for size in ("b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"):
a = array.array(size, 10 * [99])
spi.readinto(a, start=1)
print(a)
a = array.array(size, 10 * [99])
spi.readinto(a, start=2, end=100)
print(a)
a = array.array(size, 10 * [99])
spi.readinto(a, start=-2)
print(a)
a = array.array(size, 10 * [99])
spi.readinto(a, end=-2)
print(a) I got lucky finding a bug in readinto. The others would be harder to test. |
I have verified on the current version that it works on signed and unsigned 8, 16, and 32 bit destination arrays. I also verify that the current version has fixed the regression on the pin arguments. A feature request #7452 for non-polling read is not part of this merge request, but if enacted would probably be best addressed while this part of the code is still fresh in @tannewt or @dhalbert 's mind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmopalmer Thanks for the testing!
The comment says it is
buffer[start:end]
but it assumed elements were a single byte long. Now it correctly does multibyte elements from array.array.Fixes #4988
I only compiled it. I'm hoping @dmopalmer and @dmcomm will give it a try.