How to write non-blocking I2S code #2747
-
Hi, I'm struggling a bit with how to write non-blocking I2S send/receive code. I'm assuming the callback functions or the availableToWrite() function is supposed to be used in some manner, but the provided examples don't really utilize these at all, making it a bit tough to discern the intended usage. Could someone possibly point me in the direction of a repository that utilizes these functions or describe the general intended usage? I've seen talk of using The general usecase is that I want to run a C++ representation of a PureData patch, sampling the ADCs, and sending/receiving I2S data from a codec. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Nevermind, I figured it out. For posterity: using That said, if anyone else would like to share example code that utilizes the callbacks for more efficient processing, I'd be happy to see it. |
Beta Was this translation helpful? Give feedback.
Nevermind, I figured it out.
For posterity: using
while(i2s.availableToWrite()){i2s.write()}
, the write function and any other code in the while loop will trigger once per 1/samplerate seconds. Using this you can ensure that other things are also triggered in sync with writing to the dac if needed, and if you want other things to trigger asynchronously, you can simply have them execute outside of the while loop.That said, if anyone else would like to share example code that utilizes the callbacks for more efficient processing, I'd be happy to see it.