mirror of
https://github.com/goldenfishs/MRobot.git
synced 2026-02-04 18:00:19 +08:00
修复bsp
This commit is contained in:
parent
f25f474ae8
commit
572c8b61d6
@ -235,7 +235,15 @@ class BspPeripheralBase(QWidget):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def _generate_source_file(self, configs, template_dir):
|
def _generate_source_file(self, configs, template_dir):
|
||||||
template_path = os.path.join(template_dir, self.template_names['source'])
|
# 从子文件夹加载模板(与_generate_header_file保持一致)
|
||||||
|
periph_folder = self.peripheral_name.lower()
|
||||||
|
template_base_dir = CodeGenerator.get_assets_dir("User_code/bsp")
|
||||||
|
template_path = os.path.join(template_base_dir, periph_folder, self.template_names['source'])
|
||||||
|
|
||||||
|
if not os.path.exists(template_path):
|
||||||
|
# 如果子文件夹不存在,尝试从根目录加载(向后兼容)
|
||||||
|
template_path = os.path.join(template_base_dir, self.template_names['source'])
|
||||||
|
|
||||||
template_content = CodeGenerator.load_template(template_path)
|
template_content = CodeGenerator.load_template(template_path)
|
||||||
if not template_content:
|
if not template_content:
|
||||||
return False
|
return False
|
||||||
@ -398,7 +406,15 @@ class bsp_can(BspPeripheralBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _generate_source_file(self, configs, template_dir):
|
def _generate_source_file(self, configs, template_dir):
|
||||||
template_path = os.path.join(template_dir, self.template_names['source'])
|
# 从子文件夹加载模板(与_generate_header_file保持一致)
|
||||||
|
periph_folder = self.peripheral_name.lower()
|
||||||
|
template_base_dir = CodeGenerator.get_assets_dir("User_code/bsp")
|
||||||
|
template_path = os.path.join(template_base_dir, periph_folder, self.template_names['source'])
|
||||||
|
|
||||||
|
if not os.path.exists(template_path):
|
||||||
|
# 如果子文件夹不存在,尝试从根目录加载(向后兼容)
|
||||||
|
template_path = os.path.join(template_base_dir, self.template_names['source'])
|
||||||
|
|
||||||
template_content = CodeGenerator.load_template(template_path)
|
template_content = CodeGenerator.load_template(template_path)
|
||||||
if not template_content:
|
if not template_content:
|
||||||
return False
|
return False
|
||||||
@ -1048,7 +1064,14 @@ class bsp_gpio(QWidget):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def _generate_header_file(self, configs, template_dir):
|
def _generate_header_file(self, configs, template_dir):
|
||||||
template_path = os.path.join(template_dir, "gpio.h")
|
# 从子文件夹加载模板
|
||||||
|
template_base_dir = CodeGenerator.get_assets_dir("User_code/bsp")
|
||||||
|
template_path = os.path.join(template_base_dir, "gpio", "gpio.h")
|
||||||
|
|
||||||
|
if not os.path.exists(template_path):
|
||||||
|
# 向后兼容:从根目录加载
|
||||||
|
template_path = os.path.join(template_base_dir, "gpio.h")
|
||||||
|
|
||||||
template_content = CodeGenerator.load_template(template_path)
|
template_content = CodeGenerator.load_template(template_path)
|
||||||
if not template_content:
|
if not template_content:
|
||||||
return False
|
return False
|
||||||
@ -1067,7 +1090,14 @@ class bsp_gpio(QWidget):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def _generate_source_file(self, configs, template_dir):
|
def _generate_source_file(self, configs, template_dir):
|
||||||
template_path = os.path.join(template_dir, "gpio.c")
|
# 从子文件夹加载模板
|
||||||
|
template_base_dir = CodeGenerator.get_assets_dir("User_code/bsp")
|
||||||
|
template_path = os.path.join(template_base_dir, "gpio", "gpio.c")
|
||||||
|
|
||||||
|
if not os.path.exists(template_path):
|
||||||
|
# 向后兼容:从根目录加载
|
||||||
|
template_path = os.path.join(template_base_dir, "gpio.c")
|
||||||
|
|
||||||
template_content = CodeGenerator.load_template(template_path)
|
template_content = CodeGenerator.load_template(template_path)
|
||||||
if not template_content:
|
if not template_content:
|
||||||
return False
|
return False
|
||||||
@ -1305,7 +1335,14 @@ class bsp_pwm(QWidget):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def _generate_header_file(self, configs, template_dir):
|
def _generate_header_file(self, configs, template_dir):
|
||||||
template_path = os.path.join(template_dir, "pwm.h")
|
# 从子文件夹加载模板
|
||||||
|
template_base_dir = CodeGenerator.get_assets_dir("User_code/bsp")
|
||||||
|
template_path = os.path.join(template_base_dir, "pwm", "pwm.h")
|
||||||
|
|
||||||
|
if not os.path.exists(template_path):
|
||||||
|
# 向后兼容:从根目录加载
|
||||||
|
template_path = os.path.join(template_base_dir, "pwm.h")
|
||||||
|
|
||||||
template_content = CodeGenerator.load_template(template_path)
|
template_content = CodeGenerator.load_template(template_path)
|
||||||
if not template_content:
|
if not template_content:
|
||||||
return False
|
return False
|
||||||
@ -1324,7 +1361,14 @@ class bsp_pwm(QWidget):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def _generate_source_file(self, configs, template_dir):
|
def _generate_source_file(self, configs, template_dir):
|
||||||
template_path = os.path.join(template_dir, "pwm.c")
|
# 从子文件夹加载模板
|
||||||
|
template_base_dir = CodeGenerator.get_assets_dir("User_code/bsp")
|
||||||
|
template_path = os.path.join(template_base_dir, "pwm", "pwm.c")
|
||||||
|
|
||||||
|
if not os.path.exists(template_path):
|
||||||
|
# 向后兼容:从根目录加载
|
||||||
|
template_path = os.path.join(template_base_dir, "pwm.c")
|
||||||
|
|
||||||
template_content = CodeGenerator.load_template(template_path)
|
template_content = CodeGenerator.load_template(template_path)
|
||||||
if not template_content:
|
if not template_content:
|
||||||
return False
|
return False
|
||||||
|
|||||||
@ -243,8 +243,13 @@ class DeviceSimple(QWidget):
|
|||||||
# 使用设备名称作为子文件夹名(小写)
|
# 使用设备名称作为子文件夹名(小写)
|
||||||
device_folder = self.device_name.lower()
|
device_folder = self.device_name.lower()
|
||||||
template_base_dir = CodeGenerator.get_assets_dir("User_code/device")
|
template_base_dir = CodeGenerator.get_assets_dir("User_code/device")
|
||||||
|
device_template_dir = os.path.join(template_base_dir, device_folder)
|
||||||
files = self.device_config.get('files', {})
|
files = self.device_config.get('files', {})
|
||||||
|
|
||||||
|
# 收集需要替换BSP配置的文件列表
|
||||||
|
files_to_process = list(files.values())
|
||||||
|
|
||||||
|
# 处理配置中定义的主要文件(需要BSP替换)
|
||||||
for file_type, filename in files.items():
|
for file_type, filename in files.items():
|
||||||
# 先尝试从子文件夹加载
|
# 先尝试从子文件夹加载
|
||||||
src_path = os.path.join(template_base_dir, device_folder, filename)
|
src_path = os.path.join(template_base_dir, device_folder, filename)
|
||||||
@ -273,6 +278,25 @@ class DeviceSimple(QWidget):
|
|||||||
with open(dst_path, 'w', encoding='utf-8') as f:
|
with open(dst_path, 'w', encoding='utf-8') as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
|
# 复制设备文件夹下的其他文件(如 lcd_lib.h)
|
||||||
|
if os.path.exists(device_template_dir):
|
||||||
|
import shutil
|
||||||
|
for item in os.listdir(device_template_dir):
|
||||||
|
# 跳过已处理的文件
|
||||||
|
if item in files_to_process:
|
||||||
|
continue
|
||||||
|
|
||||||
|
src_file = os.path.join(device_template_dir, item)
|
||||||
|
dst_file = os.path.join(self.project_path, f"User/device/{item}")
|
||||||
|
|
||||||
|
# 只复制文件,不复制子目录
|
||||||
|
if os.path.isfile(src_file):
|
||||||
|
# 检查文件是否已存在,避免覆盖
|
||||||
|
if not os.path.exists(dst_file):
|
||||||
|
os.makedirs(os.path.dirname(dst_file), exist_ok=True)
|
||||||
|
shutil.copy2(src_file, dst_file)
|
||||||
|
print(f"复制额外文件: {dst_file}")
|
||||||
|
|
||||||
self._save_config()
|
self._save_config()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ class ModulePage(QWidget):
|
|||||||
module_dir = CodeGenerator.get_assets_dir("User_code/module")
|
module_dir = CodeGenerator.get_assets_dir("User_code/module")
|
||||||
if subtype:
|
if subtype:
|
||||||
self.module_path = os.path.join(module_dir, module_type, subtype)
|
self.module_path = os.path.join(module_dir, module_type, subtype)
|
||||||
self.module_key = subtype
|
self.module_key = module_type # 使用类型名作为目标文件夹
|
||||||
else:
|
else:
|
||||||
self.module_path = os.path.join(module_dir, module_type)
|
self.module_path = os.path.join(module_dir, module_type)
|
||||||
self.module_key = module_type
|
self.module_key = module_type
|
||||||
@ -139,10 +139,7 @@ class ModulePage(QWidget):
|
|||||||
|
|
||||||
def _check_generated_status(self):
|
def _check_generated_status(self):
|
||||||
"""检查模块是否已生成"""
|
"""检查模块是否已生成"""
|
||||||
if self.subtype:
|
dst_dir = os.path.join(self.project_path, "User/module", self.module_key)
|
||||||
dst_dir = os.path.join(self.project_path, "User/module", self.module_type, self.subtype)
|
|
||||||
else:
|
|
||||||
dst_dir = os.path.join(self.project_path, "User/module", self.module_type)
|
|
||||||
|
|
||||||
if os.path.exists(dst_dir):
|
if os.path.exists(dst_dir):
|
||||||
has_code = any(
|
has_code = any(
|
||||||
@ -165,11 +162,8 @@ class ModulePage(QWidget):
|
|||||||
# 首先生成 config(如果不存在)
|
# 首先生成 config(如果不存在)
|
||||||
self._generate_config()
|
self._generate_config()
|
||||||
|
|
||||||
# 目标目录
|
# 目标目录:展平到 User/module/{module_key}
|
||||||
if self.subtype:
|
dst_dir = os.path.join(self.project_path, "User/module", self.module_key)
|
||||||
dst_dir = os.path.join(self.project_path, "User/module", self.module_type, self.subtype)
|
|
||||||
else:
|
|
||||||
dst_dir = os.path.join(self.project_path, "User/module", self.module_type)
|
|
||||||
|
|
||||||
# 检查是否已存在
|
# 检查是否已存在
|
||||||
if os.path.exists(dst_dir):
|
if os.path.exists(dst_dir):
|
||||||
|
|||||||
@ -240,6 +240,22 @@ devices:
|
|||||||
description: "lcd驱动(SPI)"
|
description: "lcd驱动(SPI)"
|
||||||
dependencies:
|
dependencies:
|
||||||
bsp: ["gpio", "spi"]
|
bsp: ["gpio", "spi"]
|
||||||
|
bsp_requirements:
|
||||||
|
- type: "spi"
|
||||||
|
var_name: "BSP_SPI_LCD"
|
||||||
|
description: "用于LCD通信的SPI总线"
|
||||||
|
- type: "gpio"
|
||||||
|
var_name: "BSP_GPIO_LCD_CS"
|
||||||
|
description: "LCD片选引脚"
|
||||||
|
gpio_type: "output"
|
||||||
|
- type: "gpio"
|
||||||
|
var_name: "BSP_GPIO_LCD_DC"
|
||||||
|
description: "LCD数据/命令控制引脚"
|
||||||
|
gpio_type: "output"
|
||||||
|
- type: "gpio"
|
||||||
|
var_name: "BSP_GPIO_LCD_RST"
|
||||||
|
description: "LCD复位引脚"
|
||||||
|
gpio_type: "output"
|
||||||
thread_signals: []
|
thread_signals: []
|
||||||
files:
|
files:
|
||||||
header: "lcd.h"
|
header: "lcd.h"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user