nrfx 4.5.0
Loading...
Searching...
No Matches
I2S driver

Inter-IC Sound (I2S) peripheral driver. More...

Topics

 I2S peripheral driver configuration
 

Data Structures

struct  nrfx_i2s_prescalers_t
 I2S prescalers structure. More...
 
struct  nrfx_i2s_clk_params_t
 Parameters use to describe I2S clock prescaling. More...
 
struct  nrfx_i2s_config_t
 I2S driver configuration structure. More...
 
struct  nrfx_i2s_t
 I2S driver instance data structure. More...
 

Macros

#define NRFX_I2S_DEFAULT_CONFIG(_pin_sck, _pin_lrck, _pin_mck, _pin_sdout, _pin_sdin)
 I2S driver default configuration.
 
#define NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED   (1UL << 0)
 
#define NRFX_I2S_STATUS_TRANSFER_STOPPED   (1UL << 1)
 
#define NRFX_I2S_INSTANCE(reg)
 Macro for creating an I2S driver instance.
 

Typedefs

typedef nrfy_i2s_xfer_desc_t nrfx_i2s_buffers_t
 I2S driver buffers structure.
 
typedef void(* nrfx_i2s_data_handler_t) (nrfx_i2s_buffers_t const *p_released, uint32_t status)
 I2S driver data handler type.
 

Functions

int nrfx_i2s_init (nrfx_i2s_t *p_instance, nrfx_i2s_config_t const *p_config, nrfx_i2s_data_handler_t handler)
 Function for initializing the I2S driver.
 
void nrfx_i2s_uninit (nrfx_i2s_t *p_instance)
 Function for uninitializing the I2S driver.
 
bool nrfx_i2s_init_check (nrfx_i2s_t const *p_instance)
 Function for checking if the I2S driver instance is initialized.
 
int nrfx_i2s_start (nrfx_i2s_t *p_instance, nrfx_i2s_buffers_t const *p_initial_buffers, uint8_t flags)
 Function for starting the continuous I2S transfer.
 
int nrfx_i2s_next_buffers_set (nrfx_i2s_t *p_instance, nrfx_i2s_buffers_t const *p_buffers)
 Function for supplying the buffers to be used in the next part of the transfer.
 
void nrfx_i2s_stop (nrfx_i2s_t *p_instance)
 Function for stopping the I2S transfer.
 
int nrfx_i2s_prescalers_calc (nrfx_i2s_clk_params_t const *clk_params, nrfx_i2s_prescalers_t *prescalers)
 Function for calculating I2S clock prescaler values.
 
void nrfx_i2s_irq_handler (nrfx_i2s_t *p_instance)
 Driver interrupt handler.
 

Detailed Description

Inter-IC Sound (I2S) peripheral driver.

Macro Definition Documentation

◆ NRFX_I2S_DEFAULT_CONFIG

#define NRFX_I2S_DEFAULT_CONFIG ( _pin_sck,
_pin_lrck,
_pin_mck,
_pin_sdout,
_pin_sdin )
Value:
{ \
.sck_pin = _pin_sck, \
.lrck_pin = _pin_lrck, \
.mck_pin = _pin_mck, \
.sdout_pin = _pin_sdout, \
.sdin_pin = _pin_sdin, \
.irq_priority = NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY, \
.format = NRF_I2S_FORMAT_I2S, \
.alignment = NRF_I2S_ALIGN_LEFT, \
.sample_width = NRF_I2S_SWIDTH_16BIT, \
.channels = NRF_I2S_CHANNELS_LEFT, \
.prescalers = \
{ \
.mck_setup = NRF_I2S_MCK_32MDIV8, \
.ratio = NRF_I2S_RATIO_32X, \
NRFX_COND_CODE_1(NRF_I2S_HAS_CLKCONFIG, \
(.enable_bypass = false), \
()) \
}, \
NRFX_COND_CODE_1(NRF_I2S_HAS_CLKCONFIG, \
(.clksrc = NRF_I2S_CLKSRC_PCLK32M), \
()) \
}
#define NRF_I2S_HAS_CLKCONFIG
Symbol indicating whether clock source configuration is available.
Definition nrf_i2s.h:66
@ NRF_I2S_MODE_MASTER
Master mode.
Definition nrf_i2s.h:137
@ NRF_I2S_RATIO_32X
LRCK = MCK / 32.
Definition nrf_i2s.h:180
@ NRF_I2S_FORMAT_I2S
Original I2S format.
Definition nrf_i2s.h:224
@ NRF_I2S_MCK_32MDIV8
32 MHz / 8 = 4.0 MHz.
Definition nrf_i2s.h:162
@ NRF_I2S_CHANNELS_LEFT
Left only.
Definition nrf_i2s.h:232
@ NRF_I2S_SWIDTH_16BIT
16 bit.
Definition nrf_i2s.h:195
@ NRF_I2S_CLKSRC_PCLK32M
32MHz peripheral clock.
Definition nrf_i2s.h:240
@ NRF_I2S_ALIGN_LEFT
Left-aligned.
Definition nrf_i2s.h:217

