249 lines
5.1 KiB
C
249 lines
5.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"
|
||
|
||
#if KEY_HALL_ENABLE
|
||
/******************************************************************************\
|
||
Macro definitions
|
||
\******************************************************************************/
|
||
|
||
/******************************************************************************\
|
||
Variables definitions
|
||
\******************************************************************************/
|
||
idata KEY_EVENT_E Event_key = 0;
|
||
|
||
bit Key_Press_short_irq = 0;
|
||
bit Key_Press_l_irq = 0;
|
||
bit Key_Press_ll_irq = 0;
|
||
|
||
//bit Key_short_Flag = 0;
|
||
bit Key_l_Flag = 0;
|
||
//bit Key_ll_Flag = 0;
|
||
|
||
bit Hall_Positive_Flg = 0;
|
||
bit Hall_Negative_Flg = 0;
|
||
|
||
|
||
/******************************************************************************\
|
||
Functions definitions
|
||
\******************************************************************************/
|
||
|
||
/*
|
||
*******************************************************************************
|
||
* void Key_Init(void)
|
||
*
|
||
* Description : Hey Initialization
|
||
*
|
||
* Arguments :
|
||
|
||
* Returns :
|
||
|
||
* Notes :
|
||
*
|
||
*******************************************************************************
|
||
*/
|
||
#if 0
|
||
void Key_Init(void)
|
||
{
|
||
|
||
SFRADDR = MFP_CTL1; //Set P05 as key Function
|
||
SFRDATA &= ~0x3C;
|
||
SFRDATA |= 0x14;
|
||
|
||
SFRADDR = PMU_CTL0;
|
||
SFRDATA |= 0x02; //Key Detect Enable
|
||
|
||
//KEY_CTL = 0x04; //Set all of the functions about KEY are enable.
|
||
}
|
||
#endif
|
||
|
||
/*
|
||
*******************************************************************************
|
||
* void KEY_irq(void)
|
||
*
|
||
* Description : INT4 <20>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϰ<D0B6><CFB0><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>͡<EFBFBD>
|
||
*
|
||
* Arguments : NONE
|
||
|
||
* Returns : NONE
|
||
|
||
* Notes : NONE
|
||
*
|
||
*******************************************************************************
|
||
*/
|
||
void KEY_irq(void)
|
||
{
|
||
uint8_t IRQ7_Status = 0;
|
||
|
||
IRQ7_Status = IRQ_FLAG7;
|
||
IRQ_FLAG7 = IRQ7_Status;
|
||
|
||
if( IRQ7_Status & 0x10 ) //Key short press for 16ms-1s interrupt flag
|
||
{
|
||
Key_Press_short_irq = 1;
|
||
Event_key = KEY_EVENT_SHORT;
|
||
}
|
||
|
||
if( IRQ7_Status & 0x20 ) //Key long press for 2s interrupt flag and Key release interrupt flag
|
||
{
|
||
Key_Press_l_irq = 1;
|
||
Event_key = KEY_EVENT_L_2S;
|
||
}
|
||
|
||
if( IRQ7_Status & 0x40 ) //Key super long press for 8s interrupt flag
|
||
{
|
||
Key_Press_ll_irq = 1;
|
||
Key_Press_l_irq = 0;
|
||
Event_key = KEY_EVENT_LL_8;
|
||
}
|
||
|
||
if( IRQ7_Status & 0x08 )
|
||
{
|
||
if( Key_Press_l_irq )
|
||
{
|
||
Key_Press_l_irq = 0;
|
||
Key_l_Flag = 1;
|
||
}
|
||
}
|
||
|
||
if( (IRQ7_Status & 0xF0) == 0xF0 )
|
||
{
|
||
gIrq_Event_Type |= KEY_IRQ_EVENT;
|
||
}
|
||
}
|
||
/*
|
||
*******************************************************************************
|
||
* void Key_Handler(void)
|
||
*
|
||
* Description : Key Handler --- <20><>ѭ<EFBFBD><D1AD><EFBFBD>е<EFBFBD><D0B5>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>10ms<6D><73><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD><D0B3><EFBFBD>(<28><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2s(or 3s))<29><>Ҫ<EFBFBD>ж<EFBFBD>̧<EFBFBD><CCA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD><EFBFBD>
|
||
CoverStatus --- <20><><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṩ<EFBFBD><E1B9A9>ӦKey<65>¼<EFBFBD><C2BC><EFBFBD>־λ<D6BE><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD>
|
||
*
|
||
* Arguments : NONE
|
||
|
||
* Returns : NONE
|
||
|
||
* Notes : NONE
|
||
*
|
||
*******************************************************************************
|
||
*/
|
||
|
||
void Key_Handler(void)
|
||
{
|
||
if( Key_l_Flag )
|
||
{
|
||
Key_Press_l_irq = 0;
|
||
Key_l_Flag = 0;
|
||
|
||
Event_key = KEY_EVENT_L_2S;
|
||
|
||
#ifdef LED_DISPLAY
|
||
|
||
LED_R_FLASH(500,8);
|
||
|
||
#endif
|
||
|
||
#ifdef _DEBUG_KEY
|
||
printf("long press\r\n");
|
||
#endif
|
||
}
|
||
|
||
if( Key_Press_ll_irq )
|
||
{
|
||
Key_Press_ll_irq = 0;
|
||
|
||
Event_key = KEY_EVENT_LL_8;
|
||
|
||
#ifdef LED_DISPLAY
|
||
|
||
LED_R_FLASH(500,5);
|
||
#endif
|
||
|
||
#ifdef _DEBUG_KEY
|
||
printf("supper long press\r\n");
|
||
#endif
|
||
}
|
||
|
||
if( Key_Press_short_irq )
|
||
{
|
||
Key_Press_short_irq = 0;
|
||
|
||
Event_key = KEY_EVENT_SHORT;
|
||
|
||
#ifdef LED_DISPLAY
|
||
LED_R_FLASH(500,3);
|
||
#endif
|
||
|
||
#ifdef _DEBUG_KEY
|
||
printf("short press\r\n");
|
||
#endif
|
||
|
||
}
|
||
}
|
||
/*
|
||
*******************************************************************************
|
||
* void EX4_isr(void) interrupt Interrupt_Vector_IE4
|
||
*
|
||
* Description : System External Intterupt 4
|
||
*
|
||
* Arguments : NONE
|
||
|
||
* Returns : NONE
|
||
|
||
* Notes : NONE
|
||
*
|
||
*******************************************************************************
|
||
*/
|
||
void EX4_isr(void) interrupt Interrupt_Vector_IE4
|
||
{
|
||
uint8_t IRQ10_Status = 0;
|
||
|
||
IRQ10_Status = IRQ_FLAG10;
|
||
IRQ_FLAG10 = IRQ10_Status;
|
||
|
||
KEY_irq();
|
||
|
||
if(IRQ10_Status & 0x08)
|
||
{
|
||
Hall_Negative_Flg = 1;
|
||
}
|
||
else
|
||
if(IRQ10_Status & 0x04)
|
||
{
|
||
Hall_Positive_Flg = 1;
|
||
}
|
||
|
||
if(IRQ10_Status & 0x0C)
|
||
{
|
||
gIrq_Event_Type |= HALL_IRQ_EVENT;
|
||
}
|
||
|
||
#if SLEEP_ENABLE
|
||
if(!Enter_Sleep_Cnt_Restart_Flag)
|
||
{
|
||
Enter_Sleep_Cnt_Restart_Flag = 1;
|
||
}
|
||
#endif
|
||
}
|
||
|
||
#endif
|