📄 wmgpio.c
字号:
/*
* Get the GPIO details
*/
pGPIODetails = private_GPIODetails( hDevice, gpio );
if ( pGPIODetails == NULL )
{
goto error;
}
gpioPin = pGPIODetails->gpioPin;
gpioAltFunc = pGPIODetails->gpioAltFunc;
/*
* Check to see if this GPIO has an alternate function.
*/
if ( WM_GPIO_NONE == gpioAltFunc )
{
goto error;
}
if ( enable )
{
/*
* Clear the GPIO bit to disconnect from GPIO logic and use
* the alternate function.
*/
status = WMClearField( hDevice, WM97_GPIO_PIN_ASSIGN, gpioPin );
if ( WM_ERROR( status ) )
{
goto error;
}
/*
* Set the GPIO as an output.
*/
status = WMGPIOConfig( hDevice, gpioPin, WM_GPIO_OUTPUT );
if ( WM_ERROR( status ) )
{
goto error;
}
}
else
{
/*
* Set the GPIO bit to connect the GPIO logic and use the pin as
* a GPIO.
*/
status = WMSetField( hDevice, WM97_GPIO_PIN_ASSIGN, gpioPin, gpioPin );
if ( WM_ERROR( status ) )
{
goto error;
}
}
return WMS_SUCCESS;
error:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMGPIOInvertIRQ
*
* Set the IRQ signal to be inverted.
* NOTE: This function assumes that GPIO2/IRQ has been configured for
* use as the alternate function IRQ.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* invert inverted if TRUE, non-inverted if FALSE.
*
* Returns: WMSTATUS
* See WMStatus.h.
* <values/meanings>
*---------------------------------------------------------------------------*/
WMSTATUS WMGPIOInvertIRQ( WM_DEVICE_HANDLE hDevice,
WM_BOOL invert
)
{
WMSTATUS status = WMS_UNSUPPORTED;
WM_REGTYPE reg = 0;
if ( IS_WM9712_FAMILY( hDevice ) )
{
reg = WM97_ADD_FUN;
}
if ( IS_WM9713_FAMILY( hDevice ) )
{
reg = WM9713_ADD_FUN1;
}
if ( invert )
{
/*
* Set IRQ to be inverted.
*/
status = WMSetField( hDevice,
reg,
WM_GPIO_IRQ_INV,
WM_GPIO_IRQ_INV
);
}
else
{
/*
* Set IRQ to be non-inverted.
*/
status = WMClearField( hDevice,
reg,
WM_GPIO_IRQ_INV
);
}
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMGPIOEnableGlobalWake
*
* Enable the global GPIO wake-up. If any GPIO has both its sticky bit and
* its wake up bit set, this 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.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* enable enabled if TRUE, disabled if FALSE.
*
* Returns: WMSTATUS
* See WMStatus.h.
* <values/meanings>
*---------------------------------------------------------------------------*/
WMSTATUS WMGPIOEnableGlobalWake( WM_DEVICE_HANDLE hDevice,
WM_BOOL enable
)
{
WMSTATUS status = WMS_UNSUPPORTED;
WM_REGTYPE reg = 0;
if ( IS_WM9712_FAMILY( hDevice ) )
{
reg = WM97_ADD_FUN;
}
if ( IS_WM9713_FAMILY( hDevice ) )
{
reg = WM9713_ADD_FUN1;
}
if ( enable )
{
/*
* Set global GPIO wake-up.
*/
status = WMSetField( hDevice,
reg,
WM_GPIO_WAKEEN,
WM_GPIO_WAKEEN
);
}
else
{
/*
* Clear global GPIO wake-up.
*/
status = WMClearField( hDevice,
reg,
WM_GPIO_WAKEEN
);
}
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMGPIOSetOutputLevel
*
* If the GPIO is configured as an output, this function will set the level of
* the GPIO.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* gpio the GPIO to change.
* level the level to set the GPIO to.
* WM_GPIO_OUTPUT_HIGH to set it high.
* WM_GPIO_OUTPUT_LOW to set it low.
*
* Returns: WMSTATUS
* See WMStatus.h.
* <values/meanings>
*---------------------------------------------------------------------------*/
WMSTATUS WMGPIOSetOutputLevel( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio,
unsigned short level
)
{
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 output.
*/
if ( private_GPIOIsInput( hDevice, gpioPin ) )
{
status = WMS_WRONG_MODE;
goto finish;
}
#endif /* DEBUG */
if ( WM_GPIO_OUTPUT_HIGH == level )
{
status = WMSetField( hDevice,
WM97_GPIO_PIN_STATUS,
gpioPin,
gpioPin
);
}
else
{
status = WMClearField( hDevice,
WM97_GPIO_PIN_STATUS,
gpioPin
);
}
finish:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMGPIOGetOutputLevel
*
* If the GPIO is configured as an output, this function will return the
* current level of the GPIO.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* gpio the GPIO to check.
* pLevel variable to receive GPIO level -
* WM_GPIO_OUTPUT_HIGH or WM_GPIO_OUTPUT_LOW.
*
* Returns: WMSTATUS
* See WMStatus.h.
*---------------------------------------------------------------------------*/
WMSTATUS WMGPIOGetOutputLevel( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio,
unsigned short *pLevel
)
{
WMSTATUS status = WMS_UNSUPPORTED;
WM_GPIO_PIN gpioPin = WM_GPIO_NONE;
WM_REGVAL gpioStatus = 0;
const WM_GPIO_DETAILS *pGPIODetails = NULL;
if ( NULL == pLevel )
{
status = WMS_INVALID_PARAMETER;
goto finish;
}
/*
* Get the GPIO details
*/
pGPIODetails = private_GPIODetails( hDevice, gpio );
if ( NULL == pGPIODetails )
{
goto finish;
}
gpioPin = pGPIODetails->gpioPin;
#ifdef DEBUG
/*
* Check to make sure that this is an output.
*/
if ( private_GPIOIsInput( hDevice, gpioPin ) )
{
status = WMS_WRONG_MODE;
goto finish;
}
#endif /* DEBUG */
status = WMRead( hDevice, WM97_GPIO_PIN_STATUS, &gpioStatus );
if ( WM_ERROR( status ) )
{
goto finish;
}
/*
* Check the status bit of the GPIO to see if it is set.
*/
if ( gpioStatus & gpioPin )
{
*pLevel = WM_GPIO_OUTPUT_HIGH;
}
else
{
*pLevel = WM_GPIO_OUTPUT_LOW;
}
finish:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMGPIOIsSignalled
*
* Check to see if the input GPIO has been signalled.
* A GPIO is signalled when the level changes to match the GPIO's polarity.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* gpio the GPIO to check.
*
* Returns: WM_BOOL TRUE if the status bit is set,
* FALSE if the status bit is clear.
*---------------------------------------------------------------------------*/
WM_BOOL WMGPIOIsSignalled( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN gpio
)
{
WM_BOOL retval = FALSE;
WMSTATUS status = WMS_UNSUPPORTED;
WM_GPIO_PIN gpioPin = WM_GPIO_NONE;
WM_REGVAL gpioStatus = 0;
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;
}
gpioPin = pGPIODetails->gpioPin;
/*
* Read the GPIO status register.
*/
status = WMRead( hDevice, WM97_GPIO_PIN_STATUS, &gpioStatus );
if ( WM_ERROR( status ) )
{
WM_ASSERT( hDevice, WM_SUCCESS( status ) );
goto finish;
}
/*
* Check to see if the status bit of the GPIO is set.
*/
if ( gpioStatus & gpioPin )
{
retval = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -