SY883x_For_Client_JLAB_JS07/UsrSrc/key/key.c
Alex xu a29b5cb50b 更改内容:1、将全局变量在定义时不赋初值,需要赋初值的变量在系统初始化函数中赋值,节省ROM占用月100Bytes;
2、删除按键短按显示电量功能;
3、增加开盖Vox输出5V给耳机充电功能,有耳机入盒灯效,无出盒灯效,Vox检测到轻载后延迟10分钟后关闭Vox输出5V,转入ADT模式;
4、增加Vox充电过程中电池电压触发3.6V低电报警阈值后,Vox发送电量码pattern功能。
2025-02-10 11:37:49 +08:00

212 lines
4.5 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 "userapp.h"
#include "vox_module.h"
#include "gpio_comm.h"
#include "hall.h"
//bit Key_Press_irq = 0;
bit Key_Press_short_irq;
bit Key_Press_ll_irq_led;
#ifdef KEY_ENABLE
/******************************************************************************\
Macro definitions
\******************************************************************************/
#define KEY_PRESS_CNT0 5 //按键长按500ms显示长按灯效
#define KEY_PRESS_CNT1 12
#define KEY_PRESS_CNT2 10
#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 Key_Press_Flag;
if( !(CHIP_STA0 & 0x02) ) //CHIP_STA0 的bit1为Key的状态值0按下
{
Key_Press_Debounce++;
if( Key_Press_Debounce >= KEY_PRESS_CNT ) //长按3s显示灯效和发码
{
if( nKey_Press_Flag )
{
nKey_Press_Flag = 0;
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_CNT2 ) //长按1.5s,先升压到3s后如果有双耳机充电则显示灯效和发码。
{
if( (!nKey_Press_Flag) && !F_batlevel_protect )
{
Key_Press_short_irq = 1;
if( Key_Press_Debounce < KEY_PRESS_CNT1 )
{
VOX_CTL0 |= 0x30; //VOX Enable 5V
BST_EN = 0;
SFRADDR = P0_OE;
SFRDATA &= 0xF9; //P01、P02为Floating
return;
}
P01 = 1;
SFRADDR = P0_OE;
SFRDATA |= 0x02;
VOX_CTL0 &= ~0x30;
Wkup_Earphone_Flag = 1;
Get_Vox_Num_Flag = 1;
nKey_Press_Flag = 1;
}
}
Key_Press_Flag = 1;
}
else
{
if( Key_Press_Flag )
{
Key_Press_Flag = 0;
nKey_Press_Flag = 0;
Key_Press_short_irq = 0;
#if 0
if( (Key_Press_Debounce < KEY_PRESS_CNT0) ) //松开按键按下时间小于500ms则识别为短按显示电量
{
Key_Press_irq = 1; //短按,显示电量
#if LED_DISPLAY
LED_On_Flag = 1;
#endif
}
#endif
}
Key_Press_Debounce = 0;
}
/*按键3s后发清除配对码吗每隔400ms发4次发完后蓝灯亮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 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 = 0;
#if 0
if( CoverStatus == OPEN )
{
Vout_Ctrl_OFF(ON);
}
#endif
}
}
}
#endif