8000 extmod/machine_i2c: Extend I2C transfer func to support write then read. by dpgeorge · Pull Request #8682 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

extmod/machine_i2c: Extend I2C transfer func to support write then read. #8682

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

Conversation

dpgeorge
Copy link
Member

This PR aims to fix #8135, and optimise I2C as per #7134.

The general I2C transfer function has changed from:

transfer(self, addr, n, bufs, flags)

to:

transfer(self, addr, nwrite, nread, bufs, flags)

That means it supports 0 or more writes followed by 0 or more reads, in one "transaction".

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge added the extmod Relates to extmod/ directory in source label May 20, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #8682 (42b2611) into master (7883ae4) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #8682   +/-   ##
=======================================
  Coverage   98.23%   98.23%           
=======================================
  Files         154      154           
  Lines       20334    20334           
=======================================
  Hits        19975    19975           
  Misses        359      359           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7883ae4...42b2611. Read the comment docs.

@robert-hh
Copy link
Contributor

That looks like a good extension. Do I have to adapt the mimxrt port, or is that handled in extmod/machine_i2c.c by calling machine_i2c_transfer_single() as often as needed?

@dpgeorge
Copy link
Member Author

Do I have to adapt the mimxrt port, or is that handled in extmod/machine_i2c.c by calling machine_i2c_transfer_single() as often as needed?

No need to change mimxrt, it's handled by transfer single.

All ports should be working with this PR (but I didn't yet test any...).

@dpgeorge
Copy link
Member Author
dpgeorge commented Jun 1, 2022

This increases code size by:

      stm32:  +128 +0.032% PYBV10
    esp8266:   +20 +0.003% GENERIC
      esp32:   +88 +0.006% GENERIC
        nrf:  +148 +0.080% pca10040
        rp2:  +112 +0.022% PICO

Which is a fair bit for a feature that only esp32 makes use of. The other ports don't need and don't benefit from this change.

So I will close this in favour of #8718.

@dpgeorge dpgeorge closed this Jun 1, 2022
@dpgeorge dpgeorge deleted the extmod-machine-i2c-extended-write-and-read branch June 1, 2022 03:22
tannewt added a commit to tannewt/circuitpython that referenced this pull request Jan 24, 2024
This leaves internal memory for FreeRTOS and other IDF buffers.

Fixes micropython#8682
tannewt added a commit to tannewt/circuitpython that referenced this pull request Jan 31, 2024
We used to default to `malloc()` using SPIRAM but it disables
dynamic WiFi TX buffers. The increased static buffer allocation
prevents MBEDTLS from allocating everything it needs. So, switch
the IDF to SPIRAM through caps_alloc only. This is pretty much what
we do in CP8 except we no longer need to explicitly give the IDF
SPIRAM memory to use.

Fixes micropython#8682 (again)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extmod Relates to extmod/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESP32-s2 i2c - writeto with stop=False cause reboot
3 participants
0