V1-1硬件,更改KEY IO
This commit is contained in:
parent
4d2621e2e4
commit
a6f40e4c90
|
@ -17,11 +17,11 @@
|
|||
#define KEY_IDLE_TIMEOUT_EVT (0x0001 << 3)
|
||||
|
||||
// KEY_B_PIN at PB7,low->active
|
||||
#define KEY_A_PIN GPIO_Pin_7
|
||||
#define KEY_BPIN GPIO_Pin_15
|
||||
|
||||
extern volatile uint8_t key_wakeup_flag;
|
||||
|
||||
#define IS_KEY_Vaild() ((GPIOA_ReadPortPin(KEY_A_PIN) ? 0 : 1))
|
||||
#define IS_KEY_Vaild() ((GPIOB_ReadPortPin(KEY_BPIN) ? 0 : 1))
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#define LED_VALVE_R_PIN GPIO_Pin_8
|
||||
#define LED_VALVE_G_PIN GPIO_Pin_9
|
||||
#define LED_ALARM_PIN GPIO_Pin_1
|
||||
#define LED_VBAT_PIN GPIO_Pin_12
|
||||
#define LED_VBAT_PIN GPIO_Pin_7
|
||||
|
||||
/***********************************************************************************************
|
||||
#define LED_VALVE_OPEN {GPIOA_ResetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
|
||||
|
@ -26,12 +26,12 @@
|
|||
|
||||
#define LED_ALARM_CLOSE GPIOB_ResetBits(LED_ALARM_PIN)
|
||||
|
||||
#define LED_VBAT_OPEN GPIOB_SetBits(LED_VBAT_PIN)
|
||||
#define LED_VBAT_OPEN GPIOA_SetBits(LED_VBAT_PIN)
|
||||
|
||||
#define LED_VBAT_CLOSE GPIOB_ResetBits(LED_VBAT_PIN)
|
||||
#define LED_VBAT_CLOSE GPIOA_ResetBits(LED_VBAT_PIN)
|
||||
|
||||
#define LED_ALL_OPEN {GPIOA_SetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
|
||||
GPIOB_SetBits(LED_ALARM_PIN | LED_VBAT_PIN);}
|
||||
GPIOA_SetBits(LED_ALARM_PIN | LED_VBAT_PIN)}
|
||||
|
||||
#define LED_ALL_CLOSE {GPIOA_ResetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
|
||||
GPIOA_ResetBits(LED_ALARM_PIN | LED_VBAT_PIN);}
|
||||
|
|
|
@ -424,8 +424,8 @@ void Lower_IO_Deinit(void)
|
|||
GPIOA_ModeCfg(LED_VBAT_PIN | LED_ALARM_PIN, GPIO_ModeIN_PD);
|
||||
|
||||
// KEY | RESET KEY | boot KEY
|
||||
GPIOA_ResetBits(KEY_A_PIN);
|
||||
GPIOA_ModeCfg(KEY_A_PIN, GPIO_ModeIN_PU);
|
||||
GPIOA_ResetBits(KEY_BPIN);
|
||||
GPIOA_ModeCfg(KEY_BPIN, GPIO_ModeIN_PU);
|
||||
// GPIOB_ResetBits(GPIO_Pin_23 | GPIO_Pin_22);
|
||||
// GPIOB_ModeCfg(GPIO_Pin_23 | GPIO_Pin_22, GPIO_ModeIN_PD);
|
||||
|
||||
|
@ -1162,27 +1162,6 @@ __INTERRUPT
|
|||
__HIGH_CODE
|
||||
void GPIOA_IRQHandler(void)
|
||||
{
|
||||
// 清除中断标志位
|
||||
GPIOA_ClearITFlagBit(KEY_A_PIN);
|
||||
|
||||
// 检查是否为真实按键事件(通过确认电平是否真的接近0V)
|
||||
if (GPIOA_ReadPortPin(KEY_A_PIN) == 0)
|
||||
{
|
||||
// 再次确认是否真的为低电平(接近0V)
|
||||
DelayUs(10); // 短暂延时50
|
||||
if (GPIOA_ReadPortPin(KEY_A_PIN) == 0)
|
||||
{
|
||||
// 确认是真实按键事件
|
||||
// 阻止睡眠
|
||||
BSP_BlockSleep();
|
||||
// 关按键中断
|
||||
BSP_KEY_ExitLowpower();
|
||||
|
||||
printf("KEY IRQHandler !!!");
|
||||
key_wakeup_flag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (R16_PA_INT_IF & GPIO_Pin_9)
|
||||
{
|
||||
R16_PA_INT_IF = GPIO_Pin_9;
|
||||
|
|
|
@ -173,14 +173,14 @@ void BSP_KEY_EnterLowpower(void)
|
|||
|
||||
// TODO:按键电平触发设置
|
||||
// 下降沿触发
|
||||
GPIOA_ITModeCfg(KEY_A_PIN, GPIO_ITMode_FallEdge);
|
||||
GPIOB_ITModeCfg(KEY_BPIN, GPIO_ITMode_FallEdge);
|
||||
|
||||
// 开启GPIO的睡眠唤醒,如果需要的话
|
||||
// PWR_PeriphWakeUpCfg(ENABLE, RB_SLP_GPIO_WAKE, Long_Delay);
|
||||
PWR_PeriphWakeUpCfg(ENABLE, RB_GPIO_WAKE_MODE | RB_SLP_GPIO_WAKE, Long_Delay);
|
||||
|
||||
// 开启GPIOB中断
|
||||
PFIC_EnableIRQ(GPIO_A_IRQn);
|
||||
PFIC_EnableIRQ(GPIO_B_IRQn);
|
||||
}
|
||||
|
||||
void BSP_KEY_ExitLowpower(void)
|
||||
|
@ -188,7 +188,7 @@ void BSP_KEY_ExitLowpower(void)
|
|||
BSP_BlockSleep();
|
||||
|
||||
// 关闭GPIOB中断
|
||||
PFIC_DisableIRQ(GPIO_A_IRQn);
|
||||
PFIC_DisableIRQ(GPIO_B_IRQn);
|
||||
PWR_PeriphWakeUpCfg(DISABLE, RB_GPIO_WAKE_MODE | RB_SLP_GPIO_WAKE, Long_Delay);
|
||||
}
|
||||
|
||||
|
@ -298,21 +298,19 @@ void BSP_KEY_Init(app_task_evt_handler_t handler)
|
|||
key_task_id = TMOS_ProcessEventRegister(KEY_Task_ProcessEvent);
|
||||
|
||||
// 由外部上拉电阻了
|
||||
// 设置为浮空输入模式
|
||||
// GPIOB_SetBits(KEY_B_PIN);
|
||||
GPIOA_ModeCfg(KEY_A_PIN, GPIO_ModeIN_PU);
|
||||
GPIOB_ModeCfg(KEY_BPIN, GPIO_ModeIN_PU);
|
||||
|
||||
// 下降沿触发
|
||||
GPIOA_ITModeCfg(KEY_A_PIN, GPIO_ITMode_FallEdge);
|
||||
// GPIOB_ITModeCfg(KEY_BPIN, GPIO_ITMode_FallEdge);
|
||||
|
||||
// 开启GPIO的睡眠唤醒,如果需要的话
|
||||
// PWR_PeriphWakeUpCfg(ENABLE, RB_SLP_GPIO_WAKE, Long_Delay);
|
||||
PWR_PeriphWakeUpCfg(ENABLE, RB_GPIO_WAKE_MODE | RB_SLP_GPIO_WAKE, Long_Delay);
|
||||
// PWR_PeriphWakeUpCfg(ENABLE, RB_GPIO_WAKE_MODE | RB_SLP_GPIO_WAKE, Long_Delay);
|
||||
|
||||
// 开启GPIOB中断
|
||||
PFIC_EnableIRQ(GPIO_A_IRQn);
|
||||
// PFIC_EnableIRQ(GPIO_B_IRQn);
|
||||
|
||||
tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(KEY_SACN_MS));
|
||||
// tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(KEY_SACN_MS));
|
||||
|
||||
// tmos_start_task(key_task_id, KEY_SCAN_EVT, MS1_TO_SYSTEM_TIME(5));
|
||||
|
||||
|
@ -326,12 +324,12 @@ __attribute__((noinline))
|
|||
void KEY_ProcessLoop(void)
|
||||
{
|
||||
// static uint8_t key_flag = 0;
|
||||
|
||||
|
||||
if (key_wakeup_flag)
|
||||
{
|
||||
key_wakeup_flag = 0;
|
||||
press_count++;
|
||||
|
||||
|
||||
if (press_count == 1)
|
||||
{
|
||||
motor_flag = 3;
|
||||
|
@ -362,49 +360,29 @@ void KEY_ProcessLoop(void)
|
|||
// }
|
||||
press_count = 0;
|
||||
}
|
||||
|
||||
|
||||
tmos_set_event(key_task_id, KEY_SCAN_EVT);
|
||||
logDebug("KEY_ProcessLoop");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__INTERRUPT // 告诉编译器使用硬件压栈
|
||||
__HIGH_CODE // 放到RAM里
|
||||
void GPIOB_IRQHandler(void)
|
||||
{
|
||||
/* // 清除中断标志位
|
||||
GPIOA_ClearITFlagBit(KEY_A_PIN);
|
||||
// 清除中断标志位
|
||||
GPIOB_ClearITFlagBit(KEY_BPIN);
|
||||
|
||||
// 检查是否为真实按键事件(通过确认电平是否真的接近0V)
|
||||
if (GPIOA_ReadPortPin(KEY_A_PIN) == 0) {
|
||||
// 再次确认是否真的为低电平(接近0V)
|
||||
DelayUs(50); // 短暂延时
|
||||
if (GPIOA_ReadPortPin(KEY_A_PIN) == 0) {
|
||||
// 确认是真实按键事件
|
||||
// 阻止睡眠
|
||||
BSP_BlockSleep();
|
||||
// 关按键中断
|
||||
BSP_KEY_ExitLowpower();
|
||||
|
||||
printf("KEY IRQ");
|
||||
key_wakeup_flag = 1;
|
||||
}
|
||||
} else {
|
||||
// 可能是电源波动导致的中断,忽略此次中断
|
||||
printf("Power Fluctuation - Ignored");
|
||||
} */
|
||||
|
||||
|
||||
// // 阻止睡眠
|
||||
// BSP_BlockSleep();
|
||||
// // 关按键中断
|
||||
// BSP_KEY_ExitLowpower();
|
||||
|
||||
// printf("KEY IRQ");
|
||||
|
||||
// GPIOB_ClearITFlagBit(KEY_B_PIN);
|
||||
|
||||
// key_wakeup_flag = 1;
|
||||
if (IS_KEY_Vaild() == 0)
|
||||
{
|
||||
// 确认是真实按键事件
|
||||
// 阻止睡眠
|
||||
BSP_BlockSleep();
|
||||
// 关按键中断
|
||||
BSP_KEY_ExitLowpower();
|
||||
|
||||
logDebug("KEY IRQ");
|
||||
key_wakeup_flag = 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue