Is there a way to do a non-blocking write to UART1? It appears to me that PollTx is blocking (correct me if I’m wrong about that!), which is causing me real headaches in trying to avoid starving the audio callback. I’d really like something like Serial.write() on the Arduino, which only blocks if the transmit buffer is full. Is there something like this? If not, any tips on structuring code? Thanks!
You’re not wrong, there isn’t DMA based transmit support in Daisy UART code. I’m sure that it would be added eventually and TODO on top of that file hints that transmit code would be improved.
In this case you shouldn’t be sending data from your audio callback. Probably you’ll have to use a circular buffer for outgoing data and make transmit calls from the main loop.
Thanks, @antisvin It’s helpful to hear that from someone else. I had figured that a FIFO queue would be the way to go. BTW, I wasn’t trying to imply any processing from the audio callback; I simply meant that a blocking read anywhere could starve the audio processing. I’m much clearer now what I need to do, and can press forward with my new mantra, “No blocking I/O anywhere!!”
And a little tale: My wife has been patiently listening to way too much technical detail about what I’m working on. Yesterday she informed me that she thinks I should start to tell her comfort stories about a bunny named “Patches.” And this morning she added that Patches has a girlbunny named “Mux”. After I read your post, I told her a little story entitled, “Patches & Mux and the circular buffer”
It sounds like you’ve got it a bit wrong.
Audio callback is running from an interrupt handler, so you can’t block it from another place in main loop. You can still shoot yourself in the foot by putting some blocking code in handler for another interrupt that has higher priority. So using it in main loop is sort of fine - only main loop will get blocked.
It’s better to use DMA if possible, but in this case it may not give you any noticeable difference and would require some effort to fight with libDaisy. If you still have doubts that it’s ok, you should look at what the main loop does - it’s already constantly running blocking code and it does not call your audio callback (it only configures which function get called by SAI callback and enables circular DMA for that peripheral).
In such case part two can be titled “Using MDMA on Daisy”, but I can’t take responsibility if you’ll get sent to rehab after that.