📄 wmgpio.c
字号:
}
finish:
return retval;
}
/*-----------------------------------------------------------------------------
* Function: WMGPIOClearInput
*
* Clear the status of the GPIO.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* gpio the GPIO to clear.
*
* Returns: WMSTATUS
* See WMStatus.h.
* <values/meanings>
*---------------------------------------------------------------------------*/
WMSTATUS WMGPIOClearInput( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio
)
{
WMSTATUS status = WMS_UNSUPPORTED;
WM_GPIO_PIN gpioPin = WM_GPIO_NONE;
WM_REGVAL regval;
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 */
/*
* Read the current value.
*/
status = WMRead( hDevice, WM97_GPIO_PIN_STATUS, ®val );
if ( WM_ERROR( status ) )
{
WM_TRACE( hDevice, ( "WMGPIOClearInput: read failed: 0%s\n",
WMStatusText( status ) ) );
goto finish;
}
/*
* Now clear the bit.
*/
regval &= ~gpioPin;
if ( WM_IS_AC97( hDevice ) )
{
status = WMPlatformACLinkClearGPIOInput( hDevice, regval );
}
finish:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMGPIOHasAltFunc
*
* Does this GPIO have an alternate function.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* gpio the GPIO to check.
*
* Returns: WMSTATUS
* WMS_RETURN_TRUE if the GPIO has an alternate
* function.
* WMS_RETURN_FALSE if the GPIO does not
* have an alternate function.
* WMS_UNSUPPORTED if the GPIO is not available
* on this device.
* See WMStatus.h for all other values and meanings.
*---------------------------------------------------------------------------*/
WMSTATUS WMGPIOHasAltFunc( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio
)
{
WMSTATUS status = WMS_UNSUPPORTED;
WM_GPIO_PIN gpioAltFunc = WM_GPIO_NONE;
const WM_GPIO_DETAILS *pGPIODetails = NULL;
/*
* Get the GPIO details
*/
pGPIODetails = private_GPIODetails( hDevice, gpio );
if ( pGPIODetails == NULL )
{
WM_ASSERT( hDevice, pGPIODetails == NULL );
goto finish;
}
gpioAltFunc = pGPIODetails->gpioAltFunc;
/*
* Check to see if this is an alternate function.
*/
if ( WM_GPIO_NONE != gpioAltFunc )
{
status = WMS_RETURN_TRUE;
}
else
{
status = WMS_RETURN_FALSE;
}
finish:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMGPIOHasVirtualGPIO
*
* Does this GPIO have a virtual GPIO function.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* gpio the GPIO to check.
*
* Returns: WMSTATUS
* WMS_RETURN_TRUE if the GPIO has a virtual
* function.
* WMS_RETURN_FALSE if the GPIO does not
* have a virtual function.
* WMS_UNSUPPORTED if the GPIO is not available
* on this device.
* See WMStatus.h for all other values and meanings.
*---------------------------------------------------------------------------*/
WMSTATUS WMGPIOHasVirtualGPIO( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio
)
{
WMSTATUS status = WMS_UNSUPPORTED;
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 )
{
WM_ASSERT( hDevice, pGPIODetails == NULL );
goto finish;
}
gpioVirtualFunc = pGPIODetails->gpioVirtualFunc;
/*
* Check to see if this is an Virtual GPIO.
*/
if ( WM_GPIO_NONE != gpioVirtualFunc )
{
status = WMS_RETURN_TRUE;
}
else
{
status = WMS_RETURN_FALSE;
}
finish:
return status;
}
/*-----------------------------------------------------------------------------
* Function: private_GPIODetails
*
* Called to get the GPIO's details.
*
* Parameters:
* hDevice The handle to the device (from WMOpenDevice).
* gpio The GPIO we are interested in.
* NOTE : This function will accept the GPIO name,
* the GPIO alternate name or the virtual function
* name.
*
* Returns: const WM_GPIO_DETAILS *
* Pointer to the GPIO details, or NULL if no match.
*---------------------------------------------------------------------------*/
const WM_GPIO_DETAILS *private_GPIODetails( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio
)
{
const WM_CHIPDEF *pChipDef = NULL;
unsigned int nGPIO = 0;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
if ( !pChipDef )
{
goto error;
}
/*
* Run through the gpio pins.
*/
for ( nGPIO = 0; nGPIO < pChipDef->gpioCount; nGPIO++ )
{
if ( pChipDef->pGPIODetails[ nGPIO ].gpioPin == gpio )
{
/* Found it */
return &pChipDef->pGPIODetails[ nGPIO ];
}
}
/*
* If we get here, we failed.
*/
error:
return NULL;
}
/*-----------------------------------------------------------------------------
* Function: private_GPIOIsInput
*
* Check to see if the GPIO is configured as an input.
*
* Parameters:
* hDevice The handle to the device (from WMOpenDevice).
* gpio The GPIO we are interested in.
*
* Returns: WM_BOOL
* TRUE if the GPIO is an input, FALSE if the GPIO is an output.
*---------------------------------------------------------------------------*/
WM_BOOL private_GPIOIsInput( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio
)
{
WM_BOOL retval = FALSE;
WMSTATUS status;
WM_REGVAL direction = 0;
status = WMRead( hDevice, WM97_GPIO_PIN_CONFIG, &direction );
if( WM_ERROR( status ) )
{
WM_ASSERT( hDevice, WM_SUCCESS( status ) );
goto finish;
}
/*
* If the direction bit is set to 1 for the GPIO
* then this is an input.
*/
if ( direction & gpio )
{
retval = TRUE;
}
finish:
return retval;
}
/*-----------------------------------------------------------------------------
* Function: private_GPIOWM9713EnableGPIOFunction
*
* Some of the GPIO pins can be used for diffrent purposes on the WM9713.
* This function enables or disables the pins to be used as GPIOs.
*
* NOTE: This function is untested and may be required at a later date
* externally.
*
* Parameters:
* hDevice The handle to the device (from WMOpenDevice).
* gpio The GPIO we are interested in.
* enable set as GPIO if TRUE, set as non-GPIO if FALSE.
*
* Returns: void
*---------------------------------------------------------------------------*/
void private_GPIOWM9713EnableGPIOFunction( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio,
WM_BOOL enable
)
{
if ( IS_WM9713_FAMILY( hDevice ) )
{
WM_BOOL pcm = FALSE;
WM_BOOL resetb = FALSE;
switch ( gpio )
{
case WM_GPIO_1:
case WM_GPIO_3:
case WM_GPIO_4:
case WM_GPIO_5:
pcm = TRUE;
break;
case WM_GPIO_7:
resetb = TRUE;
break;
}
if( pcm )
{
if( enable )
{
WMClearField( hDevice,
WM9713_VOICE_CODEC_CONTROL,
WM_GPIO_VOICE_INTERFACE_ENABLE
);
#if WM_VOICE
WM_TRACE( hDevice,
( "private_GPIOWM9713EnableGPIOFunction: "
"Disabled voice interface. "
"Are you sure you wanted to do this?"));
#endif
}
else
{
WMSetField( hDevice,
WM9713_VOICE_CODEC_CONTROL,
WM_GPIO_VOICE_INTERFACE_ENABLE,
WM_GPIO_VOICE_INTERFACE_ENABLE
);
}
}
else if( resetb )
{
if( enable )
{
WMSetField( hDevice,
WM9713_ADD_FUN1,
WM_GPIO_RESETB_DISABLE,
WM_GPIO_RESETB_DISABLE
);
}
else
{
WMClearField( hDevice,
WM9713_ADD_FUN1,
WM_GPIO_RESETB_DISABLE
);
}
}
}
}
#endif /* WM_GPIO_CONTROL */
/*------------------------------ END OF FILE ---------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -