Ejemplo n.º 1
0
//{{{
uint32_t wm8994_SetVolume (uint16_t DeviceAddr, uint8_t Volume) {

  uint32_t counter = 0;
  uint8_t convertedvol = VOLUME_CONVERT(Volume);

  /* Output volume */
  if (outputEnabled != 0) {
    if (convertedvol > 0x3E) {
      /* Unmute audio codec */
      counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
      /* Left Headphone Volume */
      counter += CODEC_IO_Write(DeviceAddr, 0x1C, 0x3F | 0x140);
      /* Right Headphone Volume */
      counter += CODEC_IO_Write(DeviceAddr, 0x1D, 0x3F | 0x140);
      /* Left Speaker Volume */
      counter += CODEC_IO_Write(DeviceAddr, 0x26, 0x3F | 0x140);
      /* Right Speaker Volume */
      counter += CODEC_IO_Write(DeviceAddr, 0x27, 0x3F | 0x140);
      }
    else if (Volume == 0) 
      /* Mute audio codec */
      counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_ON);
    else {
      /* Unmute audio codec */
      counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
      /* Left Headphone Volume */
      counter += CODEC_IO_Write(DeviceAddr, 0x1C, convertedvol | 0x140);
      /* Right Headphone Volume */
      counter += CODEC_IO_Write(DeviceAddr, 0x1D, convertedvol | 0x140);
      /* Left Speaker Volume */
      counter += CODEC_IO_Write(DeviceAddr, 0x26, convertedvol | 0x140);
      /* Right Speaker Volume */
      counter += CODEC_IO_Write(DeviceAddr, 0x27, convertedvol | 0x140);
      }
    }

  /* Input volume */
  if (inputEnabled != 0) {
    convertedvol = VOLUME_IN_CONVERT(Volume);
    /* Left AIF1 ADC1 volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x400, convertedvol | 0x100);
    /* Right AIF1 ADC1 volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x401, convertedvol | 0x100);
    /* Left AIF1 ADC2 volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x404, convertedvol | 0x100);
    /* Right AIF1 ADC2 volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x405, convertedvol | 0x100);
    }

  return counter;
  }
Ejemplo n.º 2
0
/**
  * @brief Stops audio Codec playing. It powers down the codec.
  * @param DeviceAddr: Device address on communication Bus. 
  * @param CodecPdwnMode: selects the  power down mode.
  *          - CODEC_PDWN_SW: only mutes the audio codec. When resuming from this 
  *                           mode the codec keeps the previous initialization
  *                           (no need to re-Initialize the codec registers).
  *          - CODEC_PDWN_HW: Physically power down the codec. When resuming from this
  *                           mode, the codec is set to default configuration 
  *                           (user should re-Initialize the codec in order to 
  *                            play again the audio stream).
  * @retval 0 if correct communication, else wrong communication
  */
uint32_t wm8994_Stop(uint16_t DeviceAddr, uint32_t CodecPdwnMode)
{
  uint32_t counter = 0;
  
  /* Mute the output first */
  counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_ON);
  
  if (CodecPdwnMode == CODEC_PDWN_SW)
  {    
     /* Only output mute required*/
  }
  else /* CODEC_PDWN_HW */
  { 
    /* Mute the AIF1 Timeslot 0 DAC1 path */
    counter += CODEC_IO_Write(DeviceAddr, 0x420, 0x0200);
    
    /* Mute the AIF1 Timeslot 1 DAC2 path */
    counter += CODEC_IO_Write(DeviceAddr, 0x422, 0x0200);
    
    /* Disable DAC1L_TO_HPOUT1L */
    counter += CODEC_IO_Write(DeviceAddr, 0x2D, 0x0000);
    
    /* Disable DAC1R_TO_HPOUT1R */
    counter += CODEC_IO_Write(DeviceAddr, 0x2E, 0x0000);
    
    /* Disable DAC1 and DAC2 */
    counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0000);
    
    /* Reset Codec by wrinting in 0x0000 address register */
    counter += CODEC_IO_Write(DeviceAddr, 0x0000, 0x0000);    
  }
  
  return counter;
}
Ejemplo n.º 3
0
/**
  * @brief Sets higher or lower the codec volume level.
  * @param DeviceAddr: Device address on communication Bus.
  * @param Volume: a byte value from 0 to 255 (refer to codec registers 
  *         description for more details).
  * @retval 0 if correct communication, else wrong communication
  */
uint32_t wm8994_SetVolume(uint16_t DeviceAddr, uint8_t Volume)
{
  uint32_t counter = 0;
  uint8_t convertedvol = VOLUME_CONVERT(Volume);

  if(convertedvol > 0x3E)
  {
    /* Unmute audio codec */
    counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
    
    /* Left Headphone Volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x1C, 0x3F | 0x140);
    
    /* Right Headphone Volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x1D, 0x3F | 0x140);
    
    /* Left Speaker Volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x26, 0x3F | 0x140);
    
    /* Right Speaker Volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x27, 0x3F | 0x140);
  }
  else if (Volume == 0)
  {
    /* Mute audio codec */
    counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_ON);
  }
  else
  {
    /* Unmute audio codec */
    counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
    
    /* Left Headphone Volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x1C, convertedvol | 0x140);
    
    /* Right Headphone Volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x1D, convertedvol | 0x140);
    
    /* Left Speaker Volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x26, convertedvol | 0x140);
    
    /* Right Speaker Volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x27, convertedvol | 0x140);
  }
  
  return counter;
}
Ejemplo n.º 4
0
/**
  * @brief Resumes playing on the audio codec.
  * @param DeviceAddr: Device address on communication Bus. 
  * @retval 0 if correct communication, else wrong communication
  */
uint32_t wm8994_Resume(uint16_t DeviceAddr)
{
  uint32_t counter = 0;
 
  /* Resumes the audio file playing */  
  /* Unmute the output first */
  counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
  
  return counter;
}
Ejemplo n.º 5
0
/**
  * @brief Pauses playing on the audio codec.
  * @param DeviceAddr: Device address on communication Bus. 
  * @retval 0 if correct communication, else wrong communication
  */
uint32_t wm8994_Pause(uint16_t DeviceAddr)
{  
  uint32_t counter = 0;
 
  /* Pause the audio file playing */
  /* Mute the output first */
  counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_ON);
  
  /* Put the Codec in Power save mode */
  counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x01);
 
  return counter;
}