![]() |
MCUXpresso SDK API Reference Manual
Rev 2.16.000
NXP Semiconductors
|
Data Structures | |
| struct | _tfa9xxx_audio_format |
| tfa9xxx audio format More... | |
| struct | tfa9xxx_config |
| Initialize structure of TFA9XXX. More... | |
| struct | _tfa9xxx_handle |
| tfa9xxx codec handler Application should allocate a buffer with TFA9XXX_HANDLE_SIZE for handle definition, such as uint8_t tfa9xxxHandleBuffer[TFA9XXX_HANDLE_SIZE]; tfa9xxx_handle_t *tfa9xxxHandle = tfa9xxxHandleBuffer; More... | |
Macros | |
| #define | TFA9XXX_I2C_HANDLER_SIZE (CODEC_I2C_MASTER_HANDLER_SIZE) |
| tfa9xxx handle size | |
| #define | TFA9XXX_I2C_BAUDRATE (400000U) |
| TFA9XXX_ I2C baudrate. | |
Typedefs | |
| typedef enum _tfa9xxx_protocol | tfa9xxx_protocol_t |
| The audio data transfer protocol choice. More... | |
|
typedef struct _tfa9xxx_audio_format | tfa9xxx_audio_format_t |
| tfa9xxx audio format | |
| typedef struct tfa2_device | tfa9xxx_device_t |
| tfa9xxx device | |
| typedef struct tfa9xxx_config | tfa9xxx_config_t |
| Initialize structure of TFA9XXX. | |
| typedef struct _tfa9xxx_handle | tfa9xxx_handle_t |
| tfa9xxx codec handler Application should allocate a buffer with TFA9XXX_HANDLE_SIZE for handle definition, such as uint8_t tfa9xxxHandleBuffer[TFA9XXX_HANDLE_SIZE]; tfa9xxx_handle_t *tfa9xxxHandle = tfa9xxxHandleBuffer; | |
Enumerations | |
| enum | _tfa9xxx_protocol { kTFA9XXX_BusI2S = 0 } |
| The audio data transfer protocol choice. More... | |
| enum | _tfa9xxx_sample_rate { kTFA9XXX_AudioSampleRate48KHz = 48000U } |
| audio sample rate definition, more sample rates can be supported in the future More... | |
| enum | _tfa9xxx_audio_bit_width { kTFA9XXX_AudioBitWidth16bit = 16U } |
| audio bit width, more bit width can be supported in the future More... | |
| enum | _tfa98xxx_play_channel { kTFA9XXX_PlayChannelLeft0 = 1U, kTFA9XXX_PlayChannelRight0 = 2U } |
| play channel More... | |
Functions | |
| status_t | TFA9XXX_Init (tfa9xxx_handle_t *handle, tfa9xxx_config_t *tfa9xxxConfig) |
| Initialize the TFA, put the TFA to operating state, allocate memory side. More... | |
| status_t | TFA9XXX_Deinit (tfa9xxx_handle_t *handle) |
| Deinitialize the TFA, put the TFA to powerdown state. More... | |
| status_t | TFA9XXX_SetMute (tfa9xxx_handle_t *handle, bool isMute) |
| Mute/Unmute the TFA. More... | |
| status_t | TFA9XXX_ConfigDataFormat (tfa9xxx_handle_t *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth) |
| Configure the TFA based on I2S format. More... | |
| status_t | TFA9XXX_SetVolume (tfa9xxx_handle_t *handle, uint32_t volume) |
| Set the volume level. More... | |
| status_t | TFA9XXX_SetPlayChannel (tfa9xxx_handle_t *handle, uint32_t playChannel) |
| Set the audio channel for a speaker. More... | |
| status_t | TFA9XXX_Start (tfa9xxx_handle_t *handle) |
| Start the TFA. More... | |
| status_t | TFA9XXX_Stop (tfa9xxx_handle_t *handle) |
| Stop the TFA. More... | |
| status_t | TFA9XXX_Reset (tfa9xxx_handle_t *handle) |
| Reset the TFA. More... | |
| status_t | TFA9XXX_CheckCalibrationStatus (tfa9xxx_handle_t *handle, bool *isTFACalibrated) |
| check if TFA is calibrated. More... | |
| status_t | TFA9XXX_CalibrateSpeakerBoost (tfa9xxx_handle_t *handle) |
| Start Speakerboost Calibration. More... | |
| status_t | TFA9XXX_HardcodeCalibrationValue (tfa9xxx_handle_t *handle) |
| Hardcode calibration value for DSP usage instead of triggering calibration. More... | |
| status_t | TFA9XXX_GetStatus (tfa9xxx_handle_t *handle) |
| Get the status of a running TFA. More... | |
| status_t | TFA9XXX_ConvertErrorCode (int32_t rc) |
| Convert the return check value from TFA driver to predefined error code. More... | |
Driver version | |
| #define | FSL_TFA9XXX_DRIVER_VERSION (MAKE_VERSION(8, 1, 2)) |
| TFA9XXX driver version 8.1.2. More... | |
Initialize TFA:
Create a tfa9xxx_config_t, and set up all the necessary fields.
#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};
tfa9xxx_config_t..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.
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().
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().
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");
}
TFA9XXX_Init() 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.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.| struct _tfa9xxx_audio_format |
Data Fields | |
| enum _tfa9xxx_sample_rate | sampleRate |
| sample rate | |
| enum _tfa9xxx_audio_bit_width | bitWidth |
| bit width | |
| struct tfa9xxx_config |
Data Fields | |
| tfa9xxx_protocol_t | protocol |
| Audio transfer protocol. | |
| tfa9xxx_audio_format_t | format |
| Audio format. | |
| uint8_t | slaveAddress |
| tfa9xxx device address | |
| codec_i2c_config_t | i2cConfig |
| i2c configuration | |
| uint8_t * | tfaContainer |
| tfa container array | |
| uint8_t | deviceIndex |
| tfa device index, starting from 0, up to TFA9XXX_DEV_NUM - 1 | |
| struct _tfa9xxx_handle |
Data Fields | |
| tfa9xxx_config_t * | config |
| tfa9xxx config pointer | |
| uint8_t | i2cHandle [TFA9XXX_I2C_HANDLER_SIZE] |
| i2c handle | |
| #define FSL_TFA9XXX_DRIVER_VERSION (MAKE_VERSION(8, 1, 2)) |
| typedef enum _tfa9xxx_protocol tfa9xxx_protocol_t |
TFA9XXX only supports I2S format.
| enum _tfa9xxx_protocol |
| enum _tfa9xxx_sample_rate |
| status_t TFA9XXX_Init | ( | tfa9xxx_handle_t * | handle, |
| tfa9xxx_config_t * | tfa9xxxConfig | ||
| ) |
| handle | TFA9XXX handle structure. |
| tfa9xxxConfig | TFA9XXX configuration structure. |
| status_t TFA9XXX_Deinit | ( | tfa9xxx_handle_t * | handle | ) |
| handle | TFA9XXX handle structure. |
| status_t TFA9XXX_SetMute | ( | tfa9xxx_handle_t * | handle, |
| bool | isMute | ||
| ) |
This function has dependency on internal structure, it has to be called after TFA9XXX_CreatePlatform();
| handle | TFA9XXX handle structure. |
| isMute | true is mute, false is unmute.. |
| status_t TFA9XXX_ConfigDataFormat | ( | tfa9xxx_handle_t * | handle, |
| uint32_t | mclk, | ||
| uint32_t | sampleRate, | ||
| uint32_t | bitWidth | ||
| ) |
Assuming TFA_Init() is already called by calling CODEC_Init(), the TFA will be in operating state. So before calling TFA_SetFormat(), the TFA needs to be in powerdown state by calling TFA_Stop().
| handle | TFA9XXX handle structure. |
| mclk | The mclk. |
| sampleRate | The sample rate. |
| bitWidth | The bit width. |
| status_t TFA9XXX_SetVolume | ( | tfa9xxx_handle_t * | handle, |
| uint32_t | volume | ||
| ) |
This function has dependency on internal structure, it has to be called after TFA9XXX_CreatePlatform();
| handle | TFA9XXX handle structure. |
| volume | volume volume value, support 0 ~ 100, 0 is mute, 100 is the maximum volume value. |
| status_t TFA9XXX_SetPlayChannel | ( | tfa9xxx_handle_t * | handle, |
| uint32_t | playChannel | ||
| ) |
By default, I2S channel is configured by the .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.
This function has dependency on internal structure, it has to be called after TFA9XXX_CreatePlatform();
| handle | TFA9XXX handle structure. |
| playChannel | _codec_play_channel play channel, available values are kCODEC_PlayChannelSpeakerLeft, kCODEC_PlayChannelSpeakerRight, kCODEC_PlayChannelSpeakerLeft | kCODEC_PlayChannelSpeakerRight. |
| status_t TFA9XXX_Start | ( | tfa9xxx_handle_t * | handle | ) |
Start device will initialize if the device is in cold state if already warm then only clocks will be started.
This function has dependency on internal structure, it has to be called after TFA9XXX_CreatePlatform();
| handle | The TFA codec handle. |
| status_t TFA9XXX_Stop | ( | tfa9xxx_handle_t * | handle | ) |
Stop will put the TFA in powerdown/standby mode, the next time TFA start will be a warm start.
This function has dependency on internal structure, it has to be called after TFA9XXX_CreatePlatform();
| handle | The TFA9XXX handle structure. |
| status_t TFA9XXX_Reset | ( | tfa9xxx_handle_t * | handle | ) |
Reset will put the in powerdown/standby mode, the next time TFA start will be a cold start.
This function has dependency on internal structure, it has to be called after TFA9XXX_CreatePlatform();
| handle | The TFA9XXX handle structure. |
| status_t TFA9XXX_CheckCalibrationStatus | ( | tfa9xxx_handle_t * | handle, |
| bool * | isTFACalibrated | ||
| ) |
This function has dependency on internal structure, it has to be called after TFA9XXX_CreatePlatform();
| handle | The TFA9XXX handle structure. |
| isTFACalibrated | This value stores if TFA is calibrated. |
| status_t TFA9XXX_CalibrateSpeakerBoost | ( | tfa9xxx_handle_t * | handle | ) |
The calibration will measure speaker impedance, and calculate the speaker impedance at 25 degree. This value will be used to estimate the real-time temperature.
This function has dependency on internal structure, it has to be called after TFA9XXX_CreatePlatform();
| handle | The TFA codec handle. |
| status_t TFA9XXX_HardcodeCalibrationValue | ( | tfa9xxx_handle_t * | handle | ) |
This function has dependency on internal structure, it has to be called after TFA9XXX_CreatePlatform();
| handle | TFA9XXX handle structure. |
| status_t TFA9XXX_GetStatus | ( | tfa9xxx_handle_t * | handle | ) |
This function has dependency on internal structure, it has to be called after TFA9XXX_CreatePlatform();
| handle | The TFA9XXX handle structure. |
| status_t TFA9XXX_ConvertErrorCode | ( | int32_t | rc | ) |
| rc | Return check value from TFA driver. |