feat: 蜂鸣器和旋钮适配
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "violet_firmware_zf",
|
"name": "firmware_zinnia",
|
||||||
"type": "RISC-V",
|
"type": "RISC-V",
|
||||||
"dependenceList": [],
|
"dependenceList": [],
|
||||||
"srcDirs": [
|
"srcDirs": [
|
||||||
|
|||||||
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -7,7 +7,7 @@
|
|||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "openocd",
|
"name": "openocd",
|
||||||
"servertype": "openocd",
|
"servertype": "openocd",
|
||||||
"executable": "build\\Debug\\violet_firmware_zf.elf",
|
"executable": "build\\Debug\\firmware_zinnia.elf",
|
||||||
"runToEntryPoint": "main",
|
"runToEntryPoint": "main",
|
||||||
"configFiles": [
|
"configFiles": [
|
||||||
"${workspaceFolder}/tools/wch-riscv.cfg"
|
"${workspaceFolder}/tools/wch-riscv.cfg"
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#include "by_buzzer.h"
|
#include "by_buzzer.h"
|
||||||
#include "by_rt_button.h"
|
|
||||||
|
|
||||||
#include "zf_common_headfile.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "zf_common_headfile.h"
|
||||||
|
|
||||||
|
#define BUZZER_QUEUE_LENGTH 40
|
||||||
|
|
||||||
uint16_t queue_long = 0;
|
uint16_t queue_long = 0;
|
||||||
const uint32_t max_long = 40;
|
uint32_t a[40] = {0};
|
||||||
uint32_t a[40];
|
|
||||||
void queue_init(void)
|
void queue_init(void)
|
||||||
{
|
{
|
||||||
memset(a, 0, sizeof(a));
|
memset(a, 0, sizeof(a));
|
||||||
@@ -14,7 +15,7 @@ void queue_init(void)
|
|||||||
|
|
||||||
void queue_add_element(int element)
|
void queue_add_element(int element)
|
||||||
{
|
{
|
||||||
if (queue_long < max_long) {
|
if (queue_long < BUZZER_QUEUE_LENGTH) {
|
||||||
a[queue_long] = element;
|
a[queue_long] = element;
|
||||||
queue_long += 1;
|
queue_long += 1;
|
||||||
}
|
}
|
||||||
@@ -38,5 +39,18 @@ void queue_pop_read(void)
|
|||||||
|
|
||||||
void by_buzzer_init(void)
|
void by_buzzer_init(void)
|
||||||
{
|
{
|
||||||
|
queue_init();
|
||||||
pwm_init(BUZZER_PIN, 2000, 0);
|
pwm_init(BUZZER_PIN, 2000, 0);
|
||||||
|
|
||||||
|
by_buzzer_add(1250);
|
||||||
|
by_buzzer_add(1500);
|
||||||
|
by_buzzer_add(1750);
|
||||||
|
by_buzzer_add(1500);
|
||||||
|
by_buzzer_add(1200);
|
||||||
|
by_buzzer_add(900);
|
||||||
|
}
|
||||||
|
|
||||||
|
void by_buzzer_add(uint16_t tone)
|
||||||
|
{
|
||||||
|
queue_add_element(tone);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,23 @@
|
|||||||
#ifndef _BY_BUZZER_H__
|
#ifndef _BY_BUZZER_H__
|
||||||
#define _BY_BUZZER_H__
|
#define _BY_BUZZER_H__
|
||||||
|
|
||||||
#include "by_rt_button.h"
|
#include "zf_common_headfile.h"
|
||||||
|
|
||||||
#include "stdio.h"
|
|
||||||
#include "ch32v30x.h"
|
|
||||||
|
|
||||||
#define BY_PRESS_SHORT 2000
|
#define BY_PRESS_SHORT 2000
|
||||||
#define BY_PRESS_LONG 2500
|
#define BY_PRESS_LONG 2500
|
||||||
#define BY_FORWARD 1500
|
#define BY_FORWARD 1500
|
||||||
#define BY_BACKWARD 1800
|
#define BY_BACKWARD 1800
|
||||||
#define BUZZER_PIN TIM3_PWM_MAP0_CH2_A7
|
#define BUZZER_PIN TIM9_PWM_MAP0_CH1_A2
|
||||||
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 uint32_t a[40];
|
||||||
extern uint16_t queue_long;
|
extern uint16_t queue_long;
|
||||||
extern const uint32_t max_long;
|
extern const uint32_t max_long;
|
||||||
extern uint8_t queue_flag;
|
extern uint8_t queue_flag;
|
||||||
|
|
||||||
|
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 void by_buzzer_init(void);
|
||||||
|
extern void by_buzzer_add(uint16_t tone);
|
||||||
#endif
|
#endif
|
||||||
@@ -3,17 +3,6 @@
|
|||||||
#include "by_imu.h"
|
#include "by_imu.h"
|
||||||
uint8_t rotate_button;
|
uint8_t rotate_button;
|
||||||
|
|
||||||
void by_gpio_init(void)
|
|
||||||
{
|
|
||||||
gpio_init(E10, GPI, GPIO_HIGH, GPI_PULL_UP);
|
|
||||||
}
|
|
||||||
|
|
||||||
void by_exit_init(void)
|
|
||||||
{
|
|
||||||
exti_init(E9, EXTI_TRIGGER_FALLING);
|
|
||||||
exti_init(E11, EXTI_TRIGGER_BOTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 查询旋钮状态 - 查询后状态归零
|
* @brief 查询旋钮状态 - 查询后状态归零
|
||||||
*
|
*
|
||||||
@@ -22,37 +11,16 @@ void by_exit_init(void)
|
|||||||
uint8_t by_get_rb_status(void)
|
uint8_t by_get_rb_status(void)
|
||||||
{
|
{
|
||||||
uint8_t temp_s = rotate_button;
|
uint8_t temp_s = rotate_button;
|
||||||
rotate_button = 0;
|
rotate_button = rotate_button_none;
|
||||||
return temp_s;
|
return temp_s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void by_ips_show(void)
|
void by_rb_init(void)
|
||||||
{
|
{
|
||||||
ips200_show_string(0, 0, "button status:");
|
gpio_init(E9, GPI, GPIO_HIGH, GPI_PULL_UP);
|
||||||
// ips200_show_uint(104, 0, by_get_rb_status(), 1);
|
gpio_init(E10, GPI, GPIO_HIGH, GPI_PULL_UP);
|
||||||
switch (by_get_rb_status()) {
|
gpio_init(E11, GPI, GPIO_HIGH, GPI_PULL_UP);
|
||||||
case 1:
|
|
||||||
ips200_show_string(104, 0, "press");
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
ips200_show_string(104, 0, "up ");
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
ips200_show_string(104, 0, "down ");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
exti_init(E9, EXTI_TRIGGER_FALLING);
|
||||||
ips200_show_string(104, 0, " ");
|
exti_init(E11, EXTI_TRIGGER_BOTH);
|
||||||
break;
|
|
||||||
}
|
|
||||||
// 按钮
|
|
||||||
ips200_show_string(0, 16, "imu:");
|
|
||||||
ips200_show_float(46, 32, eulerAngle.pitch, 3, 2);
|
|
||||||
ips200_show_float(46, 48, eulerAngle.roll, 3, 2);
|
|
||||||
ips200_show_float(46, 64, eulerAngle.yaw, 3, 2);
|
|
||||||
// ips200_show_float(46 , 32, icm_data.gyro_x, 2, 2);
|
|
||||||
// ips200_show_float(106, 32, icm_data.gyro_y, 2, 2);
|
|
||||||
// ips200_show_float(166, 32, icm_data.gyro_z, 2, 2);
|
|
||||||
ips200_show_float(46, 80, imu660ra_temperature, 2, 2);
|
|
||||||
// printf("%d,%d,%d\n", (int16_t)(icm_data.gyro_x * 10), (int16_t)(icm_data.gyro_y * 10), (int16_t)(icm_data.gyro_z * 10));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#define LONG_PRESS_THRESHOLD_TICK (LONG_PRESS_THRESHOLD_MS * 18000ULL)
|
#define LONG_PRESS_THRESHOLD_TICK (LONG_PRESS_THRESHOLD_MS * 18000ULL)
|
||||||
|
|
||||||
typedef enum rotate_button_event {
|
typedef enum rotate_button_event {
|
||||||
|
rotate_button_none = 0,
|
||||||
rotate_button_press_short = 1,
|
rotate_button_press_short = 1,
|
||||||
rotate_button_press_long = 2,
|
rotate_button_press_long = 2,
|
||||||
rotate_button_forward = 3,
|
rotate_button_forward = 3,
|
||||||
@@ -16,9 +17,7 @@ typedef enum rotate_button_event {
|
|||||||
|
|
||||||
extern uint8_t rotate_button;
|
extern uint8_t rotate_button;
|
||||||
|
|
||||||
extern void by_exit_init(void);
|
|
||||||
extern void by_gpio_init(void);
|
|
||||||
extern uint8_t by_get_rb_status(void);
|
extern uint8_t by_get_rb_status(void);
|
||||||
extern void by_ips_show(void);
|
extern void by_rb_init(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -202,6 +202,7 @@ void EXTI9_5_IRQHandler(void)
|
|||||||
}
|
}
|
||||||
if (SET == EXTI_GetITStatus(EXTI_Line9)) {
|
if (SET == EXTI_GetITStatus(EXTI_Line9)) {
|
||||||
|
|
||||||
|
if (rotate_button == rotate_button_none) {
|
||||||
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);
|
queue_add_element(BY_BACKWARD);
|
||||||
@@ -209,6 +210,8 @@ void EXTI9_5_IRQHandler(void)
|
|||||||
rotate_button = rotate_button_forward;
|
rotate_button = rotate_button_forward;
|
||||||
queue_add_element(BY_FORWARD);
|
queue_add_element(BY_FORWARD);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
EXTI_ClearITPendingBit(EXTI_Line9);
|
EXTI_ClearITPendingBit(EXTI_Line9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
81
app/main.c
81
app/main.c
@@ -33,66 +33,41 @@
|
|||||||
#include "by_imu.h"
|
#include "by_imu.h"
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
int16_t i = 0;
|
||||||
clock_init(SYSTEM_CLOCK_120M);
|
clock_init(SYSTEM_CLOCK_120M);
|
||||||
system_delay_init();
|
system_delay_init();
|
||||||
debug_init();
|
debug_init();
|
||||||
mt9v03x_init();
|
|
||||||
ips200_init(IPS200_TYPE_SPI);
|
ips200_init(IPS200_TYPE_SPI);
|
||||||
by_gpio_init();
|
|
||||||
by_exit_init();
|
by_rb_init();
|
||||||
by_pwm_init();
|
|
||||||
jj_bt_init();
|
|
||||||
by_buzzer_init();
|
by_buzzer_init();
|
||||||
while (imu660ra_init())
|
by_pwm_init();
|
||||||
;
|
|
||||||
jj_param_eeprom_init();
|
|
||||||
Page_Init();
|
Page_Init();
|
||||||
sport_pid_init();
|
|
||||||
pit_ms_init(TIM6_PIT, 2);
|
|
||||||
pit_ms_init(TIM1_PIT, 2);
|
|
||||||
// gyroOffset_init();
|
|
||||||
while (1) {
|
while (1) {
|
||||||
Page_Run();
|
|
||||||
jj_bt_run();
|
// switch (by_get_rb_status()) {
|
||||||
|
// case 3:
|
||||||
|
// i++;
|
||||||
|
// break;
|
||||||
|
// case 4:
|
||||||
|
// i--;
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// by_pwm_update_duty(500 + i * 50, 500 + i * 50);
|
||||||
|
// by_pwm_power_duty(500 + i * 50, 500 + i * 50, 500 + i * 50, 500 + i * 50);
|
||||||
|
// // ips200_show_uint(0, 0, 1000, 4);
|
||||||
|
// ips200_draw_rect(0, 0, 50, 50, RGB565_YELLOW);
|
||||||
|
// system_delay_ms(100);
|
||||||
|
// ips200_draw_rect(0, 0, 50, 50, RGB565_BLACK);
|
||||||
|
// system_delay_ms(10);
|
||||||
|
|
||||||
queue_pop_read();
|
queue_pop_read();
|
||||||
bt_printf("hello:%f,%f\n",out_M,out_yaw);
|
Page_Run();
|
||||||
if (mt9v03x_finish_flag) {
|
|
||||||
// 该操作消耗大概 1970 个 tick,折合约 110us
|
|
||||||
memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t)));
|
|
||||||
//adaptiveThreshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, 188, 120, 7, 17);
|
|
||||||
//ips200_show_gray_image(0, 0, mt9v03x_image_copy[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0);
|
|
||||||
mt9v03x_finish_flag = 0;
|
|
||||||
|
|
||||||
state_type = COMMON_STATE;
|
|
||||||
img_processing();
|
|
||||||
get_corners();
|
|
||||||
aim_distance = COMMON_AIM;
|
|
||||||
tracking();
|
|
||||||
ElementJudge();
|
|
||||||
ElementRun();
|
|
||||||
MidLineTrack();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void adaptiveThreshold(uint8_t* img_data, uint8_t* output_data, int width, int height, int block, uint8_t clip_value){
|
|
||||||
int half_block = block / 2;
|
|
||||||
for(int y=half_block; y<height-half_block; y++){
|
|
||||||
for(int x=half_block; x<width-half_block; x++){
|
|
||||||
// 计算局部阈值
|
|
||||||
int thres = 0;
|
|
||||||
for(int dy=-half_block; dy<=half_block; dy++){
|
|
||||||
for(int dx=-half_block; dx<=half_block; dx++){
|
|
||||||
thres += img_data[(x+dx)+(y+dy)*width];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
thres = thres / (block * block) - clip_value;
|
|
||||||
// 进行二值化
|
|
||||||
output_data[x+y*width] = img_data[x+y*width]>thres ? 255 : 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user