⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wm9713audio.c

📁 pxa270平台 windows mobile 5.2 wm9713 触摸屏+音频驱动
💻 C
字号:
/*-----------------------------------------------------------------------------
 * Copyright (c) Wolfson Microelectronics plc.  All rights reserved.
 *
 * This software as well as any related documentation is furnished under 
 * license and may only be used or copied in accordance with the terms of the 
 * license. The information in this file is furnished for informational use 
 * only, is subject to change without notice, and should not be construed as 
 * a commitment by Wolfson Microelectronics plc. Wolfson Microelectronics plc
 * assumes no responsibility or liability for any errors or inaccuracies that
 * may appear in this document or any software that may be provided in
 * association with this document. 
 *
 * Except as permitted by such license, no part of this document may be 
 * reproduced, stored in a retrieval system, or transmitted in any form or by 
 * any means without the express written consent of Wolfson Microelectronics plc. 
 *
 * $Id: WM9713Audio.c 2348 2005-10-24 15:58:21Z ib $
 *
 * Configure the Voice interface for and AC97 device.
 *
 * Warning:
 *  This driver is specifically written for Wolfson Codecs. It is not a 
 *  general CODEC device driver.
 *
 * --------------------------------------------------------------------------*/

/*
 * Include files
 */
#include "WMCommon.h"
#include "WMDevice.h"
#include "WMControlLink.h"
#include "WMPlatformDebug.h"
#include "WMGPIO.h"
#include "WM9713Audio.h"

/*
 * Only build this if we're doing Audio Voice support for WM9713 devices.
 */
#if WM_AUDIO && WM9713_FAMILY

 /*
 * Global definitions
 */

/*
 * Function prototypes
 */

/*-----------------------------------------------------------------------------
 * Function:    WM9713EnableStream
 *
 * Device-specific stuff for enabling a given stream.
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      stream          The stream to enable
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WM9713EnableStream( WM_DEVICE_HANDLE hDevice,
                             WM_STREAM_ID     ifStream
                           )
{
    WMSTATUS            status;
    WM_STREAM_ID        stream = _WMAudioGetRealStream( hDevice, ifStream );
    
    switch ( stream )
    {
        case WM_STREAM_HIFI_IN:
        case WM_STREAM_HIFI_OUT:
        case WM_STREAM_MONO_OUT:
            /* These are enabled by default */
            status = WMS_SUCCESS;
            break;

#if WM_VOICE
        case WM_STREAM_VOICE_OUT:
            status = WM9713VoiceEnable( hDevice );
            break;
#endif  /* WM_VOICE */

		case WM_STREAM_VOICE_IN:
			/* Voice in is not supported yet */
        default:
            status = WMS_UNSUPPORTED;
            break;
    }
    
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WM9713DisableStream
 *
 * Device-specific stuff for disabling a given stream.
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      stream          The stream to enable
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WM9713DisableStream( WM_DEVICE_HANDLE hDevice,
                                   WM_STREAM_ID     ifStream
                                 )
{
    /*
     * AC'97 stream are implicitly enabled - the power-down, etc is handled
     * at a higher level.
     */
    return WMS_SUCCESS;
}

#if WM_VOICE
/*-----------------------------------------------------------------------------
 * Function:    WM9713VoiceEnable
 *
 * Enable the Voice DAC Interface
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WM9713VoiceEnable( WM_DEVICE_HANDLE hDevice )
{
    WMSTATUS status;

    /*
     * Configure the GPIOs used by the Voice interface for
     * master mode.
     *
     * GPIO1 : PCMCLK - Output
     * GPIO3 : PCMFS  - Output
     * GPIO4 : PCMDAC - Input
     * GPIO5 : PCMADC - Not Supported (Input)
     */

    status = WMGPIOConfig( hDevice, WM_GPIO_1, WM_GPIO_OUTPUT );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }

    status = WMGPIOConfig( hDevice, WM_GPIO_3, WM_GPIO_OUTPUT );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }

    status = WMGPIOConfig( hDevice, WM_GPIO_4, WM_GPIO_INPUT );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }

    /*
     * We do not support voice record at the moment so we
     * have configured PCMADC as an input.
     */
    status = WMGPIOConfig( hDevice, WM_GPIO_5, WM_GPIO_INPUT );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }

    /*
     * Enable the Voice DAC interface in master mode.
     */
    status = WMSetField( hDevice,
                         WM9713_VOICE_CODEC_CONTROL,
                         ( WM9713_VOICE_ENABLE        |
                           WM9713_VOICE_MODE_MASTER   |
                           WM9713_VOICE_DIV_VXDAC_CLK |
                           WM9713_VOICE_VDACOSR       |
                           WM9713_VOICE_SEL_LEFT_ADC  |
                           WM9713_VOICE_WL_16_BITS    |
                           WM9713_VOICE_FMT_DSP ),
                         ( WM9713_VOICE_CTRL          |
                           WM9713_VOICE_MODE_MASK     |
                           WM9713_VOICE_DIV_MASK      |
                           WM9713_VOICE_VDACOSR       |
                           WM9713_VOICE_SEL_MASK      |
                           WM9713_VOICE_WL_MASK       |
                           WM9713_VOICE_FMT_MASK )
                        );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }

    return WMS_SUCCESS;

error:
    return status;
}


/*-----------------------------------------------------------------------------
 * Function:    WM9713VoiceSetRate
 *
 * Set the Voice DAC sample rate
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *      sampleRate   The requested sample rate.
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WM9713VoiceSetRate( WM_DEVICE_HANDLE hDevice, 
                             WM_SAMPLE_RATE   sampleRate 
                         )
{
    WMSTATUS status = WMS_SUCCESS;
    WM_REGVAL pcmSampleRate = 0;

    switch ( sampleRate )
    {
        case WM_SAMPLE_RATE_8K:
            pcmSampleRate = WM_VOICE_SAMPLE_RATE_8K;
            break;
        case WM_SAMPLE_RATE_12K:
            pcmSampleRate = WM_VOICE_SAMPLE_RATE_12K;
            break;
        case WM_SAMPLE_RATE_16K:
            pcmSampleRate = WM_VOICE_SAMPLE_RATE_16K;
            break;
        case WM_SAMPLE_RATE_24K:
            pcmSampleRate = WM_VOICE_SAMPLE_RATE_24K;
            break;
        case WM_SAMPLE_RATE_32K:
            pcmSampleRate = WM_VOICE_SAMPLE_RATE_32K;
            break;
        case WM_SAMPLE_RATE_48K:
            pcmSampleRate = WM_VOICE_SAMPLE_RATE_48K;
            break;
        case WM_SAMPLE_RATE_96K:
            pcmSampleRate = WM_VOICE_SAMPLE_RATE_96K;
            break;
        default :
            status = WMS_INVALID_PARAMETER;
            goto finish;
    }

    status = WMSetField( hDevice,
                         WM9713_MCLK_CONTROL_1,
                         ( WM_VOICECTRL_CLKSRC_EXTERNAL |
                           pcmSampleRate ),
                         ( WM_VOICECTRL_CLKSRC_EXTERNAL |
                           WM_VOICECTRL_SEXT_VOICE_MASK )
                       );

finish:
    return status;
}

#ifdef DEBUG
/*-----------------------------------------------------------------------------
 * Function:    WM9713VoiceDumpRegs
 *
 * Dump all the Voice DAC related registers
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     none
 *---------------------------------------------------------------------------*/
void WM9713VoiceDumpRegs( WM_DEVICE_HANDLE hDevice )
{
    WM_REGVAL pcmSetup = 0;

	WM_TRACE( hDevice, ("  WM9713 Voice DAC Reg Dump") );
	WM_TRACE( hDevice, ("-----------------------------") );

    WMRead( hDevice, WM9713_VOICE_CODEC_CONTROL, &pcmSetup );

    WM_TRACE( hDevice, ("Voice DAC Codec Control 0x36 = 0x%04X", pcmSetup ) );

    WMRead( hDevice, WM9713_MCLK_CONTROL_1, &pcmSetup );

    WM_TRACE( hDevice, ("MCLK/PLL Control 1 0x44 = 0x%04X", pcmSetup ) );

    WMRead( hDevice, WM9713_MCLK_CONTROL_2, &pcmSetup );

    WM_TRACE( hDevice, ("MCLK/PLL Control 2 0x46 = 0x%04X", pcmSetup ) );

    WMPlatformDumpSSP2Regs( hDevice );
}
#endif /* DEBUG */

#endif /* WM_VOICE */
#endif /* WM_AUDIO && WM9713_FAMILY */

/*------------------------------ END OF FILE ---------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -