daisy::SaiHandle¶
#include <sai.h>
Public Classes¶
Name | |
---|---|
struct | Config |
Public Types¶
Name | |
---|---|
enum class | Result |
typedef void(*)(int32_t *in, int32_t *out, size_t size) | CallbackFunctionPtr |
Public Functions¶
Name | |
---|---|
SaiHandle() | |
SaiHandle(const SaiHandle & other) =default | |
SaiHandle & | operator=(const SaiHandle & other) =default |
Result | Init(const Config & config) |
Result | DeInit() |
const Config & | GetConfig() const |
Result | StartDma(int32_t * buffer_rx, int32_t * buffer_tx, size_t size, CallbackFunctionPtr callback) |
Result | StopDma() |
float | GetSampleRate() |
size_t | GetBlockSize() |
float | GetBlockRate() |
size_t | GetOffset() const |
bool | IsInitialized() const |
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¶
enum Result¶
Enumerator | Value | Description |
---|---|---|
OK | ||
ERR |
Return values for SAI functions
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.
Public Functions Documentation¶
function SaiHandle¶
function SaiHandle¶
function operator=¶
function Init¶
Initializes an SAI peripheral
function DeInit¶
Deinitializes an SAI peripheral
function GetConfig¶
Returns the current configuration
function StartDma¶
Result 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 GetSampleRate¶
Returns the samplerate based on the current configuration
function GetBlockSize¶
Returns the number of samples per audio block Calculated as Buffer Size / 2 / number of channels
function GetBlockRate¶
Returns the Block Rate of the current stream based on the size of the buffer passed in, and the current samplerate.
function GetOffset¶
Returns the current offset within the SAI buffer, will be either 0 or size/2
function IsInitialized¶
---¶
Updated on 2024-01-03 at 19:41:00 +0000