Astra MCU SDK Peripheral Driver Library
Loading...
Searching...
No Matches

Functions for the I2S driver. More...

Typedefs

typedef void(* i2s_event_cb_t) (i2s_instance_en instance, i2s_direction_en direction, i2s_event_en event, void *user_data)
 I2S event callback function type.
typedef void(* i2s_buffer_cb_t) (i2s_instance_en instance, i2s_direction_en direction, void *buffer, size_t size, void *user_data)
 I2S buffer completion callback function type.

Functions

INIT_CODE i2s_status_en i2s_init (i2s_instance_en instance)
i2s_status_en i2s_get_fifo_depth (i2s_instance_en instance, i2s_direction_en direction, uint32_t *depth)
i2s_status_en i2s_set_fifo_depth (i2s_instance_en instance, i2s_direction_en direction, uint32_t depth_words)
i2s_status_en i2s_deinit (i2s_instance_en instance)
i2s_status_en i2s_intr_enable (i2s_instance_en id, int enable)
i2s_status_en i2s_get_config (i2s_instance_en instance, i2s_direction_en direction, i2s_config_t *config)
i2s_status_en i2s_get_capabilities (i2s_instance_en instance, i2s_capabilities_t *caps)
i2s_status_en i2s_trigger (i2s_instance_en instance, i2s_direction_en direction, i2s_trigger_cmd_en cmd)
i2s_status_en i2s_register_callback (i2s_instance_en instance, i2s_event_cb_t callback, void *user_data)
i2s_status_en i2s_register_buffer_callback (i2s_instance_en instance, i2s_buffer_cb_t callback, void *user_data)
i2s_status_en i2s_configure (i2s_instance_en id, i2s_direction_en direction, const i2s_config_t *cfg)
 Configure I2S (clock + bit clock + mode + format).
i2s_status_en i2s_write_async (i2s_instance_en instance, const void *buffer, size_t size)
i2s_status_en i2s_read_async (i2s_instance_en instance, void *buffer, size_t size)
i2s_state_en i2s_get_state (i2s_instance_en instance, i2s_direction_en direction)
i2s_status_en i2s_flush (i2s_instance_en instance, i2s_direction_en direction)

Detailed Description

Functions for the I2S driver.

General functions for I2S driver.

Typedef Documentation

◆ i2s_event_cb_t

typedef void(* i2s_event_cb_t) (i2s_instance_en instance, i2s_direction_en direction, i2s_event_en event, void *user_data)

I2S event callback function type.

This callback is invoked when an I2S event occurs (completion, error, etc.).

Parameters
instanceI2S instance that generated the event
directionTransfer direction (TX or RX)
eventEvent type (bitmask of i2s_event_en values)
user_dataUser-provided context pointer

◆ i2s_buffer_cb_t

typedef void(* i2s_buffer_cb_t) (i2s_instance_en instance, i2s_direction_en direction, void *buffer, size_t size, void *user_data)

I2S buffer completion callback function type.

This callback is invoked when a buffer transfer completes successfully. It provides direct access to the completed buffer for processing or reuse.

Parameters
instanceI2S instance
directionTransfer direction (TX or RX)
bufferPointer to completed buffer
sizeNumber of bytes transferred
user_dataUser-provided context pointer

Function Documentation

◆ i2s_init()

INIT_CODE i2s_status_en i2s_init ( i2s_instance_en instance)

Initialize I2S instance.

Initializes the specified I2S hardware instance and its associated driver context. This function must be invoked before any configuration or data transfer APIs are called for the given instance.

The function performs basic peripheral reset, context initialization, and prepares the hardware for subsequent configuration via i2s_configure.

Parameters
instanceI2S instance identifier.
Returns
i2s_status_en Status code indicating success or failure.
Return values
I2S_OKInitialization successful.
I2S_ERROR_INVALID_PARAMInvalid I2S instance.
I2S_ERROR_BUSYInstance already initialized.
I2S_ERROR_HW_FAULTHardware initialization failed.

◆ i2s_get_fifo_depth()

i2s_status_en i2s_get_fifo_depth ( i2s_instance_en instance,
i2s_direction_en direction,
uint32_t * depth )

Query FIFO depth for TX or RX direction.

Retrieves the hardware FIFO depth (in words) for the specified I2S instance and data direction.

Parameters
instanceI2S instance identifier.
directionData direction (TX or RX).
depthPointer to store the FIFO depth (in words).
Returns
i2s_status_en Status code indicating success or failure.
Return values
I2S_OKFIFO depth retrieved successfully.
I2S_ERROR_INVALID_PARAMInvalid instance, direction, or depth pointer.
I2S_ERROR_NOT_READYInstance not initialized.

◆ i2s_set_fifo_depth()

i2s_status_en i2s_set_fifo_depth ( i2s_instance_en instance,
i2s_direction_en direction,
uint32_t depth_words )

Set FIFO depth used as the maximum submit size.

