arduino-audio-driver
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AudioDriverZephyrT< T, DefaultI2CAddress > Class Template Reference

Generic Driver API that wraps a codec driver class which has been ported from the Zephyr RTOS (see Codecs/<chip>/*.h, e.g. WM8904, DA7212, TAS2563, ...). It provides the I2C wire/address from the pin configuration to the driver and calls its begin()/setVolume()/setMute() (or setOutputVolume()/setOutputMute()) methods, so that the chip can be used via the regular AudioDriver API. More...

#include <AudioDriver.h>

Inheritance diagram for AudioDriverZephyrT< T, DefaultI2CAddress >:
AudioDriver

Public Member Functions

 AudioDriverZephyrT (uint8_t i2cAddress=DefaultI2CAddress)
 
virtual bool begin (CodecConfig codecCfg, DriverDeviceInfo &pins)
 Starts the processing.
 
T & driver ()
 Provides access to the wrapped Zephyr driver instance.
 
virtual bool end (void)
 Ends the processing: shut down dac and adc.
 
API_GPIOgetGPIO ()
 
virtual int getI2CAddress ()
 Provides the i2c address.
 
int getInputVolume ()
 
int getVolume () override
 Determines the actual volume (range: 0-100)
 
bool isInputVolumeSupported () override
 Determines if setInputVolume() is supported.
 
virtual bool isVolumeSupported ()
 Determines if setVolume() is suppored.
 
 operator bool ()
 
virtual DriverDeviceInfopins ()
 Provides the pin information.
 
virtual bool setConfig (CodecConfig codecCfg)
 changes the configuration
 
virtual bool setI2CAddress (uint16_t adr)
 Defines the i2c address.
 
bool setInputVolume (int volume) override
 Defines the input volume (range: 0-100) if supported.
 
bool setMute (bool enable) override
 Mutes all output lines.
 
virtual bool setMute (bool mute, int line)
 Mute individual lines: only supported for some rare DACs.
 
bool setPAPower (bool enable)
 Sets the PA Power pin to active or inactive.
 
void setPins (DriverDeviceInfo &pins)
 
void setupI2CAddress ()
 If no address is defined in the pins we provide it here.
 
bool setVolume (int volume) override
 Defines the Volume (in %) if volume is 0, mute is enabled,range is 0-100.
 

Protected Member Functions

bool configInterface (codec_mode_t mode, I2SDefinition iface) override
 Configures the codec (sample rate, bits per sample) for the given I2S setup.
 
bool controlState (codec_mode_t mode) override
 
bool deinit () override
 Stops the input and output and (if supported) shuts down the codec.
 
virtual i2c_bus_handle_t getI2C ()
 Determine the TwoWire object from the I2C config or use Wire.
 
bool init (codec_config_t codecCfg) override
 
int limitValue (int volume, int min=0, int max=100)
 
int mapVolume (int x, int in_min, int in_max, int out_min, int out_max)
 

Protected Attributes

CodecConfig codec_cfg
 
int i2c_default_address = -1
 
DriverDeviceInfop_pins = nullptr
 
int volume_value = 100
 
zephyr_driver
 

Detailed Description

template<class T, uint8_t DefaultI2CAddress = 0>
class audio_driver::AudioDriverZephyrT< T, DefaultI2CAddress >

Generic Driver API that wraps a codec driver class which has been ported from the Zephyr RTOS (see Codecs/<chip>/*.h, e.g. WM8904, DA7212, TAS2563, ...). It provides the I2C wire/address from the pin configuration to the driver and calls its begin()/setVolume()/setMute() (or setOutputVolume()/setOutputMute()) methods, so that the chip can be used via the regular AudioDriver API.

Some chips require additional parameters (e.g. the master clock frequency) for their begin() method: in this case begin() is not called automatically and driver() must be used to set up the chip manually before AudioDriver::begin() is called.

Template Parameters
Tthe Zephyr ported codec driver class (e.g. WM8904)
DefaultI2CAddressthe default I2C address of the chip
Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ AudioDriverZephyrT()

template<class T , uint8_t DefaultI2CAddress = 0>
AudioDriverZephyrT ( uint8_t  i2cAddress = DefaultI2CAddress)
inline

Member Function Documentation

◆ begin()

virtual bool begin ( CodecConfig  codecCfg,
DriverDeviceInfo pins 
)
inlinevirtualinherited

◆ configInterface()

template<class T , uint8_t DefaultI2CAddress = 0>
bool configInterface ( codec_mode_t  mode,
I2SDefinition  iface 
)
inlineoverrideprotectedvirtual

Configures the codec (sample rate, bits per sample) for the given I2S setup.

Reimplemented from AudioDriver.

◆ controlState()

template<class T , uint8_t DefaultI2CAddress = 0>
bool controlState ( codec_mode_t  mode)
inlineoverrideprotectedvirtual

Reimplemented from AudioDriver.

◆ deinit()

template<class T , uint8_t DefaultI2CAddress = 0>
bool deinit ( )
inlineoverrideprotectedvirtual

Stops the input and output and (if supported) shuts down the codec.

Reimplemented from AudioDriver.

◆ driver()

template<class T , uint8_t DefaultI2CAddress = 0>
T & driver ( )
inline

Provides access to the wrapped Zephyr driver instance.

◆ end()

virtual bool end ( void  )
inlinevirtualinherited

◆ getGPIO()

API_GPIO & getGPIO ( )
inlineinherited

◆ getI2C()

virtual i2c_bus_handle_t getI2C ( )
inlineprotectedvirtualinherited

Determine the TwoWire object from the I2C config or use Wire.

◆ getI2CAddress()

virtual int getI2CAddress ( )
inlinevirtualinherited

Provides the i2c address.

◆ getInputVolume()

template<class T , uint8_t DefaultI2CAddress = 0>
int getInputVolume ( )
inline

◆ getVolume()

template<class T , uint8_t DefaultI2CAddress = 0>
int getVolume ( )
inlineoverridevirtual

Determines the actual volume (range: 0-100)

Implements AudioDriver.

◆ init()

template<class T , uint8_t DefaultI2CAddress = 0>
bool init ( codec_config_t  codecCfg)
inlineoverrideprotectedvirtual

Reimplemented from AudioDriver.

◆ isInputVolumeSupported()

template<class T , uint8_t DefaultI2CAddress = 0>
bool isInputVolumeSupported ( )
inlineoverridevirtual

Determines if setInputVolume() is supported.

Reimplemented from AudioDriver.

◆ isVolumeSupported()

virtual bool isVolumeSupported ( )
inlinevirtualinherited

◆ limitValue()

int limitValue ( int  volume,
int  min = 0,
int  max = 100 
)
inlineprotectedinherited

make sure that value is in range

Parameters
volume
Returns

◆ mapVolume()

int mapVolume ( int  x,
int  in_min,
int  in_max,
int  out_min,
int  out_max 
)
inlineprotectedinherited

◆ operator bool()

operator bool ( )
inlineinherited

◆ pins()

virtual DriverDeviceInfo & pins ( )
inlinevirtualinherited

Provides the pin information.

Reimplemented in AudioDriverCS42448Class.

◆ setConfig()

virtual bool setConfig ( CodecConfig  codecCfg)
inlinevirtualinherited

◆ setI2CAddress()

virtual bool setI2CAddress ( uint16_t  adr)
inlinevirtualinherited

Defines the i2c address.

◆ setInputVolume()

template<class T , uint8_t DefaultI2CAddress = 0>
bool setInputVolume ( int  volume)
inlineoverridevirtual

Defines the input volume (range: 0-100) if supported.

Reimplemented from AudioDriver.

◆ setMute() [1/2]

template<class T , uint8_t DefaultI2CAddress = 0>
bool setMute ( bool  enable)
inlineoverridevirtual

Mutes all output lines.

Implements AudioDriver.

◆ setMute() [2/2]

virtual bool setMute ( bool  mute,
int  line 
)
inlinevirtualinherited

Mute individual lines: only supported for some rare DACs.

Reimplemented in AudioDriverCS42448Class, AudioDriverES8388Class, AudioDriverPCM3168Class, and AudioDriverWM8978Class.

◆ setPAPower()

bool setPAPower ( bool  enable)
inlineinherited

Sets the PA Power pin to active or inactive.

◆ setPins()

void setPins ( DriverDeviceInfo pins)
inlineinherited

◆ setupI2CAddress()

void setupI2CAddress ( )
inlineinherited

If no address is defined in the pins we provide it here.

◆ setVolume()

template<class T , uint8_t DefaultI2CAddress = 0>
bool setVolume ( int  volume)
inlineoverridevirtual

Defines the Volume (in %) if volume is 0, mute is enabled,range is 0-100.

Implements AudioDriver.

Member Data Documentation

◆ codec_cfg

CodecConfig codec_cfg
protectedinherited

◆ i2c_default_address

int i2c_default_address = -1
protectedinherited

◆ p_pins

DriverDeviceInfo* p_pins = nullptr
protectedinherited

◆ volume_value

template<class T , uint8_t DefaultI2CAddress = 0>
int volume_value = 100
protected

◆ zephyr_driver

template<class T , uint8_t DefaultI2CAddress = 0>
T zephyr_driver
protected

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