libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::SaiHandle Class Reference

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(. . .);

#include <sai.h>

Classes

struct  Config
 

Public Types

enum class  Result { OK , ERR }
 
typedef void(* CallbackFunctionPtr) (int32_t *in, int32_t *out, size_t size)
 

Public Member Functions

 SaiHandle ()
 
 SaiHandle (const SaiHandle &other)=default
 
SaiHandleoperator= (const SaiHandle &other)=default
 
Result Init (const Config &config)
 
Result DeInit ()
 
const ConfigGetConfig () 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
 

Member Typedef Documentation

◆ CallbackFunctionPtr

typedef void(* daisy::SaiHandle::CallbackFunctionPtr) (int32_t *in, int32_t *out, size_t size)

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.

Member Enumeration Documentation

◆ Result

Return values for SAI functions

Enumerator
OK 
ERR 

Constructor & Destructor Documentation

◆ SaiHandle() [1/2]

daisy::SaiHandle::SaiHandle ( )
inline

◆ SaiHandle() [2/2]

daisy::SaiHandle::SaiHandle ( const SaiHandle other)
default

Member Function Documentation

◆ DeInit()

Result daisy::SaiHandle::DeInit ( )

Deinitializes an SAI peripheral

◆ GetBlockRate()

float daisy::SaiHandle::GetBlockRate ( )

Returns the Block Rate of the current stream based on the size of the buffer passed in, and the current samplerate.

◆ GetBlockSize()

size_t daisy::SaiHandle::GetBlockSize ( )

Returns the number of samples per audio block Calculated as Buffer Size / 2 / number of channels

◆ GetConfig()

const Config & daisy::SaiHandle::GetConfig ( ) const

Returns the current configuration

◆ GetOffset()

size_t daisy::SaiHandle::GetOffset ( ) const

Returns the current offset within the SAI buffer, will be either 0 or size/2

◆ GetSampleRate()

float daisy::SaiHandle::GetSampleRate ( )

Returns the samplerate based on the current configuration

◆ Init()

Result daisy::SaiHandle::Init ( const Config config)

Initializes an SAI peripheral

◆ IsInitialized()

bool daisy::SaiHandle::IsInitialized ( ) const
inline

◆ operator=()

SaiHandle & daisy::SaiHandle::operator= ( const SaiHandle other)
default

◆ 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.

◆ StopDma()

Result daisy::SaiHandle::StopDma ( )

Stops the DMA stream for the SAI blocks in use.


The documentation for this class was generated from the following file: