feat: 添加蓝牙通信

This commit is contained in:
2024-01-07 16:58:53 +08:00
parent 6bb5b9eaad
commit e93eb8127b
4 changed files with 65 additions and 6 deletions

View File

@@ -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);
}
}

49
app/jj_blueteeth.c Normal file
View File

@@ -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;
}
}

10
app/jj_blueteeth.h Normal file
View File

@@ -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

View File

@@ -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)));