release v0.9
This commit is contained in:
1 parent
0045c0c390
commit
14f2ff94d0
11 files changed
+337
-61
No files matched your search
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @file key.c
|
||||
* @brief 单 GPIO 按键控制实现 (低电平有效, 软件消抖)
|
||||
*/
|
||||
|
||||
#include "key.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
static int s_gpio = -1;
|
||||
|
||||
void key_init(int gpio)
|
||||
{
|
||||
s_gpio = gpio;
|
||||
|
||||
gpio_reset_pin(s_gpio);
|
||||
gpio_set_direction(s_gpio, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(s_gpio, GPIO_PULLUP_ONLY);
|
||||
}
|
||||
|
||||
bool key_is_pressed(void)
|
||||
{
|
||||
if (s_gpio < 0) return false;
|
||||
|
||||
/* 低电平有效 + 简单消抖: 连续两次读到低电平才算按下 */
|
||||
if (gpio_get_level(s_gpio) == 0) {
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
return (gpio_get_level(s_gpio) == 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in new issue
Block a user