Compare commits

..

No commits in common. "a66c9ae105ef3c434f10270037517c875bd1a903" and "a4455d0c6d31ef06f644f0feed554cd960a0618f" have entirely different histories.

5 changed files with 31 additions and 46 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -469,8 +469,6 @@ class MRobotApp:
# 生成 user_task.h 文件 # 生成 user_task.h 文件
# ...existing code... # ...existing code...
# ...existing code...
def generate_user_task_header(self): def generate_user_task_header(self):
try: try:
template_file_path = os.path.join(REPO_DIR, "User", "task", "user_task.h.template") template_file_path = os.path.join(REPO_DIR, "User", "task", "user_task.h.template")
@ -498,10 +496,10 @@ class MRobotApp:
template_content = f.read() template_content = f.read()
# 定义占位符内容 # 定义占位符内容
thread_definitions = "\n".join([f" osThreadId_t {task_var.get().lower()};" for task_var, _ in self.task_vars]) thread_definitions = "\n".join([f" osThreadId_t {task_var.get()};" for task_var, _ in self.task_vars])
msgq_definitions = existing_msgq_content if existing_msgq_content else " osMessageQueueId_t default_msgq;" msgq_definitions = existing_msgq_content if existing_msgq_content else " osMessageQueueId_t default_msgq;"
freq_definitions = "\n".join([f" float {task_var.get().lower()};" for task_var, _ in self.task_vars]) freq_definitions = "\n".join([f" float {task_var.get()};" for task_var, _ in self.task_vars])
last_up_time_definitions = "\n".join([f" uint32_t {task_var.get().lower()};" for task_var, _ in self.task_vars]) last_up_time_definitions = "\n".join([f" uint32_t {task_var.get()};" for task_var, _ in self.task_vars])
task_attr_declarations = "\n".join([f"extern const osThreadAttr_t attr_{task_var.get().lower()};" for task_var, _ in self.task_vars]) task_attr_declarations = "\n".join([f"extern const osThreadAttr_t attr_{task_var.get().lower()};" for task_var, _ in self.task_vars])
task_function_declarations = "\n".join([f"void {task_var.get()}(void *argument);" for task_var, _ in self.task_vars]) task_function_declarations = "\n".join([f"void {task_var.get()}(void *argument);" for task_var, _ in self.task_vars])
task_frequency_definitions = "\n".join([ task_frequency_definitions = "\n".join([
@ -509,7 +507,6 @@ class MRobotApp:
for task_var, freq_var in self.task_vars for task_var, freq_var in self.task_vars
]) ])
task_init_delay_definitions = "\n".join([f"#define TASK_INIT_DELAY_{task_var.get().upper()} (0u)" for task_var, _ in self.task_vars]) task_init_delay_definitions = "\n".join([f"#define TASK_INIT_DELAY_{task_var.get().upper()} (0u)" for task_var, _ in self.task_vars])
task_handle_definitions = "\n".join([f" osThreadId_t {task_var.get().lower()};" for task_var, _ in self.task_vars])
# 替换模板中的占位符 # 替换模板中的占位符
header_content = template_content.replace("{{thread_definitions}}", thread_definitions) header_content = template_content.replace("{{thread_definitions}}", thread_definitions)
@ -520,7 +517,6 @@ class MRobotApp:
header_content = header_content.replace("{{task_function_declarations}}", task_function_declarations) header_content = header_content.replace("{{task_function_declarations}}", task_function_declarations)
header_content = header_content.replace("{{task_frequency_definitions}}", task_frequency_definitions) header_content = header_content.replace("{{task_frequency_definitions}}", task_frequency_definitions)
header_content = header_content.replace("{{task_init_delay_definitions}}", task_init_delay_definitions) header_content = header_content.replace("{{task_init_delay_definitions}}", task_init_delay_definitions)
header_content = header_content.replace("{{task_handle_definitions}}", task_handle_definitions)
# 如果存在 /* USER MESSAGE BEGIN */ 区域内容,则保留 # 如果存在 /* USER MESSAGE BEGIN */ 区域内容,则保留
if existing_msgq_content: if existing_msgq_content:
@ -538,8 +534,6 @@ class MRobotApp:
except Exception as e: except Exception as e:
print(f"生成 user_task.h 文件时出错: {e}") print(f"生成 user_task.h 文件时出错: {e}")
# ...existing code...
def generate_init_file(self): def generate_init_file(self):
try: try:
@ -552,18 +546,6 @@ class MRobotApp:
os.makedirs(os.path.dirname(generated_file_path), exist_ok=True) os.makedirs(os.path.dirname(generated_file_path), exist_ok=True)
# 如果 init.c 已存在,提取 /* USER MESSAGE BEGIN */ 和 /* USER MESSAGE END */ 区域内容
existing_msgq_content = ""
if os.path.exists(generated_file_path):
with open(generated_file_path, "r", encoding="utf-8") as f:
content = f.read()
# 提取 /* USER MESSAGE BEGIN */ 和 /* USER MESSAGE END */ 区域内容
match = re.search(r"/\* USER MESSAGE BEGIN \*/\s*(.*?)\s*/\* USER MESSAGE END \*/", content, re.DOTALL)
if match:
existing_msgq_content = match.group(1).strip()
print("已存在的消息队列区域内容:")
print(existing_msgq_content)
with open(template_file_path, "r", encoding="utf-8") as f: with open(template_file_path, "r", encoding="utf-8") as f:
template_content = f.read() template_content = f.read()
@ -576,15 +558,6 @@ class MRobotApp:
# 替换模板中的占位符 # 替换模板中的占位符
init_content = template_content.replace("{{thread_creation_code}}", thread_creation_code) init_content = template_content.replace("{{thread_creation_code}}", thread_creation_code)
# 如果存在 /* USER MESSAGE BEGIN */ 区域内容,则保留
if existing_msgq_content:
init_content = re.sub(
r"/\* USER MESSAGE BEGIN \*/\s*.*?\s*/\* USER MESSAGE END \*/",
f"/* USER MESSAGE BEGIN */\n {existing_msgq_content}\n /* USER MESSAGE END */",
init_content,
flags=re.DOTALL
)
with open(generated_file_path, "w", encoding="utf-8") as f: with open(generated_file_path, "w", encoding="utf-8") as f:
f.write(init_content) f.write(init_content)
@ -592,8 +565,6 @@ class MRobotApp:
except Exception as e: except Exception as e:
print(f"生成 init.c 文件时出错: {e}") print(f"生成 init.c 文件时出错: {e}")
# 修改 generate_action 方法 # 修改 generate_action 方法
def generate_action(self): def generate_action(self):

