earlephilhower / arduino-pico

Raspberry Pi Pico Arduino core, for all RP2040 and RP2350 boards
GNU Lesser General Public License v2.1
1.96k stars 406 forks source link

Feature Request: Non-Blocking I2C #1730

Closed Rastloser closed 3 months ago

Rastloser commented 11 months ago

I don't know of a non-blocking or perhaps even DMA I2C-Library for the RP2040-Arduino-Core. There is a DMA-library for FreeRTOS under PICO-I2C-DMA, but it would be great to have something Arduino compatible...

earlephilhower commented 11 months ago

That library may use DMA, but it definitely is blocking on the caller (i.e. a call to i2c-read-write-dma takes exactly as many wall seconds to return as a i2c-read-write-polling call would).

I guess in the case of FreeRTOS that lets you run another task instead of busy waiting, but here we don't have tasks (unless you use FreeRTOS...in which case the library may almost work as-is).

I'm not sure what the API would be here, though, where there are no tasks. You'd need a callback function or something (called ar IRQ time) or a flag your app could poll to see if the I2C op is really done or not.

Rastloser commented 11 months ago

I'd personally go with a callback, but a polled function/flag would be a solid choice, too. Maybe even preferably since some people might put too much code into the callback-handler... The Teensy-Version uses a finished flag, but does expose IRQ-based callbacks with ample warning not to put lengthy code into it...

earlephilhower commented 3 months ago

If anyone looking at this request could take a look at #2167 and try their hand at using it in their application I'd much appreciate it. I have the TalkingToMyself test running in asynchronous mode stably, but don't seem to have any I2C gadgets to hoop up and try on external HW...