Description
It is common to have write()
and readinto()
functions that take in WriteableBuffer
and ReadableBuffer
. The are some cases where you want to send or receive as you go. We've thought about this mostly in terms of async versions of these APIs. However, I wonder if it'd be ok to accept new FIFO types along side the fixed buffers. The corresponding methods would return immediately when given a FIFO. Then, data would be read or written via the FIFO. By taking in a new type, the old API is preserved and can still be used for fixed length transactions. (Under the hood, we could create a FIFO with the given buffer and then block based on it.)
The reason I'm thinking about this again is that I'm trying to sniff I2C using PIO. I2C traffic is bursty so the PIO's 8 entry FIFO isn't deep enough for me to keep up. If I had an InputFIFO
, then I could allocate a larger incoming buffer. busio.UART
already does this internally but a generic and common way to do it would be nice. The FIFOs would either use DMA or ringbuf underneath. This is similar to #7452.
Potential API:
class InputFIFO:
def __init__(self, typecode="B", size=64):
# Allocates the underlying ring buffer.
@property
def overflowed(self):
# True when data was dropped.
# Methods like a stream or like a list/array.
class OutputFIFO:
def __init__(self, typecode="B", size=64):
# Allocates the underlying ring buffer.
@property
def underflowed(self):
# True when data was dropped.
# Methods like a stream or like a list/array.
Ideally, I'd be able to do:
fifo_in = fifo.InputFIFO("b", 64)
sm.readinto(fifo_in)
for value in fifo_in:
print(value)