I2S Master

I2S Master Usage

The following code snippet demonstrates the basic usage of an I2S master device.

#include <xs1.h>
#include <i2s.h>

port_t p_i2s_dout[1];
port_t p_bclk;
port_t p_lrclk;
port_t p_mclk;
xclock_t bclk;
i2s_callback_group_t i2s_cb_group;

// Setup ports and clocks
p_i2s_dout[0] = PORT_I2S_DAC_DATA;
p_bclk = PORT_I2S_BCLK;
p_lrclk = PORT_I2S_LRCLK;
p_mclk = PORT_MCLK_IN;
bclk = I2S_CLKBLK;

port_enable(p_mclk);
port_enable(p_bclk);
// NOTE:  p_lrclk does not need to be enabled by the caller

// Setup callbacks
//  NOTE: See API or SDK examples for more on using the callbacks
i2s_cb_group.init = (i2s_init_t) i2s_init;
i2s_cb_group.restart_check = (i2s_restart_check_t) i2s_restart_check;
i2s_cb_group.receive = (i2s_receive_t) i2s_receive;
i2s_cb_group.send = (i2s_send_t) i2s_send;
i2s_cb_group.app_data = NULL;

// Start the master device in this thread
//  NOTE: You may wish to launch the slave device in a different thread.
//        See the XTC Tools documentation reference for lib_xcore.
i2s_master(&i2s_cb_group, p_i2s_dout, 1, NULL, 0, p_bclk, p_lrclk, p_mclk, bclk);

I2S Master API

The following structures and functions are used to initialize and start an I2S master instance.

void i2s_master(const i2s_callback_group_t *const i2s_cbg, const port_t p_dout[], const size_t num_out, const port_t p_din[], const size_t num_in, const port_t p_bclk, const port_t p_lrclk, const port_t p_mclk, const xclock_t bclk)

I2S master task

This task performs I2S on the provided pins. It will perform callbacks over the i2s_callback_group_t callback group to get/receive frames of data from the application using this component.

The task performs I2S master so will drive the word clock and bit clock lines.

Parameters
  • i2s_cbg – The I2S callback group pointing to the application’s functions to use for initialization and getting and receiving frames. Also points to application specific data which will be shared between the callbacks.

  • p_dout – An array of data output ports

  • num_out – The number of output data ports

  • p_din – An array of data input ports

  • num_in – The number of input data ports

  • p_bclk – The bit clock output port

  • p_lrclk – The word clock output port

  • p_mclk – Input port which supplies the master clock

  • bclk – A clock that will get configured for use with the bit clock

void i2s_master_external_clock(const i2s_callback_group_t *const i2s_cbg, const port_t p_dout[], const size_t num_out, const port_t p_din[], const size_t num_in, const port_t p_bclk, const port_t p_lrclk, const xclock_t bclk)

I2S master task

This task differs from i2s_master() in that bclk must already be configured to the BCLK frequency. Other than that, it is identical.

This task performs I2S on the provided pins. It will perform callbacks over the i2s_callback_group_t callback group to get/receive frames of data from the application using this component.

The task performs I2S master so will drive the word clock and bit clock lines.

Parameters
  • i2s_cbg – The I2S callback group pointing to the application’s functions to use for initialization and getting and receiving frames. Also points to application specific data which will be shared between the callbacks.

  • p_dout – An array of data output ports

  • num_out – The number of output data ports

  • p_din – An array of data input ports

  • num_in – The number of input data ports

  • p_bclk – The bit clock output port

  • p_lrclk – The word clock output port

  • bclk – A clock that is configured externally to be used as the bit clock