Skip to content

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

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jmuchemb
Copy link

@jmuchemb jmuchemb commented Dec 6, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant