Is it possible to use DMA for sends and receives over i2c on the teensy 4
The hardware support is there, but so far no software.
I'm curious why so much focus on using DMA?
So far I have taken the 4th option: Punt
That's what I've done too. And realistically, I'm going to keep doing this a while longer, since right now I'm working on making bootloader chips available, and then my main plans for Teensyduino 1.54 involve supporting more file storage media, file and filesytem abstractions, and MTP. I consider both of those a much higher priority than advanced I2C APIs.
But long term, we do need better I2C support. Slave mode is the most important missing piece. But good non-blocking master mode also matters. I've spent some time thinking about how I want to do this, but so far no coding. The main thing I want to see is an alternative non-blocking API that uses a queue of transfers to be performed. I really want to get away from the existing API where many function calls are used to set up a transfer, because that's a nightmare to make thread safe. I want to see a single function call that queues a transfer to be performed, with optional callback upon completion. Each transfer should be a single atomic bus use, beginning with start condition and ending with stop condition. The difficult part is handling repeated starts and whether to support data-dependent action (like deciding to read more data based on the first byte received). But those are fringe cases. The 3 most common transfers are write, read, and write-then-read.
Even with a good non-blocking queued transfer API on the Wire library, I'm still not convinced DMA makes sense. Maybe it does for very large transfers? But for small transfers it seems like a lot of extra overhead just to avoid a few interrupts, which aren't even that sensitive to latency since we have a small FIFO in the I2C hardware on Teensy 4.x.
Maybe DMA will turn out to be easier than I've imagined? But so far every lesson I've learned about I2C is it's relatively easy to make a library that works for the normal case where things go as they should, but even for the simple case of blocking APIs handling all the corner cases for a highly robust library when people deploy it with noisy environments and unusual I2C chips is extremely difficult. Adding the complexity & overhead of DMA feeling like it may turn out to be a long & painful journey of those ugly corner cases.