Chinaunix首页 | 论坛 | 博客
  • 博客访问: 245797
  • 博文数量: 35
  • 博客积分: 1415
  • 博客等级: 上尉
  • 技术积分: 334
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-10 21:31
文章分类

全部博文(35)

文章存档

2010年(22)

2009年(13)

我的朋友

分类: 嵌入式

2010-03-17 10:31:15

初始化Codec后,只需要修改如下两个函数即可。另外要注意数据格式(LSB,MSB, I2S)

BOOL
HardwareContext::CodecPowerControl()
{
    USHORT powerCtrl1;
    USHORT powerCtrl2;

    powerCtrl1 = ReadCodecRegister(CS42L52__POWER_CONTROL_1);
    powerCtrl2 = ReadCodecRegister(CS42L52__POWER_CONTROL_2);

    if( m_bInputDMARunning & m_bOutputDMARunning ) // ADC, DAC power up

    {
        RETAILMSG(HWC_MSG,(_T("Codec_channel() - In & Out\r\n")));

        WriteCodecRegister(CS42L52__POWER_CONTROL_1, (powerCtrl1 & ( CS42L52_POWERUP_ADC_CHARGE_PUMP |
                                                                     CS42L52_POWERUP_PGA_A |
                                                                     CS42L52_POWERUP_PGA_B |
                                                                     CS42L52_POWERUP_ADC_A |
                                                                     CS42L52_POWERUP_ADC_B |
                                                                     CS42L52_POWERUP_CODEC )));

        WriteCodecRegister(CS42L52__POWER_CONTROL_2, (powerCtrl2 & ( CS42L52_POWERDOWN_ADC_A_OVERRIDE_ENABLE |
                                                                     CS42L52_POWERDOWN_ADC_B_OVERRIDE_ENABLE |
                                                                     CS42L52_POWERUP_MIC_A |
                                                                     CS42L52_POWERUP_MIC_B |
                                                                     CS42L52_POWERUP_MIC_BIAS )));

        WriteCodecRegister(CS42L52__POWER_CONTROL_3, ( CS42L52_HEADPHONE_A_ON_PIN31_HI |
                                                       CS42L52_HEADPHONE_B_ON_PIN31_HI |
                                                       CS42L52_SPEAKER_A_ON_PIN31_LO |
                                                       CS42L52_SPEAKER_B_ON_PIN31_LO ));
    }
    else if( m_bInputDMARunning ) // ADC power up, DAC power down

    {
        RETAILMSG(HWC_MSG,(_T("Codec_channel() - In\r\n")));
         
        WriteCodecRegister(CS42L52__POWER_CONTROL_1, (powerCtrl1 & ( CS42L52_POWERUP_ADC_CHARGE_PUMP |
                                                                     CS42L52_POWERUP_PGA_A |
                                                                     CS42L52_POWERUP_PGA_B |
                                                                     CS42L52_POWERUP_ADC_A |
                                                                     CS42L52_POWERUP_ADC_B |
                                                                     CS42L52_POWERUP_CODEC )));

        WriteCodecRegister(CS42L52__POWER_CONTROL_2, (powerCtrl2 & ( CS42L52_POWERDOWN_ADC_A_OVERRIDE_ENABLE |
                                                                     CS42L52_POWERDOWN_ADC_B_OVERRIDE_ENABLE |
                                                                     CS42L52_POWERUP_MIC_A |
                                                                     CS42L52_POWERUP_MIC_B |
                                                                     CS42L52_POWERUP_MIC_BIAS )));

        WriteCodecRegister(CS42L52__POWER_CONTROL_3, ( CS42L52_HEADPHONE_A_ALWAYS_OFF |
                                                       CS42L52_HEADPHONE_B_ALWAYS_OFF |
                                                       CS42L52_SPEAKER_A_ALWAYS_OFF |
                                                       CS42L52_SPEAKER_B_ALWAYS_OFF ));

    }
    else if( m_bOutputDMARunning ) // DAC power up, ADC power down

    {
        RETAILMSG(HWC_MSG,(_T("Codec_channel() - Out\r\n")));

        WriteCodecRegister(CS42L52__POWER_CONTROL_1, (powerCtrl1 & ( CS42L52_POWERUP_ADC_CHARGE_PUMP |
                                                                     CS42L52_POWERDOWN_PGA_A |
                                                                     CS42L52_POWERDOWN_PGA_B |
                                                                     CS42L52_POWERDOWN_ADC_A |
                                                                     CS42L52_POWERDOWN_ADC_B |
                                                                     CS42L52_POWERDOWN_CODEC )));

        WriteCodecRegister(CS42L52__POWER_CONTROL_2, (powerCtrl2 & ( CS42L52_POWERDOWN_ADC_A_OVERRIDE_DISABLE |
                                                                     CS42L52_POWERDOWN_ADC_B_OVERRIDE_DISABLE |
                                                                     CS42L52_POWERDOWN_MIC_A |
                                                                     CS42L52_POWERDOWN_MIC_B |
                                                                     CS42L52_POWERDOWN_MIC_BIAS )));

        WriteCodecRegister(CS42L52__POWER_CONTROL_3, ( CS42L52_HEADPHONE_A_ON_PIN31_HI |
                                                       CS42L52_HEADPHONE_B_ON_PIN31_HI |
                                                       CS42L52_SPEAKER_A_ON_PIN31_LO |
                                                       CS42L52_SPEAKER_B_ON_PIN31_LO ));
    }
    else // ADC/DAC power down

    {
        RETAILMSG(HWC_MSG,(_T("Codec_channel() - none\r\n")));

        WriteCodecRegister(CS42L52__POWER_CONTROL_1, (powerCtrl1 & ( CS42L52_POWERUP_ADC_CHARGE_PUMP |
                                                                     CS42L52_POWERDOWN_PGA_A |
                                                                     CS42L52_POWERDOWN_PGA_B |
                                                                     CS42L52_POWERDOWN_ADC_A |
                                                                     CS42L52_POWERDOWN_ADC_B |
                                                                     CS42L52_POWERDOWN_CODEC )));

        WriteCodecRegister(CS42L52__POWER_CONTROL_2, (powerCtrl2 & ( CS42L52_POWERDOWN_ADC_A_OVERRIDE_DISABLE |
                                                                     CS42L52_POWERDOWN_ADC_B_OVERRIDE_DISABLE |
                                                                     CS42L52_POWERDOWN_MIC_A |
                                                                     CS42L52_POWERDOWN_MIC_B |
                                                                     CS42L52_POWERDOWN_MIC_BIAS )));

        WriteCodecRegister(CS42L52__POWER_CONTROL_3, ( CS42L52_HEADPHONE_A_ALWAYS_OFF |
                                                       CS42L52_HEADPHONE_B_ALWAYS_OFF |
                                                       CS42L52_SPEAKER_A_ALWAYS_OFF |
                                                       CS42L52_SPEAKER_B_ALWAYS_OFF ));
    }

    return(TRUE);
}


