Class daisy::SaiHandle¶
#include <sai.h>
Classes¶
Type | Name |
---|---|
struct | Config |
Public Types¶
Type | Name |
---|---|
typedef void(* | CallbackFunctionPtr |
enum | Result |
Public Functions¶
Type | Name |
---|---|
Result | DeInit () |
float | GetBlockRate () |
size_t | GetBlockSize () |
const Config & | GetConfig () const |
size_t | GetOffset () const |
float | GetSampleRate () |
Result | Init (const Config & config) |
bool | IsInitialized () const |
SaiHandle () |
|
SaiHandle (const SaiHandle & other) = default |
|
Result | StartDma (int32_t * buffer_rx, int32_t * buffer_tx, size_t size, CallbackFunctionPtr callback) |
Result | StopDma () |
SaiHandle & | operator= (const SaiHandle & other) = default |
Detailed Description¶
Support for I2S Audio Protocol with different bit-depth, samplerate options Allows for master or slave, as well as freedom of selecting direction, and other behavior for each peripheral, and block.
DMA Transfer commands must use buffers located within non-cached memory or use cache maintenance To declare an unitialized global element in the DMA memory section: int32_t DSY_DMA_BUFFER_SECTOR my_buffer[96];
Callback functions will be called once per half of the buffer. In the above example, the callback function would be called once for every 48 samples.
Use SAI Handle like this:
SaiHandle::Config sai_config; sai_config.periph = SaiHandle::Config::Peripheral::SAI_1; sai_config.sr = SaiHandle::Config::SampleRate::SAI_48KHZ; sai_config.bit_depth = SaiHandle::Config::BitDepth::SAI_24BIT; sai_config.a_sync = SaiHandle::Config::Sync::MASTER; sai_config.b_sync = SaiHandle::Config::Sync::SLAVE; sai_config.a_dir = SaiHandle::Config::Direction::RECEIVE; sai_config.b_dir = SaiHandle::Config::Direction::TRANSMIT; sai_config.pin_config.fs = {DSY_GPIOE, 4}; sai_config.pin_config.mclk = {DSY_GPIOE, 2}; sai_config.pin_config.sck = {DSY_GPIOE, 5}; sai_config.pin_config.sa = {DSY_GPIOE, 6}; sai_config.pin_config.sb = {DSY_GPIOE, 3}; // Then Initialize SaiHandle sai; sai.Init(sai_config); // Now you can use it: sai.StartDma(. . .);
Public Types Documentation¶
typedef CallbackFunctionPtr¶
Callback Function to be called when DMA transfer is complete and half complete. This callback is prepared however the data is transmitted/received from the device. For example, using an AK4556 the data will be interleaved 24bit MSB Justified
The hid/audio class will be allow for type conversions, de-interleaving, etc.
enum Result¶
Return values for SAI functions
Public Functions Documentation¶
function DeInit¶
Deinitializes an SAI peripheral
function GetBlockRate¶
Returns the Block Rate of the current stream based on the size of the buffer passed in, and the current samplerate.
function GetBlockSize¶
Returns the number of samples per audio block Calculated as Buffer Size / 2 / number of channels
function GetConfig¶
Returns the current configuration
function GetOffset¶
Returns the current offset within the SAI buffer, will be either 0 or size/2
function GetSampleRate¶
Returns the samplerate based on the current configuration
function Init¶
Initializes an SAI peripheral
function IsInitialized¶
function SaiHandle [½]¶
function SaiHandle [2/2]¶
function StartDma¶
Result daisy::SaiHandle::StartDma (
int32_t * buffer_rx,
int32_t * buffer_tx,
size_t size,
CallbackFunctionPtr callback
)
Starts Rx and Tx in Circular Buffer Mode The callback will be called when half of the buffer is ready, and will handle size/2 samples per callback.
function StopDma¶
Stops the DMA stream for the SAI blocks in use.
function operator=¶
The documentation for this class was generated from the following file external-docs/libDaisy/src/per/sai.h