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

📄 hwctxt.h

📁 pxa270平台 windows mobile 5.2 wm9713 触摸屏+音频驱动
💻 H
字号:
#pragma once
//-----------------------------------------------------------------------------
// 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: hwctxt.h 3998 2006-10-03 13:00:37Z fb $
//
// This file provides the rest of the WaveDev2 driver with the access to
// Wolfson codecs via the Wolfson Driver API.
//
// Warning:
//  This driver is specifically written for Wolfson Audio Codecs.  It is
//  not a general audio CODEC device driver.
//-----------------------------------------------------------------------------

//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// -----------------------------------------------------------------------------
//
//      THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//      ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//      THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//      PARTICULAR PURPOSE.
//
// -----------------------------------------------------------------------------

#if defined ( WM_BSP_MAINSTONEII )  || defined( WM_BSP_INTEL_DBPXA27X ) || defined( WM_BSP_MAINSTONEIII )
#   include "bsp.h"
#else
#   include <oalintr.h>
#endif
#include <WaveDev.h>

#include "WDCL.h"

#define BITSPERSAMPLE (16)

typedef INT16 HWSAMPLE;
typedef HWSAMPLE *PHWSAMPLE;

typedef INT32 LHWSAMPLE;
typedef LHWSAMPLE *PLHWSAMPLE;

// Set USE_MIX_SATURATE to 1 if you want the mixing code to guard against saturation
// This costs a couple of instructions in the inner loop
#define USE_MIX_SATURATE (1)
// The code will use the follwing values as saturation points
#define AUDIO_SAMPLE_MAX    (32767)
#define AUDIO_SAMPLE_MIN    (-32768)

// Define MONO_GAIN to force all gain to be mono (left volume applied to both channels)
#define MONO_GAIN 1

// The following define the maximum attenuations for the SW volume controls in devctxt.cpp
// e.g. 100 => range is from 0dB to -100dB
#define STREAM_ATTEN_MAX       100

#define DEVICE_ATTEN_MAX        35

#define CLASS_ATTEN_MAX         35

/*
 * Shared audio data. This data is
 * shared between the device process
 * and the power management process
 */
typedef struct tagWM_SHARED_AUDIO_DATA WM_SHARED_AUDIO_DATA;

struct tagWM_SHARED_AUDIO_DATA
{   
    BOOL   inPowerHandler;
    BOOL   HiFiInputDMARunning;
    BOOL   HiFiOutputDMARunning;
    BOOL   VoiceInputDMARunning;
    BOOL   VoiceOutputDMARunning;
    BOOL   MonoOutputDMARunning;
#if WM_OUTPUT_MUTE_DELAY
    BOOL   HiFiOutputMuted;
    BOOL   VoiceOutputMuted;
    BOOL   MonoOutputMuted;
    BOOL   OutputMuteTimerStarted;
#endif
};

#define WM_GLOBAL_DATA_MUTEX_NAME  _T("WMGlobalDataMutex")

#define WM_GLOBAL_DATA_TIME_OUT    5000 /* 5 second timeout */

#define WM_OUTPUT_MUTE_TIMEOUT_EVENT_NAME _T("WMOutputMuteTimoutEvent")

//-----------------------------------------------------------------------------
// Class:    HardwareContext
//
// This class handles the communication with the codec, so the rest
// of the driver doesn't have to worry about it.
//-----------------------------------------------------------------------------
class HardwareContext
{
public:
    static BOOL CreateHWContext(DWORD Index);
    HardwareContext();
    ~HardwareContext();

    void Lock()   {EnterCriticalSection(&m_Lock);}
    void Unlock() {LeaveCriticalSection(&m_Lock);}

    DWORD GetNumInputDevices()  {
		//
		// HiFi & Voice may or may not be available, 
		// depending on compiled options and Codec present
		// To ensure constant device IDs we must tell the system that 
		// 2 devices are available.
		//

		return 2;
	}
    DWORD GetNumOutputDevices()
    {
		//
		// HiFi is always present,
		// Voice and Mono may or may not be available, 
		// depending on compiled options and Codec present
		// To ensure constant device IDs we must tell the system that 
		// 3 devices are available.
		//
        return 3;
    }

