移植了ch585_ble_uart_new_lpr_test的基本可以

This commit is contained in:
stark1898y 2024-12-14 16:53:49 +08:00
parent 1dab144866
commit c1ed09206c
4 changed files with 79 additions and 72 deletions

View File

@ -38,26 +38,27 @@
__attribute__((aligned(4))) uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4]; __attribute__((aligned(4))) uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];
// void app_task_handler(TeAppEvtType app_evt_type) void app_task_handler(TeAppEvtType app_evt_type)
// { {
// switch(app_evt_type) switch(app_evt_type)
// { {
// case kKeyShort:{ case kKeyShort:{
// PRINT("button short press\r\n"); PRINT("button short press\r\n");
// break; break;
// } }
// case kKeyLong: case kKeyLong:
// PRINT("button long press\r\n"); PRINT("button long press\r\n");
// break; break;
// case kKeyRelease: case kKeyRelease:
// PRINT("gpio relase\r\n"); BSP_KEY_EnterLowpower();
PRINT("gpio relase\r\n");
// break; break;
// default: default:
// break; break;
// } }
// } }
/********************************************************************* /*********************************************************************
* @fn Main_Circulation * @fn Main_Circulation
@ -154,7 +155,7 @@ void Main_Circulation()
*/ */
void BLE_AdvertiseEventCB(uint32_t timeUs) void BLE_AdvertiseEventCB(uint32_t timeUs)
{ {
logDebug("BLE_AdvertiseEventCB"); // logDebug("BLE_AdvertiseEventCB");
} }
/********************************************************************* /*********************************************************************
@ -215,7 +216,8 @@ int main(void)
// DelayMs(100); // DelayMs(100);
// } // }
BSP_KEY_Init(); // BSP_KEY_Init();
BSP_KEY_Init(app_task_handler);
Main_Circulation(); Main_Circulation();
} }

View File

@ -23,11 +23,12 @@ typedef enum
kKeyRelease, kKeyRelease,
} TeAppEvtType; } TeAppEvtType;
typedef void (*app_task_evt_handler_t)(TeAppEvtType app_task_evt_type);
void BSP_KEY_EnterLowpower(void); void BSP_KEY_EnterLowpower(void);
void BSP_KEY_ExitLowpower(void); void BSP_KEY_ExitLowpower(void);
void BSP_KEY_Init(void); void BSP_KEY_Init(app_task_evt_handler_t handler);
void KEY_ProcessLoop(void); void KEY_ProcessLoop(void);

View File

@ -1,7 +1,5 @@
#include "bsp_key.h" #include "bsp_key.h"
#include "multi_button.h"
#include "bsp_uart.h" #include "bsp_uart.h"
#include "log.h" #include "log.h"
@ -15,17 +13,15 @@
#undef LOG_TAG #undef LOG_TAG
#define LOG_TAG "key" #define LOG_TAG "key"
enum Button_IDs {
btn1_id,
};
struct Button btn1;
tmosTaskID key_task_id = INVALID_TASK_ID; tmosTaskID key_task_id = INVALID_TASK_ID;
volatile uint8_t key_wakeup_flag = 0; volatile uint8_t key_wakeup_flag = 0;
volatile uint8_t key_timeout_flag = 0; volatile uint8_t key_timeout_flag = 0;
static app_task_evt_handler_t p_handler = NULL;
static volatile uint8_t key_timeout_cnt = 0;
static void KEY_Task_ProcessTmosMsg(tmos_event_hdr_t *pMsg) static void KEY_Task_ProcessTmosMsg(tmos_event_hdr_t *pMsg)
{ {
switch (pMsg->event) switch (pMsg->event)
@ -36,7 +32,9 @@ static void KEY_Task_ProcessTmosMsg(tmos_event_hdr_t *pMsg)
} }
} }
#if 0 #define KEY_TIMOUT_MS 5000
#if 1
static uint16_t KEY_Task_ProcessEvent(uint8_t task_id, uint16_t events) static uint16_t KEY_Task_ProcessEvent(uint8_t task_id, uint16_t events)
{ {
if (events & SYS_EVENT_MSG) if (events & SYS_EVENT_MSG)
@ -74,7 +72,7 @@ static uint16_t KEY_Task_ProcessEvent(uint8_t task_id, uint16_t events)
{ {
key_vaild_times++; key_vaild_times++;
} }
key_timeout_cnt = 10; key_timeout_cnt = KEY_TIMOUT_MS / 100;
} }
else else
{ // button release { // button release
@ -94,7 +92,7 @@ static uint16_t KEY_Task_ProcessEvent(uint8_t task_id, uint16_t events)
if (key_timeout_cnt) if (key_timeout_cnt)
{ {
key_timeout_cnt--; key_timeout_cnt--;
tmos_start_task(key_task_id, KEY_SCAN_EVT, 64); // 40ms tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(100)); // 40ms
} }
else else
{ {
@ -112,8 +110,8 @@ static uint16_t KEY_Task_ProcessEvent(uint8_t task_id, uint16_t events)
// 由按键中断唤醒后开启按键扫描 // 由按键中断唤醒后开启按键扫描
void BSP_KEY_EnterLowpower(void) void BSP_KEY_EnterLowpower(void)
{ {
key_wakeup_flag = 0; // key_wakeup_flag = 0;
tmos_stop_task(key_task_id, KEY_SCAN_EVT); // tmos_stop_task(key_task_id, KEY_SCAN_EVT);
// R16_PB_INT_MODE |= KEY_B_PIN; // edge mode // R16_PB_INT_MODE |= KEY_B_PIN; // edge mode
// GPIOB_ResetBits(KEY_B_PIN); // edge fall // GPIOB_ResetBits(KEY_B_PIN); // edge fall
@ -147,26 +145,9 @@ void BSP_KEY_ExitLowpower(void)
// tmos_start_reload_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(30)); // tmos_start_reload_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(30));
} }
__HIGH_CODE
__attribute__((noinline))
void KEY_ProcessLoop(void)
{
// if (R16_PB_INT_IF & KEY_B_PIN)
// {
// R16_PB_INT_IF = KEY_B_PIN;
// tmos_set_event(key_task_id, KEY_SCAN_EVT);
// logDebug("KEY_ProcessLoop");
// }
if (key_wakeup_flag)
{
key_wakeup_flag = 0;
tmos_set_event(key_task_id, KEY_SCAN_EVT);
// tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(20));
// tmos_start_task(key_task_id, KEY_IDLE_TIMEOUT_EVT, MS1_TO_SYSTEM_TIME(1000 * 10));
logDebug("key_wakeup_flag");
}
}
#if 0
uint8_t read_button_GPIO(uint8_t button_id) uint8_t read_button_GPIO(uint8_t button_id)
{ {
// you can share the GPIO read function with multiple Buttons // you can share the GPIO read function with multiple Buttons
@ -264,27 +245,18 @@ static uint16_t KEY_Task_ProcessEvent(uint8_t task_id, uint16_t events)
// Discard unknown events // Discard unknown events
return 0; return 0;
} }
#endif
void BSP_KEY_Init(app_task_evt_handler_t handler)
void BSP_KEY_Init(void)
{ {
p_handler = handler;
key_task_id = TMOS_ProcessEventRegister(KEY_Task_ProcessEvent);
// 由外部上拉电阻了 // 由外部上拉电阻了
// 设置为浮空输入模式 // 设置为浮空输入模式
GPIOB_SetBits(KEY_B_PIN); GPIOB_SetBits(KEY_B_PIN);
GPIOB_ModeCfg(KEY_B_PIN, GPIO_ModeIN_PU); GPIOB_ModeCfg(KEY_B_PIN, GPIO_ModeIN_PU);
button_init(&btn1, read_button_GPIO, 0, btn1_id);
// button_attach(&btn1, PRESS_DOWN, BTN1_PRESS_DOWN_Handler);
button_attach(&btn1, PRESS_UP, BTN1_PRESS_UP_Handler);
button_attach(&btn1, SINGLE_CLICK, BTN1_SINGLE_Click_Handler);
button_attach(&btn1, DOUBLE_CLICK, BTN1_DOUBLE_Click_Handler);
button_attach(&btn1, LONG_PRESS_START, BTN1_LONG_PRESS_START_Handler);
button_start(&btn1);
// 下降沿触发 // 下降沿触发
GPIOB_ITModeCfg(KEY_B_PIN, GPIO_ITMode_FallEdge); GPIOB_ITModeCfg(KEY_B_PIN, GPIO_ITMode_FallEdge);
@ -295,15 +267,47 @@ void BSP_KEY_Init(void)
// 开启GPIOB中断 // 开启GPIOB中断
PFIC_EnableIRQ(GPIO_B_IRQn); PFIC_EnableIRQ(GPIO_B_IRQn);
key_task_id = TMOS_ProcessEventRegister(KEY_Task_ProcessEvent); tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(20));
// tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(5)); // tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(5));
//开始一个定时事件,不断的执行,除非运行tmos_stop_task关掉, //开始一个定时事件,不断的执行,除非运行tmos_stop_task关掉,
//tmosTimer具体是 1600 = 1s //tmosTimer具体是 1600 = 1s
// tmos_start_reload_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(20));
// BSP_KEY_EnterLowpower(); // BSP_KEY_EnterLowpower();
} }
__HIGH_CODE
__attribute__((noinline))
void KEY_ProcessLoop(void)
{
// {
// if (R16_PB_INT_IF & KEY_B_PIN)
// {
// R16_PB_INT_IF = KEY_B_PIN;
// tmos_set_event(key_task_id, KEY_SCAN_EVT);
// logDebug("KEY_ProcessLoop");
// }
// }
if (key_wakeup_flag)
{
key_wakeup_flag = 0;
GPIOB_ClearITFlagBit(KEY_B_PIN);
tmos_set_event(key_task_id, KEY_SCAN_EVT);
logDebug("KEY_ProcessLoop");
}
// if (key_wakeup_flag)
// {
// key_wakeup_flag = 0;
// tmos_set_event(key_task_id, KEY_SCAN_EVT);
// // tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(20));
// // tmos_start_task(key_task_id, KEY_IDLE_TIMEOUT_EVT, MS1_TO_SYSTEM_TIME(1000 * 10));
// logDebug("key_wakeup_flag");
// }
}
__INTERRUPT // 告诉编译器使用硬件压栈 __INTERRUPT // 告诉编译器使用硬件压栈
__HIGH_CODE // 放到RAM里 __HIGH_CODE // 放到RAM里
void GPIOB_IRQHandler(void) void GPIOB_IRQHandler(void)
@ -315,10 +319,10 @@ void GPIOB_IRQHandler(void)
logDebug("KEY IRQ"); logDebug("KEY IRQ");
GPIOB_ClearITFlagBit(KEY_B_PIN); // GPIOB_ClearITFlagBit(KEY_B_PIN);
key_wakeup_flag = 1; key_wakeup_flag = 1;
key_timeout_flag = 0; // key_timeout_flag = 0;
// BSP_BlockSleep(); // BSP_BlockSleep();

View File

@ -105,7 +105,7 @@ uint32_t CH59x_LowPower(uint32_t time)
// LOW POWER-sleep模式 // LOW POWER-sleep模式
if (!RTCTigFlag) if (!RTCTigFlag)
{ {
// BSP_KEY_EnterLowpower(); BSP_KEY_EnterLowpower();
LowPower_Sleep(RB_PWR_RAM2K | RB_PWR_RAM24K | RB_PWR_EXTEND | RB_XT_PRE_EN); LowPower_Sleep(RB_PWR_RAM2K | RB_PWR_RAM24K | RB_PWR_EXTEND | RB_XT_PRE_EN);
HSECFG_Current(HSE_RCur_100); // 降为额定电流(低功耗函数中提升了HSE偏置电流) HSECFG_Current(HSE_RCur_100); // 降为额定电流(低功耗函数中提升了HSE偏置电流)