I2S Standard Bindings
This document provides an overview of the I2S Standard bindings exposed to WebAssembly through the i2s_std
namespace. These bindings allow you to configure and interact with the I2S peripheral.
I2S Standard Configuration
Create I2S Standard Configuration
i2s_std_config_create() -> u32
- Description: Creates a new I2S standard configuration object.
- Returns: A pointer to the I2S standard configuration object.
Set GPIO MCLK Pin
i2s_std_config_gpio_cfg_set_mclk(config_ptr: u32, mclk: u32) -> void
- Parameters:
config_ptr
: Pointer to the I2S standard configuration object.mclk
: GPIO number for the MCLK pin.
- Description: Sets the GPIO pin for the MCLK signal.
Set GPIO BCLK Pin
i2s_std_config_gpio_cfg_set_bclk(config_ptr: u32, bclk: u32) -> void
- Parameters:
config_ptr
: Pointer to the I2S standard configuration object.bclk
: GPIO number for the BCLK pin.
- Description: Sets the GPIO pin for the BCLK signal.
Set GPIO WS Pin
i2s_std_config_gpio_cfg_set_ws(config_ptr: u32, ws: u32) -> void
- Parameters:
config_ptr
: Pointer to the I2S standard configuration object.ws
: GPIO number for the WS pin.
- Description: Sets the GPIO pin for the WS signal.
Set GPIO DOUT Pin
i2s_std_config_gpio_cfg_set_dout(config_ptr: u32, dout: u32) -> void
- Parameters:
config_ptr
: Pointer to the I2S standard configuration object.dout
: GPIO number for the DOUT pin.
- Description: Sets the GPIO pin for the DOUT signal.
Set GPIO DIN Pin
i2s_std_config_gpio_cfg_set_din(config_ptr: u32, din: u32) -> void
- Parameters:
config_ptr
: Pointer to the I2S standard configuration object.din
: GPIO number for the DIN pin.
- Description: Sets the GPIO pin for the DIN signal.
Destroy I2S Standard Configuration
i2s_std_config_destroy(config_ptr: u32) -> void
- Parameters:
config_ptr
: Pointer to the I2S standard configuration object.
- Description: Frees the memory allocated for the I2S standard configuration object.
I2S Channel
Enable Channel
i2s_channel_enable(chan_handle_ptr: u32) -> u32
- Parameters:
chan_handle_ptr
: Pointer to the I2S channel handle.
- Returns:
0
on success, or an error code on failure. - Description: Enables the I2S channel.
Disable Channel
i2s_channel_disable(chan_handle_ptr: u32) -> u32
- Parameters:
chan_handle_ptr
: Pointer to the I2S channel handle.
- Returns:
0
on success, or an error code on failure. - Description: Disables the I2S channel.
Read Data
i2s_channel_read(chan_handle_ptr: u32, buffer_ptr: u32, size: u32) -> u32
- Parameters:
chan_handle_ptr
: Pointer to the I2S channel handle.buffer_ptr
: Pointer to the buffer where data will be stored.size
: Number of bytes to read.
- Returns:
0
on success, or an error code on failure. - Description: Reads data from the I2S channel.
Preload Data
i2s_channel_preload_data(tx_handle_ptr: u32, buffer_ptr: u32, size: u32) -> u32
- Parameters:
tx_handle_ptr
: Pointer to the I2S transmit handle.buffer_ptr
: Pointer to the buffer containing data to preload.size
: Number of bytes to preload.
- Returns:
0
on success, or an error code on failure. - Description: Preloads data into the I2S transmit buffer.
Write Data
i2s_channel_write(chan_handle_ptr: u32, buffer_ptr: u32, size: u32) -> u32
- Parameters:
chan_handle_ptr
: Pointer to the I2S channel handle.buffer_ptr
: Pointer to the buffer containing data to write.size
: Number of bytes to write.
- Returns: A pointer to a result structure containing the write result.
Destroy Write Result
i2s_channel_write_result_destroy(result_ptr: u32) -> void
- Parameters:
result_ptr
: Pointer to the write result structure.
- Description: Frees the memory allocated for the write result structure.
Get Write Result
i2s_channel_write_result_get_ret(result_ptr: u32) -> u32
i2s_channel_write_result_get_bytes_written(result_ptr: u32) -> u32
- Parameters:
result_ptr
: Pointer to the write result structure.
- Returns:
ret
: The result of the write operation (0
on success).bytes_written
: The number of bytes written.
I2S Channel Configuration
Create Channel Configuration
i2s_chan_cfg_create() -> u32
- Description: Creates a new I2S channel configuration object.
- Returns: A pointer to the I2S channel configuration object.
Set Channel ID
i2s_chan_cfg_set_id(chan_cfg_ptr: u32, id: u32) -> void
- Parameters:
chan_cfg_ptr
: Pointer to the I2S channel configuration object.id
: Channel ID.
- Description: Sets the ID for the I2S channel.
Set Channel Role
i2s_chan_cfg_set_role(chan_cfg_ptr: u32, role: u32) -> void
- Parameters:
chan_cfg_ptr
: Pointer to the I2S channel configuration object.role
: Channel role (e.g.,I2S_ROLE_MASTER
,I2S_ROLE_SLAVE
).
- Description: Sets the role for the I2S channel.
Destroy Channel Configuration
i2s_chan_cfg_destroy(chan_cfg_ptr: u32) -> void
- Parameters:
chan_cfg_ptr
: Pointer to the I2S channel configuration object.
- Description: Frees the memory allocated for the I2S channel configuration object.
I2S Channel Initialization
Create New Channel
i2s_new_channel(chan_cfg_ptr: u32) -> u32
- Parameters:
chan_cfg_ptr
: Pointer to the I2S channel configuration object.
- Returns:
0
on success, or an error code on failure. - Description: Creates a new I2S channel.
Get TX and RX Handles
i2s_new_channel_result_get_ret(result_ptr: u32) -> u32
i2s_new_channel_result_get_tx_handle(result_ptr: u32) -> u32
i2s_new_channel_result_get_rx_handle(result_ptr: u32) -> u32
- Parameters:
result_ptr
: Pointer to the result structure ofi2s_new_channel
.
- Returns:
ret
: The result of the operation (0
on success).tx_handle
: The transmit handle.rx_handle
: The receive handle.
Destroy New Channel Result
i2s_new_channel_result_destroy(result_ptr: u32) -> void
- Parameters:
result_ptr
: Pointer to the result structure ofi2s_new_channel
.
- Description: Frees the memory allocated for the result structure.
Initialize Channel in Standard Mode
i2s_channel_init_std_mode(chan_handle_ptr: u32, std_config_ptr: u32) -> u32
- Parameters:
chan_handle_ptr
: Pointer to the I2S channel handle.std_config_ptr
: Pointer to the I2S standard configuration object.
- Returns:
0
on success, or an error code on failure. - Description: Initializes the I2S channel in standard mode.
Example Usage
config = i2s_std_config_create()
i2s_std_config_gpio_cfg_set_mclk(config, 0)
i2s_std_config_gpio_cfg_set_bclk(config, 1)
i2s_std_config_gpio_cfg_set_ws(config, 2)
i2s_std_config_gpio_cfg_set_dout(config, 3)
i2s_std_config_gpio_cfg_set_din(config, 4)
chan_cfg = i2s_chan_cfg_create()
i2s_chan_cfg_set_id(chan_cfg, 1)
i2s_chan_cfg_set_role(chan_cfg, 0)
tx_handle = i2s_new_channel(chan_cfg)
i2s_channel_init_std_mode(tx_handle, config)
i2s_std_config_destroy(config)
i2s_chan_cfg_destroy(chan_cfg)