131 lines
3.1 KiB
C
131 lines
3.1 KiB
C
/*
|
||
******************************************************************************
|
||
*
|
||
* @file key.c
|
||
* @brief key module
|
||
*
|
||
*
|
||
* @version 1.0
|
||
* @date 2022/08/04 15:00:40
|
||
* @author Alex Xu
|
||
*
|
||
* Copyright (c) 2013-2099,Tkplusemi Technology Co.,Ltd.
|
||
* All Rights Reserved
|
||
*
|
||
* History:
|
||
* Revision Date Author Desc
|
||
* 1.0.0 2022/08/04 Alex build this file
|
||
******************************************************************************/
|
||
/*_____ I N C L U D E S ____________________________________________________*/
|
||
#include "key.h"
|
||
#include "system.h"
|
||
#include "led.h"
|
||
#include "sleep.h"
|
||
#include "adc.h"
|
||
#include "bat.h"
|
||
#include "vox_module.h"
|
||
#include "userapp.h"
|
||
|
||
#if KEY_ENABLE
|
||
/******************************************************************************\
|
||
Macro definitions
|
||
\******************************************************************************/
|
||
#define KEY_PRESS_CNT0 5 //按键长按500ms显示长按灯效
|
||
#define KEY_PRESS_CNT 50 //按键按下计数5s
|
||
|
||
/******************************************************************************\
|
||
Variables definitions
|
||
\******************************************************************************/
|
||
|
||
bit Key_Press_short_irq = 0;
|
||
bit Key_Press_l_irq = 0;
|
||
bit Key_Press_ll_irq = 0;
|
||
bit Key_Press_ll_irq1 = 0;
|
||
|
||
bit Key_l_Flag = 0;
|
||
|
||
//idata KEY_EVENT_E Event_key = 0;
|
||
|
||
idata uint8_t Key_Press_Debounce = 0;
|
||
|
||
/******************************************************************************\
|
||
Functions definitions
|
||
\******************************************************************************/
|
||
|
||
/*
|
||
*******************************************************************************
|
||
* void Key_Handler(void)
|
||
*
|
||
* Description : Key Handler --- 主循环中调用,调用周期5ms。其中长按(按键时间大于2s)需要判断抬键动作才触发。
|
||
CoverStatus --- 充电仓盖子状态。(本函数提供对应Key事件标志位,后续应用待定)
|
||
10ms调用周期
|
||
*
|
||
* Arguments : NONE
|
||
|
||
* Returns : NONE
|
||
|
||
* Notes : NONE
|
||
*
|
||
*******************************************************************************
|
||
*/
|
||
|
||
void Key_Handler(void)
|
||
{
|
||
|
||
if( !(CHIP_STA0 & 0x02) ) //CHIP_STA0 的bit1为Key的状态值:0:按下;
|
||
{
|
||
Key_Press_Debounce++;
|
||
|
||
if( Key_Press_Debounce >= KEY_PRESS_CNT ) //长按5s
|
||
{
|
||
Key_Press_ll_irq = 1;
|
||
|
||
Key_Press_Debounce = 0;
|
||
}
|
||
else
|
||
if( Key_Press_Debounce >= KEY_PRESS_CNT0 ) //按键长按500ms显示长按灯效
|
||
{
|
||
if( !Key_Press_ll_irq1 )
|
||
{
|
||
Key_Press_ll_irq1 = 1;
|
||
|
||
LED_On_Flag = 1;
|
||
}
|
||
}
|
||
|
||
Key_l_Flag = 1;
|
||
|
||
#if SLEEP_ENABLE
|
||
|
||
Enter_Sleep_Cnt_Restart_Flag = 1;
|
||
|
||
#endif
|
||
|
||
}
|
||
else
|
||
{
|
||
if( Key_l_Flag )
|
||
{
|
||
Key_l_Flag = 0;
|
||
|
||
LED_On_Flag = 1;
|
||
|
||
if( (Key_Press_Debounce < KEY_PRESS_CNT0) ) //松开按键,按下时间小于500ms,则识别为短按,显示电量
|
||
{
|
||
Key_Press_short_irq = 1; //短按,显示电量
|
||
}
|
||
else
|
||
if( Key_Press_Debounce < KEY_PRESS_CNT ) //长按不到5s,灯效灭。
|
||
{
|
||
Key_Press_ll_irq1 = 0;
|
||
}
|
||
}
|
||
|
||
Key_Press_Debounce = 0;
|
||
}
|
||
|
||
}
|
||
|
||
#endif
|
||
|