tpa6130_with_cs2200.c File Reference


Detailed Description

TPA6130 amplifier driver.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file tpa6130_with_cs2200.c.

#include "pdca.h"
#include "abdac.h"
#include "gpio.h"
#include "intc.h"
#include "board.h"
#include "tpa6130.h"
#include "conf_tpa6130.h"
#include "audio.h"
#include "cs2200.h"
#include "twim.h"
#include "conf_audio_player.h"

Go to the source code of this file.

Defines

#define BRIDGE_TIED_LOAD   0x20
#define DUAL_MONO_HP   0x10
#define HIZ_L   0x80
#define HIZ_R   0x40
#define HP_EN_L   0x80
#define HP_EN_R   0x40
#define MUTE_L   0x80
#define MUTE_R   0x40
#define STEREO_HP   0x00
#define SW_SHUTDOWN   0x01
#define THERMAL   0x02
#define TPA6130_CONTROL   0x1
#define TPA6130_CONTROL_DEFAULT   0x00
#define TPA6130_I2C_ADDRESS_VERSION   0x4
#define TPA6130_I2C_ADDRESS_VERSION_DEFAULT   0x02
#define TPA6130_MAX_VOLUME   0x3F
#define TPA6130_OUTPUT_IMPEDANCE   0x3
#define TPA6130_OUTPUT_IMPEDANCE_DEFAULT   0x00
#define TPA6130_VOLUME_AND_MUTE   0x2
#define TPA6130_VOLUME_AND_MUTE_DEFAULT   0x0F
#define TWI_READ_HW   0
#define TWI_READ_SR   1
#define VERSION   0x02

Functions

static void tpa6130_abdac_tx_pdca_int_handler (void)
void tpa6130_dac_decrease_volume (void)
 Decreases the output volume of the amplifier by one step.
void tpa6130_dac_flush (void)
 Flushes the sample buffer being output to the ABDAC.
U8 tpa6130_dac_get_volume (void)
 Returns the current volume of the DAC. The volume is in the range 0 - 255.
void tpa6130_dac_increase_volume (void)
 Increases the output volume of the amplifier by one step. Stops at the maximum volume and thus does not wrap to the lowest 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.
Bool tpa6130_dac_output (void *sample_buffer, size_t sample_length)
 Outputs a sample buffer to the DACs. The input requires a sample buffer that consists of words (32-bit) which contain two (16-bit) samples, one for each channel.
void tpa6130_dac_set_volume (U8 volume)
 Set the volume of the DAC.
void tpa6130_dac_setup (U32 sample_rate_hz, U8 num_channels, U8 bits_per_sample, Bool swap_channels, void(*callback)(U32 arg), U32 callback_opt, U32 pba_hz)
 Sets the DACs up with new settings.
void tpa6130_dac_start (U32 sample_rate_hz, U8 num_channels, U8 bits_per_sample, Bool swap_channels, void(*callback)(U32 arg), U32 callback_opt, U32 pba_hz)
 Starts the ABDAC.
void tpa6130_dac_stop (void)
 Stops the ABDAC and puts the amplifier in low power mode. Additionally it sets all used pins to the GPIO state. The counter part of this function is tpa6130_dac_start(...).
S8 tpa6130_get_volume (void)
 Gets the current volume settings.
S8 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 ..).
void tpa6130_powerup (void)
 Powers up the amplifier from low power mode.
static U8 tpa6130_read_data (U8 reg, Bool shadow)
 Reads data from a register. The shadow parameter is used to specify if the data should be read from a driver internal register shadowing or directly from the device.
void tpa6130_set_volume (S8 volume)
 Sets the volume of the amplifier. Valid values are between 0 (min -59dB) and 63 (max 4dB) altough the function takes care of any values higher than that by setting it to max. A volume of 0 will mute both channels. Any other value will unmute them.
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.
static void tpa6130_write_data (U8 reg, U8 data)
 Writes data to a register.

Variables

