📄 wmprofiles.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: WMProfiles.c 2370 2005-11-07 17:01:18Z ib $
*
* This file contains the profile interface, which allows standard
* configurations to be prepared in advance and loaded with a single
* function call.
*
* Warning:
* This driver is specifically written for Wolfson Codecs. It is not a
* general CODEC device driver.
*
*---------------------------------------------------------------------------*/
/*
* Include files
*/
#include "WMCommon.h"
#include "WMProfiles.h"
#include "WMControlLink.h"
#include <ctype.h>
/*
* Global definitions
*/
/*
* Function prototypes
*/
static const WM_PROFILE *private_FindProfile( const char *name,
WM_CHIPTYPE deviceType,
const WM_PROFILE *profiles,
unsigned int nProfiles
);
static WM_BOOL private_NamesMatch( const char *name1, const char *name2 );
/*-----------------------------------------------------------------------------
* Function: WMLoadProfile
*
* Loads a pre-prepared configuration (set of register settings/changes)
* to the device.
*
* Note:
* - if there is an action with an unrecognised action field, or if there
* is a bad parameter to a recognised action, all other actions will
* still be executed and this function will effectively skip over the
* bad one(s).
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* pActions The actions to take
* nActions Number of actions in the pActions array
*
* Returns: WMSTATUS
* The first error status, or WMS_SUCCESS if all actions completed
* successfully. Note: even if this function returns an error status,
* some actions may have been executed.
*---------------------------------------------------------------------------*/
WMSTATUS WMLoadProfile( WM_DEVICE_HANDLE hDevice,
const WM_ACTION *pActions,
unsigned int nActions
)
{
WMSTATUS status = WMS_SUCCESS;
unsigned int action;
const WM_ACTION *pAction;
/*
* Run through the actions, doing each in turn.
*/
for ( action = 0; action < nActions; action++ )
{
WMSTATUS newStatus = WMS_SUCCESS;
pAction = &pActions[action];
/*
WM_TRACE( hDevice, ( "%d: 0x%X => 0x%X & 0x%X",
pAction->action,
pAction->dest.reg,
pAction->val.uintval,
pAction->mask
) );
*/
switch ( pAction->action )
{
case WMA_WRITE:
if ( 0xFFFF == pAction->mask )
{
newStatus = WMWrite( hDevice, pAction->dest.reg, pAction->val.regval );
if ( WM_ERROR( newStatus ) )
{
WM_TRACE( hDevice, (
"pActions[%d]: write 0x%X to R%02xh failed: %s",
action,
pAction->val.regval,
pAction->dest.reg,
WMStatusText( newStatus )
));
}
}
else
{
newStatus = WMSetField( hDevice,
pAction->dest.reg,
pAction->val.regval,
pAction->mask
);
if ( WM_ERROR( newStatus ) )
{
WM_TRACE( hDevice, (
"pActions[%d]: setfield 0x%X (mask 0x%X) to R%02xh failed: %s",
action,
pAction->val.regval,
pAction->mask,
pAction->dest.reg,
WMStatusText( newStatus )
));
}
}
break;
case WMA_RESET:
newStatus = WMReset( hDevice );
if ( WM_ERROR( newStatus ) )
{
WM_TRACE( hDevice, (
"pActions[%d]: reset failed: %s",
action,
WMStatusText( newStatus )
));
}
break;
case WMA_WAKE:
newStatus = WMWake( hDevice );
if ( WM_ERROR( newStatus ) )
{
WM_TRACE( hDevice, (
"pActions[%d]: wake failed: %s",
action,
WMStatusText( newStatus )
));
}
break;
case WMA_SLEEP:
MilliSleep( hDevice, pAction->val.uintval );
newStatus = WMS_SUCCESS;
break;
case WMA_POWERUP:
newStatus = WMPowerUp( hDevice, WM_DRIVER_RAW, pAction->val.uintval );
if ( WM_ERROR( newStatus ) )
{
WM_TRACE( hDevice, (
"pActions[%d]: power up of 0x%X failed: %s",
action,
pAction->val.uintval,
WMStatusText( newStatus )
));
}
break;
case WMA_POWERDOWN:
newStatus = WMPowerDown( hDevice, WM_DRIVER_RAW, pAction->val.uintval );
if ( WM_ERROR( newStatus ) )
{
WM_TRACE( hDevice, (
"pActions[%d]: power down of 0x%X failed: %s",
action,
pAction->val.uintval,
WMStatusText( newStatus )
));
}
break;
#if WM_AUDIO
case WMA_ENABLE_STREAM:
newStatus = WMAudioEnableStream( hDevice, pAction->val.uintval );
if ( WM_ERROR( newStatus ) )
{
WM_TRACE( hDevice, (
"pActions[%d]: enable of stream %d failed: %s",
action,
pAction->val.uintval,
WMStatusText( newStatus )
));
}
break;
case WMA_DISABLE_STREAM:
newStatus = WMAudioDisableStream( hDevice, pAction->val.uintval );
if ( WM_ERROR( newStatus ) )
{
WM_TRACE( hDevice, (
"pActions[%d]: disable of stream %d failed: %s",
action,
pAction->val.uintval,
WMStatusText( newStatus )
));
}
break;
case WMA_SET_VOLUME:
newStatus = WMAudioSetSignalVolumeAdv( hDevice,
pAction->dest.signal,
pAction->val.intval,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -