TI中文支持网
TI专业的中文技术问题搜集分享网站

CC3235SF: 如何使用按键查询的方式来获取按键是否按下呢?

Part Number:CC3235SF

我看了按键例程,它是用中断的方式来运行的,那么如果我想要使用按键查询的方式来获取按键值,我应该如何修改例程呢?

Kevin Qiu1:

查询的方式会一直占用CPU,i降低效率,在wifi的应用中一般不用这种方式

代码修改就是加一个扫描的部分,一直扫描或定期扫描

,

wu:

但是Button_open()这里需要传入一个callbackfxn函数,那么这里应该怎么处理呢?

,

Kevin Qiu1:

这个参考的Button_open有些错误,它应该只有两个参数,不应包含callback函数

/*!*@briefFunction to open a given Button**Function to open a button instance corresponding to a #Button_Config in the*Button_config array. The GPIO configurations must exist prior to calling*this function. The #Button_Params may be used to specify runtime parameters.**@preButton_init() has to be called first**@param[in] buttonIndexLogical button number indexed into*the Button_config table**@param[in] *paramsA pointer to #Button_Params structure. If NULL,*it will use default values.**@returnA #Button_Handle on success, or a NULL on failure.**@saButton_init()*@saButton_Params_init()*@saButton_close()*/
extern Button_Handle Button_open(uint_least8_t buttonIndex, Button_Params *params);

,

wu:

例程里面的函数原型也是需要callbackfxn参数的,而且我并没有找到您上面截图的不含callbackfxn参数的函数原型,请问您这个函数应该去哪里找呢?

,

Kevin Qiu1:

我说的是SDK5.30中的,你的应该是此前的版本,使用参考下面的说明

https://dev.ti.com/tirex/content/simplelink_cc32xx_sdk_5_30_00_08/docs/drivers/doxygen/html/_button_8h.html

https://dev.ti.com/tirex/content/simplelink_cc32xx_sdk_5_20_00_06/docs/drivers/doxygen/html/_button_8h.html

你可以按照SDK5.20中的方式使用,具体参考上面的文档

,

wu:

SDK5.20就是使用中断的方式,也就是callbackfxn函数来处理,但是我想要用查询的方式我的Button_open()里面也要callbackfxn的参数,我应该如何修改呢

,

Kevin Qiu1:

callback是中断的回调函数,如果也要使用查询,则不应使用button驱动

应该直接使用GPIO:https://dev.ti.com/tirex/content/simplelink_cc32xx_sdk_5_30_00_08/docs/drivers/doxygen/html/_g_p_i_o_8h.html

使用GPIO_read获取电平判断是否按下

,

zhiyong chen:

GPIO_init();

/* Configure the LED and button pins */ GPIO_setConfig(13, GPIO_CFG_IN_PU);   //可不写,因为已在GPIO_init()中配置了。 GPIO_setConfig(22, GPIO_CFG_IN_PU);  //可不写,因为已在GPIO_init()中配置了。

/* Turn on user LED */ GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);

uint8_t tmp8; while(1){    tmp8= GPIO_read(13);       if(tmp8)    {     //GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);     GPIOPinWrite(GPIOA1_BASE, GPIO_PIN_1, GPIO_PIN_1);     }     else{     //GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF);     GPIOPinWrite(GPIOA1_BASE, GPIO_PIN_1, 0);     }

}

我对open,read,write也不习惯。

,

wu:

但是这样的话好像只能判断按键是否按下,那如果我想要跟例程一样能够判断按键是否单击、双击、长按等状态时,我应该如何操作呢?

,

Kevin Qiu1:

提供一个思路:基本上都根据时间长短来判断,具体的代码要自己写,没有示例程序

赞(0)
未经允许不得转载:TI中文支持网 » CC3235SF: 如何使用按键查询的方式来获取按键是否按下呢?
分享到: 更多 (0)