volatile avr32_pm_t * pm = &AVR32_PM
static const gpio_map_t TPA6130_ABDAC_GPIO_MAP
struct {
   void(*   callback )(U32 arg)
   U32   callback_opt
   U8   num_channels
tpa6130_output_param
struct {
   U8   control
   U8   i2c_address_version
   U8   output_impedance
   U8   volume_and_mute
tpa6130_shadow_regs
U32 usb_stream_resync_frequency
 CS2200 out frequency.


Define Documentation

#define BRIDGE_TIED_LOAD   0x20

Definition at line 87 of file tpa6130_with_cs2200.c.

#define DUAL_MONO_HP   0x10

Definition at line 86 of file tpa6130_with_cs2200.c.

#define HIZ_L   0x80

Definition at line 94 of file tpa6130_with_cs2200.c.

#define HIZ_R   0x40

Definition at line 95 of file tpa6130_with_cs2200.c.

#define HP_EN_L   0x80

Definition at line 83 of file tpa6130_with_cs2200.c.

#define HP_EN_R   0x40

Definition at line 84 of file tpa6130_with_cs2200.c.

#define MUTE_L   0x80

Definition at line 91 of file tpa6130_with_cs2200.c.

#define MUTE_R   0x40

Definition at line 92 of file tpa6130_with_cs2200.c.

#define STEREO_HP   0x00

Definition at line 85 of file tpa6130_with_cs2200.c.

#define SW_SHUTDOWN   0x01

Definition at line 88 of file tpa6130_with_cs2200.c.

#define THERMAL   0x02

Definition at line 89 of file tpa6130_with_cs2200.c.

#define TPA6130_CONTROL   0x1

Definition at line 70 of file tpa6130_with_cs2200.c.

#define TPA6130_CONTROL_DEFAULT   0x00

Definition at line 76 of file tpa6130_with_cs2200.c.

#define TPA6130_I2C_ADDRESS_VERSION   0x4

Definition at line 73 of file tpa6130_with_cs2200.c.

#define TPA6130_I2C_ADDRESS_VERSION_DEFAULT   0x02

Definition at line 80 of file tpa6130_with_cs2200.c.

#define TPA6130_MAX_VOLUME   0x3F

Definition at line 102 of file tpa6130_with_cs2200.c.

#define TPA6130_OUTPUT_IMPEDANCE   0x3

Definition at line 72 of file tpa6130_with_cs2200.c.

#define TPA6130_OUTPUT_IMPEDANCE_DEFAULT   0x00

Definition at line 79 of file tpa6130_with_cs2200.c.

#define TPA6130_VOLUME_AND_MUTE   0x2

Definition at line 71 of file tpa6130_with_cs2200.c.

#define TPA6130_VOLUME_AND_MUTE_DEFAULT   0x0F

Definition at line 78 of file tpa6130_with_cs2200.c.

#define TWI_READ_HW   0

Definition at line 106 of file tpa6130_with_cs2200.c.

#define TWI_READ_SR   1

Definition at line 108 of file tpa6130_with_cs2200.c.

#define VERSION   0x02

Definition at line 97 of file tpa6130_with_cs2200.c.


Function Documentation

static void tpa6130_abdac_tx_pdca_int_handler ( void   )  [static]

Definition at line 208 of file tpa6130_with_cs2200.c.

References tpa6130_output_param.

00209 {
00210   if (pdca_get_transfer_status(TPA6130_ABDAC_PDCA_CHANNEL) & PDCA_TRANSFER_COMPLETE)
00211   {
00212     pdca_disable_interrupt_transfer_complete(TPA6130_ABDAC_PDCA_CHANNEL);
00213     if (tpa6130_output_param.callback_opt & AUDIO_DAC_OUT_OF_SAMPLE_CB)
00214       tpa6130_output_param.callback(AUDIO_DAC_OUT_OF_SAMPLE_CB);
00215   }
00216 
00217   if (pdca_get_transfer_status(TPA6130_ABDAC_PDCA_CHANNEL) & PDCA_TRANSFER_COUNTER_RELOAD_IS_ZERO)
00218   {
00219     pdca_disable_interrupt_reload_counter_zero(TPA6130_ABDAC_PDCA_CHANNEL);
00220     if (tpa6130_output_param.callback_opt & AUDIO_DAC_RELOAD_CB)
00221       tpa6130_output_param.callback(AUDIO_DAC_RELOAD_CB);
00222   }
00223 }

void tpa6130_dac_decrease_volume ( void   ) 

Decreases the output volume of the amplifier by one step.

Decreases the output volume of the DACs.

Stops at the lowest possible volume.

Definition at line 673 of file tpa6130_with_cs2200.c.

References MUTE_L, MUTE_R, tpa6130_get_volume(), tpa6130_set_volume(), and TPA6130_VOL_MIN.

00674 {
00675   S8 volume = tpa6130_get_volume()& (~(MUTE_L | MUTE_R));;
00676   if( volume > TPA6130_VOL_MIN )
00677     --volume;
00678   tpa6130_set_volume( volume );
00679 }

void tpa6130_dac_flush ( void   ) 

Flushes the sample buffer being output to the ABDAC.

Flushes the sample buffer being output to the DACs.

Definition at line 683 of file tpa6130_with_cs2200.c.

00684 {
00685   pdca_disable_interrupt_transfer_complete(TPA6130_ABDAC_PDCA_CHANNEL);
00686   pdca_disable_interrupt_reload_counter_zero(TPA6130_ABDAC_PDCA_CHANNEL);
00687 
00688   /*TODO Do we really want to wait here? Or do we just don't care when
00689    * the buffer is empty/flushed */
00690   //while(!pdca_get_transfer_status(TPA6130_ABDAC_PDCA_CHANNEL) &
00691   //  PDCA_TRANSFER_COMPLETE);
00692   pdca_disable       (TPA6130_ABDAC_PDCA_CHANNEL       );
00693   pdca_load_channel  (TPA6130_ABDAC_PDCA_CHANNEL,0x0, 0);
00694   pdca_reload_channel(TPA6130_ABDAC_PDCA_CHANNEL,0x0, 0);
00695   pdca_enable        (TPA6130_ABDAC_PDCA_CHANNEL       );
00696 }

U8 tpa6130_dac_get_volume ( void   ) 

Returns the current volume of the DAC. The volume is in the range 0 - 255.

Returns the current volume of the DAC.

Definition at line 639 of file tpa6130_with_cs2200.c.

References MUTE_L, MUTE_R, tpa6130_get_volume(), and TPA6130_VOL_MAX.

00640 {
00641  // return volume is num display step for LCD
00642  //  volume scale is between 10 and 245
00643  // 0 is -100db
00644  // 245 is max volume
00645   U16 raw_volume;
00646   raw_volume = (tpa6130_get_volume() & (~(MUTE_L | MUTE_R)));
00647   return (U8) ((raw_volume * 255) / TPA6130_VOL_MAX);
00648 }

void tpa6130_dac_increase_volume ( void   ) 

Increases the output volume of the amplifier by one step. Stops at the maximum volume and thus does not wrap to the lowest volume.

Increases the output volume of the DACs.

Definition at line 661 of file tpa6130_with_cs2200.c.

References MUTE_L, MUTE_R, tpa6130_get_volume(), tpa6130_set_volume(), and TPA6130_VOL_MIN.

00662 {
00663   S8 volume = tpa6130_get_volume()& (~(MUTE_L | MUTE_R));
00664   if( volume < TPA6130_VOL_MIN )
00665     volume = TPA6130_VOL_MIN;
00666   tpa6130_set_volume(volume+1);
00667 }

Bool tpa6130_dac_is_volume_boosted ( void   ) 

Returns the state of the boost mode of the DAC.

Note:
The DAC must have been started beforehand.

Definition at line 631 of file tpa6130_with_cs2200.c.

00632 {
00633   return FALSE;
00634 }

Bool tpa6130_dac_is_volume_muted ( void   ) 

Returns the state of the mute mode of the DAC.

Note:
The DAC must have been started beforehand.

Definition at line 574 of file tpa6130_with_cs2200.c.

00575 {
00576   return FALSE;
00577 }

void tpa6130_dac_mute ( Bool  mute  ) 

No more audio if input is true.

Definition at line 579 of file tpa6130_with_cs2200.c.

References MUTE_L, MUTE_R, tpa6130_get_volume(), tpa6130_output_param, TPA6130_VOLUME_AND_MUTE, and tpa6130_write_data().

00580 {
00581   // //1st Version Mute Audio for Play/Pause
00582 /*  int volume=tpa6130_get_volume();
00583   if(mute==TRUE) {
00584      //Mute volume
00585      volume= volume|MUTE_L|MUTE_R;
00586   }
00587   else {
00588      //Unmute volume
00589      volume= volume&(~(MUTE_L|MUTE_R));
00590  
00591   }
00592  tpa6130_write_data(TPA6130_VOLUME_AND_MUTE,volume);
00593 */
00594   //2n Version Stop PDCA >> No lost of audio when pause
00595 /*  if(mute==TRUE) {
00596     pdca_disable(TPA6130_ABDAC_PDCA_CHANNEL);
00597   }
00598   else {
00599     pdca_enable(TPA6130_ABDAC_PDCA_CHANNEL);
00600   }
00601 */
00602 
00603   // 3rd Version wait until the current buffers are empty and disable the interrutps
00604   S8 volume = tpa6130_get_volume();
00605   if (mute)
00606   {
00607     U32 save_dac_reload_callback_opt;
00608 
00609     // Mute the audio stream
00610     volume = volume | MUTE_L | MUTE_R;
00611     tpa6130_write_data(TPA6130_VOLUME_AND_MUTE, volume);
00612     // Disable the reload channel of the interrupt
00613     save_dac_reload_callback_opt = tpa6130_output_param.callback_opt;
00614     tpa6130_output_param.callback_opt = 0;
00615     // Disable the reload interruption and wait until the transfer is complete
00616     pdca_disable_interrupt_reload_counter_zero(TPA6130_ABDAC_PDCA_CHANNEL);
00617     while (!(pdca_get_transfer_status(TPA6130_ABDAC_PDCA_CHANNEL) & PDCA_TRANSFER_COMPLETE));
00618     // Restore the reload callback function
00619     tpa6130_output_param.callback_opt = save_dac_reload_callback_opt;
00620   }
00621   else
00622   {
00623     // Re-enable the interrupts
00624     pdca_enable_interrupt_reload_counter_zero(TPA6130_ABDAC_PDCA_CHANNEL);
00625     // Un-mute the audio stream
00626     volume = volume & (~(MUTE_L | MUTE_R));
00627     tpa6130_write_data(TPA6130_VOLUME_AND_MUTE, volume);
00628   }
00629 }

Bool tpa6130_dac_output ( void *  sample_buffer,
size_t  sample_length 
)

Outputs a sample buffer to the DACs. The input requires a sample buffer that consists of words (32-bit) which contain two (16-bit) samples, one for each channel.

Outputs a sample buffer to the DACs.

Note:
The DACs must have been started beforehand.

Definition at line 533 of file tpa6130_with_cs2200.c.

References tpa6130_output_param.

00534 {
00535   //int global_interrupt_enabled;
00536 
00537   /*Wait until the PDCA loads the reload value to its transfer
00538    * counter register(TCRR=0). Then we are ready to set up a new
00539    * transfer */
00540   if(!(pdca_get_transfer_status(TPA6130_ABDAC_PDCA_CHANNEL) &
00541     PDCA_TRANSFER_COUNTER_RELOAD_IS_ZERO))
00542   {
00543     return FALSE;
00544   }
00545 
00546   /* Nothing to do if we get no data. */
00547   if(sample_length)
00548   {
00549 
00550     /*TODO Do we really need to adjust the buffer for mono*/
00551 
00552     /* While reloading the PDC we do not need any active interrupt*/
00553     //if((global_interrupt_enabled = Is_global_interrupt_enabled()))
00554     //  Disable_global_interrupt();
00555 
00556     /*FIXME This assumes a stereo 16-bit sample size */
00557     // one sample here consists of 2x16-bit (16-bit stereo)
00558     pdca_reload_channel(TPA6130_ABDAC_PDCA_CHANNEL,
00559       sample_buffer, sample_length);
00560 
00561     //if(global_interrupt_enabled)
00562     //  Enable_global_interrupt();
00563 
00564     /*TODO enable transfer complete interrupt
00565      * Is it possible to move this to setup or other places?*/
00566     if(tpa6130_output_param.callback_opt & AUDIO_DAC_OUT_OF_SAMPLE_CB)
00567       pdca_enable_interrupt_transfer_complete(TPA6130_ABDAC_PDCA_CHANNEL);
00568     if (tpa6130_output_param.callback_opt & AUDIO_DAC_RELOAD_CB)
00569       pdca_enable_interrupt_reload_counter_zero(TPA6130_ABDAC_PDCA_CHANNEL);
00570   }
00571   return TRUE;
00572 }

void tpa6130_dac_set_volume ( U8  volume  ) 

Set the volume of the DAC.

Definition at line 652 of file tpa6130_with_cs2200.c.

References tpa6130_set_volume().

00653 {
00654    tpa6130_set_volume(volume);
00655 }

void tpa6130_dac_setup ( U32  sample_rate_hz,
U8  num_channels,
U8  bits_per_sample,
Bool  swap_channels,
void(*)(U32 arg)  callback,
U32  callback_opt,
U32  pba_hz 
)

Sets the DACs up with new settings.

Note:
The DACs must have been started beforehand.

Definition at line 417 of file tpa6130_with_cs2200.c.

References callback, FPBA_HZ, pm, TPA6130_ABDAC_GCLK_INPUT_HZ, tpa6130_init(), tpa6130_output_param, and usb_stream_resync_frequency.

00424 {
00425   // Change the CPU frequency
00426   //
00427   //Disable_global_interrupt();
00428 
00429   // Switch to OSC0 during OSC1 transition
00430   //pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);
00431 
00432   // Switch to PLL0 as the master clock
00433   //pm_switch_to_clock(&AVR32_PM, AVR32_PM_MCCTRL_MCSEL_PLL0);
00434 
00435   if (sample_rate_hz < (8000 + 8021) / 2)
00436   { // 8000 Hz
00437   }
00438   else if (sample_rate_hz < (8021 + 32000) / 2)
00439   { // 8021 Hz
00440   }
00441   else if (sample_rate_hz < (32000 + 44100) / 2)
00442   { // 32000 Hz
00443     usb_stream_resync_frequency = 8192000;
00444     cs2200_freq_clk_out(_32_BITS_RATIO(usb_stream_resync_frequency));
00445     pba_hz = FCPU_HZ = FHSB_HZ = FPBA_HZ = FPBB_HZ = FMCK_HZ(8192000);
00446   }
00447   else if (sample_rate_hz < (44100 + 48000) / 2)
00448   { // 44100 Hz
00449     usb_stream_resync_frequency = 11289600;
00450     cs2200_freq_clk_out(_32_BITS_RATIO(usb_stream_resync_frequency));
00451     pba_hz = FCPU_HZ = FHSB_HZ = FPBA_HZ = FPBB_HZ = FMCK_HZ(11289600);
00452   }
00453   else if (sample_rate_hz < (48000 + 88200) / 2)
00454   { // 48000 Hz
00455     usb_stream_resync_frequency = 12288000;
00456     cs2200_freq_clk_out(_32_BITS_RATIO(usb_stream_resync_frequency));
00457     pba_hz = FCPU_HZ = FHSB_HZ = FPBA_HZ = FPBB_HZ = FMCK_HZ(12288000);
00458   }
00459   else if (sample_rate_hz < (88200 + 96000) / 2)
00460   { // 88200 Hz
00461   }
00462   else
00463   { // 96000 Hz
00464   }
00465 
00466   //Enable_global_interrupt();
00467 
00468   // save input parameters to local driver data
00469   tpa6130_output_param.num_channels = num_channels;
00470   tpa6130_output_param.callback     = callback;
00471   tpa6130_output_param.callback_opt = callback_opt;
00472 
00473   /* Probe for amplifier and initialize it */
00474   tpa6130_init();
00475 
00476 #if defined(TPA6130_DAC_CLOCK_SET_CALLBACK)
00477   TPA6130_DAC_CLOCK_SET_CALLBACK(sample_rate_hz);
00478 #else
00479   /* ABDAC configuration
00480    * The ABDAC needs the input frequency of its generic clock (bus_hz)
00481    * Here we use the configuration value from the conf_tpa6130.h file
00482    * (TPA6130_ABDAC_GCLK_INPUT_HZ).
00483    * The sample rate specifies the desired sample rate for the ABDAC.
00484    * The generic clock input must be greater than 256*sample_rate_hz
00485    * or the setup of the ABDAC will fail silently here.
00486    * TODO we could add asserts here to detect wrong settings during
00487    * compile time.
00488    */
00489    pm->GCCTRL[ABDAC_GCLK].div= 0;  // No Div factor
00490    pm->GCCTRL[ABDAC_GCLK].diven=0; // div disable
00491    pm->GCCTRL[ABDAC_GCLK].pllsel=0;// Oscilator source
00492    pm->GCCTRL[ABDAC_GCLK].oscsel=1;// OSC1        
00493 #endif
00494 
00495   if(swap_channels)
00496   {
00497     abdac_swap_channels(TPA6130_ABDAC);
00498   }
00499   abdac_enable(TPA6130_ABDAC);
00500 
00501   /* PDCA setup */
00502   /*FIXME we use only word as transfer size for now.
00503    * half-word transfer size will only write to channel0
00504    * of the ABDAC, this can be used to implement mono */
00505   pdca_channel_options_t tpa6130_abdac_pdca_options =
00506   {
00507     .addr   = NULL,
00508     .size   = 0,
00509     .r_addr   = 0,
00510     .r_size   = 0,
00511     .pid    = TPA6130_ABDAC_PDCA_PID,
00512     .transfer_size  = PDCA_TRANSFER_SIZE_WORD
00513   };
00514 
00515   /* Initialize the PCDA for the ABDAC
00516    * The channel number can be set in the configuration file
00517    * with the define TPA6130_ABDAC_PDCA_CHANNEL.
00518    */
00519   pdca_init_channel(TPA6130_ABDAC_PDCA_CHANNEL,
00520     &tpa6130_abdac_pdca_options);
00521   /* Enable the PDCA channel. Since we did not provide any data
00522    * yet the channel is in idle mode */
00523   pdca_enable(TPA6130_ABDAC_PDCA_CHANNEL);
00524 
00525 }

void tpa6130_dac_start ( U32  sample_rate_hz,
U8  num_channels,
U8  bits_per_sample,
Bool  swap_channels,
void(*)(U32 arg)  callback,
U32  callback_opt,
U32  pba_hz 
)

Starts the ABDAC.

Parameters:
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.

Definition at line 377 of file tpa6130_with_cs2200.c.

References callback, TPA6130_ABDAC_GPIO_MAP, tpa6130_abdac_tx_pdca_int_handler(), tpa6130_dac_setup(), tpa6130_dac_stop(), and tpa6130_powerup().

00384 {
00385   /* stop ABDAC if running*/
00386   tpa6130_dac_stop();
00387 
00388   /* configure used pins for ABDAC */
00389   gpio_enable_module(TPA6130_ABDAC_GPIO_MAP,
00390     sizeof(TPA6130_ABDAC_GPIO_MAP) /
00391     sizeof(TPA6130_ABDAC_GPIO_MAP[0]));
00392 
00393   /* configure and start PDC and ABDAC*/
00394   tpa6130_dac_setup(sample_rate_hz,
00395     num_channels,
00396     bits_per_sample,
00397     swap_channels,
00398     callback,
00399     callback_opt,
00400     pba_hz);
00401 
00402   /* Register a interrupt service routine for the ABDAC channel of
00403    * the PDCA
00404    */
00405   INTC_register_interrupt(&tpa6130_abdac_tx_pdca_int_handler,
00406     TPA6130_ABDAC_PDCA_IRQ,
00407     TPA6130_ABDAC_PDCA_INT_LEVEL);
00408 
00409   tpa6130_powerup();
00410 
00411 }

void tpa6130_dac_stop ( void   ) 

Stops the ABDAC and puts the amplifier in low power mode. Additionally it sets all used pins to the GPIO state. The counter part of this function is tpa6130_dac_start(...).

Stops the DACs.

Definition at line 702 of file tpa6130_with_cs2200.c.

References TPA6130_ABDAC_GPIO_MAP, tpa6130_output_param, and tpa6130_shutdown().

00703 {
00704   /* Disable amplifier 1st */
00705   tpa6130_shutdown();
00706 
00707   /* Flush the dac */
00708   // Don't flush the DAC when stop
00709   //tpa6130_dac_flush();
00710 
00711   /* Disable ABDAC */
00712   abdac_disable(TPA6130_ABDAC);
00713 
00714   /* Stop  PDCA */
00715   pdca_disable(TPA6130_ABDAC_PDCA_CHANNEL);
00716 
00717   /* Set used GPIO pins to GPIO state */
00718   gpio_enable_gpio(TPA6130_ABDAC_GPIO_MAP,
00719     sizeof(TPA6130_ABDAC_GPIO_MAP)
00720     / sizeof(TPA6130_ABDAC_GPIO_MAP[0]));
00721 
00722   tpa6130_output_param.num_channels = 0;
00723   tpa6130_output_param.callback     = NULL;
00724   tpa6130_output_param.callback_opt = 0;
00725 }

S8 tpa6130_get_volume ( void   ) 

Gets the current volume settings.

Returns:
Current volume settings. Value is between 0 (-59dB) and 63 (4dB).

Definition at line 363 of file tpa6130_with_cs2200.c.

References tpa6130_read_data(), TPA6130_VOLUME_AND_MUTE, and TWI_READ_SR.

00364 {
00365   return tpa6130_read_data(TPA6130_VOLUME_AND_MUTE, TWI_READ_SR);
00366 }

S8 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 ..).

Returns:
A positive value upon success and a negative value upon failure.

Definition at line 299 of file tpa6130_with_cs2200.c.

References HP_EN_L, HP_EN_R, TPA6130_CONTROL, TPA6130_I2C_ADDRESS_VERSION, TPA6130_MODE, tpa6130_read_data(), tpa6130_shadow_regs, TPA6130_TWI_ADDRESS, TPA6130_VOLUME_AND_MUTE, tpa6130_write_data(), TWI_READ_HW, and VERSION.

00300 {
00301   /* Check if the device responds on the TWI bus*/
00302   if(twi_probe(TPA6130_TWI, TPA6130_TWI_ADDRESS) != TWI_SUCCESS)
00303   return TWI_NO_CHIP_FOUND;
00304   /* If the device has no valid version we can not use it */
00305   if(tpa6130_read_data(TPA6130_I2C_ADDRESS_VERSION, TWI_READ_HW)!= VERSION)
00306   {
00307     return -8;
00308   }
00309   /* un-mute the output channels, the volume is still 0 and
00310    * should be increased by an application (fade-in/fade-out) */
00311   tpa6130_write_data(TPA6130_VOLUME_AND_MUTE, tpa6130_shadow_regs.volume_and_mute);
00312   /* set stereo/mono mode and enable both amplifiers (left/right) */
00313   tpa6130_write_data(TPA6130_CONTROL,(TPA6130_MODE << 4) | HP_EN_L | HP_EN_R);
00314 
00315   return TWI_SUCCESS;
00316 }

void tpa6130_powerup ( void   ) 

Powers up the amplifier from low power mode.

Powers up the amplifier from low power mode. This is the software low power mode described in the datasheet.

Definition at line 329 of file tpa6130_with_cs2200.c.

References SW_SHUTDOWN, TPA6130_CONTROL, tpa6130_read_data(), tpa6130_write_data(), and TWI_READ_HW.

00330 {
00331   U8 data;
00332   data = tpa6130_read_data(TPA6130_CONTROL, TWI_READ_HW);
00333   tpa6130_write_data(TPA6130_CONTROL, data & (~SW_SHUTDOWN));
00334 }

static U8 tpa6130_read_data ( U8  reg,
Bool  shadow 
) [static]

Reads data from a register. The shadow parameter is used to specify if the data should be read from a driver internal register shadowing or directly from the device.

Parameters:
reg Register index.
shadow Read from device (shadow=FALSE) or from shadowed register (shadow=TRUE).

Definition at line 260 of file tpa6130_with_cs2200.c.

References tpa6130_shadow_regs, and TPA6130_TWI_ADDRESS.

00261 {
00262   U8 data;
00263   /*If we want to read from the shadowed registers */
00264   if(shadow)
00265   {
00266     data = *((U8 *) &tpa6130_shadow_regs + reg - 1);
00267   }
00268   else
00269   {
00270     twi_package_t twi_package =
00271     {
00272       .chip = TPA6130_TWI_ADDRESS,
00273       .addr_length = 1,//AVR32_TWI_MMR_IADRSZ_ONE_BYTE,
00274       .addr = reg,
00275       .buffer = &data,
00276       .length = sizeof(data)
00277     };
00278     twi_master_read(TPA6130_TWI, &twi_package);
00279   }
00280   //print_dbg("Read reg ");
00281   //print_dbg_ulong(reg);
00282   //print_dbg(" = 0x");
00283   //print_dbg_hex(data);
00284   //print_dbg("\n");
00285 
00286   return data;
00287 }

void tpa6130_set_volume ( S8  volume  ) 

Sets the volume of the amplifier. Valid values are between 0 (min -59dB) and 63 (max 4dB) altough the function takes care of any values higher than that by setting it to max. A volume of 0 will mute both channels. Any other value will unmute them.

Sets the volume of the amplifier. Valid values are between 0 (min -59dB) and 63 (max 4dB) altough the function takes care of any values higher than that by setting it to max.

Definition at line 342 of file tpa6130_with_cs2200.c.

References MUTE_L, MUTE_R, TPA6130_VOL_MAX, TPA6130_VOL_MIN, TPA6130_VOLUME_AND_MUTE, and tpa6130_write_data().

00343 {
00344   S8 new_volume = volume;
00345 
00346   if(volume > TPA6130_VOL_MAX)
00347   {
00348     new_volume = TPA6130_VOL_MAX;
00349   }
00350   else if(volume <= TPA6130_VOL_MIN )
00351   {
00352     // MUTE Left and Right;
00353     new_volume = MUTE_L|MUTE_R;
00354   }
00355   
00356   tpa6130_write_data(TPA6130_VOLUME_AND_MUTE, new_volume );
00357 }

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.

Definition at line 321 of file tpa6130_with_cs2200.c.

References SW_SHUTDOWN, TPA6130_CONTROL, tpa6130_read_data(), tpa6130_write_data(), and TWI_READ_HW.

00322 {
00323   U8 data;
00324   data = tpa6130_read_data(TPA6130_CONTROL, TWI_READ_HW);
00325   tpa6130_write_data(TPA6130_CONTROL, data | SW_SHUTDOWN);
00326 }

static void tpa6130_write_data ( U8  reg,
U8  data 
) [static]

Writes data to a register.

Parameters:
reg Register index. Use the defines in this file.
data Register data. Macros from this file can be used to ease writing to the bitfields.

Definition at line 230 of file tpa6130_with_cs2200.c.

References tpa6130_shadow_regs, and TPA6130_TWI_ADDRESS.

00231 {
00232   U16 message = (reg << 8) | data;
00233   int twi_status;
00234 
00235   twi_package_t twi_package =
00236   {
00237     .chip = TPA6130_TWI_ADDRESS,
00238     .addr_length = 0,//AVR32_TWI_MMR_IADRSZ_NO_ADDR,
00239     .buffer = &message,
00240     .length = sizeof(message)
00241   };
00242 
00243   do
00244   {
00245      twi_status=twi_master_write(TPA6130_TWI, &twi_package);
00246   }
00247   while( twi_status != TWI_SUCCESS );
00248 
00249   /* Save write value to shadow registers */
00250   *(((U8 *) &tpa6130_shadow_regs) + reg - 1) = data;
00251 }


Variable Documentation

void(* callback)(U32 arg)

Definition at line 175 of file tpa6130_with_cs2200.c.

U8 control

Definition at line 191 of file tpa6130_with_cs2200.c.

Definition at line 194 of file tpa6130_with_cs2200.c.

Definition at line 173 of file tpa6130_with_cs2200.c.

Definition at line 193 of file tpa6130_with_cs2200.c.

volatile avr32_pm_t* pm = &AVR32_PM

Definition at line 185 of file tpa6130_with_cs2200.c.

Referenced by tpa6130_dac_setup().

const gpio_map_t TPA6130_ABDAC_GPIO_MAP [static]

Initial value:

{
  {TPA6130_DATA0_PIN, TPA6130_DATA0_FUNCTION},
  {TPA6130_DATA1_PIN, TPA6130_DATA1_FUNCTION},
  {TPA6130_DATAN0_PIN, TPA6130_DATAN0_FUNCTION},
  {TPA6130_DATAN1_PIN, TPA6130_DATAN1_FUNCTION}
}

Definition at line 117 of file tpa6130_with_cs2200.c.

struct { ... } tpa6130_output_param [static]

struct { ... } tpa6130_shadow_regs [static]

CS2200 out frequency.

Referenced by tpa6130_dac_setup().

Definition at line 192 of file tpa6130_with_cs2200.c.


Generated on Thu Dec 17 19:57:30 2009 for AVR32 UC3 - Example of using the TPA6130A2 by  doxygen 1.5.5