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

Analog Device ADAU1361A audio codec control class. More...

#include <adau1361.hpp>

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

Public Types

enum  CodecChannel { LineInput , AuxInput , LineOutput , HeadphoneOutput }
 Signal path definition. More...
 

Public Member Functions

 Adau1361 (unsigned int fs, unsigned int master_clock, Adau1361Lower &adau1361_lower)
 constructor.
 
virtual void Start (void)
 Set up the ADAU1361 codec, and then, start the codec.
 
virtual void SetGain (CodecChannel channel, float left_gain, float right_gain)
 Set channel gain.
 
virtual void Mute (CodecChannel channel, bool mute=true)
 Mute the specific channel.
 

Detailed Description

Analog Device ADAU1361A audio codec control class.

Control the ADAU1361A through the lower level controller class for example UmbAdau1361Lower. Such the lower level controller variable is passed through the adau1361_lower parameter of the constructor.

The following is an example code to create an Adau1361 variable.

::rpp_driver::I2cMaster i2c(sdk, // Inject SDK Dependency.
*i2c1, // I2C controller to use.
kI2cClock, // I2C Clock [Hz]
kI2cScl_pin, // GPIO pin for SCL
kI2cSdaPin); // GPIO pin # for SDA
i2c, // Inject I2C controller dependency.
kAdau1361I2cAddress); // I2C address of UMB-ADAU1361-A
kFs, // Sampling frequency[Hz].
kMClock, // Master clock of UMB-ADAU1361-A[Hz].
codec_lower); // Inject Codec lower part dependency.
Analog Device ADAU1361A audio codec control class.
Definition: adau1361.hpp:83
I2C Master controller class.
Definition: i2cmaster.hpp:83
lower part of the Adau1361 CODEC controller class.
Definition: umbadau1361lower.hpp:27

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::MockAdau1361 inside adau1361.hpp.

#include <gmock/gmock.h>
#include <gtest/gtest.h>
class UserCodeTest : public ::testing::Test {
protected:
virtual void SetUp() {
mock_i2c_ = new ::rpp_driver::MockI2cMaster(mock_sdk_);
mock_codec_lower_ = new ::rpp_driver::MockAdau1361Lower(*mock_i2c_);
mock_codec_ = new ::rpp_driver::MockAdau1361(*mock_codec_lower_);
}
virtual void TearDown() {
delete mock_codec_;
delete mock_codec_lower_;
delete mock_i2c_;
}
::rpp_driver::MockAdau1361Lower *mock_codec_lower_;
};
TEST_F(UserCodeTest, foo) {
// Write Test code here.
}
ADAU1361A CODEC Control.
Mock class for test.
Definition: adau1361lower.hpp:239
Mock class for test.
Definition: adau1361.hpp:207
Mock class for test.
Definition: i2cmaster.hpp:150
Wrapper class for the RasPi Pico SDK functions.
Definition: sdkwrapper.hpp:74
I2C Master Controller.
Lower class for the UMB-ADAU1361A.

Member Enumeration Documentation

◆ CodecChannel

Signal path definition.

This type specify the CODEC input / output channel to change the gain and mute.

See also
SetGain() and Mute().
Enumerator
LineInput 

Physical input channel as line in audio.

AuxInput 

Physical input channel as aux in audio.

LineOutput 

Physical output channel as line out audio.

HeadphoneOutput 

Physical output channel as head phone out audio.

Constructor & Destructor Documentation

◆ Adau1361()

rpp_driver::Adau1361::Adau1361 ( unsigned int  fs,
unsigned int  master_clock,
Adau1361Lower adau1361_lower 
)
explicit

constructor.

Parameters
fsSampling frequency[Hz]
master_clockInput master clock frequency to the MCLK pin[Hz]
adau1361_lowerHelper object.

initialize the internal variables. This constructor assumes the codec receive a master clock from outside. And output the I2C clocks as clock master.

The fs parameter is the sampling frequency of the CODEC in Hz. This parameter is limited as one of the following :

  • 24000
  • 32000
  • 48000
  • 96000
  • 22050
  • 44100
  • 88200

The master_clock parameter is the MCLK input to the ADAU1361 in Hz. This parameter must be one of followings :

  • 8000000
  • 12000000
  • 13000000
  • 14400000
  • 19200000
  • 19680000
  • 19800000
  • 24000000
  • 26000000
  • 27000000
  • 12288000
  • 24576000

Note : Due to the limitation of the MCLK of hardware and PLL, only 8, 12, 13, 14.4, 12.288, 19.2MHz are tested

The analog signals are routed to the physical pins as following :

  • Line In : LINN/RINN single ended.
  • Aux In : LAUX/RAUX input
  • LINE out : LOUTP/ROUTP single ended
  • HP out : LHP/RHP

Member Function Documentation

◆ Mute()

virtual void rpp_driver::Adau1361::Mute ( CodecChannel  channel,
bool  mute = true 
)
virtual

Mute the specific channel.

Parameters
channelChannel to mute on / off
muteMute-on if true. Mute-off if false.

◆ SetGain()

virtual void rpp_driver::Adau1361::SetGain ( CodecChannel  channel,
float  left_gain,
float  right_gain 
)
virtual

Set channel gain.

Parameters
channelCODEC input output channels like line-in, line-out, aux-in, headphone-out
left_gainGain by dB. [6 .. -12], The gain value outside of the acceptable range will be saturated.
right_gainGain by dB. [6 .. -12], The gain value outside of the acceptable range will be saturated.

◆ Start()

virtual void rpp_driver::Adau1361::Start ( void  )
virtual

Set up the ADAU1361 codec, and then, start the codec.

This method starts the ADAU1361 AD/DA conversion and I2S communication.

The line in is configured to use the Single-End negative input. This is funny but ADAU1361 data sheet specifies to do it. The positive in and diff in are killed. All biases are set as "normal".

The CODEC is configured as master mode. That mean, BCLK and WS are given from ADAU1361 to the micro processor.

At initial state, ADAU1361 is set as :

  • All input and output channels are set as 0.0dB.
  • All input and output channels are muted.

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