Merge pull request '日常更新' (#17) from bmy/firmware_violet_zf:master into master
Reviewed-on: http://git.isthmus.tk:441/btl143/firmware_violet_zf/pulls/17
This commit is contained in:
42
app/by_buzzer.c
Normal file
42
app/by_buzzer.c
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#include "by_buzzer.h"
|
||||||
|
#include "by_rt_button.h"
|
||||||
|
|
||||||
|
#include "zf_common_headfile.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
24
app/by_buzzer.h
Normal file
24
app/by_buzzer.h
Normal file
@@ -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
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
#include "zf_common_headfile.h"
|
#include "zf_common_headfile.h"
|
||||||
#include "by_rt_button.h"
|
#include "by_rt_button.h"
|
||||||
#include "by_imu.h"
|
#include "by_imu.h"
|
||||||
|
#include "by_buzzer.h"
|
||||||
|
|
||||||
void NMI_Handler(void) __attribute__((interrupt()));
|
void NMI_Handler(void) __attribute__((interrupt()));
|
||||||
void HardFault_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)) {
|
if (SET == gpio_get_level(E10)) {
|
||||||
rotate_button = rotate_button_backward;
|
rotate_button = rotate_button_backward;
|
||||||
|
queue_add_element(BY_BACKWARD);
|
||||||
} else {
|
} else {
|
||||||
rotate_button = rotate_button_forward;
|
rotate_button = rotate_button_forward;
|
||||||
|
queue_add_element(BY_FORWARD);
|
||||||
}
|
}
|
||||||
EXTI_ClearITPendingBit(EXTI_Line9);
|
EXTI_ClearITPendingBit(EXTI_Line9);
|
||||||
}
|
}
|
||||||
@@ -227,8 +229,11 @@ void EXTI15_10_IRQHandler(void)
|
|||||||
time_via = system_get_tick() - time_via;
|
time_via = system_get_tick() - time_via;
|
||||||
if (time_via > LONG_PRESS_THRESHOLD_TICK) {
|
if (time_via > LONG_PRESS_THRESHOLD_TICK) {
|
||||||
rotate_button = rotate_button_press_long;
|
rotate_button = rotate_button_press_long;
|
||||||
|
queue_add_element(BY_PRESS_LONG);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
rotate_button = rotate_button_press_short;
|
rotate_button = rotate_button_press_short;
|
||||||
|
queue_add_element(BY_PRESS_SHORT);
|
||||||
}
|
}
|
||||||
time_via = 0;
|
time_via = 0;
|
||||||
EXTI_ClearITPendingBit(EXTI_Line11);
|
EXTI_ClearITPendingBit(EXTI_Line11);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#include "by_rt_button.h"
|
#include "by_rt_button.h"
|
||||||
#include "by_fan_control.h"
|
#include "by_fan_control.h"
|
||||||
#include "./page/cw_page.h"
|
#include "./page/cw_page.h"
|
||||||
#include "./page/cw_page_ui_widget.h"
|
#include "by_buzzer.h"
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
@@ -39,6 +39,7 @@ int main(void)
|
|||||||
by_gpio_init();
|
by_gpio_init();
|
||||||
by_exit_init();
|
by_exit_init();
|
||||||
by_pwm_init();
|
by_pwm_init();
|
||||||
|
by_buzzer_init();
|
||||||
// while (imu660ra_init())
|
// while (imu660ra_init())
|
||||||
// ;
|
// ;
|
||||||
|
|
||||||
@@ -47,6 +48,8 @@ int main(void)
|
|||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
Page_Run();
|
Page_Run();
|
||||||
|
queue_pop_read();
|
||||||
|
|
||||||
if (mt9v03x_finish_flag) {
|
if (mt9v03x_finish_flag) {
|
||||||
// 该操作消耗大概 1970 个 tick,折合约 110us
|
// 该操作消耗大概 1970 个 tick,折合约 110us
|
||||||
memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t)));
|
memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t)));
|
||||||
|
|||||||
Reference in New Issue
Block a user