SY883x_For_Clients_langxun-J8/UsrSrc/key/key.c

154 lines
3.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
******************************************************************************
*
* @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"
#if KEY_ENABLE
/******************************************************************************\
Macro definitions
\******************************************************************************/
#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_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事件标志位后续应用待定
*
* Arguments : NONE
* Returns : NONE
* Notes : NONE
*
*******************************************************************************
*/
void Key_Handler(void)
{
#if 1
#if 0
if( IRQ_FLAG7 ) //有按键触发
{
if( IRQ_FLAG7 & 0x40 ) //key super long press for 8s interrupt flag
{
Key_Press_ll_irq = 1;
Event_key = KEY_EVENT_LL_8S;
}
IRQ_FLAG7 = 0xFF; //Clear Key Interrupt Flag
}
#else
if( !(CHIP_STA0 & 0x02) ) //CHIP_STA0 的bit1为Key的状态值0按下
{
Key_Press_Debounce++;
if( Key_Press_Debounce >= KEY_PRESS_CNT )
{
if( (CHIP_STA0 & 0x02) == 0 )
{
Key_Press_ll_irq = 1;
Event_key = KEY_EVENT_LL_8S;
Key_Press_Debounce = 0;
}
}
#if SLEEP_ENABLE
Enter_Sleep_Cnt_Restart_Flag = 1;
#endif
}
else
{
Key_Press_Debounce = 0;
}
#endif
#else
if( Key_l_Flag )
{
Key_Press_l_irq = 0;
Key_l_Flag = 0;
/*todo*/
Event_key = KEY_EVENT_L_2S;
/*耳机配对*/
#ifdef _DEBUG_KEY
printf("long press\r\n");
#endif
}
if( Key_Press_ll_irq )
{
Key_Press_ll_irq = 0;
/*todo*/
Event_key = KEY_EVENT_LL_8S;
#ifdef _DEBUG_KEY
printf("supper long press\r\n");
#endif
}
if( Key_Press_short_irq )
{
Key_Press_short_irq = 0;
/*todo*/
Event_key = KEY_EVENT_SHORT;
#ifdef _DEBUG_KEY
printf("short press\r\n");
#endif
}
#endif
}
#endif