Configures the maximum number of words that can be submitted to the FIFO per transfer for the specified I2S instance and direction. The configured depth must not exceed the period size configured for the instance.

Parameters
instanceI2S instance identifier.
directionData direction (TX or RX).
depth_wordsFIFO depth value in words.
Returns
i2s_status_en Status code indicating success or failure.
Return values
I2S_OKFIFO depth configured successfully.
I2S_ERROR_INVALID_PARAMInvalid instance, direction, or depth value.
I2S_ERROR_NOT_READYInstance not initialized.

◆ i2s_deinit()

i2s_status_en i2s_deinit ( i2s_instance_en instance)

Deinitialize I2S instance.

Stops ongoing I2S operations, disables the peripheral, and resets the internal driver context for the specified instance. After this call, the instance must be reinitialized using i2s_init before performing further configuration or data transfer operations.

Parameters
instanceI2S instance identifier.
Returns
i2s_status_en Status code indicating success or failure.
Return values
I2S_OKDeinitialization successful.
I2S_ERROR_PARAMETERInvalid I2S instance.
I2S_ERROR_NOT_INITIALIZEDInstance not initialized.

◆ i2s_intr_enable()

i2s_status_en i2s_intr_enable ( i2s_instance_en id,
int enable )

Enable or disable I2S interrupts.

Configures the interrupt generation for the specified I2S instance. This function enables or disables the interrupt at the peripheral level based on the value of the enable parameter.

Parameters
idI2S instance identifier.
enableInterrupt control flag.
  • 1 : Enable interrupts.
  • 0 : Disable interrupts.
Returns
i2s_status_en Status code indicating success or failure.
Return values
I2S_OKInterrupt configuration successful.
I2S_ERROR_INVALID_PARAMInvalid I2S instance or parameter.
I2S_ERROR_NOT_READYInstance not initialized.

◆ i2s_get_config()

i2s_status_en i2s_get_config ( i2s_instance_en instance,
i2s_direction_en direction,
i2s_config_t * config )

Get I2S configuration.

Retrieves the current configuration for the specified instance.

Note
Returned configuration reflects the most recent settings applied via i2s_configure. Fields not tracked by hardware will reflect the driver-side cached values.
Parameters
instanceI2S instance identifier.
directionI2S direction (TX or RX).
configPointer to configuration structure to populate.
Returns
i2s_status_en Status code indicating success or failure.
Return values
I2S_OKConfiguration returned successfully (scalar fields only).
I2S_ERROR_INVALID_PARAMInvalid instance or config pointer.

◆ i2s_get_capabilities()

i2s_status_en i2s_get_capabilities ( i2s_instance_en instance,
i2s_capabilities_t * caps )

Get I2S capabilities.

Queries the hardware capabilities of the specified I2S instance.

Parameters
instanceI2S instance identifier.
capsPointer to capabilities structure to populate.
Returns
i2s_status_en Status code indicating success or failure.
Return values
I2S_OKCapabilities returned successfully.
I2S_ERROR_INVALID_PARAMInvalid instance or caps pointer.

◆ i2s_trigger()

i2s_status_en i2s_trigger ( i2s_instance_en instance,
i2s_direction_en direction,
i2s_trigger_cmd_en cmd )

Control I2S stream state.

Issues a trigger command to control the operational state of the specified I2S direction (TX or RX). Supported commands include START, STOP, PAUSE, RESUME, and PREPARE.

State transitions are validated against the current instance state. Invalid transitions are rejected.

Parameters
instanceI2S instance identifier.
directionI2S direction (TX or RX).
cmdTrigger command (i2s_trigger_cmd_en).
Returns
i2s_status_en
Return values
I2S_OKTrigger command executed successfully.
I2S_ERROR_PARAMETERInvalid instance, direction, or command.
I2S_ERROR_INVALID_STATECommand not allowed in current state.

◆ i2s_register_callback()

i2s_status_en i2s_register_callback ( i2s_instance_en instance,
i2s_event_cb_t callback,
void * user_data )

Register or unregister I2S event callback.

Registers a single event callback for the specified I2S instance. The callback is invoked on transfer completion, error conditions, or other driver-generated events.

Only one callback may be active per instance. Passing NULL unregisters the currently registered callback.

Parameters
instanceI2S instance identifier.
callbackEvent callback function pointer. Set to NULL to unregister.
user_dataUser-defined context pointer passed to the callback during invocation.
Returns
i2s_status_en
Return values
I2S_OKCallback registered or unregistered successfully.
I2S_ERROR_INVALID_PARAMInvalid instance.
I2S_ERROR_NOT_INITIALIZEDInstance not initialized.

◆ i2s_register_buffer_callback()

i2s_status_en i2s_register_buffer_callback ( i2s_instance_en instance,
i2s_buffer_cb_t callback,
void * user_data )

Register or unregister buffer completion callback.

Registers a callback function that is invoked when a transmit or receive buffer transfer completes. The callback provides direct access to the completed buffer for processing, reuse, or release.

