generate_v2_0_assets.py 119 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412
  1. #!/usr/bin/env python3
  2. """Generate board-viewer assets for FCB V2.0 (Mainboard) and FCB_FAN V2.0 (Fan Board).
  3. Extracts board-viewer data from the supplied Allegro 17.4 BRDs using record-pattern scans.
  4. Pin/net extraction is distinct from electrical path verification. Geometry is approximate;
  5. arcs, pad shapes and layer artwork are simplified. This is not a lossless CAD importer:
  6. - 0x1200 string table, 0x31/0x30 pin text records, 0x00020003 component value records
  7. - 0x1b net records, 0x04 net connection records, 0x1c padstack records
  8. - 0x2d placed symbol instances (exact x, y, rotation, side)
  9. - 0x07 component instances, 0x0d footprint pin definitions, 0x32 placed pin instances
  10. - 0xfd010014 board outline geometry, 0xf7090014/0xfc090014/0xf6090014 silkscreen outlines
  11. - 0x00060005/0x05060005 copper clines, 0x15/0x16/0x17/0x01 line/arc segments
  12. """
  13. from __future__ import annotations
  14. from collections import Counter, deque
  15. from collections.abc import Mapping
  16. from datetime import datetime, timezone
  17. import hashlib
  18. import json
  19. import math
  20. from pathlib import Path
  21. import re
  22. import struct
  23. import sys
  24. from typing import Any
  25. from jsonschema import Draft202012Validator
  26. VIEWER_DIR = Path(__file__).resolve().parent
  27. ROOT = VIEWER_DIR.parents[1]
  28. if str(VIEWER_DIR) not in sys.path:
  29. sys.path.insert(0, str(VIEWER_DIR))
  30. from board_viewer.annotations import expand_annotation_templates
  31. from board_viewer.data import (
  32. BOARD_DATA_SCHEMA_ID,
  33. _apply_connector_profile,
  34. _attach_related_resistors,
  35. _build_value_coverage,
  36. _merge_annotation,
  37. _merge_programming_annotation,
  38. _programming_guidance,
  39. _refresh_recommendation,
  40. _resistor_dict,
  41. _touchpoint_dict,
  42. _unique_strings,
  43. validate_resistor_index,
  44. )
  45. from board_viewer.pcb import (
  46. Footprint,
  47. Pad,
  48. ParsedBoard,
  49. _footprint_bounds,
  50. select_resistors,
  51. select_touchpoints,
  52. )
  53. DATA_SCHEMA_PATH = ROOT / "schemas" / "board_viewer_data.schema.json"
  54. BUILD_INFO_SCHEMA_PATH = ROOT / "schemas" / "board_viewer_build_info.schema.json"
  55. ANNOTATIONS_V12_PATH = ROOT / "config" / "board_viewer_annotations.fcb_fpga_mcu_v1_2.json"
  56. POWER_AND_GND_NETS = {
  57. "GND",
  58. "AGND",
  59. "PGND",
  60. "DGND",
  61. "+3.3V",
  62. "+3V3",
  63. "+5V",
  64. "+12V",
  65. "+24V",
  66. "+24V_VIN",
  67. "VBUS",
  68. "VCC",
  69. "VDD",
  70. }
  71. def sha256_file(path: Path | str) -> str:
  72. h = hashlib.sha256()
  73. with open(path, "rb") as f:
  74. while chunk := f.read(1024 * 1024):
  75. h.update(chunk)
  76. return h.hexdigest()
  77. def _generator_sources() -> dict[str, dict[str, str]]:
  78. paths = {"generator_v20": Path(__file__).resolve()}
  79. for name in ("annotations", "data", "eligibility", "pcb", "sexpr"):
  80. paths[f"generator_{name}"] = VIEWER_DIR / "board_viewer" / f"{name}.py"
  81. return {
  82. key: {"path": str(path.relative_to(ROOT)), "sha256": sha256_file(path)}
  83. for key, path in paths.items()
  84. }
  85. def _mark_inferred(value: Any) -> None:
  86. """A reused annotation or graph search does not constitute cross-verification."""
  87. if isinstance(value, dict):
  88. if "evidence_tier" in value:
  89. value["evidence_tier"] = "name_inferred"
  90. for child in value.values():
  91. _mark_inferred(child)
  92. elif isinstance(value, list):
  93. for child in value:
  94. _mark_inferred(child)
  95. def _pad_sort_key(pad: Pad) -> tuple[int, int, str]:
  96. num = pad.number.strip()
  97. if not num:
  98. return (2, 0, "")
  99. if num.isdigit():
  100. return (0, int(num), "")
  101. m = re.match(r"^([A-Za-z]+)(\d+)$", num)
  102. if m:
  103. return (1, int(m.group(2)), m.group(1))
  104. return (1, 0, num)
  105. # ---------------------------------------------------------------------------
  106. # Targeted Cadence Allegro 17.4 Binary .brd Extraction
  107. # ---------------------------------------------------------------------------
  108. def parse_allegro_brd(brd_path: Path) -> tuple[ParsedBoard, dict[str, Any]]:
  109. """Parse an Allegro 17.x binary .brd into ParsedBoard + CAD graphics metadata."""
  110. data = brd_path.read_bytes()
  111. u32 = struct.unpack(f"<{len(data) // 4}I", data[: len(data) // 4 * 4])
  112. i32 = struct.unpack(f"<{len(data) // 4}i", data[: len(data) // 4 * 4])
  113. # 1. String table at 0x1200
  114. pos = 0x1200
  115. strings: dict[int, str] = {}
  116. while pos < len(data) - 8:
  117. sid = struct.unpack_from("<I", data, pos)[0]
  118. if sid < 0x7C or sid > 50000:
  119. break
  120. end = data.find(b"\x00", pos + 4)
  121. if end == -1:
  122. break
  123. strings[sid] = data[pos + 4 : end].decode("latin1", errors="replace")
  124. pos = (end + 1 + 3) & ~3
  125. # 2. Text records (0x31 -> 0x30) for pin numbers
  126. t31: dict[int, str] = {}
  127. for idx in range(len(u32) - 8):
  128. if (u32[idx] & 0xFFFF) == 0x0031 and (u32[idx] >> 24) >= 0xF0:
  129. oid = u32[idx + 1]
  130. off = (idx + 7) * 4
  131. end = data.find(b"\x00", off)
  132. if end != -1 and end - off < 64:
  133. t31[oid] = data[off:end].decode("latin1", errors="replace")
  134. text30: dict[int, str] = {}
  135. for idx in range(len(u32) - 10):
  136. if (u32[idx] & 0xFFFF) == 0x0030:
  137. oid = u32[idx + 1]
  138. t31_id = u32[idx + 8]
  139. if t31_id in t31:
  140. text30[oid] = t31[t31_id]
  141. # 3. Device value property records (0x00020003)
  142. dev_val: dict[int, str] = {}
  143. for idx in range(len(u32) - 10):
  144. if u32[idx] == 0x00020003:
  145. dev_id = u32[idx + 3]
  146. off = (idx + 6) * 4
  147. end = data.find(b"\x00", off)
  148. if end != -1 and end - off < 120:
  149. val = data[off:end].decode("latin1", errors="replace").strip()
  150. if val:
  151. dev_val[dev_id] = val
  152. # 4. Nets (0x1b) and connection pointers (0x04)
  153. nets: dict[int, str] = {}
  154. for idx in range(len(u32) - 10):
  155. if u32[idx] == 0x1B:
  156. oid = u32[idx + 1]
  157. nsid = u32[idx + 3]
  158. if nsid in strings:
  159. nets[oid] = strings[nsid]
  160. conn04: dict[int, int] = {}
  161. for idx in range(len(u32) - 6):
  162. if (u32[idx] & 0xFF) == 0x04 and (u32[idx] & 0xFFFF00) in (0, 0x0900):
  163. conn04[u32[idx + 1]] = u32[idx + 2]
  164. # 5. Padstacks (0x1c) and Footprint Pin Definitions (0x0d)
  165. padstacks: dict[int, dict[str, Any]] = {}
  166. for idx in range(len(u32) - 24):
  167. if u32[idx] == 0x1C:
  168. psid = u32[idx + 1]
  169. nsid = u32[idx + 3]
  170. if nsid in strings:
  171. ptype = u32[idx + 11]
  172. drill_raw = i32[idx + 16] / 10000.0
  173. drill = max(0.0, drill_raw) if ptype != 1 and 0.0 < drill_raw <= 10.0 else 0.0
  174. padstacks[psid] = {
  175. "name": strings[nsid],
  176. "ptype": ptype,
  177. "drill": round(drill, 4),
  178. }
  179. pindefs: dict[int, int] = {}
  180. for idx in range(len(u32) - 8):
  181. if u32[idx] == 0x0D:
  182. pindefs[u32[idx + 1]] = u32[idx + 2]
  183. # 6. Placed Symbol Instances (0x2d / 0x1002d) and Component Instances (0x07)
  184. syms: dict[int, dict[str, Any]] = {}
  185. for idx in range(len(u32) - 10):
  186. if u32[idx] in (0x2D, 0x1002D) and u32[idx + 4] == 0 and u32[idx + 5] == 0:
  187. oid = u32[idx + 1]
  188. syms[oid] = {
  189. "fpid": u32[idx + 3],
  190. "side": "back" if (u32[idx] & 0x10000) else "front",
  191. "rot": round((u32[idx + 7] / 1000.0) % 360.0, 4),
  192. "x": round(i32[idx + 8] / 10000.0, 4),
  193. "y": round(i32[idx + 9] / 10000.0, 4),
  194. }
  195. sym_to_comp: dict[int, dict[str, str]] = {}
  196. for idx in range(len(u32) - 10):
  197. if u32[idx] == 0x07 and u32[idx + 4] == 0 and u32[idx + 5] == 0:
  198. dev_id = u32[idx + 3]
  199. sym_id = u32[idx + 6]
  200. ref_sid = u32[idx + 7]
  201. pkg_id = u32[idx + 8]
  202. if ref_sid in strings and sym_id in syms:
  203. pkg_name = strings.get(pkg_id, "")
  204. cval = dev_val.get(dev_id, "") or pkg_name
  205. sym_to_comp[sym_id] = {
  206. "ref": strings[ref_sid],
  207. "cval": cval,
  208. "pkg": pkg_name,
  209. }
  210. # 7. Placed Pin Instances (0x32)
  211. sym_pads: dict[int, list[Pad]] = {}
  212. comp_pins: dict[str, dict[str, str]] = {}
  213. net_to_pins: dict[str, list[tuple[str, str]]] = {}
  214. unassigned_holes: list[tuple[float, float, float]] = []
  215. for idx in range(len(u32) - 21):
  216. w0 = u32[idx]
  217. if (w0 & 0xFF00FF) in (0x0C0032, 0x0C0232):
  218. sym_id = u32[idx + 7]
  219. if sym_id not in syms:
  220. continue
  221. c04 = u32[idx + 3]
  222. pdid = u32[idx + 9]
  223. tid = u32[idx + 15]
  224. pnum = text30.get(tid, "").strip()
  225. net = nets.get(conn04.get(c04, 0), "")
  226. ps = padstacks.get(pindefs.get(pdid, 0), {"name": "", "ptype": 1, "drill": 0.0})
  227. bx1 = i32[idx + 17] / 10000.0
  228. by1 = i32[idx + 18] / 10000.0
  229. bx2 = i32[idx + 19] / 10000.0
  230. by2 = i32[idx + 20] / 10000.0
  231. if not (-50.0 <= bx1 <= 600.0 and -50.0 <= by1 <= 600.0):
  232. continue
  233. wx = round((bx1 + bx2) / 2.0, 4)
  234. wy = round((by1 + by2) / 2.0, 4)
  235. bw = round(max(abs(bx2 - bx1), ps["drill"], 0.24), 4)
  236. bh = round(max(abs(by2 - by1), ps["drill"], 0.24), 4)
  237. ptype = ps["ptype"]
  238. side = syms[sym_id]["side"]
  239. if sym_id not in sym_to_comp:
  240. if ptype == 0 or "MTG" in ps["name"].upper():
  241. unassigned_holes.append((wx, wy, max(ps["drill"], bw)))
  242. continue
  243. ref = sym_to_comp[sym_id]["ref"]
  244. comp_pins.setdefault(ref, {})[pnum] = net
  245. if net:
  246. net_to_pins.setdefault(net, []).append((ref, pnum))
  247. if ptype == 0 or not pnum:
  248. pad_type = "np_thru_hole"
  249. layers = ("*.Cu", "*.Mask")
  250. mech = True
  251. elif ptype == 1:
  252. pad_type = "smd"
  253. layers = ("F.Cu", "F.Mask", "F.Paste") if side == "front" else ("B.Cu", "B.Mask", "B.Paste")
  254. mech = False
  255. else:
  256. pad_type = "thru_hole"
  257. layers = ("*.Cu", "*.Mask")
  258. mech = False
  259. ps_upper = ps["name"].upper()
  260. if "CIR" in ps_upper or ptype == 0 or (abs(bw - bh) < 0.02 and "REC" not in ps_upper):
  261. shape = "circle"
  262. elif "SLOT" in ps_upper or "OB" in ps_upper:
  263. shape = "oval"
  264. else:
  265. shape = "rect"
  266. pad = Pad(
  267. number=pnum,
  268. pad_type=pad_type,
  269. shape=shape,
  270. x=wx,
  271. y=round(-wy, 4),
  272. width=bw,
  273. height=bh,
  274. rotation=0.0,
  275. net=net if net else None,
  276. layers=layers,
  277. drill_width=round(ps["drill"], 4),
  278. drill_height=round(ps["drill"], 4),
  279. mechanical=mech,
  280. electrical=not mech,
  281. )
  282. sym_pads.setdefault(sym_id, []).append(pad)
  283. footprints: list[Footprint] = []
  284. for sym_id, cinfo in sym_to_comp.items():
  285. s = syms[sym_id]
  286. pads = sorted(sym_pads.get(sym_id, []), key=_pad_sort_key)
  287. fx, fy = s["x"], round(-s["y"], 4)
  288. fp = Footprint(
  289. reference=cinfo["ref"],
  290. component_value=cinfo["cval"],
  291. x=fx,
  292. y=fy,
  293. rotation=s["rot"],
  294. side=s["side"],
  295. layer="B.Cu" if s["side"] == "back" else "F.Cu",
  296. pads=pads,
  297. bounds=_footprint_bounds(pads, fx, fy),
  298. )
  299. footprints.append(fp)
  300. # 8. Board Outline, Silkscreen Outlines, and Copper Clines
  301. outline_oids: set[int] = set()
  302. silk_front_oids: set[int] = set()
  303. silk_back_oids: set[int] = set()
  304. cline_front_oids: set[int] = set()
  305. cline_back_oids: set[int] = set()
  306. for idx in range(len(u32) - 8):
  307. w0 = u32[idx]
  308. oid = u32[idx + 1]
  309. if w0 == 0xFD010014:
  310. outline_oids.add(oid)
  311. elif w0 in (0xF7090014, 0xFC090014) and u32[idx + 3] in syms:
  312. silk_front_oids.add(oid)
  313. elif w0 == 0xF6090014 and u32[idx + 3] in syms:
  314. silk_back_oids.add(oid)
  315. elif w0 == 0x00060005:
  316. cline_front_oids.add(oid)
  317. elif w0 == 0x05060005:
  318. cline_back_oids.add(oid)
  319. ox: list[float] = []
  320. oy: list[float] = []
  321. silk_front_segs: list[tuple[float, float, float, float, float]] = []
  322. silk_back_segs: list[tuple[float, float, float, float, float]] = []
  323. cline_front_segs: list[tuple[float, float, float, float, float]] = []
  324. cline_back_segs: list[tuple[float, float, float, float, float]] = []
  325. for idx in range(len(u32) - 12):
  326. w0 = u32[idx]
  327. if w0 in (0x15, 0x16, 0x17, 0x01, 0x40000001, 0x80000001):
  328. parent = u32[idx + 3]
  329. if (
  330. parent not in outline_oids
  331. and parent not in silk_front_oids
  332. and parent not in silk_back_oids
  333. and parent not in cline_front_oids
  334. and parent not in cline_back_oids
  335. ):
  336. continue
  337. width = max(0.12, min(1.2, u32[idx + 6] / 10000.0))
  338. x1 = i32[idx + 7] / 10000.0
  339. y1 = i32[idx + 8] / 10000.0
  340. x2 = i32[idx + 9] / 10000.0
  341. y2 = i32[idx + 10] / 10000.0
  342. if not (-10.0 <= x1 <= 500.0 and -10.0 <= y1 <= 200.0 and -10.0 <= x2 <= 500.0 and -10.0 <= y2 <= 200.0):
  343. continue
  344. if abs(x1 - x2) < 1e-4 and abs(y1 - y2) < 1e-4:
  345. continue
  346. if parent in outline_oids:
  347. ox.extend([x1, x2])
  348. oy.extend([y1, y2])
  349. elif parent in silk_front_oids:
  350. silk_front_segs.append((x1, y1, x2, y2, width))
  351. elif parent in silk_back_oids:
  352. silk_back_segs.append((x1, y1, x2, y2, width))
  353. elif parent in cline_front_oids:
  354. cline_front_segs.append((x1, y1, x2, y2, width))
  355. elif parent in cline_back_oids:
  356. cline_back_segs.append((x1, y1, x2, y2, width))
  357. board_w = round(max(ox) - min(ox), 4) if ox else 430.0
  358. board_h = round(max(oy) - min(oy), 4) if oy else 60.0
  359. bounds = {"x": 0.0, "y": round(-board_h, 4), "width": board_w, "height": board_h}
  360. parsed_board = ParsedBoard(
  361. footprints=footprints,
  362. footprint_count=len(footprints),
  363. bounds=bounds,
  364. )
  365. cad_meta = {
  366. "comp_pins": comp_pins,
  367. "net_to_pins": net_to_pins,
  368. "silk_front_segs": silk_front_segs,
  369. "silk_back_segs": silk_back_segs,
  370. "cline_front_segs": cline_front_segs,
  371. "cline_back_segs": cline_back_segs,
  372. "unassigned_holes": unassigned_holes,
  373. }
  374. return parsed_board, cad_meta
  375. def trace_net_to_u3_u27(
  376. start_ref: str,
  377. start_pin: str,
  378. comp_pins: Mapping[str, Mapping[str, str]],
  379. net_to_pins: Mapping[str, list[tuple[str, str]]],
  380. ) -> tuple[str, tuple[str, str, str, list[str], list[str]] | None]:
  381. """Return a structural path candidate to U3/U27, not verified conduction.
  382. This search crosses component pins without checking fitted/NC options or
  383. transistor gate/source/drain behavior. Its result must remain name_inferred;
  384. it cannot prove a usable GPIO, polarity, voltage or populated signal path.
  385. """
  386. start_net = comp_pins.get(start_ref, {}).get(start_pin, "")
  387. if not start_net or start_net in POWER_AND_GND_NETS:
  388. return start_net, None
  389. queue: deque[tuple[str, list[str], list[str]]] = deque(
  390. [(start_net, [f"{start_ref}.{start_pin} ({start_net})"], [])]
  391. )
  392. visited_nets = {start_net}
  393. visited_comps = {start_ref}
  394. while queue:
  395. net, path, ext_comps = queue.popleft()
  396. for r, p in net_to_pins.get(net, []):
  397. if r == "U3":
  398. return start_net, ("U3", p, net, [*path, f"U3.{p} ({net})"], ext_comps)
  399. if r == "U27":
  400. return start_net, ("U27", p, net, [*path, f"U27.{p} ({net})"], ext_comps)
  401. if len(path) >= 6:
  402. continue
  403. for r, p in net_to_pins.get(net, []):
  404. if r in visited_comps or r.startswith(("C", "CON", "J", "TP", "PL", "U")):
  405. continue
  406. pins_of_r = comp_pins.get(r, {})
  407. if len(pins_of_r) <= 6:
  408. visited_comps.add(r)
  409. for p2, n2 in pins_of_r.items():
  410. if p2 != p and n2 and n2 not in POWER_AND_GND_NETS and n2 not in visited_nets:
  411. visited_nets.add(n2)
  412. new_ext = [*ext_comps, f"{r}.{p}->{p2}" if r.startswith("R") else r]
  413. queue.append((n2, [*path, f"{r}.{p}->{p2} ({n2})"], new_ext))
  414. return start_net, None
  415. # ---------------------------------------------------------------------------
  416. # Derived SVG Layer Renderer (simplified geometry)
  417. # ---------------------------------------------------------------------------
  418. def generate_svg_layers_from_brd(
  419. parsed_board: ParsedBoard,
  420. cad_meta: Mapping[str, Any],
  421. title: str,
  422. touchpoints: list[dict[str, Any]],
  423. out_dir: Path,
  424. ) -> None:
  425. """Render simplified SVG layers from parsed Allegro geometry; not a lossless CAD export."""
  426. out_dir.mkdir(parents=True, exist_ok=True)
  427. board_w = float(parsed_board.bounds["width"])
  428. board_h = float(parsed_board.bounds["height"])
  429. # Collect mounting holes (NPTH pads + unassigned MTG holes)
  430. mounting_holes: list[tuple[float, float, float]] = []
  431. for hx, hy, hd in cad_meta.get("unassigned_holes", []):
  432. mounting_holes.append((hx, board_h - hy, hd / 2.0))
  433. for fp in parsed_board.footprints:
  434. for pad in fp.pads:
  435. if pad.pad_type == "np_thru_hole" and pad.drill_width >= 1.0:
  436. mounting_holes.append((pad.x, board_h + pad.y, pad.drill_width / 2.0))
  437. # --- 1. MASK & EDGE ---
  438. def build_mask(side: str) -> str:
  439. bg_col = "#eef7f2"
  440. inner_stroke = "#cde7d8"
  441. border_stroke = "#64748b"
  442. lines = [
  443. '<?xml version="1.0" encoding="UTF-8"?>',
  444. f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {board_w:g} {board_h:g}" width="{board_w:g}mm" height="{board_h:g}mm">',
  445. f' <title>{title} - {"Front" if side == "front" else "Back"} Mask &amp; Edge</title>',
  446. f' <rect x="0" y="0" width="{board_w:g}" height="{board_h:g}" rx="2.0" fill="{bg_col}" stroke="{border_stroke}" stroke-width="0.35"/>',
  447. f' <rect x="0.8" y="0.8" width="{board_w - 1.6:g}" height="{board_h - 1.6:g}" rx="1.6" fill="none" stroke="{inner_stroke}" stroke-width="0.18"/>',
  448. " <!-- Soldermask Openings -->",
  449. ' <g fill="#fbbf24" stroke="#b45309" stroke-width="0.05">',
  450. ]
  451. for fp in parsed_board.footprints:
  452. for pad in fp.pads:
  453. if pad.pad_type == "np_thru_hole":
  454. continue
  455. is_th = "*.Mask" in pad.layers or pad.drill_width > 0
  456. if (side == "front" and ("F.Mask" in pad.layers or is_th)) or (
  457. side == "back" and ("B.Mask" in pad.layers or is_th)
  458. ):
  459. vx = pad.x
  460. vy = board_h + pad.y
  461. if side == "back":
  462. vx = board_w - vx
  463. pw = pad.width + 0.06
  464. ph = pad.height + 0.06
  465. if pad.shape == "circle":
  466. r = max(pw, ph) / 2.0
  467. lines.append(f' <circle cx="{vx:.3f}" cy="{vy:.3f}" r="{r:.3f}"/>')
  468. else:
  469. rx_attr = f' rx="{min(pw, ph)/2:.3f}"' if pad.shape == "oval" else ""
  470. lines.append(
  471. f' <rect x="{vx - pw/2:.3f}" y="{vy - ph/2:.3f}" width="{pw:.3f}" height="{ph:.3f}"{rx_attr}/>'
  472. )
  473. if pad.drill_width > 0:
  474. lines.append(
  475. f' <circle cx="{vx:.3f}" cy="{vy:.3f}" r="{pad.drill_width/2:.3f}" fill="#1e293b" stroke="none"/>'
  476. )
  477. for hx, hy, hr in mounting_holes:
  478. vx = board_w - hx if side == "back" else hx
  479. lines.append(
  480. f' <circle cx="{vx:.3f}" cy="{hy:.3f}" r="{hr + 0.45:.3f}" fill="#cbd5e1" stroke="#64748b" stroke-width="0.08"/>'
  481. )
  482. lines.append(f' <circle cx="{vx:.3f}" cy="{hy:.3f}" r="{hr:.3f}" fill="#1e293b" stroke="none"/>')
  483. lines.append(" </g>")
  484. lines.append("</svg>")
  485. return "\n".join(lines) + "\n"
  486. # --- 2. COPPER ---
  487. def build_copper(side: str) -> str:
  488. segs = cad_meta["cline_front_segs"] if side == "front" else cad_meta["cline_back_segs"]
  489. lines = [
  490. '<?xml version="1.0" encoding="UTF-8"?>',
  491. f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {board_w:g} {board_h:g}" width="{board_w:g}mm" height="{board_h:g}mm">',
  492. f' <title>{title} - {"Front" if side == "front" else "Back"} Copper</title>',
  493. ' <g id="copper-tracks" stroke="#529b7a" stroke-opacity="0.26" stroke-linecap="round" fill="none">',
  494. ]
  495. # Group segments by rounded width for compact SVG path output
  496. by_width: dict[float, list[str]] = {}
  497. for x1, y1, x2, y2, w in segs:
  498. vx1 = board_w - x1 if side == "back" else x1
  499. vy1 = board_h - y1
  500. vx2 = board_w - x2 if side == "back" else x2
  501. vy2 = board_h - y2
  502. rw = round(max(0.15, min(0.8, w)), 2)
  503. by_width.setdefault(rw, []).append(f"M{vx1:.2f} {vy1:.2f}L{vx2:.2f} {vy2:.2f}")
  504. for rw, d_parts in sorted(by_width.items()):
  505. for i in range(0, len(d_parts), 200):
  506. chunk = "".join(d_parts[i : i + 200])
  507. lines.append(f' <path stroke-width="{rw:.2f}" d="{chunk}"/>')
  508. lines.append(" </g>")
  509. lines.append(' <g id="pads" fill="#fbbf24" stroke="#b45309" stroke-width="0.05">')
  510. for fp in parsed_board.footprints:
  511. for pad in fp.pads:
  512. if pad.pad_type == "np_thru_hole":
  513. continue
  514. is_th = "*.Cu" in pad.layers or pad.drill_width > 0
  515. if (side == "front" and ("F.Cu" in pad.layers or is_th)) or (
  516. side == "back" and ("B.Cu" in pad.layers or is_th)
  517. ):
  518. vx = pad.x
  519. vy = board_h + pad.y
  520. if side == "back":
  521. vx = board_w - vx
  522. pw = pad.width
  523. ph = pad.height
  524. if pad.shape == "circle":
  525. r = max(pw, ph) / 2.0
  526. lines.append(f' <circle cx="{vx:.3f}" cy="{vy:.3f}" r="{r:.3f}"/>')
  527. else:
  528. rx_attr = f' rx="{min(pw, ph)/2:.3f}"' if pad.shape == "oval" else ""
  529. lines.append(
  530. f' <rect x="{vx - pw/2:.3f}" y="{vy - ph/2:.3f}" width="{pw:.3f}" height="{ph:.3f}"{rx_attr}/>'
  531. )
  532. if pad.drill_width > 0:
  533. lines.append(
  534. f' <circle cx="{vx:.3f}" cy="{vy:.3f}" r="{pad.drill_width/2:.3f}" fill="#1e293b" stroke="none"/>'
  535. )
  536. lines.append(" </g>")
  537. lines.append("</svg>")
  538. return "\n".join(lines) + "\n"
  539. # --- 3. SILKSCREEN ---
  540. def build_silkscreen(side: str) -> str:
  541. segs = cad_meta["silk_front_segs"] if side == "front" else cad_meta["silk_back_segs"]
  542. lines = [
  543. '<?xml version="1.0" encoding="UTF-8"?>',
  544. f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {board_w:g} {board_h:g}" width="{board_w:g}mm" height="{board_h:g}mm">',
  545. f' <title>{title} - {"Front" if side == "front" else "Back"} Silkscreen</title>',
  546. ' <g id="silkscreen-outlines" stroke="#0f172a" stroke-width="0.14" stroke-linecap="round" fill="none">',
  547. ]
  548. d_parts: list[str] = []
  549. for x1, y1, x2, y2, _w in segs:
  550. vx1 = board_w - x1 if side == "back" else x1
  551. vy1 = board_h - y1
  552. vx2 = board_w - x2 if side == "back" else x2
  553. vy2 = board_h - y2
  554. d_parts.append(f"M{vx1:.2f} {vy1:.2f}L{vx2:.2f} {vy2:.2f}")
  555. for i in range(0, len(d_parts), 200):
  556. chunk = "".join(d_parts[i : i + 200])
  557. lines.append(f' <path d="{chunk}"/>')
  558. lines.append(" </g>")
  559. lines.append(' <g id="silkscreen-labels" fill="#0f172a" font-family="monospace, sans-serif" font-weight="bold">')
  560. for tp in touchpoints:
  561. if tp.get("side", "front") != side:
  562. continue
  563. ref = str(tp["reference"])
  564. if ref.startswith("J") and len(tp.get("pins", [])) == 1 and tp["pins"][0].get("mechanical"):
  565. continue
  566. vb = tp["view_bounds"]
  567. bx = board_w - (vb["x"] + vb["width"]) if side == "back" else vb["x"]
  568. by = vb["y"]
  569. bw = vb["width"]
  570. bh = vb["height"]
  571. tx = bx + bw / 2.0
  572. ty = by - 0.35 if by > 2.2 else by + bh + 0.95
  573. lines.append(f' <text x="{tx:.2f}" y="{ty:.2f}" font-size="0.82" text-anchor="middle">{ref}</text>')
  574. for fp in parsed_board.footprints:
  575. if fp.side != side:
  576. continue
  577. if re.match(r"^(U|F)\d+$", fp.reference):
  578. vx = board_w - fp.x if side == "back" else fp.x
  579. vy = board_h + fp.y
  580. fsize = "1.15" if fp.reference in ("U3", "U27") else "0.72"
  581. lines.append(
  582. f' <text x="{vx:.2f}" y="{vy + 0.3:.2f}" font-size="{fsize}" text-anchor="middle">{fp.reference}</text>'
  583. )
  584. lines.append(" </g>")
  585. lines.append("</svg>")
  586. return "\n".join(lines) + "\n"
  587. (out_dir / "board-mask-edge.svg").write_text(build_mask("front"), encoding="utf-8")
  588. (out_dir / "board-mask-edge-back.svg").write_text(build_mask("back"), encoding="utf-8")
  589. (out_dir / "board-silkscreen.svg").write_text(build_silkscreen("front"), encoding="utf-8")
  590. (out_dir / "board-silkscreen-back.svg").write_text(build_silkscreen("back"), encoding="utf-8")
  591. (out_dir / "board-copper.svg").write_text(build_copper("front"), encoding="utf-8")
  592. (out_dir / "board-copper-back.svg").write_text(build_copper("back"), encoding="utf-8")
  593. # ---------------------------------------------------------------------------
  594. # Build V2.0 Mainboard Annotations & Connector Profiles
  595. # ---------------------------------------------------------------------------
  596. def _build_v20_annotations(
  597. parsed_board: ParsedBoard,
  598. cad_meta: Mapping[str, Any],
  599. pin_inv: Mapping[str, Any],
  600. ) -> dict[str, Any]:
  601. """Build complete V2.0 annotations combining V1.2 shared touchpoints + V2.0 pin inventory + BRD net trace."""
  602. v12_raw = json.loads(ANNOTATIONS_V12_PATH.read_text(encoding="utf-8"))
  603. v12_expanded = expand_annotation_templates(v12_raw)
  604. v12_tps = v12_expanded.get("touchpoints", {})
  605. comp_pins = cad_meta["comp_pins"]
  606. net_to_pins = cad_meta["net_to_pins"]
  607. connector_profiles = {
  608. "CON_11251W00_NPX_SX_4P": {
  609. "references": [
  610. "CON12",
  611. "CON54",
  612. "CON70",
  613. "CON77",
  614. "CON103",
  615. "CON126",
  616. "CON134",
  617. "CON144",
  618. "CON145",
  619. "CON146",
  620. "CON164",
  621. "CON171",
  622. ],
  623. "contact_pins": ["1", "2", "3", "4"],
  624. "shield_pads": ["5", "6"],
  625. "evidence_tier": "cross_verified",
  626. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  627. },
  628. "CON_51541_00301_V01_3P": {
  629. "references": ["CON53", "CON55", "CON56", "CON57", "CON79", "CON80", "CON81", "CON82"],
  630. "contact_pins": ["1", "2", "3"],
  631. "shield_pads": ["4", "5"],
  632. "evidence_tier": "cross_verified",
  633. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  634. },
  635. "CON_3110_20P_P2D54": {
  636. "references": ["CON147", "CON148", "CON149", "CON150"],
  637. "contact_pins": [str(i) for i in range(1, 21)],
  638. "shield_pads": [],
  639. "evidence_tier": "cross_verified",
  640. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  641. },
  642. "CON_SMD_2D54_2X7P": {
  643. "references": [
  644. "CON154",
  645. "CON155",
  646. "CON156",
  647. "CON157",
  648. "CON158",
  649. "CON159",
  650. "CON160",
  651. "CON161",
  652. "CON162",
  653. "CON163",
  654. "CON165",
  655. "CON166",
  656. ],
  657. "contact_pins": [str(i) for i in range(1, 15)],
  658. "shield_pads": ["15", "16"],
  659. "evidence_tier": "cross_verified",
  660. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  661. },
  662. "HDR_1X4P_P2D54": {
  663. "references": ["CON168"],
  664. "contact_pins": ["1", "2", "3", "4"],
  665. "shield_pads": [],
  666. "evidence_tier": "cross_verified",
  667. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  668. },
  669. "RJ45_RJHSE538X_12P": {
  670. "references": ["CON170"],
  671. "contact_pins": [str(i) for i in range(1, 13)],
  672. "shield_pads": ["13", "14"],
  673. "evidence_tier": "cross_verified",
  674. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  675. },
  676. "USBC_16P_U263": {
  677. "references": ["CON172"],
  678. "contact_pins": [
  679. "A1",
  680. "A4",
  681. "A5",
  682. "A6",
  683. "A7",
  684. "A9",
  685. "A12",
  686. "B1",
  687. "B4",
  688. "B5",
  689. "B6",
  690. "B7",
  691. "B9",
  692. "B12",
  693. ],
  694. "shield_pads": ["1", "2", "3", "4"],
  695. "evidence_tier": "cross_verified",
  696. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  697. },
  698. "CON_3110_12P_P4D2": {
  699. "references": ["CON173", "CON174"],
  700. "contact_pins": [str(i) for i in range(1, 13)],
  701. "shield_pads": [],
  702. "evidence_tier": "cross_verified",
  703. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  704. },
  705. "J3_FPGA_JTAG_2X5": v12_expanded["connector_profiles"]["J3_FPGA_JTAG_2X5"],
  706. "J19_FPGA_BANK1_DEBUG_1X5": v12_expanded["connector_profiles"]["J19_FPGA_BANK1_DEBUG_1X5"],
  707. "J25_GD32_SWD_1X5": v12_expanded["connector_profiles"]["J25_GD32_SWD_1X5"],
  708. "J_GD32_HEADER_2X5": {
  709. "references": ["J29", "J30"],
  710. "contact_pins": [str(i) for i in range(1, 11)],
  711. "shield_pads": [],
  712. "evidence_tier": "cross_verified",
  713. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  714. },
  715. }
  716. # Copy shared touchpoints from V1.2 annotations and adapt to V2.0
  717. touchpoint_anns: dict[str, Any] = {}
  718. v2_tp_refs = {fp.reference for fp in select_touchpoints(parsed_board)}
  719. for ref in v2_tp_refs:
  720. if ref in v12_tps:
  721. touchpoint_anns[ref] = json.loads(json.dumps(v12_tps[ref]))
  722. _mark_inferred(touchpoint_anns[ref])
  723. touchpoint_anns[ref]["summary"] = (
  724. "V1.2 参考注释,V2.0 未逐项复核:" + touchpoint_anns[ref].get("summary", ref)
  725. )
  726. # Fix V2.0-specific differences on shared touchpoints:
  727. # 1. CON12 is 6400 V2.0 Host TTL (R1875/R1876 instead of V1.2 R1307/R1308)
  728. touchpoint_anns["CON12"] = {
  729. "summary": "6400 V2.0 Host TTL 串口座(Pin 3 TX → R1875 → U3.K2 host_ttl_tx,Pin 4 RX ← R1876 ← U3.J4 host_ttl_rx,对接 STM32H7 P1.26/P1.25)",
  730. "pins": {
  731. "1": {
  732. "summary": "CON12.1 +3.3V 板内电源参考(跨板连接不并接)",
  733. "direction": "passive",
  734. "external_level": "+3.3V",
  735. "function_category": "power",
  736. "reserved": True,
  737. "path": ["CON12.1 +3.3V"],
  738. "evidence_tier": "cross_verified",
  739. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  740. },
  741. "2": {
  742. "summary": "CON12.2 GND 串口信号共地(接 STM32H7 P1.19 GND)",
  743. "direction": "passive",
  744. "external_level": "0V",
  745. "function_category": "ground",
  746. "path": ["CON12.2 GND"],
  747. "evidence_tier": "cross_verified",
  748. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  749. },
  750. "3": {
  751. "summary": "CON12.3 (EX_GPIO1) Host TTL TX → R1875 → FPGA U3.K2 (host_ttl_tx) ↔ STM32H7 P1.26 (PB11)",
  752. "direction": "output",
  753. "external_level": "3.3V LVCMOS",
  754. "function_category": "uart_tx",
  755. "external_components": ["R1875", "STM32H7 P1.26 (PB11)"],
  756. "path": ["CON12.3 (EX_GPIO1)", "R1875.2->1 (CPLD_GPIO79)", "U3.K2 (host_ttl_tx)"],
  757. "evidence_tier": "cross_verified",
  758. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  759. "fpga": {
  760. "ball": "K2",
  761. "board_signal": "EX_GPIO1",
  762. "io_standard": "LVCMOS33",
  763. "capabilities": ["uart_tx", "gpio_output", "gpio"],
  764. "evidence_tier": "cross_verified",
  765. "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  766. },
  767. },
  768. "4": {
  769. "summary": "CON12.4 (EX_GPIO2) Host TTL RX ← R1876 ← FPGA U3.J4 (host_ttl_rx) ↔ STM32H7 P1.25 (PB10)",
  770. "direction": "input",
  771. "external_level": "3.3V LVCMOS",
  772. "function_category": "uart_rx",
  773. "external_components": ["R1876", "STM32H7 P1.25 (PB10)"],
  774. "path": ["CON12.4 (EX_GPIO2)", "R1876.2->1 (CPLD_GPIO80)", "U3.J4 (host_ttl_rx)"],
  775. "evidence_tier": "cross_verified",
  776. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  777. "fpga": {
  778. "ball": "J4",
  779. "board_signal": "EX_GPIO2",
  780. "io_standard": "LVCMOS33",
  781. "capabilities": ["uart_rx", "gpio_input", "gpio"],
  782. "evidence_tier": "cross_verified",
  783. "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  784. },
  785. },
  786. },
  787. }
  788. # 2. CON54 in V2.0 has R572/R574 removed (uses R573/R747 and R575/R748)
  789. if "CON54" in touchpoint_anns:
  790. for pnum, r_list in (("1", ["R573", "R747"]), ("2", ["R575", "R748"])):
  791. p_ann = touchpoint_anns["CON54"].get("pins", {}).get(pnum, {})
  792. p_ann["external_components"] = r_list
  793. p_ann["path"] = [
  794. f"CON54.{pnum}",
  795. f"{r_list[0]}",
  796. f"{r_list[1]}",
  797. f"U3.{'A9' if pnum == '1' else 'C9'}",
  798. ]
  799. # These V2.0 LED outputs use HL2309 and fitted +24V selection resistors.
  800. # Replace the inherited V1.2 pin annotation (12V/AO3415A) as one object.
  801. for ref, number, ball, series, gate, nmos, pmos, supply, option in (
  802. ("CON144", 1, "G6", "R1299", "R1274", "Q10617", "Q10616", "R1281", "R1282"),
  803. ("CON145", 2, "F5", "R1300", "R1290", "Q10619", "Q10618", "R1287", "R1288"),
  804. ):
  805. touchpoint_anns[ref]["summary"] = (
  806. f"V2.0 LED/按键连接器{number}:Pin1为24V KEYLED功率输出,由U3.{ball}控制;"
  807. "Pin3为按键输入,Pin2/4为GND;Host TTL使用CON12。"
  808. )
  809. touchpoint_anns[ref]["pins"]["1"] = {
  810. "summary": f"U3.{ball}经{series}/{gate}、{nmos} 2N7002和{pmos} HL2309控制KEYLED_V{number};{supply}已装接+24V,{option}的+5V选项未装。不是TTL。",
  811. "direction": "output", "external_level": "+24V switched power",
  812. "function_category": "power", "reserved": True,
  813. "fixed_load_conflict": True, "evidence_tier": "cross_verified",
  814. "fpga": None,
  815. "path": [f"U3.{ball}", series, gate, nmos, pmos, f"{ref}.1 (KEYLED_V{number})"],
  816. "external_components": [series, gate, nmos, pmos, supply, option],
  817. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "evidence/hardware/20261023/main_bom.csv", "evidence/hardware/20261023/main_pins.csv"],
  818. }
  819. # V2.0 R1294 is fitted to +24V; V1.2 uses +12V at the same reference.
  820. # V3.0 schematic & v3.2.0 RTL bind CON146.1/2 to the MCU-triggered +24V buzzer
  821. # (4000 Hz, 80% duty square wave on U3.H6; NOT a TTL UART).
  822. touchpoint_anns["CON146"] = {
  823. "summary": "蜂鸣器 +24V 高边驱动座(电气图 V3.0:Pin1 KEYLED_V3 +24V 蜂鸣器正端 ← U3.H6 经 R1301/R1297/Q10621/Q10620 驱动,开启时 4000Hz 80% 占空比方波;Pin2 GND 蜂鸣器负端;SET_ALL 字节35 / GET_DATA 字节89;非 TTL)",
  824. "pins": {
  825. "1": {
  826. "summary": "CON146.1 (KEYLED_V3, +24V 高边蜂鸣器输出) ← Q10620(HL2309, R1294装+24V/R1295 NC) ← Q10621(2N7002) ← R1297(220Ω) ← SW_KEYLED3 ← R1301(0Ω) ← FPGA U3.H6 (buzzer_out:开启 4000Hz 80% 占空比方波 6250拍周期/5000高/1250低;关闭/复位/看门狗保持低电平;非 TTL)",
  827. "direction": "output", "external_level": "+24V high-side buzzer (4000Hz 80% duty)",
  828. "function_category": "pwm", "active_level": "high", "polarity": "normal",
  829. "reserved": True, "fixed_load_conflict": True, "evidence_tier": "cross_verified",
  830. "path": ["U3.H6 (buzzer_out)", "R1301 (0R)", "SW_KEYLED3", "R1297 (220R)", "Q10621 (2N7002)", "Q10620 (HL2309 +24V)", "CON146.1 (KEYLED_V3)"],
  831. "external_components": ["R1301", "R1297", "Q10621", "Q10620", "R1294", "R1295"],
  832. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V3.0.pdf", "constraints/prod2u_6400_v2.adc"],
  833. "fpga": {
  834. "ball": "H6",
  835. "board_signal": "SW_KEYLED3",
  836. "io_standard": "LVCMOS33",
  837. "capabilities": ["pwm", "gpio_output"],
  838. "evidence_tier": "cross_verified",
  839. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V3.0.pdf", "constraints/prod2u_6400_v2.adc"],
  840. },
  841. },
  842. "3": {
  843. "summary": "CON146.3 KEY3_CON 经 R1293/R1110 接 U3.N7;按键输入网络带 RC,当前固件未绑定,不作为 Host TTL。",
  844. "direction": "input", "external_level": "3.3V key input with RC",
  845. "function_category": "gpio_input", "reserved": True,
  846. "evidence_tier": "cross_verified",
  847. "path": ["CON146.3 (KEY3_CON)", "R1293", "R1110", "U3.N7"],
  848. "external_components": ["R1293", "R1110"],
  849. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  850. },
  851. "2": {
  852. "summary": "CON146.2 GND(蜂鸣器负极回路地)",
  853. "direction": "passive", "external_level": "0V", "function_category": "ground",
  854. "path": ["CON146.2 (GND)"], "evidence_tier": "cross_verified",
  855. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V3.0.pdf"],
  856. },
  857. "4": {
  858. "summary": "CON146.4 GND",
  859. "direction": "passive", "external_level": "0V", "function_category": "ground",
  860. "path": ["CON146.4 (GND)"], "evidence_tier": "cross_verified",
  861. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  862. },
  863. },
  864. }
  865. # 3b. CON134 is 6400 V2.0 active Host RS-232 (Pin 1 TX -> U22 -> R1225 -> U3.T14, Pin 2 RX <- U22 <- R1226 <- U3.R13)
  866. touchpoint_anns["CON134"] = {
  867. "summary": "6400 V2.0 Host RS-232 串口座(Pin 1 RS232_TX3 → U22 → R1225 → U3.T14 host_rs232_tx,Pin 2 RS232_RX3 ← U22 ← R1226 ← U3.R13 host_rs232_rx,Pin 3/4 GND)",
  868. "pins": {
  869. "1": {
  870. "summary": "CON134.1 (RS232_TX3) → TRSF3232EIPWR U22.7/10 → R1225 → FPGA U3.T14 (host_rs232_tx)",
  871. "direction": "output",
  872. "external_level": "RS232",
  873. "function_category": "uart_tx",
  874. "external_components": ["U22", "R1225"],
  875. "path": ["CON134.1 (RS232_TX3)", "U22.7->10 (UART3_TX)", "R1225.2->1 (BANK2_LVDS8_N)", "U3.T14 (host_rs232_tx)"],
  876. "evidence_tier": "cross_verified",
  877. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  878. "fpga": {
  879. "ball": "T14",
  880. "board_signal": "RS232_TX3",
  881. "io_standard": "LVCMOS33",
  882. "capabilities": ["uart_tx", "rs232_via_transceiver"],
  883. "evidence_tier": "cross_verified",
  884. "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  885. },
  886. },
  887. "2": {
  888. "summary": "CON134.2 (RS232_RX3) ← TRSF3232EIPWR U22.8/9 ← R1226 ← FPGA U3.R13 (host_rs232_rx)",
  889. "direction": "input",
  890. "external_level": "RS232",
  891. "function_category": "uart_rx",
  892. "external_components": ["U22", "R1226"],
  893. "path": ["CON134.2 (RS232_RX3)", "U22.8->9 (UART3_RX)", "R1226.2->1 (BANK2_LVDS8_P)", "U3.R13 (host_rs232_rx)"],
  894. "evidence_tier": "cross_verified",
  895. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  896. "fpga": {
  897. "ball": "R13",
  898. "board_signal": "RS232_RX3",
  899. "io_standard": "LVCMOS33",
  900. "capabilities": ["uart_rx", "rs232_via_transceiver"],
  901. "evidence_tier": "cross_verified",
  902. "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  903. },
  904. },
  905. "3": {
  906. "summary": "CON134.3 GND 串口地",
  907. "direction": "passive",
  908. "external_level": "0V",
  909. "function_category": "ground",
  910. "path": ["CON134.3 (GND)"],
  911. "evidence_tier": "cross_verified",
  912. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  913. },
  914. "4": {
  915. "summary": "CON134.4 GND 串口地",
  916. "direction": "passive",
  917. "external_level": "0V",
  918. "function_category": "ground",
  919. "path": ["CON134.4 (GND)"],
  920. "evidence_tier": "cross_verified",
  921. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  922. },
  923. },
  924. }
  925. # 3c. CON77 is BMC RS-232 (Pin 1 TX -> U22 -> R818 -> U3.L10, Pin 2 RX <- U22 <- R819 <- U3.M9)
  926. touchpoint_anns["CON77"] = {
  927. "summary": "BMC 测温轮询 RS-232 串口座(Pin 1 RS232_TX1 → U22 → R818 → U3.L10 bmc_tx,Pin 2 RS232_RX1 ← U22 ← R819 ← U3.M9 bmc_rx,Pin 3/4 GND)",
  928. "pins": {
  929. "1": {
  930. "summary": "CON77.1 (RS232_TX1) → TRSF3232EIPWR U22.14/11 → R818 → FPGA U3.L10 (bmc_tx, 115200 8N1)",
  931. "direction": "output",
  932. "external_level": "RS232",
  933. "function_category": "uart_tx",
  934. "external_components": ["U22", "R818"],
  935. "path": ["CON77.1 (RS232_TX1)", "U22.14->11 (UART1_TX)", "R818.2->1 (BANK2_GPIO52)", "U3.L10 (bmc_tx)"],
  936. "evidence_tier": "cross_verified",
  937. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  938. "fpga": {
  939. "ball": "L10",
  940. "board_signal": "RS232_TX1",
  941. "io_standard": "LVCMOS33",
  942. "capabilities": ["uart_tx", "rs232_via_transceiver"],
  943. "evidence_tier": "cross_verified",
  944. "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  945. },
  946. },
  947. "2": {
  948. "summary": "CON77.2 (RS232_RX1) ← TRSF3232EIPWR U22.13/12 ← R819 ← FPGA U3.M9 (bmc_rx, 115200 8N1)",
  949. "direction": "input",
  950. "external_level": "RS232",
  951. "function_category": "uart_rx",
  952. "external_components": ["U22", "R819"],
  953. "path": ["CON77.2 (RS232_RX1)", "U22.13->12 (UART1_RX)", "R819.2->1 (BANK2_GPIO53)", "U3.M9 (bmc_rx)"],
  954. "evidence_tier": "cross_verified",
  955. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  956. "fpga": {
  957. "ball": "M9",
  958. "board_signal": "RS232_RX1",
  959. "io_standard": "LVCMOS33",
  960. "capabilities": ["uart_rx", "rs232_via_transceiver"],
  961. "evidence_tier": "cross_verified",
  962. "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  963. },
  964. },
  965. "3": {
  966. "summary": "CON77.3 GND 串口地",
  967. "direction": "passive",
  968. "external_level": "0V",
  969. "function_category": "ground",
  970. "path": ["CON77.3 (GND)"],
  971. "evidence_tier": "cross_verified",
  972. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  973. },
  974. "4": {
  975. "summary": "CON77.4 GND 串口地",
  976. "direction": "passive",
  977. "external_level": "0V",
  978. "function_category": "ground",
  979. "path": ["CON77.4 (GND)"],
  980. "evidence_tier": "cross_verified",
  981. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  982. },
  983. },
  984. }
  985. # 3d. CON103 on V2.0: schematic Page 4/9 labels "-CON103 MCU串口连接器" wired to -U6-2 TX1/RX1,
  986. # while PCB routes CON103.1/2 to onboard STM32 U27.12/13 (PA2/PA3) & CP2102 U33 (not FPGA U3; CON12 routes to FPGA U3.K2/J4).
  987. touchpoint_anns["CON103"] = {
  988. "summary": "板载 STM32 MCU 串口连接器(电气图第4/9页标为 -CON103 MCU串口连接器 对接 -U6-2 TX1/RX1;PCB 网表 Pin 1/2 接板载 STM32 U27.12/13 PA2/PA3 与 CP2102 U33,直通 FPGA U3.K2/J4 的 TTL 口为紧邻的 CON12)",
  989. "pins": {
  990. "1": {
  991. "summary": "CON103.1 (MCU_UART1_TX_CON) → R1029 → 板载 STM32 U27.12 (PA2/MCU_UART1_TX) & R1921 → CP2102 U33(电气图第4/9页标为 TX1 接 -U6-2 P1.26 RX1)",
  992. "direction": "bidirectional",
  993. "external_level": "3.3V LVCMOS",
  994. "function_category": "mcu_gpio",
  995. "reserved": True,
  996. "fixed_load_conflict": False,
  997. "external_components": ["R1029", "R1921", "U33"],
  998. "path": ["CON103.1 (MCU_UART1_TX_CON)", "R1029.2->1 (MCU_UART1_TX)", "U27.12 (PA2)", "R1921 -> CP2102 U33"],
  999. "evidence_tier": "cross_verified",
  1000. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  1001. "mcu": {
  1002. "device": "U27",
  1003. "family": "STM32F103CBT6",
  1004. "pin": "12",
  1005. "signal": "PA2/MCU_UART1_TX",
  1006. "capabilities": ["gpio", "firmware_configurable", "mcu_uart_tx"],
  1007. "evidence_tier": "cross_verified",
  1008. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1009. },
  1010. },
  1011. "2": {
  1012. "summary": "CON103.2 (MCU_UART1_RX_CON) ← R1030 ← 板载 STM32 U27.13 (PA3/MCU_UART1_RX) & R1920 ← CP2102 U33(电气图第4/9页标为 RX1 接 -U6-2 P1.25 TX1)",
  1013. "direction": "bidirectional",
  1014. "external_level": "3.3V LVCMOS",
  1015. "function_category": "mcu_gpio",
  1016. "reserved": True,
  1017. "fixed_load_conflict": False,
  1018. "external_components": ["R1030", "R1920", "U33"],
  1019. "path": ["CON103.2 (MCU_UART1_RX_CON)", "R1030.2->1 (MCU_UART1_RX)", "U27.13 (PA3)", "R1920 -> CP2102 U33"],
  1020. "evidence_tier": "cross_verified",
  1021. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  1022. "mcu": {
  1023. "device": "U27",
  1024. "family": "STM32F103CBT6",
  1025. "pin": "13",
  1026. "signal": "PA3/MCU_UART1_RX",
  1027. "capabilities": ["gpio", "firmware_configurable", "mcu_uart_rx"],
  1028. "evidence_tier": "cross_verified",
  1029. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1030. },
  1031. },
  1032. "3": {
  1033. "summary": "CON103.3 +3.3V 电源参考",
  1034. "direction": "passive",
  1035. "external_level": "+3.3V",
  1036. "function_category": "power",
  1037. "reserved": True,
  1038. "fixed_load_conflict": True,
  1039. "path": ["CON103.3 (+3.3V)"],
  1040. "evidence_tier": "cross_verified",
  1041. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1042. },
  1043. "4": {
  1044. "summary": "CON103.4 GND 串口参考地(电气图第4/9页接 -U6-2 P1.19 GND3)",
  1045. "direction": "passive",
  1046. "external_level": "0V",
  1047. "function_category": "ground",
  1048. "reserved": True,
  1049. "fixed_load_conflict": True,
  1050. "path": ["CON103.4 (GND)"],
  1051. "evidence_tier": "cross_verified",
  1052. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  1053. },
  1054. },
  1055. }
  1056. # 3e. CON53..CON82 temperature probe labels from Page 4 of 温控板测试V2.0电气图
  1057. v20_probe_labels = {
  1058. "CON53": "1#腔室温度1(进风口)— CT7428 U6 远端温度通道 1(DP1/DN 二极管差分接口)",
  1059. "CON55": "1#腔室温度2(出风口)— CT7428 U6 远端温度通道 2(DP2/DN 二极管差分接口)",
  1060. "CON56": "2#腔室温度1(进风口)— CT7428 U6 远端温度通道 3(DP3/DN 二极管差分接口)",
  1061. "CON57": "2#腔室温度2(出风口)— CT7428 U6 远端温度通道 4(DP4/DN 二极管差分接口)",
  1062. "CON79": "3#腔室温度1(进风口)— CT7428 U6 远端温度通道 5(DP5/DN 二极管差分接口)",
  1063. "CON80": "3#腔室温度2(出风口)— CT7428 U6 远端温度通道 6(DP6/DN 二极管差分接口)",
  1064. "CON81": "4#腔室温度1(进风口)— CT7428 U6 远端温度通道 7(DP7/DN 二极管差分接口)",
  1065. "CON82": "4#腔室温度2(出风口)— CT7428 U6 远端温度通道 8(DP8/DN 二极管差分接口)",
  1066. }
  1067. for probe_ref, probe_summary in v20_probe_labels.items():
  1068. if probe_ref in touchpoint_anns:
  1069. touchpoint_anns[probe_ref]["summary"] = probe_summary
  1070. # 4. Build PTC lookup from pin_inventory
  1071. ptc_active_map: dict[str, dict[str, Any]] = {}
  1072. for item in pin_inv.get("ptc_channels", []):
  1073. conn_str = str(item["connector"])
  1074. if "/" in conn_str:
  1075. base_ref, pin_pair = conn_str.split(".", 1)
  1076. for p_part in pin_pair.split("/"):
  1077. ptc_active_map[f"{base_ref}.{p_part}"] = item
  1078. else:
  1079. ptc_active_map[conn_str] = item
  1080. # CON147, CON148, CON149, CON150 (20-pin PTC headers, 30W/24V heaters on Page 8)
  1081. ptc_summaries = {
  1082. "CON147": "1# 腔体 20Pin PTC 加热输出座(6×30W/24V -1-E1..6:奇脚 1..11 为 6400 V2.0 启用 PTC1..6 → U3.F16/G16/T4/R5/T6/R7;奇脚 13..19 为预留 PTC7..10 → U3.M1/N1/P1/R1;偶脚 2..20 为 PGND)",
  1083. "CON148": "2# 腔体 20Pin PTC 加热输出座(6×30W/24V -2-E1..6:奇脚 1..11 为 6400 V2.0 启用 PTC11..16 → U3.T2/R3/P16/R16/M16/N16;奇脚 13..19 为预留 PTC17..20 → U3.P8/P7/T9/P9;偶脚 2..20 为 PGND)",
  1084. "CON149": "3# 腔体 20Pin PTC 加热输出座(6×30W/24V -3-E1..6:奇脚 1..11 为 6400 V2.0 启用 PTC21..26 → U3.P10/R10/T13/T12/L3/N2;Pin 19 PTC30 → U3.K5 为 ptc_pwm_out[18]、4#腔第1路;Pin 13/15/17 为预留 PTC27..29 → U3.P2/M3/L5;偶脚 2..20 为 PGND)",
  1085. "CON150": "4# 腔体 20Pin PTC 双针并联加热输出座(30W/24V -4-E2..6:PCB 奇脚对 1/3, 5/7, 9/11, 13/15, 17/19 两两并联为 5 路物理通道 PTC31..35 → U3.L4/H4/J6/H5/C15 对应 ptc_pwm_out[19..23];4#腔第1路在 CON149.19;偶脚 2..20 为 PGND)",
  1086. }
  1087. for ref in ("CON147", "CON148", "CON149", "CON150"):
  1088. pins_dict: dict[str, Any] = {}
  1089. for p_idx in range(1, 21):
  1090. pnum = str(p_idx)
  1091. key = f"{ref}.{pnum}"
  1092. net, hit = trace_net_to_u3_u27(ref, pnum, comp_pins, net_to_pins)
  1093. if p_idx % 2 == 0:
  1094. pins_dict[pnum] = {
  1095. "summary": f"{key} PTC 加热回路功率地 (PGND)",
  1096. "direction": "passive",
  1097. "external_level": "0V",
  1098. "function_category": "ground",
  1099. "path": [f"{key} (PGND)"],
  1100. "evidence_tier": "cross_verified",
  1101. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  1102. }
  1103. elif hit is not None:
  1104. _dev, ball, fpga_net, path_list, ext_list = hit
  1105. active_info = ptc_active_map.get(key)
  1106. if active_info is not None:
  1107. idx = active_info["index"]
  1108. role_txt = f"ptc_pwm_out[{idx}] (6400 V2.0 已启用, 30W/24V)"
  1109. else:
  1110. role_txt = f"{net} 预留加热通道 (6400 V2.0 未启用)"
  1111. pins_dict[pnum] = {
  1112. "summary": f"{key} ({net}) → FPGA U3.{ball} ({role_txt})",
  1113. "direction": "output",
  1114. "external_level": "24V PTC PWM",
  1115. "function_category": "pwm",
  1116. "active_level": "high",
  1117. "polarity": "normal",
  1118. "external_components": ext_list,
  1119. "path": path_list,
  1120. "evidence_tier": "cross_verified",
  1121. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  1122. "fpga": {
  1123. "ball": ball,
  1124. "board_signal": net,
  1125. "io_standard": "LVCMOS33",
  1126. "capabilities": ["pwm", "gpio_output"],
  1127. "evidence_tier": "cross_verified",
  1128. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1129. },
  1130. }
  1131. touchpoint_anns[ref] = {"summary": ptc_summaries[ref], "pins": pins_dict}
  1132. # CON154..CON158 (14-pin + 2-shield Fan headers)
  1133. fan_active_map = {item["connector"]: item for item in pin_inv.get("fan_channels", [])}
  1134. fan_summaries = {
  1135. "CON155": "3# & 4# 腔体风扇控制座(Pin 5/6/11/12 为 CON_PWM5..8 → 经 NMOS 反相至 U3.P12/A10/D8/C7 对应 fan_front_out[2..3]/fan_rear_out[2..3];Pin 1..4/7..10 为 FG 测速反馈;Pin 13/14 为 GND)",
  1136. "CON154": "1# & 2# 腔体风扇控制座(Pin 5/6/11/12 为 CON_PWM1..4 → 经 NMOS 反相至 U3.C4/B5/B1/A14 对应 fan_front_out[0..1]/fan_rear_out[0..1];Pin 1..4/7..10 为 FG 测速反馈;Pin 13/14 为 GND)",
  1137. "CON156": "备用 14Pin 风扇控制扩展座 1(空余插座:Pin 5/6/11/12 为 CON_PWM9..12 → U3.F10/L8/C8/E7,Pin 1..4/7..10 为 FG9..12 测速,Pin 13/14 为 GND)",
  1138. "CON157": "备用 14Pin 风扇控制扩展座 2(空余插座:Pin 5/6/11/12 为 CON_PWM13..16 → U3.A3/B11/K15/J15,Pin 1..4/7..10 为 FG13..16 测速,Pin 13/14 为 GND)",
  1139. "CON158": "备用 14Pin 风扇控制扩展座 3(空余插座:Pin 5/6/11/12 为 CON_PWM17..20 → U3.T3/T5/T7/P13,Pin 1..4/7..10 为 FG17..20 测速,Pin 13/14 为 GND)",
  1140. }
  1141. for ref in ("CON154", "CON155", "CON156", "CON157", "CON158"):
  1142. pins_dict = {}
  1143. for p_idx in range(1, 15):
  1144. pnum = str(p_idx)
  1145. key = f"{ref}.{pnum}"
  1146. net, hit = trace_net_to_u3_u27(ref, pnum, comp_pins, net_to_pins)
  1147. if p_idx in (13, 14):
  1148. pins_dict[pnum] = {
  1149. "summary": f"{key} 风扇控制共地 (GND)",
  1150. "direction": "passive",
  1151. "external_level": "0V",
  1152. "function_category": "ground",
  1153. "path": [f"{key} (GND)"],
  1154. "evidence_tier": "cross_verified",
  1155. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1156. }
  1157. elif hit is not None:
  1158. _dev, ball, _fpga_net, path_list, ext_list = hit
  1159. if p_idx in (5, 6, 11, 12):
  1160. f_act = fan_active_map.get(key)
  1161. if f_act is not None:
  1162. rtl_sig = f"fan_{f_act['group']}_out[{f_act['index']}]"
  1163. desc = f"{key} ({net}) → 经 {f_act['nmos']} 2N7002 反相 → FPGA U3.{ball} ({rtl_sig})"
  1164. else:
  1165. desc = f"{key} ({net}) → 经 NMOS 反相 → FPGA U3.{ball}(备用风扇 PWM)"
  1166. pins_dict[pnum] = {
  1167. "summary": desc,
  1168. "direction": "output",
  1169. "external_level": "主板NMOS反相后的开漏PWM;连接器高电平为ON",
  1170. "function_category": "pwm",
  1171. "active_level": "FPGA低电平有效;连接器高电平为ON",
  1172. "polarity": "FPGA与连接器之间反相(主板NMOS)",
  1173. "external_components": ext_list,
  1174. "path": path_list,
  1175. "evidence_tier": "cross_verified",
  1176. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
  1177. "fpga": {
  1178. "ball": ball,
  1179. "board_signal": net,
  1180. "io_standard": "LVCMOS33",
  1181. "capabilities": ["pwm", "gpio_output"],
  1182. "evidence_tier": "cross_verified",
  1183. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1184. },
  1185. }
  1186. else:
  1187. pins_dict[pnum] = {
  1188. "summary": f"{key} ({net} 风扇转速反馈) ← FPGA U3.{ball}",
  1189. "direction": "input",
  1190. "external_level": "3.3V Divided Tach",
  1191. "function_category": "tach",
  1192. "external_components": ext_list,
  1193. "path": path_list,
  1194. "evidence_tier": "cross_verified",
  1195. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1196. "fpga": {
  1197. "ball": ball,
  1198. "board_signal": net,
  1199. "io_standard": "LVCMOS33",
  1200. "capabilities": ["tach", "gpio_input"],
  1201. "evidence_tier": "cross_verified",
  1202. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1203. },
  1204. }
  1205. touchpoint_anns[ref] = {"summary": fan_summaries[ref], "pins": pins_dict}
  1206. # CON159..CON163 (14-pin + 2-shield Stepper Motor headers)
  1207. con159_damper_map = {
  1208. 1: "X1-S → -U1 X-STEP (1轴 -M1 1#前部风门 STEP)",
  1209. 2: "X1-D → -U1 X-DIR (1轴 -M1 1#前部风门 DIR)",
  1210. 3: "Y1-S → -U1 Y-STEP (2轴 -M2 1#后部风门 STEP)",
  1211. 4: "Y1-D → -U1 Y-DIR (2轴 -M2 1#后部风门 DIR)",
  1212. 5: "Z1-S → -U1 Z-STEP (3轴 -M3 1#顶部风门 STEP)",
  1213. 6: "Z1-D → -U1 Z-DIR (3轴 -M3 1#顶部风门 DIR)",
  1214. 7: "A1-S → -U1 A-STEP (轴4 -M4 2#前部风门 STEP)",
  1215. 8: "A1-D → -U1 A-DIR (轴4 -M4 2#前部风门 DIR)",
  1216. 9: "ENA1 → -U1 EN: 使能 (与 CAD CON165.1/现场14 共用 U3.F3,已固定低电平)",
  1217. }
  1218. for idx_m, ref in enumerate(("CON159", "CON160", "CON161", "CON162", "CON163"), start=1):
  1219. ch_start = (idx_m - 1) * 4 + 1
  1220. ch_end = idx_m * 4
  1221. pins_dict = {}
  1222. for p_idx in range(1, 15):
  1223. pnum = str(p_idx)
  1224. key = f"{ref}.{pnum}"
  1225. net, hit = trace_net_to_u3_u27(ref, pnum, comp_pins, net_to_pins)
  1226. if p_idx in (11, 13):
  1227. pins_dict[pnum] = {
  1228. "summary": (
  1229. f"{key} (GND6) 步进驱动器信号地 (GND, 接第3页 -U1 GND)"
  1230. if ref == "CON159"
  1231. else f"{key} 步进驱动器信号地 (GND)"
  1232. ),
  1233. "direction": "passive",
  1234. "external_level": "0V",
  1235. "function_category": "ground",
  1236. "path": [f"{key} (GND)"],
  1237. "evidence_tier": "cross_verified",
  1238. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  1239. }
  1240. elif p_idx in (12, 14):
  1241. pins_dict[pnum] = {
  1242. "summary": (
  1243. f"{key} (P6 +5V) 步进驱动板 +5V 逻辑电源 (接第3页 -U1 5V)"
  1244. if ref == "CON159"
  1245. else f"{key} +5V 步进驱动器光电耦合共阳电源"
  1246. ),
  1247. "direction": "output",
  1248. "external_level": "+5V",
  1249. "function_category": "power",
  1250. "path": [f"{key} (+5V)"],
  1251. "evidence_tier": "cross_verified",
  1252. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  1253. }
  1254. elif p_idx == 10:
  1255. pins_dict[pnum] = {
  1256. "summary": (
  1257. f"{key} (NC1) 电气图第3/4页接 -U1 GND: 使能地(PCB 焊盘悬空 NC)"
  1258. if ref == "CON159"
  1259. else f"{key} 悬空空脚 (NC)"
  1260. ),
  1261. "direction": "passive",
  1262. "external_level": "none",
  1263. "function_category": "unknown",
  1264. "path": [f"{key} (NC)"],
  1265. "evidence_tier": "cross_verified",
  1266. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  1267. }
  1268. elif hit is not None:
  1269. _dev, ball, _fpga_net, path_list, ext_list = hit
  1270. if ref == "CON159" and p_idx in con159_damper_map:
  1271. damper_desc = con159_damper_map[p_idx]
  1272. pins_dict[pnum] = {
  1273. "summary": f"{key} ({net}) → FPGA U3.{ball}(电气图第3/4页:{damper_desc};6400 32B 协议空余未启用)",
  1274. "direction": "output",
  1275. "external_level": "3.3V LVCMOS",
  1276. "function_category": "gpio_output",
  1277. "external_components": ext_list,
  1278. "path": path_list,
  1279. "evidence_tier": "cross_verified",
  1280. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  1281. "fpga": {
  1282. "ball": ball,
  1283. "board_signal": net,
  1284. "io_standard": "LVCMOS33",
  1285. "capabilities": ["gpio_output", "gpio"],
  1286. "evidence_tier": "cross_verified",
  1287. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
  1288. },
  1289. }
  1290. else:
  1291. pins_dict[pnum] = {
  1292. "summary": f"{key} ({net}) → FPGA U3.{ball}(6400 V2.0 无步进电机,空余未用)",
  1293. "direction": "output",
  1294. "external_level": "5V CMOS Buffer",
  1295. "function_category": "gpio_output",
  1296. "external_components": ext_list,
  1297. "path": path_list,
  1298. "evidence_tier": "cross_verified",
  1299. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1300. "fpga": {
  1301. "ball": ball,
  1302. "board_signal": net,
  1303. "io_standard": "LVCMOS33",
  1304. "capabilities": ["gpio_output", "gpio"],
  1305. "evidence_tier": "cross_verified",
  1306. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1307. },
  1308. }
  1309. if ref == "CON159":
  1310. touchpoint_anns[ref] = {
  1311. "summary": (
  1312. "步进控制接口 1(电气图第3/4页接 -U1 四轴驱动板控制 -M1 1#前部风门 / -M2 1#后部风门 / -M3 1#顶部风门 / -M4 2#前部风门:"
  1313. "Pin 1..8 为 PUL/DIR1..4 → U3.C12/B12/L12/J11/L14/K14/L13/K11,Pin 9 为 ENA1 → U3.F3;6400 协议空余插座)"
  1314. ),
  1315. "pins": pins_dict,
  1316. }
  1317. else:
  1318. touchpoint_anns[ref] = {
  1319. "summary": f"备用 14Pin 步进电机驱动扩展座 {idx_m}(空余插座:Pin 1..8 为 PUL/DIR{ch_start}..{ch_end},Pin 9 为 ENA{idx_m} → U3.F3,Pin 11/13 为 GND,Pin 12/14 为 +5V)",
  1320. "pins": pins_dict,
  1321. }
  1322. # CON165, CON166 (14-pin + 2-shield SSR / Hood-Button / Photoelectric headers)
  1323. # 6400高温罩电气图V3.0 Page 4 aligns CON165 pins 1:1 with FCB_FPGA+MCU_V2.0_20260914.brd:
  1324. # CON165.14/13/11 -> SSR1/SSR2/SSR4 (U3.E14/E8/D9, 20Hz PWM)
  1325. # CON165.12 -> NC (empty pin; old temporary U3.F7 removed)
  1326. # CON165.10/9/8 -> EPB1/SB1/SB2 (U3.F8/C11/A11, PULLDOWN, GET_ALL bytes 86/87/88)
  1327. ssr_active_pins = {
  1328. "CON165.14": ("SSR1 (ssr1_out, 腔1 -1-7E 110W/24V 加热布)", "R1698", "R1860", "CPLD_GPIO64"),
  1329. "CON165.13": ("SSR2 (ssr2_out, 腔2+3共用 -2-7E 220W/24V 加热布)", "R1695", "R1859", "ADC0_CH7"),
  1330. "CON165.11": ("SSR4 (ssr4_out, 腔4 -4-7E 110W/24V 加热布)", "R1694", "R1857", "ADC0_CH5"),
  1331. }
  1332. v30_button_pins = {
  1333. "CON165.10": (
  1334. "急停按钮 EPB1 (estop_btn_in)",
  1335. "F8",
  1336. "IO10 / CON_PE10 -> R1696(22Ω) -> PE10 -> R1856(0Ω) -> ADC0_CH0 -> U3.F8",
  1337. ["R1696", "R1856", "R1724"],
  1338. "R1724(10K上拉)未贴装(NC),约束配 LVCMOS33 + 内部 PULLDOWN(默认低 0x00,按下高 0x01);仅在 GET_ALL 时放进回包第 86 字节透传,不做任何 CPLD 安全联锁或停机处理",
  1339. ),
  1340. "CON165.9": (
  1341. "开罩按钮 SB1 (hood_open_btn_in)",
  1342. "C11",
  1343. "IO9 / CON_PE9 -> R1693(22Ω) -> PE9 -> R1855(0Ω) -> BANK0_GPIO2 -> U3.C11",
  1344. ["R1693", "R1855", "R1717"],
  1345. "R1717(10K上拉)未贴装(NC),约束配 LVCMOS33 + 内部 PULLDOWN(默认低 0x00,按下高 0x01);仅在 GET_ALL 时放进回包第 87 字节,不主动上报",
  1346. ),
  1347. "CON165.8": (
  1348. "合罩按钮 SB2 (hood_close_btn_in)",
  1349. "A11",
  1350. "IO8 / CON_PE8 -> R1692(22Ω) -> PE8 -> R1854(0Ω) -> BANK0_GPIO1 -> U3.A11",
  1351. ["R1692", "R1854", "R1723"],
  1352. "R1723(10K上拉)未贴装(NC),约束配 LVCMOS33 + 内部 PULLDOWN(默认低 0x00,按下高 0x01);仅在 GET_ALL 时放进回包第 88 字节,不主动上报",
  1353. ),
  1354. }
  1355. con165_verified_pins = {"14", "13", "12", "11", "10", "9", "8", "1", "2", "4"}
  1356. for ref in ("CON165", "CON166"):
  1357. pins_dict = {}
  1358. for p_idx in range(1, 15):
  1359. pnum = str(p_idx)
  1360. key = f"{ref}.{pnum}"
  1361. net, hit = trace_net_to_u3_u27(ref, pnum, comp_pins, net_to_pins)
  1362. if key in v30_button_pins:
  1363. btn_label, btn_ball, chain_txt, btn_res, btn_note = v30_button_pins[key]
  1364. pins_dict[pnum] = {
  1365. "summary": f"{key} ({net}) → {btn_label} → FPGA U3.{btn_ball}({chain_txt};{btn_note})",
  1366. "direction": "input",
  1367. "external_level": "3.3V LVCMOS (PULLDOWN, active-HIGH 0x01)",
  1368. "function_category": "gpio_input",
  1369. "active_level": "high",
  1370. "polarity": "normal",
  1371. "adc_pulltype": "PULLDOWN",
  1372. "external_components": btn_res,
  1373. "path": [f"{key} ({net})", f"{btn_res[0]} (22R)", f"{btn_res[1]} (0R)", f"U3.{btn_ball} ({btn_label})"],
  1374. "evidence_tier": "cross_verified",
  1375. "sources": [
  1376. "FCB_FPGA+MCU_V2.0_20260914.brd",
  1377. "6400高温罩电气图V3.0.pdf",
  1378. "evidence/hardware/20261023/main_bom.csv",
  1379. "constraints/prod2u_6400_v2.adc",
  1380. ],
  1381. "fpga": {
  1382. "ball": btn_ball,
  1383. "board_signal": net,
  1384. "io_standard": "LVCMOS33",
  1385. "capabilities": ["gpio_input", "gpio"],
  1386. "evidence_tier": "cross_verified",
  1387. "sources": ["6400高温罩电气图V3.0.pdf", "constraints/prod2u_6400_v2.adc"],
  1388. },
  1389. }
  1390. elif key == "CON165.12":
  1391. pins_dict[pnum] = {
  1392. "summary": "CON165.12 (IO12 / CON_PE12) — 电气图 V3.0 第4页为空脚 (NC),已取消旧版暂绑的 U3.F7",
  1393. "direction": "passive",
  1394. "external_level": "NC (unconnected in V3.0)",
  1395. "function_category": "unknown",
  1396. "path": ["CON165.12 (CON_PE12)", "R1697 (22R)", "R1858 (0R)", "U3.F7 (unbound/NC in V3.0)"],
  1397. "external_components": ["R1697", "R1858", "R1725"],
  1398. "evidence_tier": "cross_verified",
  1399. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V3.0.pdf"],
  1400. }
  1401. elif hit is not None:
  1402. _dev, ball, _fpga_net, path_list, ext_list = hit
  1403. if key in ssr_active_pins:
  1404. ssr_label, r_ser, r_zero, fpga_sig = ssr_active_pins[key]
  1405. pins_dict[pnum] = {
  1406. "summary": f"{key} ({net} → {r_ser}/{r_zero} → {fpga_sig}) → FPGA U3.{ball}({ssr_label},20Hz PWM 50ms周期,高有效,默认/看门狗关闭)",
  1407. "direction": "output",
  1408. "external_level": "3.3V SSR 20Hz PWM",
  1409. "function_category": "pwm",
  1410. "active_level": "high",
  1411. "polarity": "normal",
  1412. "external_components": [r_ser, r_zero],
  1413. "path": [f"{key} ({net})", f"{r_ser} (22R)", f"{r_zero} (0R)", f"U3.{ball} ({fpga_sig})"],
  1414. "evidence_tier": "cross_verified",
  1415. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V3.0.pdf", "constraints/prod2u_6400_v2.adc"],
  1416. "fpga": {
  1417. "ball": ball,
  1418. "board_signal": net,
  1419. "io_standard": "LVCMOS33",
  1420. "capabilities": ["pwm", "gpio_output", "gpio"],
  1421. "evidence_tier": "cross_verified",
  1422. "sources": ["6400高温罩电气图V3.0.pdf", "constraints/prod2u_6400_v2.adc"],
  1423. },
  1424. }
  1425. elif ref == "CON165" and p_idx in (1, 2, 4):
  1426. pins_dict[pnum] = {
  1427. "summary": f"{key} ({net}) → U3.{ball},旧版废弃 SSR 引脚(当前固件 ssr_unused_zero 固定拉低)",
  1428. "direction": "output", "external_level": "0V", "function_category": "gpio_output",
  1429. "reserved": True,
  1430. "path": path_list, "external_components": ext_list,
  1431. "evidence_tier": "cross_verified", "sources": ["constraints/prod2u_6400_v2.adc"],
  1432. "fpga": {"ball": ball, "board_signal": net, "io_standard": "LVCMOS33", "evidence_tier": "cross_verified", "sources": ["constraints/prod2u_6400_v2.adc"]},
  1433. }
  1434. else:
  1435. pins_dict[pnum] = {
  1436. "summary": f"{key} ({net}) ↔ FPGA U3.{ball}(光电限位/GPIO 预留通道,6400 V2.0 空余)",
  1437. "direction": "bidirectional",
  1438. "external_level": "3.3V LVCMOS",
  1439. "function_category": "gpio",
  1440. "external_components": ext_list,
  1441. "path": path_list,
  1442. "evidence_tier": "cross_verified",
  1443. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1444. "fpga": {
  1445. "ball": ball,
  1446. "board_signal": net,
  1447. "io_standard": "LVCMOS33",
  1448. "capabilities": ["gpio", "gpio_input", "gpio_output"],
  1449. "evidence_tier": "cross_verified",
  1450. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1451. },
  1452. }
  1453. touchpoint_anns[ref] = {
  1454. "summary": (
  1455. "固态继电器 SSR 与急停/开关罩按钮接口座(电气图 V3.0 第4页与主板物理脚位 1:1 对齐:"
  1456. "Pin 14/13/11=SSR1/SSR2/SSR4 → U3.E14/E8/D9 20Hz PWM;Pin 12=空脚 NC;"
  1457. "Pin 10=急停 EPB1 → U3.F8、Pin 9=开罩 SB1 → U3.C11、Pin 8=合罩 SB2 → U3.A11 均配 PULLDOWN 仅 GET_ALL 透传;旧 F3/F1/G4 固定低电平)"
  1458. if ref == "CON165"
  1459. else "光电限位与 GPIO 扩展座 2(空余插座:Pin 1..14 为 CON_PE15..28 ↔ U3.D16/E15/D14/R9/T10/L2/L1/M2/N3/K4/H2/H1/J2/K3)"
  1460. ),
  1461. "pins": pins_dict,
  1462. }
  1463. # CON164 (4-pin + 2-shield SSR GND & auxiliary power)
  1464. touchpoint_anns["CON164"] = {
  1465. "summary": "固态继电器 SSR 公共回路地与辅助电源座(Pin 1: +5V,Pin 2/3: GND1 配合 CON165.1/2/4 构成 SSR 回路负端,Pin 4: +3.3V)",
  1466. "pins": {
  1467. "1": {"summary": "CON164.1 +5V 辅助电源", "direction": "output", "external_level": "+5V", "function_category": "power", "path": ["CON164.1 (+5V)"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]},
  1468. "2": {"summary": "CON164.2 GND 公共地", "direction": "passive", "external_level": "0V", "function_category": "ground", "path": ["CON164.2 (GND)"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]},
  1469. "3": {"summary": "CON164.3 GND1 固态继电器 SSR 公共负端回路 (配合 CON165.1/2/4)", "direction": "passive", "external_level": "0V", "function_category": "ground", "path": ["CON164.3 (GND)"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"]},
  1470. "4": {"summary": "CON164.4 +3.3V 辅助电源参考", "direction": "output", "external_level": "+3.3V", "function_category": "power", "path": ["CON164.4 (+3.3V)"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]},
  1471. },
  1472. }
  1473. # CON168 on Mainboard (4-pin LCD UART header)
  1474. touchpoint_anns["CON168"] = {
  1475. "summary": "板载 STM32 MCU 串口屏扩展座(空余插座:Pin 1 GND,Pin 2 CON_LCD_RX → U27.30 PA9,Pin 3 CON_LCD_TX ← U27.31 PA10,Pin 4 CON_LCD_VCC;新版电气图第4页未接线)",
  1476. "pins": {
  1477. "1": {"summary": "CON168.1 GND", "direction": "passive", "external_level": "0V", "function_category": "ground", "path": ["CON168.1 (GND)"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]},
  1478. "2": {
  1479. "summary": "CON168.2 (CON_LCD_RX) → R1892 → 板载 MCU U27.30 (PA9 / MCU_UART0_TX)",
  1480. "direction": "output",
  1481. "external_level": "3.3V LVCMOS",
  1482. "function_category": "uart_tx",
  1483. "external_components": ["R1892"],
  1484. "path": ["CON168.2 (CON_LCD_RX)", "R1892.2->1 (MCU_UART0_TX)", "U27.30 (PA9)"],
  1485. "evidence_tier": "cross_verified",
  1486. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1487. "mcu": {"device": "U27", "family": "STM32F103CBT6", "pin": "30", "signal": "PA9/MCU_UART0_TX", "capabilities": ["mcu_uart_tx"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]},
  1488. },
  1489. "3": {
  1490. "summary": "CON168.3 (CON_LCD_TX) ← R1893 ← 板载 MCU U27.31 (PA10 / MCU_UART0_RX)",
  1491. "direction": "input",
  1492. "external_level": "3.3V LVCMOS",
  1493. "function_category": "uart_rx",
  1494. "external_components": ["R1893"],
  1495. "path": ["CON168.3 (CON_LCD_TX)", "R1893.2->1 (MCU_UART0_RX)", "U27.31 (PA10)"],
  1496. "evidence_tier": "cross_verified",
  1497. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1498. "mcu": {"device": "U27", "family": "STM32F103CBT6", "pin": "31", "signal": "PA10/MCU_UART0_RX", "capabilities": ["mcu_uart_rx"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]},
  1499. },
  1500. "4": {"summary": "CON168.4 (CON_LCD_VCC) 经 R1891 接 +5V", "direction": "output", "external_level": "+5V", "function_category": "power", "external_components": ["R1891"], "path": ["CON168.4 (CON_LCD_VCC)", "R1891", "+5V"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]},
  1501. },
  1502. }
  1503. # CON170 on Mainboard (RJ45 BMC RS232 alternate port)
  1504. con170_pins: dict[str, Any] = {}
  1505. for p_idx in range(1, 13):
  1506. pnum = str(p_idx)
  1507. if pnum == "3":
  1508. con170_pins[pnum] = {
  1509. "summary": "CON170.3 (RS232_TX1_RJ45) → R1898 → TRSF3232EIPWR U22.14/11 → R818 → FPGA U3.L10 (bmc_tx,与 CON77.1 并联)",
  1510. "direction": "output",
  1511. "external_level": "RS232",
  1512. "function_category": "uart_tx",
  1513. "external_components": ["R1898", "U22", "R818"],
  1514. "path": ["CON170.3 (RS232_TX1_RJ45)", "R1898.2->1 (RS232_TX1)", "U22.14->11 (UART1_TX)", "R818.2->1 (BANK2_GPIO52)", "U3.L10 (bmc_tx)"],
  1515. "evidence_tier": "cross_verified",
  1516. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1517. "fpga": {"ball": "L10", "board_signal": "BANK2_GPIO52", "io_standard": "LVCMOS33", "capabilities": ["uart_tx", "rs232_via_transceiver"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]},
  1518. }
  1519. elif pnum == "6":
  1520. con170_pins[pnum] = {
  1521. "summary": "CON170.6 (RS232_RX1_RJ45) ← R1899 ← TRSF3232EIPWR U22.13/12 ← R819 ← FPGA U3.M9 (bmc_rx,与 CON77.2 并联)",
  1522. "direction": "input",
  1523. "external_level": "RS232",
  1524. "function_category": "uart_rx",
  1525. "external_components": ["R1899", "U22", "R819"],
  1526. "path": ["CON170.6 (RS232_RX1_RJ45)", "R1899.2->1 (RS232_RX1)", "U22.13->12 (UART1_RX)", "R819.2->1 (BANK2_GPIO53)", "U3.M9 (bmc_rx)"],
  1527. "evidence_tier": "cross_verified",
  1528. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1529. "fpga": {"ball": "M9", "board_signal": "BANK2_GPIO53", "io_standard": "LVCMOS33", "capabilities": ["uart_rx", "rs232_via_transceiver"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]},
  1530. }
  1531. elif pnum in ("4", "9"):
  1532. con170_pins[pnum] = {"summary": f"CON170.{pnum} GND", "direction": "passive", "external_level": "0V", "function_category": "ground", "path": [f"CON170.{pnum} (GND)"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]}
  1533. elif pnum == "10":
  1534. con170_pins[pnum] = {"summary": "CON170.10 RJ45 指示灯阳极 (经 R1900 接 +3.3V)", "direction": "passive", "external_level": "3.3V", "function_category": "power", "external_components": ["R1900"], "path": ["CON170.10 (N11538228)", "R1900", "+3.3V"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]}
  1535. else:
  1536. con170_pins[pnum] = {"summary": f"CON170.{pnum} 悬空触点 (NC)", "direction": "passive", "external_level": "none", "function_category": "unknown", "path": [f"CON170.{pnum} (NC)"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]}
  1537. touchpoint_anns["CON170"] = {
  1538. "summary": "RJ45 BMC RS-232 备用接口座(Pin 3 TX1_RJ45 → U3.L10,Pin 6 RX1_RJ45 ← U3.M9,与 CON77 共用 TRSF3232EIPWR U22 通道)",
  1539. "pins": con170_pins,
  1540. }
  1541. # CON171 (4-pin + 2-shield GPIO header: EX_GPIO7..10 -> M10, N11, L7, M7)
  1542. con171_pins: dict[str, Any] = {}
  1543. for p_idx in range(1, 5):
  1544. pnum = str(p_idx)
  1545. net, hit = trace_net_to_u3_u27("CON171", pnum, comp_pins, net_to_pins)
  1546. if hit is not None:
  1547. _dev, ball, _fpga_net, path_list, ext_list = hit
  1548. con171_pins[pnum] = {
  1549. "summary": f"CON171.{pnum} ({net}) ↔ FPGA U3.{ball}(外部 3.3V GPIO 扩展,6400 V2.0 空余)",
  1550. "direction": "bidirectional",
  1551. "external_level": "3.3V LVCMOS",
  1552. "function_category": "gpio",
  1553. "external_components": ext_list,
  1554. "path": path_list,
  1555. "evidence_tier": "cross_verified",
  1556. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1557. "fpga": {"ball": ball, "board_signal": net, "io_standard": "LVCMOS33", "capabilities": ["gpio", "gpio_input", "gpio_output"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]},
  1558. }
  1559. touchpoint_anns["CON171"] = {
  1560. "summary": "外部 3.3V GPIO 扩展座(空余插座:Pin 1..4 为 EX_GPIO7..10 ↔ R1901..R1904 ↔ FPGA U3.M10/N11/L7/M7)",
  1561. "pins": con171_pins,
  1562. }
  1563. # CON172 on Mainboard (18-pad USB Type-C connector -> CP2102 U33 -> MCU U27.12/13)
  1564. con172_pins: dict[str, Any] = {}
  1565. for pnum in ("A1", "A4", "A5", "A6", "A7", "A9", "A12", "B1", "B4", "B5", "B6", "B7", "B9", "B12"):
  1566. if pnum in ("A6", "B6"):
  1567. con172_pins[pnum] = {
  1568. "summary": f"CON172.{pnum} (USB_D+) ↔ R1917 ↔ CP2102 U33.4 ↔ R1920/R1921 ↔ 板载 MCU U27.12/13 (PA2/PA3 MCU_UART1)",
  1569. "direction": "bidirectional",
  1570. "external_level": "USB 2.0 Differential",
  1571. "function_category": "uart",
  1572. "external_components": ["R1917", "U33", "R1920", "R1921"],
  1573. "path": [f"CON172.{pnum} (USB_D+)", "R1917", "U33 (CP2102)", "R1920/R1921", "U27.12/13 (PA2/PA3)"],
  1574. "evidence_tier": "cross_verified",
  1575. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1576. "mcu": {"device": "U27", "family": "STM32F103CBT6", "pin": "12/13", "signal": "PA2/PA3 (via CP2102 U33)", "capabilities": ["usb_uart_bridge"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]},
  1577. }
  1578. elif pnum in ("A7", "B7"):
  1579. con172_pins[pnum] = {
  1580. "summary": f"CON172.{pnum} (USB_D-) ↔ R1918 ↔ CP2102 U33.5 ↔ R1920/R1921 ↔ 板载 MCU U27.12/13 (PA2/PA3 MCU_UART1)",
  1581. "direction": "bidirectional",
  1582. "external_level": "USB 2.0 Differential",
  1583. "function_category": "uart",
  1584. "external_components": ["R1918", "U33", "R1920", "R1921"],
  1585. "path": [f"CON172.{pnum} (USB_D-)", "R1918", "U33 (CP2102)", "R1920/R1921", "U27.12/13 (PA2/PA3)"],
  1586. "evidence_tier": "cross_verified",
  1587. "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
  1588. "mcu": {"device": "U27", "family": "STM32F103CBT6", "pin": "12/13", "signal": "PA2/PA3 (via CP2102 U33)", "capabilities": ["usb_uart_bridge"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]},
  1589. }
  1590. elif pnum in ("A4", "A9", "B4", "B9"):
  1591. con172_pins[pnum] = {"summary": f"CON172.{pnum} (VBUS) USB 5V 供电输入 (经 R1915 至 CP2102 U33)", "direction": "input", "external_level": "+5V VBUS", "function_category": "power", "external_components": ["R1915"], "path": [f"CON172.{pnum} (VBUS)", "R1915", "CP2102_VBUS"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]}
  1592. elif pnum in ("A5", "B5"):
  1593. r_cc = "R1913" if pnum == "A5" else "R1914"
  1594. con172_pins[pnum] = {"summary": f"CON172.{pnum} USB Type-C CC 配置脚 (经 {r_cc} 5.1k 下拉至 GND)", "direction": "passive", "external_level": "USB CC", "function_category": "power", "external_components": [r_cc], "path": [f"CON172.{pnum}", r_cc, "GND"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]}
  1595. else:
  1596. con172_pins[pnum] = {"summary": f"CON172.{pnum} USB GND", "direction": "passive", "external_level": "0V", "function_category": "ground", "path": [f"CON172.{pnum} (GND)"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]}
  1597. touchpoint_anns["CON172"] = {
  1598. "summary": "USB Type-C 板载 MCU 调试串口座(经 CP2102 U33 USB-UART 桥接芯片连接 GD32 U27.12/13 PA2/PA3,非 FPGA 端口)",
  1599. "pins": con172_pins,
  1600. }
  1601. # CON173, CON174 (12-pin +24V_VIN main power connectors)
  1602. for ref in ("CON173", "CON174"):
  1603. p_dict: dict[str, Any] = {}
  1604. for p_idx in range(1, 13):
  1605. pnum = str(p_idx)
  1606. if p_idx <= 6:
  1607. p_dict[pnum] = {"summary": f"{ref}.{pnum} PCB 网表 24V 主电源输入负端 (GND;注:电气图第4页符号将 Pin 1..6 标为 24V P24,接线请以 PCB 铜皮为准)", "direction": "passive", "external_level": "0V", "function_category": "ground", "path": [f"{ref}.{pnum} (GND)"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"]}
  1608. else:
  1609. p_dict[pnum] = {"summary": f"{ref}.{pnum} PCB 网表 +24V_VIN 主电源输入正端 (+24V;注:电气图第4页符号将 Pin 7..12 标为 GND N24,接线请以 PCB 铜皮为准)", "direction": "input", "external_level": "+24V DC", "function_category": "power", "path": [f"{ref}.{pnum} (+24V_VIN)"], "evidence_tier": "cross_verified", "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"]}
  1610. touchpoint_anns[ref] = {
  1611. "summary": "12Pin +24V_VIN 主功率电源输入座(PCB 网表 Pin 1..6 为 GND、Pin 7..12 为 +24V_VIN;注:电气图第4页符号标为 Pin 1..6=24V P24、Pin 7..12=GND N24)",
  1612. "pins": p_dict,
  1613. }
  1614. interfaces = [
  1615. {
  1616. "id": "host-ttl",
  1617. "name": "Host TTL 串口 (连接外部 STM32H7 核心板)",
  1618. "touchpoint": "CON12",
  1619. "pins": ["1", "2", "3", "4"],
  1620. "external_level": "3.3V LVCMOS",
  1621. "evidence_tier": "cross_verified",
  1622. "sources": ["reference/original/schematics/6400高温罩电气图V2.0.pdf", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  1623. },
  1624. {
  1625. "id": "host-rs232",
  1626. "name": "Host RS-232 串口 (921600 波特率)",
  1627. "touchpoint": "CON134",
  1628. "pins": ["1", "2", "3", "4"],
  1629. "external_level": "RS232",
  1630. "evidence_tier": "cross_verified",
  1631. "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  1632. },
  1633. {
  1634. "id": "bmc-rs232",
  1635. "name": "BMC RS-232 串口 (115200 波特率)",
  1636. "touchpoint": "CON77",
  1637. "pins": ["1", "2", "3", "4"],
  1638. "external_level": "RS232",
  1639. "evidence_tier": "cross_verified",
  1640. "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  1641. },
  1642. {
  1643. "id": "ptc-chamber1",
  1644. "name": "1# 腔体 PTC 加热输出 (PTC1..6)",
  1645. "touchpoint": "CON147",
  1646. "pins": ["1", "3", "5", "7", "9", "11"],
  1647. "external_level": "24V PTC PWM",
  1648. "evidence_tier": "cross_verified",
  1649. "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  1650. },
  1651. {
  1652. "id": "ptc-chamber2",
  1653. "name": "2# 腔体 PTC 加热输出 (PTC11..16)",
  1654. "touchpoint": "CON148",
  1655. "pins": ["1", "3", "5", "7", "9", "11"],
  1656. "external_level": "24V PTC PWM",
  1657. "evidence_tier": "cross_verified",
  1658. "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  1659. },
  1660. {
  1661. "id": "ptc-chamber3",
  1662. "name": "3# 腔体 PTC 加热输出 (PTC21..26)",
  1663. "touchpoint": "CON149",
  1664. "pins": ["1", "3", "5", "7", "9", "11"],
  1665. "external_level": "24V PTC PWM",
  1666. "evidence_tier": "cross_verified",
  1667. "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  1668. },
  1669. {
  1670. "id": "ptc-chamber4",
  1671. "name": "4# 腔体 PTC 第2..6路 (PTC31..35;第1路在CON149.19)",
  1672. "touchpoint": "CON150",
  1673. "pins": ["1", "3", "5", "7", "9", "11", "13", "15", "17", "19"],
  1674. "external_level": "24V PTC PWM",
  1675. "evidence_tier": "cross_verified",
  1676. "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  1677. },
  1678. {
  1679. "id": "fan-chamber1-2",
  1680. "name": "1# & 2# 腔体前/后风扇 PWM (Front0..1, Rear0..1)",
  1681. "touchpoint": "CON154",
  1682. "pins": ["5", "6", "11", "12"],
  1683. "external_level": "主板NMOS反相后的风扇PWM",
  1684. "evidence_tier": "cross_verified",
  1685. "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  1686. },
  1687. {
  1688. "id": "fan-chamber3-4",
  1689. "name": "3# & 4# 腔体前/后风扇 PWM (Front2..3, Rear2..3)",
  1690. "touchpoint": "CON155",
  1691. "pins": ["5", "6", "11", "12"],
  1692. "external_level": "主板NMOS反相后的风扇PWM",
  1693. "evidence_tier": "cross_verified",
  1694. "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  1695. },
  1696. {
  1697. "id": "ssr-control",
  1698. "name": "三路加热布 SSR 调功控制 (SSR1/SSR2/SSR4)",
  1699. "touchpoint": "CON165",
  1700. "pins": ["14", "13", "11"],
  1701. "external_level": "3.3V高有效;20Hz PWM (50ms周期);默认/看门狗关闭",
  1702. "evidence_tier": "cross_verified",
  1703. "sources": ["reference/original/schematics/6400高温罩电气图V3.0.pdf", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  1704. },
  1705. {
  1706. "id": "hood-buttons",
  1707. "name": "急停 EPB1 / 开罩 SB1 / 合罩 SB2 按钮检测 (仅 GET_ALL 透传)",
  1708. "touchpoint": "CON165",
  1709. "pins": ["10", "9", "8"],
  1710. "external_level": "3.3V LVCMOS + 内部 PULLDOWN(外置上拉未贴装,默认低0x00/按下高0x01)",
  1711. "evidence_tier": "cross_verified",
  1712. "sources": ["reference/original/schematics/6400高温罩电气图V3.0.pdf", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  1713. },
  1714. {
  1715. "id": "buzzer-output",
  1716. "name": "MCU 触发蜂鸣器高边驱动 (4000Hz / 80% 占空比)",
  1717. "touchpoint": "CON146",
  1718. "pins": ["1", "2"],
  1719. "external_level": "+24V 高边开关 (U3.H6 4000Hz 80%占空比方波:6250拍周期/5000高/1250低)",
  1720. "evidence_tier": "cross_verified",
  1721. "sources": ["reference/original/schematics/6400高温罩电气图V3.0.pdf", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
  1722. },
  1723. ]
  1724. # These pin paths are produced by the structural BFS above. NC options and
  1725. # transistor conduction are not verified by that search, even if names match.
  1726. # CON165 pins verified against main_bom.csv + main_pins.csv + V3.0 PDF stay cross_verified.
  1727. for ref in [*(f"CON{i}" for i in range(147, 151)),
  1728. *(f"CON{i}" for i in range(154, 164)), "CON165", "CON166", "CON171"]:
  1729. for pnum, pin in touchpoint_anns.get(ref, {}).get("pins", {}).items():
  1730. if ref == "CON165" and pnum in con165_verified_pins:
  1731. continue
  1732. if "fpga" in pin:
  1733. _mark_inferred(pin)
  1734. pin["summary"] = "拓扑候选(未核装配/导通):" + pin.get("summary", "")
  1735. return {
  1736. "board_id": "fcb_fpga_mcu_v2_0_20260914",
  1737. "connector_profiles": connector_profiles,
  1738. "touchpoints": touchpoint_anns,
  1739. "interfaces": interfaces,
  1740. }
  1741. def _assemble_board_payload(
  1742. parsed_board: ParsedBoard,
  1743. annotations: Mapping[str, Any],
  1744. *,
  1745. board_name: str,
  1746. ) -> dict[str, Any]:
  1747. """Assemble and validate a board-viewer-data-v2 payload from ParsedBoard + annotations."""
  1748. touchpoints = [_touchpoint_dict(fp, parsed_board.bounds) for fp in select_touchpoints(parsed_board)]
  1749. resistors = [
  1750. _resistor_dict(fp, parsed_board.bounds)
  1751. for fp in sorted(select_resistors(parsed_board), key=lambda item: int(item.reference[1:]))
  1752. ]
  1753. profiles: dict[str, tuple[str, Mapping[str, Any]]] = {}
  1754. for prof_name, prof_obj in annotations.get("connector_profiles", {}).items():
  1755. for ref in prof_obj.get("references", []):
  1756. profiles[str(ref)] = (str(prof_name), prof_obj)
  1757. tp_anns = annotations.get("touchpoints", {})
  1758. for tp in touchpoints:
  1759. ref = tp["reference"]
  1760. prof_entry = profiles.get(ref)
  1761. if tp["category"] == "CON" or prof_entry is not None:
  1762. _apply_connector_profile(tp, prof_entry)
  1763. tp_ann = tp_anns.get(ref, {})
  1764. if isinstance(tp_ann, Mapping) and tp_ann.get("summary"):
  1765. tp["summary"] = str(tp_ann["summary"])
  1766. pin_anns = tp_ann.get("pins", {}) if isinstance(tp_ann, Mapping) else {}
  1767. for pin in tp["pins"]:
  1768. p_ann = pin_anns.get(str(pin["number"]), {})
  1769. if isinstance(p_ann, Mapping) and p_ann:
  1770. _merge_annotation(pin, p_ann)
  1771. pin["evidence_sources"] = _unique_strings(list(pin.get("evidence_sources", [])))
  1772. pin["programming"] = _programming_guidance(ref, pin)
  1773. prog_ann = p_ann.get("programming", {}) if isinstance(p_ann, Mapping) else {}
  1774. if isinstance(prog_ann, Mapping) and prog_ann:
  1775. _merge_programming_annotation(pin["programming"], prog_ann)
  1776. _refresh_recommendation(pin)
  1777. _attach_related_resistors(touchpoints, resistors)
  1778. category_counts = Counter(item["category"] for item in touchpoints)
  1779. touchpoint_side_counts = Counter(item["side"] for item in touchpoints)
  1780. resistor_side_counts = Counter(item["side"] for item in resistors)
  1781. connector_touchpoints = [item for item in touchpoints if item["category"] == "CON"]
  1782. resistor_pad_count = sum(len(item["pads"]) for item in resistors)
  1783. resistor_electrical_pad_count = sum(
  1784. 1 for item in resistors for pad in item["pads"] if pad.get("pad_role") == "electrical"
  1785. )
  1786. if resistors:
  1787. value_coverage = _build_value_coverage(resistors)
  1788. else:
  1789. value_coverage = {
  1790. "resistors_total": 0,
  1791. "component_value_nonempty": 0,
  1792. "value_parsed": 0,
  1793. "value_zero_ohm_fitted_or_unknown": 0,
  1794. "value_zero_ohm_not_fitted": 0,
  1795. "assembly_not_fitted": 0,
  1796. "value_missing_or_unparsed": 0,
  1797. "component_value_source_status": "passive_board_no_resistors",
  1798. "example_available_tokens": ["fuse"],
  1799. "note": "Passive connector expansion board with no discrete resistors.",
  1800. }
  1801. payload = {
  1802. "schema": BOARD_DATA_SCHEMA_ID,
  1803. "board": {
  1804. "id": str(annotations.get("board_id")),
  1805. "name": board_name,
  1806. "source_bounds": dict(parsed_board.bounds),
  1807. "view_box": {
  1808. "x": 0.0,
  1809. "y": 0.0,
  1810. "width": parsed_board.bounds["width"],
  1811. "height": parsed_board.bounds["height"],
  1812. },
  1813. },
  1814. "counts": {
  1815. "footprints": parsed_board.footprint_count,
  1816. "touchpoints": len(touchpoints),
  1817. "pads": sum(len(item["pins"]) for item in touchpoints),
  1818. "resistors": len(resistors),
  1819. "resistor_pads": resistor_pad_count,
  1820. "resistor_electrical_pads": resistor_electrical_pad_count,
  1821. "connector_contacts": sum(int(item["connector"]["contact_count"]) for item in connector_touchpoints),
  1822. "connector_auxiliary_pads": sum(
  1823. int(item["connector"]["auxiliary_pad_count"]) for item in connector_touchpoints
  1824. ),
  1825. "categories": {
  1826. "CON": category_counts.get("CON", 0),
  1827. "J": category_counts.get("J", 0),
  1828. "PL": category_counts.get("PL", 0),
  1829. "TP": category_counts.get("TP", 0),
  1830. "R": len(resistors),
  1831. },
  1832. "sides": {key: touchpoint_side_counts.get(key, 0) for key in ("front", "back")},
  1833. "touchpoint_sides": {key: touchpoint_side_counts.get(key, 0) for key in ("front", "back")},
  1834. "resistor_sides": {key: resistor_side_counts.get(key, 0) for key in ("front", "back")},
  1835. },
  1836. "value_coverage": value_coverage,
  1837. "component_value_source_status": value_coverage["component_value_source_status"],
  1838. "touchpoints": touchpoints,
  1839. "resistors": resistors,
  1840. "resistor_links": [],
  1841. "evidence_conflicts": [],
  1842. "interfaces": list(annotations.get("interfaces", [])),
  1843. "photo_overlay": None,
  1844. }
  1845. validate_resistor_index(payload)
  1846. data_schema = json.loads(DATA_SCHEMA_PATH.read_text(encoding="utf-8"))
  1847. Draft202012Validator(data_schema).validate(payload)
  1848. return payload
  1849. # ---------------------------------------------------------------------------
  1850. # Entry Points: Mainboard & Fan Board
  1851. # ---------------------------------------------------------------------------
  1852. def generate_v2_0_mainboard() -> None:
  1853. print("[V2.0] Starting FCB V2.0 (6400 Mainboard) asset generation from Allegro BRD...")
  1854. brd_path = ROOT / "reference/original/board/FCB_FPGA_MCU_V2.0_20260914/FCB_FPGA+MCU_V2.0_20260914.brd"
  1855. pin_inv_path = ROOT / "config/pin_inventory.fcb_fpga_mcu_v2_0.json"
  1856. out_dir = ROOT / "tools/board-viewer/generated-v2_0"
  1857. out_dir.mkdir(parents=True, exist_ok=True)
  1858. parsed_board, cad_meta = parse_allegro_brd(brd_path)
  1859. pin_inv = json.loads(pin_inv_path.read_text(encoding="utf-8"))
  1860. annotations = _build_v20_annotations(parsed_board, cad_meta, pin_inv)
  1861. board_data = _assemble_board_payload(
  1862. parsed_board,
  1863. annotations,
  1864. board_name="FCB FPGA+MCU V2.0 20260914 (6400 主控板)",
  1865. )
  1866. print(
  1867. f"[V2.0] Parsed {board_data['counts']['footprints']} footprints, "
  1868. f"{board_data['counts']['touchpoints']} touchpoints ({board_data['counts']['pads']} pads), "
  1869. f"{board_data['counts']['resistors']} resistors ({board_data['counts']['resistor_pads']} pads) "
  1870. f"on {parsed_board.bounds['width']}x{parsed_board.bounds['height']} mm board"
  1871. )
  1872. (out_dir / "board-data.json").write_text(
  1873. json.dumps(board_data, indent=2, ensure_ascii=False) + "\n",
  1874. encoding="utf-8",
  1875. )
  1876. generate_svg_layers_from_brd(
  1877. parsed_board,
  1878. cad_meta,
  1879. "FCB FPGA+MCU V2.0 20260914",
  1880. board_data["touchpoints"],
  1881. out_dir,
  1882. )
  1883. cats = board_data["counts"]["categories"]
  1884. import_report = {
  1885. "board_id": "fcb_fpga_mcu_v2_0_20260914",
  1886. "source": "reference/original/board/FCB_FPGA_MCU_V2.0_20260914/FCB_FPGA+MCU_V2.0_20260914.brd",
  1887. "source_file": brd_path.name,
  1888. "source_format": "allegro_brd",
  1889. "output_file": "board-data.json",
  1890. "errors": [],
  1891. "timestamp": datetime.now(timezone.utc).isoformat(),
  1892. "stats": {
  1893. "connectors": cats["CON"],
  1894. "jumpers": cats["J"],
  1895. "power_terminals": cats["PL"],
  1896. "test_points": cats["TP"],
  1897. "resistors": cats["R"],
  1898. },
  1899. "status": "success",
  1900. }
  1901. (out_dir / "import-report.json").write_text(json.dumps(import_report, indent=2) + "\n", encoding="utf-8")
  1902. assets_meta: dict[str, dict[str, Any]] = {}
  1903. for asset_file in (out_dir / name for name in (
  1904. "board-data.json", "import-report.json", "board-mask-edge.svg",
  1905. "board-mask-edge-back.svg", "board-copper.svg", "board-copper-back.svg",
  1906. "board-silkscreen.svg", "board-silkscreen-back.svg",
  1907. )):
  1908. if asset_file.is_file():
  1909. assets_meta[asset_file.name] = {
  1910. "sha256": sha256_file(asset_file),
  1911. "bytes": asset_file.stat().st_size,
  1912. }
  1913. v30_pdf_path = ROOT / "reference/original/schematics/6400高温罩电气图V3.0.pdf"
  1914. build_info = {
  1915. "schema": "board-viewer-build-info-v1",
  1916. "generated_at": datetime.now(timezone.utc).isoformat(),
  1917. "generator_version": "3.3.0",
  1918. "toolchain": {"python": sys.version.split()[0], "kicad": "not_used"},
  1919. "sources": {
  1920. **_generator_sources(),
  1921. "brd": {
  1922. "path": "reference/original/board/FCB_FPGA_MCU_V2.0_20260914/FCB_FPGA+MCU_V2.0_20260914.brd",
  1923. "sha256": sha256_file(brd_path),
  1924. },
  1925. "schematic_v3_0": {
  1926. "path": "reference/original/schematics/6400高温罩电气图V3.0.pdf",
  1927. "sha256": sha256_file(v30_pdf_path),
  1928. },
  1929. "annotations": {
  1930. "path": str(ANNOTATIONS_V12_PATH.relative_to(ROOT)),
  1931. "sha256": sha256_file(ANNOTATIONS_V12_PATH),
  1932. },
  1933. "inventory": {
  1934. "path": "config/pin_inventory.fcb_fpga_mcu_v2_0.json",
  1935. "sha256": sha256_file(pin_inv_path),
  1936. },
  1937. "schema_data": {
  1938. "path": "schemas/board_viewer_data.schema.json",
  1939. "sha256": sha256_file(DATA_SCHEMA_PATH),
  1940. },
  1941. "schema_build_info": {
  1942. "path": "schemas/board_viewer_build_info.schema.json",
  1943. "sha256": sha256_file(BUILD_INFO_SCHEMA_PATH),
  1944. },
  1945. },
  1946. "assets": assets_meta,
  1947. "verification": {
  1948. "ipcd356": {
  1949. "status": "not_run",
  1950. "reason": "No independent IPC-D-356 export or alignment comparison was executed by this BRD viewer generator.",
  1951. },
  1952. "side_views": {
  1953. "front_layers": [
  1954. "board-mask-edge.svg",
  1955. "board-silkscreen.svg",
  1956. "board-copper.svg",
  1957. ],
  1958. "back_layers": [
  1959. "board-mask-edge-back.svg",
  1960. "board-silkscreen-back.svg",
  1961. "board-copper-back.svg",
  1962. ],
  1963. "back_mirror_axis": "y",
  1964. "back_svg_export_mirrored": True,
  1965. "convention": "Back SVGs are rendered by this script, mirrored about the vertical/Y axis; viewer hotspot X = board_width - view_position.x. Geometry is simplified, not a KiCad export.",
  1966. },
  1967. },
  1968. "counts": {
  1969. "footprints": board_data["counts"]["footprints"],
  1970. "touchpoints": board_data["counts"]["touchpoints"],
  1971. "pads": board_data["counts"]["pads"],
  1972. "resistors": board_data["counts"]["resistors"],
  1973. "resistor_pads": board_data["counts"]["resistor_pads"],
  1974. },
  1975. }
  1976. build_info_schema = json.loads(BUILD_INFO_SCHEMA_PATH.read_text(encoding="utf-8"))
  1977. Draft202012Validator(build_info_schema).validate(build_info)
  1978. (out_dir / "build-info.json").write_text(json.dumps(build_info, indent=2) + "\n", encoding="utf-8")
  1979. print(f"[V2.0] Asset generation complete! {len(assets_meta)} assets in {out_dir.name}")
  1980. def _build_v20_fan_annotations() -> dict[str, Any]:
  1981. connector_profiles = {
  1982. "CON_SMD_2D54_2X7P": {
  1983. "references": ["CON168"],
  1984. "contact_pins": [str(i) for i in range(1, 15)],
  1985. "shield_pads": [],
  1986. "evidence_tier": "cross_verified",
  1987. "sources": ["FCB_FAN_V2.0_20260914.brd"],
  1988. },
  1989. "CON_PZGM_B03_08P": {
  1990. "references": ["CON8", "CON169", "CON170", "CON171"],
  1991. "contact_pins": [str(i) for i in range(1, 9)],
  1992. "shield_pads": [],
  1993. "evidence_tier": "cross_verified",
  1994. "sources": ["FCB_FAN_V2.0_20260914.brd"],
  1995. },
  1996. "CON_X9556WV_2X4P": {
  1997. "references": ["CON2", "CON172"],
  1998. "contact_pins": [str(i) for i in range(1, 9)],
  1999. "shield_pads": [],
  2000. "evidence_tier": "cross_verified",
  2001. "sources": ["FCB_FAN_V2.0_20260914.brd"],
  2002. },
  2003. }
  2004. con168_pins: dict[str, Any] = {}
  2005. fg_map = {
  2006. "1": ("FG1_1", "CON8.5", "D2/N10"),
  2007. "2": ("FG2_1", "CON169.5", "E6 / U3.R11"),
  2008. "3": ("FG1_2", "CON8.6", "D3/M11"),
  2009. "4": ("FG2_2", "CON169.6", "D6/B9"),
  2010. "7": ("FG3_1", "CON170.5", "C1/D10"),
  2011. "8": ("FG4_1", "CON171.5", "B3/E9"),
  2012. "9": ("FG3_2", "CON170.6", "C2/E10"),
  2013. "10": ("FG4_2", "CON171.6", "B13/B7"),
  2014. }
  2015. pwm_map = {
  2016. "5": ("PWM1", "CON8.7", "P12/C4", "fan_front_2_0"),
  2017. "6": ("PWM2", "CON169.7", "A10/B5", "fan_rear_2_0"),
  2018. "11": ("PWM3", "CON170.7", "D8/B1", "fan_front_3_1"),
  2019. "12": ("PWM4", "CON171.7", "C7/A14", "fan_rear_3_1"),
  2020. }
  2021. for p_idx in range(1, 15):
  2022. pnum = str(p_idx)
  2023. if pnum in pwm_map:
  2024. net, dest, ball, bsig = pwm_map[pnum]
  2025. con168_pins[pnum] = {
  2026. "summary": f"CON168.{pnum} ({net}) → 直通 {dest} ↔ 主板 CON155/CON154.{pnum} → FPGA U3.{ball} ({bsig})",
  2027. "direction": "input",
  2028. "external_level": "主板NMOS反相后的开漏PWM;连接器高电平为ON",
  2029. "function_category": "pwm",
  2030. "path": [f"CON168.{pnum} ({net})", dest, f"主板 U3.{ball} ({bsig})"],
  2031. "evidence_tier": "cross_verified",
  2032. "sources": ["FCB_FAN_V2.0_20260914.brd", "docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
  2033. }
  2034. elif pnum in fg_map:
  2035. net, src, ball = fg_map[pnum]
  2036. con168_pins[pnum] = {
  2037. "summary": f"CON168.{pnum} ({net}) ← 直通 {src} 转速反馈 → 主板 FPGA U3.{ball}",
  2038. "direction": "output",
  2039. "external_level": "Tach Open-Collector",
  2040. "function_category": "tach",
  2041. "path": [src, f"CON168.{pnum} ({net})", f"主板 U3.{ball}"],
  2042. "evidence_tier": "cross_verified",
  2043. "sources": ["FCB_FAN_V2.0_20260914.brd", "docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
  2044. }
  2045. else:
  2046. con168_pins[pnum] = {
  2047. "summary": f"CON168.{pnum} (GND) 主控板与风扇板信号共地",
  2048. "direction": "passive",
  2049. "external_level": "0V",
  2050. "function_category": "ground",
  2051. "path": [f"CON168.{pnum} (GND)"],
  2052. "evidence_tier": "cross_verified",
  2053. "sources": ["FCB_FAN_V2.0_20260914.brd"],
  2054. }
  2055. touchpoint_anns: dict[str, Any] = {
  2056. "CON168": {
  2057. "summary": "主控板 14Pin 风扇控制与测速输入座(Pin 5/6/11/12 为 PWM1..4,Pin 1..4/7..10 为 FG1_1..FG4_2,Pin 13/14 为 GND,对接主板 CON155/CON154)",
  2058. "pins": con168_pins,
  2059. }
  2060. }
  2061. fan_out_defs = {
  2062. "CON8": ("1# 前风扇输出座 (FM1或FM5双风机)", "PWM1", "5", "FG1_1", "1", "FG1_2", "3", "F32", "P12/C4", "fan_front_2_0"),
  2063. "CON169": ("2# 后风扇输出座 (FM2或FM6)", "PWM2", "6", "FG2_1", "2", "FG2_2", "4", "F132", "A10/B5", "fan_rear_2_0"),
  2064. "CON170": ("3# 前风扇输出座 (FM3或FM7双风机)", "PWM3", "11", "FG3_1", "7", "FG3_2", "9", "F133", "D8/B1", "fan_front_3_1"),
  2065. "CON171": ("4# 后风扇输出座 (FM4或FM8)", "PWM4", "12", "FG4_1", "8", "FG4_2", "10", "F134", "C7/A14", "fan_rear_3_1"),
  2066. }
  2067. for ref, (title_desc, pwm_net, pwm_pin, fg_a, fg_a_pin, fg_b, fg_b_pin, fuse_ref, ball, bsig) in fan_out_defs.items():
  2068. p_dict: dict[str, Any] = {
  2069. "1": {"summary": f"{ref}.1 +12V 风扇供电正极 (经保险丝 {fuse_ref} 保护)", "direction": "output", "external_level": "+12V DC", "function_category": "power", "path": ["CON2/CON172 (+12V)", fuse_ref, f"{ref}.1"], "evidence_tier": "cross_verified", "sources": ["FCB_FAN_V2.0_20260914.brd"]},
  2070. "2": {"summary": f"{ref}.2 +12V 风扇供电正极 (经保险丝 {fuse_ref} 保护)", "direction": "output", "external_level": "+12V DC", "function_category": "power", "path": ["CON2/CON172 (+12V)", fuse_ref, f"{ref}.2"], "evidence_tier": "cross_verified", "sources": ["FCB_FAN_V2.0_20260914.brd"]},
  2071. "3": {"summary": f"{ref}.3 GND 风扇回路地", "direction": "passive", "external_level": "0V", "function_category": "ground", "path": [f"{ref}.3 (GND)"], "evidence_tier": "cross_verified", "sources": ["FCB_FAN_V2.0_20260914.brd"]},
  2072. "4": {"summary": f"{ref}.4 GND 风扇回路地", "direction": "passive", "external_level": "0V", "function_category": "ground", "path": [f"{ref}.4 (GND)"], "evidence_tier": "cross_verified", "sources": ["FCB_FAN_V2.0_20260914.brd"]},
  2073. "5": {
  2074. "summary": f"{ref}.5 ({fg_a}) 转速反馈输入 → CON168.{fg_a_pin}",
  2075. "direction": "input",
  2076. "external_level": "Tach Open-Collector",
  2077. "function_category": "tach",
  2078. "path": [f"{ref}.5 ({fg_a})", f"CON168.{fg_a_pin}"],
  2079. "evidence_tier": "cross_verified",
  2080. "sources": ["FCB_FAN_V2.0_20260914.brd"],
  2081. },
  2082. "6": {
  2083. "summary": f"{ref}.6 ({fg_b}) 转速反馈输入 → CON168.{fg_b_pin}",
  2084. "direction": "input",
  2085. "external_level": "Tach Open-Collector",
  2086. "function_category": "tach",
  2087. "path": [f"{ref}.6 ({fg_b})", f"CON168.{fg_b_pin}"],
  2088. "evidence_tier": "cross_verified",
  2089. "sources": ["FCB_FAN_V2.0_20260914.brd"],
  2090. },
  2091. "7": {
  2092. "summary": f"{ref}.7 ({pwm_net}) 风扇 PWM 输出 ← CON168.{pwm_pin} ← 主板 FPGA U3.{ball} ({bsig})",
  2093. "direction": "output",
  2094. "external_level": "主板NMOS反相后的开漏PWM;连接器高电平为ON",
  2095. "function_category": "pwm",
  2096. "path": [f"{ref}.7 ({pwm_net})", f"CON168.{pwm_pin}", f"主板 U3.{ball} ({bsig})"],
  2097. "evidence_tier": "cross_verified",
  2098. "sources": ["FCB_FAN_V2.0_20260914.brd", "docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
  2099. },
  2100. "8": {"summary": f"{ref}.8 GND 风扇回路地", "direction": "passive", "external_level": "0V", "function_category": "ground", "path": [f"{ref}.8 (GND)"], "evidence_tier": "cross_verified", "sources": ["FCB_FAN_V2.0_20260914.brd"]},
  2101. }
  2102. touchpoint_anns[ref] = {
  2103. "summary": f"{title_desc}(Pin 1/2: +12V 经 {fuse_ref},Pin 3/4/8: GND,Pin 5/6: {fg_a}/{fg_b},Pin 7: {pwm_net} 直通 CON168.{pwm_pin})",
  2104. "pins": p_dict,
  2105. }
  2106. for ref, role_desc in (("CON2", "外部 DC +12V 主电源输入座"), ("CON172", "DC +12V 电源级联输出座")):
  2107. p_dict = {}
  2108. for p_idx in range(1, 9):
  2109. pnum = str(p_idx)
  2110. if p_idx <= 4:
  2111. p_dict[pnum] = {"summary": f"{ref}.{pnum} (GND) 12V 电源地", "direction": "passive", "external_level": "0V", "function_category": "ground", "path": [f"{ref}.{pnum} (GND)"], "evidence_tier": "cross_verified", "sources": ["FCB_FAN_V2.0_20260914.brd"]}
  2112. else:
  2113. p_dict[pnum] = {"summary": f"{ref}.{pnum} (+12V) 12V 功率主电源轨", "direction": "input" if ref == "CON2" else "output", "external_level": "+12V DC", "function_category": "power", "path": [f"{ref}.{pnum} (+12V)"], "evidence_tier": "cross_verified", "sources": ["FCB_FAN_V2.0_20260914.brd"]}
  2114. touchpoint_anns[ref] = {
  2115. "summary": f"{role_desc}(Pin 1..4 为 GND,Pin 5..8 为 +12V 电源轨)",
  2116. "pins": p_dict,
  2117. }
  2118. fan_interfaces = [
  2119. {
  2120. "id": "fan-ctrl-in",
  2121. "name": "主控板风扇控制输入母座",
  2122. "touchpoint": "CON168",
  2123. "pins": ["5", "6", "11", "12"],
  2124. "external_level": "12V PWM",
  2125. "evidence_tier": "cross_verified",
  2126. "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
  2127. },
  2128. {
  2129. "id": "fan-1",
  2130. "name": "1# 风扇输出 (FM1或FM5双风机)",
  2131. "touchpoint": "CON8",
  2132. "pins": ["1", "2", "3", "4", "5", "6", "7", "8"],
  2133. "external_level": "12V / 5V PWM",
  2134. "evidence_tier": "cross_verified",
  2135. "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
  2136. },
  2137. {
  2138. "id": "fan-2",
  2139. "name": "2# 风扇输出 (FM2或FM6)",
  2140. "touchpoint": "CON169",
  2141. "pins": ["1", "2", "3", "4", "5", "6", "7", "8"],
  2142. "external_level": "12V / 5V PWM",
  2143. "evidence_tier": "cross_verified",
  2144. "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
  2145. },
  2146. {
  2147. "id": "fan-3",
  2148. "name": "3# 风扇输出 (FM3或FM7双风机)",
  2149. "touchpoint": "CON170",
  2150. "pins": ["1", "2", "3", "4", "5", "6", "7", "8"],
  2151. "external_level": "12V / 5V PWM",
  2152. "evidence_tier": "cross_verified",
  2153. "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
  2154. },
  2155. {
  2156. "id": "fan-4",
  2157. "name": "4# 风扇输出 (FM4或FM8)",
  2158. "touchpoint": "CON171",
  2159. "pins": ["1", "2", "3", "4", "5", "6", "7", "8"],
  2160. "external_level": "12V / 5V PWM",
  2161. "evidence_tier": "cross_verified",
  2162. "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
  2163. },
  2164. ]
  2165. return {
  2166. "board_id": "fcb_fan_v2_0_20260914",
  2167. "connector_profiles": connector_profiles,
  2168. "touchpoints": touchpoint_anns,
  2169. "interfaces": fan_interfaces,
  2170. }
  2171. def generate_v2_0_fan_board() -> None:
  2172. print("[V2.0-FAN] Starting FCB_FAN V2.0 (Fan Board) asset generation from Allegro BRD...")
  2173. brd_path = ROOT / "reference/original/board/FCB_FAN_V2.0_20260914/FCB_FAN_V2.0_20260914.brd"
  2174. out_dir = ROOT / "tools/board-viewer/generated-v2_0_fan"
  2175. out_dir.mkdir(parents=True, exist_ok=True)
  2176. parsed_board, cad_meta = parse_allegro_brd(brd_path)
  2177. annotations = _build_v20_fan_annotations()
  2178. fan_board_data = _assemble_board_payload(
  2179. parsed_board,
  2180. annotations,
  2181. board_name="FCB_FAN V2.0 20260914 (风扇扩展板)",
  2182. )
  2183. print(
  2184. f"[V2.0-FAN] Parsed {fan_board_data['counts']['footprints']} footprints, "
  2185. f"{fan_board_data['counts']['touchpoints']} touchpoints ({fan_board_data['counts']['pads']} pads) "
  2186. f"on {parsed_board.bounds['width']}x{parsed_board.bounds['height']} mm board"
  2187. )
  2188. (out_dir / "board-data.json").write_text(
  2189. json.dumps(fan_board_data, indent=2, ensure_ascii=False) + "\n",
  2190. encoding="utf-8",
  2191. )
  2192. generate_svg_layers_from_brd(
  2193. parsed_board,
  2194. cad_meta,
  2195. "FCB_FAN V2.0 20260914",
  2196. fan_board_data["touchpoints"],
  2197. out_dir,
  2198. )
  2199. import_report = {
  2200. "board_id": "fcb_fan_v2_0_20260914",
  2201. "source": "reference/original/board/FCB_FAN_V2.0_20260914/FCB_FAN_V2.0_20260914.brd",
  2202. "source_file": brd_path.name,
  2203. "source_format": "allegro_brd",
  2204. "output_file": "board-data.json",
  2205. "errors": [],
  2206. "timestamp": datetime.now(timezone.utc).isoformat(),
  2207. "stats": {"connectors": fan_board_data["counts"]["touchpoints"], "fuses": 4},
  2208. "status": "success",
  2209. }
  2210. (out_dir / "import-report.json").write_text(json.dumps(import_report, indent=2) + "\n", encoding="utf-8")
  2211. assets_meta: dict[str, dict[str, Any]] = {}
  2212. for asset_file in (out_dir / name for name in (
  2213. "board-data.json", "import-report.json", "board-mask-edge.svg",
  2214. "board-mask-edge-back.svg", "board-copper.svg", "board-copper-back.svg",
  2215. "board-silkscreen.svg", "board-silkscreen-back.svg",
  2216. )):
  2217. if asset_file.is_file():
  2218. assets_meta[asset_file.name] = {
  2219. "sha256": sha256_file(asset_file),
  2220. "bytes": asset_file.stat().st_size,
  2221. }
  2222. build_info = {
  2223. "schema": "board-viewer-build-info-v1",
  2224. "generated_at": datetime.now(timezone.utc).isoformat(),
  2225. "generator_version": "2.1.0",
  2226. "toolchain": {"python": sys.version.split()[0], "kicad": "not_used"},
  2227. "sources": {
  2228. **_generator_sources(),
  2229. "brd": {
  2230. "path": "reference/original/board/FCB_FAN_V2.0_20260914/FCB_FAN_V2.0_20260914.brd",
  2231. "sha256": sha256_file(brd_path),
  2232. },
  2233. "schema_data": {
  2234. "path": "schemas/board_viewer_data.schema.json",
  2235. "sha256": sha256_file(DATA_SCHEMA_PATH),
  2236. },
  2237. "schema_build_info": {
  2238. "path": "schemas/board_viewer_build_info.schema.json",
  2239. "sha256": sha256_file(BUILD_INFO_SCHEMA_PATH),
  2240. },
  2241. },
  2242. "assets": assets_meta,
  2243. "verification": {
  2244. "ipcd356": {
  2245. "status": "not_run",
  2246. "reason": "No independent IPC-D-356 export or alignment comparison was executed by this BRD viewer generator.",
  2247. },
  2248. "side_views": {
  2249. "front_layers": [
  2250. "board-mask-edge.svg",
  2251. "board-silkscreen.svg",
  2252. "board-copper.svg",
  2253. ],
  2254. "back_layers": [
  2255. "board-mask-edge-back.svg",
  2256. "board-silkscreen-back.svg",
  2257. "board-copper-back.svg",
  2258. ],
  2259. "back_mirror_axis": "y",
  2260. "back_svg_export_mirrored": True,
  2261. "convention": "Back SVGs are rendered by this script, mirrored about the vertical/Y axis; viewer hotspot X = board_width - view_position.x. Geometry is simplified, not a KiCad export.",
  2262. },
  2263. },
  2264. "counts": {
  2265. "footprints": fan_board_data["counts"]["footprints"],
  2266. "touchpoints": fan_board_data["counts"]["touchpoints"],
  2267. "pads": fan_board_data["counts"]["pads"],
  2268. "resistors": 0,
  2269. "resistor_pads": 0,
  2270. },
  2271. }
  2272. build_info_schema = json.loads(BUILD_INFO_SCHEMA_PATH.read_text(encoding="utf-8"))
  2273. Draft202012Validator(build_info_schema).validate(build_info)
  2274. (out_dir / "build-info.json").write_text(json.dumps(build_info, indent=2) + "\n", encoding="utf-8")
  2275. print(f"[V2.0-FAN] Asset generation complete! {len(assets_meta)} assets in {out_dir.name}")
  2276. def main() -> None:
  2277. generate_v2_0_mainboard()
  2278. generate_v2_0_fan_board()
  2279. print("\n[SUCCESS] Generated all V2.0 board viewer assets from Allegro BRD binaries!")
  2280. if __name__ == "__main__":
  2281. main()