tpa6130.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.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 "twim.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

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


Define Documentation

#define BRIDGE_TIED_LOAD   0x20

Definition at line 84 of file tpa6130.c.

#define DUAL_MONO_HP   0x10

Definition at line 83 of file tpa6130.c.

#define HIZ_L   0x80

Definition at line 91 of file tpa6130.c.

#define HIZ_R   0x40

Definition at line 92 of file tpa6130.c.

#define HP_EN_L   0x80

Definition at line 80 of file tpa6130.c.

Referenced by tpa6130_init().

#define HP_EN_R   0x40

Definition at line 81 of file tpa6130.c.

Referenced by tpa6130_init().

#define MUTE_L   0x80

#define MUTE_R   0x40

#define STEREO_HP   0x00

Definition at line 82 of file tpa6130.c.

#define SW_SHUTDOWN   0x01

Definition at line 85 of file tpa6130.c.

Referenced by tpa6130_powerup(), and tpa6130_shutdown().

#define THERMAL   0x02

Definition at line 86 of file tpa6130.c.

#define TPA6130_CONTROL   0x1

Definition at line 67 of file tpa6130.c.

Referenced by tpa6130_init(), tpa6130_powerup(), and tpa6130_shutdown().

#define TPA6130_CONTROL_DEFAULT   0x00

Definition at line 73 of file tpa6130.c.

#define TPA6130_I2C_ADDRESS_VERSION   0x4

Definition at line 70 of file tpa6130.c.

Referenced by tpa6130_init().

#define TPA6130_I2C_ADDRESS_VERSION_DEFAULT   0x02

Definition at line 77 of file tpa6130.c.

#define TPA6130_MAX_VOLUME   0x3F

Definition at line 99 of file tpa6130.c.

#define TPA6130_OUTPUT_IMPEDANCE   0x3

Definition at line 69 of file tpa6130.c.

#define TPA6130_OUTPUT_IMPEDANCE_DEFAULT   0x00

Definition at line 76 of file tpa6130.c.

#define TPA6130_VOLUME_AND_MUTE   0x2

Definition at line 68 of file tpa6130.c.

Referenced by tpa6130_dac_mute(), tpa6130_get_volume(), tpa6130_init(), and tpa6130_set_volume().

#define TPA6130_VOLUME_AND_MUTE_DEFAULT   0x0F

Definition at line 75 of file tpa6130.c.

#define TWI_READ_HW   0

Definition at line 103 of file tpa6130.c.

Referenced by tpa6130_init(), tpa6130_powerup(), and tpa6130_shutdown().

#define TWI_READ_SR   1

Definition at line 105 of file tpa6130.c.

Referenced by tpa6130_get_volume().

#define VERSION   0x02

Definition at line 94 of file tpa6130.c.

Referenced by tpa6130_init().


Function Documentation

static void tpa6130_abdac_tx_pdca_int_handler ( void   )  [static]

Definition at line 201 of file tpa6130.c.

References tpa6130_output_param.

Referenced by tpa6130_dac_start().

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

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 624 of file tpa6130.c.

00625 {
00626   S8 volume = tpa6130_get_volume()& (~(MUTE_L | MUTE_R));;
00627   if( volume > TPA6130_VOL_MIN )
00628     --volume;
00629   tpa6130_set_volume( volume );
00630 }

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 634 of file tpa6130.c.

00635 {
00636   pdca_disable_interrupt_transfer_complete(TPA6130_ABDAC_PDCA_CHANNEL);
00637   pdca_disable_interrupt_reload_counter_zero(TPA6130_ABDAC_PDCA_CHANNEL);
00638 
00639   /*TODO Do we really want to wait here? Or do we just don't care when
00640    * the buffer is empty/flushed */
00641   //while(!pdca_get_transfer_status(TPA6130_ABDAC_PDCA_CHANNEL) &
00642   //  PDCA_TRANSFER_COMPLETE);
00643   pdca_disable       (TPA6130_ABDAC_PDCA_CHANNEL       );
00644   pdca_load_channel  (TPA6130_ABDAC_PDCA_CHANNEL,0x0, 0);
00645   pdca_reload_channel(TPA6130_ABDAC_PDCA_CHANNEL,0x0, 0);
00646   pdca_enable        (TPA6130_ABDAC_PDCA_CHANNEL       );
00647 }

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 590 of file tpa6130.c.

