main
John Lauer Publish 1.0.0 c441804
# adom-aiflow rules: jlcpcb 4L (from adom/pcb-design-rules); P1 HV60 rules appended
(version 1)

# JLCPCB 4-layer design rules (standard process)
# 
# Min trace width: 0.09 mm (3.5 mil) - 1 oz copper outer layer, 3 mil acceptable in BGA fan-outs
# Min spacing: 0.09 mm (3.5 mil) - 1 oz copper, different nets
# Min drill: 0.15 mm (5.91 mil)
# Min via: 0.15 mm hole / 0.25 mm pad
# Annular ring: via 0.15 mm
# Copper to board edge: 0.2 mm
# Hole to hole: 0.2 mm
# Board thickness options: 0.4 mm, 0.6 mm, 0.8 mm, 1.0 mm, 1.2 mm, 1.6 mm, 2.0 mm
# Copper weight options: 1 oz, 2 oz
# Surface finishes: HASL leaded, HASL lead-free, ENIG
# Max board size: 663 x 593 mm
# 
# Same source page as 2 layer, multilayer column. Inner layer copper 0.5/1/2 oz, 0.5 oz default. Inner layer via hole to copper clearance 0.2 mm, inner PTH pad hole to copper clearance 0.3 mm. 2 oz outer: min trace/spacing 0.15/0.15 mm (6/6 mil). Min plated slot width 0.35 mm multilayer. Controlled impedance available. Blind/buried vias not supported, through holes only.
# 
# Sources:
# - https://jlcpcb.com/capabilities/pcb-capabilities (read 2026-09-03)

(rule "min-track-width"
  (constraint track_width (min 0.09mm))
  (layer "*.Cu")
  (condition "A.type == 'track'"))

(rule "min-clearance"
  (constraint clearance (min 0.09mm))
  (condition "A.type == 'track' && B.type == 'track'"))

(rule "min-hole"
  (constraint hole (min 0.15mm))
  (condition "A.type == 'pad' || A.type == 'via'"))

(rule "min-via-diameter"
  (constraint via_diameter (min 0.25mm))
  (condition "A.type == 'via'"))

(rule "min-edge-clearance"
  (constraint edge_clearance (min 0.2mm))
  (condition "A.type == 'track'"))

(rule "min-silk-thickness"
  (constraint text_thickness (min 0.15mm))
  (layer "*.SilkS")
  (condition "A.type == 'text' || A.type == 'graphic'"))

# JLCPCB lists 1.0 mm; Adom has tested 0.8 mm and it prints legibly (2026-10-08).
(rule "min-silk-text-height"
  (constraint text_height (min 0.8mm))
  (layer "*.SilkS")
  (condition "A.type == 'text'"))

# ---------------------------------------------------------------------------------------------------------------
# 60 V spacing (conformal-coated assembly; IPC-2221 table 6-1, 51 to 100 V).
# HV60 = VMOT, the phases and every net tied to them (netclass patterns in the .kicad_pro; list in design/calcs.json
# spacing60V). Rules are listed general first: KiCad applies the last matching rule.

# board rule: at least 0.25 mm from an HV60 net to any other net, every layer
(rule "HV60 board spacing"
  (constraint clearance (min 0.25mm))
  (condition "(A.hasNetclass('HV60') || B.hasNetclass('HV60')) && A.Net != B.Net"))

# always 0.6 mm within about 3 mm of a masked (uncoated) region on the outer layers: the rule areas named HV_MASKED
# are drawn 3 mm around every machine contact, corner pin and probe test pad and around the bottom heat-pedestal land
(rule "HV60 near masked areas"
  (layer outer)
  (constraint clearance (min 0.6mm))
  (condition "(A.hasNetclass('HV60') || B.hasNetclass('HV60')) && A.Net != B.Net && (A.intersectsArea('HV_MASKED') || B.intersectsArea('HV_MASKED'))"))

# footprint-internal exclusion: inside the DRV8353S (102 V rated on VDRAIN, SHx, GHx) the spacing is its own package's,
# 0.5 mm pitch QFN; the 0.25 mm board rule does not apply to its lands and fan-out within its courtyard
(rule "HV60 inside the DRV8353S package (exclusion)"
  (constraint clearance (min 0.09mm))
  (condition "(A.hasNetclass('HV60') || B.hasNetclass('HV60')) && A.Net != B.Net && A.intersectsCourtyard('U2') && B.intersectsCourtyard('U2')"))

