mirror of
https://gitee.com/moluo-tech/AT-Command
synced 2025-06-18 00:17:53 +00:00
57 lines
1.6 KiB
C
57 lines
1.6 KiB
C
![]() |
/******************************************************************************
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>ʾkeyģ<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>)
|
|||
|
*
|
|||
|
* Copyright (c) 2020, <morro_luo@163.com>
|
|||
|
*
|
|||
|
* SPDX-License-Identifier: Apache-2.0
|
|||
|
*
|
|||
|
* Change Logs:
|
|||
|
* Date Author Notes
|
|||
|
* 2020/07/03 Morro
|
|||
|
******************************************************************************/
|
|||
|
#include "led.h"
|
|||
|
#include "key.h"
|
|||
|
#include "module.h"
|
|||
|
#include "public.h"
|
|||
|
|
|||
|
static key_t key; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
|
|||
|
static void key_event(int type, unsigned int duration);
|
|||
|
|
|||
|
/*
|
|||
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ״̬
|
|||
|
* @return 0 | 1
|
|||
|
*/
|
|||
|
static int readkey(void)
|
|||
|
{
|
|||
|
return GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4) == 0;
|
|||
|
}
|
|||
|
|
|||
|
/*
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD> io<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
* PC4 -> key;
|
|||
|
* @return none
|
|||
|
*/
|
|||
|
static void key_io_init(void)
|
|||
|
{
|
|||
|
gpio_conf(GPIOC, GPIO_Mode_IN, GPIO_PuPd_UP, GPIO_Pin_4);
|
|||
|
key_create(&key, readkey, key_event); /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
}
|
|||
|
|
|||
|
/*
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @return type -
|
|||
|
*/
|
|||
|
static void key_event(int type, unsigned int duration)
|
|||
|
{
|
|||
|
if (type == KEY_PRESS)
|
|||
|
led_ctrl(LED_TYPE_GREEN, LED_MODE_FAST, 3); /*<2A>̰<EFBFBD>,<2C>̵<EFBFBD><CCB5><EFBFBD>3<EFBFBD><33>*/
|
|||
|
else if (type == KEY_LONG_DOWN)
|
|||
|
led_ctrl(LED_TYPE_GREEN, LED_MODE_ON, 0); /*<2A><><EFBFBD><EFBFBD>,<2C>̵Ƴ<CCB5><C6B3><EFBFBD>*/
|
|||
|
else if (type == KEY_LONG_UP)
|
|||
|
led_ctrl(LED_TYPE_GREEN, LED_MODE_OFF, 0); /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>,<2C>̵ƹر<C6B9>*/
|
|||
|
}
|
|||
|
|
|||
|
driver_init("key", key_io_init); /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>*/
|
|||
|
task_register("key", key_scan_process, 20); /*<2A><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 20ms<6D><73>ѯ1<D1AF><31>*/
|