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 "twi.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 81 of file tpa6130_with_cs2200.c.

#define DUAL_MONO_HP   0x10

Definition at line 80 of file tpa6130_with_cs2200.c.

#define HIZ_L   0x80

Definition at line 88 of file tpa6130_with_cs2200.c.

#define HIZ_R   0x40

Definition at line 89 of file tpa6130_with_cs2200.c.

#define HP_EN_L   0x80

Definition at line 77 of file tpa6130_with_cs2200.c.

#define HP_EN_R   0x40

Definition at line 78 of file tpa6130_with_cs2200.c.

#define MUTE_L   0x80

Definition at line 85 of file tpa6130_with_cs2200.c.

#define MUTE_R   0x40

Definition at line 86 of file tpa6130_with_cs2200.c.

#define STEREO_HP   0x00

Definition at line 79 of file tpa6130_with_cs2200.c.

#define SW_SHUTDOWN   0x01

Definition at line 82 of file tpa6130_with_cs2200.c.

#define THERMAL   0x02

Definition at line 83 of file tpa6130_with_cs2200.c.

#define TPA6130_CONTROL   0x1

Definition at line 64 of file tpa6130_with_cs2200.c.

#define TPA6130_CONTROL_DEFAULT   0x00

Definition at line 70 of file tpa6130_with_cs2200.c.

#define TPA6130_I2C_ADDRESS_VERSION   0x4

Definition at line 67 of file tpa6130_with_cs2200.c.

#define TPA6130_I2C_ADDRESS_VERSION_DEFAULT   0x02

Definition at line 74 of file tpa6130_with_cs2200.c.

#define TPA6130_MAX_VOLUME   0x3F

Definition at line 96 of file tpa6130_with_cs2200.c.

#define TPA6130_OUTPUT_IMPEDANCE   0x3

Definition at line 66 of file tpa6130_with_cs2200.c.

#define TPA6130_OUTPUT_IMPEDANCE_DEFAULT   0x00

Definition at line 73 of file tpa6130_with_cs2200.c.

#define TPA6130_VOLUME_AND_MUTE   0x2

Definition at line 65 of file tpa6130_with_cs2200.c.

#define TPA6130_VOLUME_AND_MUTE_DEFAULT   0x0F

Definition at line 72 of file tpa6130_with_cs2200.c.

#define TWI_READ_HW   0

Definition at line 100 of file tpa6130_with_cs2200.c.

#define TWI_READ_SR   1

Definition at line 102 of file tpa6130_with_cs2200.c.

#define VERSION   0x02

Definition at line 91 of file tpa6130_with_cs2200.c.


Function Documentation

static void tpa6130_abdac_tx_pdca_int_handler ( void   )  [static]

Definition at line 202 of file tpa6130_with_cs2200.c.

References tpa6130_output_param.

00203 {
00204   if (pdca_get_transfer_status(TPA6130_ABDAC_PDCA_CHANNEL) & PDCA_TRANSFER_COMPLETE)
00205   {
00206     pdca_disable_interrupt_transfer_complete(TPA6130_ABDAC_PDCA_CHANNEL);
00207     if (tpa6130_output_param.callback_opt & AUDIO_DAC_OUT_OF_SAMPLE_CB)
00208       tpa6130_output_param.callback(AUDIO_DAC_OUT_OF_SAMPLE_CB);
00209   }
00210 
00211   if (pdca_get_transfer_status(TPA6130_ABDAC_PDCA_CHANNEL) & PDCA_TRANSFER_COUNTER_RELOAD_IS_ZERO)
00212   {
00213     pdca_disable_interrupt_reload_counter_zero(TPA6130_ABDAC_PDCA_CHANNEL);
00214     if (tpa6130_output_param.callback_opt & AUDIO_DAC_RELOAD_CB)
00215       tpa6130_output_param.callback(AUDIO_DAC_RELOAD_CB);
00216   }
00217 }

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 667 of file tpa6130_with_cs2200.c.

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

00668 {
00669   S8 volume = tpa6130_get_volume()& (~(MUTE_L | MUTE_R));;
00670   if( volume > TPA6130_VOL_MIN )
00671     --volume;
00672   tpa6130_set_volume( volume );
00673 }

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 677 of file tpa6130_with_cs2200.c.

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

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 633 of file tpa6130_with_cs2200.c.

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

