MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
The tfa9xxx driver supported the following TFA amplifiers: TFA9894N1, TFA9894N2 and TFA9892N1.
Initialize TFA:
Create a tfa9xxx_config_t
, and set up all the necessary fields.
```C #include "tfa_config_tfa9894N2.h"
tfa9xxx_config_t tfa9xxxConfig = { .i2cConfig = {.codecI2CInstance = BOARD_CODEC_I2C_INSTANCE, .codecI2CSourceClock = 19000000U}, .slaveAddress = TFA9XXX_I2C_ADDR_0, .protocol = kTFA9XXX_BusI2S, .format = {.sampleRate = kTFA9XXX_AudioSampleRate48KHz, .bitWidth = kTFA9XXX_AudioBitWidth16bit}, .tfaContainer = tfa_container_bin, .deviceIndex = 0, }; codec_config_t boardCodecConfig = {.codecDevType = kCODEC_TFA9XXX, .codecDevConfig = &tfa9xxxConfig}; ``
.tfaContainer
should point to an hex array, here defined in tfa_config_tfa9894N2.h
. This header file included in the driver is for default usage. A customized tuning can be achieved using QuickStudio or TFAConfigurator, generating customized configuration header file..deviceIndex
should be 0 for a single TFA. For multiple TFAs use case, the .deviceIndex
should be from 0 to (TFA9XXX_DEV_NUM - 1
) for each tfa9xxx_config_t
. Call
CODEC_Init(codecHandle, &boardCodecConfig)
to initialize the TFA.
```C void BOARD_Codec_Init() { status_t rc; rc = CODEC_Init(&codecHandle, &boardCodecConfig); if(rc != kStatus_Success) usb_echo("Codec init failed!\n"); } ```
CODEC_Init()
for each TFA, every call with its own handle and config.CODEC_Init()
eventually calls TFA9XXX_Init()
, this is the actual function for TFA initialization.Set Volume:
Call
CODEC_SetVolume()
with volume between 0 ~ 100, which eventually passes volume to TFA9XXX_SetVolume()
.
```C CODEC_SetVolume(&codecHandle, kCODEC_SupportPlayChannelLeft0 | kCODEC_SupportPlayChannelRight0, volume); ```
For tuning using QuickStudio, it is suggested to set the volume to be 100 (maximum) before tuning started. Otherwise, changes during tuning might be too subtle to be heard.
Mute/unmute
Call
CODEC_SetMute()
to mute or unmute the TFA, which eventually calls TFA9XXX_SetMute()
. ```C void BOARD_SetCodecMuteUnmute(bool mute) { status_t rc; rc = CODEC_SetMute(&codecHandle, kCODEC_PlayChannelLeft0 | kCODEC_PlayChannelRight0, mute); if(rc != kStatus_Success) usb_echo("Codec set mute/unmute failed!\n"); } ``
function calls
TFA9XXX_SetMute()at the end to unmute the TFA. This is fine for single TFA usage. If multiple TFAs are used, you might want to unmute all of them at once instead of unmuting TFA one by one as
TFA9XXX_Init()is called respectively. In this case, you need to comment out the
TFA9XXX_SetMute()part in
TFA9XXX_Init()function, and do the unmute after all the
CODEC_Init()` calls.```C status_t TFA9XXX_SetPlayChannel(tfa9xxx_handle_t *handle, enum _codec_play_channel playChannel); ```
.tfaContainer
in tfa9xxx_config_t
. So you don't need to call this function. However, if required, calling this function allows overwriting I2S channel selection. This can be useful when the tuning is done, and you simply want to change the I2S channel.