From e93eb8127bc241c437792a0eaca89bec6ecf3baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=95=E6=98=8E=E6=B1=9F?= <246462502@qq.com> Date: Sun, 7 Jan 2024 16:58:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=93=9D=E7=89=99?= =?UTF-8?q?=E9=80=9A=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/isr.c | 5 +++-- app/jj_blueteeth.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ app/jj_blueteeth.h | 10 ++++++++++ app/main.c | 7 +++---- 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 app/jj_blueteeth.c create mode 100644 app/jj_blueteeth.h diff --git a/app/isr.c b/app/isr.c index 6e909d6..41e16fa 100644 --- a/app/isr.c +++ b/app/isr.c @@ -36,7 +36,7 @@ #include "zf_common_headfile.h" #include "by_rt_button.h" #include "by_imu.h" - +#include "jj_blueteeth.h" void NMI_Handler(void) __attribute__((interrupt())); void HardFault_Handler(void) __attribute__((interrupt())); @@ -90,7 +90,8 @@ void USART1_IRQHandler(void) void USART2_IRQHandler(void) { if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) { - + uart_query_byte(UART_2,&bt_buffer); + bt_rx_flag=true; USART_ClearITPendingBit(USART2, USART_IT_RXNE); } } diff --git a/app/jj_blueteeth.c b/app/jj_blueteeth.c new file mode 100644 index 0000000..dcacd40 --- /dev/null +++ b/app/jj_blueteeth.c @@ -0,0 +1,49 @@ +#include "jj_blueteeth.h" +bool bt_rx_flag = false; +uint8 bt_buffer;//接收字符存入 +enum bt_order { + Start_work = 0x01, + Turn_Left = 0x02, + Turn_Right = 0x03, + Speed_up = 0x04, + Speed_down = 0x05, +}; +/** + * @brief 蓝牙初始化 + * @retval 无 + */ +void jj_bt_init() +{ + uart_init(UART_2, 115200, UART2_MAP1_TX_D5, UART2_MAP1_RX_D6); + // uart_tx_interrupt(UART_2, 1); + uart_rx_interrupt(UART_2, ENABLE); +} +/** + *@brief 蓝牙中断回调函数 + */ +void jj_bt_run() +{ + if (bt_rx_flag) { + switch (bt_buffer) { + case Start_work: + printf("1\r\n"); + break; + case Turn_Left: + printf("2\r\n"); + break; + case Turn_Right: + printf("3\r\n"); + break; + case Speed_down: + printf("5\r\n"); + break; + case Speed_up: + printf("4\r\n"); + break; + default: + break; + } + uart_write_byte(UART_2,bt_buffer); + bt_rx_flag = false; + } +} \ No newline at end of file diff --git a/app/jj_blueteeth.h b/app/jj_blueteeth.h new file mode 100644 index 0000000..f648434 --- /dev/null +++ b/app/jj_blueteeth.h @@ -0,0 +1,10 @@ +#ifndef _JJ_BLUETEETH_H_ +#define _JJ_BLUETEETH_H_ +#include "zf_common_headfile.h" +#include "zf_driver_uart.h" +extern bool bt_rx_flag; +extern uint8 bt_buffer; +void jj_bt_init(); +void jj_bt_run(); + +#endif \ No newline at end of file diff --git a/app/main.c b/app/main.c index 975c919..093ebf3 100644 --- a/app/main.c +++ b/app/main.c @@ -21,12 +21,11 @@ * 许可证副本在 libraries 文件夹下 即该文件夹下的 LICENSE 文件 * 欢迎各位使用并传播本程序 但修改内容时必须保留逐飞科技的版权声明(即本声明) ********************************************************************************************************************/ -#include "zf_common_headfile.h" #include "gl_headfile.h" #include "by_rt_button.h" #include "by_fan_control.h" #include "./page/cw_page.h" - +#include "jj_blueteeth.h" int main(void) { clock_init(SYSTEM_CLOCK_120M); @@ -37,15 +36,15 @@ int main(void) by_gpio_init(); by_exit_init(); by_pwm_init(); + jj_bt_init(); // while (imu660ra_init()) // ; Page_Init(); while (1) { - Page_Run(); - + jj_bt_run(); if (mt9v03x_finish_flag) { // 该操作消耗大概 1970 个 tick,折合约 110us memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t)));