I2S driver default configuration.

This configuration sets up I2S with the following options:

  • master mode
  • i2s data format
  • left alignment
  • sample width 16 bit
  • left channel enabled
  • MCK frequency 4 MHz
  • LRCK frequency 125 kHz
Parameters
[in]_pin_sckSCK pin number.
[in]_pin_lrckLRCK pin number.
[in]_pin_mckMCK pin number.
[in]_pin_sdoutSDOUT pin number.
[in]_pin_sdinSDIN pin number.

◆ NRFX_I2S_INSTANCE

#define NRFX_I2S_INSTANCE ( reg)
Value:
{ \
.p_reg = (NRF_I2S_Type *)reg, \
.cb = {0}, \
}

Macro for creating an I2S driver instance.

◆ NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED

#define NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED   (1UL << 0)

The application must provide buffers that are to be used in the next part of the transfer. A call to nrfx_i2s_next_buffers_set must be done before the currently used buffers are completely processed (that is, the time remaining for supplying the next buffers depends on the used size of the buffers).

◆ NRFX_I2S_STATUS_TRANSFER_STOPPED

#define NRFX_I2S_STATUS_TRANSFER_STOPPED   (1UL << 1)

The I2S peripheral has been stopped and all buffers that were passed to the driver have been released.

Typedef Documentation

◆ nrfx_i2s_data_handler_t

typedef void(* nrfx_i2s_data_handler_t) (nrfx_i2s_buffers_t const *p_released, uint32_t status)

I2S driver data handler type.

A data handling function of this type must be specified during the initialization of the driver. The driver will call this function when it finishes using buffers passed to it by the application, and when it needs to be provided with buffers for the next part of the transfer.

Note
The p_released pointer passed to this function is temporary and will be invalid after the function returns, hence it cannot be stored and used later. If needed, the pointed content (that is, buffers pointers) must be copied instead.
Parameters
[in]p_releasedPointer to a structure with pointers to buffers passed previously to the driver that will no longer be accessed by it (they can be now safely released or used for another purpose, in particular for a next part of the transfer). This pointer will be NULL if the application did not supply the buffers for the next part of the transfer (via a call to nrfx_i2s_next_buffers_set) since the previous time the data handler signaled such need. This means that data corruption occurred (the previous buffers are used for the second time) and no buffers can be released at the moment. Both pointers in this structure are NULL when the handler is called for the first time after a transfer is started, because no data has been transferred yet at this point. In all successive calls, the pointers specify what has been sent (TX) and what has been received (RX) in the part of the transfer that has just been completed (provided that a given direction is enabled, see nrfx_i2s_start).
Note
Since the peripheral is stopped asynchronously, buffers that are released after the call to nrfx_i2s_stop are not used entirely. In this case, only a part (if any) of the TX buffer has been actually transmitted and only a part (if any) of the RX buffer is filled with received data.
Parameters
[in]statusBit field describing the current status of the transfer. It can be 0 or a combination of the following flags:

Function Documentation