View File

@ -11,8 +11,10 @@ static void (*I2C_Callback[BSP_I2C_NUM][BSP_I2C_CB_NUM])(void);
static BSP_I2C_t I2C_Get(I2C_HandleTypeDef *hi2c) { static BSP_I2C_t I2C_Get(I2C_HandleTypeDef *hi2c) {
if (hi2c->Instance == I2C1) if (hi2c->Instance == I2C1)
return BSP_I2C_EXAMPLE; return BSP_I2C_EXAMPLE;
// else if (hi2c->Instance == I2CX) /*
// return BSP_I2C_XXX; else if (hi2c->Instance == I2CX)
return BSP_I2C_XXX;
*/
else else
return BSP_I2C_ERR; return BSP_I2C_ERR;
} }
@ -94,8 +96,10 @@ I2C_HandleTypeDef *BSP_I2C_GetHandle(BSP_I2C_t i2c) {
switch (i2c) { switch (i2c) {
case BSP_I2C_EXAMPLE: case BSP_I2C_EXAMPLE:
return &hi2c1; return &hi2c1;
// case BSP_I2C_XXX: /*
// return &hi2cX; case BSP_I2C_XXX:
return &hi2cX;
*/
default: default:
return NULL; return NULL;
} }

View File

@ -1,3 +1,13 @@
/*
* @file oled_i2c.c
* @brief OLED I2C驱动程序
* @version 1.0
* @date 2023-10-01
* @note OLED显示屏的I2C通信和基本绘图功能
*/
*/
/* Includes ----------------------------------------------------------------- */ /* Includes ----------------------------------------------------------------- */
#include "device/oled_i2c.h" #include "device/oled_i2c.h"
#include "bsp/i2c.h" #include "bsp/i2c.h"

View File

@ -8,5 +8,5 @@ const osThreadAttr_t attr_init = {
.stack_size = 256 * 4, .stack_size = 256 * 4,
}; };
// USER TASK // 用户自定义任务
{{task_attr_definitions}} {{task_attr_definitions}}