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

📄 wm8731audio.c

📁 pxa270平台 windows mobile 5.2 wm9713 触摸屏+音频驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
 * Note: this is not required for AC'97 streams - HIFI and MONO on AC'97
 * codecs.
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      audioIF         the interface to configure
 *      isMaster        whether the codec masters the link
 *      format          the streaming format to use
 *      width           the number of bits per sample
 *      flags           extra configuration flags
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WM8731ConfigureInterface( WM_DEVICE_HANDLE     hDevice,
                                   WM_AUDIO_INTERFACE   audioIF,
                                   WM_BOOL              isMaster,
                                   WM_AUDIOIF_FORMAT    format,
                                   WM_AUDIOIF_WIDTH     width,
                                   WM_AUDIOIF_FLAGS     flags
                                 )
{
    WMSTATUS            status;
    WM_REGVAL           controlVal = 0;

    /*
     * We've only got a HiFi interface.
     */    
    if ( WM_AUDIOIF_HIFI != audioIF )
    {
        WM_TRACE( hDevice, (
                  "WM8731ConfigureInterface: unsupported interface %d",
                  audioIF
                ));
        status = WMS_UNSUPPORTED;
        goto error;
    }
    
    /*
     * Master or slave?
     */
    if ( isMaster )
        controlVal |= WM8731_MASTER;
    else
        controlVal |= WM8731_SLAVE;

    /*
     * Set data format.
     */
    switch ( format )
    {
        case WM_AUDIOIF_I2S:
            controlVal |= WM8731_DATA_FORMAT_I2S;
            break;
            
        case WM_AUDIOIF_LEFT_JUSTIFY:
            controlVal |= WM8731_DATA_FORMAT_LJUST;
            break;
            
        case WM_AUDIOIF_RIGHT_JUSTIFY:
            controlVal |= WM8731_DATA_FORMAT_RJUST;
            break;
            
        case WM_AUDIOIF_DSP_MODE_A:
            controlVal |= WM8731_DATA_FORMAT_DSP | WM8731_DSP_MODE_A;
            break;
    
        case WM_AUDIOIF_DSP_MODE_B:
            controlVal |= WM8731_DATA_FORMAT_DSP | WM8731_DSP_MODE_B;
            break;
        
        default:
            WM_TRACE( hDevice, (
                      "WM8731ConfigureInterface: unsupported format %d",
                      format
                    ));
            status = WMS_UNSUPPORTED;
            goto error;
    }
    
    /*
     * Set data word length.
     */
    switch ( width )
    {
        case WM_AUDIOIF_16BIT:
            controlVal |= WM8731_WORD_LENGTH_16BIT;
            break;
            
        case WM_AUDIOIF_20BIT:
            controlVal |= WM8731_WORD_LENGTH_20BIT;
            break;

        case WM_AUDIOIF_24BIT:
            controlVal |= WM8731_WORD_LENGTH_24BIT;
            break;

        case WM_AUDIOIF_32BIT:
            if ( WM_AUDIOIF_DSP_MODE_A == format ||
                 WM_AUDIOIF_DSP_MODE_B == format
               )
            {
                WM_TRACE( hDevice, (
                          "WM8731ConfigureInterface: 32-bit word length is not supported in DSP mode"
                        ));
                status = WMS_UNSUPPORTED;
                goto error;
            }
            controlVal |= WM8731_WORD_LENGTH_32BIT;
            break;
        
        default:
            WM_TRACE( hDevice, (
                      "WM8731ConfigureInterface: unsupported word length %d",
                      width
                    ));
            status = WMS_UNSUPPORTED;
            goto error;
    }
    
    /*
     * Check for misc extras.
     */
     
    /* Clock inversion */
    if ( flags & WM_AUDIOIF_INVERT_CLOCK )
        controlVal |= WM8731_BITCLKINV;
    
    /* LR clock polarity inversion - doesn't apply to DSP mode */
    if ( flags & WM_AUDIOIF_INVERT_LR_CLOCK )
    {
        if ( WM_AUDIOIF_DSP_MODE_A == format ||
             WM_AUDIOIF_DSP_MODE_B == format
           )
        {
            WM_TRACE( hDevice, (
                      "WM8731ConfigureInterface: LR Clock invert is not relevant in DSP mode"
                    ));
            status = WMS_INVALID_PARAMETER;
            goto error;
        }
        
        controlVal |= WM8731_LRC_INVERT;
    }

    /* Left/right channel swap - only applies to HiFi */
    if ( flags & WM_AUDIOIF_LR_SWAP )
    {
        controlVal |= WM8731_LR_SWAP;
    }
    
    /* Mono - only applies to Voice */
    if ( flags & WM_AUDIOIF_MONO )
    {
        WM_TRACE( hDevice, (
                  "WM8731ConfigureInterface: Mono is not supported"
                ));
        status = WMS_UNSUPPORTED;
        goto error;
    }

    /*
     * Set up the interface.
     */
    status = WMWrite( hDevice, WM8731_INTERFACE_CONTROL, controlVal );
    if ( WM_ERROR( status ) )
    {
        WM_TRACE( hDevice, (
                  "WM8731ConfigureInterface: Write failed: %s",
                  WMStatusText( status )
                ));
        goto error;
    }
    
    /*
     * Make the chip active.
     */
    status = WMWrite( hDevice, WM8731_ACTIVE_CONTROL, WM8731_ACTIVE );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }
    
    /*
     * We're done.
     */
    return WMS_SUCCESS;
    
error:
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WM8731UnconfigureInterface
 *
 * Unconfigures the streaming format for the link for the given interface.
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      audioIF         the interface to configure
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WM8731UnconfigureInterface( WM_DEVICE_HANDLE     hDevice,
                                     WM_AUDIO_INTERFACE   audioIF
                                   )
{
    WMSTATUS            status;
    
    /*
     * We've only got a HiFi interface.
     */    
    if ( WM_AUDIOIF_HIFI != audioIF )
    {
        WM_TRACE( hDevice, (
                  "WM8731ConfigureInterface: unsupported interface %d",
                  audioIF
                ));
        status = WMS_UNSUPPORTED;
        goto error;
    }
    
    /*
     * Make the chip inactive.
     */
    status = WMClearField( hDevice, WM8731_ACTIVE_CONTROL, WM8731_ACTIVE );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }
    
    return WMS_SUCCESS;
    
error:
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WM8731EnableHifiPath
 *
 * Sets up for HiFi across I2S.
 *
 * Parameters:
 *      hDevice      handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WM8731EnableHifiPath( WM_DEVICE_HANDLE hDevice )
{
	WMSTATUS    status = WMS_UNSUPPORTED;

	return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WM8731ConfigureHiFiPath
 *
 * Configure and enable the paths from the DAC to the outputs.
 * NOTE: This function is enabling as many of the outputs as possible
 *       so that there is a good chance that anything coming from the
 *       DAC will end up being heard through any of the outputs.
 *       You will probably want to change this set up to suit your
 *       particular application.
 *
 * Parameters:
 *      hDevice      handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WM8731ConfigureHiFiPath( WM_DEVICE_HANDLE hDevice )
{
	WMSTATUS    status = WMS_UNSUPPORTED;

	return status;
}

#endif  /* WM_AUDIO && WM8731_FAMILY */

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

⌨️ 快捷键说明

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