| | |
| | | /******************************************************************************* |
| | | * File Name : bluetooth.h |
| | | * Description : |
| | | * Created on : |
| | | * Author : |
| | | * Description : Bluetooth Communication Protocol (New V2) |
| | | * Created on : 2025-12-04 |
| | | * Author : HIDO |
| | | *******************************************************************************/ |
| | | |
| | | #ifndef FML_BLUETOOTH_H_ |
| | | #define FML_BLUETOOTH_H_ |
| | | |
| | | /******************************************************************************* |
| | | * Include Files * |
| | | *******************************************************************************/ |
| | |
| | | /******************************************************************************* |
| | | * Macro * |
| | | *******************************************************************************/ |
| | | #define OUTPUT_BUF_SIZE 512 |
| | | #define BT_UART_RX_BUF_SIZE 256 |
| | | #define BT_UART_TX_BUF_SIZE (1024*2) |
| | | #define BT_UART_TX_QUEUE_MEMBER_CNT 64 |
| | | #define BT_UART_RX_BUF_SIZE 1024 |
| | | #define UART6_DMA_RX_BUF_SIZE BT_UART_RX_BUF_SIZE |
| | | #define BT_UART_TX_BUF_SIZE 1024 |
| | | #define BT_UART_TX_QUEUE_MEMBER_CNT 16 |
| | | |
| | | // 定义最大重试次数 |
| | | #define MAX_RETRY 5 |
| | | #define RESPONSE_TIMEOUT 1000 // 1秒超时 |
| | | #define UART6_DMA_RX_BUF_SIZE 50 |
| | | // Protocol Constants |
| | | #define BT_FRAME_HEADER1 0xAA |
| | | #define BT_FRAME_HEADER2 0x55 |
| | | #define BT_FRAME_TAIL 0x0D |
| | | |
| | | |
| | | // 定义状态枚举 |
| | | typedef enum { |
| | | BT_STATE_IDLE = 0, // 空闲状态 |
| | | BT_STATE_RECEIVING = 1, // 接收数据中 |
| | | BT_STATE_COMPLETE = 2 // 数据接收完成 |
| | | } BT_RevState; |
| | | |
| | | // 定义状态枚举 |
| | | typedef enum { |
| | | BT_CONFIG_FAIL= 0, // 失败 |
| | | BT_CONFIG_SUCCESS = 1, // 成功 |
| | | } BT_Config; |
| | | |
| | | // 摇杆输入结构体 |
| | | typedef struct { |
| | | int16_t x1; |
| | | int16_t y1; |
| | | int16_t x2; |
| | | int16_t y2; |
| | | } Joystick_t; |
| | | |
| | | |
| | | /******************************************************************************* |
| | | * Local Function Declaration * |
| | | *******************************************************************************/ |
| | | extern HIDO_UINT8 uart6_dma_recv_end_flag; |
| | | extern HIDO_UINT8 uart6_dma_recv_len; |
| | | extern HIDO_UINT8 uart6_dma_rxbuf[UART6_DMA_RX_BUF_SIZE]; |
| | | // Command Types |
| | | #define BT_CMD_PATH_COORDS 0x01 |
| | | #define BT_CMD_REF_POINT 0x02 |
| | | #define BT_CMD_CONTROL 0x03 |
| | | |
| | | /******************************************************************************* |
| | | * Type Definition * |
| | | *******************************************************************************/ |
| | | |
| | | #pragma pack(push, 1) |
| | | |
| | | typedef struct |
| | | { |
| | | HIDO_UINT8 m_u8Header1; |
| | | HIDO_UINT8 m_u8Header2; |
| | | HIDO_UINT8 m_u8CmdType; |
| | | HIDO_UINT16 m_u16DataLen; |
| | | HIDO_UINT16 m_u16SeqNum; |
| | | } ST_BT_FrameHeader; |
| | | |
| | | typedef struct |
| | | { |
| | | HIDO_DOUBLE m_dX; |
| | | HIDO_DOUBLE m_dY; |
| | | } ST_BT_PathPoint; |
| | | |
| | | typedef struct |
| | | { |
| | | HIDO_DOUBLE m_dLat; |
| | | HIDO_DOUBLE m_dLon; |
| | | HIDO_CHAR m_cLatDir; |
| | | HIDO_CHAR m_cLonDir; |
| | | HIDO_UINT8 m_au8Reserved[14]; |
| | | } ST_BT_RefPointData; |
| | | |
| | | typedef struct |
| | | { |
| | | HIDO_INT8 m_i8SteerSpeed; // -100 to 100 (Negative Left) |
| | | HIDO_INT8 m_i8TravelSpeed; // -100 to 100 (Negative Reverse) |
| | | HIDO_UINT8 m_au8Reserved[2]; |
| | | } ST_BT_ControlData; |
| | | |
| | | #pragma pack(pop) |
| | | |
| | | /******************************************************************************* |
| | | * Global Function * |
| | | *******************************************************************************/ |
| | | |
| | | HIDO_VOID BT_Poll(void); |
| | | void BT_DisConnect(void); |
| | | HIDO_VOID BT_Init(void); |
| | | // 函数声明 |
| | | void Joystick_Process(Joystick_t *joy); |
| | | void Parse_Joystick_Data(char *data); |
| | | HIDO_VOID BT_Poll(void); |
| | | HIDO_VOID UART6_StartReceive(void); |
| | | |
| | | // Exposed for ISR |
| | | extern HIDO_UINT8 uart6_dma_rxbuf[BT_UART_RX_BUF_SIZE]; |
| | | extern HIDO_UINT8 uart6_dma_recv_end_flag; |
| | | extern HIDO_UINT16 uart6_dma_recv_len; |
| | | extern volatile HIDO_UINT32 g_u32BtIdleIntCount; |
| | | |
| | | #endif |
| | | #endif /* FML_BLUETOOTH_H_ */ |