   //
   // For WM8753 the Voice interface is the only input interface that
   // is currently supported.
   // For all other codecs the HiFi interface is the only input interface
   // that is supported.
   //
    DeviceContext *GetInputDeviceContext(UINT DeviceId)
    {
#if WM_VOICE
		if ( WM_IS_VOICE_SUPPORTED( m_hAudioDevice ) )
		{
			if ( AUDIO_VOICE_DEV_ID == DeviceId )
			{
				if ( IS_WM8753_FAMILY( m_hAudioDevice ) )
				{
					return &m_VoiceInputDeviceContext;
				}
				else
				{
					// A valid ID has not been given => return NULL.
					return (DeviceContext *)NULL;
				}
			}
		}
#endif // WM_VOICE
        if ( AUDIO_HIFI_DEV_ID == DeviceId )
        {
			if ( !IS_WM8753_FAMILY( m_hAudioDevice ) )
			{
				return &m_HiFiInputDeviceContext;
			}
			else
			{
				// A valid ID has not been given => return NULL.
				return (DeviceContext *)NULL;
			}
		}

		// A valid ID has not been given => return NULL.
		return (DeviceContext *)NULL;
	}

	DeviceContext *GetOutputDeviceContext(UINT DeviceId)
	{
#if WM_VOICE
		if (WM_IS_VOICE_SUPPORTED( m_hAudioDevice ) )
		{
			if ( AUDIO_VOICE_DEV_ID == DeviceId )
			{
				return &m_VoiceOutputDeviceContext;
			}
		}
#endif // WM_VOICE
#if WM_MONODAC
		if ( WM_IS_MONO_SUPPORTED( m_hAudioDevice ) )
		{
			if ( AUDIO_MONODAC_DEV_ID == DeviceId )
			{
				return &m_MonoOutputDeviceContext;
			}
		}
#endif // WM_MONODAC
        if ( AUDIO_HIFI_DEV_ID == DeviceId )
		{
			// There is _always_ a HiFi device present
        	return &m_HiFiOutputDeviceContext;
        }

		// A valid ID has not been given => return NULL.
		return (DeviceContext *)NULL;
	}

    BOOL Init(DWORD Index);
	BOOL Deinit();

    void PowerUp();
    void PowerDown();

    void StartHiFiInputDMA();
    void StartHiFiOutputDMA();
#if WM_VOICE
    void StartVoiceInputDMA();
    void StartVoiceOutputDMA();
#endif // WM_VOICE
#if WM_MONODAC
    void StartMonoOutputDMA();
#endif // WM_MONODAC

    void StopHiFiInputDMA( volatile WM_SHARED_AUDIO_DATA *pWMAudioData );
    void StopHiFiOutputDMA( volatile WM_SHARED_AUDIO_DATA *pWMAudioData );
#if WM_VOICE
    void StopVoiceInputDMA( volatile WM_SHARED_AUDIO_DATA *pWMAudioData );
    void StopVoiceOutputDMA( volatile WM_SHARED_AUDIO_DATA *pWMAudioData );
#endif // WM_VOICE
#if WM_MONODAC
    void StopMonoOutputDMA( volatile WM_SHARED_AUDIO_DATA *pWMAudioData );
#endif // WM_MONODAC

#if WM_USE_DYNAMIC_DMA_CHANNEL
    void HiFiInputInterruptThread();
    void HiFiOutputInterruptThread();
#   if WM_VOICE
    void VoiceInputInterruptThread();
    void VoiceOutputInterruptThread();
#   endif // WM_VOICE
#   if WM_MONODAC
    void MonoOutputInterruptThread();
#   endif // WM_MONODAC
#else // WM_USE_DYNAMIC_DMA_CHANNEL
    void InterruptThread();
#endif // WM_USE_DYNAMIC_DMA_CHANNEL

#if WM_OUTPUT_MUTE_DELAY
    void OutputMuteInterruptThread();
#endif
    
    DWORD HandleDriverMessage( UINT uDeviceId,
                               UINT uMsg,
                               DWORD dwParam1,
                               DWORD dwParam2
                             );

    BOOL PmControlMessage ( DWORD  dwCode,
                            PBYTE  pBufIn,
                            DWORD  dwLenIn,
                            PBYTE  pBufOut,
                            DWORD  dwLenOut,
                            PDWORD pdwActualOut
                          );

    DWORD ForceSpeaker (BOOL bSpeaker);

    DWORD SetOutputGain( DWORD dwGain );
    DWORD GetOutputGain(void );

    DWORD SetHardwareVolume( WM_STREAM_ID stream,
                             volatile WM_SHARED_AUDIO_DATA *pWMAudioData,
                             ULONG volume
                           );

    DWORD LockGlobalData( HANDLE hGlobalData )
    {
        //
        // Lock our global data access
        //
        if ( WAIT_OBJECT_0 != ( WaitForSingleObject( hGlobalData, WM_GLOBAL_DATA_TIME_OUT ) ) )
        {
            ASSERT( GetLastError() );
            return MMSYSERR_ERROR;
        }
        else
            return MMSYSERR_NOERROR;
    }
    
    void UnlockGlobalData( HANDLE hGlobalData )
    {
        ReleaseMutex( hGlobalData );
    }



protected:
    WM_DEVICE_HANDLE m_hAudioDevice;
    WM_STREAM_HANDLE m_hHiFiOutputStream;
    WM_STREAM_HANDLE m_hHiFiInputStream;
#if WM_VOICE
    WM_STREAM_HANDLE m_hVoiceOutputStream;
    WM_STREAM_HANDLE m_hVoiceInputStream;
#endif // WM_VOICE
#if WM_MONODAC
    WM_STREAM_HANDLE m_hMonoOutputStream;
#endif // WM_MONODAC

    int m_nextHiFiOutputBuf;
    BOOL m_HiFiOutputStarted;
    int m_nextHiFiInputBuf;
    BOOL m_HiFiInputStarted;
#if WM_VOICE
    int m_nextVoiceOutputBuf;
    BOOL m_VoiceOutputStarted;
    int m_nextVoiceInputBuf;
    BOOL m_VoiceInputStarted;
#endif // WM_VOICE
#if WM_MONODAC
    int m_nextMonoOutputBuf;
    BOOL m_MonoOutputStarted;
#endif // WM_MONODAC

	BOOL m_shuttingDown;

    DWORD m_MicrophoneRouting;
    DWORD m_SpeakerRouting;
    DWORD m_InternalRouting;
    DWORD m_MasterOutputVolume;
    BOOL  m_MasterOutputMute;
    
#if WM_OUTPUT_MUTE_DELAY
    HANDLE m_hOutputMuteIntEvent;
    HANDLE m_hOutputMuteTimeoutEvent;
    HANDLE m_hOutputMuteInterruptThread;
    BOOL   InitOutputMuteTimerThread();
#endif


//
// When the volume is zero we mute the
// codec so that we get maximum attenuation.
// This global define allows us to check if
// we are at zero volume and should leave
// the codec outputs muted.
//
    BOOL  m_OutputMaxAtten;

    WM_CHIPTYPE m_deviceType;

    WM_AUDIO_SIGNAL m_SignalL;
    WM_AUDIO_SIGNAL m_SignalR;

    BOOL InitInterruptThread();

    BOOL InitCodec();

    BOOL TransferHiFiInputBuffer(ULONG NumBuf, ULONG *pBytesTransferred);
    BOOL TransferHiFiOutputBuffer(ULONG NumBuf, ULONG *pBytesTransferred);
#if WM_VOICE
    BOOL TransferVoiceInputBuffer(ULONG NumBuf, ULONG *pBytesTransferred);
    BOOL TransferVoiceOutputBuffer(ULONG NumBuf, ULONG *pBytesTransferred);
#endif // WM_VOICE
#if WM_MONODAC
    BOOL TransferMonoOutputBuffer(ULONG NumBuf, ULONG *pBytesTransferred);
#endif // WM_MONODAC
    ULONG TransferHiFiInputBuffers();
    ULONG TransferHiFiOutputBuffers();
#if WM_VOICE
    ULONG TransferVoiceInputBuffers();
    ULONG TransferVoiceOutputBuffers();
#endif // WM_VOICE
#if WM_MONODAC
    ULONG TransferMonoOutputBuffers();
#endif // WM_MONODAC