00591 {
00592  // return volume is num display step for LCD
00593  //  volume scale is between 10 and 245
00594  // 0 is -100db
00595  // 245 is max volume
00596   U16 raw_volume;
00597   raw_volume = (tpa6130_get_volume() & (~(MUTE_L | MUTE_R)));
00598   return (U8) ((raw_volume * 255) / TPA6130_VOL_MAX);
00599 }

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 612 of file tpa6130.c.

00613 {
00614   S8 volume = tpa6130_get_volume()& (~(MUTE_L | MUTE_R));
00615   if( volume < TPA6130_VOL_MIN )
00616     volume = TPA6130_VOL_MIN;
00617   tpa6130_set_volume(volume+1);
00618 }

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 582 of file tpa6130.c.

00583 {
00584   return FALSE;
00585 }

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 525 of file tpa6130.c.

00526 {
00527   return FALSE;
00528 }

void tpa6130_dac_mute ( Bool  mute  ) 

No more audio if input is true.

Definition at line 530 of file tpa6130.c.

00531 {
00532   // //1st Version Mute Audio for Play/Pause
00533 /*  int volume=tpa6130_get_volume();
00534   if(mute==TRUE) {
00535      //Mute volume
00536      volume= volume|MUTE_L|MUTE_R;
00537   }
00538   else {
00539      //Unmute volume
00540      volume= volume&(~(MUTE_L|MUTE_R));
00541  
00542   }
00543  tpa6130_write_data(TPA6130_VOLUME_AND_MUTE,volume);
00544 */
00545   //2n Version Stop PDCA >> No lost of audio when pause
00546 /*  if(mute==TRUE) {
00547     pdca_disable(TPA6130_ABDAC_PDCA_CHANNEL);
00548   }
00549   else {
00550     pdca_enable(TPA6130_ABDAC_PDCA_CHANNEL);
00551   }
00552 */
00553 
00554   // 3rd Version wait until the current buffers are empty and disable the interrutps
00555   S8 volume = tpa6130_get_volume();
00556   if (mute)
00557   {
00558     U32 save_dac_reload_callback_opt;
00559 
00560     // Mute the audio stream
00561     volume = volume | MUTE_L | MUTE_R;
00562     tpa6130_write_data(TPA6130_VOLUME_AND_MUTE, volume);
00563     // Disable the reload channel of the interrupt
00564     save_dac_reload_callback_opt = tpa6130_output_param.callback_opt;
00565     tpa6130_output_param.callback_opt = 0;
00566     // Disable the reload interruption and wait until the transfer is complete
00567     pdca_disable_interrupt_reload_counter_zero(TPA6130_ABDAC_PDCA_CHANNEL);
00568     while (!(pdca_get_transfer_status(TPA6130_ABDAC_PDCA_CHANNEL) & PDCA_TRANSFER_COMPLETE));
00569     // Restore the reload callback function
00570     tpa6130_output_param.callback_opt = save_dac_reload_callback_opt;
00571   }
00572   else
00573   {
00574     // Re-enable the interrupts
00575     pdca_enable_interrupt_reload_counter_zero(TPA6130_ABDAC_PDCA_CHANNEL);
00576     // Un-mute the audio stream
00577     volume = volume & (~(MUTE_L | MUTE_R));
00578     tpa6130_write_data(TPA6130_VOLUME_AND_MUTE, volume);
00579   }
00580 }

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 484 of file tpa6130.c.

Referenced by main().

00485 {
00486   //int global_interrupt_enabled;
00487 
00488   /*Wait until the PDCA loads the reload value to its transfer
00489    * counter register(TCRR=0). Then we are ready to set up a new
00490    * transfer */
00491   if(!(pdca_get_transfer_status(TPA6130_ABDAC_PDCA_CHANNEL) &
00492     PDCA_TRANSFER_COUNTER_RELOAD_IS_ZERO))
00493   {
00494     return FALSE;
00495   }
00496 
00497   /* Nothing to do if we get no data. */
00498   if(sample_length)
00499   {
00500 
00501     /*TODO Do we really need to adjust the buffer for mono*/
00502 
00503     /* While reloading the PDC we do not need any active interrupt*/
00504     //if((global_interrupt_enabled = Is_global_interrupt_enabled()))
00505     //  Disable_global_interrupt();
00506 
00507     /*FIXME This assumes a stereo 16-bit sample size */
00508     // one sample here consists of 2x16-bit (16-bit stereo)
00509     pdca_reload_channel(TPA6130_ABDAC_PDCA_CHANNEL,
00510       sample_buffer, sample_length);
00511 
00512     //if(global_interrupt_enabled)
00513     //  Enable_global_interrupt();
00514 
00515     /*TODO enable transfer complete interrupt
00516      * Is it possible to move this to setup or other places?*/
00517     if(tpa6130_output_param.callback_opt & AUDIO_DAC_OUT_OF_SAMPLE_CB)
00518       pdca_enable_interrupt_transfer_complete(TPA6130_ABDAC_PDCA_CHANNEL);
00519     if (tpa6130_output_param.callback_opt & AUDIO_DAC_RELOAD_CB)
00520       pdca_enable_interrupt_reload_counter_zero(TPA6130_ABDAC_PDCA_CHANNEL);
00521   }
00522   return TRUE;
00523 }

void tpa6130_dac_set_volume ( U8  volume  ) 

Set the volume of the DAC.

Definition at line 603 of file tpa6130.c.

00604 {
00605    tpa6130_set_volume(volume);
00606 }

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 410 of file tpa6130.c.

Referenced by tpa6130_dac_start().

00417 {
00418   // save input parameters to local driver data
00419   tpa6130_output_param.num_channels = num_channels;
00420   tpa6130_output_param.callback     = callback;
00421   tpa6130_output_param.callback_opt = callback_opt;
00422 
00423   /* Probe for amplifier and initialize it */
00424   tpa6130_init();
00425 
00426 #if defined(TPA6130_DAC_CLOCK_SET_CALLBACK)
00427   TPA6130_DAC_CLOCK_SET_CALLBACK(sample_rate_hz);
00428 #else
00429   /* ABDAC configuration
00430    * The ABDAC needs the input frequency of its generic clock (bus_hz)
00431    * Here we use the configuration value from the conf_tpa6130.h file
00432    * (TPA6130_ABDAC_GCLK_INPUT_HZ).
00433    * The sample rate specifies the desired sample rate for the ABDAC.
00434    * The generic clock input must be greater than 256*sample_rate_hz
00435    * or the setup of the ABDAC will fail silently here.
00436    * TODO we could add asserts here to detect wrong settings during
00437    * compile time.
00438    */
00439   if(!abdac_set_dac_sample_rate(sample_rate_hz)) {
00440     // if it is not possible to set correctly the sample rate
00441     // Use default set function
00442     abdac_set_dac_hz(TPA6130_ABDAC, TPA6130_ABDAC_GCLK_INPUT_HZ,sample_rate_hz);
00443   }
00444 #endif
00445 
00446   if(swap_channels)
00447   {
00448     abdac_swap_channels(TPA6130_ABDAC);
00449   }
00450   abdac_enable(TPA6130_ABDAC);
00451 
00452   /* PDCA setup */
00453   /*FIXME we use only word as transfer size for now.
00454    * half-word transfer size will only write to channel0
00455    * of the ABDAC, this can be used to implement mono */
00456   pdca_channel_options_t tpa6130_abdac_pdca_options =
00457   {
00458     .addr   = NULL,
00459     .size   = 0,
00460     .r_addr   = 0,
00461     .r_size   = 0,
00462     .pid    = TPA6130_ABDAC_PDCA_PID,
00463     .transfer_size  = PDCA_TRANSFER_SIZE_WORD
00464   };
00465 
00466   /* Initialize the PCDA for the ABDAC
00467    * The channel number can be set in the configuration file
00468    * with the define TPA6130_ABDAC_PDCA_CHANNEL.
00469    */
00470   pdca_init_channel(TPA6130_ABDAC_PDCA_CHANNEL,
00471     &tpa6130_abdac_pdca_options);
00472   /* Enable the PDCA channel. Since we did not provide any data
00473    * yet the channel is in idle mode */
00474   pdca_enable(TPA6130_ABDAC_PDCA_CHANNEL);
00475 
00476 }

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 370 of file tpa6130.c.