Only one buffer callback may be registered per instance. Passing NULL unregisters the current callback.

Parameters
instanceI2S instance identifier.
callbackBuffer completion callback function pointer. Set to NULL to unregister.
user_dataUser-defined context pointer passed to the callback.
Returns
i2s_status_en
Return values
I2S_OKCallback registered or unregistered successfully.
I2S_ERROR_INVALID_PARAMInvalid instance.
I2S_ERROR_NOT_INITIALIZEDInstance not initialized.

◆ i2s_configure()

i2s_status_en i2s_configure ( i2s_instance_en id,
i2s_direction_en direction,
const i2s_config_t * cfg )

Configure I2S (clock + bit clock + mode + format).

Configure I2S module parameters.

Applies configuration parameters to the active I2S direction (TX or RX) of the given instance.

Parameters
idI2S instance identifier.
directionI2S direction (TX or RX).
cfgPointer to I2S configuration structure.
Returns
i2s_status_en
Return values
I2S_OKConfiguration applied successfully.
I2S_ERROR_INVALID_PARAMInvalid instance, module, or NULL configuration pointer.
I2S_ERROR_INVALID_STATEInstance not initialized or module in active state.
I2S_ERROR_NOT_SUPPORTEDUnsupported configuration parameter.

Wrapper that applies clock tree, bit clock divider, mode select, and format/config settings in one call.

Parameters
idI2S instance identifier.
directionI2S direction (TX or RX).
cfgI2S configuration structure.
Returns
i2s_status_en

◆ i2s_write_async()

i2s_status_en i2s_write_async ( i2s_instance_en instance,
const void * buffer,
size_t size )

Write data to the I2S transmitter asynchronously (buffered copy).

Copies the provided data into the internal TX buffer. The caller must start streaming separately via i2s_trigger with I2S_TRIGGER_START. During streaming, this API can be called from the TX buffer callback to refill the completed buffer for the next transfer.

Parameters
instanceI2S instance identifier.
bufferPointer to the source buffer.
sizeSize of the buffer in bytes.
Returns
i2s_status_en
Return values
I2S_OKBuffer queued successfully for transmission.
I2S_ERROR_INVALID_PARAMInvalid instance or buffer parameters.
I2S_ERROR_INVALID_STATEI2S module not in READY or RUNNING state.
I2S_ERROR_NO_MEMORYNo space available in the transmit queue.

◆ i2s_read_async()

i2s_status_en i2s_read_async ( i2s_instance_en instance,
void * buffer,
size_t size )

Queue a receive buffer for asynchronous RX.

Provides a pre-allocated buffer for non-blocking reception. The buffer must remain valid until the registered buffer callback signals completion.

Parameters
instanceI2S instance identifier.
bufferPointer to the receive buffer.
sizeSize of the buffer in bytes.
Returns
i2s_status_en
Return values
I2S_OKBuffer queued successfully for reception.
I2S_ERROR_INVALID_PARAMInvalid instance or buffer parameters.
I2S_ERROR_INVALID_STATEI2S module not in READY or RUNNING state.
I2S_ERROR_NO_MEMORYNo space available in the receive queue.

◆ i2s_get_state()

i2s_state_en i2s_get_state ( i2s_instance_en instance,
i2s_direction_en direction )

Get the current state of the I2S driver for a specific direction.

Returns the internal driver state associated with the specified I2S instance and data direction (TX or RX). This can be used by the application to determine whether the driver is idle, running, or in an error condition before initiating new operations.

The returned state reflects the status of the transfer engine maintained by the driver and may be used for synchronization or flow control in higher-level application logic.

Parameters
instanceI2S instance identifier.
directionData direction for which the state is requested (TX or RX).
Returns
i2s_state_en
Return values
I2S_STATE_IDLENo active transfer in the specified direction.
I2S_STATE_READYI2S direction is configured and ready for transfer.
I2S_STATE_RUNNINGA transfer is currently in progress.
I2S_STATE_ERRORThe driver encountered an error condition.

◆ i2s_flush()

i2s_status_en i2s_flush ( i2s_instance_en instance,
i2s_direction_en direction )

Flush the I2S FIFO and reset transfer state for a direction.

Clears the hardware FIFO and resets the internal driver transfer state associated with the specified direction (TX or RX). This operation discards any pending or partially transferred data and prepares the direction for a fresh transfer sequence.

This function can be used to recover from underrun/overrun conditions or to ensure that stale data does not remain in the FIFO before starting a new transfer.

Note
Flushing during an active transfer may result in data loss. Applications should ensure that the transfer is stopped or in an appropriate state before invoking this API.
Parameters
instanceI2S instance identifier.
directionData direction to flush (TX or RX).
Returns
i2s_status_en
Return values
I2S_OKFIFO and transfer state successfully flushed.
I2S_ERROR_INVALID_PARAMInvalid instance or direction parameter.
I2S_ERROR_INVALID_STATEI2S module not initialized or not in a valid state.