# footprint-internal exclusion, two-pin parts: between the two lands of one resistor, capacitor, diode or fuse that carries an HV60 net,
# the part's own rating governs (0402 thick film 50 V working, each sees at most about 21 V across itself; 0603 TNPW 75 V;
# NANO2 125 V; SMB/SMC diodes 100 V). Written by design/gen_dru_exclusion.py from the netlist, one term per part.
(rule "HV60 inside two-pin rated parts (exclusion)"
  (constraint clearance (min 0.09mm))
  (condition "(A.memberOfFootprint('F2') && B.memberOfFootprint('F2')) || (A.memberOfFootprint('D7') && B.memberOfFootprint('D7')) || (A.memberOfFootprint('D8') && B.memberOfFootprint('D8')) || (A.memberOfFootprint('R6') && B.memberOfFootprint('R6')) || (A.memberOfFootprint('R7') && B.memberOfFootprint('R7')) || (A.memberOfFootprint('R8') && B.memberOfFootprint('R8')) || (A.memberOfFootprint('C4') && B.memberOfFootprint('C4')) || (A.memberOfFootprint('C5') && B.memberOfFootprint('C5')) || (A.memberOfFootprint('C6') && B.memberOfFootprint('C6')) || (A.memberOfFootprint('C7') && B.memberOfFootprint('C7')) || (A.memberOfFootprint('C8') && B.memberOfFootprint('C8')) || (A.memberOfFootprint('C9') && B.memberOfFootprint('C9')) || (A.memberOfFootprint('C10') && B.memberOfFootprint('C10')) || (A.memberOfFootprint('C11') && B.memberOfFootprint('C11')) || (A.memberOfFootprint('C12') && B.memberOfFootprint('C12')) || (A.memberOfFootprint('C13') && B.memberOfFootprint('C13')) || (A.memberOfFootprint('C14') && B.memberOfFootprint('C14')) || (A.memberOfFootprint('D1') && B.memberOfFootprint('D1')) || (A.memberOfFootprint('C17') && B.memberOfFootprint('C17')) || (A.memberOfFootprint('C18') && B.memberOfFootprint('C18')) || (A.memberOfFootprint('C19') && B.memberOfFootprint('C19')) || (A.memberOfFootprint('R38') && B.memberOfFootprint('R38')) || (A.memberOfFootprint('R39') && B.memberOfFootprint('R39')) || (A.memberOfFootprint('R40') && B.memberOfFootprint('R40')) || (A.memberOfFootprint('R42') && B.memberOfFootprint('R42')) || (A.memberOfFootprint('R43') && B.memberOfFootprint('R43')) || (A.memberOfFootprint('R44') && B.memberOfFootprint('R44')) || (A.memberOfFootprint('R46') && B.memberOfFootprint('R46')) || (A.memberOfFootprint('R47') && B.memberOfFootprint('R47')) || (A.memberOfFootprint('R48') && B.memberOfFootprint('R48')) || (A.memberOfFootprint('R50') && B.memberOfFootprint('R50')) || (A.memberOfFootprint('R51') && B.memberOfFootprint('R51')) || (A.memberOfFootprint('R52') && B.memberOfFootprint('R52')) || (A.memberOfFootprint('D4') && B.memberOfFootprint('D4')) || (A.memberOfFootprint('R56') && B.memberOfFootprint('R56')) || (A.memberOfFootprint('R57') && B.memberOfFootprint('R57')) || (A.memberOfFootprint('R59') && B.memberOfFootprint('R59')) || (A.memberOfFootprint('R60') && B.memberOfFootprint('R60')) || (A.memberOfFootprint('R61') && B.memberOfFootprint('R61')) || (A.memberOfFootprint('R80') && B.memberOfFootprint('R80')) || (A.memberOfFootprint('R81') && B.memberOfFootprint('R81')) || (A.memberOfFootprint('R82') && B.memberOfFootprint('R82')) || (A.memberOfFootprint('R85') && B.memberOfFootprint('R85')) || (A.memberOfFootprint('R86') && B.memberOfFootprint('R86')) || (A.memberOfFootprint('R87') && B.memberOfFootprint('R87'))"))

# Added 2026-11-21 (P1 finishing): copper pours next to HV60 copper keep the masked-area spacing on the outer layers everywhere.
# Stricter than the rules above, never looser: KiCad's zone filler does not evaluate intersectsArea(), so without this rule a
# pour would fill at 0.25 mm where "HV60 near masked areas" asks for 0.6 mm.
(rule "Pours next to HV60 keep 0.6 mm on outer layers"
  (layer outer)
  (constraint clearance (min 0.6mm))
  (condition "A.Type == 'Zone' && (A.hasNetclass('HV60') || B.hasNetclass('HV60')) && A.Net != B.Net"))