◆ nrfx_i2s_init()

int nrfx_i2s_init ( nrfx_i2s_t * p_instance,
nrfx_i2s_config_t const * p_config,
nrfx_i2s_data_handler_t handler )

Function for initializing the I2S driver.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_configPointer to the structure with the initial configuration.
[in]handlerData handler provided by the user. Must not be NULL.
Return values
0Initialization was successful.
-EALREADYThe driver is already initialized.
-EINVALThe requested combination of configuration options is not allowed by the I2S peripheral.

◆ nrfx_i2s_init_check()

bool nrfx_i2s_init_check ( nrfx_i2s_t const * p_instance)

Function for checking if the I2S driver instance is initialized.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueInstance is already initialized.
falseInstance is not initialized.

◆ nrfx_i2s_irq_handler()

void nrfx_i2s_irq_handler ( nrfx_i2s_t * p_instance)

Driver interrupt handler.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_i2s_next_buffers_set()

int nrfx_i2s_next_buffers_set ( nrfx_i2s_t * p_instance,
nrfx_i2s_buffers_t const * p_buffers )

Function for supplying the buffers to be used in the next part of the transfer.

The application must call this function when the data handler receives NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED in the status parameter. The call can be done immediately from the data handler function or later, but it has to be done before the I2S peripheral finishes processing the buffers supplied previously. Otherwise, data corruption will occur.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_buffersPointer to a structure specifying the buffers to be used in the upcoming part of the transfer.
Return values
0If the operation was successful.
-EINPROGRESSIf the buffers were already supplied or the peripheral is currently being stopped.
-EACCESThe provided buffers are not placed in the Data RAM region.
See also
nrfx_i2s_data_handler_t

◆ nrfx_i2s_prescalers_calc()

int nrfx_i2s_prescalers_calc ( nrfx_i2s_clk_params_t const * clk_params,
nrfx_i2s_prescalers_t * prescalers )

Function for calculating I2S clock prescaler values.

Call this function to find suitable value for prescalers in nrfx_i2s_config_t structure.

Parameters
[in]clk_paramsParameters used to describe clock prescaling.
[out]prescalersPrescaler structure pointer to be filled with prescaler values.
Return values
0Suitable prescaler values were found.
-EINVALNo suitable prescaler values were found.
-ENOTSUPRequested configuration is not supported.

◆ nrfx_i2s_start()

int nrfx_i2s_start ( nrfx_i2s_t * p_instance,
nrfx_i2s_buffers_t const * p_initial_buffers,
uint8_t flags )

Function for starting the continuous I2S transfer.

The I2S data transfer can be performed in one of three modes: RX (reception) only, TX (transmission) only, or in both directions simultaneously. The mode is selected by specifying a proper buffer for a given direction in the call to this function or by passing NULL instead if this direction is to be disabled.

The length of the buffer (which is a common value for RX and TX if both directions are enabled) is specified in 32-bit words. One 32-bit memory word can either contain four 8-bit samples, two 16-bit samples, or one right-aligned 24-bit sample sign-extended to a 32-bit value. For a detailed memory mapping for different supported configurations, see the Product Specification.

Note
Peripherals using EasyDMA (including I2S) require the transfer buffers to be placed in the Data RAM region. If this condition is not met, this function will fail with the error code -EACCES.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_initial_buffersPointer to a structure specifying the buffers to be used in the initial part of the transfer (buffers for all consecutive parts are provided through the data handler).
[in]flagsTransfer options (0 for default settings). Currently, no additional flags are available.
Return values
0The operation was successful.
-EINPROGRESSTransfer was already started or the driver has not been initialized.
-EACCESThe provided buffers are not placed in the Data RAM region.

◆ nrfx_i2s_stop()

void nrfx_i2s_stop ( nrfx_i2s_t * p_instance)

Function for stopping the I2S transfer.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_i2s_uninit()

void nrfx_i2s_uninit ( nrfx_i2s_t * p_instance)

Function for uninitializing the I2S driver.

Parameters
[in]p_instancePointer to the driver instance structure.