Quentin Roche / ST_I2S

Dependents:   X_NUCLEO_CCA02M1

Fork of ST_I2S by ST

Embed: (wiki syntax)

« Back to documentation index

I2S Class Reference

A I2S Master/Slave, used for communicating with I2S slave/master devices. More...

#include <I2S.h>

Public Member Functions

 I2S (PinName dpin, PinName clk, PinName wsel, PinName fdpin=NC, PinName mck=NC)
 Create a I2S master connected to the specified pins.
int format (int dbits, int fbits, int polarity=0)
 Configure the data transmission format.
int audio_frequency (unsigned int hz)
 Set the i2s audio frequency.
unsigned int get_audio_frequency (void)
 Get the i2s audio frequency.
int protocol (i2s_bitorder_t protocol)
 Set the i2s bus protocol.
int mode (i2s_mode_t mode, bool circular)
 Set the i2s mode.
template<typename Type >
int transfer (const Type *tx_buffer, int tx_length, Type *rx_buffer, int rx_length, const mbed::event_callback_t &callback, int event)
 Start non-blocking I2S transfer as configured with above methods.
void abort_transfer ()
 Abort the on-going I2S transfer, and continue with transfer's in the queue if any.
void clear_transfer_buffer ()
 Clear the transaction buffer.
void abort_all_transfers ()
 Clear the transaction buffer and abort on-going transfer.
int get_transfer_status ()
 Get transfer status.
unsigned int get_module ()
 Get internal module id.
int dma_priority (i2s_dma_prio_t prio)
 Configure DMA priority for transfers.

Static Public Member Functions

static int harmonize (I2S &dev_i2s_1, I2S &dev_i2s_2)
 Harmonize the frequencies of the given I2S objects so that they are the exact multiple one of the other.

Static Public Attributes

static events::EventQueue i2s_bh_queue
 Bottom-half & transactions event queue for all I2S objects Must be used by application programmer to schedule/execute bottom-halves (i.e.

Protected Member Functions

virtual void lock (void)
 Acquire exclusive access to this I2S bus.
virtual void unlock (void)
 Release exclusive access to this I2S bus.
void irq_handler_asynch_tx (void)
 I2S TX DMA IRQ handler.
void irq_handler_asynch_rx (void)
 I2S RX DMA IRQ handler.
int queue_transfer (const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, const mbed::event_callback_t &callback, int event)
 Add a transfer to the queue.
void start_transfer (const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, const mbed::event_callback_t &callback, int event)
 Configures a callback, i2s peripheral and initiate a new transfer.
void start_transaction (mbed::transaction_t *data)
 Start a new transaction.
void dequeue_transaction ()
 Dequeue a transaction.

Detailed Description

A I2S Master/Slave, used for communicating with I2S slave/master devices.

The default format is set to master transmission mode, one-shot (i.e. not circular) 16 data bits & 16 bits per frame, clock polarity 0, protocol PHILIPS, and a clock frequency of 44.1kHz

Most I2S devices will also require Reset signals. These can be controlled using <DigitalOut> pins

Synchronization level: Thread safe

Definition at line 32 of file I2S.h.


Constructor & Destructor Documentation

I2S ( PinName  dpin,
PinName  clk,
PinName  wsel,
PinName  fdpin = NC,
PinName  mck = NC 
)

Create a I2S master connected to the specified pins.

Parameters:
dpinI2S data input/output pin
clkI2S clock output pin
wselI2S word select output pin (might be NC for PDM sources)
fdpinI2S data input pin (for full-duplex operation, default = NC)
mckI2S master clock output (additional pin when needed for some external audio devices, default = NC)

It is up to the application programmer to not generate at the same time two I2S instances with the same pin (NC excluded) for one of the parameters, otherwise the correct operation of this class cannot be guaranteed (e.g. things like SPI/I2S clock enabling and above all disabling might not work correctly)!

Definition at line 30 of file I2S.cpp.


Member Function Documentation

void abort_all_transfers (  )

Clear the transaction buffer and abort on-going transfer.

Definition at line 152 of file I2S.cpp.

void abort_transfer (  )

Abort the on-going I2S transfer, and continue with transfer's in the queue if any.

Definition at line 132 of file I2S.cpp.

int audio_frequency ( unsigned int  hz )

Set the i2s audio frequency.

Parameters:
hzaudio frequency in hz
Returns:
Zero if the usage was set, -1 if a transaction is on-going

Definition at line 63 of file I2S.cpp.

void clear_transfer_buffer (  )

Clear the transaction buffer.

Definition at line 143 of file I2S.cpp.

void dequeue_transaction (  ) [protected]

Dequeue a transaction.

Definition at line 248 of file I2S.cpp.

int dma_priority ( i2s_dma_prio_t  prio )

Configure DMA priority for transfers.

Parameters:
prioThe DMA priority to be used
Returns:
Zero if the usage was set, -1 if a transaction is on-going

Definition at line 176 of file I2S.cpp.

int format ( int  dbits,
int  fbits,
int  polarity = 0 
)

Configure the data transmission format.

Parameters:
dbitsNumber of data bits per I2S frame (16, 24, or 32)
fbitsNumber of bits per I2S frame (16 or 32)
polarityClock polarity (either 0/low or 1/high, default = 0)
Returns:
Zero if the usage was set, -1 if a transaction is on-going

Definition at line 48 of file I2S.cpp.

unsigned int get_audio_frequency ( void   )

Get the i2s audio frequency.

Returns:
Currently set audio frequency

Definition at line 69 of file I2S.h.

unsigned int get_module (  )

Get internal module id.

Returns:
internal module id

Definition at line 171 of file I2S.cpp.

int get_transfer_status (  )

Get transfer status.

Returns:
-1 if a transaction is on-going, zero otherwise

Definition at line 160 of file I2S.cpp.

int harmonize ( I2S dev_i2s_1,
I2S dev_i2s_2 
) [static]

Harmonize the frequencies of the given I2S objects so that they are the exact multiple one of the other.

It can be useful whenever two I2S peripherals have to work together and no drift is allowed between them.

Parameters:
dev_i2s_1reference to the first I2S object.
dev_i2s_2reference to the second I2S object.
Returns:
Zero if the frequencies have been harmonized correctly, -1 otherwise.

Definition at line 103 of file I2S.cpp.

void irq_handler_asynch_rx ( void   ) [protected]

I2S RX DMA IRQ handler.

Definition at line 265 of file I2S.cpp.

void irq_handler_asynch_tx ( void   ) [protected]

I2S TX DMA IRQ handler.

Definition at line 278 of file I2S.cpp.

void lock ( void   ) [protected, virtual]

Acquire exclusive access to this I2S bus.

Definition at line 12 of file I2S.cpp.

int mode ( i2s_mode_t  mode,
bool  circular 
)

Set the i2s mode.

Parameters:
modeI2S mode to be used
circularI2S should read/write buffers continuously (in circular mode)
Returns:
Zero if the usage was set, -1 if a transaction is on-going

Definition at line 89 of file I2S.cpp.

int protocol ( i2s_bitorder_t  protocol )

Set the i2s bus protocol.

Parameters:
protocolI2S protocol to be used
Returns:
Zero if the usage was set, -1 if a transaction is on-going

Definition at line 76 of file I2S.cpp.

int queue_transfer ( const void *  tx_buffer,
int  tx_length,
void *  rx_buffer,
int  rx_length,
const mbed::event_callback_t &  callback,
int  event 
) [protected]

Add a transfer to the queue.

Parameters:
dataTransaction data
Returns:
Zero if a transfer was added to the queue, or -1 if the queue is full

Definition at line 188 of file I2S.cpp.

void start_transaction ( mbed::transaction_t *  data ) [protected]

Start a new transaction.

Parameters:
dataTransaction data

Definition at line 243 of file I2S.cpp.

void start_transfer ( const void *  tx_buffer,
int  tx_length,
void *  rx_buffer,
int  rx_length,
const mbed::event_callback_t &  callback,
int  event 
) [protected]

Configures a callback, i2s peripheral and initiate a new transfer.

Parameters:
dataTransaction data

Definition at line 227 of file I2S.cpp.

int transfer ( const Type *  tx_buffer,
int  tx_length,
Type *  rx_buffer,
int  rx_length,
const mbed::event_callback_t &  callback,
int  event 
)

Start non-blocking I2S transfer as configured with above methods.

Parameters:
tx_bufferThe TX buffer with data to be transfered. If NULL is passed, no transmission will be set up
tx_lengthThe length of TX buffer in bytes
rx_bufferThe RX buffer which is used for received data. If NULL is passed, received data will be ignored
rx_lengthThe length of RX buffer in bytes
callbackThe event callback function
eventThe logical OR of events to notify. Look at i2s hal header file for I2S events.
Returns:
Zero if the transfer has started (or been queued), or -1 if I2S peripheral is busy (or out of resources)

Definition at line 102 of file I2S.h.

void unlock ( void   ) [protected, virtual]

Release exclusive access to this I2S bus.

Definition at line 21 of file I2S.cpp.


Field Documentation

events::EventQueue i2s_bh_queue [static]

Bottom-half & transactions event queue for all I2S objects Must be used by application programmer to schedule/execute bottom-halves (i.e.

transfer event callback functions) and automatically start queued transactions (i.e. transfers), e.g. by calling `eventsEventQueue::dispatch_forever()`!

Definition at line 168 of file I2S.h.