#!/usr/bin/env python3 """Generate the mrdimm-chamber ADC pin constraints from V1.2 evidence. Sources, in authority order: 1. config/pin_inventory.prod2u_door_temp_v1_2.json (board fcb_fpga_mcu_v1_2_ 20260717, evidence_matrix_v1_2_e2e) for clock, host RS232, CT7428 bus, PTC8 physical channels and FAN4. 2. ACTIVE-TASK board authority for the current motor seats: the door motor connectors were rewired from the old NPN-buffered CON104/105/106 seats (C12/B12, L12/J11, L14/K14 in the inventory) to direct 3.3V series-R seats CON142/126/127 (X H4/J6, Y E7/A4, Z B4/A12). Limits keep the six-limit map CON12/129 (A5/B6, C8/A8, K16/J15, active high). 3. No V1.2 evidence exists for BMC UART or Host I2C pads: those pads are deliberately NOT assigned (the production wrapper holds the inputs idle and does not export them, so TD cannot auto-place them onto unrelated board signals). LOGIC_TESTED, not PAD_BOUND. """ from __future__ import annotations import argparse import json from pathlib import Path ROOT = Path(__file__).resolve().parents[1] OUT = ROOT / "constraints" # Active-authority motor seat override (see module docstring, point 2). MOTOR_SEATS = { "x_step": ("H4", "CON142.2"), "x_dir": ("J6", "CON142.3"), "y_step": ("E7", "CON126.2"), "y_dir": ("A4", "CON126.3"), "z_step": ("B4", "CON127.2"), "z_dir": ("A12", "CON127.3"), } # V1.2 fans are active_low at the ball; connector side is high duty. The # top-level fan board adapter inverts all four (evidence: inventory rows # fan_pwm_out[0..3] B1/C4/B5/A14 polarity active_low). FAN_INVERT_MASK = "4'hF" def generate(root: Path | None = None) -> dict[Path, bytes]: base = root if root is not None else ROOT inv = json.loads((base / "config" / "pin_inventory.prod2u_door_temp_v1_2.json").read_text(encoding="utf-8")) assert inv["board_id"] == "fcb_fpga_mcu_v1_2_20260717", inv["board_id"] rows = {p["signal"]: p for p in inv["pins"]} lines: list[str] = [] lines.append("# mrdimm-chamber FCB V1.2 confirmed pins (generated from") lines.append(f"# config/pin_inventory.prod2u_door_temp_v1_2.json {inv['board_id']},") lines.append(f"# status {inv['status']}). Motor seats overridden to the current") lines.append("# direct 3.3V CON142/126/127 wiring per the active board authority;") lines.append("# the superseded NPN-buffered seats appear in comments.") lines.append("# NOT BOUND on this product (no V1.2 evidence; wrapper holds idle):") lines.append("# bmc_rs232_rx/tx, host_ttl_rx/tx, host_i2c_scl/sda.") lv = "IOSTANDARD = LVCMOS33; PULLTYPE = NONE;" def emit(signal: str, ball: str, note: str = "") -> None: suffix = f" # {note}" if note else "" lines.append(f"set_pin_assignment {{ {signal} }} {{ LOCATION = {ball}; {lv} }}{suffix}") emit("sys_clk", rows["sys_clk"]["fpga_ball"]) emit("host_rs232_tx", rows["host_uart_tx"]["fpga_ball"], "CON78.1") emit("host_rs232_rx", rows["host_uart_rx"]["fpga_ball"], "CON78.2") emit("temp_scl", rows["temp_scl"]["fpga_ball"], "CT7428 bus") emit("temp_sda", rows["temp_sda"]["fpga_ball"], "CT7428 bus") for i in range(8): sig = f"ptc_pwm_out[{i}]" chamber = i // 2 + 1 half = "A" if i % 2 == 0 else "B" emit(sig, rows[sig]["fpga_ball"], f"chamber{chamber} physical {half}") for i in range(4): sig = f"fan_pwm_out[{i}]" emit(sig, rows[sig]["fpga_ball"], f"chamber{i+1} fan, board_invert=1") emit("motor_en_n", rows["motor_en_n"]["fpga_ball"], "constant 1, NPN invert at board") for axis in ("x", "y", "z"): index="xyz".index(axis) emit(f"limit_lower_raw[{index}]", rows[f"{axis}_limit_ls"]["fpga_ball"], "active high") emit(f"limit_upper_raw[{index}]", rows[f"{axis}_limit_hs"]["fpga_ball"], "active high") for sig, (ball, seat) in MOTOR_SEATS.items(): old = rows[sig].get("fpga_ball", "?") emit(sig, ball, f"{seat} direct 3.3V; superseded NPN seat ball {old}") lines.append(f"# FAN_BOARD_INVERT_MASK = {FAN_INVERT_MASK} (all four V1.2 fans active low at ball)") text = "\n".join(lines) + "\n" return {base / 'constraints/prod2u_mrdimm.adc': text.encode('utf-8')} def main() -> int: ap = argparse.ArgumentParser() ap.add_argument('--check', action='store_true') args = ap.parse_args() for path, data in generate().items(): if args.check: if not path.is_file() or path.read_bytes() != data: print('generated drift: constraints/prod2u_mrdimm.adc') return 1 else: path.parent.mkdir(parents=True, exist_ok=True) path.write_bytes(data) print('PASS: mrdimm adc generated') return 0 if __name__ == '__main__': raise SystemExit(main())