Exemple #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;
  }
/**
  * @brief  Configure the audio peripherals.
  * @param  OutputDevice: OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE,
  *                       OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO .
  * @param  Volume: Initial volume level (from 0 (Mute) to 100 (Max))
  * @param  AudioFreq: Audio frequency used to play the audio stream.
  * @retval 0 if correct communication, else wrong communication
  */
uint32_t EVAL_AUDIO_Init(uint16_t OutputDevice, uint8_t Volume,
			 uint32_t AudioFreq)
{
	/* Perform low layer Codec initialization */
	if (Codec_Init(OutputDevice, VOLUME_CONVERT(Volume), AudioFreq) != 0) {
		return 1;
	} else {
		/* I2S data transfer preparation:
		   Prepare the Media to be used for the audio transfer from memory to I2S peripheral */
		Audio_MAL_Init();

		/* Return 0 when all operations are OK */
		return 0;
	}
}
Exemple #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;
}
/**
  * @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 cs42l52_SetVolume(uint16_t DeviceAddr, uint8_t Volume)
{
  uint32_t counter = 0;
  uint8_t convertedvol = VOLUME_CONVERT(Volume);

  if(Volume > 0xE6)
  {
    /* Set the Master volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x20, convertedvol - 0xE7); 
    counter += CODEC_IO_Write(DeviceAddr, 0x21, convertedvol - 0xE7);     
  }
  else
  {
    /* Set the Master volume */
    counter += CODEC_IO_Write(DeviceAddr, 0x20, convertedvol + 0x19); 
    counter += CODEC_IO_Write(DeviceAddr, 0x21, convertedvol + 0x19); 
  }

  return counter;
}
Exemple #5
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 cs43l22_SetVolume(uint16_t DeviceAddr, uint8_t Volume)
{
  uint32_t counter = 0;
  uint8_t convertedvol = VOLUME_CONVERT(Volume);

  if(Volume > 0xE6)
  {
    /* Set the Master volume */
    counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MASTER_A_VOL, convertedvol - 0xE7); 
    counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MASTER_B_VOL, convertedvol - 0xE7);     
  }
  else
  {
    /* Set the Master volume */
    counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MASTER_A_VOL, convertedvol + 0x19); 
    counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MASTER_B_VOL, convertedvol + 0x19); 
  }

  return counter;
}
/**
  * @brief Controls the current audio volume level. 
  * @param Volume: Volume level to be set in percentage from 0% to 100% (0 for 
  *        Mute and 100 for Max volume level).
  * @retval o if correct communication, else wrong communication
  */
uint32_t EVAL_AUDIO_VolumeCtl(uint8_t Volume)
{
  /* Call the codec volume control function with converted volume value */
  return (Codec_VolumeCtrl(VOLUME_CONVERT(Volume)));
}