00634 {
00635  // return volume is num display step for LCD
00636  //  volume scale is between 10 and 245
00637  // 0 is -100db
00638  // 245 is max volume
00639   U16 raw_volume;
00640   raw_volume = (tpa6130_get_volume() & (~(MUTE_L | MUTE_R)));
00641   return (U8) ((raw_volume * 255) / TPA6130_VOL_MAX);
00642 }

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 655 of file tpa6130_with_cs2200.c.

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

00656 {
00657   S8 volume = tpa6130_get_volume()& (~(MUTE_L | MUTE_R));
00658   if( volume < TPA6130_VOL_MIN )
00659     volume = TPA6130_VOL_MIN;
00660   tpa6130_set_volume(volume+1);
00661 }

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 625 of file tpa6130_with_cs2200.c.

00626 {
00627   return FALSE;
00628 }

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 568 of file tpa6130_with_cs2200.c.

00569 {
00570   return FALSE;
00571 }

void tpa6130_dac_mute ( Bool  mute  ) 

No more audio if input is true.

Definition at line 573 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().

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

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 527 of file tpa6130_with_cs2200.c.

References tpa6130_output_param.

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

void tpa6130_dac_set_volume ( U8  volume  ) 

Set the volume of the DAC.

Definition at line 646 of file tpa6130_with_cs2200.c.

References tpa6130_set_volume().

00647 {
00648    tpa6130_set_volume(volume);
00649 }

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 411 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.

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

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 371 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().

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

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 696 of file tpa6130_with_cs2200.c.

References TPA6130_ABDAC_GPIO_MAP, tpa6130_output_param, and tpa6130_shutdown().

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

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 357 of file tpa6130_with_cs2200.c.

References tpa6130_read_data(), TPA6130_VOLUME_AND_MUTE, and TWI_READ_SR.

00358 {
00359   return tpa6130_read_data(TPA6130_VOLUME_AND_MUTE, TWI_READ_SR);
00360 }

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 293 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.

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

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 323 of file tpa6130_with_cs2200.c.

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

00324 {
00325   U8 data;
00326   data = tpa6130_read_data(TPA6130_CONTROL, TWI_READ_HW);
00327   tpa6130_write_data(TPA6130_CONTROL, data & (~SW_SHUTDOWN));
00328 }

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 254 of file tpa6130_with_cs2200.c.

References tpa6130_shadow_regs, and TPA6130_TWI_ADDRESS.

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

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 336 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().

00337 {
00338   S8 new_volume = volume;
00339 
00340   if(volume > TPA6130_VOL_MAX)
00341   {
00342     new_volume = TPA6130_VOL_MAX;
00343   }
00344   else if(volume <= TPA6130_VOL_MIN )
00345   {
00346     // MUTE Left and Right;
00347     new_volume = MUTE_L|MUTE_R;
00348   }
00349   
00350   tpa6130_write_data(TPA6130_VOLUME_AND_MUTE, new_volume );
00351 }

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 315 of file tpa6130_with_cs2200.c.

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

00316 {
00317   U8 data;
00318   data = tpa6130_read_data(TPA6130_CONTROL, TWI_READ_HW);
00319   tpa6130_write_data(TPA6130_CONTROL, data | SW_SHUTDOWN);
00320 }

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 224 of file tpa6130_with_cs2200.c.

References tpa6130_shadow_regs, and TPA6130_TWI_ADDRESS.

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


Variable Documentation

void(* callback)(U32 arg)

Definition at line 169 of file tpa6130_with_cs2200.c.

U8 control

Definition at line 185 of file tpa6130_with_cs2200.c.

Definition at line 188 of file tpa6130_with_cs2200.c.

Definition at line 167 of file tpa6130_with_cs2200.c.

Definition at line 187 of file tpa6130_with_cs2200.c.

volatile avr32_pm_t* pm = &AVR32_PM

Definition at line 179 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 111 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 186 of file tpa6130_with_cs2200.c.


Generated on Fri Feb 19 02:23:28 2010 for AVR32 UC3 - Example of using the TPA6130A2 by  doxygen 1.5.5