📄 polaris_gpiopin.cpp
字号:
/*+++ *******************************************************************\
*
* Copyright and Disclaimer:
*
* ---------------------------------------------------------------
* This software is provided "AS IS" without warranty of any kind,
* either expressed or implied, including but not limited to the
* implied warranties of noninfringement, merchantability and/or
* fitness for a particular purpose.
* ---------------------------------------------------------------
*
* Copyright (c) 2008 Conexant Systems, Inc.
* All rights reserved.
*
\******************************************************************* ---*/
#include "Polaris_GPIOPin.h"
#include "PolarisUsbInterface.h"
////////////////////////////////////////////////////////////////////////////////////////
// constructor with just demod reset and sleep bits (For Sonora)
PolarisGPIOPin::PolarisGPIOPin(PolarisUsbInterface* p_firmware,
BYTE p_base,
BYTE demod_reset_gpio_bit,
BYTE demod_sleep_gpio_bit) :
_p_firmware(p_firmware),
_p_base(p_base),
_demod_reset_gpio_bit(demod_reset_gpio_bit),
_demod_sleep_gpio_bit(demod_sleep_gpio_bit),
_gpio_direction(0), ///all 32 bit input
_gpio_logic_value(0), //all input low
_gpio_direction_status(0) //all input
{
KeInitializeMutex( &_mutex, 0 );
}
// constructor with demod reset, IF select, and tuner enable bits (For Sahara/Titan)
PolarisGPIOPin::PolarisGPIOPin(PolarisUsbInterface* p_firmware,
BYTE p_base,
BYTE demod_reset_gpio_bit,
BYTE if_select_gpio_bit,
BYTE tuner_enable_i2c_bit) :
_p_firmware(p_firmware),
_p_base(p_base),
_demod_reset_gpio_bit(demod_reset_gpio_bit),
_if_select_gpio_bit(if_select_gpio_bit),
_tuner_enable_i2c_bit(tuner_enable_i2c_bit),
_gpio_direction(0), ///all 32 bit input
_gpio_logic_value(0), //all input low
_gpio_direction_status(0) //all input
{
KeInitializeMutex( &_mutex, 0 );
}
///////////////////////////////////////////////////////////////////////////////////////
// SetGpioPinDirection
// Sets the direction of the GPIO pin to input or output
//
// Parameters :
// pinNumber : The GPIO Pin number to program the direction for
// pinLogicValue : The Direction of the GPIO Pin under reference.
// 0 = Input direction
// 1 = Output direction
///////////////////////////////////////////////////////////////////////////////////////
VOID PolarisGPIOPin::SetGpioPinDirection(
INT pinNumber, //from 0 to 31
INT pinLogicValue)
{
NTSTATUS status = STATUS_SUCCESS;
lock();
// Check for valid pinNumber - if 32 , bail out
if (pinNumber >= 32)
{
unlock();
return;
}
ULONG value = 0;
if (pinLogicValue == 0) //input
{
value = _gpio_direction &(~(1<<pinNumber)) ; //clear
}
else
{
value = _gpio_direction | (1<<pinNumber) ;
}
status = _p_firmware->setGpio(value, (PBYTE)&_gpio_logic_value, 4, 0);
_gpio_direction = value;
unlock();
}
///////////////////////////////////////////////////////////////////////////////////////
// SetGpioPinLogicValue
// Sets the value of the GPIO pin to Logic high or low. The Pin under
// reference should ALREADY BE SET IN OUTPUT MODE !!!!!!!!!
//
// Parameters :
// pinNumber : The GPIO Pin number to program the direction for
// pinLogicValue : The value of the GPIO Pin under reference.
// 0 = set it to 0
// 1 = set it to 1
///////////////////////////////////////////////////////////////////////////////////////
VOID PolarisGPIOPin::SetGpioPinLogicValue(
INT pinNumber,
INT pinLogicValue)
{
// !!!!!!!!!!!!!
// NOTE: The relevant direction bits of the GPIOs have already been set in the
// constructor !!!!!!!!
// !!!!!!!!!!!!!
NTSTATUS status = STATUS_SUCCESS;
lock();
// Check for valid pinNumber - if 0xFF , bail out
if (pinNumber >= 32)
return;
ULONG value = 0;
// first do a sanity check - if the Pin is not output, make it output
if ((_gpio_direction & (1<<pinNumber)) == 0x00)
{
// It is input.
value = _gpio_direction| (1<<pinNumber) ;
_gpio_direction = value;
status = _p_firmware->setGpio(_gpio_direction, (PBYTE)&_gpio_logic_value, 4, 0);
value = 0;
}
if (pinLogicValue == 0)
{
value = _gpio_logic_value & (~(1<<pinNumber));
}
else
{
value = _gpio_logic_value | (1<<pinNumber);
}
_gpio_logic_value=value;
// toggle bit0 of GP_IO
status = _p_firmware->setGpio(_gpio_direction, (PBYTE)&_gpio_logic_value, 4, 0);
unlock();
}
///////////////////////////////////////////////////////////////////////////////////////
// GetGpioPinDirection
// Gets the direction of the GPIO pin
//
// Parameters :
// pinNumber : The GPIO Pin number to program the direction for
//
// Return Value
// 0 = Input direction
// 1 = Output direction
// -1 = ERROR
///////////////////////////////////////////////////////////////////////////////////////
ULONG PolarisGPIOPin::GetGpioPinDirection(
INT pinNumber)
{
// Check for valid pinNumber - if 0xFF , bail out
if (pinNumber >= 32)
return -1;
lock();
ULONG value = 0;
value = (_gpio_direction & (1<<pinNumber));
unlock();
return value ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -