From bf76c25f41c1798c2440ebba7925e53b334d46a9 Mon Sep 17 00:00:00 2001 From: bmy <2583236812@qq.com> Date: Mon, 8 Jan 2024 22:08:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=A3=B0=E9=9F=B3?= =?UTF-8?q?=E5=BA=8F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/by_buzzer.c | 42 ++++++++++++++++++++++++++++++++++++++++++ app/by_buzzer.h | 24 ++++++++++++++++++++++++ app/isr.c | 7 ++++++- app/main.c | 4 ++++ app/page/cw_page.c | 2 +- 5 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 app/by_buzzer.c create mode 100644 app/by_buzzer.h diff --git a/app/by_buzzer.c b/app/by_buzzer.c new file mode 100644 index 0000000..c29e383 --- /dev/null +++ b/app/by_buzzer.c @@ -0,0 +1,42 @@ +#include "by_buzzer.h" +#include "by_rt_button.h" + +#include "zf_common_headfile.h" +#include + +uint16_t queue_long = 0; +const uint32_t max_long = 40; +uint32_t a[40]; +void queue_init(void) +{ + memset(a, 0, sizeof(a)); +} + +void queue_add_element(int element) +{ + if (queue_long < max_long) { + a[queue_long] = element; + queue_long += 1; + } +} +void queue_pop_element(void) +{ + memmove(a, &a[1], queue_long * sizeof(a)); + if (queue_long > 0) { + queue_long--; + } +} +void queue_pop_read(void) +{ + while (queue_long != 0) { + pwm_init(TIM8_PWM_MAP0_CH1_C6, a[0], 5000); + queue_pop_element(); + system_delay_ms(100); + pwm_set_duty(TIM8_PWM_MAP0_CH1_C6, 0); + } +} + +void by_buzzer_init(void) +{ + pwm_init(TIM8_PWM_MAP0_CH1_C6, 2000, 0); +} diff --git a/app/by_buzzer.h b/app/by_buzzer.h new file mode 100644 index 0000000..9bf9f9a --- /dev/null +++ b/app/by_buzzer.h @@ -0,0 +1,24 @@ +#ifndef _BY_BUZZER_H__ +#define _BY_BUZZER_H__ + +#include "by_rt_button.h" + +#include "stdio.h" +#include "ch32v30x.h" + +#define BY_PRESS_SHORT 2000 +#define BY_PRESS_LONG 2500 +#define BY_FORWARD 1500 +#define BY_BACKWARD 1800 + +extern void by_buzzer_init(void); +extern void queue_init(void); +extern void queue_add_element(int element); +extern void queue_pop_element(void); +extern void queue_pop_read(void); + +extern uint32_t a[40]; +extern uint16_t queue_long; +extern const uint32_t max_long; +extern uint8_t queue_flag; +#endif \ No newline at end of file diff --git a/app/isr.c b/app/isr.c index 6e909d6..12fc857 100644 --- a/app/isr.c +++ b/app/isr.c @@ -36,6 +36,7 @@ #include "zf_common_headfile.h" #include "by_rt_button.h" #include "by_imu.h" +#include "by_buzzer.h" void NMI_Handler(void) __attribute__((interrupt())); void HardFault_Handler(void) __attribute__((interrupt())); @@ -199,9 +200,10 @@ void EXTI9_5_IRQHandler(void) if (SET == gpio_get_level(E10)) { rotate_button = rotate_button_backward; - + queue_add_element(BY_BACKWARD); } else { rotate_button = rotate_button_forward; + queue_add_element(BY_FORWARD); } EXTI_ClearITPendingBit(EXTI_Line9); } @@ -227,8 +229,11 @@ void EXTI15_10_IRQHandler(void) time_via = system_get_tick() - time_via; if (time_via > LONG_PRESS_THRESHOLD_TICK) { rotate_button = rotate_button_press_long; + queue_add_element(BY_PRESS_LONG); + } else { rotate_button = rotate_button_press_short; + queue_add_element(BY_PRESS_SHORT); } time_via = 0; EXTI_ClearITPendingBit(EXTI_Line11); diff --git a/app/main.c b/app/main.c index 975c919..c77cd72 100644 --- a/app/main.c +++ b/app/main.c @@ -26,6 +26,7 @@ #include "by_rt_button.h" #include "by_fan_control.h" #include "./page/cw_page.h" +#include "by_buzzer.h" int main(void) { @@ -37,6 +38,7 @@ int main(void) by_gpio_init(); by_exit_init(); by_pwm_init(); + by_buzzer_init(); // while (imu660ra_init()) // ; @@ -45,6 +47,8 @@ int main(void) while (1) { Page_Run(); + queue_pop_read(); + if (mt9v03x_finish_flag) { // 该操作消耗大概 1970 个 tick,折合约 110us diff --git a/app/page/cw_page.c b/app/page/cw_page.c index 8716b8e..62d48e8 100644 --- a/app/page/cw_page.c +++ b/app/page/cw_page.c @@ -89,7 +89,7 @@ uint8_t Page_GetStatus(void) */ void Page_Run(void) { - uint8_t temp_status = by_get_rb_status(); // 轮询旋钮状态 + uint8_t temp_status = by_get_rb_status(); // 轮询旋钮状态 if(temp_status){ pagelist[now_page].EventCallback(temp_status); }