README.md
1@ingroup tfa9xxx
2
3The **tfa9xxx** driver supported the following TFA amplifiers: TFA9894N1, TFA9894N2 and TFA9892N1.
4
5### Typical use cases:
6
71. Initialize TFA:
8
9 Create a `tfa9xxx_config_t`, and set up all the necessary fields.
10
11 #include "tfa_config_tfa9894N2.h"
12 tfa9xxx_config_t tfa9xxxConfig = {
13 .i2cConfig = {.codecI2CInstance = BOARD_CODEC_I2C_INSTANCE, .codecI2CSourceClock = 19000000U},
14 .slaveAddress = TFA9XXX_I2C_ADDR_0,
15 .protocol = kTFA9XXX_BusI2S,
16 .format = {.sampleRate = kTFA9XXX_AudioSampleRate48KHz, .bitWidth = kTFA9XXX_AudioBitWidth16bit},
17 .tfaContainer = tfa_container_bin,
18 .deviceIndex = 0,
19 };
20 codec_config_t boardCodecConfig = {.codecDevType = kCODEC_TFA9XXX, .codecDevConfig = &tfa9xxxConfig};
21
22 - If you use multiple TFAs, each TFA requires a `tfa9xxx_config_t`.
23
24 - The `.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.
25
26 - The `.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`.
27
28 - The slave address of TFA is defined by the voltage level on pin ADS2 and ADS1. Therefore 4 possible slave addresses are: 0x34, 0x35, 0x36 and 0x37.
29
30 Call `CODEC_Init(codecHandle, &boardCodecConfig)` to initialize the TFA.
31
32 void BOARD_Codec_Init()
33 {
34 status_t rc;
35 rc = CODEC_Init(&codecHandle, &boardCodecConfig);
36 if(rc != kStatus_Success)
37 usb_echo("Codec init failed!\n");
38 }
39
40 - If you use multiple TFAs, you need to call `CODEC_Init()` for each TFA, every call with its own handle and config.
41
42 - `CODEC_Init()` eventually calls `TFA9XXX_Init()`, this is the actual function for TFA initialization.
43
442. Set Volume:
45
46 Call `CODEC_SetVolume()` with volume between 0 ~ 100, which eventually passes volume to `TFA9XXX_SetVolume()`.
47
48 CODEC_SetVolume(&codecHandle, kCODEC_SupportPlayChannelLeft0 | kCODEC_SupportPlayChannelRight0, volume);
49
50 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.
51
52
533. Mute/unmute
54
55 Call `CODEC_SetMute()` to mute or unmute the TFA, which eventually calls `TFA9XXX_SetMute()`.
56
57 void BOARD_SetCodecMuteUnmute(bool mute)
58 {
59 status_t rc;
60 rc = CODEC_SetMute(&codecHandle, kCODEC_PlayChannelLeft0 | kCODEC_PlayChannelRight0, mute);
61 if(rc != kStatus_Success)
62 usb_echo("Codec set mute/unmute failed!\n");
63 }
64
65 - The `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.
66
67## Special functions
68
69 status_t TFA9XXX_SetPlayChannel(tfa9xxx_handle_t *handle, enum _codec_play_channel playChannel);
70
71- 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.
72
73- A typical stereo setup is to play left channel for left speaker and right channel for right speaker. A typical mono setup is play both channel for a single speaker.
74
75