199 lines
4.3 KiB
C
199 lines
4.3 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 "userapp.h"
|
||
#include "vox_module.h"
|
||
#include "gpio_comm.h"
|
||
#include "hall.h"
|
||
|
||
bit Key_Press_irq = 0;
|
||
|
||
bit Key_Press_short_irq = 0;
|
||
|
||
bit Key_Press_ll_irq_led = 0;
|
||
|
||
#ifdef KEY_ENABLE
|
||
/******************************************************************************\
|
||
Macro definitions
|
||
\******************************************************************************/
|
||
#define KEY_PRESS_CNT0 5 //按键长按500ms显示长按灯效
|
||
|
||
#define KEY_PRESS_CNT1 15
|
||
|
||
#define KEY_PRESS_CNT 30 //按键按下计数3s
|
||
|
||
#define Vox_TX_Key_Pattern_Tim 3
|
||
|
||
#define Vox_TX_Pattern_Tim 24
|
||
|
||
#define Vox_TX_Interval 5 //Vox定时发送指令时间间隔
|
||
|
||
/******************************************************************************\
|
||
Variables definitions
|
||
\******************************************************************************/
|
||
|
||
//bit Key_Press_Flag = 0;
|
||
|
||
/******************************************************************************\
|
||
Functions definitions
|
||
\******************************************************************************/
|
||
|
||
/*
|
||
*******************************************************************************
|
||
* void Key_Handler(void)
|
||
*
|
||
* Description : Key Handler --- 主循环中调用,调用周期5ms。其中长按(按键时间大于2s)需要判断抬键动作才触发。
|
||
CoverStatus --- 充电仓盖子状态。(本函数提供对应Key事件标志位,后续应用待定)
|
||
*
|
||
* Arguments : NONE
|
||
|
||
* Returns : NONE
|
||
|
||
* Notes : NONE
|
||
*
|
||
*******************************************************************************
|
||
*/
|
||
|
||
void Key_Handler(void)
|
||
{
|
||
static uint8_t Key_Press_Debounce;
|
||
|
||
static uint8_t Msg_TX_Debounce;
|
||
|
||
static bit Key_Press_ll_irq;
|
||
|
||
static bit nKey_Press_Flag;
|
||
|
||
static bit nKey_Press_Flag1;
|
||
|
||
static bit Key_Press_Flag;
|
||
|
||
//static bit Key_Lift_Flag;
|
||
|
||
if( !(CHIP_STA0 & 0x02) ) //CHIP_STA0 的bit1为Key的状态值:0:按下;
|
||
{
|
||
Key_Press_Debounce++;
|
||
if( Key_Press_Debounce >= KEY_PRESS_CNT ) //长按3s,VOX掉电
|
||
{
|
||
if( !nKey_Press_Flag )
|
||
{
|
||
nKey_Press_Flag = 1;
|
||
|
||
Key_Press_ll_irq = 1;
|
||
|
||
if( Earphone_Num_2Inbox )
|
||
{
|
||
Key_Press_ll_irq_led = 1;
|
||
#if LED_DISPLAY
|
||
LED_On_Flag = 1;
|
||
#endif
|
||
|
||
}
|
||
}
|
||
}
|
||
else
|
||
if( Key_Press_Debounce >= KEY_PRESS_CNT1 ) //长按1.5s,先升压,到3s后如果有双耳机充电,则显示灯效和发码。
|
||
{
|
||
if( !nKey_Press_Flag1 )
|
||
{
|
||
Wkup_Earphone_Flag = 1;
|
||
|
||
Key_Press_short_irq = 1;
|
||
|
||
nKey_Press_Flag1 = 1;
|
||
}
|
||
}
|
||
|
||
Key_Press_Flag = 1;
|
||
}
|
||
else
|
||
{
|
||
if( Key_Press_Flag )
|
||
{
|
||
Key_Press_Flag = 0;
|
||
|
||
nKey_Press_Flag = 0;
|
||
|
||
//Key_Lift_Flag = 1;
|
||
|
||
nKey_Press_Flag1 = 0;
|
||
|
||
Key_Press_short_irq = 0;
|
||
|
||
if( (Key_Press_Debounce < KEY_PRESS_CNT0) ) //松开按键,按下时间小于500ms,则识别为短按,显示电量
|
||
{
|
||
Key_Press_irq = 1; //短按,显示电量
|
||
#if LED_DISPLAY
|
||
LED_On_Flag = 1;
|
||
#endif
|
||
}
|
||
}
|
||
|
||
Key_Press_Debounce = 0;
|
||
}
|
||
|
||
/*按键3s后,发清除配对码吗,每隔400ms发5次,发完后蓝灯亮4下。*/
|
||
if( Key_Press_ll_irq )
|
||
{
|
||
if( Msg_TX_Debounce <= Vox_TX_Pattern_Tim )
|
||
{
|
||
if( (Msg_TX_Debounce % Vox_TX_Interval == 0) )
|
||
{
|
||
if( Earphone_Num_2Inbox ) //按键发码需双耳机在盒才发。
|
||
{
|
||
|
||
//if( (CHIP_STA1 & 0xAC) == 0xA0 )
|
||
{
|
||
#if VOX_TX_PATTERN
|
||
|
||
Pattern_TX_Start = 1;
|
||
|
||
Pattern_TX_Data = 0x05;
|
||
|
||
g_Key_Type = 1;
|
||
#endif
|
||
}
|
||
}
|
||
}
|
||
|
||
Msg_TX_Debounce++;
|
||
}
|
||
else
|
||
{
|
||
Key_Press_ll_irq = 0;
|
||
|
||
Msg_TX_Debounce = 1;
|
||
|
||
if( CoverStatus == OPEN )
|
||
{
|
||
Vout_Ctrl_OFF(ON);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
#endif
|