BOOL
HardwareContext::CodecMuteControl(DWORD channel, BOOL bMute)
{
    USHORT val;

    if(channel & DMA_CH_OUT)
    {
        val = ReadCodecRegister(CS42L52__PLAYBACK_CONTROL_2);

        if(bMute)
        {
            WriteCodecRegister(CS42L52__PLAYBACK_CONTROL_2, (val & (CS42L52_SPEAKER_A_MUTE_ENABLE | CS42L52_SPEAKER_B_MUTE_ENABLE)));
        }
        else
        {

            WriteCodecRegister(CS42L52__PLAYBACK_CONTROL_2, (val & (CS42L52_SPEAKER_A_MUTE_DISABLE| CS42L52_SPEAKER_B_MUTE_DISABLE)));
        }
    }
    if(channel & DMA_CH_IN)
    {
        val = ReadCodecRegister(CS42L52__MISC_ADC_CONTROL);

        if(bMute)
        {
            WriteCodecRegister(CS42L52__MISC_ADC_CONTROL, (val & (CS42L52_ADC_A_MUTE_ENABLE | CS42L52_ADC_A_MUTE_ENABLE)));
        }
        else
        {
            WriteCodecRegister(CS42L52__MISC_ADC_CONTROL, (val & (CS42L52_ADC_A_MUTE_DISABLE | CS42L52_ADC_B_MUTE_DISABLE)));
        }
    }
    return(TRUE);
}


阅读(1775) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~