Software Driver for the TPA6130A2 Audio Amplifier.
The TPA6130A2 is connected to the AVR UC3 through the ABDAC hardware module for the data stream and through the TWI hardware module for the control stream.
Macros | |
#define | TPA6130_MODE_MONO 1 |
#define | TPA6130_MODE_STEREO 0 |
#define | TPA6130_SIG_DIFF 0 |
#define | TPA6130_SIG_POS 1 |
#define | TPA6130_TWI_ADDRESS 0x60 |
Functions | |
void | tpa6130_dac_decrease_volume (void) |
Decreases the output volume of the DACs. More... | |
void | tpa6130_dac_flush (void) |
Flushes the sample buffer being output to the DACs. More... | |
uint8_t | tpa6130_dac_get_volume (void) |
Returns the current volume of the DAC. More... | |
void | tpa6130_dac_increase_volume (void) |
Increases the output volume of the DACs. More... | |
bool | tpa6130_dac_is_volume_boosted (void) |
Returns the state of the boost mode of the DAC. More... | |
bool | tpa6130_dac_is_volume_muted (void) |
Returns the state of the mute mode of the DAC. More... | |
void | tpa6130_dac_mute (bool mute) |
No more audio if input is true. More... | |
bool | tpa6130_dac_output (void *sample_buffer, size_t sample_length) |
Outputs a sample buffer to the DACs. More... | |
void | tpa6130_dac_set_volume (uint8_t volume) |
Set the volume of the DAC. More... | |
void | tpa6130_dac_setup (uint32_t sample_rate_hz, uint8_t num_channels, uint8_t bits_per_sample, bool swap_channels, void(*callback)(uint32_t arg), uint32_t callback_opt, uint32_t pba_hz) |
Sets the DACs up with new settings. More... | |
void | tpa6130_dac_start (uint32_t sample_rate_hz, uint8_t num_channels, uint8_t bits_per_sample, bool swap_channels, void(*callback)(uint32_t arg), uint32_t callback_opt, uint32_t pba_hz) |
Starts the ABDAC. More... | |
void | tpa6130_dac_stop (void) |
Stops the DACs. More... | |
int8_t | tpa6130_get_volume (void) |
Gets the current volume settings. More... | |
int8_t | tpa6130_init (void) |
Probes and initializes the amplifier. Probes the TWI bus for the amplifier by using the slave address specified in the configuration (TPA6130_TWI_ADDRESS). If the device responds with an ACK the version register is read out and compared to the valid versions (TPA6130_VERSION). Last step is to set volume to 0, unmute and set the configuration specified in the conf_tpa6130.h file (stereo, mono ..). More... | |
void | tpa6130_powerup (void) |
Powers up the amplifier from low power mode. This is the software low power mode described in the datasheet. More... | |
void | tpa6130_set_volume (int8_t volume) |
Sets the volume of the amplifier. Valid values are between 0 (min -59dB) and 63 (max 4dB) although the function takes care of any values higher than that by setting it to max. More... | |
void | tpa6130_shutdown (void) |
Shuts down the amplifier and sets it into low power mode. This is the software low power mode described in the datasheet. More... | |
Volume Control | |
#define | TPA6130_VOL_MIN ((int8_t)( 0)) |
#define | TPA6130_VOL_MAX ((int8_t)( 63)) |
#define TPA6130_MODE_MONO 1 |
#define TPA6130_MODE_STEREO 0 |
#define TPA6130_SIG_DIFF 0 |
#define TPA6130_SIG_POS 1 |
#define TPA6130_TWI_ADDRESS 0x60 |
Referenced by init_twi(), tpa6130_init(), tpa6130_read_data(), and tpa6130_write_data().
#define TPA6130_VOL_MAX ((int8_t)( 63)) |
Referenced by tpa6130_dac_get_volume(), and tpa6130_set_volume().
#define TPA6130_VOL_MIN ((int8_t)( 0)) |
Referenced by tpa6130_dac_decrease_volume(), tpa6130_dac_increase_volume(), and tpa6130_set_volume().
void tpa6130_dac_decrease_volume | ( | void | ) |
Decreases the output volume of the DACs.
Decreases the output volume of the DACs.
Stops at the lowest possible volume.
References MUTE_L, MUTE_R, tpa6130_get_volume(), tpa6130_set_volume(), TPA6130_VOL_MIN, and volume.
void tpa6130_dac_flush | ( | void | ) |
Flushes the sample buffer being output to the DACs.
Flushes the sample buffer being output to the DACs.
References pdca_disable(), pdca_disable_interrupt_reload_counter_zero(), pdca_disable_interrupt_transfer_complete(), pdca_enable(), pdca_load_channel(), pdca_reload_channel(), and TPA6130_ABDAC_PDCA_CHANNEL.
uint8_t tpa6130_dac_get_volume | ( | void | ) |
Returns the current volume of the DAC.
Returns the current volume of the DAC.
References MUTE_L, MUTE_R, tpa6130_get_volume(), and TPA6130_VOL_MAX.
void tpa6130_dac_increase_volume | ( | void | ) |
Increases the output volume of the DACs.
Increases the output volume of the DACs.
References MUTE_L, MUTE_R, tpa6130_get_volume(), tpa6130_set_volume(), TPA6130_VOL_MIN, and volume.
bool tpa6130_dac_is_volume_boosted | ( | void | ) |
Returns the state of the boost mode of the DAC.
bool tpa6130_dac_is_volume_muted | ( | void | ) |
Returns the state of the mute mode of the DAC.
void tpa6130_dac_mute | ( | bool | mute | ) |
No more audio if input is true.
References MUTE_L, MUTE_R, pdca_disable_interrupt_reload_counter_zero(), pdca_enable_interrupt_reload_counter_zero(), pdca_get_transfer_status(), PDCA_TRANSFER_COMPLETE, TPA6130_ABDAC_PDCA_CHANNEL, tpa6130_get_volume(), tpa6130_output_param, TPA6130_VOLUME_AND_MUTE, tpa6130_write_data(), and volume.
bool tpa6130_dac_output | ( | void * | sample_buffer, |
size_t | sample_length | ||
) |
Outputs a sample buffer to the DACs.
Outputs a sample buffer to the DACs.
References AUDIO_DAC_OUT_OF_SAMPLE_CB, AUDIO_DAC_RELOAD_CB, pdca_enable_interrupt_reload_counter_zero(), pdca_enable_interrupt_transfer_complete(), pdca_get_transfer_status(), pdca_reload_channel(), PDCA_TRANSFER_COUNTER_RELOAD_IS_ZERO, TPA6130_ABDAC_PDCA_CHANNEL, and tpa6130_output_param.
void tpa6130_dac_set_volume | ( | uint8_t | volume | ) |
Set the volume of the DAC.
References tpa6130_set_volume().
void tpa6130_dac_setup | ( | uint32_t | sample_rate_hz, |
uint8_t | num_channels, | ||
uint8_t | bits_per_sample, | ||
bool | swap_channels, | ||
void(*)(uint32_t arg) | callback, | ||
uint32_t | callback_opt, | ||
uint32_t | pba_hz | ||
) |
Sets the DACs up with new settings.
References abdac_enable(), abdac_set_dac_hz(), abdac_set_dac_sample_rate(), abdac_swap_channels(), pdca_channel_options_t::addr, callback, callback_opt, num_channels, pdca_enable(), pdca_init_channel(), PDCA_TRANSFER_SIZE_WORD, TPA6130_ABDAC, TPA6130_ABDAC_GCLK_INPUT_HZ, TPA6130_ABDAC_PDCA_CHANNEL, TPA6130_ABDAC_PDCA_PID, tpa6130_init(), and tpa6130_output_param.
Referenced by tpa6130_dac_start().
void tpa6130_dac_start | ( | uint32_t | sample_rate_hz, |
uint8_t | num_channels, | ||
uint8_t | bits_per_sample, | ||
bool | swap_channels, | ||
void(*)(uint32_t arg) | callback, | ||
uint32_t | callback_opt, | ||
uint32_t | pba_hz | ||
) |
Starts the ABDAC.
sample_rate_hz | Sample rate for the ABDAC. |
num_channels | number of channel |
bits_per_sample | number of bit per sample |
swap_channels | true -> swap the channels |
callback | Provide a functions that handles callback. |
callback_opt | Callback flag |
pba_hz | Speed of the peripheral bus A. |
References callback, gpio_enable_module(), irq_register_handler, TPA6130_ABDAC_PDCA_IRQ, tpa6130_dac_setup(), tpa6130_dac_stop(), and tpa6130_powerup().
void tpa6130_dac_stop | ( | void | ) |
Stops the DACs.
Stops the DACs.
References abdac_disable(), gpio_enable_gpio(), pdca_disable(), TPA6130_ABDAC, TPA6130_ABDAC_PDCA_CHANNEL, tpa6130_output_param, and tpa6130_shutdown().
Referenced by tpa6130_dac_start().
int8_t tpa6130_get_volume | ( | void | ) |
Gets the current volume settings.
References tpa6130_read_data(), TPA6130_VOLUME_AND_MUTE, and TWI_READ_SR.
Referenced by tpa6130_dac_decrease_volume(), tpa6130_dac_get_volume(), tpa6130_dac_increase_volume(), and tpa6130_dac_mute().
int8_t tpa6130_init | ( | void | ) |
Probes and initializes the amplifier. Probes the TWI bus for the amplifier by using the slave address specified in the configuration (TPA6130_TWI_ADDRESS). If the device responds with an ACK the version register is read out and compared to the valid versions (TPA6130_VERSION). Last step is to set volume to 0, unmute and set the configuration specified in the conf_tpa6130.h file (stereo, mono ..).
References HP_EN_L, HP_EN_R, TPA6130_CONTROL, TPA6130_I2C_ADDRESS_VERSION, TPA6130_MODE, tpa6130_read_data(), tpa6130_shadow_regs, TPA6130_TWI, TPA6130_TWI_ADDRESS, TPA6130_VOLUME_AND_MUTE, tpa6130_write_data(), TWI_NO_CHIP_FOUND, twi_probe(), TWI_READ_HW, TWI_SUCCESS, and VERSION.
Referenced by tpa6130_dac_setup().
void tpa6130_powerup | ( | void | ) |
Powers up the amplifier from low power mode. This is the software low power mode described in the datasheet.
Powers up the amplifier from low power mode. This is the software low power mode described in the datasheet.
References SW_SHUTDOWN, TPA6130_CONTROL, tpa6130_read_data(), tpa6130_write_data(), and TWI_READ_HW.
Referenced by tpa6130_dac_start().
void tpa6130_set_volume | ( | int8_t | volume | ) |
Sets the volume of the amplifier. Valid values are between 0 (min -59dB) and 63 (max 4dB) although the function takes care of any values higher than that by setting it to max.
Sets the volume of the amplifier. Valid values are between 0 (min -59dB) and 63 (max 4dB) although the function takes care of any values higher than that by setting it to max.
References MUTE_L, MUTE_R, TPA6130_VOL_MAX, TPA6130_VOL_MIN, TPA6130_VOLUME_AND_MUTE, tpa6130_write_data(), and volume.
Referenced by tpa6130_dac_decrease_volume(), tpa6130_dac_increase_volume(), and tpa6130_dac_set_volume().
void tpa6130_shutdown | ( | void | ) |
Shuts down the amplifier and sets it into low power mode. This is the software low power mode described in the datasheet.
References SW_SHUTDOWN, TPA6130_CONTROL, tpa6130_read_data(), tpa6130_write_data(), and TWI_READ_HW.
Referenced by tpa6130_dac_stop().