python-periphery icon indicating copy to clipboard operation
python-periphery copied to clipboard

i2c: when reading, modify mutable buffer in-place; accept more types

Open jmuchemb opened this issue 8 months ago • 0 comments

First commit is important for performance because it avoids useless data copies when the caller provides a mutable buffer. Locally, I have an incomplete micropython-compat layer that I'd like to write as follows:

    def readfrom_into(self, addr, buf, stop=True):
        self.transfer(addr, [self.Message(buf, read=True)])

But without this PR, I'd have to do:

    def readfrom_into(self, addr, buf, stop=True):
        msg = self.Message(buf, read=True)
        self.transfer(addr, [msg])
        buf[:] = msg.data

(off-topic: I don't know yet what to with the stop=True parameter)

The next 2 commits are less important. They only relax some typing constraints, for free. I haven't checked my changes to i2c.pyi.

jmuchemb avatar Dec 06 '23 19:12 jmuchemb