diff --git a/robot/bspMCU/drv_interface.c b/robot/bspMCU/drv_interface.c index ce79b6c..1856989 100644 --- a/robot/bspMCU/drv_interface.c +++ b/robot/bspMCU/drv_interface.c @@ -16,10 +16,11 @@ 修改内容 : 创建文件 ******************************************************************************/ -#include "bsp_config.h" -#include "main.h" -#include "bsp_uart.h" -#include "bsp_CAN.h" +#include "drv_interface.h" + +#include "cmsis_os.h" +#include "FreeRTOS.h" +#include "task.h" /*----------------------------------------------* * 外部变量说明 * @@ -183,4 +184,61 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) } } +void Read_RS485_1(void *argument) +{ + char pcBuffer[52] = {0}; + + while(1) + { + __disable_irq(); + rd_ComRead(g_ptRS485_1, pcBuffer, 25); + __enable_irq(); + osDelay(1); + } +} + +void SendAll_Task(void *argument) +{ + while(1) + { + rd_ComSendProc(g_ptRS485_1); + osDelay(1); + rd_ComSendProc(g_ptRS485_2); + osDelay(1); + rd_ComSendProc(g_ptRS485_3); + osDelay(1); + rd_ComSendProc(g_ptRS485_4); + osDelay(1); + rd_ComSendProc(g_ptLTE_7S0); + osDelay(1); + rd_ComSendProc(g_ptE28_SBUS); + osDelay(1); + rd_ComSendProc(g_ptInterCall); + osDelay(1); + rd_ComSendProc(g_ptFDCAN1); + osDelay(1); + rd_ComSendProc(g_ptFDCAN2); + osDelay(1); + } +} +void MK32_Init(void); + +void Drv_InterfaceInit(void) +{ + MK32_Init(); + + const osThreadAttr_t Read_RS485_1_attributes = { + .name = "RS485_1", + .stack_size = 512, + .priority = (osPriority_t) osPriorityHigh7, + }; + (void)osThreadNew(Read_RS485_1, NULL, &Read_RS485_1_attributes); + + const osThreadAttr_t send_task_attributes = { + .name = "send_task", + .stack_size = 512, + .priority = (osPriority_t) osPriorityRealtime, + }; + (void)osThreadNew(SendAll_Task, NULL, &send_task_attributes); +} diff --git a/robot/bspMCU/include/drv_interface.h b/robot/bspMCU/include/drv_interface.h new file mode 100644 index 0000000..79f6157 --- /dev/null +++ b/robot/bspMCU/include/drv_interface.h @@ -0,0 +1,110 @@ +/****************************************************************************** + + 版权所有 (C), 2018-2099, Radkil + + ****************************************************************************** + 文 件 名 : drv_interface.h + 版 本 号 : 初稿 + 作 者 : radkil + 生成日期 : 2026年6月8日 + 最近修改 : + 功能描述 : drv_interface.c 的头文件 + + 修改历史 : + 1.日 期 : 2026年6月8日 + 作 者 : radkil + 修改内容 : 创建文件 + +******************************************************************************/ + +/*----------------------------------------------* + * 外部变量说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 外部函数原型说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 内部函数原型说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 全局变量 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 模块级变量 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 常量定义 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 宏定义 * + *----------------------------------------------*/ + +#ifndef __DRV_INTERFACE_H__ +#define __DRV_INTERFACE_H__ + + +#ifdef __cplusplus +#if __cplusplus +extern "C"{ +#endif +#endif /* __cplusplus */ + + +/*==============================================* + * include header files * + *----------------------------------------------*/ +#include "bsp_config.h" +#include "main.h" +#include "bsp_uart.h" +#include "bsp_CAN.h" +#include "fdcan.h" + + + +/*==============================================* + * constants or macros define * + *----------------------------------------------*/ + + +/*==============================================* + * project-wide global variables * + *----------------------------------------------*/ +extern TComCtrl *g_ptRS485_1; +extern TComCtrl *g_ptRS485_2; +extern TComCtrl *g_ptRS485_3; +extern TComCtrl *g_ptRS485_4; +extern TComCtrl *g_ptLTE_7S0; +extern TComCtrl *g_ptE28_SBUS; +extern TComCtrl *g_ptInterCall; + +extern TComCtrl *g_ptFDCAN1; +extern TComCtrl *g_ptFDCAN2; + +/*==============================================* + * routines' or functions' implementations * + *----------------------------------------------*/ + +extern int E28_SBUS_Send(char *_pBuffer, uint32_t _iSize); +extern int FDCAN1_Send(char *_pBuffer, uint32_t _iSize); +extern int FDCAN2_Send(char *_pBuffer, uint32_t _iSize); +extern int InterCall_Send(char *_pBuffer, uint32_t _iSize); +extern int LTE_7S0_Send(char *_pBuffer, uint32_t _iSize); +extern int RS485_1_Send(char *_pBuffer, uint32_t _iSize); +extern int RS485_2_Send(char *_pBuffer, uint32_t _iSize); +extern int RS485_3_Send(char *_pBuffer, uint32_t _iSize); +extern int RS485_4_Send(char *_pBuffer, uint32_t _iSize); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + + +#endif /* __DRV_INTERFACE_H__ */ diff --git a/robot/bspMCU/include/msp_MK32.h b/robot/bspMCU/include/msp_MK32.h new file mode 100644 index 0000000..ece783a --- /dev/null +++ b/robot/bspMCU/include/msp_MK32.h @@ -0,0 +1,109 @@ +/****************************************************************************** + + 版权所有 (C), 2018-2099, Radkil + + ****************************************************************************** + 文 件 名 : msp_MK32.h + 版 本 号 : 初稿 + 作 者 : radkil + 生成日期 : 2026年6月8日 + 最近修改 : + 功能描述 : msp_MK32.c 的头文件 + + 修改历史 : + 1.日 期 : 2026年6月8日 + 作 者 : radkil + 修改内容 : 创建文件 + +******************************************************************************/ + +/*----------------------------------------------* + * 外部变量说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 外部函数原型说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 内部函数原型说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 全局变量 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 模块级变量 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 常量定义 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 宏定义 * + *----------------------------------------------*/ + +#ifndef __MSP_MK32_H__ +#define __MSP_MK32_H__ + + +#ifdef __cplusplus +#if __cplusplus +extern "C"{ +#endif +#endif /* __cplusplus */ + + +/*==============================================* + * include header files * + *----------------------------------------------*/ +#include + + + +/*==============================================* + * constants or macros define * + *----------------------------------------------*/ +typedef struct _SP_MSP_MK32_Button +{ + int32_t RxIndex; + int32_t CH0_RY_H; + int32_t CH1_RY_V; + int32_t CH2_LY_V; + int32_t CH3_LY_H; + int32_t CH4_SA; + int32_t CH5_SB; + int32_t CH6_SC; + int32_t CH7_SD; + int32_t CH8_SE; + int32_t CH9_SF; + int32_t CH10_LD1; + int32_t CH11_RD1; + int32_t CH12_S1; + int32_t CH13_S2; + int32_t CH14_LT; + int32_t CH15_RT; + int32_t IsOnline; +} SP_MSP_MK32_Button; + + +/*==============================================* + * project-wide global variables * + *----------------------------------------------*/ + + + +/*==============================================* + * routines' or functions' implementations * + *----------------------------------------------*/ + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + + +#endif /* __MSP_MK32_H__ */ diff --git a/robot/bspMCU/msp_MK32.c b/robot/bspMCU/msp_MK32.c new file mode 100644 index 0000000..9154c46 --- /dev/null +++ b/robot/bspMCU/msp_MK32.c @@ -0,0 +1,125 @@ +/****************************************************************************** + + 版权所有 (C), 2018-2099, Radkil + + ****************************************************************************** + 文 件 名 : msp_MK32.c + 版 本 号 : 初稿 + 作 者 : radkil + 生成日期 : 2026年6月8日 + 最近修改 : + 功能描述 : MK32遥控器 + + 修改历史 : + 1.日 期 : 2026年6月8日 + 作 者 : radkil + 修改内容 : 创建文件 + +******************************************************************************/ +#include "msp_MK32.h" +#include "drv_interface.h" + +/*----------------------------------------------* + * 外部变量说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 外部函数原型说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 内部函数原型说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 全局变量 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 模块级变量 * + *----------------------------------------------*/ +static SP_MSP_MK32_Button RB_MK32; + +/*----------------------------------------------* + * 常量定义 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 宏定义 * + *----------------------------------------------*/ + +static int check_MK32Data(char *_pBuffer, uint32_t _iSize) +{ + if (_pBuffer[0] != 0x0f) + { + return -1; + } + if (_pBuffer[24] != 0x0f) + { + return -1; + } + else + { + return 25; + } +} + +static void decode_MK32Data(const char *buf, uint32_t _iSize) +{ + int16_t CH[16]; + int Start_byte = -1; + + CH[0] = ((buf[Start_byte + 1] | buf[Start_byte + 2] << 8) & 0x07FF); + CH[1] = ((buf[Start_byte + 2] >> 3 | buf[Start_byte + 3] << 5) & 0x07FF); + CH[2] = ((buf[Start_byte + 3] >> 6 | buf[Start_byte + 4] << 2 + | buf[Start_byte + 5] << 10) & 0x07FF); + CH[3] = ((buf[Start_byte + 5] >> 1 | buf[Start_byte + 6] << 7) & 0x07FF); + CH[4] = ((buf[Start_byte + 6] >> 4 | buf[Start_byte + 7] << 4) & 0x07FF); + CH[5] = ((buf[Start_byte + 7] >> 7 | buf[Start_byte + 8] << 1 + | buf[Start_byte + 9] << 9) & 0x07FF); + CH[6] = ((buf[Start_byte + 9] >> 2 | buf[Start_byte + 10] << 6) & 0x07FF); + CH[7] = ((buf[Start_byte + 10] >> 5 | buf[Start_byte + 11] << 3) & 0x07FF); + CH[8] = ((buf[Start_byte + 12] | buf[Start_byte + 13] << 8) & 0x07FF); + CH[9] = ((buf[Start_byte + 13] >> 3 | buf[Start_byte + 14] << 5) & 0x07FF); + CH[10] = ((buf[Start_byte + 14] >> 6 | buf[Start_byte + 15] << 2 + | buf[Start_byte + 16] << 10) & 0x07FF); + CH[11] = ((buf[Start_byte + 16] >> 1 | buf[Start_byte + 17] << 7) & 0x07FF); + CH[12] = ((buf[Start_byte + 17] >> 4 | buf[Start_byte + 18] << 4) & 0x07FF); + CH[13] = ((buf[Start_byte + 18] >> 7 | buf[Start_byte + 19] << 1 + | buf[Start_byte + 20] << 9) & 0x07FF); + CH[14] = ((buf[Start_byte + 20] >> 2 | buf[Start_byte + 21] << 6) & 0x07FF); + CH[15] = ((buf[Start_byte + 21] >> 5 | buf[Start_byte + 22] << 3) & 0x07FF); + + int32_t* channel_ptrs[16] = + { + &RB_MK32.CH0_RY_H, &RB_MK32.CH1_RY_V, &RB_MK32.CH2_LY_V, &RB_MK32.CH3_LY_H, + &RB_MK32.CH4_SA, &RB_MK32.CH5_SB, &RB_MK32.CH6_SC, &RB_MK32.CH7_SD, + &RB_MK32.CH8_SE, &RB_MK32.CH9_SF, &RB_MK32.CH10_LD1, &RB_MK32.CH11_RD1, + &RB_MK32.CH12_S1, &RB_MK32.CH13_S2, &RB_MK32.CH14_LT, &RB_MK32.CH15_RT + }; + + // 按键数值转换:1050为中间值,272-1712 + for (int i = 0; i < 16; i++) + { + // 通过指针解引用赋值,完美替代原来的 RB_MK32[i + 1] + *channel_ptrs[i] = (int32_t)((CH[i] - 992) * 1.388889); + } + + // 【核心修改】:通过具体的成员名访问 IsOnline,替代原来的 RB_MK32[17] + if (buf[22] == 0) + { + RB_MK32.IsOnline = 1; + } + else + { + RB_MK32.IsOnline = 0; + } + RB_MK32.RxIndex++; +} + +void MK32_Init(void) +{ + TUartUserData *ptUartUserData = UART_userdata_init(5, 115200, 4096); + g_ptE28_SBUS = rd_ComCreate(check_MK32Data, decode_MK32Data, E28_SBUS_Send, ptUartUserData->m_buf_size, ptUartUserData); + UART_IT_init(g_ptE28_SBUS); +}