feat: 添加旋转编码器按键长短按功能

This commit is contained in:
2024-01-05 15:55:17 +08:00
parent b4b265cdef
commit 535cb372df
8 changed files with 75 additions and 38 deletions

View File

@@ -11,7 +11,7 @@ void by_gpio_init(void)
void by_exit_init(void)
{
exti_init(E9, EXTI_TRIGGER_FALLING);
exti_init(E11, EXTI_TRIGGER_FALLING);
exti_init(E11, EXTI_TRIGGER_BOTH);
}
/**

View File

@@ -3,9 +3,15 @@
#include "stdio.h"
#include "ch32v30x.h"
#define ROTATE_BUTTON_PRESS 1
#define ROTATE_BUTTON_FORWARD 2
#define ROTATE_BUTTON_BACKWARD 3
// #define rotate_button_press_short 1
// #define rotate_button_forward 2
// #define rotate_button_backward 3
typedef enum rotate_button_event{
rotate_button_press_short = 1,
rotate_button_press_long = 2,
rotate_button_forward = 3,
rotate_button_backward = 4,
}rotate_button_event;
extern uint8_t rotate_button;

View File

@@ -198,10 +198,10 @@ void EXTI9_5_IRQHandler(void)
if (SET == EXTI_GetITStatus(EXTI_Line9)) {
if (SET == gpio_get_level(E10)) {
rotate_button = ROTATE_BUTTON_BACKWARD;
rotate_button = rotate_button_backward;
} else {
rotate_button = ROTATE_BUTTON_FORWARD;
rotate_button = rotate_button_forward;
}
EXTI_ClearITPendingBit(EXTI_Line9);
}
@@ -218,37 +218,54 @@ void EXTI15_10_IRQHandler(void)
EXTI_ClearITPendingBit(EXTI_Line10);
}
if (SET == EXTI_GetITStatus(EXTI_Line11)) {
static uint64_t time_fly = 0;
system_delay_us(200);
if (SET == !gpio_get_level(E11)) {
rotate_button = ROTATE_BUTTON_PRESS;
if (RESET == gpio_get_level(E11)) {
system_delay_us(200);
if (RESET == gpio_get_level(E11)) {
time_fly = system_get_tick();
// rotate_button = rotate_button_press_short;
}
EXTI_ClearITPendingBit(EXTI_Line11);
} else {
system_delay_us(200);
if (SET == gpio_get_level(E11)) {
// rotate_button = rotate_button_press_short;
time_fly = system_get_tick() - time_fly;
if (time_fly > LONG_PRESS_THRESHOLD_TICK) {
rotate_button = rotate_button_press_long;
} else {
rotate_button = rotate_button_press_short;
}
time_fly = 0;
}
EXTI_ClearITPendingBit(EXTI_Line11);
}
EXTI_ClearITPendingBit(EXTI_Line11);
}
if (SET == EXTI_GetITStatus(EXTI_Line12)) {
EXTI_ClearITPendingBit(EXTI_Line12);
}
if (SET == EXTI_GetITStatus(EXTI_Line13)) {
// -----------------* ToF INT <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
tof_module_exti_handler();
// -----------------* ToF INT <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
// <20>˴<EFBFBD><CBB4><EFBFBD>д<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD> (A13/B13..E13) <20><><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD>
if (SET == EXTI_GetITStatus(EXTI_Line12)) {
EXTI_ClearITPendingBit(EXTI_Line12);
}
if (SET == EXTI_GetITStatus(EXTI_Line13)) {
// -----------------* ToF INT <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
tof_module_exti_handler();
// -----------------* ToF INT <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
// <20>˴<EFBFBD><CBB4><EFBFBD>д<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD> (A13/B13..E13) <20><><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD>
// <20>˴<EFBFBD><CBB4><EFBFBD>д<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD> (A13/B13..E13) <20><><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD>
// <20>˴<EFBFBD><CBB4><EFBFBD>д<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD> (A13/B13..E13) <20><><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD>
EXTI_ClearITPendingBit(EXTI_Line13);
}
if (SET == EXTI_GetITStatus(EXTI_Line14)) {
// -----------------* DM1XA <20><><EFBFBD>ź<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
dm1xa_light_callback();
// -----------------* DM1XA <20><><EFBFBD>ź<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
EXTI_ClearITPendingBit(EXTI_Line14);
}
if (SET == EXTI_GetITStatus(EXTI_Line15)) {
// -----------------* DM1XA <20><>/<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
dm1xa_sound_callback();
// -----------------* DM1XA <20><>/<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
EXTI_ClearITPendingBit(EXTI_Line15);
EXTI_ClearITPendingBit(EXTI_Line13);
}
if (SET == EXTI_GetITStatus(EXTI_Line14)) {
// -----------------* DM1XA <20><><EFBFBD>ź<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
dm1xa_light_callback();
// -----------------* DM1XA <20><><EFBFBD>ź<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
EXTI_ClearITPendingBit(EXTI_Line14);
}
if (SET == EXTI_GetITStatus(EXTI_Line15)) {
// -----------------* DM1XA <20><>/<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
dm1xa_sound_callback();
// -----------------* DM1XA <20><>/<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
EXTI_ClearITPendingBit(EXTI_Line15);
}
}
}

View File

@@ -28,9 +28,10 @@ enum PageID {
};
typedef enum page_event{
page_event_forward = ROTATE_BUTTON_FORWARD,
page_event_backward = ROTATE_BUTTON_BACKWARD,
page_event_press = ROTATE_BUTTON_PRESS
page_event_forward = rotate_button_forward,
page_event_backward = rotate_button_backward,
page_event_press_short = rotate_button_press_short,
page_event_press_long = rotate_button_press_long,
} page_event;
typedef void (*CallbackFunction_t)(void);

View File

@@ -60,7 +60,7 @@ static void Event(page_event event)
Curser--; // 光标上移
} else if (page_event_backward == event) {
Curser++; // 光标下移
} else if (page_event_press == event) {
} else if (page_event_press_short == event) {
if (page_max > Curser && page_menu < Curser) {
Page_Shift(Curser); // 切换到光标选中的页面
}

View File

@@ -61,7 +61,10 @@ static void Event(page_event event)
Curser--; // 光标上移
} else if (page_event_backward == event) {
Curser++; // 光标下移
} else if (page_event_press == event) {
} else if (page_event_press_short == event) {
} else if (page_event_press_long == event) {
Page_Shift(page_menu);
}
if (Curser < LINE_HEAD) {

View File

@@ -89,6 +89,12 @@ void system_delay_us(uint32 num)
}
}
uint64_t system_get_tick(void)
{
uint64_t time_temp = SysTick->CNT;
return (time_temp);
}
void system_delay_init(void)
{
SysTick->CTLR |= 0x21;

View File

@@ -39,8 +39,12 @@
#include "zf_common_clock.h"
#include "zf_common_typedef.h"
#define LONG_PRESS_THRESHOLD_MS (300ULL)
#define LONG_PRESS_THRESHOLD_TICK (LONG_PRESS_THRESHOLD_MS * 18000ULL)
void system_delay_ms(uint32 time);
void system_delay_us(uint32 time);
uint64_t system_get_tick(void);
void system_delay_init(void);
#endif