    DWORD GetInterruptThreadPriority();

    DWORD m_DriverIndex;
    CRITICAL_SECTION m_Lock;

    BOOL m_Initialized;
#if !WM_USE_DYNAMIC_DMA_CHANNEL
    DWORD m_IntrAudio;
#endif // WM_USE_DYNAMIC_DMA_CHANNEL
    HiFiInputDeviceContext m_HiFiInputDeviceContext;
    HiFiOutputDeviceContext m_HiFiOutputDeviceContext;
#if WM_VOICE
    VoiceInputDeviceContext m_VoiceInputDeviceContext;
    VoiceOutputDeviceContext m_VoiceOutputDeviceContext;
#endif // WM_VOICE
#if WM_MONODAC
    MonoOutputDeviceContext m_MonoOutputDeviceContext;
#endif // WM_MONODAC

    volatile WM_SHARED_AUDIO_DATA *m_pWMAudioDeviceData;

    HANDLE m_hGlobalDataDeviceMutex;

    ULONG m_HiFiOutBytes[2];
    ULONG m_HiFiInBytes[2];
#if WM_VOICE
    ULONG m_VoiceInBytes[2];
    ULONG m_VoiceOutBytes[2];
#endif // WM_VOICE
#if WM_MONODAC
    ULONG m_MonoOutBytes[2];
#endif // WM_MONODAC

    ULONG m_nVolume;        // Current HW Playback Volume (should be in device context??)
#if WM_USE_DYNAMIC_DMA_CHANNEL
    HANDLE  hHiFiOutputIntEvent;
	HANDLE  hHiFiInputIntEvent;
#   if WM_VOICE
    HANDLE  hVoiceOutputIntEvent;
    HANDLE  hVoiceInputIntEvent;
#   endif // WM_VOICE
#   if WM_MONODAC
    HANDLE  hMonoOutputIntEvent;
#   endif // WM_MONODAC
    HANDLE  m_hAudioHiFiOutputInterruptThread;
	HANDLE  m_hAudioHiFiInputInterruptThread;
#   if WM_VOICE
    HANDLE  m_hAudioVoiceInputInterruptThread;
    HANDLE  m_hAudioVoiceOutputInterruptThread;
#   endif // WM_VOICE
#   if WM_MONODAC
    HANDLE  m_hAudioMonoOutputInterruptThread;
#   endif // WM_MONODAC
#else // WM_USE_DYNAMIC_DMA_CHANNEL
    HANDLE m_hAudioInterrupt;          // Handle to Audio Interrupt event.
    HANDLE m_hAudioInterruptThread;    // Handle to thread which waits on an audio interrupt event.
#endif // WM_USE_DYNAMIC_DMA_CHANNEL
    LONG m_NumForcedSpeaker;
    void SetSpeakerEnable(BOOL bEnable);
    void RecalcSpeakerEnable();
    DWORD private_MuteAllOutputs( WM_STREAM_ID stream,
                                  volatile WM_SHARED_AUDIO_DATA *pWMAudioData,
                                  BOOL mute 
                                );
    DWORD private_PrepareOutputPaths( WM_STREAM_ID stream,
                                      volatile WM_SHARED_AUDIO_DATA *pWMAudioData,
                                      BOOL enable 
                                    );
    DWORD private_PrepareInputPaths( WM_STREAM_ID stream,
                                     volatile WM_SHARED_AUDIO_DATA *pWMAudioData,
                                     BOOL enable 
                                   );

    CEDEVICE_POWER_STATE m_DxState;
};

void CallInterruptThread(HardwareContext *pHWContext);

extern HardwareContext *g_pHWContext;

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

⌨️ 快捷键说明

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