From d5d580f384edce8dc65ebfa7a82e035dc469f04b Mon Sep 17 00:00:00 2001 From: Robofish <1683502971@qq.com> Date: Sat, 20 Sep 2025 00:32:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9can?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/code_page/bsp_interface.py | 74 ++++++++--- app/code_page/component_interface.py | 22 +++- app/code_page/device_interface.py | 36 +++++- assets/User_code/bsp/bsp.h | 12 ++ assets/User_code/bsp/can.c | 142 +++++++++------------- assets/User_code/bsp/can.h | 26 +++- assets/User_code/bsp/dwt.c | 16 +++ assets/User_code/bsp/dwt.h | 16 +++ assets/User_code/bsp/gpio.c | 16 +++ assets/User_code/bsp/gpio.h | 12 ++ assets/User_code/bsp/i2c.c | 12 ++ assets/User_code/bsp/i2c.h | 11 ++ assets/User_code/bsp/mm.c | 18 ++- assets/User_code/bsp/mm.h | 12 ++ assets/User_code/bsp/pwm.c | 12 ++ assets/User_code/bsp/pwm.h | 12 ++ assets/User_code/bsp/spi.c | 16 +++ assets/User_code/bsp/spi.h | 12 ++ assets/User_code/bsp/time.c | 18 ++- assets/User_code/bsp/time.h | 12 ++ assets/User_code/bsp/uart.c | 18 ++- assets/User_code/bsp/uart.h | 12 ++ assets/User_code/component/ahrs.c | 12 ++ assets/User_code/component/ahrs.h | 16 +++ assets/User_code/component/capacity.c | 12 ++ assets/User_code/component/capacity.h | 12 ++ assets/User_code/component/cmd.c | 12 ++ assets/User_code/component/cmd.h | 14 ++- assets/User_code/component/crc16.c | 12 ++ assets/User_code/component/crc16.h | 12 ++ assets/User_code/component/crc8.c | 12 ++ assets/User_code/component/crc8.h | 12 ++ assets/User_code/component/error_detect.h | 16 +++ assets/User_code/component/filter.h | 16 +++ assets/User_code/component/limiter.h | 8 ++ assets/User_code/component/mixer.h | 16 +++ assets/User_code/component/pid.h | 12 ++ assets/User_code/component/ui.h | 8 ++ assets/User_code/component/user_math.c | 8 +- assets/User_code/component/user_math.h | 18 +++ assets/User_code/device/bmi088.c | 13 ++ assets/User_code/device/bmi088.h | 16 +++ assets/User_code/device/buzzer.c | 12 ++ assets/User_code/device/buzzer.h | 16 +++ assets/User_code/device/device.h | 16 +++ assets/User_code/device/dm_imu.c | 2 +- assets/User_code/device/dr16.c | 12 ++ assets/User_code/device/dr16.h | 11 ++ assets/User_code/device/ist8310.c | 17 +++ assets/User_code/device/led.c | 17 +++ assets/User_code/device/motor.c | 15 +++ assets/User_code/device/motor.h | 16 +++ assets/User_code/device/motor_lk.c | 22 +++- assets/User_code/device/motor_lz.c | 3 +- assets/User_code/device/motor_rm.c | 18 +++ assets/User_code/device/servo.c | 14 ++- assets/User_code/device/servo.h | 16 +++ assets/User_code/device/vofa.c | 17 +++ assets/User_code/device/ws2812.c | 18 +++ 59 files changed, 910 insertions(+), 126 deletions(-) diff --git a/app/code_page/bsp_interface.py b/app/code_page/bsp_interface.py index f04c6d4..2f202f3 100644 --- a/app/code_page/bsp_interface.py +++ b/app/code_page/bsp_interface.py @@ -86,8 +86,15 @@ class BspSimplePeripheral(QWidget): return self.generate_checkbox.isChecked() def _generate_bsp_code_internal(self): + # 检查是否需要生成 if not self.is_need_generate(): - return False + # 如果未勾选,检查文件是否已存在,如果存在则跳过 + for filename in self.template_names.values(): + output_path = os.path.join(self.project_path, f"User/bsp/{filename}") + if os.path.exists(output_path): + return "skipped" # 返回特殊值表示跳过 + return "not_needed" # 返回特殊值表示不需要生成 + template_dir = CodeGenerator.get_template_dir() for key, filename in self.template_names.items(): template_path = os.path.join(template_dir, filename) @@ -309,8 +316,16 @@ class BspPeripheralBase(QWidget): sel_widget.setCurrentText(instance) def _generate_bsp_code_internal(self): + # 检查是否需要生成 if not self.is_need_generate(): - return False + # 如果未勾选,检查文件是否已存在,如果存在则跳过 + header_file = f"{self.yaml_key}.h" + source_file = f"{self.yaml_key}.c" + header_path = os.path.join(self.project_path, f"User/bsp/{header_file}") + source_path = os.path.join(self.project_path, f"User/bsp/{source_file}") + if os.path.exists(header_path) or os.path.exists(source_path): + return "skipped" # 返回特殊值表示跳过 + return "not_needed" # 返回特殊值表示不需要生成 configs = self._collect_configs() if not configs: return False @@ -487,8 +502,7 @@ class bsp_can(BspPeripheralBase): f" BSP_CAN_RegisterCallback({self.enum_prefix}_{name}, HAL_CAN_RX_FIFO0_MSG_PENDING_CB, BSP_CAN_RxFifo0Callback);", "", f" // 激活{instance}中断", - f" HAL_CAN_ActivateNotification(&hcan{can_num}, CAN_IT_RX_FIFO0_MSG_PENDING | ", - f" CAN_IT_TX_MAILBOX_EMPTY); // 激活发送邮箱空中断", + f" HAL_CAN_ActivateNotification(&hcan{can_num}, CAN_IT_RX_FIFO0_MSG_PENDING);", "" ]) @@ -538,8 +552,7 @@ class bsp_can(BspPeripheralBase): f" BSP_CAN_RegisterCallback({self.enum_prefix}_{name}, HAL_CAN_RX_FIFO1_MSG_PENDING_CB, BSP_CAN_RxFifo1Callback);", "", f" // 激活CAN2中断", - f" HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO1_MSG_PENDING | ", - f" CAN_IT_TX_MAILBOX_EMPTY); // 激活发送邮箱空中断", + f" HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO1_MSG_PENDING);", "" ]) @@ -572,8 +585,7 @@ class bsp_can(BspPeripheralBase): f" BSP_CAN_RegisterCallback({self.enum_prefix}_{name}, HAL_CAN_RX_FIFO0_MSG_PENDING_CB, BSP_CAN_RxFifo0Callback);", "", f" // 激活CAN1中断", - f" HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING | ", - f" CAN_IT_TX_MAILBOX_EMPTY); // 激活发送邮箱空中断", + f" HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);", "" ]) @@ -591,8 +603,7 @@ class bsp_can(BspPeripheralBase): f" BSP_CAN_RegisterCallback({self.enum_prefix}_{name}, HAL_CAN_RX_FIFO0_MSG_PENDING_CB, BSP_CAN_RxFifo0Callback);", "", f" // 激活CAN2中断", - f" HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO0_MSG_PENDING | ", - f" CAN_IT_TX_MAILBOX_EMPTY); // 激活发送邮箱空中断", + f" HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO0_MSG_PENDING);", "" ]) @@ -612,8 +623,7 @@ class bsp_can(BspPeripheralBase): f" BSP_CAN_RegisterCallback({self.enum_prefix}_{name}, HAL_CAN_RX_FIFO1_MSG_PENDING_CB, BSP_CAN_RxFifo1Callback);", "", f" // 激活{instance}中断", - f" HAL_CAN_ActivateNotification(&hcan{can_num}, CAN_IT_RX_FIFO1_MSG_PENDING | ", - f" CAN_IT_TX_MAILBOX_EMPTY); // 激活发送邮箱空中断", + f" HAL_CAN_ActivateNotification(&hcan{can_num}, CAN_IT_RX_FIFO1_MSG_PENDING);", "" ]) filter_bank += 1 # 为下一个CAN分配不同的过滤器组 @@ -822,8 +832,14 @@ class bsp_gpio(QWidget): return configs def _generate_bsp_code_internal(self): + # 检查是否需要生成 if not self.is_need_generate(): - return False + # 如果未勾选,检查文件是否已存在,如果存在则跳过 + gpio_h_path = os.path.join(self.project_path, "User/bsp/gpio.h") + gpio_c_path = os.path.join(self.project_path, "User/bsp/gpio.c") + if os.path.exists(gpio_h_path) or os.path.exists(gpio_c_path): + return "skipped" # 返回特殊值表示跳过 + return "not_needed" # 返回特殊值表示不需要生成 configs = self._collect_configs() if not configs: @@ -1073,8 +1089,14 @@ class bsp_pwm(QWidget): return configs def _generate_bsp_code_internal(self): + # 检查是否需要生成 if not self.is_need_generate(): - return False + # 如果未勾选,检查文件是否已存在,如果存在则跳过 + pwm_h_path = os.path.join(self.project_path, "User/bsp/pwm.h") + pwm_c_path = os.path.join(self.project_path, "User/bsp/pwm.c") + if os.path.exists(pwm_h_path) or os.path.exists(pwm_c_path): + return "skipped" # 返回特殊值表示跳过 + return "not_needed" # 返回特殊值表示不需要生成 configs = self._collect_configs() if not configs: @@ -1201,16 +1223,32 @@ class bsp(QWidget): total = 0 success_count = 0 fail_count = 0 + skipped_count = 0 fail_list = [] + skipped_list = [] for page in pages: # 只处理BSP页面:有 is_need_generate 方法但没有 component_name 属性的页面 if hasattr(page, 'is_need_generate') and not hasattr(page, 'component_name'): - if page.is_need_generate(): + # 先检查是否有文件存在但未勾选的情况 + if not page.is_need_generate(): + try: + result = page._generate_bsp_code_internal() + if result == "skipped": + total += 1 + skipped_count += 1 + skipped_list.append(page.__class__.__name__) + except Exception: + pass # 忽略未勾选页面的错误 + else: + # 勾选的页面,正常处理 total += 1 try: result = page._generate_bsp_code_internal() - if result: + if result == "skipped": + skipped_count += 1 + skipped_list.append(page.__class__.__name__) + elif result: success_count += 1 else: fail_count += 1 @@ -1219,7 +1257,9 @@ class bsp(QWidget): fail_count += 1 fail_list.append(f"{page.__class__.__name__} (异常: {e})") - msg = f"总共尝试生成 {total} 项,成功 {success_count} 项,失败 {fail_count} 项。" + msg = f"总共处理 {total} 项,成功生成 {success_count} 项,跳过 {skipped_count} 项,失败 {fail_count} 项。" + if skipped_list: + msg += f"\n跳过项(文件已存在且未勾选):\n" + "\n".join(skipped_list) if fail_list: msg += "\n失败项:\n" + "\n".join(fail_list) diff --git a/app/code_page/component_interface.py b/app/code_page/component_interface.py index 2e104df..f126488 100644 --- a/app/code_page/component_interface.py +++ b/app/code_page/component_interface.py @@ -157,8 +157,15 @@ class ComponentSimple(QWidget): return self.dependencies.get(self.component_name.lower(), []) def _generate_component_code_internal(self): + # 检查是否需要生成 if not self.is_need_generate(): - return False + # 如果未勾选,检查文件是否已存在,如果存在则跳过 + for filename in self.template_names.values(): + output_path = os.path.join(self.project_path, f"User/component/{filename}") + if os.path.exists(output_path): + return "skipped" # 返回特殊值表示跳过 + return "not_needed" # 返回特殊值表示不需要生成 + template_dir = self._get_component_template_dir() for key, filename in self.template_names.items(): template_path = os.path.join(template_dir, filename) @@ -377,6 +384,9 @@ class component(QWidget): print(f"复制依赖失败: {dep_path}, 错误: {e}") # 生成组件代码 + skipped_count = 0 + skipped_list = [] + for comp_name in components_to_generate: if comp_name in component_pages: page = component_pages[comp_name] @@ -384,7 +394,11 @@ class component(QWidget): # 确保调用正确的方法名 if hasattr(page, '_generate_component_code_internal'): result = page._generate_component_code_internal() - if result: + if result == "skipped": + skipped_count += 1 + skipped_list.append(comp_name) + print(f"跳过组件生成: {comp_name}") + elif result: success_count += 1 print(f"成功生成组件: {comp_name}") else: @@ -401,7 +415,9 @@ class component(QWidget): print(f"生成组件异常: {comp_name}, 错误: {e}") total_items = len(all_deps) + len(components_to_generate) - msg = f"组件代码生成完成:总共尝试生成 {total_items} 项,成功 {success_count} 项,失败 {fail_count} 项。" + msg = f"组件代码生成完成:总共处理 {total_items} 项,成功生成 {success_count} 项,跳过 {skipped_count} 项,失败 {fail_count} 项。" + if skipped_list: + msg += f"\n跳过项(文件已存在且未勾选):\n" + "\n".join(skipped_list) if fail_list: msg += "\n失败项:\n" + "\n".join(fail_list) diff --git a/app/code_page/device_interface.py b/app/code_page/device_interface.py index b99a9db..72523ea 100644 --- a/app/code_page/device_interface.py +++ b/app/code_page/device_interface.py @@ -230,8 +230,15 @@ class DeviceSimple(QWidget): def _generate_device_code_internal(self): """生成设备代码""" + # 检查是否需要生成 if not self.is_need_generate(): - return False + # 如果未勾选,检查文件是否已存在,如果存在则跳过 + files = self.device_config.get('files', {}) + for filename in files.values(): + output_path = os.path.join(self.project_path, f"User/device/{filename}") + if os.path.exists(output_path): + return "skipped" # 返回特殊值表示跳过 + return "not_needed" # 返回特殊值表示不需要生成 # 获取BSP配置 bsp_config = self.get_bsp_config() @@ -349,18 +356,33 @@ class device(QWidget): """生成所有设备代码""" success_count = 0 fail_count = 0 + skipped_count = 0 fail_list = [] + skipped_list = [] enabled_devices = [] # 生成设备代码 for page in pages: if hasattr(page, "device_name") and hasattr(page, "is_need_generate"): - if page.is_need_generate(): - enabled_devices.append(page.device_name) + # 先检查是否有文件存在但未勾选的情况 + if not page.is_need_generate(): try: result = page._generate_device_code_internal() - if result: + if result == "skipped": + skipped_count += 1 + skipped_list.append(page.device_name) + except Exception: + pass # 忽略未勾选页面的错误 + else: + # 勾选的页面,正常处理 + try: + result = page._generate_device_code_internal() + if result == "skipped": + skipped_count += 1 + skipped_list.append(page.device_name) + elif result: success_count += 1 + enabled_devices.append(page.device_name) else: fail_count += 1 fail_list.append(page.device_name) @@ -384,8 +406,10 @@ class device(QWidget): except Exception as e: print(f"刷新页面 {getattr(page, 'device_name', 'Unknown')} 的BSP选项失败: {e}") - total_items = success_count + fail_count - msg = f"设备代码生成完成:总共尝试生成 {total_items} 项,成功 {success_count} 项,失败 {fail_count} 项。" + total_items = success_count + fail_count + skipped_count + msg = f"设备代码生成完成:总共处理 {total_items} 项,成功生成 {success_count} 项,跳过 {skipped_count} 项,失败 {fail_count} 项。" + if skipped_list: + msg += f"\n跳过项(文件已存在且未勾选):\n" + "\n".join(skipped_list) if fail_list: msg += "\n失败项:\n" + "\n".join(fail_list) diff --git a/assets/User_code/bsp/bsp.h b/assets/User_code/bsp/bsp.h index 6a3171b..1f8cbfd 100644 --- a/assets/User_code/bsp/bsp.h +++ b/assets/User_code/bsp/bsp.h @@ -4,6 +4,14 @@ extern "C" { #endif +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + #define BSP_OK (0) #define BSP_ERR (-1) #define BSP_ERR_NULL (-2) @@ -11,6 +19,10 @@ extern "C" { #define BSP_ERR_NO_DEV (-4) #define BSP_ERR_TIMEOUT (-5) +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/bsp/can.c b/assets/User_code/bsp/can.c index 91727db..71451fc 100644 --- a/assets/User_code/bsp/can.c +++ b/assets/User_code/bsp/can.c @@ -5,11 +5,18 @@ #include #include +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ #define CAN_QUEUE_MUTEX_TIMEOUT 100 /* 队列互斥锁超时时间(ms) */ -#define CAN_TX_SEMAPHORE_TIMEOUT 1000 /* 发送信号量超时时间(ms) */ #define CAN_TX_MAILBOX_NUM 3 /* CAN发送邮箱数量 */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ typedef struct BSP_CAN_QueueNode { @@ -20,10 +27,13 @@ typedef struct BSP_CAN_QueueNode { struct BSP_CAN_QueueNode *next; /* 指向下一个节点的指针 */ } BSP_CAN_QueueNode_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ static BSP_CAN_QueueNode_t *queue_list = NULL; static osMutexId_t queue_mutex = NULL; -static osSemaphoreId_t tx_semaphore[BSP_CAN_NUM] = {NULL}; /* 发送信号量,用于控制发送邮箱访问 */ static void (*CAN_Callback[BSP_CAN_NUM][BSP_CAN_CB_NUM])(void); static bool inited = false; static BSP_CAN_IdParser_t id_parser = NULL; /* ID解析器 */ @@ -35,12 +45,13 @@ static int8_t BSP_CAN_CreateIdQueue(BSP_CAN_t can, uint32_t can_id, uint8_t queu static int8_t BSP_CAN_DeleteIdQueue(BSP_CAN_t can, uint32_t can_id); static void BSP_CAN_RxFifo0Callback(void); static void BSP_CAN_RxFifo1Callback(void); -static void BSP_CAN_TxCompleteCallback(CAN_HandleTypeDef *hcan); -static void BSP_CAN_TxAbortCallback(CAN_HandleTypeDef *hcan); static BSP_CAN_FrameType_t BSP_CAN_GetFrameType(CAN_RxHeaderTypeDef *header); static uint32_t BSP_CAN_DefaultIdParser(uint32_t original_id, BSP_CAN_FrameType_t frame_type); /* Private functions -------------------------------------------------------- */ +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ /** * @brief 根据CAN句柄获取BSP_CAN实例 @@ -213,38 +224,10 @@ static void BSP_CAN_RxFifo1Callback(void) { } } -/** - * @brief 发送完成回调统一处理函数 - */ -static void BSP_CAN_TxCompleteCallback(CAN_HandleTypeDef *hcan) { - BSP_CAN_t bsp_can = CAN_Get(hcan); - if (bsp_can != BSP_CAN_ERR) { - // 释放发送信号量 - if (tx_semaphore[bsp_can] != NULL) { - osSemaphoreRelease(tx_semaphore[bsp_can]); - } - } -} - -/** - * @brief 发送中止回调统一处理函数 - */ -static void BSP_CAN_TxAbortCallback(CAN_HandleTypeDef *hcan) { - BSP_CAN_t bsp_can = CAN_Get(hcan); - if (bsp_can != BSP_CAN_ERR) { - // 释放发送信号量(发送中止也要释放) - if (tx_semaphore[bsp_can] != NULL) { - osSemaphoreRelease(tx_semaphore[bsp_can]); - } - } -} - /* HAL Callback Functions --------------------------------------------------- */ void HAL_CAN_TxMailbox0CompleteCallback(CAN_HandleTypeDef *hcan) { BSP_CAN_t bsp_can = CAN_Get(hcan); if (bsp_can != BSP_CAN_ERR) { - // 自动释放发送信号量 - BSP_CAN_TxCompleteCallback(hcan); // 调用用户回调 if (CAN_Callback[bsp_can][HAL_CAN_TX_MAILBOX0_CPLT_CB]) CAN_Callback[bsp_can][HAL_CAN_TX_MAILBOX0_CPLT_CB](); @@ -254,8 +237,6 @@ void HAL_CAN_TxMailbox0CompleteCallback(CAN_HandleTypeDef *hcan) { void HAL_CAN_TxMailbox1CompleteCallback(CAN_HandleTypeDef *hcan) { BSP_CAN_t bsp_can = CAN_Get(hcan); if (bsp_can != BSP_CAN_ERR) { - // 自动释放发送信号量 - BSP_CAN_TxCompleteCallback(hcan); // 调用用户回调 if (CAN_Callback[bsp_can][HAL_CAN_TX_MAILBOX1_CPLT_CB]) CAN_Callback[bsp_can][HAL_CAN_TX_MAILBOX1_CPLT_CB](); @@ -265,8 +246,6 @@ void HAL_CAN_TxMailbox1CompleteCallback(CAN_HandleTypeDef *hcan) { void HAL_CAN_TxMailbox2CompleteCallback(CAN_HandleTypeDef *hcan) { BSP_CAN_t bsp_can = CAN_Get(hcan); if (bsp_can != BSP_CAN_ERR) { - // 自动释放发送信号量 - BSP_CAN_TxCompleteCallback(hcan); // 调用用户回调 if (CAN_Callback[bsp_can][HAL_CAN_TX_MAILBOX2_CPLT_CB]) CAN_Callback[bsp_can][HAL_CAN_TX_MAILBOX2_CPLT_CB](); @@ -276,8 +255,6 @@ void HAL_CAN_TxMailbox2CompleteCallback(CAN_HandleTypeDef *hcan) { void HAL_CAN_TxMailbox0AbortCallback(CAN_HandleTypeDef *hcan) { BSP_CAN_t bsp_can = CAN_Get(hcan); if (bsp_can != BSP_CAN_ERR) { - // 自动释放发送信号量 - BSP_CAN_TxAbortCallback(hcan); // 调用用户回调 if (CAN_Callback[bsp_can][HAL_CAN_TX_MAILBOX0_ABORT_CB]) CAN_Callback[bsp_can][HAL_CAN_TX_MAILBOX0_ABORT_CB](); @@ -287,8 +264,6 @@ void HAL_CAN_TxMailbox0AbortCallback(CAN_HandleTypeDef *hcan) { void HAL_CAN_TxMailbox1AbortCallback(CAN_HandleTypeDef *hcan) { BSP_CAN_t bsp_can = CAN_Get(hcan); if (bsp_can != BSP_CAN_ERR) { - // 自动释放发送信号量 - BSP_CAN_TxAbortCallback(hcan); // 调用用户回调 if (CAN_Callback[bsp_can][HAL_CAN_TX_MAILBOX1_ABORT_CB]) CAN_Callback[bsp_can][HAL_CAN_TX_MAILBOX1_ABORT_CB](); @@ -298,8 +273,6 @@ void HAL_CAN_TxMailbox1AbortCallback(CAN_HandleTypeDef *hcan) { void HAL_CAN_TxMailbox2AbortCallback(CAN_HandleTypeDef *hcan) { BSP_CAN_t bsp_can = CAN_Get(hcan); if (bsp_can != BSP_CAN_ERR) { - // 自动释放发送信号量 - BSP_CAN_TxAbortCallback(hcan); // 调用用户回调 if (CAN_Callback[bsp_can][HAL_CAN_TX_MAILBOX2_ABORT_CB]) CAN_Callback[bsp_can][HAL_CAN_TX_MAILBOX2_ABORT_CB](); @@ -381,25 +354,6 @@ int8_t BSP_CAN_Init(void) { return BSP_ERR; } - // 创建发送信号量,每个CAN通道有3个发送邮箱 - for (int i = 0; i < BSP_CAN_NUM; i++) { - tx_semaphore[i] = osSemaphoreNew(CAN_TX_MAILBOX_NUM, CAN_TX_MAILBOX_NUM, NULL); - if (tx_semaphore[i] == NULL) { - // 清理已创建的信号量 - for (int j = 0; j < i; j++) { - if (tx_semaphore[j] != NULL) { - osSemaphoreDelete(tx_semaphore[j]); - tx_semaphore[j] = NULL; - } - } - if (queue_mutex != NULL) { - osMutexDelete(queue_mutex); - queue_mutex = NULL; - } - return BSP_ERR; - } - } - /* AUTO GENERATED CAN_INIT */ inited = true; @@ -424,14 +378,6 @@ int8_t BSP_CAN_DeInit(void) { osMutexRelease(queue_mutex); } - // 删除发送信号量 - for (int i = 0; i < BSP_CAN_NUM; i++) { - if (tx_semaphore[i] != NULL) { - osSemaphoreDelete(tx_semaphore[i]); - tx_semaphore[i] = NULL; - } - } - // 删除互斥锁 if (queue_mutex != NULL) { osMutexDelete(queue_mutex); @@ -494,20 +440,8 @@ int8_t BSP_CAN_Transmit(BSP_CAN_t can, BSP_CAN_Format_t format, return BSP_ERR; } - // 获取发送信号量,确保有可用的发送邮箱 - if (tx_semaphore[can] == NULL) { - return BSP_ERR; - } - - osStatus_t sem_status = osSemaphoreAcquire(tx_semaphore[can], CAN_TX_SEMAPHORE_TIMEOUT); - if (sem_status != osOK) { - return BSP_ERR_TIMEOUT; // 获取信号量超时,表示发送邮箱已满 - } - CAN_HandleTypeDef *hcan = BSP_CAN_GetHandle(can); if (hcan == NULL) { - // 如果获取句柄失败,需要释放信号量 - osSemaphoreRelease(tx_semaphore[can]); return BSP_ERR_NULL; } @@ -536,8 +470,6 @@ int8_t BSP_CAN_Transmit(BSP_CAN_t can, BSP_CAN_Format_t format, header.RTR = CAN_RTR_REMOTE; break; default: - // 如果格式错误,需要释放信号量 - osSemaphoreRelease(tx_semaphore[can]); return BSP_ERR; } @@ -547,12 +479,9 @@ int8_t BSP_CAN_Transmit(BSP_CAN_t can, BSP_CAN_Format_t format, HAL_StatusTypeDef result = HAL_CAN_AddTxMessage(hcan, &header, data, &mailbox); if (result != HAL_OK) { - // 如果发送失败,需要释放信号量 - osSemaphoreRelease(tx_semaphore[can]); return BSP_ERR; } - // 发送成功,信号量将在发送完成回调中释放 return BSP_OK; } @@ -672,3 +601,44 @@ uint32_t BSP_CAN_ParseId(uint32_t original_id, BSP_CAN_FrameType_t frame_type) { } return BSP_CAN_DefaultIdParser(original_id, frame_type); } + +int8_t BSP_CAN_WaitTxMailboxEmpty(BSP_CAN_t can, uint32_t timeout) { + if (!inited) { + return BSP_ERR_INITED; + } + if (can >= BSP_CAN_NUM) { + return BSP_ERR; + } + + CAN_HandleTypeDef *hcan = BSP_CAN_GetHandle(can); + if (hcan == NULL) { + return BSP_ERR_NULL; + } + + uint32_t start_time = HAL_GetTick(); + + // 如果超时时间为0,立即检查并返回 + if (timeout == 0) { + uint32_t free_level = HAL_CAN_GetTxMailboxesFreeLevel(hcan); + return (free_level > 0) ? BSP_OK : BSP_ERR_TIMEOUT; + } + + // 等待至少有一个邮箱空闲 + while (true) { + uint32_t free_level = HAL_CAN_GetTxMailboxesFreeLevel(hcan); + if (free_level > 0) { + return BSP_OK; + } + + // 检查超时 + if (timeout != BSP_CAN_TIMEOUT_FOREVER) { + uint32_t elapsed = HAL_GetTick() - start_time; + if (elapsed >= timeout) { + return BSP_ERR_TIMEOUT; + } + } + + // 短暂延时,避免占用过多CPU + osDelay(1); + } +} diff --git a/assets/User_code/bsp/can.h b/assets/User_code/bsp/can.h index c1bc147..f987abe 100644 --- a/assets/User_code/bsp/can.h +++ b/assets/User_code/bsp/can.h @@ -12,12 +12,19 @@ extern "C" { #include #include +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Exported constants ------------------------------------------------------- */ #define BSP_CAN_MAX_DLC 8 #define BSP_CAN_DEFAULT_QUEUE_SIZE 10 #define BSP_CAN_TIMEOUT_IMMEDIATE 0 #define BSP_CAN_TIMEOUT_FOREVER osWaitForever -#define CAN_TX_SEMAPHORE_TIMEOUT 1000 /* 发送信号量超时时间(ms) */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ /* Exported macro ----------------------------------------------------------- */ /* Exported types ----------------------------------------------------------- */ @@ -94,6 +101,10 @@ typedef struct { /* ID解析回调函数类型 */ typedef uint32_t (*BSP_CAN_IdParser_t)(uint32_t original_id, BSP_CAN_FrameType_t frame_type); +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Exported functions prototypes -------------------------------------------- */ /** @@ -161,6 +172,14 @@ int8_t BSP_CAN_TransmitExtDataFrame(BSP_CAN_t can, BSP_CAN_ExtDataFrame_t *frame */ int8_t BSP_CAN_TransmitRemoteFrame(BSP_CAN_t can, BSP_CAN_RemoteFrame_t *frame); +/** + * @brief 等待CAN发送邮箱空闲 + * @param can CAN 枚举 + * @param timeout 超时时间(毫秒),0为立即返回,osWaitForever为永久等待 + * @return BSP_OK 成功,其他值失败 + */ +int8_t BSP_CAN_WaitTxMailboxEmpty(BSP_CAN_t can, uint32_t timeout); + /** * @brief 注册 CAN ID 接收队列 * @param can CAN 枚举 @@ -225,6 +244,11 @@ int8_t BSP_CAN_UnregisterIdParser(void); */ uint32_t BSP_CAN_ParseId(uint32_t original_id, BSP_CAN_FrameType_t frame_type); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/assets/User_code/bsp/dwt.c b/assets/User_code/bsp/dwt.c index 15e3e51..c16af9e 100644 --- a/assets/User_code/bsp/dwt.c +++ b/assets/User_code/bsp/dwt.c @@ -12,6 +12,18 @@ */ #include "bsp/dwt.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + DWT_Time_t SysTime; static uint32_t CPU_FREQ_Hz, CPU_FREQ_Hz_ms, CPU_FREQ_Hz_us; static uint32_t CYCCNT_RountCount; @@ -19,6 +31,10 @@ static uint32_t CYCCNT_LAST; uint64_t CYCCNT64; static void DWT_CNT_Update(void); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + void DWT_Init(uint32_t CPU_Freq_mHz) { /* 使能DWT外设 */ diff --git a/assets/User_code/bsp/dwt.h b/assets/User_code/bsp/dwt.h index 817e922..65a731e 100644 --- a/assets/User_code/bsp/dwt.h +++ b/assets/User_code/bsp/dwt.h @@ -16,6 +16,14 @@ #include "main.h" #include "stdint.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + typedef struct { uint32_t s; @@ -23,6 +31,10 @@ typedef struct uint16_t us; } DWT_Time_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + void DWT_Init(uint32_t CPU_Freq_mHz); float DWT_GetDeltaT(uint32_t *cnt_last); double DWT_GetDeltaT64(uint32_t *cnt_last); @@ -34,4 +46,8 @@ void DWT_SysTimeUpdate(void); extern DWT_Time_t SysTime; +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #endif /* DWT_H_ */ diff --git a/assets/User_code/bsp/gpio.c b/assets/User_code/bsp/gpio.c index 5001f39..5c3113c 100644 --- a/assets/User_code/bsp/gpio.c +++ b/assets/User_code/bsp/gpio.c @@ -4,7 +4,15 @@ #include #include +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ typedef struct { @@ -12,6 +20,10 @@ typedef struct { GPIO_TypeDef *gpio; } BSP_GPIO_MAP_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ static const BSP_GPIO_MAP_t GPIO_Map[BSP_GPIO_NUM] = { /* AUTO GENERATED BSP_GPIO_MAP */ @@ -20,6 +32,10 @@ static const BSP_GPIO_MAP_t GPIO_Map[BSP_GPIO_NUM] = { static void (*GPIO_Callback[16])(void); /* Private function -------------------------------------------------------- */ +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { for (uint8_t i = 0; i < 16; i++) { if (GPIO_Pin & (1 << i)) { diff --git a/assets/User_code/bsp/gpio.h b/assets/User_code/bsp/gpio.h index 75027f1..0f30a9b 100644 --- a/assets/User_code/bsp/gpio.h +++ b/assets/User_code/bsp/gpio.h @@ -10,8 +10,16 @@ extern "C" { #include "bsp/bsp.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Exported constants ------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Exported types ----------------------------------------------------------- */ typedef enum { /* AUTO GENERATED BSP_GPIO_ENUM */ @@ -30,6 +38,10 @@ int8_t BSP_GPIO_TogglePin(BSP_GPIO_t gpio); bool BSP_GPIO_ReadPin(BSP_GPIO_t gpio); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/assets/User_code/bsp/i2c.c b/assets/User_code/bsp/i2c.c index 2885125..6120f59 100644 --- a/assets/User_code/bsp/i2c.c +++ b/assets/User_code/bsp/i2c.c @@ -1,9 +1,21 @@ /* Includes ----------------------------------------------------------------- */ #include "bsp\i2c.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ static void (*I2C_Callback[BSP_I2C_NUM][BSP_I2C_CB_NUM])(void); diff --git a/assets/User_code/bsp/i2c.h b/assets/User_code/bsp/i2c.h index ab75d48..79086e7 100644 --- a/assets/User_code/bsp/i2c.h +++ b/assets/User_code/bsp/i2c.h @@ -11,8 +11,16 @@ extern "C" { #include "bsp/bsp.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Exported constants ------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Exported types ----------------------------------------------------------- */ /* 要添加使用I2C的新设备,需要先在此添加对应的枚举值 */ @@ -61,6 +69,9 @@ int8_t BSP_I2C_MemRead(BSP_I2C_t i2c, uint16_t devAddr, uint16_t memAddr, int8_t BSP_I2C_MemWrite(BSP_I2C_t i2c, uint16_t devAddr, uint16_t memAddr, uint8_t *data, uint16_t size, bool dma); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ #ifdef __cplusplus } diff --git a/assets/User_code/bsp/mm.c b/assets/User_code/bsp/mm.c index b78e3c4..13d20c0 100644 --- a/assets/User_code/bsp/mm.c +++ b/assets/User_code/bsp/mm.c @@ -1,14 +1,30 @@ /* Includes ----------------------------------------------------------------- */ -#include "bsp\mm.h" +#include "bsp/mm.h" #include "FreeRTOS.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private variables -------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private function -------------------------------------------------------- */ /* Exported functions ------------------------------------------------------- */ inline void *BSP_Malloc(size_t size) { return pvPortMalloc(size); } inline void BSP_Free(void *pv) { vPortFree(pv); } + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ diff --git a/assets/User_code/bsp/mm.h b/assets/User_code/bsp/mm.h index 57bdcac..d24634e 100644 --- a/assets/User_code/bsp/mm.h +++ b/assets/User_code/bsp/mm.h @@ -8,13 +8,25 @@ extern "C" { #include #include +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Exported constants ------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Exported types ----------------------------------------------------------- */ /* Exported functions prototypes -------------------------------------------- */ void *BSP_Malloc(size_t size); void BSP_Free(void *pv); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/bsp/pwm.c b/assets/User_code/bsp/pwm.c index 34e9893..3caedb0 100644 --- a/assets/User_code/bsp/pwm.c +++ b/assets/User_code/bsp/pwm.c @@ -3,7 +3,15 @@ #include "bsp/pwm.h" #include "bsp.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ typedef struct { @@ -11,6 +19,10 @@ typedef struct { uint16_t channel; } BSP_PWM_Config_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ static const BSP_PWM_Config_t PWM_Map[BSP_PWM_NUM] = { /* AUTO GENERATED BSP_PWM_MAP */ diff --git a/assets/User_code/bsp/pwm.h b/assets/User_code/bsp/pwm.h index a1fa3c9..c50c127 100644 --- a/assets/User_code/bsp/pwm.h +++ b/assets/User_code/bsp/pwm.h @@ -9,9 +9,17 @@ extern "C" { #include "tim.h" #include "bsp.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Exported constants ------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Exported types ----------------------------------------------------------- */ /* PWM通道 */ typedef enum { @@ -31,6 +39,10 @@ TIM_HandleTypeDef* BSP_PWM_GetHandle(BSP_PWM_Channel_t ch); int8_t BSP_PWM_Start_DMA(BSP_PWM_Channel_t ch, uint32_t *pData, uint16_t Length); int8_t BSP_PWM_Stop_DMA(BSP_PWM_Channel_t ch); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/assets/User_code/bsp/spi.c b/assets/User_code/bsp/spi.c index b4701de..d8ac00e 100644 --- a/assets/User_code/bsp/spi.c +++ b/assets/User_code/bsp/spi.c @@ -2,9 +2,21 @@ #include #include "bsp/spi.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ static void (*SPI_Callback[BSP_SPI_NUM][BSP_SPI_CB_NUM])(void); @@ -163,3 +175,7 @@ int8_t BSP_SPI_MemWrite(BSP_SPI_t spi, uint8_t reg, uint8_t *data, uint16_t size BSP_SPI_Transmit(spi, ®, 1u, true); return BSP_SPI_Transmit(spi, data, size, true); } + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ diff --git a/assets/User_code/bsp/spi.h b/assets/User_code/bsp/spi.h index 374b34a..8c0afae 100644 --- a/assets/User_code/bsp/spi.h +++ b/assets/User_code/bsp/spi.h @@ -11,8 +11,16 @@ extern "C" { #include "bsp/bsp.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Exported constants ------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Exported types ----------------------------------------------------------- */ /* 要添加使用SPI的新设备,需要先在此添加对应的枚举值 */ @@ -53,6 +61,10 @@ int8_t BSP_SPI_MemWriteByte(BSP_SPI_t spi, uint8_t reg, uint8_t data); int8_t BSP_SPI_MemRead(BSP_SPI_t spi, uint8_t reg, uint8_t *data, uint16_t size); int8_t BSP_SPI_MemWrite(BSP_SPI_t spi, uint8_t reg, uint8_t *data, uint16_t size); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/bsp/time.c b/assets/User_code/bsp/time.c index 5817cea..21918ed 100644 --- a/assets/User_code/bsp/time.c +++ b/assets/User_code/bsp/time.c @@ -6,9 +6,21 @@ #include "FreeRTOS.h" #include "main.h" #include "task.h" + +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ /* Private define ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ /* Private function -------------------------------------------------------- */ /* Exported functions ------------------------------------------------------- */ @@ -62,4 +74,8 @@ int8_t BSP_TIME_Delay_us(uint32_t us) { return BSP_OK; } -int8_t BSP_TIME_Delay(uint32_t ms) __attribute__((alias("BSP_TIME_Delay_ms"))); \ No newline at end of file +int8_t BSP_TIME_Delay(uint32_t ms) __attribute__((alias("BSP_TIME_Delay_ms"))); + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ \ No newline at end of file diff --git a/assets/User_code/bsp/time.h b/assets/User_code/bsp/time.h index 5273f0f..c69085b 100644 --- a/assets/User_code/bsp/time.h +++ b/assets/User_code/bsp/time.h @@ -9,8 +9,16 @@ extern "C" { #include "bsp/bsp.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Exported constants ------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Exported types ----------------------------------------------------------- */ /* Exported functions prototypes -------------------------------------------- */ uint32_t BSP_TIME_Get_ms(); @@ -26,6 +34,10 @@ int8_t BSP_TIME_Delay_us(uint32_t us); int8_t BSP_TIME_Delay(uint32_t ms); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/bsp/uart.c b/assets/User_code/bsp/uart.c index 8cde78a..a403fdc 100644 --- a/assets/User_code/bsp/uart.c +++ b/assets/User_code/bsp/uart.c @@ -3,9 +3,21 @@ #include "bsp/uart.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ static void (*UART_Callback[BSP_UART_NUM][BSP_UART_CB_NUM])(void); @@ -134,4 +146,8 @@ int8_t BSP_UART_Receive(BSP_UART_t uart, uint8_t *data, uint16_t size, bool dma) } else { return HAL_UART_Receive_IT(BSP_UART_GetHandle(uart), data, size); } -} \ No newline at end of file +} + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ \ No newline at end of file diff --git a/assets/User_code/bsp/uart.h b/assets/User_code/bsp/uart.h index 49a758b..06ff849 100644 --- a/assets/User_code/bsp/uart.h +++ b/assets/User_code/bsp/uart.h @@ -11,8 +11,16 @@ extern "C" { #include "bsp/bsp.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Exported constants ------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Exported types ----------------------------------------------------------- */ /* 要添加使用UART的新设备,需要先在此添加对应的枚举值 */ @@ -51,6 +59,10 @@ int8_t BSP_UART_RegisterCallback(BSP_UART_t uart, BSP_UART_Callback_t type, int8_t BSP_UART_Transmit(BSP_UART_t uart, uint8_t *data, uint16_t size, bool dma); int8_t BSP_UART_Receive(BSP_UART_t uart, uint8_t *data, uint16_t size, bool dma); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/component/ahrs.c b/assets/User_code/component/ahrs.c index 5886297..ffdb870 100644 --- a/assets/User_code/component/ahrs.c +++ b/assets/User_code/component/ahrs.c @@ -9,9 +9,17 @@ #include "user_math.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + #define BETA_IMU (0.033f) #define BETA_AHRS (0.041f) +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* 2 * proportional gain (Kp) */ static float beta = BETA_IMU; @@ -403,3 +411,7 @@ int8_t AHRS_GetEulr(AHRS_Eulr_t *eulr, const AHRS_t *ahrs) { * \param eulr 被操作的数据 */ void AHRS_ResetEulr(AHRS_Eulr_t *eulr) { memset(eulr, 0, sizeof(*eulr)); } + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ diff --git a/assets/User_code/component/ahrs.h b/assets/User_code/component/ahrs.h index add8b8b..2245b1f 100644 --- a/assets/User_code/component/ahrs.h +++ b/assets/User_code/component/ahrs.h @@ -11,6 +11,14 @@ extern "C" { #include "user_math.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* 欧拉角(Euler angle) */ typedef struct { float yaw; /* 偏航角(Yaw angle) */ @@ -55,6 +63,10 @@ typedef struct { float inv_sample_freq; /* 采样频率的的倒数 */ } AHRS_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /** * @brief 初始化姿态解算 * @@ -93,6 +105,10 @@ int8_t AHRS_GetEulr(AHRS_Eulr_t *eulr, const AHRS_t *ahrs); */ void AHRS_ResetEulr(AHRS_Eulr_t *eulr); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/component/capacity.c b/assets/User_code/component/capacity.c index a7bf801..fd64eb2 100644 --- a/assets/User_code/component/capacity.c +++ b/assets/User_code/component/capacity.c @@ -5,6 +5,14 @@ #include "capacity.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /** * @brief 通过电压计算电池剩余电量 * @@ -56,3 +64,7 @@ float Capacity_GetCapacitorRemain(float vcap, float vbat, float v_cutoff) { return percentage; } + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ diff --git a/assets/User_code/component/capacity.h b/assets/User_code/component/capacity.h index a3839d4..b4010e9 100644 --- a/assets/User_code/component/capacity.h +++ b/assets/User_code/component/capacity.h @@ -12,6 +12,14 @@ extern "C" { #include "user_math.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /** * @brief 通过电压计算电池剩余电量 * @@ -30,6 +38,10 @@ float Capacity_GetBatteryRemain(float volt); */ float Capacity_GetCapacitorRemain(float vcap, float vbat, float v_cutoff); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/component/cmd.c b/assets/User_code/component/cmd.c index 205869c..1effe69 100644 --- a/assets/User_code/component/cmd.c +++ b/assets/User_code/component/cmd.c @@ -6,6 +6,14 @@ #include +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /** * @brief 行为转换为对应按键 * @@ -373,3 +381,7 @@ int8_t CMD_RefereeAdd(CMD_RefereeCmd_t *ref, CMD_UI_t cmd) { ref->counter++; return 0; } + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ diff --git a/assets/User_code/component/cmd.h b/assets/User_code/component/cmd.h index 8561239..df84538 100644 --- a/assets/User_code/component/cmd.h +++ b/assets/User_code/component/cmd.h @@ -13,7 +13,15 @@ extern "C" { #include "component/ahrs.h" -#define CMD_REFEREE_MAX_NUM (3) /* 发送命令限定的最大数量 */ +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +#define CMD_REFEREE_MAX_NUM (3) /* Lines 16 omitted */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ /* 机器人型号 */ typedef enum { @@ -301,6 +309,10 @@ int8_t CMD_ParseHost(const CMD_Host_t *host, CMD_t *cmd, float dt_sec); */ int8_t CMD_RefereeAdd(CMD_RefereeCmd_t *ref, CMD_UI_t cmd); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/component/crc16.c b/assets/User_code/component/crc16.c index 2d9de2a..0d17eb0 100644 --- a/assets/User_code/component/crc16.c +++ b/assets/User_code/component/crc16.c @@ -1,5 +1,13 @@ #include "crc16.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + static const uint16_t crc16_tab[256] = { 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, @@ -48,3 +56,7 @@ bool CRC16_Verify(const uint8_t *buf, size_t len) { ((const uint16_t *)((const uint8_t *)buf + (len % 2)))[len / sizeof(uint16_t) - 1]; } + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ diff --git a/assets/User_code/component/crc16.h b/assets/User_code/component/crc16.h index dc54b30..68b0a87 100644 --- a/assets/User_code/component/crc16.h +++ b/assets/User_code/component/crc16.h @@ -8,11 +8,23 @@ extern "C" { #include "user_math.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + #define CRC16_INIT 0XFFFF uint16_t CRC16_Calc(const uint8_t *buf, size_t len, uint16_t crc); bool CRC16_Verify(const uint8_t *buf, size_t len); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/component/crc8.c b/assets/User_code/component/crc8.c index bf0bcf9..66f4ad2 100644 --- a/assets/User_code/component/crc8.c +++ b/assets/User_code/component/crc8.c @@ -1,5 +1,13 @@ #include "crc8.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + static const uint8_t crc8_tab[256] = { 0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41, 0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e, @@ -38,3 +46,7 @@ bool CRC8_Verify(const uint8_t *buf, size_t len) { uint8_t expected = CRC8_Calc(buf, len - sizeof(uint8_t), CRC8_INIT); return expected == buf[len - sizeof(uint8_t)]; } + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ diff --git a/assets/User_code/component/crc8.h b/assets/User_code/component/crc8.h index 61b221a..a376c71 100644 --- a/assets/User_code/component/crc8.h +++ b/assets/User_code/component/crc8.h @@ -8,11 +8,23 @@ extern "C" { #include #include +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + #define CRC8_INIT 0xFF uint8_t CRC8_Calc(const uint8_t *buf, size_t len, uint8_t crc); bool CRC8_Verify(const uint8_t *buf, size_t len); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/component/error_detect.h b/assets/User_code/component/error_detect.h index eb79614..3dba7a2 100644 --- a/assets/User_code/component/error_detect.h +++ b/assets/User_code/component/error_detect.h @@ -11,6 +11,14 @@ extern "C" { #include #include +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + typedef enum { /* Low priority */ ERROR_DETECT_UNIT_NO_DEV = 0, @@ -53,6 +61,10 @@ typedef struct { ErrorDetect_Error_t error[ERROR_DETECT_UNIT_NUM]; } ErrorDetect_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + int8_t ErrorDetect_Init(void); void ErrorDetect_Processing(uint32_t sys_time); bool ErrorDetect_ErrorExist(ErrorDetect_Unit_t unit); @@ -61,6 +73,10 @@ const ErrorDetect_Error_t *ErrorDetect_GetDetail(ErrorDetect_Unit_t unit); void ErrorDetect_Update(ErrorDetect_Unit_t unit, uint32_t time_current); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/component/filter.h b/assets/User_code/component/filter.h index c075946..ae2b072 100644 --- a/assets/User_code/component/filter.h +++ b/assets/User_code/component/filter.h @@ -10,6 +10,14 @@ extern "C" { #include "user_math.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* 二阶低通滤波器 */ typedef struct { float cutoff_freq; /* 截止频率 */ @@ -42,6 +50,10 @@ typedef struct { } NotchFilter_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /** * @brief 初始化滤波器 * @@ -99,6 +111,10 @@ float NotchFilter_Apply(NotchFilter_t *f, float sample); */ float NotchFilter_Reset(NotchFilter_t *f, float sample); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/component/limiter.h b/assets/User_code/component/limiter.h index 7c24cb5..d0aa92a 100644 --- a/assets/User_code/component/limiter.h +++ b/assets/User_code/component/limiter.h @@ -11,6 +11,14 @@ extern "C" { #include #include +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /** * @brief 限制底盘功率不超过power_limit * diff --git a/assets/User_code/component/mixer.h b/assets/User_code/component/mixer.h index 98de3b0..b8e4401 100644 --- a/assets/User_code/component/mixer.h +++ b/assets/User_code/component/mixer.h @@ -10,6 +10,14 @@ extern "C" { #include "user_math.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /** 四轮布局 */ /* 前 */ /* 2 1 */ @@ -33,6 +41,10 @@ typedef struct { Mixer_Mode_t mode; } Mixer_t; /* 混合器主结构体 */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /** * @brief 初始化混合器 * @@ -55,6 +67,10 @@ int8_t Mixer_Init(Mixer_t *mixer, Mixer_Mode_t mode); int8_t Mixer_Apply(Mixer_t *mixer, MoveVector_t *move_vec, float *out, int8_t len, float scale); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/component/pid.h b/assets/User_code/component/pid.h index a93acaa..4b451eb 100644 --- a/assets/User_code/component/pid.h +++ b/assets/User_code/component/pid.h @@ -14,6 +14,14 @@ extern "C" { #include "filter.h" #include "user_math.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* PID模式 */ typedef enum { KPID_MODE_NO_D = 0, /* 不使用微分项,PI控制器 */ @@ -90,6 +98,10 @@ int8_t PID_ResetIntegral(KPID_t *pid); */ int8_t PID_Reset(KPID_t *pid); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/component/ui.h b/assets/User_code/component/ui.h index e569985..4f742d3 100644 --- a/assets/User_code/component/ui.h +++ b/assets/User_code/component/ui.h @@ -13,6 +13,10 @@ extern "C" { #include "component/user_math.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + #define UI_DEL_OPERATION_NOTHING (0) #define UI_DEL_OPERATION_DEL (1) #define UI_DEL_OPERATION_DEL_ALL (2) @@ -31,6 +35,10 @@ extern "C" { #define UI_GRAPIC_LAYER_CMD (6) #define UI_DEFAULT_WIDTH (0x01) + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ #define UI_CHAR_DEFAULT_WIDTH (0x02) typedef enum { diff --git a/assets/User_code/component/user_math.c b/assets/User_code/component/user_math.c index f3f3964..49a4723 100644 --- a/assets/User_code/component/user_math.c +++ b/assets/User_code/component/user_math.c @@ -3,8 +3,10 @@ */ #include "user_math.h" - #include +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ inline float InvSqrt(float x) { //#if 0 @@ -130,3 +132,7 @@ inline float CalculateRpm(float bullet_speed, float fric_radius, bool is17mm) { // __NOP(); // } // } + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ \ No newline at end of file diff --git a/assets/User_code/component/user_math.h b/assets/User_code/component/user_math.h index fea820f..d4531e6 100644 --- a/assets/User_code/component/user_math.h +++ b/assets/User_code/component/user_math.h @@ -14,6 +14,10 @@ extern "C" { #include #include +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + #define M_DEG2RAD_MULT (0.01745329251f) #define M_RAD2DEG_MULT (57.2957795131f) @@ -43,6 +47,12 @@ extern "C" { _a < _b ? _a : _b; \ }) +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + + + /* 移动向量 */ typedef struct { float vx; /* 前后平移 */ @@ -50,6 +60,10 @@ typedef struct { float wz; /* 转动 */ } MoveVector_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + float InvSqrt(float x); float AbsClip(float in, float limit); @@ -159,3 +173,7 @@ float CalculateRpm(float bullet_speed, float fric_radius, bool is17mm); // * @param line 行号 // */ // void VerifyFailed(const char *file, uint32_t line); + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ \ No newline at end of file diff --git a/assets/User_code/device/bmi088.c b/assets/User_code/device/bmi088.c index 328f728..0f4c154 100644 --- a/assets/User_code/device/bmi088.c +++ b/assets/User_code/device/bmi088.c @@ -15,6 +15,11 @@ #include "bsp/spi.h" #include "component/user_math.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* Private define ----------------------------------------------------------- */ /* Private define ----------------------------------------------------------- */ #define BMI088_REG_ACCL_CHIP_ID (0x00) #define BMI088_REG_ACCL_ERR (0x02) @@ -79,6 +84,10 @@ typedef enum { BMI_GYRO, } BMI_Device_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ static uint8_t buffer[2]; static uint8_t bmi088_rxbuf[BMI088_LEN_RX_BUFF]; @@ -87,6 +96,10 @@ static osThreadId_t thread_alert; static bool inited = false; /* Private function -------------------------------------------------------- */ +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + static void BMI_WriteSingle(BMI_Device_t dv, uint8_t reg, uint8_t data) { buffer[0] = (reg & 0x7f); buffer[1] = data; diff --git a/assets/User_code/device/bmi088.h b/assets/User_code/device/bmi088.h index 0f33ccc..eb44e0c 100644 --- a/assets/User_code/device/bmi088.h +++ b/assets/User_code/device/bmi088.h @@ -11,6 +11,14 @@ extern "C" { #include "component/ahrs.h" #include "device/device.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Exported constants ------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */ /* Exported types ----------------------------------------------------------- */ @@ -32,6 +40,10 @@ typedef struct { const BMI088_Cali_t *cali; } BMI088_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Exported functions prototypes -------------------------------------------- */ int8_t BMI088_Init(BMI088_t *bmi088, const BMI088_Cali_t *cali); int8_t BMI088_Restart(void); @@ -60,6 +72,10 @@ int8_t BMI088_ParseAccl(BMI088_t *bmi088); int8_t BMI088_ParseGyro(BMI088_t *bmi088); float BMI088_GetUpdateFreq(BMI088_t *bmi088); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/device/buzzer.c b/assets/User_code/device/buzzer.c index 89f616b..013c1a8 100644 --- a/assets/User_code/device/buzzer.c +++ b/assets/User_code/device/buzzer.c @@ -1,5 +1,13 @@ #include "device/buzzer.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + int8_t BUZZER_Init(BUZZER_t *buzzer, BSP_PWM_Channel_t channel) { if (buzzer == NULL) return DEVICE_ERR; @@ -42,3 +50,7 @@ int8_t BUZZER_Set(BUZZER_t *buzzer, float freq, float duty_cycle) { return result; } + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ diff --git a/assets/User_code/device/buzzer.h b/assets/User_code/device/buzzer.h index 3939e23..f743dff 100644 --- a/assets/User_code/device/buzzer.h +++ b/assets/User_code/device/buzzer.h @@ -9,14 +9,26 @@ extern "C" { #include "bsp/pwm.h" #include +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Exported constants ------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Exported types ----------------------------------------------------------- */ typedef struct { DEVICE_Header_t header; BSP_PWM_Channel_t channel; } BUZZER_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Exported functions prototypes -------------------------------------------- */ int8_t BUZZER_Init(BUZZER_t *buzzer, BSP_PWM_Channel_t channel); @@ -30,6 +42,10 @@ int8_t BUZZER_Stop(BUZZER_t *buzzer); int8_t BUZZER_Set(BUZZER_t *buzzer, float freq, float duty_cycle); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/device/device.h b/assets/User_code/device/device.h index 79f1140..3fd8bf5 100644 --- a/assets/User_code/device/device.h +++ b/assets/User_code/device/device.h @@ -7,6 +7,14 @@ extern "C" { #include #include +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + #define DEVICE_OK (0) #define DEVICE_ERR (-1) #define DEVICE_ERR_NULL (-2) @@ -26,6 +34,14 @@ typedef struct { uint64_t last_online_time; } DEVICE_Header_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/device/dm_imu.c b/assets/User_code/device/dm_imu.c index 96c1feb..e05c1de 100644 --- a/assets/User_code/device/dm_imu.c +++ b/assets/User_code/device/dm_imu.c @@ -166,7 +166,7 @@ int8_t DM_IMU_Request(DM_IMU_t *imu, DM_IMU_RID_t rid) { .dlc = 4, }; memcpy(frame.data, tx_data, 4); - + BSP_CAN_WaitTxMailboxEmpty(imu->param.can, 1); // 等待发送邮箱空闲 int8_t result = BSP_CAN_TransmitStdDataFrame(imu->param.can, &frame); return (result == BSP_OK) ? DEVICE_OK : DEVICE_ERR; } diff --git a/assets/User_code/device/dr16.c b/assets/User_code/device/dr16.c index c2c8f95..d2a1c8d 100644 --- a/assets/User_code/device/dr16.c +++ b/assets/User_code/device/dr16.c @@ -9,11 +9,19 @@ #include "bsp/uart.h" #include "bsp/time.h" + +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ /* Private define ----------------------------------------------------------- */ #define DR16_CH_VALUE_MIN (364u) #define DR16_CH_VALUE_MID (1024u) #define DR16_CH_VALUE_MAX (1684u) +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ /* Private variables -------------------------------------------------------- */ @@ -83,3 +91,7 @@ bool DR16_WaitDmaCplt(uint32_t timeout) { return (osThreadFlagsWait(SIGNAL_DR16_RAW_REDY, osFlagsWaitAll, timeout) == SIGNAL_DR16_RAW_REDY); } + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ diff --git a/assets/User_code/device/dr16.h b/assets/User_code/device/dr16.h index 6972647..da21ebf 100644 --- a/assets/User_code/device/dr16.h +++ b/assets/User_code/device/dr16.h @@ -10,6 +10,14 @@ extern "C" { #include "component/user_math.h" #include "device/device.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Exported constants ------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */ /* Exported types ----------------------------------------------------------- */ @@ -41,6 +49,9 @@ int8_t DR16_Restart(void); int8_t DR16_StartDmaRecv(DR16_t *dr16); bool DR16_WaitDmaCplt(uint32_t timeout); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ #ifdef __cplusplus } diff --git a/assets/User_code/device/ist8310.c b/assets/User_code/device/ist8310.c index cb5ae18..fa98506 100644 --- a/assets/User_code/device/ist8310.c +++ b/assets/User_code/device/ist8310.c @@ -13,6 +13,10 @@ #include "bsp/gpio.h" #include "bsp/i2c.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ #define IST8310_WAI (0x00) #define IST8310_STAT1 (0x02) @@ -31,6 +35,11 @@ #define IST8310_IIC_ADDRESS (0x0E << 1) #define IST8310_LEN_RX_BUFF (6) + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ #define IST8310_SET() \ BSP_GPIO_WritePin(CMPS_RST_Pin, GPIO_PIN_SET) @@ -38,6 +47,10 @@ BSP_GPIO_WritePin(CMPS_RST_Pin, GPIO_PIN_RESET) /* Private typedef ---------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ uint8_t ist8310_rxbuf[IST8310_LEN_RX_BUFF]; @@ -45,6 +58,10 @@ static osThreadId_t thread_alert; static bool inited = false; /* Private function -------------------------------------------------------- */ +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + static void IST8310_WriteSingle(uint8_t reg, uint8_t data) { BSP_I2C_MemWriteByte(BSP_I2C_COMP, IST8310_IIC_ADDRESS, reg, data); } diff --git a/assets/User_code/device/led.c b/assets/User_code/device/led.c index 16b893b..f7fd317 100644 --- a/assets/User_code/device/led.c +++ b/assets/User_code/device/led.c @@ -6,9 +6,26 @@ #include "bsp/gpio.h" #include "bsp/pwm.h" #include "device.h" + +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + int8_t LED_PWMSet(BSP_PWM_Channel_t channel,float duty_cycle) { diff --git a/assets/User_code/device/motor.c b/assets/User_code/device/motor.c index ffea060..1fb059d 100644 --- a/assets/User_code/device/motor.c +++ b/assets/User_code/device/motor.c @@ -7,13 +7,28 @@ #include +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ /* Private function -------------------------------------------------------- */ +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ /* Exported functions ------------------------------------------------------- */ float MOTOR_GetRotorAbsAngle(const MOTOR_t *motor) { diff --git a/assets/User_code/device/motor.h b/assets/User_code/device/motor.h index 6dc6a85..e1f945b 100644 --- a/assets/User_code/device/motor.h +++ b/assets/User_code/device/motor.h @@ -7,6 +7,14 @@ extern "C" { /* Includes ----------------------------------------------------------------- */ #include "device/device.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Exported constants ------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */ /* Exported types ----------------------------------------------------------- */ @@ -41,12 +49,20 @@ typedef struct { MOTOR_Feedback_t feedback; } MOTOR_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Exported functions prototypes -------------------------------------------- */ float MOTOR_GetRotorAbsAngle(const MOTOR_t *motor); float MOTOR_GetRotorSpeed(const MOTOR_t *motor); float MOTOR_GetTorqueCurrent(const MOTOR_t *motor); float MOTOR_GetTemp(const MOTOR_t *motor); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } #endif diff --git a/assets/User_code/device/motor_lk.c b/assets/User_code/device/motor_lk.c index d145868..9b34703 100644 --- a/assets/User_code/device/motor_lk.c +++ b/assets/User_code/device/motor_lk.c @@ -10,6 +10,10 @@ #include "bsp/time.h" #include "component/user_math.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ #define LK_CTRL_ID_BASE (0x140) #define LK_FB_ID_BASE (0x240) @@ -36,12 +40,24 @@ #define LK_ENC_15BIT_MAX (32767) // 15位编码器最大值 #define LK_ENC_16BIT_MAX (65535) // 16位编码器最大值 +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ static MOTOR_LK_CANManager_t *can_managers[BSP_CAN_NUM] = {NULL}; /* Private functions -------------------------------------------------------- */ +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + static float MOTOR_LK_GetCurrentLSB(MOTOR_LK_Module_t module) { switch (module) { case MOTOR_LK_MF9025: @@ -239,7 +255,7 @@ int8_t MOTOR_LK_SetOutput(MOTOR_LK_Param_t *param, float value) { tx_frame.data[5] = (uint8_t)((torque_control >> 8) & 0xFF); // 转矩电流控制值高字节 tx_frame.data[6] = 0x00; // NULL tx_frame.data[7] = 0x00; // NULL - + BSP_CAN_WaitTxMailboxEmpty(param->can, 1); // 等待发送邮箱空闲 return BSP_CAN_TransmitStdDataFrame(param->can, &tx_frame) == BSP_OK ? DEVICE_OK : DEVICE_ERR; } @@ -265,7 +281,7 @@ int8_t MOTOR_LK_MotorOn(MOTOR_LK_Param_t *param) { tx_frame.data[5] = 0x00; tx_frame.data[6] = 0x00; tx_frame.data[7] = 0x00; - + BSP_CAN_WaitTxMailboxEmpty(param->can, 1); // 等待发送邮箱空闲 return BSP_CAN_TransmitStdDataFrame(param->can, &tx_frame) == BSP_OK ? DEVICE_OK : DEVICE_ERR; } @@ -285,7 +301,7 @@ int8_t MOTOR_LK_MotorOff(MOTOR_LK_Param_t *param) { tx_frame.data[5] = 0x00; tx_frame.data[6] = 0x00; tx_frame.data[7] = 0x00; - + BSP_CAN_WaitTxMailboxEmpty(param->can, 1); // 等待发送邮箱空闲 return BSP_CAN_TransmitStdDataFrame(param->can, &tx_frame) == BSP_OK ? DEVICE_OK : DEVICE_ERR; } diff --git a/assets/User_code/device/motor_lz.c b/assets/User_code/device/motor_lz.c index e9b6607..db00617 100644 --- a/assets/User_code/device/motor_lz.c +++ b/assets/User_code/device/motor_lz.c @@ -129,7 +129,8 @@ static int8_t MOTOR_LZ_SendExtFrame(BSP_CAN_t can, uint32_t ext_id, uint8_t *dat } else { memset(tx_frame.data, 0, dlc); } - + BSP_CAN_WaitTxMailboxEmpty(can, 1); // 等待发送邮箱空闲 + return BSP_CAN_TransmitExtDataFrame(can, &tx_frame) == BSP_OK ? DEVICE_OK : DEVICE_ERR; } diff --git a/assets/User_code/device/motor_rm.c b/assets/User_code/device/motor_rm.c index 49a867e..4c63810 100644 --- a/assets/User_code/device/motor_rm.c +++ b/assets/User_code/device/motor_rm.c @@ -10,6 +10,10 @@ #include "bsp/time.h" #include "component/user_math.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ #define GM6020_FB_ID_BASE (0x205) #define GM6020_CTRL_ID_BASE (0x1ff) @@ -30,11 +34,24 @@ #define MOTOR_ENC_RES (8192) /* 电机编码器分辨率 */ #define MOTOR_CUR_RES (16384) /* 电机转矩电流分辨率 */ +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ static MOTOR_RM_CANManager_t *can_managers[BSP_CAN_NUM] = {NULL}; +/* Private function -------------------------------------------------------- */ +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + static int8_t MOTOR_RM_GetLogicalIndex(uint16_t can_id, MOTOR_RM_Module_t module) { switch (module) { case MOTOR_M2006: @@ -223,6 +240,7 @@ int8_t MOTOR_RM_Ctrl(MOTOR_RM_Param_t *param) { default: return DEVICE_ERR; } + BSP_CAN_WaitTxMailboxEmpty(param->can, 1); // 等待发送邮箱空闲 return BSP_CAN_TransmitStdDataFrame(param->can, &tx_frame) == BSP_OK ? DEVICE_OK : DEVICE_ERR; } diff --git a/assets/User_code/device/servo.c b/assets/User_code/device/servo.c index 85cdcd7..7981bf7 100644 --- a/assets/User_code/device/servo.c +++ b/assets/User_code/device/servo.c @@ -1,5 +1,5 @@ /* - pwmƶ + pwm���ƶ�� */ /*Includes -----------------------------------------*/ @@ -7,9 +7,17 @@ #include "bsp/pwm.h" #include "servo.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + #define SERVO_MIN_DUTY 0.025f #define SERVO_MAX_DUTY 0.125f +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /** * @brief * @param @@ -24,10 +32,10 @@ int8_t SERVO_Init(SERVO_t *servo) { int8_t SERVO_SetAngle(SERVO_t *servo, float angle) { if (servo == NULL) return BSP_ERR; - /*ƽǶȷΧ*/ + /*���ƽǶȷ�Χ*/ if (angle < 0.0f) angle = 0.0f; if (angle > 180.0f) angle = 180.0f; - /*Ƕӳ䵽ռձ*/ + /*�Ƕ�ӳ�䵽ռ�ձ�*/ float duty = servo->min_duty + (angle / 180.0f) * (servo->max_duty - servo->min_duty); return BSP_PWM_Set(servo->pwm_ch, duty); diff --git a/assets/User_code/device/servo.h b/assets/User_code/device/servo.h index e59ac4e..ba8562d 100644 --- a/assets/User_code/device/servo.h +++ b/assets/User_code/device/servo.h @@ -8,6 +8,14 @@ extern "C" { #include #include "bsp/pwm.h" + +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ /* Exported constants ------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */ @@ -22,6 +30,10 @@ typedef struct { float max_duty; } SERVO_t; +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /** * @brief * @param servo @@ -46,6 +58,10 @@ int8_t SERVO_SetAngle(SERVO_t *servo, float angle); int8_t SERVO_Stop(SERVO_t *servo); +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + #ifdef __cplusplus } diff --git a/assets/User_code/device/vofa.c b/assets/User_code/device/vofa.c index 0cd4c82..8561042 100644 --- a/assets/User_code/device/vofa.c +++ b/assets/User_code/device/vofa.c @@ -3,18 +3,35 @@ #include #include "device/vofa.h" #include "bsp/uart.h" + +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ #define MAX_CHANNEL 64u // 根据实际最大通道数调整 #define JUSTFLOAT_TAIL 0x7F800000 + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ static uint8_t vofa_tx_buf[sizeof(float) * MAX_CHANNEL + sizeof(uint32_t)]; static VOFA_Protocol_t current_protocol = VOFA_PROTOCOL_FIREWATER; // 默认协议 /* Private function -------------------------------------------------------- */ +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ /************************ RawData *************************/ void VOFA_RawData_Send(const char* data, bool dma) { diff --git a/assets/User_code/device/ws2812.c b/assets/User_code/device/ws2812.c index 45747b9..101edcb 100644 --- a/assets/User_code/device/ws2812.c +++ b/assets/User_code/device/ws2812.c @@ -4,18 +4,36 @@ #include "bsp/pwm.h" #include + +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + /* Private define ----------------------------------------------------------- */ #define DEVICE_WS2812_T1H (uint16_t)(BSP_PWM_GetAutoReloadPreload(BSP_PWM_WS2812) * 0.56) // High-level width of logic-1 pulse #define DEVICE_WS2812_T0H (BSP_PWM_GetAutoReloadPreload(BSP_PWM_WS2812) * 0.29) // High-level width of logic-0 pulse #define DEVICE_WS2812_WS_REST 40 // Number of reset pulses (low level) after data stream #define DEVICE_WS2812_DATA_LEN 24 // WS2812 data length: 24 bits (GRB) per LED #define DEVICE_WS2812_RST_NUM 50 // Extra reset pulses reserved at the end of the buffer + +/* USER DEFINE BEGIN */ + +/* USER DEFINE END */ + /* Private macro ------------------------------------------------------------ */ /* Private typedef ---------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + /* Private variables -------------------------------------------------------- */ static uint16_t DEVICE_WS2812_LED_NUM; // Total number of LEDs static uint16_t *DEVICE_WS2812_RGB_Buff = NULL;// PWM duty buffer for DMA /* Private function -------------------------------------------------------- */ +/* USER FUNCTION BEGIN */ + +/* USER FUNCTION END */ + /* Exported functions ------------------------------------------------------- */ /** * Set color of a single WS2812 LED