Raspberry Pio Pico Drivers project
Loading...
Searching...
No Matches
Public Member Functions
rpp_driver::I2sSlaveDuplex Class Reference

Duplex Slave I2S controller class. More...

#include <i2sslaveduplex.hpp>

Inheritance diagram for rpp_driver::I2sSlaveDuplex:
Inheritance graph
[legend]

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.
 

Detailed Description

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 :

  1. SDOUT
  2. SDIN
  3. BCLK
  4. WS

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.

Usage of mock

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.

#include <gmock/gmock.h>
#include <gtest/gtest.h>
class UserCodeTest : public ::testing::Test {
protected:
::rpp_driver::MockSdkWrapper mock_sdk_;
::rpp_driver::MockI2sSlaveDuplex* mock_i2sslaveduplex_;
virtual void SetUp() {
mock_i2sslaveduplex_ = new ::rpp_driver::MockI2sSlaveDuplex(mock_sdk_);
}
virtual void TearDown() { delete (mock_i2sslaveduplex_); }
};
TEST_F(UserCodeTest, foo) {
// Write Test code here.
}
Mock class for test.
Definition: i2sslaveduplex.hpp:187
Duplex Slave I2S class.
Wrapper for RasPi Pico SDK API.

Constructor & Destructor Documentation

◆ I2sSlaveDuplex() [1/2]

rpp_driver::I2sSlaveDuplex::I2sSlaveDuplex ( ::rpp_driver::SdkWrapper sdk,
PIO  pio,
uint  pin_base 
)

Construct a new Duplex Slave I2S object.

Parameters
sdkSDK wrapper class injection.
pioPIO to use.
pin_baseThe 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.

◆ I2sSlaveDuplex() [2/2]

rpp_driver::I2sSlaveDuplex::I2sSlaveDuplex ( ::rpp_driver::SdkWrapper sdk,
PIO  pio,
uint32_t  sm,
uint  pin_base 
)

Construct a new Duplex Slave I2S object.

Parameters
sdkSDK wrapper class injection.
pioPIO to use.
smState machine to use.
pin_baseThe 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.

Member Function Documentation

◆ GetFifoBlocking()

virtual int32_t rpp_driver::I2sSlaveDuplex::GetFifoBlocking ( )
virtual

Get one audio data from RX FIFO.

Returns
int32_t An audio data.

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.

◆ GetStateMachine()

virtual uint32_t rpp_driver::I2sSlaveDuplex::GetStateMachine ( )
virtual

Get the State Machine object.

Returns
uint32_t The number of the state machine which is claimed.

This is convenient if the state machine is assigned internally.

◆ PutFifoBlocking()

virtual void rpp_driver::I2sSlaveDuplex::PutFifoBlocking ( int32_t  value)
virtual

Put one audio data to TX FIFO.

Parameters
valueAn audio data to send. To put one stere sample, call this member function twice. The left data must be put and then, right data.

◆ Start()

virtual void rpp_driver::I2sSlaveDuplex::Start ( )
virtual

Initialize the I2S port, and run.

Assign the GPIO, configure them, load the PIO program, configure the state machine and run.

◆ Stop()

virtual void rpp_driver::I2sSlaveDuplex::Stop ( )
virtual

Stop the I2S port and disable the PIO state machine in use.

Make FIFOs empty.


The documentation for this class was generated from the following file: