Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SAI can be modeled like a UART in some regards where there are a Tx/Rx pair. Unlike a UART though SAI in iMXRT can have multiple data channels connected to the same peripheral. While each channel has its own fifo and pin they are still part of the same peripheral instance. Meaning the clock, status, FIFO watermark, and more are all the shared. This adds some complications. Use of the Tx and Rx together is also optional, its quite possible only Tx or Rx in use. So modeling this API requires some interesting use of generics, but in effect the Sai struct is a builder that enables building a Sai Tx/Rx optional pair given pins and builder like options. The goal in the end is to have static const generated register fields from perhaps a const fn friendly builder type (SaiConfig). From there a Tx/Rx pair provide functionality for writing frames of audio samples per channel, managing interrupt masks, checking status, and enabling/disabling the transmitter or receiver. In some instances the Tx/Rx pair are *synchronized* meaning between the pair one will drive the frame sync clock of the other. This leads to a small potential race at the moment if a Tx and Rx are setup as synchronized and the tx/rx is enabled/disabled independent of the other that I can see. I don't have a great way of solving this particular setup in a safe way at the moment.
- Loading branch information