Referenced by main().

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

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 653 of file tpa6130.c.

Referenced by tpa6130_dac_start().

00654 {
00655   /* Disable amplifier 1st */
00656   tpa6130_shutdown();
00657 
00658   /* Flush the dac */
00659   // Don't flush the DAC when stop
00660   //tpa6130_dac_flush();
00661 
00662   /* Disable ABDAC */
00663   abdac_disable(TPA6130_ABDAC);
00664 
00665   /* Stop  PDCA */
00666   pdca_disable(TPA6130_ABDAC_PDCA_CHANNEL);
00667 
00668   /* Set used GPIO pins to GPIO state */
00669   gpio_enable_gpio(TPA6130_ABDAC_GPIO_MAP,
00670     sizeof(TPA6130_ABDAC_GPIO_MAP)
00671     / sizeof(TPA6130_ABDAC_GPIO_MAP[0]));
00672 
00673   tpa6130_output_param.num_channels = 0;
00674   tpa6130_output_param.callback     = NULL;
00675   tpa6130_output_param.callback_opt = 0;
00676 }

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 356 of file tpa6130.c.

Referenced by main(), tpa6130_dac_decrease_volume(), tpa6130_dac_get_volume(), tpa6130_dac_increase_volume(), and tpa6130_dac_mute().

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

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 292 of file tpa6130.c.

Referenced by main(), and tpa6130_dac_setup().

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

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 322 of file tpa6130.c.

Referenced by tpa6130_dac_start().

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

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 253 of file tpa6130.c.

References tpa6130_shadow_regs, and TPA6130_TWI_ADDRESS.

Referenced by tpa6130_get_volume(), tpa6130_init(), tpa6130_powerup(), and tpa6130_shutdown().

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

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 335 of file tpa6130.c.

Referenced by main(), tpa6130_dac_decrease_volume(), tpa6130_dac_increase_volume(), and tpa6130_dac_set_volume().

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

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 314 of file tpa6130.c.

Referenced by tpa6130_dac_stop().

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

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 223 of file tpa6130.c.

References tpa6130_shadow_regs, and TPA6130_TWI_ADDRESS.

Referenced by tpa6130_dac_mute(), tpa6130_init(), tpa6130_powerup(), tpa6130_set_volume(), and tpa6130_shutdown().

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


Variable Documentation

void(* callback)(U32 arg)

Definition at line 172 of file tpa6130.c.

U8 control

Definition at line 184 of file tpa6130.c.

Definition at line 187 of file tpa6130.c.

Definition at line 170 of file tpa6130.c.

Definition at line 186 of file tpa6130.c.

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 114 of file tpa6130.c.

Referenced by tpa6130_dac_start(), and tpa6130_dac_stop().

struct { ... } tpa6130_output_param [static]

struct { ... } tpa6130_shadow_regs [static]

Definition at line 185 of file tpa6130.c.


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