改了按键唤醒、LED逻辑

This commit is contained in:
stark1898y 2025-06-03 14:52:41 +08:00
parent 013bbfb3d3
commit 1e1d323b57
4 changed files with 34 additions and 7 deletions

View File

@ -171,7 +171,7 @@ void app_task_handler(TeAppEvtType app_evt_type)
break;
}
case kKeyLong:
DelayMs(4000);
// DelayMs(4000);
logDebug("button long press");
break;
@ -185,7 +185,7 @@ void app_task_handler(TeAppEvtType app_evt_type)
LED_ALL_OFF_DEINIT;
BEEP_OFF_DEINIT;
// LDect_Deinit();
// // LDect_Deinit();
BSP_NoNeedBoost();
BSP_RequestSleep();

View File

@ -7,7 +7,7 @@
#include <stdbool.h>
#define KEY_TIMOUT_MS 3000
#define KEY_LONG_PRESS_MS 5000
#define KEY_LONG_PRESS_MS 2000
#define KEY_SACN_MS 40
#define KEY_SCAN_EVT (0x0001 << 0)

View File

@ -60,7 +60,8 @@ static uint16_t KEY_Task_ProcessEvent(uint8_t task_id, uint16_t events)
static volatile bool key_vaild_for_long_press = false;
if (IS_KEY_Vaild())
{
if (key_vaild_times > (KEY_LONG_PRESS_MS / KEY_SACN_MS))
// if (key_vaild_times > (KEY_LONG_PRESS_MS / KEY_SACN_MS))
if(key_vaild_times>100) //> 20ms*100=2000ms
{ //> 20ms*100=2000ms
if (false == key_vaild_for_long_press)
{
@ -76,12 +77,14 @@ static uint16_t KEY_Task_ProcessEvent(uint8_t task_id, uint16_t events)
key_vaild_times++;
}
key_timeout_cnt = KEY_TIMOUT_MS / KEY_SACN_MS;
// key_timeout_cnt = 10;
}
else
{
if (key_vaild_times)
{
if ((key_vaild_times) < (KEY_LONG_PRESS_MS / KEY_SACN_MS))
// if ((key_vaild_times) < (KEY_LONG_PRESS_MS / KEY_SACN_MS))
if ((key_vaild_times) < 100)
{
p_handler(kKeyShort);
}
@ -267,7 +270,7 @@ void BSP_KEY_Init(app_task_evt_handler_t handler)
// GPIOB_ModeCfg(GPIO_Pin_0, GPIO_ModeIN_PU);
// GPIOB_ModeCfg(GPIO_Pin_1, GPIO_ModeIN_Floating);
#if 1
#if 0
// 下降沿触发
GPIOB_ITModeCfg(KEY_B_PIN, GPIO_ITMode_FallEdge);
// GPIOB_ITModeCfg(GPIO_Pin_1, GPIO_ITMode_FallEdge);
@ -281,6 +284,17 @@ void BSP_KEY_Init(app_task_evt_handler_t handler)
tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(KEY_SACN_MS));
#endif
#if (HAL_SLEEP == TRUE)
{
R16_PB_INT_MODE |= KEY_B_PIN; // edge mode
GPIOB_ResetBits(KEY_B_PIN); // edge fall
R16_PB_INT_IF = KEY_B_PIN;
R16_PB_INT_EN |= KEY_B_PIN;
PWR_PeriphWakeUpCfg(ENABLE, RB_GPIO_WAKE_MODE|RB_SLP_GPIO_WAKE, Long_Delay);
}
#endif
tmos_start_task(key_task_id, KEY_SCAN_EVT, 32);
logDebug("BSP_KEY_Init=%d", IS_KEY_Vaild());
}
@ -288,6 +302,7 @@ __HIGH_CODE
__attribute__((noinline))
void KEY_ProcessLoop(void)
{
#if 0
if (key_wakeup_flag)
{
// 阻止睡眠
@ -305,6 +320,12 @@ void KEY_ProcessLoop(void)
tmos_set_event(key_task_id, KEY_SCAN_EVT);
logDebug("KEY_ProcessLoop");
}
#endif
if(R16_PB_INT_IF & KEY_B_PIN)
{
R16_PB_INT_IF = KEY_B_PIN;
tmos_set_event(key_task_id, KEY_SCAN_EVT);
}
}

View File

@ -32,16 +32,22 @@ static volatile bool block_boost_flag = false;
static uint32_t block_sleep = 0;
#define DEEP_SLEEP_VALUE 0
#define IDLE_SLEEP_VALUE 1
#define BLOCK_SLEEP_VALUE 0x80000000
__HIGH_CODE
void BSP_RequestSleep(void)
{
block_sleep_flag = false;
block_sleep = DEEP_SLEEP_VALUE;
}
__HIGH_CODE
void BSP_BlockSleep(void)
{
block_sleep_flag = true;
block_sleep = BLOCK_SLEEP_VALUE;
}
__HIGH_CODE
@ -153,7 +159,7 @@ pfnLowPowerGapProcessCB_t LowPowerGapProcess;
__HIGH_CODE
uint32_t CH58x_LowPower(uint32_t time)
{
#if 0
#if 1
// BSP_UART1_TxLowPower();
if (block_boost_flag == false)
{