📄 wmdrivermessage.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: WMDriverMessage.c 2777 2006-03-03 13:33:38Z fb $
*
* This file contains platform-independent routines for handling messages
* passed to the driver from user-mode applications.
*
* Warning:
* This driver is specifically written for Wolfson Codecs. It is not a
* general CODEC device driver.
*
* -----------------------------------------------------------------------------*/
/*
* IMPORTANT
*
* The functions in this file must obey two rules:
*
* 1. They do not use any memory other than stack space and parameters passed in.
* 2. They do not make system calls, unless WMSystemCallsAllowed returns TRUE.
*
* All functions take a context parameter, which passes in pointers to the virtual
* addresses of memory-mapped registers, and stores what type of device is being
* accessed.
*
* Some client functions provide shared memory via the v_pWMData member of the
* context structure. This cannot be relied on. However, the v_pADCData member
* can be relied on by functions in this file.
*/
/*
* Include files
*/
#include "WMCommon.h"
#include "WMDevice.h"
#include "WMGlobals.h"
#include "WMControlLink.h"
#include "WMAudio.h"
#include "WMAudioPaths.h"
#include "WMDriverMessage.h"
#include "WMAudioInternal.h"
#include "WMPower.h"
/*
* Global definitions
*/
/*
* Private data
*/
/*
* Function prototypes
*/
/*-----------------------------------------------------------------------------
* Function: WMDriverMessage
*
* Purpose: Handle any Wolfson Driver messages (including diagnostic
* requests for debugging purposes only).
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* uMsg the message ID
* dwParam1 parameter 1
* dwParam2 parameter 2
*
* Returns: WMSTATUS
* See WMStatus.h.
*
----------------------------------------------------------------------------*/
WMSTATUS WMDriverMessage( WM_DEVICE_HANDLE hDevice,
unsigned int uMsg,
WM_DWORD dwParam1,
WM_DWORD dwParam2
)
{
WM_DEVICE_CONTEXT *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
WM_REGVAL value = 0;
WM_REGTYPE reg;
WMSTATUS status = WMS_UNSUPPORTED;
switch ( uMsg )
{
#if WM_AUDIO
#if WM_AUDIO_STREAM
/* Channel selection */
case WMMSG_SELECT_DEFAULT_OUTPUT:
{
WM_STREAM_ID stream;
WMAUDIO_CHANNEL channel;
stream = (WM_STREAM_ID) dwParam1;
/* Check this is an output stream */
if ( !WM_IS_OUTPUT_STREAM( stream ) || WM_IS_DEFAULT_STREAM( stream ) )
{
WM_TRACE( hDevice, (
"WMDriverMessage - invalid output stream %d",
stream
));
status = WMS_INVALID_PARAMETER;
break;
}
/* Check this stream is supported */
channel = _WMAudioStreamToChannel( hDevice, stream );
if ( WMAUDIO_INVALID_CHANNEL == channel )
{
WM_TRACE( hDevice, (
"WMDriverMessage - unsupported output stream %d",
stream
));
status = WMS_UNSUPPORTED;
break;
}
/* And update our default */
pDeviceContext->defaultOutputStream = stream;
WM_TRACE( hDevice, (
"WMDriverMessage setting default output to %d (channel %d)",
stream,
channel
));
status = WMS_SUCCESS;
break;
}
case WMMSG_SELECT_DEFAULT_INPUT:
{
WM_STREAM_ID stream;
WMAUDIO_CHANNEL channel;
stream = (WM_STREAM_ID) dwParam1;
/* Check this is an input stream */
if ( !WM_IS_INPUT_STREAM( stream ) || WM_IS_DEFAULT_STREAM( stream ) )
{
WM_TRACE( hDevice, (
"WMDriverMessage - invalid input stream %d",
stream
));
status = WMS_INVALID_PARAMETER;
break;
}
/* Check this stream is supported */
channel = _WMAudioStreamToChannel( hDevice, stream );
if ( WMAUDIO_INVALID_CHANNEL == channel )
{
WM_TRACE( hDevice, (
"WMDriverMessage - unsupported input stream %d",
stream
));
status = WMS_UNSUPPORTED;
break;
}
/* And update our default */
pDeviceContext->defaultInputStream = stream;
WM_TRACE( hDevice, (
"WMDriverMessage setting default input to %d (channel %d)",
stream,
channel
));
status = WMS_SUCCESS;
break;
}
#endif /* WM_AUDIO_STREAM */
case WMMSG_SELECT_RECORD_SOURCES:
{
WM_AUDIO_SIGNAL leftInput;
WM_AUDIO_SIGNAL rightInput;
leftInput = (WM_AUDIO_SIGNAL) dwParam1;
rightInput = (WM_AUDIO_SIGNAL) dwParam2;
/* Ensure that the supplied parameters are valid */
if ( ! WM_SIGNAL_IS_RECORDABLE( leftInput ) )
{
WM_TRACE( hDevice, (
"WMDriverMessage - invalid record selection (left) %d",
leftInput)
);
status = WMS_INVALID_PARAMETER;
break;
}
if ( ! WM_SIGNAL_IS_RECORDABLE( rightInput ) )
{
WM_TRACE( hDevice, (
"WMDriverMessage - invalid record selection (right) %d",
rightInput)
);
status = WMS_INVALID_PARAMETER;
break;
}
/* And change our settings */
WM_TRACE( hDevice, (
"WMDriverMessage setting record sources to L = %d, R = %d",
leftInput,
rightInput
));
status = WMAudioSetRecordSources( hDevice, leftInput, rightInput );
if ( WM_ERROR( status ) )
{
WM_TRACE( hDevice, (
"WMDriverMessage: set record sources failed: %s",
WMStatusText( status )
));
break;
}
break;
}
case WMMSG_SELECT_RECORD_PATHS:
{
WM_AUDIO_SIGNAL leftInput;
WM_AUDIO_SIGNAL rightInput;
leftInput = (WM_AUDIO_SIGNAL) dwParam1;
rightInput = (WM_AUDIO_SIGNAL) dwParam2;
/* Ensure that the supplied parameters are valid */
if ( ! WM_SIGNAL_IS_RECORDABLE( leftInput ) )
{
WM_TRACE( hDevice, (
"WMDriverMessage - invalid record selection (left) %d",
leftInput)
);
status = WMS_INVALID_PARAMETER;
break;
}
if ( ! WM_SIGNAL_IS_RECORDABLE( rightInput ) )
{
WM_TRACE( hDevice, (
"WMDriverMessage - invalid record selection (right) %d",
rightInput)
);
status = WMS_INVALID_PARAMETER;
break;
}
/* And change our settings */
WM_TRACE( hDevice, (
"WMDriverMessage setting record paths to L = %d, R = %d",
leftInput,
rightInput
));
status = WMAudioSetRecPaths( hDevice, leftInput, rightInput );
if ( WM_ERROR( status ) )
{
WM_TRACE( hDevice, (
"WMDriverMessage: set record paths failed: %s",
WMStatusText( status )
));
break;
}
break;
}
case WMMSG_UNSELECT_RECORD_PATHS:
{
WM_AUDIO_SIGNAL leftInput;
WM_AUDIO_SIGNAL rightInput;
leftInput = (WM_AUDIO_SIGNAL) dwParam1;
rightInput = (WM_AUDIO_SIGNAL) dwParam2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -