📄 wmgpio.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: WMGPIO.c 2410 2005-11-14 10:59:18Z fb $
*
* This file contains platform-independent routines for controlling GPIO on
* Wolfson codecs.
*
* 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 "WMRegisterDefs.h"
#include "WMControlLink.h"
#include "WMPlatformACLink.h"
#include "WMGPIO.h"
/*
* Only build this if we're adding GPIO control support.
*/
#if WM_GPIO_CONTROL
/*
* Global definitions
*/
/*
* Function prototypes
*/
const WM_GPIO_DETAILS *private_GPIODetails( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio
);
WM_BOOL private_GPIOIsInput( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio
);
void private_GPIOWM9713EnableGPIOFunction( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio,
WM_BOOL enable
);
/*-----------------------------------------------------------------------------
* Function: WMGPIOConfig
*
* Configure the GPIO direction as an input or and output.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* gpio the GPIO to configure.
* direction the direction of the GPIO.
* WM_GPIO_OUTPUT to set it as an ouput.
* WM_GPIO_INPUT to set it as an input.
*
* Returns: WMSTATUS
* See WMStatus.h.
* <values/meanings>
*---------------------------------------------------------------------------*/
WMSTATUS WMGPIOConfig( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio,
unsigned short direction
)
{
WMSTATUS status = WMS_UNSUPPORTED;
WM_GPIO_PIN gpioPin = WM_GPIO_NONE;
WM_GPIO_PIN gpioVirtualFunc = WM_GPIO_NONE;
const WM_GPIO_DETAILS *pGPIODetails = NULL;
/*
* Get the GPIO details
*/
pGPIODetails = private_GPIODetails( hDevice, gpio );
if ( pGPIODetails == NULL )
{
goto finish;
}
gpioPin = pGPIODetails->gpioPin;
gpioVirtualFunc = pGPIODetails->gpioVirtualFunc;
/*
* If this is a virtual GPIO then we
* do not need to do anything, as these
* GPIOs are always inputs.
*/
if ( WM_GPIO_NONE != gpioVirtualFunc )
{
/*
* Only set the status to WMS_SUCCESS
* if the GPIO is an input.
*/
if ( WM_GPIO_INPUT == direction )
{
status = WMS_SUCCESS;
}
goto finish;
}
if ( IS_WM9713_FAMILY( hDevice ) )
{
/*
* Make sure that the pin is configured to be used as a GPIO.
*/
private_GPIOWM9713EnableGPIOFunction( hDevice, gpio, TRUE );
}
if ( WM_GPIO_INPUT == direction )
{
/*
* Set the GPIO bit in the config register (0x4C) to set it as an input.
*/
status = WMSetField( hDevice, WM97_GPIO_PIN_CONFIG, gpioPin, gpioPin );
}
else
{
/*
* Clear the GPIO bit in the config register (0x4C) to set it as an output.
*/
status = WMClearField( hDevice, WM97_GPIO_PIN_CONFIG, gpioPin );
}
finish:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMGPIOSetInputPolarity
*
* Set the GPIO polarity.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* gpio the GPIO to change.
* polarity the polarity of the GPIO.
* WM_GPIO_ACTIVE_HIGH for active high.
* WM_GPIO_ACTIVE_LOW for active low.
*
* Returns: WMSTATUS
* See WMStatus.h.
* <values/meanings>
*---------------------------------------------------------------------------*/
WMSTATUS WMGPIOSetInputPolarity( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio,
unsigned short polarity
)
{
WMSTATUS status = WMS_UNSUPPORTED;
WM_GPIO_PIN gpioPin = WM_GPIO_NONE;
const WM_GPIO_DETAILS *pGPIODetails = NULL;
/*
* Get the GPIO details
*/
pGPIODetails = private_GPIODetails( hDevice, gpio );
if ( pGPIODetails == NULL )
{
goto finish;
}
gpioPin = pGPIODetails->gpioPin;
#ifdef DEBUG
/*
* Check to make sure that this is an input.
*/
if ( ! private_GPIOIsInput( hDevice, gpioPin ) )
{
status = WMS_WRONG_MODE;
goto finish;
}
#endif /* DEBUG */
if ( WM_GPIO_ACTIVE_HIGH == polarity )
{
status = WMSetField( hDevice,
WM97_GPIO_PIN_POLARITY,
gpioPin,
gpioPin
);
}
else
{
status = WMClearField( hDevice,
WM97_GPIO_PIN_POLARITY,
gpioPin
);
}
finish:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMGPIOEnableSticky
*
* Enable the GPIO sticky bit. The sticky bit is used by GPIOs that are set
* up as inputs to hold the status bit.
* The sticky bit is cleared by calling WMGPIOClearInput().
*
* Note: Both the global wake bit and the wake up bit of the GPIO must be set
* for the sticky bit to work correctly.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* gpio the GPIO to change.
* enable set the sticky bit if TRUE, clear the sticky bit
* if FALSE.
*
* Returns: WMSTATUS
* See WMStatus.h.
* <values/meanings>
*---------------------------------------------------------------------------*/
WMSTATUS WMGPIOEnableSticky( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio,
WM_BOOL enable
)
{
WMSTATUS status = WMS_UNSUPPORTED;
WM_GPIO_PIN gpioPin = WM_GPIO_NONE;
const WM_GPIO_DETAILS *pGPIODetails = NULL;
/*
* Get the GPIO details
*/
pGPIODetails = private_GPIODetails( hDevice, gpio );
if ( pGPIODetails == NULL )
{
goto finish;
}
gpioPin = pGPIODetails->gpioPin;
#ifdef DEBUG
/*
* Check to make sure that this is an input.
*/
if ( ! private_GPIOIsInput( hDevice, gpioPin ) )
{
status = WMS_WRONG_MODE;
goto finish;
}
#endif /* DEBUG */
if ( enable )
{
status = WMSetField( hDevice, WM97_GPIO_PIN_STICKY, gpioPin, gpioPin );
}
else
{
status = WMClearField( hDevice, WM97_GPIO_PIN_STICKY, gpioPin );
}
finish:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMGPIOEnableWakeUp
*
* Enable the GPIO WakeUp bit. The wake up bit allows the GPIO to do two things.
* It can wake up the AC Link, if the codec is sleeping.
* It will also set bit 0 of slot 12, the GPIO interrupt (GPIO_INT) bit.
*
* Note: Both the global wake bit and the sticky bit of the GPIO must be set
* for the wake up bit to work correctly.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* gpio the GPIO to change.
* enable set the wakeup bit set if TRUE, cleared if FALSE.
*
* Returns: WMSTATUS
* See WMStatus.h.
* <values/meanings>
*---------------------------------------------------------------------------*/
WMSTATUS WMGPIOEnableWakeUp( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio,
WM_BOOL enable
)
{
WMSTATUS status = WMS_UNSUPPORTED;
WM_GPIO_PIN gpioPin = WM_GPIO_NONE;
const WM_GPIO_DETAILS *pGPIODetails = NULL;
/*
* Get the GPIO details
*/
pGPIODetails = private_GPIODetails( hDevice, gpio );
if ( pGPIODetails == NULL )
{
goto finish;
}
gpioPin = pGPIODetails->gpioPin;
#ifdef DEBUG
/*
* Check to make sure that this is an input.
*/
if ( ! private_GPIOIsInput( hDevice, gpioPin ) )
{
status = WMS_WRONG_MODE;
goto finish;
}
#endif /* DEBUG */
if ( enable )
{
status = WMSetField( hDevice, WM97_GPIO_PIN_WAKEUP, gpioPin, gpioPin );
}
else
{
status = WMClearField( hDevice, WM97_GPIO_PIN_WAKEUP, gpioPin );
}
finish:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMGPIOEnableAlternateFunction
*
* Enables the GPIO to use its alternate function.
* NOTE: This function call will only work with GPIOs that have alternate
* functions.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* gpio the GPIO to change.
* enable Selects the alternative function if TRUE,
* uses the GPIO if FALSE.
*
* Returns: WMSTATUS
* See WMStatus.h.
* <values/meanings>
*---------------------------------------------------------------------------*/
WMSTATUS WMGPIOEnableAlternateFunction( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio,
WM_BOOL enable
)
{
WMSTATUS status = WMS_UNSUPPORTED;
WM_GPIO_PIN gpioPin = WM_GPIO_NONE;
WM_GPIO_PIN gpioAltFunc = WM_GPIO_NONE;
const WM_GPIO_DETAILS *pGPIODetails = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -