Reading GPIO output state

取消
显示结果 
搜索替代 
您的意思是: 

Reading GPIO output state

521 次查看
dan_quist
Contributor III

Hi,

 

Does MQX support reading the the state of an ouput GPIO pin? Of course I can keep track manually which pins are set or not, but I find it surprising that there's not a method to do this through the GPIO driver.

 

Maybe I'm missing something? I tried GPIO_IOCTL_READ, but that command is only valid for input pins.

0 项奖励
1 回复

168 次查看
KJFPE
Contributor III


Hi
What I did on the K60 tower system to read a button I used lwgpio_get_value


// Setup the button
if (!lwgpio_init(&btn1, BSP_BUTTON1, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE))
{
DEBUG_OUT("Initializing button GPIO as input failed.\n");
}

lwgpio_set_functionality(&btn1, BSP_BUTTON1_MUX_GPIO);
lwgpio_set_attribute(&btn1, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE);


// Then some where else you can now read the state of the button

/************************************************************************/
/* Read Switch */
/************************************************************************/
int_16 Read ()
{
int_16 result=-1;

if (LWGPIO_VALUE_HIGH == lwgpio_get_value(&btn1))
{
DEBUG_OUT("Button IDLE");
result = 1;
}
else
{
DEBUG_OUT("Button PRESSED");
result = 0;
}
}

 

 

Hope this helps