A well tested I2S library where the send and recieve parts are seperate instances.
Dependents:
TLV320_Write_test
flash_audio_playerI2S
Wolfson_3_wav
« Back to documentation index
I2S Class Reference
A class to play give access to the I2S library.
More...
#include <I2S.h >
Public Member Functions
I2S (bool rxtx, PinName sd, PinName ws, PinName clk)
Create a I2S instance.
I2S (bool rxtx, PinName sd)
Create a I2S instance: Only with the serial data line set.
I2S (bool rxtx, PinName sd, PinName ws)
Create a I2S instance: Only with serial data line and word select.
I2S (bool rxtx, PinName sd, bool fourwiremode)
Create a I2S instance: Only with serial data line.
I2S (bool rxtx, PinName sd, PinName ws, bool fourwiremode)
Create a I2S instance: Only with serial data line and word select line.
~I2S ()
Destroy the I2S instance.
void write (char buf[], int len)
Write to the FIFO.
void write (int buf[], int len)
Write to the FIFO.
int read ()
Read the FIFOs contents.
void read (char buf[], int len)
Read from the FIFO.
void read (int buf[], int len)
Read from the FIFO.
int max_fifo_points ()
Get the maximum number of points of data the FIFO could store.
void power (bool pwr)
Switch the peripheral on and off.
void masterslave (bool mastermode)
Switch the peripheral between master and slave.
void wordsize (int words)
Switch the peripheral between different wordsizes.
void mclk_freq (int freq)
Define the mclk frequency.
void frequency (int freq)
Define the sample rate.
void set_interrupt_fifo_level (int level)
Set the level that the fifo interrupts at.
int fifo_level ()
Get the current FIFO level.
int fifo_points ()
Get the current number of samples in the FIFO.
void stereomono (bool stereomode)
Set whether the peripheral is in stereo or mono mode: in mono the perifpheral sends out the same data twice.
void mute ()
Mute the peripheral.
void mute (bool mute_en)
Set the mute status of the peripheral.
void stop ()
Stop the peripheral.
void start ()
Start the peripheral.
bool setup_ok ()
Check the Clock and Pin setup went according to plan.
void attach (void(*fptr)(void))
Attach a function to be called when the FIFO triggers.
template<typename T >
void attach (T *tptr, void(T::*mptr)(void))
Attach a member function to be called when the FIFO triggers.
Detailed Description
A class to play give access to the I2S library.
Definition at line 55 of file I2S.h .
Constructor & Destructor Documentation
I2S
(
bool
rxtx ,
PinName
sd ,
PinName
ws ,
PinName
clk
)
Create a I2S instance.
Parameters:
rxtx Set the I2S instance to be transmit or recieve (I2S_TRANSMIT/I2S_RECEIVE)
sd The serial data pin
ws The word select pin
clk The clock pin
Definition at line 22 of file I2S.cpp .
I2S
(
bool
rxtx ,
PinName
sd
)
Create a I2S instance: Only with the serial data line set.
Won't really do much.
Parameters:
rxtx Set the I2S instance to be transmit or recieve (I2S_TRANSMIT/I2S_RECEIVE)
sd The serial data pin
Definition at line 48 of file I2S.cpp .
I2S
(
bool
rxtx ,
PinName
sd ,
PinName
ws
)
Create a I2S instance: Only with serial data line and word select.
Parameters:
rxtx Set the I2S instance to be transmit or recieve (I2S_TRANSMIT/I2S_RECEIVE)
sd The serial data pin
ws The word select pin
Definition at line 121 of file I2S.cpp .
I2S
(
bool
rxtx ,
PinName
sd ,
bool
fourwiremode
)
Create a I2S instance: Only with serial data line.
Four wire mode means this is functional
Parameters:
rxtx Set the I2S instance to be transmit or recieve (I2S_TRANSMIT/I2S_RECEIVE)
sd The serial data pin
fourwiremode True means the peripheral is in 4-wire mode. It borrows WS and CLK from the other half
Definition at line 72 of file I2S.cpp .
I2S
(
bool
rxtx ,
PinName
sd ,
PinName
ws ,
bool
fourwiremode
)
Create a I2S instance: Only with serial data line and word select line.
Four wire mode means this is functional
Parameters:
rxtx Set the I2S instance to be transmit or recieve (I2S_TRANSMIT/I2S_RECEIVE)
sd The serial data pin
ws The word select pin
fourwiremode True means the peripheral is in 4-wire mode. It borrows WS and CLK from the other half
Definition at line 96 of file I2S.cpp .
Destroy the I2S instance.
Definition at line 146 of file I2S.cpp .
Member Function Documentation
void attach
(
void(*)(void)
fptr )
Attach a function to be called when the FIFO triggers.
Parameters:
fptr A pointer to the function to be called
Definition at line 232 of file I2S.h .
void attach
(
T *
tptr ,
void(T::*)(void)
mptr
)
Attach a member function to be called when the FIFO triggers.
Parameters:
tptr A pointer to the instance of the class
mptr A pointer to the member function
Definition at line 252 of file I2S.h .
Get the current FIFO level.
Returns: A number between 0 and 7 the FIFO is currently at
Definition at line 375 of file I2S.cpp .
Get the current number of samples in the FIFO.
Returns: A number showing how many samples are in the FIFO
Definition at line 323 of file I2S.cpp .
void frequency
(
int
freq )
Define the sample rate.
Parameters:
freq The desired sample rate frequency
Definition at line 369 of file I2S.cpp .
void masterslave
(
bool
mastermode )
Switch the peripheral between master and slave.
Parameters:
mastermode The peripherals master/slave status (I2S_MASTER/I2S_SLAVE)
Definition at line 347 of file I2S.cpp .
Get the maximum number of points of data the FIFO could store.
Returns: The number of points
Definition at line 309 of file I2S.cpp .
void mclk_freq
(
int
freq )
Define the mclk frequency.
Parameters:
freq The frequency desired for the mclk
Definition at line 363 of file I2S.cpp .
Mute the peripheral.
Definition at line 399 of file I2S.cpp .
void mute
(
bool
mute_en )
Set the mute status of the peripheral.
Parameters:
mute_en Set whether the mute is enabled
Definition at line 405 of file I2S.cpp .
Switch the peripheral on and off.
Parameters:
Definition at line 337 of file I2S.cpp .
void read
(
char
buf [],
int
len
)
Read from the FIFO.
Parameters:
buf[] The buffer of values to read: raw bit shifted
len The number of chars to read
Definition at line 254 of file I2S.cpp .
void read
(
int
buf [],
int
len
)
Read from the FIFO.
Parameters:
buf[] The buffer of values to read: sorted to just values
len The number of chars to read
Definition at line 279 of file I2S.cpp .
Read the FIFOs contents.
Returns: The buffers value.
Definition at line 249 of file I2S.cpp .
void set_interrupt_fifo_level
(
int
level )
Set the level that the fifo interrupts at.
Parameters:
level A number between 0 and 7 at which the fifo interrupts
Definition at line 417 of file I2S.cpp .
Check the Clock and Pin setup went according to plan.
Returns: Setup okay?
Definition at line 430 of file I2S.cpp .
Start the peripheral.
Definition at line 423 of file I2S.cpp .
void stereomono
(
bool
stereomode )
Set whether the peripheral is in stereo or mono mode: in mono the perifpheral sends out the same data twice.
Parameters:
stereomode Whether the peripheral is in stereo or mono: I2S_STEREO/I2S_MONO
Definition at line 390 of file I2S.cpp .
Stop the peripheral.
Definition at line 411 of file I2S.cpp .
void wordsize
(
int
words )
Switch the peripheral between different wordsizes.
Parameters:
words The number of bits per word: 8,16,32
Definition at line 357 of file I2S.cpp .
void write
(
char
buf [],
int
len
)
Write to the FIFO.
Parameters:
buf[] The buffer of values to write: are bit stuffed in fours
len The number of chars to write
Definition at line 173 of file I2S.cpp .
void write
(
int
buf [],
int
len
)
Write to the FIFO.
Parameters:
buf[] The buffer of values to write: are bit stuffed automatically
len The number of chars to write
Definition at line 192 of file I2S.cpp .