| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299 |
- #!/usr/bin/env python3
- """Generate board-viewer assets for FCB V2.0 (Mainboard) and FCB_FAN V2.0 (Fan Board).
- Extracts board-viewer data from the supplied Allegro 17.4 BRDs using record-pattern scans.
- Pin/net extraction is distinct from electrical path verification. Geometry is approximate;
- arcs, pad shapes and layer artwork are simplified. This is not a lossless CAD importer:
- - 0x1200 string table, 0x31/0x30 pin text records, 0x00020003 component value records
- - 0x1b net records, 0x04 net connection records, 0x1c padstack records
- - 0x2d placed symbol instances (exact x, y, rotation, side)
- - 0x07 component instances, 0x0d footprint pin definitions, 0x32 placed pin instances
- - 0xfd010014 board outline geometry, 0xf7090014/0xfc090014/0xf6090014 silkscreen outlines
- - 0x00060005/0x05060005 copper clines, 0x15/0x16/0x17/0x01 line/arc segments
- """
- from __future__ import annotations
- from collections import Counter, deque
- from collections.abc import Mapping
- from datetime import datetime, timezone
- import hashlib
- import json
- import math
- from pathlib import Path
- import re
- import struct
- import sys
- from typing import Any
- from jsonschema import Draft202012Validator
- VIEWER_DIR = Path(__file__).resolve().parent
- ROOT = VIEWER_DIR.parents[1]
- if str(VIEWER_DIR) not in sys.path:
- sys.path.insert(0, str(VIEWER_DIR))
- from board_viewer.annotations import expand_annotation_templates
- from board_viewer.data import (
- BOARD_DATA_SCHEMA_ID,
- _apply_connector_profile,
- _attach_related_resistors,
- _build_value_coverage,
- _merge_annotation,
- _merge_programming_annotation,
- _programming_guidance,
- _refresh_recommendation,
- _resistor_dict,
- _touchpoint_dict,
- _unique_strings,
- validate_resistor_index,
- )
- from board_viewer.pcb import (
- Footprint,
- Pad,
- ParsedBoard,
- _footprint_bounds,
- select_resistors,
- select_touchpoints,
- )
- DATA_SCHEMA_PATH = ROOT / "schemas" / "board_viewer_data.schema.json"
- BUILD_INFO_SCHEMA_PATH = ROOT / "schemas" / "board_viewer_build_info.schema.json"
- ANNOTATIONS_V12_PATH = ROOT / "config" / "board_viewer_annotations.fcb_fpga_mcu_v1_2.json"
- POWER_AND_GND_NETS = {
- "GND",
- "AGND",
- "PGND",
- "DGND",
- "+3.3V",
- "+3V3",
- "+5V",
- "+12V",
- "+24V",
- "+24V_VIN",
- "VBUS",
- "VCC",
- "VDD",
- }
- def sha256_file(path: Path | str) -> str:
- h = hashlib.sha256()
- with open(path, "rb") as f:
- while chunk := f.read(1024 * 1024):
- h.update(chunk)
- return h.hexdigest()
- def _generator_sources() -> dict[str, dict[str, str]]:
- paths = {"generator_v20": Path(__file__).resolve()}
- for name in ("annotations", "data", "eligibility", "pcb", "sexpr"):
- paths[f"generator_{name}"] = VIEWER_DIR / "board_viewer" / f"{name}.py"
- return {
- key: {"path": str(path.relative_to(ROOT)), "sha256": sha256_file(path)}
- for key, path in paths.items()
- }
- def _mark_inferred(value: Any) -> None:
- """A reused annotation or graph search does not constitute cross-verification."""
- if isinstance(value, dict):
- if "evidence_tier" in value:
- value["evidence_tier"] = "name_inferred"
- for child in value.values():
- _mark_inferred(child)
- elif isinstance(value, list):
- for child in value:
- _mark_inferred(child)
- def _pad_sort_key(pad: Pad) -> tuple[int, int, str]:
- num = pad.number.strip()
- if not num:
- return (2, 0, "")
- if num.isdigit():
- return (0, int(num), "")
- m = re.match(r"^([A-Za-z]+)(\d+)$", num)
- if m:
- return (1, int(m.group(2)), m.group(1))
- return (1, 0, num)
- # ---------------------------------------------------------------------------
- # Targeted Cadence Allegro 17.4 Binary .brd Extraction
- # ---------------------------------------------------------------------------
- def parse_allegro_brd(brd_path: Path) -> tuple[ParsedBoard, dict[str, Any]]:
- """Parse an Allegro 17.x binary .brd into ParsedBoard + CAD graphics metadata."""
- data = brd_path.read_bytes()
- u32 = struct.unpack(f"<{len(data) // 4}I", data[: len(data) // 4 * 4])
- i32 = struct.unpack(f"<{len(data) // 4}i", data[: len(data) // 4 * 4])
- # 1. String table at 0x1200
- pos = 0x1200
- strings: dict[int, str] = {}
- while pos < len(data) - 8:
- sid = struct.unpack_from("<I", data, pos)[0]
- if sid < 0x7C or sid > 50000:
- break
- end = data.find(b"\x00", pos + 4)
- if end == -1:
- break
- strings[sid] = data[pos + 4 : end].decode("latin1", errors="replace")
- pos = (end + 1 + 3) & ~3
- # 2. Text records (0x31 -> 0x30) for pin numbers
- t31: dict[int, str] = {}
- for idx in range(len(u32) - 8):
- if (u32[idx] & 0xFFFF) == 0x0031 and (u32[idx] >> 24) >= 0xF0:
- oid = u32[idx + 1]
- off = (idx + 7) * 4
- end = data.find(b"\x00", off)
- if end != -1 and end - off < 64:
- t31[oid] = data[off:end].decode("latin1", errors="replace")
- text30: dict[int, str] = {}
- for idx in range(len(u32) - 10):
- if (u32[idx] & 0xFFFF) == 0x0030:
- oid = u32[idx + 1]
- t31_id = u32[idx + 8]
- if t31_id in t31:
- text30[oid] = t31[t31_id]
- # 3. Device value property records (0x00020003)
- dev_val: dict[int, str] = {}
- for idx in range(len(u32) - 10):
- if u32[idx] == 0x00020003:
- dev_id = u32[idx + 3]
- off = (idx + 6) * 4
- end = data.find(b"\x00", off)
- if end != -1 and end - off < 120:
- val = data[off:end].decode("latin1", errors="replace").strip()
- if val:
- dev_val[dev_id] = val
- # 4. Nets (0x1b) and connection pointers (0x04)
- nets: dict[int, str] = {}
- for idx in range(len(u32) - 10):
- if u32[idx] == 0x1B:
- oid = u32[idx + 1]
- nsid = u32[idx + 3]
- if nsid in strings:
- nets[oid] = strings[nsid]
- conn04: dict[int, int] = {}
- for idx in range(len(u32) - 6):
- if (u32[idx] & 0xFF) == 0x04 and (u32[idx] & 0xFFFF00) in (0, 0x0900):
- conn04[u32[idx + 1]] = u32[idx + 2]
- # 5. Padstacks (0x1c) and Footprint Pin Definitions (0x0d)
- padstacks: dict[int, dict[str, Any]] = {}
- for idx in range(len(u32) - 24):
- if u32[idx] == 0x1C:
- psid = u32[idx + 1]
- nsid = u32[idx + 3]
- if nsid in strings:
- ptype = u32[idx + 11]
- drill_raw = i32[idx + 16] / 10000.0
- drill = max(0.0, drill_raw) if ptype != 1 and 0.0 < drill_raw <= 10.0 else 0.0
- padstacks[psid] = {
- "name": strings[nsid],
- "ptype": ptype,
- "drill": round(drill, 4),
- }
- pindefs: dict[int, int] = {}
- for idx in range(len(u32) - 8):
- if u32[idx] == 0x0D:
- pindefs[u32[idx + 1]] = u32[idx + 2]
- # 6. Placed Symbol Instances (0x2d / 0x1002d) and Component Instances (0x07)
- syms: dict[int, dict[str, Any]] = {}
- for idx in range(len(u32) - 10):
- if u32[idx] in (0x2D, 0x1002D) and u32[idx + 4] == 0 and u32[idx + 5] == 0:
- oid = u32[idx + 1]
- syms[oid] = {
- "fpid": u32[idx + 3],
- "side": "back" if (u32[idx] & 0x10000) else "front",
- "rot": round((u32[idx + 7] / 1000.0) % 360.0, 4),
- "x": round(i32[idx + 8] / 10000.0, 4),
- "y": round(i32[idx + 9] / 10000.0, 4),
- }
- sym_to_comp: dict[int, dict[str, str]] = {}
- for idx in range(len(u32) - 10):
- if u32[idx] == 0x07 and u32[idx + 4] == 0 and u32[idx + 5] == 0:
- dev_id = u32[idx + 3]
- sym_id = u32[idx + 6]
- ref_sid = u32[idx + 7]
- pkg_id = u32[idx + 8]
- if ref_sid in strings and sym_id in syms:
- pkg_name = strings.get(pkg_id, "")
- cval = dev_val.get(dev_id, "") or pkg_name
- sym_to_comp[sym_id] = {
- "ref": strings[ref_sid],
- "cval": cval,
- "pkg": pkg_name,
- }
- # 7. Placed Pin Instances (0x32)
- sym_pads: dict[int, list[Pad]] = {}
- comp_pins: dict[str, dict[str, str]] = {}
- net_to_pins: dict[str, list[tuple[str, str]]] = {}
- unassigned_holes: list[tuple[float, float, float]] = []
- for idx in range(len(u32) - 21):
- w0 = u32[idx]
- if (w0 & 0xFF00FF) in (0x0C0032, 0x0C0232):
- sym_id = u32[idx + 7]
- if sym_id not in syms:
- continue
- c04 = u32[idx + 3]
- pdid = u32[idx + 9]
- tid = u32[idx + 15]
- pnum = text30.get(tid, "").strip()
- net = nets.get(conn04.get(c04, 0), "")
- ps = padstacks.get(pindefs.get(pdid, 0), {"name": "", "ptype": 1, "drill": 0.0})
- bx1 = i32[idx + 17] / 10000.0
- by1 = i32[idx + 18] / 10000.0
- bx2 = i32[idx + 19] / 10000.0
- by2 = i32[idx + 20] / 10000.0
- if not (-50.0 <= bx1 <= 600.0 and -50.0 <= by1 <= 600.0):
- continue
- wx = round((bx1 + bx2) / 2.0, 4)
- wy = round((by1 + by2) / 2.0, 4)
- bw = round(max(abs(bx2 - bx1), ps["drill"], 0.24), 4)
- bh = round(max(abs(by2 - by1), ps["drill"], 0.24), 4)
- ptype = ps["ptype"]
- side = syms[sym_id]["side"]
- if sym_id not in sym_to_comp:
- if ptype == 0 or "MTG" in ps["name"].upper():
- unassigned_holes.append((wx, wy, max(ps["drill"], bw)))
- continue
- ref = sym_to_comp[sym_id]["ref"]
- comp_pins.setdefault(ref, {})[pnum] = net
- if net:
- net_to_pins.setdefault(net, []).append((ref, pnum))
- if ptype == 0 or not pnum:
- pad_type = "np_thru_hole"
- layers = ("*.Cu", "*.Mask")
- mech = True
- elif ptype == 1:
- pad_type = "smd"
- layers = ("F.Cu", "F.Mask", "F.Paste") if side == "front" else ("B.Cu", "B.Mask", "B.Paste")
- mech = False
- else:
- pad_type = "thru_hole"
- layers = ("*.Cu", "*.Mask")
- mech = False
- ps_upper = ps["name"].upper()
- if "CIR" in ps_upper or ptype == 0 or (abs(bw - bh) < 0.02 and "REC" not in ps_upper):
- shape = "circle"
- elif "SLOT" in ps_upper or "OB" in ps_upper:
- shape = "oval"
- else:
- shape = "rect"
- pad = Pad(
- number=pnum,
- pad_type=pad_type,
- shape=shape,
- x=wx,
- y=round(-wy, 4),
- width=bw,
- height=bh,
- rotation=0.0,
- net=net if net else None,
- layers=layers,
- drill_width=round(ps["drill"], 4),
- drill_height=round(ps["drill"], 4),
- mechanical=mech,
- electrical=not mech,
- )
- sym_pads.setdefault(sym_id, []).append(pad)
- footprints: list[Footprint] = []
- for sym_id, cinfo in sym_to_comp.items():
- s = syms[sym_id]
- pads = sorted(sym_pads.get(sym_id, []), key=_pad_sort_key)
- fx, fy = s["x"], round(-s["y"], 4)
- fp = Footprint(
- reference=cinfo["ref"],
- component_value=cinfo["cval"],
- x=fx,
- y=fy,
- rotation=s["rot"],
- side=s["side"],
- layer="B.Cu" if s["side"] == "back" else "F.Cu",
- pads=pads,
- bounds=_footprint_bounds(pads, fx, fy),
- )
- footprints.append(fp)
- # 8. Board Outline, Silkscreen Outlines, and Copper Clines
- outline_oids: set[int] = set()
- silk_front_oids: set[int] = set()
- silk_back_oids: set[int] = set()
- cline_front_oids: set[int] = set()
- cline_back_oids: set[int] = set()
- for idx in range(len(u32) - 8):
- w0 = u32[idx]
- oid = u32[idx + 1]
- if w0 == 0xFD010014:
- outline_oids.add(oid)
- elif w0 in (0xF7090014, 0xFC090014) and u32[idx + 3] in syms:
- silk_front_oids.add(oid)
- elif w0 == 0xF6090014 and u32[idx + 3] in syms:
- silk_back_oids.add(oid)
- elif w0 == 0x00060005:
- cline_front_oids.add(oid)
- elif w0 == 0x05060005:
- cline_back_oids.add(oid)
- ox: list[float] = []
- oy: list[float] = []
- silk_front_segs: list[tuple[float, float, float, float, float]] = []
- silk_back_segs: list[tuple[float, float, float, float, float]] = []
- cline_front_segs: list[tuple[float, float, float, float, float]] = []
- cline_back_segs: list[tuple[float, float, float, float, float]] = []
- for idx in range(len(u32) - 12):
- w0 = u32[idx]
- if w0 in (0x15, 0x16, 0x17, 0x01, 0x40000001, 0x80000001):
- parent = u32[idx + 3]
- if (
- parent not in outline_oids
- and parent not in silk_front_oids
- and parent not in silk_back_oids
- and parent not in cline_front_oids
- and parent not in cline_back_oids
- ):
- continue
- width = max(0.12, min(1.2, u32[idx + 6] / 10000.0))
- x1 = i32[idx + 7] / 10000.0
- y1 = i32[idx + 8] / 10000.0
- x2 = i32[idx + 9] / 10000.0
- y2 = i32[idx + 10] / 10000.0
- 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):
- continue
- if abs(x1 - x2) < 1e-4 and abs(y1 - y2) < 1e-4:
- continue
- if parent in outline_oids:
- ox.extend([x1, x2])
- oy.extend([y1, y2])
- elif parent in silk_front_oids:
- silk_front_segs.append((x1, y1, x2, y2, width))
- elif parent in silk_back_oids:
- silk_back_segs.append((x1, y1, x2, y2, width))
- elif parent in cline_front_oids:
- cline_front_segs.append((x1, y1, x2, y2, width))
- elif parent in cline_back_oids:
- cline_back_segs.append((x1, y1, x2, y2, width))
- board_w = round(max(ox) - min(ox), 4) if ox else 430.0
- board_h = round(max(oy) - min(oy), 4) if oy else 60.0
- bounds = {"x": 0.0, "y": round(-board_h, 4), "width": board_w, "height": board_h}
- parsed_board = ParsedBoard(
- footprints=footprints,
- footprint_count=len(footprints),
- bounds=bounds,
- )
- cad_meta = {
- "comp_pins": comp_pins,
- "net_to_pins": net_to_pins,
- "silk_front_segs": silk_front_segs,
- "silk_back_segs": silk_back_segs,
- "cline_front_segs": cline_front_segs,
- "cline_back_segs": cline_back_segs,
- "unassigned_holes": unassigned_holes,
- }
- return parsed_board, cad_meta
- def trace_net_to_u3_u27(
- start_ref: str,
- start_pin: str,
- comp_pins: Mapping[str, Mapping[str, str]],
- net_to_pins: Mapping[str, list[tuple[str, str]]],
- ) -> tuple[str, tuple[str, str, str, list[str], list[str]] | None]:
- """Return a structural path candidate to U3/U27, not verified conduction.
- This search crosses component pins without checking fitted/NC options or
- transistor gate/source/drain behavior. Its result must remain name_inferred;
- it cannot prove a usable GPIO, polarity, voltage or populated signal path.
- """
- start_net = comp_pins.get(start_ref, {}).get(start_pin, "")
- if not start_net or start_net in POWER_AND_GND_NETS:
- return start_net, None
- queue: deque[tuple[str, list[str], list[str]]] = deque(
- [(start_net, [f"{start_ref}.{start_pin} ({start_net})"], [])]
- )
- visited_nets = {start_net}
- visited_comps = {start_ref}
- while queue:
- net, path, ext_comps = queue.popleft()
- for r, p in net_to_pins.get(net, []):
- if r == "U3":
- return start_net, ("U3", p, net, [*path, f"U3.{p} ({net})"], ext_comps)
- if r == "U27":
- return start_net, ("U27", p, net, [*path, f"U27.{p} ({net})"], ext_comps)
- if len(path) >= 6:
- continue
- for r, p in net_to_pins.get(net, []):
- if r in visited_comps or r.startswith(("C", "CON", "J", "TP", "PL", "U")):
- continue
- pins_of_r = comp_pins.get(r, {})
- if len(pins_of_r) <= 6:
- visited_comps.add(r)
- for p2, n2 in pins_of_r.items():
- if p2 != p and n2 and n2 not in POWER_AND_GND_NETS and n2 not in visited_nets:
- visited_nets.add(n2)
- new_ext = [*ext_comps, f"{r}.{p}->{p2}" if r.startswith("R") else r]
- queue.append((n2, [*path, f"{r}.{p}->{p2} ({n2})"], new_ext))
- return start_net, None
- # ---------------------------------------------------------------------------
- # Derived SVG Layer Renderer (simplified geometry)
- # ---------------------------------------------------------------------------
- def generate_svg_layers_from_brd(
- parsed_board: ParsedBoard,
- cad_meta: Mapping[str, Any],
- title: str,
- touchpoints: list[dict[str, Any]],
- out_dir: Path,
- ) -> None:
- """Render simplified SVG layers from parsed Allegro geometry; not a lossless CAD export."""
- out_dir.mkdir(parents=True, exist_ok=True)
- board_w = float(parsed_board.bounds["width"])
- board_h = float(parsed_board.bounds["height"])
- # Collect mounting holes (NPTH pads + unassigned MTG holes)
- mounting_holes: list[tuple[float, float, float]] = []
- for hx, hy, hd in cad_meta.get("unassigned_holes", []):
- mounting_holes.append((hx, board_h - hy, hd / 2.0))
- for fp in parsed_board.footprints:
- for pad in fp.pads:
- if pad.pad_type == "np_thru_hole" and pad.drill_width >= 1.0:
- mounting_holes.append((pad.x, board_h + pad.y, pad.drill_width / 2.0))
- # --- 1. MASK & EDGE ---
- def build_mask(side: str) -> str:
- bg_col = "#eef7f2"
- inner_stroke = "#cde7d8"
- border_stroke = "#64748b"
- lines = [
- '<?xml version="1.0" encoding="UTF-8"?>',
- 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">',
- f' <title>{title} - {"Front" if side == "front" else "Back"} Mask & Edge</title>',
- 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"/>',
- 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"/>',
- " <!-- Soldermask Openings -->",
- ' <g fill="#fbbf24" stroke="#b45309" stroke-width="0.05">',
- ]
- for fp in parsed_board.footprints:
- for pad in fp.pads:
- if pad.pad_type == "np_thru_hole":
- continue
- is_th = "*.Mask" in pad.layers or pad.drill_width > 0
- if (side == "front" and ("F.Mask" in pad.layers or is_th)) or (
- side == "back" and ("B.Mask" in pad.layers or is_th)
- ):
- vx = pad.x
- vy = board_h + pad.y
- if side == "back":
- vx = board_w - vx
- pw = pad.width + 0.06
- ph = pad.height + 0.06
- if pad.shape == "circle":
- r = max(pw, ph) / 2.0
- lines.append(f' <circle cx="{vx:.3f}" cy="{vy:.3f}" r="{r:.3f}"/>')
- else:
- rx_attr = f' rx="{min(pw, ph)/2:.3f}"' if pad.shape == "oval" else ""
- lines.append(
- f' <rect x="{vx - pw/2:.3f}" y="{vy - ph/2:.3f}" width="{pw:.3f}" height="{ph:.3f}"{rx_attr}/>'
- )
- if pad.drill_width > 0:
- lines.append(
- f' <circle cx="{vx:.3f}" cy="{vy:.3f}" r="{pad.drill_width/2:.3f}" fill="#1e293b" stroke="none"/>'
- )
- for hx, hy, hr in mounting_holes:
- vx = board_w - hx if side == "back" else hx
- lines.append(
- f' <circle cx="{vx:.3f}" cy="{hy:.3f}" r="{hr + 0.45:.3f}" fill="#cbd5e1" stroke="#64748b" stroke-width="0.08"/>'
- )
- lines.append(f' <circle cx="{vx:.3f}" cy="{hy:.3f}" r="{hr:.3f}" fill="#1e293b" stroke="none"/>')
- lines.append(" </g>")
- lines.append("</svg>")
- return "\n".join(lines) + "\n"
- # --- 2. COPPER ---
- def build_copper(side: str) -> str:
- segs = cad_meta["cline_front_segs"] if side == "front" else cad_meta["cline_back_segs"]
- lines = [
- '<?xml version="1.0" encoding="UTF-8"?>',
- 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">',
- f' <title>{title} - {"Front" if side == "front" else "Back"} Copper</title>',
- ' <g id="copper-tracks" stroke="#529b7a" stroke-opacity="0.26" stroke-linecap="round" fill="none">',
- ]
- # Group segments by rounded width for compact SVG path output
- by_width: dict[float, list[str]] = {}
- for x1, y1, x2, y2, w in segs:
- vx1 = board_w - x1 if side == "back" else x1
- vy1 = board_h - y1
- vx2 = board_w - x2 if side == "back" else x2
- vy2 = board_h - y2
- rw = round(max(0.15, min(0.8, w)), 2)
- by_width.setdefault(rw, []).append(f"M{vx1:.2f} {vy1:.2f}L{vx2:.2f} {vy2:.2f}")
- for rw, d_parts in sorted(by_width.items()):
- for i in range(0, len(d_parts), 200):
- chunk = "".join(d_parts[i : i + 200])
- lines.append(f' <path stroke-width="{rw:.2f}" d="{chunk}"/>')
- lines.append(" </g>")
- lines.append(' <g id="pads" fill="#fbbf24" stroke="#b45309" stroke-width="0.05">')
- for fp in parsed_board.footprints:
- for pad in fp.pads:
- if pad.pad_type == "np_thru_hole":
- continue
- is_th = "*.Cu" in pad.layers or pad.drill_width > 0
- if (side == "front" and ("F.Cu" in pad.layers or is_th)) or (
- side == "back" and ("B.Cu" in pad.layers or is_th)
- ):
- vx = pad.x
- vy = board_h + pad.y
- if side == "back":
- vx = board_w - vx
- pw = pad.width
- ph = pad.height
- if pad.shape == "circle":
- r = max(pw, ph) / 2.0
- lines.append(f' <circle cx="{vx:.3f}" cy="{vy:.3f}" r="{r:.3f}"/>')
- else:
- rx_attr = f' rx="{min(pw, ph)/2:.3f}"' if pad.shape == "oval" else ""
- lines.append(
- f' <rect x="{vx - pw/2:.3f}" y="{vy - ph/2:.3f}" width="{pw:.3f}" height="{ph:.3f}"{rx_attr}/>'
- )
- if pad.drill_width > 0:
- lines.append(
- f' <circle cx="{vx:.3f}" cy="{vy:.3f}" r="{pad.drill_width/2:.3f}" fill="#1e293b" stroke="none"/>'
- )
- lines.append(" </g>")
- lines.append("</svg>")
- return "\n".join(lines) + "\n"
- # --- 3. SILKSCREEN ---
- def build_silkscreen(side: str) -> str:
- segs = cad_meta["silk_front_segs"] if side == "front" else cad_meta["silk_back_segs"]
- lines = [
- '<?xml version="1.0" encoding="UTF-8"?>',
- 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">',
- f' <title>{title} - {"Front" if side == "front" else "Back"} Silkscreen</title>',
- ' <g id="silkscreen-outlines" stroke="#0f172a" stroke-width="0.14" stroke-linecap="round" fill="none">',
- ]
- d_parts: list[str] = []
- for x1, y1, x2, y2, _w in segs:
- vx1 = board_w - x1 if side == "back" else x1
- vy1 = board_h - y1
- vx2 = board_w - x2 if side == "back" else x2
- vy2 = board_h - y2
- d_parts.append(f"M{vx1:.2f} {vy1:.2f}L{vx2:.2f} {vy2:.2f}")
- for i in range(0, len(d_parts), 200):
- chunk = "".join(d_parts[i : i + 200])
- lines.append(f' <path d="{chunk}"/>')
- lines.append(" </g>")
- lines.append(' <g id="silkscreen-labels" fill="#0f172a" font-family="monospace, sans-serif" font-weight="bold">')
- for tp in touchpoints:
- if tp.get("side", "front") != side:
- continue
- ref = str(tp["reference"])
- if ref.startswith("J") and len(tp.get("pins", [])) == 1 and tp["pins"][0].get("mechanical"):
- continue
- vb = tp["view_bounds"]
- bx = board_w - (vb["x"] + vb["width"]) if side == "back" else vb["x"]
- by = vb["y"]
- bw = vb["width"]
- bh = vb["height"]
- tx = bx + bw / 2.0
- ty = by - 0.35 if by > 2.2 else by + bh + 0.95
- lines.append(f' <text x="{tx:.2f}" y="{ty:.2f}" font-size="0.82" text-anchor="middle">{ref}</text>')
- for fp in parsed_board.footprints:
- if fp.side != side:
- continue
- if re.match(r"^(U|F)\d+$", fp.reference):
- vx = board_w - fp.x if side == "back" else fp.x
- vy = board_h + fp.y
- fsize = "1.15" if fp.reference in ("U3", "U27") else "0.72"
- lines.append(
- f' <text x="{vx:.2f}" y="{vy + 0.3:.2f}" font-size="{fsize}" text-anchor="middle">{fp.reference}</text>'
- )
- lines.append(" </g>")
- lines.append("</svg>")
- return "\n".join(lines) + "\n"
- (out_dir / "board-mask-edge.svg").write_text(build_mask("front"), encoding="utf-8")
- (out_dir / "board-mask-edge-back.svg").write_text(build_mask("back"), encoding="utf-8")
- (out_dir / "board-silkscreen.svg").write_text(build_silkscreen("front"), encoding="utf-8")
- (out_dir / "board-silkscreen-back.svg").write_text(build_silkscreen("back"), encoding="utf-8")
- (out_dir / "board-copper.svg").write_text(build_copper("front"), encoding="utf-8")
- (out_dir / "board-copper-back.svg").write_text(build_copper("back"), encoding="utf-8")
- # ---------------------------------------------------------------------------
- # Build V2.0 Mainboard Annotations & Connector Profiles
- # ---------------------------------------------------------------------------
- def _build_v20_annotations(
- parsed_board: ParsedBoard,
- cad_meta: Mapping[str, Any],
- pin_inv: Mapping[str, Any],
- ) -> dict[str, Any]:
- """Build complete V2.0 annotations combining V1.2 shared touchpoints + V2.0 pin inventory + BRD net trace."""
- v12_raw = json.loads(ANNOTATIONS_V12_PATH.read_text(encoding="utf-8"))
- v12_expanded = expand_annotation_templates(v12_raw)
- v12_tps = v12_expanded.get("touchpoints", {})
- comp_pins = cad_meta["comp_pins"]
- net_to_pins = cad_meta["net_to_pins"]
- connector_profiles = {
- "CON_11251W00_NPX_SX_4P": {
- "references": [
- "CON12",
- "CON54",
- "CON70",
- "CON77",
- "CON103",
- "CON126",
- "CON134",
- "CON144",
- "CON145",
- "CON146",
- "CON164",
- "CON171",
- ],
- "contact_pins": ["1", "2", "3", "4"],
- "shield_pads": ["5", "6"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- "CON_51541_00301_V01_3P": {
- "references": ["CON53", "CON55", "CON56", "CON57", "CON79", "CON80", "CON81", "CON82"],
- "contact_pins": ["1", "2", "3"],
- "shield_pads": ["4", "5"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- "CON_3110_20P_P2D54": {
- "references": ["CON147", "CON148", "CON149", "CON150"],
- "contact_pins": [str(i) for i in range(1, 21)],
- "shield_pads": [],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- },
- "CON_SMD_2D54_2X7P": {
- "references": [
- "CON154",
- "CON155",
- "CON156",
- "CON157",
- "CON158",
- "CON159",
- "CON160",
- "CON161",
- "CON162",
- "CON163",
- "CON165",
- "CON166",
- ],
- "contact_pins": [str(i) for i in range(1, 15)],
- "shield_pads": ["15", "16"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- },
- "HDR_1X4P_P2D54": {
- "references": ["CON168"],
- "contact_pins": ["1", "2", "3", "4"],
- "shield_pads": [],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- "RJ45_RJHSE538X_12P": {
- "references": ["CON170"],
- "contact_pins": [str(i) for i in range(1, 13)],
- "shield_pads": ["13", "14"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- "USBC_16P_U263": {
- "references": ["CON172"],
- "contact_pins": [
- "A1",
- "A4",
- "A5",
- "A6",
- "A7",
- "A9",
- "A12",
- "B1",
- "B4",
- "B5",
- "B6",
- "B7",
- "B9",
- "B12",
- ],
- "shield_pads": ["1", "2", "3", "4"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- "CON_3110_12P_P4D2": {
- "references": ["CON173", "CON174"],
- "contact_pins": [str(i) for i in range(1, 13)],
- "shield_pads": [],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- },
- "J3_FPGA_JTAG_2X5": v12_expanded["connector_profiles"]["J3_FPGA_JTAG_2X5"],
- "J19_FPGA_BANK1_DEBUG_1X5": v12_expanded["connector_profiles"]["J19_FPGA_BANK1_DEBUG_1X5"],
- "J25_GD32_SWD_1X5": v12_expanded["connector_profiles"]["J25_GD32_SWD_1X5"],
- "J_GD32_HEADER_2X5": {
- "references": ["J29", "J30"],
- "contact_pins": [str(i) for i in range(1, 11)],
- "shield_pads": [],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- }
- # Copy shared touchpoints from V1.2 annotations and adapt to V2.0
- touchpoint_anns: dict[str, Any] = {}
- v2_tp_refs = {fp.reference for fp in select_touchpoints(parsed_board)}
- for ref in v2_tp_refs:
- if ref in v12_tps:
- touchpoint_anns[ref] = json.loads(json.dumps(v12_tps[ref]))
- _mark_inferred(touchpoint_anns[ref])
- touchpoint_anns[ref]["summary"] = (
- "V1.2 参考注释,V2.0 未逐项复核:" + touchpoint_anns[ref].get("summary", ref)
- )
- # Fix V2.0-specific differences on shared touchpoints:
- # 1. CON12 is 6400 V2.0 Host TTL (R1875/R1876 instead of V1.2 R1307/R1308)
- touchpoint_anns["CON12"] = {
- "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)",
- "pins": {
- "1": {
- "summary": "CON12.1 +3.3V 板内电源参考(跨板连接不并接)",
- "direction": "passive",
- "external_level": "+3.3V",
- "function_category": "power",
- "reserved": True,
- "path": ["CON12.1 +3.3V"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- },
- "2": {
- "summary": "CON12.2 GND 串口信号共地(接 STM32H7 P1.19 GND)",
- "direction": "passive",
- "external_level": "0V",
- "function_category": "ground",
- "path": ["CON12.2 GND"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- },
- "3": {
- "summary": "CON12.3 (EX_GPIO1) Host TTL TX → R1875 → FPGA U3.K2 (host_ttl_tx) ↔ STM32H7 P1.26 (PB11)",
- "direction": "output",
- "external_level": "3.3V LVCMOS",
- "function_category": "uart_tx",
- "external_components": ["R1875", "STM32H7 P1.26 (PB11)"],
- "path": ["CON12.3 (EX_GPIO1)", "R1875.2->1 (CPLD_GPIO79)", "U3.K2 (host_ttl_tx)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- "fpga": {
- "ball": "K2",
- "board_signal": "EX_GPIO1",
- "io_standard": "LVCMOS33",
- "capabilities": ["uart_tx", "gpio_output", "gpio"],
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- },
- "4": {
- "summary": "CON12.4 (EX_GPIO2) Host TTL RX ← R1876 ← FPGA U3.J4 (host_ttl_rx) ↔ STM32H7 P1.25 (PB10)",
- "direction": "input",
- "external_level": "3.3V LVCMOS",
- "function_category": "uart_rx",
- "external_components": ["R1876", "STM32H7 P1.25 (PB10)"],
- "path": ["CON12.4 (EX_GPIO2)", "R1876.2->1 (CPLD_GPIO80)", "U3.J4 (host_ttl_rx)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- "fpga": {
- "ball": "J4",
- "board_signal": "EX_GPIO2",
- "io_standard": "LVCMOS33",
- "capabilities": ["uart_rx", "gpio_input", "gpio"],
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- },
- },
- }
- # 2. CON54 in V2.0 has R572/R574 removed (uses R573/R747 and R575/R748)
- if "CON54" in touchpoint_anns:
- for pnum, r_list in (("1", ["R573", "R747"]), ("2", ["R575", "R748"])):
- p_ann = touchpoint_anns["CON54"].get("pins", {}).get(pnum, {})
- p_ann["external_components"] = r_list
- p_ann["path"] = [
- f"CON54.{pnum}",
- f"{r_list[0]}",
- f"{r_list[1]}",
- f"U3.{'A9' if pnum == '1' else 'C9'}",
- ]
- # These V2.0 LED outputs use HL2309 and fitted +24V selection resistors.
- # Replace the inherited V1.2 pin annotation (12V/AO3415A) as one object.
- for ref, number, ball, series, gate, nmos, pmos, supply, option in (
- ("CON144", 1, "G6", "R1299", "R1274", "Q10617", "Q10616", "R1281", "R1282"),
- ("CON145", 2, "F5", "R1300", "R1290", "Q10619", "Q10618", "R1287", "R1288"),
- ):
- touchpoint_anns[ref]["summary"] = (
- f"V2.0 LED/按键连接器{number}:Pin1为24V KEYLED功率输出,由U3.{ball}控制;"
- "Pin3为按键输入,Pin2/4为GND;Host TTL使用CON12。"
- )
- touchpoint_anns[ref]["pins"]["1"] = {
- "summary": f"U3.{ball}经{series}/{gate}、{nmos} 2N7002和{pmos} HL2309控制KEYLED_V{number};{supply}已装接+24V,{option}的+5V选项未装。不是TTL。",
- "direction": "output", "external_level": "+24V switched power",
- "function_category": "power", "reserved": True,
- "fixed_load_conflict": True, "evidence_tier": "cross_verified",
- "fpga": None,
- "path": [f"U3.{ball}", series, gate, nmos, pmos, f"{ref}.1 (KEYLED_V{number})"],
- "external_components": [series, gate, nmos, pmos, supply, option],
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "evidence/hardware/20261023/main_bom.csv", "evidence/hardware/20261023/main_pins.csv"],
- }
- # V2.0 R1294 is fitted to +24V; V1.2 uses +12V at the same reference.
- # Neither assembly makes this power LED output a TTL UART.
- touchpoint_anns["CON146"] = {
- "summary": "按键/指示灯扩展座3:Pin1为24V KEYLED功率输出,Pin3为按键输入,Pin2/4为GND;Host TTL使用CON12。",
- "pins": {
- "1": {
- "summary": "H6经R1301/R1297、Q10621 NMOS和Q10620 PMOS控制KEYLED_V3;R1294已装接+24V,R1295的+5V选项未装。不是TTL。",
- "direction": "output", "external_level": "+24V switched power",
- "function_category": "power", "reserved": True,
- "fixed_load_conflict": True, "evidence_tier": "cross_verified",
- "path": ["U3.H6", "R1301", "R1297", "Q10621", "Q10620", "CON146.1 (KEYLED_V3)"],
- "external_components": ["R1301", "R1297", "Q10621", "Q10620", "R1294", "R1295"],
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- "3": {
- "summary": "CON146.3 KEY3_CON经R1293/R1110接U3.N7;按键输入网络带RC,不作为Host TTL。",
- "direction": "input", "external_level": "3.3V key input with RC",
- "function_category": "gpio_input", "reserved": True,
- "evidence_tier": "cross_verified",
- "path": ["CON146.3 (KEY3_CON)", "R1293", "R1110", "U3.N7"],
- "external_components": ["R1293", "R1110"],
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- **{p: {"summary": f"CON146.{p} GND", "direction": "passive",
- "external_level": "0V", "function_category": "ground",
- "path": [f"CON146.{p} (GND)"], "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"]} for p in ("2", "4")},
- },
- }
- # 3b. CON134 is 6400 V2.0 active Host RS-232 (Pin 1 TX -> U22 -> R1225 -> U3.T14, Pin 2 RX <- U22 <- R1226 <- U3.R13)
- touchpoint_anns["CON134"] = {
- "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)",
- "pins": {
- "1": {
- "summary": "CON134.1 (RS232_TX3) → TRSF3232EIPWR U22.7/10 → R1225 → FPGA U3.T14 (host_rs232_tx)",
- "direction": "output",
- "external_level": "RS232",
- "function_category": "uart_tx",
- "external_components": ["U22", "R1225"],
- "path": ["CON134.1 (RS232_TX3)", "U22.7->10 (UART3_TX)", "R1225.2->1 (BANK2_LVDS8_N)", "U3.T14 (host_rs232_tx)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- "fpga": {
- "ball": "T14",
- "board_signal": "RS232_TX3",
- "io_standard": "LVCMOS33",
- "capabilities": ["uart_tx", "rs232_via_transceiver"],
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- },
- "2": {
- "summary": "CON134.2 (RS232_RX3) ← TRSF3232EIPWR U22.8/9 ← R1226 ← FPGA U3.R13 (host_rs232_rx)",
- "direction": "input",
- "external_level": "RS232",
- "function_category": "uart_rx",
- "external_components": ["U22", "R1226"],
- "path": ["CON134.2 (RS232_RX3)", "U22.8->9 (UART3_RX)", "R1226.2->1 (BANK2_LVDS8_P)", "U3.R13 (host_rs232_rx)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- "fpga": {
- "ball": "R13",
- "board_signal": "RS232_RX3",
- "io_standard": "LVCMOS33",
- "capabilities": ["uart_rx", "rs232_via_transceiver"],
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- },
- "3": {
- "summary": "CON134.3 GND 串口地",
- "direction": "passive",
- "external_level": "0V",
- "function_category": "ground",
- "path": ["CON134.3 (GND)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- "4": {
- "summary": "CON134.4 GND 串口地",
- "direction": "passive",
- "external_level": "0V",
- "function_category": "ground",
- "path": ["CON134.4 (GND)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- },
- }
- # 3c. CON77 is BMC RS-232 (Pin 1 TX -> U22 -> R818 -> U3.L10, Pin 2 RX <- U22 <- R819 <- U3.M9)
- touchpoint_anns["CON77"] = {
- "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)",
- "pins": {
- "1": {
- "summary": "CON77.1 (RS232_TX1) → TRSF3232EIPWR U22.14/11 → R818 → FPGA U3.L10 (bmc_tx, 115200 8N1)",
- "direction": "output",
- "external_level": "RS232",
- "function_category": "uart_tx",
- "external_components": ["U22", "R818"],
- "path": ["CON77.1 (RS232_TX1)", "U22.14->11 (UART1_TX)", "R818.2->1 (BANK2_GPIO52)", "U3.L10 (bmc_tx)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- "fpga": {
- "ball": "L10",
- "board_signal": "RS232_TX1",
- "io_standard": "LVCMOS33",
- "capabilities": ["uart_tx", "rs232_via_transceiver"],
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- },
- "2": {
- "summary": "CON77.2 (RS232_RX1) ← TRSF3232EIPWR U22.13/12 ← R819 ← FPGA U3.M9 (bmc_rx, 115200 8N1)",
- "direction": "input",
- "external_level": "RS232",
- "function_category": "uart_rx",
- "external_components": ["U22", "R819"],
- "path": ["CON77.2 (RS232_RX1)", "U22.13->12 (UART1_RX)", "R819.2->1 (BANK2_GPIO53)", "U3.M9 (bmc_rx)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- "fpga": {
- "ball": "M9",
- "board_signal": "RS232_RX1",
- "io_standard": "LVCMOS33",
- "capabilities": ["uart_rx", "rs232_via_transceiver"],
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- },
- "3": {
- "summary": "CON77.3 GND 串口地",
- "direction": "passive",
- "external_level": "0V",
- "function_category": "ground",
- "path": ["CON77.3 (GND)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- "4": {
- "summary": "CON77.4 GND 串口地",
- "direction": "passive",
- "external_level": "0V",
- "function_category": "ground",
- "path": ["CON77.4 (GND)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- },
- }
- # 3d. CON103 on V2.0: schematic Page 4/9 labels "-CON103 MCU串口连接器" wired to -U6-2 TX1/RX1,
- # 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).
- touchpoint_anns["CON103"] = {
- "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)",
- "pins": {
- "1": {
- "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)",
- "direction": "bidirectional",
- "external_level": "3.3V LVCMOS",
- "function_category": "mcu_gpio",
- "reserved": True,
- "fixed_load_conflict": False,
- "external_components": ["R1029", "R1921", "U33"],
- "path": ["CON103.1 (MCU_UART1_TX_CON)", "R1029.2->1 (MCU_UART1_TX)", "U27.12 (PA2)", "R1921 -> CP2102 U33"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- "mcu": {
- "device": "U27",
- "family": "STM32F103CBT6",
- "pin": "12",
- "signal": "PA2/MCU_UART1_TX",
- "capabilities": ["gpio", "firmware_configurable", "mcu_uart_tx"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- },
- "2": {
- "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)",
- "direction": "bidirectional",
- "external_level": "3.3V LVCMOS",
- "function_category": "mcu_gpio",
- "reserved": True,
- "fixed_load_conflict": False,
- "external_components": ["R1030", "R1920", "U33"],
- "path": ["CON103.2 (MCU_UART1_RX_CON)", "R1030.2->1 (MCU_UART1_RX)", "U27.13 (PA3)", "R1920 -> CP2102 U33"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- "mcu": {
- "device": "U27",
- "family": "STM32F103CBT6",
- "pin": "13",
- "signal": "PA3/MCU_UART1_RX",
- "capabilities": ["gpio", "firmware_configurable", "mcu_uart_rx"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- },
- "3": {
- "summary": "CON103.3 +3.3V 电源参考",
- "direction": "passive",
- "external_level": "+3.3V",
- "function_category": "power",
- "reserved": True,
- "fixed_load_conflict": True,
- "path": ["CON103.3 (+3.3V)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- "4": {
- "summary": "CON103.4 GND 串口参考地(电气图第4/9页接 -U6-2 P1.19 GND3)",
- "direction": "passive",
- "external_level": "0V",
- "function_category": "ground",
- "reserved": True,
- "fixed_load_conflict": True,
- "path": ["CON103.4 (GND)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- },
- },
- }
- # 3e. CON53..CON82 temperature probe labels from Page 4 of 温控板测试V2.0电气图
- v20_probe_labels = {
- "CON53": "1#腔室温度1(进风口)— CT7428 U6 远端温度通道 1(DP1/DN 二极管差分接口)",
- "CON55": "1#腔室温度2(出风口)— CT7428 U6 远端温度通道 2(DP2/DN 二极管差分接口)",
- "CON56": "2#腔室温度1(进风口)— CT7428 U6 远端温度通道 3(DP3/DN 二极管差分接口)",
- "CON57": "2#腔室温度2(出风口)— CT7428 U6 远端温度通道 4(DP4/DN 二极管差分接口)",
- "CON79": "3#腔室温度1(进风口)— CT7428 U6 远端温度通道 5(DP5/DN 二极管差分接口)",
- "CON80": "3#腔室温度2(出风口)— CT7428 U6 远端温度通道 6(DP6/DN 二极管差分接口)",
- "CON81": "4#腔室温度1(进风口)— CT7428 U6 远端温度通道 7(DP7/DN 二极管差分接口)",
- "CON82": "4#腔室温度2(出风口)— CT7428 U6 远端温度通道 8(DP8/DN 二极管差分接口)",
- }
- for probe_ref, probe_summary in v20_probe_labels.items():
- if probe_ref in touchpoint_anns:
- touchpoint_anns[probe_ref]["summary"] = probe_summary
- # 4. Build PTC lookup from pin_inventory
- ptc_active_map: dict[str, dict[str, Any]] = {}
- for item in pin_inv.get("ptc_channels", []):
- conn_str = str(item["connector"])
- if "/" in conn_str:
- base_ref, pin_pair = conn_str.split(".", 1)
- for p_part in pin_pair.split("/"):
- ptc_active_map[f"{base_ref}.{p_part}"] = item
- else:
- ptc_active_map[conn_str] = item
- # CON147, CON148, CON149, CON150 (20-pin PTC headers, 30W/24V heaters on Page 8)
- ptc_summaries = {
- "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)",
- "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)",
- "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)",
- "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)",
- }
- for ref in ("CON147", "CON148", "CON149", "CON150"):
- pins_dict: dict[str, Any] = {}
- for p_idx in range(1, 21):
- pnum = str(p_idx)
- key = f"{ref}.{pnum}"
- net, hit = trace_net_to_u3_u27(ref, pnum, comp_pins, net_to_pins)
- if p_idx % 2 == 0:
- pins_dict[pnum] = {
- "summary": f"{key} PTC 加热回路功率地 (PGND)",
- "direction": "passive",
- "external_level": "0V",
- "function_category": "ground",
- "path": [f"{key} (PGND)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- }
- elif hit is not None:
- _dev, ball, fpga_net, path_list, ext_list = hit
- active_info = ptc_active_map.get(key)
- if active_info is not None:
- idx = active_info["index"]
- role_txt = f"ptc_pwm_out[{idx}] (6400 V2.0 已启用, 30W/24V)"
- else:
- role_txt = f"{net} 预留加热通道 (6400 V2.0 未启用)"
- pins_dict[pnum] = {
- "summary": f"{key} ({net}) → FPGA U3.{ball} ({role_txt})",
- "direction": "output",
- "external_level": "24V PTC PWM",
- "function_category": "pwm",
- "active_level": "high",
- "polarity": "normal",
- "external_components": ext_list,
- "path": path_list,
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- "fpga": {
- "ball": ball,
- "board_signal": net,
- "io_standard": "LVCMOS33",
- "capabilities": ["pwm", "gpio_output"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- }
- touchpoint_anns[ref] = {"summary": ptc_summaries[ref], "pins": pins_dict}
- # CON154..CON158 (14-pin + 2-shield Fan headers)
- fan_active_map = {item["connector"]: item for item in pin_inv.get("fan_channels", [])}
- fan_summaries = {
- "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)",
- "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)",
- "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)",
- "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)",
- "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)",
- }
- for ref in ("CON154", "CON155", "CON156", "CON157", "CON158"):
- pins_dict = {}
- for p_idx in range(1, 15):
- pnum = str(p_idx)
- key = f"{ref}.{pnum}"
- net, hit = trace_net_to_u3_u27(ref, pnum, comp_pins, net_to_pins)
- if p_idx in (13, 14):
- pins_dict[pnum] = {
- "summary": f"{key} 风扇控制共地 (GND)",
- "direction": "passive",
- "external_level": "0V",
- "function_category": "ground",
- "path": [f"{key} (GND)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- }
- elif hit is not None:
- _dev, ball, _fpga_net, path_list, ext_list = hit
- if p_idx in (5, 6, 11, 12):
- f_act = fan_active_map.get(key)
- if f_act is not None:
- rtl_sig = f"fan_{f_act['group']}_out[{f_act['index']}]"
- desc = f"{key} ({net}) → 经 {f_act['nmos']} 2N7002 反相 → FPGA U3.{ball} ({rtl_sig})"
- else:
- desc = f"{key} ({net}) → 经 NMOS 反相 → FPGA U3.{ball}(备用风扇 PWM)"
- pins_dict[pnum] = {
- "summary": desc,
- "direction": "output",
- "external_level": "主板NMOS反相后的开漏PWM;连接器高电平为ON",
- "function_category": "pwm",
- "active_level": "FPGA低电平有效;连接器高电平为ON",
- "polarity": "FPGA与连接器之间反相(主板NMOS)",
- "external_components": ext_list,
- "path": path_list,
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
- "fpga": {
- "ball": ball,
- "board_signal": net,
- "io_standard": "LVCMOS33",
- "capabilities": ["pwm", "gpio_output"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- }
- else:
- pins_dict[pnum] = {
- "summary": f"{key} ({net} 风扇转速反馈) ← FPGA U3.{ball}",
- "direction": "input",
- "external_level": "3.3V Divided Tach",
- "function_category": "tach",
- "external_components": ext_list,
- "path": path_list,
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- "fpga": {
- "ball": ball,
- "board_signal": net,
- "io_standard": "LVCMOS33",
- "capabilities": ["tach", "gpio_input"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- }
- touchpoint_anns[ref] = {"summary": fan_summaries[ref], "pins": pins_dict}
- # CON159..CON163 (14-pin + 2-shield Stepper Motor headers)
- con159_damper_map = {
- 1: "X1-S → -U1 X-STEP (1轴 -M1 1#前部风门 STEP)",
- 2: "X1-D → -U1 X-DIR (1轴 -M1 1#前部风门 DIR)",
- 3: "Y1-S → -U1 Y-STEP (2轴 -M2 1#后部风门 STEP)",
- 4: "Y1-D → -U1 Y-DIR (2轴 -M2 1#后部风门 DIR)",
- 5: "Z1-S → -U1 Z-STEP (3轴 -M3 1#顶部风门 STEP)",
- 6: "Z1-D → -U1 Z-DIR (3轴 -M3 1#顶部风门 DIR)",
- 7: "A1-S → -U1 A-STEP (轴4 -M4 2#前部风门 STEP)",
- 8: "A1-D → -U1 A-DIR (轴4 -M4 2#前部风门 DIR)",
- 9: "ENA1 → -U1 EN: 使能 (与 CAD CON165.1/现场14 共用 U3.F3,已固定低电平)",
- }
- for idx_m, ref in enumerate(("CON159", "CON160", "CON161", "CON162", "CON163"), start=1):
- ch_start = (idx_m - 1) * 4 + 1
- ch_end = idx_m * 4
- pins_dict = {}
- for p_idx in range(1, 15):
- pnum = str(p_idx)
- key = f"{ref}.{pnum}"
- net, hit = trace_net_to_u3_u27(ref, pnum, comp_pins, net_to_pins)
- if p_idx in (11, 13):
- pins_dict[pnum] = {
- "summary": (
- f"{key} (GND6) 步进驱动器信号地 (GND, 接第3页 -U1 GND)"
- if ref == "CON159"
- else f"{key} 步进驱动器信号地 (GND)"
- ),
- "direction": "passive",
- "external_level": "0V",
- "function_category": "ground",
- "path": [f"{key} (GND)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- }
- elif p_idx in (12, 14):
- pins_dict[pnum] = {
- "summary": (
- f"{key} (P6 +5V) 步进驱动板 +5V 逻辑电源 (接第3页 -U1 5V)"
- if ref == "CON159"
- else f"{key} +5V 步进驱动器光电耦合共阳电源"
- ),
- "direction": "output",
- "external_level": "+5V",
- "function_category": "power",
- "path": [f"{key} (+5V)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- }
- elif p_idx == 10:
- pins_dict[pnum] = {
- "summary": (
- f"{key} (NC1) 电气图第3/4页接 -U1 GND: 使能地(PCB 焊盘悬空 NC)"
- if ref == "CON159"
- else f"{key} 悬空空脚 (NC)"
- ),
- "direction": "passive",
- "external_level": "none",
- "function_category": "unknown",
- "path": [f"{key} (NC)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- }
- elif hit is not None:
- _dev, ball, _fpga_net, path_list, ext_list = hit
- if ref == "CON159" and p_idx in con159_damper_map:
- damper_desc = con159_damper_map[p_idx]
- pins_dict[pnum] = {
- "summary": f"{key} ({net}) → FPGA U3.{ball}(电气图第3/4页:{damper_desc};6400 32B 协议空余未启用)",
- "direction": "output",
- "external_level": "3.3V LVCMOS",
- "function_category": "gpio_output",
- "external_components": ext_list,
- "path": path_list,
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- "fpga": {
- "ball": ball,
- "board_signal": net,
- "io_standard": "LVCMOS33",
- "capabilities": ["gpio_output", "gpio"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- },
- }
- else:
- pins_dict[pnum] = {
- "summary": f"{key} ({net}) → FPGA U3.{ball}(6400 V2.0 无步进电机,空余未用)",
- "direction": "output",
- "external_level": "5V CMOS Buffer",
- "function_category": "gpio_output",
- "external_components": ext_list,
- "path": path_list,
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- "fpga": {
- "ball": ball,
- "board_signal": net,
- "io_standard": "LVCMOS33",
- "capabilities": ["gpio_output", "gpio"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- },
- }
- if ref == "CON159":
- touchpoint_anns[ref] = {
- "summary": (
- "步进控制接口 1(电气图第3/4页接 -U1 四轴驱动板控制 -M1 1#前部风门 / -M2 1#后部风门 / -M3 1#顶部风门 / -M4 2#前部风门:"
- "Pin 1..8 为 PUL/DIR1..4 → U3.C12/B12/L12/J11/L14/K14/L13/K11,Pin 9 为 ENA1 → U3.F3;6400 协议空余插座)"
- ),
- "pins": pins_dict,
- }
- else:
- touchpoint_anns[ref] = {
- "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)",
- "pins": pins_dict,
- }
- # CON165, CON166 (14-pin + 2-shield Photoelectric / SSR headers)
- ssr_active_pins = {
- "CON165.14": "现场CON165.1 SSR1 (ssr1_out, 驱动 -1-7E 110W/24V 辅助加热器)",
- "CON165.13": "现场CON165.2 SSR2 (ssr2_out, 腔体2+3共用,驱动 -2-7E 220W/24V 加热布)",
- "CON165.11": "现场CON165.4 SSR4 (ssr4_out, 驱动 -4-7E 110W/24V 辅助加热器)",
- }
- for ref in ("CON165", "CON166"):
- pins_dict = {}
- for p_idx in range(1, 15):
- pnum = str(p_idx)
- key = f"{ref}.{pnum}"
- net, hit = trace_net_to_u3_u27(ref, pnum, comp_pins, net_to_pins)
- if hit is not None:
- _dev, ball, _fpga_net, path_list, ext_list = hit
- if key in ssr_active_pins:
- ssr_label = ssr_active_pins[key]
- pins_dict[pnum] = {
- "summary": f"{key} ({net}) → FPGA U3.{ball} ({ssr_label} 20Hz PWM,高有效,默认关闭)",
- "direction": "output",
- "external_level": "3.3V SSR Control",
- "function_category": "gpio_output",
- "active_level": "high",
- "polarity": "normal",
- "external_components": ext_list,
- "path": path_list,
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd", "6400高温罩电气图V2.0.pdf"],
- "fpga": {
- "ball": ball,
- "board_signal": net,
- "io_standard": "LVCMOS33",
- "capabilities": ["gpio_output", "gpio"],
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- }
- elif ref == "CON165" and p_idx in (1, 2, 4):
- pins_dict[pnum] = {
- "summary": f"CAD {key} / 现场CON165.{15-p_idx} → U3.{ball},旧SSR引脚固定低电平",
- "direction": "output", "external_level": "0V", "function_category": "gpio_output",
- "path": path_list, "external_components": ext_list,
- "evidence_tier": "cross_verified", "sources": ["constraints/prod2u_6400_v2.adc"],
- "fpga": {"ball": ball, "board_signal": net, "io_standard": "LVCMOS33"},
- }
- else:
- pins_dict[pnum] = {
- "summary": f"{key} ({net}) ↔ FPGA U3.{ball}(光电限位/SSR 预留通道,6400 V2.0 空余)",
- "direction": "bidirectional",
- "external_level": "3.3V LVCMOS",
- "function_category": "gpio",
- "external_components": ext_list,
- "path": path_list,
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- "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"],
- },
- }
- touchpoint_anns[ref] = {
- "summary": (
- "固态继电器 SSR 与光电接口座 1(现场Pin 1/2/4(CAD 14/13/11)对应 6400 V2.0 SSR1/SSR2/SSR4 20Hz PWM,50ms控制(腔体1/2+3共用/4,默认关闭) → U3.E14/E8/D9 驱动 -1-7E 110W / -2-7E 220W / -4-7E 110W;旧F3/F1/G4固定低,其余空余;现场针号=15-CAD针号)"
- if ref == "CON165"
- else "光电限位与 GPIO 扩展座 2(空余插座:Pin 1..14 为 CON_PE15..28 ↔ U3.D16/E15/D14/R9/T10/L2/L1/M2/N3/K4/H2/H1/J2/K3)"
- ),
- "pins": pins_dict,
- }
- # CON164 (4-pin + 2-shield SSR GND & auxiliary power)
- touchpoint_anns["CON164"] = {
- "summary": "固态继电器 SSR 公共回路地与辅助电源座(Pin 1: +5V,Pin 2/3: GND1 配合 CON165.1/2/4 构成 SSR 回路负端,Pin 4: +3.3V)",
- "pins": {
- "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"]},
- "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"]},
- "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"]},
- "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"]},
- },
- }
- # CON168 on Mainboard (4-pin LCD UART header)
- touchpoint_anns["CON168"] = {
- "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页未接线)",
- "pins": {
- "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"]},
- "2": {
- "summary": "CON168.2 (CON_LCD_RX) → R1892 → 板载 MCU U27.30 (PA9 / MCU_UART0_TX)",
- "direction": "output",
- "external_level": "3.3V LVCMOS",
- "function_category": "uart_tx",
- "external_components": ["R1892"],
- "path": ["CON168.2 (CON_LCD_RX)", "R1892.2->1 (MCU_UART0_TX)", "U27.30 (PA9)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- "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"]},
- },
- "3": {
- "summary": "CON168.3 (CON_LCD_TX) ← R1893 ← 板载 MCU U27.31 (PA10 / MCU_UART0_RX)",
- "direction": "input",
- "external_level": "3.3V LVCMOS",
- "function_category": "uart_rx",
- "external_components": ["R1893"],
- "path": ["CON168.3 (CON_LCD_TX)", "R1893.2->1 (MCU_UART0_RX)", "U27.31 (PA10)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- "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"]},
- },
- "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"]},
- },
- }
- # CON170 on Mainboard (RJ45 BMC RS232 alternate port)
- con170_pins: dict[str, Any] = {}
- for p_idx in range(1, 13):
- pnum = str(p_idx)
- if pnum == "3":
- con170_pins[pnum] = {
- "summary": "CON170.3 (RS232_TX1_RJ45) → R1898 → TRSF3232EIPWR U22.14/11 → R818 → FPGA U3.L10 (bmc_tx,与 CON77.1 并联)",
- "direction": "output",
- "external_level": "RS232",
- "function_category": "uart_tx",
- "external_components": ["R1898", "U22", "R818"],
- "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)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- "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"]},
- }
- elif pnum == "6":
- con170_pins[pnum] = {
- "summary": "CON170.6 (RS232_RX1_RJ45) ← R1899 ← TRSF3232EIPWR U22.13/12 ← R819 ← FPGA U3.M9 (bmc_rx,与 CON77.2 并联)",
- "direction": "input",
- "external_level": "RS232",
- "function_category": "uart_rx",
- "external_components": ["R1899", "U22", "R819"],
- "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)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- "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"]},
- }
- elif pnum in ("4", "9"):
- 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"]}
- elif pnum == "10":
- 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"]}
- else:
- 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"]}
- touchpoint_anns["CON170"] = {
- "summary": "RJ45 BMC RS-232 备用接口座(Pin 3 TX1_RJ45 → U3.L10,Pin 6 RX1_RJ45 ← U3.M9,与 CON77 共用 TRSF3232EIPWR U22 通道)",
- "pins": con170_pins,
- }
- # CON171 (4-pin + 2-shield GPIO header: EX_GPIO7..10 -> M10, N11, L7, M7)
- con171_pins: dict[str, Any] = {}
- for p_idx in range(1, 5):
- pnum = str(p_idx)
- net, hit = trace_net_to_u3_u27("CON171", pnum, comp_pins, net_to_pins)
- if hit is not None:
- _dev, ball, _fpga_net, path_list, ext_list = hit
- con171_pins[pnum] = {
- "summary": f"CON171.{pnum} ({net}) ↔ FPGA U3.{ball}(外部 3.3V GPIO 扩展,6400 V2.0 空余)",
- "direction": "bidirectional",
- "external_level": "3.3V LVCMOS",
- "function_category": "gpio",
- "external_components": ext_list,
- "path": path_list,
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- "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"]},
- }
- touchpoint_anns["CON171"] = {
- "summary": "外部 3.3V GPIO 扩展座(空余插座:Pin 1..4 为 EX_GPIO7..10 ↔ R1901..R1904 ↔ FPGA U3.M10/N11/L7/M7)",
- "pins": con171_pins,
- }
- # CON172 on Mainboard (18-pad USB Type-C connector -> CP2102 U33 -> MCU U27.12/13)
- con172_pins: dict[str, Any] = {}
- for pnum in ("A1", "A4", "A5", "A6", "A7", "A9", "A12", "B1", "B4", "B5", "B6", "B7", "B9", "B12"):
- if pnum in ("A6", "B6"):
- con172_pins[pnum] = {
- "summary": f"CON172.{pnum} (USB_D+) ↔ R1917 ↔ CP2102 U33.4 ↔ R1920/R1921 ↔ 板载 MCU U27.12/13 (PA2/PA3 MCU_UART1)",
- "direction": "bidirectional",
- "external_level": "USB 2.0 Differential",
- "function_category": "uart",
- "external_components": ["R1917", "U33", "R1920", "R1921"],
- "path": [f"CON172.{pnum} (USB_D+)", "R1917", "U33 (CP2102)", "R1920/R1921", "U27.12/13 (PA2/PA3)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- "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"]},
- }
- elif pnum in ("A7", "B7"):
- con172_pins[pnum] = {
- "summary": f"CON172.{pnum} (USB_D-) ↔ R1918 ↔ CP2102 U33.5 ↔ R1920/R1921 ↔ 板载 MCU U27.12/13 (PA2/PA3 MCU_UART1)",
- "direction": "bidirectional",
- "external_level": "USB 2.0 Differential",
- "function_category": "uart",
- "external_components": ["R1918", "U33", "R1920", "R1921"],
- "path": [f"CON172.{pnum} (USB_D-)", "R1918", "U33 (CP2102)", "R1920/R1921", "U27.12/13 (PA2/PA3)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FPGA+MCU_V2.0_20260914.brd"],
- "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"]},
- }
- elif pnum in ("A4", "A9", "B4", "B9"):
- 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"]}
- elif pnum in ("A5", "B5"):
- r_cc = "R1913" if pnum == "A5" else "R1914"
- 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"]}
- else:
- 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"]}
- touchpoint_anns["CON172"] = {
- "summary": "USB Type-C 板载 MCU 调试串口座(经 CP2102 U33 USB-UART 桥接芯片连接 GD32 U27.12/13 PA2/PA3,非 FPGA 端口)",
- "pins": con172_pins,
- }
- # CON173, CON174 (12-pin +24V_VIN main power connectors)
- for ref in ("CON173", "CON174"):
- p_dict: dict[str, Any] = {}
- for p_idx in range(1, 13):
- pnum = str(p_idx)
- if p_idx <= 6:
- 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"]}
- else:
- 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"]}
- touchpoint_anns[ref] = {
- "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)",
- "pins": p_dict,
- }
- interfaces = [
- {
- "id": "host-ttl",
- "name": "Host TTL 串口 (连接外部 STM32H7 核心板)",
- "touchpoint": "CON12",
- "pins": ["1", "2", "3", "4"],
- "external_level": "3.3V LVCMOS",
- "evidence_tier": "cross_verified",
- "sources": ["reference/original/schematics/6400高温罩电气图V2.0.pdf", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- {
- "id": "host-rs232",
- "name": "Host RS-232 串口 (921600 波特率)",
- "touchpoint": "CON134",
- "pins": ["1", "2", "3", "4"],
- "external_level": "RS232",
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- {
- "id": "bmc-rs232",
- "name": "BMC RS-232 串口 (115200 波特率)",
- "touchpoint": "CON77",
- "pins": ["1", "2", "3", "4"],
- "external_level": "RS232",
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- {
- "id": "ptc-chamber1",
- "name": "1# 腔体 PTC 加热输出 (PTC1..6)",
- "touchpoint": "CON147",
- "pins": ["1", "3", "5", "7", "9", "11"],
- "external_level": "24V PTC PWM",
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- {
- "id": "ptc-chamber2",
- "name": "2# 腔体 PTC 加热输出 (PTC11..16)",
- "touchpoint": "CON148",
- "pins": ["1", "3", "5", "7", "9", "11"],
- "external_level": "24V PTC PWM",
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- {
- "id": "ptc-chamber3",
- "name": "3# 腔体 PTC 加热输出 (PTC21..26)",
- "touchpoint": "CON149",
- "pins": ["1", "3", "5", "7", "9", "11"],
- "external_level": "24V PTC PWM",
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- {
- "id": "ptc-chamber4",
- "name": "4# 腔体 PTC 第2..6路 (PTC31..35;第1路在CON149.19)",
- "touchpoint": "CON150",
- "pins": ["1", "3", "5", "7", "9", "11", "13", "15", "17", "19"],
- "external_level": "24V PTC PWM",
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- {
- "id": "fan-chamber1-2",
- "name": "1# & 2# 腔体前/后风扇 PWM (Front0..1, Rear0..1)",
- "touchpoint": "CON154",
- "pins": ["5", "6", "11", "12"],
- "external_level": "主板NMOS反相后的风扇PWM",
- "evidence_tier": "cross_verified",
- "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- {
- "id": "fan-chamber3-4",
- "name": "3# & 4# 腔体前/后风扇 PWM (Front2..3, Rear2..3)",
- "touchpoint": "CON155",
- "pins": ["5", "6", "11", "12"],
- "external_level": "主板NMOS反相后的风扇PWM",
- "evidence_tier": "cross_verified",
- "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md", "config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- {
- "id": "ssr-control",
- "name": "三路加热布 SSR 调功控制",
- "touchpoint": "CON165",
- "pins": ["1", "2", "4"],
- "external_level": "3.3V高有效;1秒周期;默认/看门狗关闭",
- "evidence_tier": "cross_verified",
- "sources": ["config/pin_inventory.fcb_fpga_mcu_v2_0.json"],
- },
- ]
- # These pin paths are produced by the structural BFS above. NC options and
- # transistor conduction are not verified by that search, even if names match.
- for ref in [*(f"CON{i}" for i in range(147, 151)),
- *(f"CON{i}" for i in range(154, 164)), "CON165", "CON166", "CON171"]:
- for pin in touchpoint_anns.get(ref, {}).get("pins", {}).values():
- if "fpga" in pin:
- _mark_inferred(pin)
- pin["summary"] = "拓扑候选(未核装配/导通):" + pin.get("summary", "")
- return {
- "board_id": "fcb_fpga_mcu_v2_0_20260914",
- "connector_profiles": connector_profiles,
- "touchpoints": touchpoint_anns,
- "interfaces": interfaces,
- }
- def _assemble_board_payload(
- parsed_board: ParsedBoard,
- annotations: Mapping[str, Any],
- *,
- board_name: str,
- ) -> dict[str, Any]:
- """Assemble and validate a board-viewer-data-v2 payload from ParsedBoard + annotations."""
- touchpoints = [_touchpoint_dict(fp, parsed_board.bounds) for fp in select_touchpoints(parsed_board)]
- resistors = [
- _resistor_dict(fp, parsed_board.bounds)
- for fp in sorted(select_resistors(parsed_board), key=lambda item: int(item.reference[1:]))
- ]
- profiles: dict[str, tuple[str, Mapping[str, Any]]] = {}
- for prof_name, prof_obj in annotations.get("connector_profiles", {}).items():
- for ref in prof_obj.get("references", []):
- profiles[str(ref)] = (str(prof_name), prof_obj)
- tp_anns = annotations.get("touchpoints", {})
- for tp in touchpoints:
- ref = tp["reference"]
- prof_entry = profiles.get(ref)
- if tp["category"] == "CON" or prof_entry is not None:
- _apply_connector_profile(tp, prof_entry)
- tp_ann = tp_anns.get(ref, {})
- if isinstance(tp_ann, Mapping) and tp_ann.get("summary"):
- tp["summary"] = str(tp_ann["summary"])
- pin_anns = tp_ann.get("pins", {}) if isinstance(tp_ann, Mapping) else {}
- for pin in tp["pins"]:
- p_ann = pin_anns.get(str(pin["number"]), {})
- if isinstance(p_ann, Mapping) and p_ann:
- _merge_annotation(pin, p_ann)
- pin["evidence_sources"] = _unique_strings(list(pin.get("evidence_sources", [])))
- pin["programming"] = _programming_guidance(ref, pin)
- prog_ann = p_ann.get("programming", {}) if isinstance(p_ann, Mapping) else {}
- if isinstance(prog_ann, Mapping) and prog_ann:
- _merge_programming_annotation(pin["programming"], prog_ann)
- _refresh_recommendation(pin)
- _attach_related_resistors(touchpoints, resistors)
- category_counts = Counter(item["category"] for item in touchpoints)
- touchpoint_side_counts = Counter(item["side"] for item in touchpoints)
- resistor_side_counts = Counter(item["side"] for item in resistors)
- connector_touchpoints = [item for item in touchpoints if item["category"] == "CON"]
- resistor_pad_count = sum(len(item["pads"]) for item in resistors)
- resistor_electrical_pad_count = sum(
- 1 for item in resistors for pad in item["pads"] if pad.get("pad_role") == "electrical"
- )
- if resistors:
- value_coverage = _build_value_coverage(resistors)
- else:
- value_coverage = {
- "resistors_total": 0,
- "component_value_nonempty": 0,
- "value_parsed": 0,
- "value_zero_ohm_fitted_or_unknown": 0,
- "value_zero_ohm_not_fitted": 0,
- "assembly_not_fitted": 0,
- "value_missing_or_unparsed": 0,
- "component_value_source_status": "passive_board_no_resistors",
- "example_available_tokens": ["fuse"],
- "note": "Passive connector expansion board with no discrete resistors.",
- }
- payload = {
- "schema": BOARD_DATA_SCHEMA_ID,
- "board": {
- "id": str(annotations.get("board_id")),
- "name": board_name,
- "source_bounds": dict(parsed_board.bounds),
- "view_box": {
- "x": 0.0,
- "y": 0.0,
- "width": parsed_board.bounds["width"],
- "height": parsed_board.bounds["height"],
- },
- },
- "counts": {
- "footprints": parsed_board.footprint_count,
- "touchpoints": len(touchpoints),
- "pads": sum(len(item["pins"]) for item in touchpoints),
- "resistors": len(resistors),
- "resistor_pads": resistor_pad_count,
- "resistor_electrical_pads": resistor_electrical_pad_count,
- "connector_contacts": sum(int(item["connector"]["contact_count"]) for item in connector_touchpoints),
- "connector_auxiliary_pads": sum(
- int(item["connector"]["auxiliary_pad_count"]) for item in connector_touchpoints
- ),
- "categories": {
- "CON": category_counts.get("CON", 0),
- "J": category_counts.get("J", 0),
- "PL": category_counts.get("PL", 0),
- "TP": category_counts.get("TP", 0),
- "R": len(resistors),
- },
- "sides": {key: touchpoint_side_counts.get(key, 0) for key in ("front", "back")},
- "touchpoint_sides": {key: touchpoint_side_counts.get(key, 0) for key in ("front", "back")},
- "resistor_sides": {key: resistor_side_counts.get(key, 0) for key in ("front", "back")},
- },
- "value_coverage": value_coverage,
- "component_value_source_status": value_coverage["component_value_source_status"],
- "touchpoints": touchpoints,
- "resistors": resistors,
- "resistor_links": [],
- "evidence_conflicts": [],
- "interfaces": list(annotations.get("interfaces", [])),
- "photo_overlay": None,
- }
- validate_resistor_index(payload)
- data_schema = json.loads(DATA_SCHEMA_PATH.read_text(encoding="utf-8"))
- Draft202012Validator(data_schema).validate(payload)
- return payload
- # ---------------------------------------------------------------------------
- # Entry Points: Mainboard & Fan Board
- # ---------------------------------------------------------------------------
- def generate_v2_0_mainboard() -> None:
- print("[V2.0] Starting FCB V2.0 (6400 Mainboard) asset generation from Allegro BRD...")
- brd_path = ROOT / "reference/original/board/FCB_FPGA_MCU_V2.0_20260914/FCB_FPGA+MCU_V2.0_20260914.brd"
- pin_inv_path = ROOT / "config/pin_inventory.fcb_fpga_mcu_v2_0.json"
- out_dir = ROOT / "tools/board-viewer/generated-v2_0"
- out_dir.mkdir(parents=True, exist_ok=True)
- parsed_board, cad_meta = parse_allegro_brd(brd_path)
- pin_inv = json.loads(pin_inv_path.read_text(encoding="utf-8"))
- annotations = _build_v20_annotations(parsed_board, cad_meta, pin_inv)
- board_data = _assemble_board_payload(
- parsed_board,
- annotations,
- board_name="FCB FPGA+MCU V2.0 20260914 (6400 主控板)",
- )
- print(
- f"[V2.0] Parsed {board_data['counts']['footprints']} footprints, "
- f"{board_data['counts']['touchpoints']} touchpoints ({board_data['counts']['pads']} pads), "
- f"{board_data['counts']['resistors']} resistors ({board_data['counts']['resistor_pads']} pads) "
- f"on {parsed_board.bounds['width']}x{parsed_board.bounds['height']} mm board"
- )
- (out_dir / "board-data.json").write_text(
- json.dumps(board_data, indent=2, ensure_ascii=False) + "\n",
- encoding="utf-8",
- )
- generate_svg_layers_from_brd(
- parsed_board,
- cad_meta,
- "FCB FPGA+MCU V2.0 20260914",
- board_data["touchpoints"],
- out_dir,
- )
- cats = board_data["counts"]["categories"]
- import_report = {
- "board_id": "fcb_fpga_mcu_v2_0_20260914",
- "source": "reference/original/board/FCB_FPGA_MCU_V2.0_20260914/FCB_FPGA+MCU_V2.0_20260914.brd",
- "source_file": brd_path.name,
- "source_format": "allegro_brd",
- "output_file": "board-data.json",
- "errors": [],
- "timestamp": datetime.now(timezone.utc).isoformat(),
- "stats": {
- "connectors": cats["CON"],
- "jumpers": cats["J"],
- "power_terminals": cats["PL"],
- "test_points": cats["TP"],
- "resistors": cats["R"],
- },
- "status": "success",
- }
- (out_dir / "import-report.json").write_text(json.dumps(import_report, indent=2) + "\n", encoding="utf-8")
- assets_meta: dict[str, dict[str, Any]] = {}
- for asset_file in (out_dir / name for name in (
- "board-data.json", "import-report.json", "board-mask-edge.svg",
- "board-mask-edge-back.svg", "board-copper.svg", "board-copper-back.svg",
- "board-silkscreen.svg", "board-silkscreen-back.svg",
- )):
- if asset_file.is_file():
- assets_meta[asset_file.name] = {
- "sha256": sha256_file(asset_file),
- "bytes": asset_file.stat().st_size,
- }
- build_info = {
- "schema": "board-viewer-build-info-v1",
- "generated_at": datetime.now(timezone.utc).isoformat(),
- "generator_version": "2.1.0",
- "toolchain": {"python": sys.version.split()[0], "kicad": "not_used"},
- "sources": {
- **_generator_sources(),
- "brd": {
- "path": "reference/original/board/FCB_FPGA_MCU_V2.0_20260914/FCB_FPGA+MCU_V2.0_20260914.brd",
- "sha256": sha256_file(brd_path),
- },
- "annotations": {
- "path": str(ANNOTATIONS_V12_PATH.relative_to(ROOT)),
- "sha256": sha256_file(ANNOTATIONS_V12_PATH),
- },
- "inventory": {
- "path": "config/pin_inventory.fcb_fpga_mcu_v2_0.json",
- "sha256": sha256_file(pin_inv_path),
- },
- "schema_data": {
- "path": "schemas/board_viewer_data.schema.json",
- "sha256": sha256_file(DATA_SCHEMA_PATH),
- },
- "schema_build_info": {
- "path": "schemas/board_viewer_build_info.schema.json",
- "sha256": sha256_file(BUILD_INFO_SCHEMA_PATH),
- },
- },
- "assets": assets_meta,
- "verification": {
- "ipcd356": {
- "status": "not_run",
- "reason": "No independent IPC-D-356 export or alignment comparison was executed by this BRD viewer generator.",
- },
- "side_views": {
- "front_layers": [
- "board-mask-edge.svg",
- "board-silkscreen.svg",
- "board-copper.svg",
- ],
- "back_layers": [
- "board-mask-edge-back.svg",
- "board-silkscreen-back.svg",
- "board-copper-back.svg",
- ],
- "back_mirror_axis": "y",
- "back_svg_export_mirrored": True,
- "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.",
- },
- },
- "counts": {
- "footprints": board_data["counts"]["footprints"],
- "touchpoints": board_data["counts"]["touchpoints"],
- "pads": board_data["counts"]["pads"],
- "resistors": board_data["counts"]["resistors"],
- "resistor_pads": board_data["counts"]["resistor_pads"],
- },
- }
- build_info_schema = json.loads(BUILD_INFO_SCHEMA_PATH.read_text(encoding="utf-8"))
- Draft202012Validator(build_info_schema).validate(build_info)
- (out_dir / "build-info.json").write_text(json.dumps(build_info, indent=2) + "\n", encoding="utf-8")
- print(f"[V2.0] Asset generation complete! {len(assets_meta)} assets in {out_dir.name}")
- def _build_v20_fan_annotations() -> dict[str, Any]:
- connector_profiles = {
- "CON_SMD_2D54_2X7P": {
- "references": ["CON168"],
- "contact_pins": [str(i) for i in range(1, 15)],
- "shield_pads": [],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FAN_V2.0_20260914.brd"],
- },
- "CON_PZGM_B03_08P": {
- "references": ["CON8", "CON169", "CON170", "CON171"],
- "contact_pins": [str(i) for i in range(1, 9)],
- "shield_pads": [],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FAN_V2.0_20260914.brd"],
- },
- "CON_X9556WV_2X4P": {
- "references": ["CON2", "CON172"],
- "contact_pins": [str(i) for i in range(1, 9)],
- "shield_pads": [],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FAN_V2.0_20260914.brd"],
- },
- }
- con168_pins: dict[str, Any] = {}
- fg_map = {
- "1": ("FG1_1", "CON8.5", "D2/N10"),
- "2": ("FG2_1", "CON169.5", "E6 / U3.R11"),
- "3": ("FG1_2", "CON8.6", "D3/M11"),
- "4": ("FG2_2", "CON169.6", "D6/B9"),
- "7": ("FG3_1", "CON170.5", "C1/D10"),
- "8": ("FG4_1", "CON171.5", "B3/E9"),
- "9": ("FG3_2", "CON170.6", "C2/E10"),
- "10": ("FG4_2", "CON171.6", "B13/B7"),
- }
- pwm_map = {
- "5": ("PWM1", "CON8.7", "P12/C4", "fan_front_2_0"),
- "6": ("PWM2", "CON169.7", "A10/B5", "fan_rear_2_0"),
- "11": ("PWM3", "CON170.7", "D8/B1", "fan_front_3_1"),
- "12": ("PWM4", "CON171.7", "C7/A14", "fan_rear_3_1"),
- }
- for p_idx in range(1, 15):
- pnum = str(p_idx)
- if pnum in pwm_map:
- net, dest, ball, bsig = pwm_map[pnum]
- con168_pins[pnum] = {
- "summary": f"CON168.{pnum} ({net}) → 直通 {dest} ↔ 主板 CON155/CON154.{pnum} → FPGA U3.{ball} ({bsig})",
- "direction": "input",
- "external_level": "主板NMOS反相后的开漏PWM;连接器高电平为ON",
- "function_category": "pwm",
- "path": [f"CON168.{pnum} ({net})", dest, f"主板 U3.{ball} ({bsig})"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FAN_V2.0_20260914.brd", "docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
- }
- elif pnum in fg_map:
- net, src, ball = fg_map[pnum]
- con168_pins[pnum] = {
- "summary": f"CON168.{pnum} ({net}) ← 直通 {src} 转速反馈 → 主板 FPGA U3.{ball}",
- "direction": "output",
- "external_level": "Tach Open-Collector",
- "function_category": "tach",
- "path": [src, f"CON168.{pnum} ({net})", f"主板 U3.{ball}"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FAN_V2.0_20260914.brd", "docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
- }
- else:
- con168_pins[pnum] = {
- "summary": f"CON168.{pnum} (GND) 主控板与风扇板信号共地",
- "direction": "passive",
- "external_level": "0V",
- "function_category": "ground",
- "path": [f"CON168.{pnum} (GND)"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FAN_V2.0_20260914.brd"],
- }
- touchpoint_anns: dict[str, Any] = {
- "CON168": {
- "summary": "主控板 14Pin 风扇控制与测速输入座(Pin 5/6/11/12 为 PWM1..4,Pin 1..4/7..10 为 FG1_1..FG4_2,Pin 13/14 为 GND,对接主板 CON155/CON154)",
- "pins": con168_pins,
- }
- }
- fan_out_defs = {
- "CON8": ("1# 前风扇输出座 (FM1或FM5双风机)", "PWM1", "5", "FG1_1", "1", "FG1_2", "3", "F32", "P12/C4", "fan_front_2_0"),
- "CON169": ("2# 后风扇输出座 (FM2或FM6)", "PWM2", "6", "FG2_1", "2", "FG2_2", "4", "F132", "A10/B5", "fan_rear_2_0"),
- "CON170": ("3# 前风扇输出座 (FM3或FM7双风机)", "PWM3", "11", "FG3_1", "7", "FG3_2", "9", "F133", "D8/B1", "fan_front_3_1"),
- "CON171": ("4# 后风扇输出座 (FM4或FM8)", "PWM4", "12", "FG4_1", "8", "FG4_2", "10", "F134", "C7/A14", "fan_rear_3_1"),
- }
- 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():
- p_dict: dict[str, Any] = {
- "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"]},
- "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"]},
- "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"]},
- "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"]},
- "5": {
- "summary": f"{ref}.5 ({fg_a}) 转速反馈输入 → CON168.{fg_a_pin}",
- "direction": "input",
- "external_level": "Tach Open-Collector",
- "function_category": "tach",
- "path": [f"{ref}.5 ({fg_a})", f"CON168.{fg_a_pin}"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FAN_V2.0_20260914.brd"],
- },
- "6": {
- "summary": f"{ref}.6 ({fg_b}) 转速反馈输入 → CON168.{fg_b_pin}",
- "direction": "input",
- "external_level": "Tach Open-Collector",
- "function_category": "tach",
- "path": [f"{ref}.6 ({fg_b})", f"CON168.{fg_b_pin}"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FAN_V2.0_20260914.brd"],
- },
- "7": {
- "summary": f"{ref}.7 ({pwm_net}) 风扇 PWM 输出 ← CON168.{pwm_pin} ← 主板 FPGA U3.{ball} ({bsig})",
- "direction": "output",
- "external_level": "主板NMOS反相后的开漏PWM;连接器高电平为ON",
- "function_category": "pwm",
- "path": [f"{ref}.7 ({pwm_net})", f"CON168.{pwm_pin}", f"主板 U3.{ball} ({bsig})"],
- "evidence_tier": "cross_verified",
- "sources": ["FCB_FAN_V2.0_20260914.brd", "docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
- },
- "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"]},
- }
- touchpoint_anns[ref] = {
- "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})",
- "pins": p_dict,
- }
- for ref, role_desc in (("CON2", "外部 DC +12V 主电源输入座"), ("CON172", "DC +12V 电源级联输出座")):
- p_dict = {}
- for p_idx in range(1, 9):
- pnum = str(p_idx)
- if p_idx <= 4:
- 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"]}
- else:
- 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"]}
- touchpoint_anns[ref] = {
- "summary": f"{role_desc}(Pin 1..4 为 GND,Pin 5..8 为 +12V 电源轨)",
- "pins": p_dict,
- }
- fan_interfaces = [
- {
- "id": "fan-ctrl-in",
- "name": "主控板风扇控制输入母座",
- "touchpoint": "CON168",
- "pins": ["5", "6", "11", "12"],
- "external_level": "12V PWM",
- "evidence_tier": "cross_verified",
- "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
- },
- {
- "id": "fan-1",
- "name": "1# 风扇输出 (FM1或FM5双风机)",
- "touchpoint": "CON8",
- "pins": ["1", "2", "3", "4", "5", "6", "7", "8"],
- "external_level": "12V / 5V PWM",
- "evidence_tier": "cross_verified",
- "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
- },
- {
- "id": "fan-2",
- "name": "2# 风扇输出 (FM2或FM6)",
- "touchpoint": "CON169",
- "pins": ["1", "2", "3", "4", "5", "6", "7", "8"],
- "external_level": "12V / 5V PWM",
- "evidence_tier": "cross_verified",
- "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
- },
- {
- "id": "fan-3",
- "name": "3# 风扇输出 (FM3或FM7双风机)",
- "touchpoint": "CON170",
- "pins": ["1", "2", "3", "4", "5", "6", "7", "8"],
- "external_level": "12V / 5V PWM",
- "evidence_tier": "cross_verified",
- "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
- },
- {
- "id": "fan-4",
- "name": "4# 风扇输出 (FM4或FM8)",
- "touchpoint": "CON171",
- "pins": ["1", "2", "3", "4", "5", "6", "7", "8"],
- "external_level": "12V / 5V PWM",
- "evidence_tier": "cross_verified",
- "sources": ["docs/evidence/FCB_FAN_V2_0_ANALYSIS.md"],
- },
- ]
- return {
- "board_id": "fcb_fan_v2_0_20260914",
- "connector_profiles": connector_profiles,
- "touchpoints": touchpoint_anns,
- "interfaces": fan_interfaces,
- }
- def generate_v2_0_fan_board() -> None:
- print("[V2.0-FAN] Starting FCB_FAN V2.0 (Fan Board) asset generation from Allegro BRD...")
- brd_path = ROOT / "reference/original/board/FCB_FAN_V2.0_20260914/FCB_FAN_V2.0_20260914.brd"
- out_dir = ROOT / "tools/board-viewer/generated-v2_0_fan"
- out_dir.mkdir(parents=True, exist_ok=True)
- parsed_board, cad_meta = parse_allegro_brd(brd_path)
- annotations = _build_v20_fan_annotations()
- fan_board_data = _assemble_board_payload(
- parsed_board,
- annotations,
- board_name="FCB_FAN V2.0 20260914 (风扇扩展板)",
- )
- print(
- f"[V2.0-FAN] Parsed {fan_board_data['counts']['footprints']} footprints, "
- f"{fan_board_data['counts']['touchpoints']} touchpoints ({fan_board_data['counts']['pads']} pads) "
- f"on {parsed_board.bounds['width']}x{parsed_board.bounds['height']} mm board"
- )
- (out_dir / "board-data.json").write_text(
- json.dumps(fan_board_data, indent=2, ensure_ascii=False) + "\n",
- encoding="utf-8",
- )
- generate_svg_layers_from_brd(
- parsed_board,
- cad_meta,
- "FCB_FAN V2.0 20260914",
- fan_board_data["touchpoints"],
- out_dir,
- )
- import_report = {
- "board_id": "fcb_fan_v2_0_20260914",
- "source": "reference/original/board/FCB_FAN_V2.0_20260914/FCB_FAN_V2.0_20260914.brd",
- "source_file": brd_path.name,
- "source_format": "allegro_brd",
- "output_file": "board-data.json",
- "errors": [],
- "timestamp": datetime.now(timezone.utc).isoformat(),
- "stats": {"connectors": fan_board_data["counts"]["touchpoints"], "fuses": 4},
- "status": "success",
- }
- (out_dir / "import-report.json").write_text(json.dumps(import_report, indent=2) + "\n", encoding="utf-8")
- assets_meta: dict[str, dict[str, Any]] = {}
- for asset_file in (out_dir / name for name in (
- "board-data.json", "import-report.json", "board-mask-edge.svg",
- "board-mask-edge-back.svg", "board-copper.svg", "board-copper-back.svg",
- "board-silkscreen.svg", "board-silkscreen-back.svg",
- )):
- if asset_file.is_file():
- assets_meta[asset_file.name] = {
- "sha256": sha256_file(asset_file),
- "bytes": asset_file.stat().st_size,
- }
- build_info = {
- "schema": "board-viewer-build-info-v1",
- "generated_at": datetime.now(timezone.utc).isoformat(),
- "generator_version": "2.1.0",
- "toolchain": {"python": sys.version.split()[0], "kicad": "not_used"},
- "sources": {
- **_generator_sources(),
- "brd": {
- "path": "reference/original/board/FCB_FAN_V2.0_20260914/FCB_FAN_V2.0_20260914.brd",
- "sha256": sha256_file(brd_path),
- },
- "schema_data": {
- "path": "schemas/board_viewer_data.schema.json",
- "sha256": sha256_file(DATA_SCHEMA_PATH),
- },
- "schema_build_info": {
- "path": "schemas/board_viewer_build_info.schema.json",
- "sha256": sha256_file(BUILD_INFO_SCHEMA_PATH),
- },
- },
- "assets": assets_meta,
- "verification": {
- "ipcd356": {
- "status": "not_run",
- "reason": "No independent IPC-D-356 export or alignment comparison was executed by this BRD viewer generator.",
- },
- "side_views": {
- "front_layers": [
- "board-mask-edge.svg",
- "board-silkscreen.svg",
- "board-copper.svg",
- ],
- "back_layers": [
- "board-mask-edge-back.svg",
- "board-silkscreen-back.svg",
- "board-copper-back.svg",
- ],
- "back_mirror_axis": "y",
- "back_svg_export_mirrored": True,
- "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.",
- },
- },
- "counts": {
- "footprints": fan_board_data["counts"]["footprints"],
- "touchpoints": fan_board_data["counts"]["touchpoints"],
- "pads": fan_board_data["counts"]["pads"],
- "resistors": 0,
- "resistor_pads": 0,
- },
- }
- build_info_schema = json.loads(BUILD_INFO_SCHEMA_PATH.read_text(encoding="utf-8"))
- Draft202012Validator(build_info_schema).validate(build_info)
- (out_dir / "build-info.json").write_text(json.dumps(build_info, indent=2) + "\n", encoding="utf-8")
- print(f"[V2.0-FAN] Asset generation complete! {len(assets_meta)} assets in {out_dir.name}")
- def main() -> None:
- generate_v2_0_mainboard()
- generate_v2_0_fan_board()
- print("\n[SUCCESS] Generated all V2.0 board viewer assets from Allegro BRD binaries!")
- if __name__ == "__main__":
- main()
|