From 5f29a9eca2dbdd2b38fb2585ac69bbe3966a03a6 Mon Sep 17 00:00:00 2001 From: bmy <2583236812@qq.com> Date: Wed, 7 Feb 2024 10:24:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=9C=82=E9=B8=A3=E5=99=A8=E5=92=8C?= =?UTF-8?q?=E6=97=8B=E9=92=AE=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eide/eide.json | 2 +- .vscode/launch.json | 2 +- app/by_buzzer.c | 26 +++++++-- app/by_buzzer.h | 19 +++--- app/by_rt_button.c | 46 +++------------ app/by_rt_button.h | 5 +- app/isr.c | 15 +++-- app/main.c | 81 +++++++++----------------- libraries/zf_device/zf_device_ips200.h | 2 +- 9 files changed, 78 insertions(+), 120 deletions(-) diff --git a/.eide/eide.json b/.eide/eide.json index b4e7241..e7784be 100644 --- a/.eide/eide.json +++ b/.eide/eide.json @@ -1,5 +1,5 @@ { - "name": "violet_firmware_zf", + "name": "firmware_zinnia", "type": "RISC-V", "dependenceList": [], "srcDirs": [ diff --git a/.vscode/launch.json b/.vscode/launch.json index a467a37..c26315c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,7 +7,7 @@ "request": "launch", "name": "openocd", "servertype": "openocd", - "executable": "build\\Debug\\violet_firmware_zf.elf", + "executable": "build\\Debug\\firmware_zinnia.elf", "runToEntryPoint": "main", "configFiles": [ "${workspaceFolder}/tools/wch-riscv.cfg" diff --git a/app/by_buzzer.c b/app/by_buzzer.c index 52188df..0d97078 100644 --- a/app/by_buzzer.c +++ b/app/by_buzzer.c @@ -1,12 +1,13 @@ #include "by_buzzer.h" -#include "by_rt_button.h" -#include "zf_common_headfile.h" #include +#include "zf_common_headfile.h" + +#define BUZZER_QUEUE_LENGTH 40 + +uint16_t queue_long = 0; +uint32_t a[40] = {0}; -uint16_t queue_long = 0; -const uint32_t max_long = 40; -uint32_t a[40]; void queue_init(void) { memset(a, 0, sizeof(a)); @@ -14,7 +15,7 @@ void queue_init(void) void queue_add_element(int element) { - if (queue_long < max_long) { + if (queue_long < BUZZER_QUEUE_LENGTH) { a[queue_long] = element; queue_long += 1; } @@ -38,5 +39,18 @@ void queue_pop_read(void) void by_buzzer_init(void) { + queue_init(); 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); } diff --git a/app/by_buzzer.h b/app/by_buzzer.h index c410955..a0edcad 100644 --- a/app/by_buzzer.h +++ b/app/by_buzzer.h @@ -1,24 +1,23 @@ #ifndef _BY_BUZZER_H__ #define _BY_BUZZER_H__ -#include "by_rt_button.h" - -#include "stdio.h" -#include "ch32v30x.h" +#include "zf_common_headfile.h" #define BY_PRESS_SHORT 2000 #define BY_PRESS_LONG 2500 #define BY_FORWARD 1500 #define BY_BACKWARD 1800 -#define BUZZER_PIN TIM3_PWM_MAP0_CH2_A7 -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); +#define BUZZER_PIN TIM9_PWM_MAP0_CH1_A2 extern uint32_t a[40]; extern uint16_t queue_long; extern const uint32_t max_long; 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 \ No newline at end of file diff --git a/app/by_rt_button.c b/app/by_rt_button.c index 40b5471..c3bc0f5 100644 --- a/app/by_rt_button.c +++ b/app/by_rt_button.c @@ -3,17 +3,6 @@ #include "by_imu.h" 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 查询旋钮状态 - 查询后状态归零 * @@ -22,37 +11,16 @@ void by_exit_init(void) uint8_t by_get_rb_status(void) { uint8_t temp_s = rotate_button; - rotate_button = 0; + rotate_button = rotate_button_none; return temp_s; } -void by_ips_show(void) +void by_rb_init(void) { - ips200_show_string(0, 0, "button status:"); - // ips200_show_uint(104, 0, by_get_rb_status(), 1); - switch (by_get_rb_status()) { - 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; + gpio_init(E9, GPI, GPIO_HIGH, GPI_PULL_UP); + gpio_init(E10, GPI, GPIO_HIGH, GPI_PULL_UP); + gpio_init(E11, GPI, GPIO_HIGH, GPI_PULL_UP); - default: - ips200_show_string(104, 0, " "); - 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)); + exti_init(E9, EXTI_TRIGGER_FALLING); + exti_init(E11, EXTI_TRIGGER_BOTH); } diff --git a/app/by_rt_button.h b/app/by_rt_button.h index c42d6e0..deb8af8 100644 --- a/app/by_rt_button.h +++ b/app/by_rt_button.h @@ -8,6 +8,7 @@ #define LONG_PRESS_THRESHOLD_TICK (LONG_PRESS_THRESHOLD_MS * 18000ULL) typedef enum rotate_button_event { + rotate_button_none = 0, rotate_button_press_short = 1, rotate_button_press_long = 2, rotate_button_forward = 3, @@ -16,9 +17,7 @@ typedef enum rotate_button_event { 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 void by_ips_show(void); +extern void by_rb_init(void); #endif \ No newline at end of file diff --git a/app/isr.c b/app/isr.c index 33d4983..02ee1e4 100644 --- a/app/isr.c +++ b/app/isr.c @@ -202,13 +202,16 @@ void EXTI9_5_IRQHandler(void) } if (SET == EXTI_GetITStatus(EXTI_Line9)) { - 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); + if (rotate_button == rotate_button_none) { + 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); } } diff --git a/app/main.c b/app/main.c index d68f3d6..81faf24 100644 --- a/app/main.c +++ b/app/main.c @@ -33,66 +33,41 @@ #include "by_imu.h" int main(void) { - + int16_t i = 0; clock_init(SYSTEM_CLOCK_120M); system_delay_init(); debug_init(); - mt9v03x_init(); + ips200_init(IPS200_TYPE_SPI); - by_gpio_init(); - by_exit_init(); - by_pwm_init(); - jj_bt_init(); + + by_rb_init(); by_buzzer_init(); - while (imu660ra_init()) - ; - jj_param_eeprom_init(); + by_pwm_init(); + Page_Init(); - sport_pid_init(); - pit_ms_init(TIM6_PIT, 2); - pit_ms_init(TIM1_PIT, 2); - // gyroOffset_init(); + 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(); - bt_printf("hello:%f,%f\n",out_M,out_yaw); - 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(); - - } + Page_Run(); } } - - - -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; ythres ? 255 : 0; - } - } -} diff --git a/libraries/zf_device/zf_device_ips200.h b/libraries/zf_device/zf_device_ips200.h index 6169e6b..a37ea56 100644 --- a/libraries/zf_device/zf_device_ips200.h +++ b/libraries/zf_device/zf_device_ips200.h @@ -76,7 +76,7 @@ #else //====================================================硬件 SPI 驱动==================================================== // 如果使用的是单排排针的两寸屏幕 SPI 驱动控制引脚 可以修改 -#define IPS200_SPI_SPEED (72 * 1000 * 1000) // 硬件 SPI 速率 这里设置为系统时钟二分频 +#define IPS200_SPI_SPEED (72 * 1000 * 1000) // 硬件 SPI 速率 这里设置为系统时钟二分频 #define IPS200_SPI (SPI_2) // 硬件 SPI 号 #define IPS200_SCL_PIN_SPI (SPI2_MAP0_SCK_B13) // 硬件 SPI SCK 引脚 #define IPS200_SDA_PIN_SPI (SPI2_MAP0_MOSI_B15) // 硬件 SPI MOSI 引脚