Raspberry Pio Pico Drivers project
|
Duplex Slave I2S controller class. More...
#include <i2sslaveduplex.hpp>
Public Member Functions | |
I2sSlaveDuplex (::rpp_driver::SdkWrapper &sdk, PIO pio, uint pin_base) | |
Construct a new Duplex Slave I2S object. | |
I2sSlaveDuplex (::rpp_driver::SdkWrapper &sdk, PIO pio, uint32_t sm, uint pin_base) | |
Construct a new Duplex Slave I2S object. | |
~I2sSlaveDuplex () | |
Unclaim the state machine. No actual processing. | |
virtual void | Start () |
Initialize the I2S port, and run. | |
virtual void | Stop () |
Stop the I2S port and disable the PIO state machine in use. | |
virtual uint32_t | GetStateMachine () |
Get the State Machine object. | |
virtual int32_t | GetFifoBlocking () |
Get one audio data from RX FIFO. | |
virtual void | PutFifoBlocking (int32_t value) |
Put one audio data to TX FIFO. | |
Duplex Slave I2S controller class.
This class supports the duplex communication of the I2S on the PIO port of the RP2040/2350 SoC MCU.
The timing signal (BCLK and WS) of the I2S must be provided from the external device. This class supports up to 192kHz Fs if the MCU system clock is higher than 120MHz.
The I2S pins can be mapped on the GPIO. This mapping is based on the pin_base parameter of the constructors.
The pin_base parameter of the constructors is the first pin of 4 I2S signals. The signals must be consecutive on the GPIO pins as like :
For example, let's assume SDTOUT is GPIO 15. Then, SDIN, BCLK and WS are GPIO 16, 17 and 18 respectively.
To start and stop the I2S transfer, call the Start() and the Stop() member functions respectively.
The audio sample in and out are through the GetFifoBlocking() and the PutFifoBlocking() member functions, respectively. These are blocking function. That mean, program will wait until the data is ready, or FIFO has room for data.
This class assumes polling based data transfer instead of interrupt / DMA based data transfer.
Typically, program process the signal obtained from GetFifoBLock() and output to PutFifoBLock(). To provide the high quality processing, The first GetFifoBlocking() call should be as soon as possible, after calling start() function.
In the case of the testing of the user program which uses this class, a programmer can use the pre-defined mock class rpp_driver::MockI2sSlaveDuplex inside i2sslaveduplex.hpp.
rpp_driver::I2sSlaveDuplex::I2sSlaveDuplex | ( | ::rpp_driver::SdkWrapper & | sdk, |
PIO | pio, | ||
uint | pin_base | ||
) |
Construct a new Duplex Slave I2S object.
sdk | SDK wrapper class injection. |
pio | PIO to use. |
pin_base | The GPIO pin number of SDOUT signal. |
The state machine number is not specified in this constructor. Internally, the state machine will be allocate from the unused one.
This constructor just registers the given parameters and allocated state machine to the internal parameters. And then, claim the state machine. No other processing will be done.
rpp_driver::I2sSlaveDuplex::I2sSlaveDuplex | ( | ::rpp_driver::SdkWrapper & | sdk, |
PIO | pio, | ||
uint32_t | sm, | ||
uint | pin_base | ||
) |
Construct a new Duplex Slave I2S object.
sdk | SDK wrapper class injection. |
pio | PIO to use. |
sm | State machine to use. |
pin_base | The GPIO pin number of SDOUT signal. |
This constructor just registers the given parameters to the internal parameters. And then, claim the state machine. No other processing will be done.
|
virtual |
Get one audio data from RX FIFO.
To get one stere sample, call this member function twice. The left data will be given and then, right data.
This function is blocking. That mean, program will wait until the data has been received.
|
virtual |
Get the State Machine object.
This is convenient if the state machine is assigned internally.
|
virtual |
Put one audio data to TX FIFO.
value | An audio data to send. To put one stere sample, call this member function twice. The left data must be put and then, right data. |
|
virtual |
Initialize the I2S port, and run.
Assign the GPIO, configure them, load the PIO program, configure the state machine and run.
|
virtual |
Stop the I2S port and disable the PIO state machine in use.
Make FIFOs empty.