BSB Developer Docs
Loading...
Searching...
No Matches
furi_hal_sai.h File Reference

HAL APIs for Serial Audio Interface (SAI). More...

#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Typedefs

typedef void(* FuriHalSaiCallback) (FuriHalSaiEvent event, void *context)
 SAI event callback type.
 

Enumerations

enum  FuriHalSaiEvent { FuriHalSaiEventHalfTransfer , FuriHalSaiEventTransferComplete }
 Enumeration of SAI events. More...
 

Functions

bool furi_hal_sai_init (void)
 Initialise the SAI peripheral.
 
void furi_hal_sai_set_buffer (const int16_t *buffer, uint32_t buffer_depth)
 Set the circular buffer pointer and depth.
 
void furi_hal_sai_set_callback (FuriHalSaiCallback callback, void *context)
 Set the callback function to be called upon SAI events.
 
void furi_hal_sai_enable_amplifier (void)
 Enables the DAC/amplifier unit.
 
void furi_hal_sai_disable_amplifier (void)
 Disables the DAC/amplifier unit.
 
void furi_hal_sai_start (void)
 Start transferring sample data via SAI.
 
void furi_hal_sai_stop (void)
 Stop transferring sample data via SAI.
 

Detailed Description

HAL APIs for Serial Audio Interface (SAI).

Data format expected by SAI:

  • Rate: 44100 Hz
  • Bits: 16bit LE

Once started, it will output the data in a circular manner, providing two events: Half Transfer and Transfer complete to indicate which portion of the buffer can be updated by the application code.

Typedef Documentation

◆ FuriHalSaiCallback

typedef void(* FuriHalSaiCallback) (FuriHalSaiEvent event, void *context)

SAI event callback type.

Parameters
[in]eventone of FuriHalSaiEvent values to indicate the occurred event
[in,out]contextpointer to a user-specific object

Enumeration Type Documentation

◆ FuriHalSaiEvent

Enumeration of SAI events.

Enumerator
FuriHalSaiEventHalfTransfer 

Half of the buffer has been transferred.

FuriHalSaiEventTransferComplete 

Complete buffer has been transferred.

Function Documentation

◆ furi_hal_sai_enable_amplifier()

void furi_hal_sai_enable_amplifier ( void )

Enables the DAC/amplifier unit.

It must be enabled for any sound to come out. If any non-zero data is fed into it within 100 ms after enabling, the output will be distorted with clicks.

◆ furi_hal_sai_init()

bool furi_hal_sai_init ( void )

Initialise the SAI peripheral.

The application code doesn't need to call this function, as it is done in furi_hal_init().

Returns
true if the initialisation was successful, false otherwise

◆ furi_hal_sai_set_buffer()

void furi_hal_sai_set_buffer ( const int16_t * buffer,
uint32_t buffer_depth )

Set the circular buffer pointer and depth.

The application code must fill the buffer with sample data in a timely manner in accordance to the events produced by the SAI.

Parameters
[in]bufferpointer to the sample buffer
[in]buffer_depthbuffer depth in samples (NOT bytes)

◆ furi_hal_sai_set_callback()

void furi_hal_sai_set_callback ( FuriHalSaiCallback callback,
void * context )

Set the callback function to be called upon SAI events.

Parameters
[in]callback
[in,out]contextpointer to a user-specific object (will be passed as context param in callback)

◆ furi_hal_sai_start()

void furi_hal_sai_start ( void )

Start transferring sample data via SAI.

Warning
Before calling this function, a buffer MUST be set using furi_hal_set_buffer() and, in most cases, the event callback must be registered by calling furi_hal_sai_set_callback().

◆ furi_hal_sai_stop()

void furi_hal_sai_stop ( void )

Stop transferring sample data via SAI.

Data transfer stops immediately after calling this function.