Skip to content

Commit

Permalink
Added a tool to query for a via from a Substrate
Browse files Browse the repository at this point in the history
This provides a tool for selecting a via from a Substrate
definition without having to refer to an explicit via
definition. This helps with swapping in/out PCB
substrate definitions for a design.
  • Loading branch information
callendorph committed Oct 23, 2024
1 parent 38f9494 commit 225b980
Showing 1 changed file with 100 additions and 1 deletion.
101 changes: 100 additions & 1 deletion src/design/Substrate.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ defpackage jsl/design/Substrate:
import jitx
import jitx/commands

import maybe-utils

import jsl/ensure
import jsl/errors
import jsl/layerstack
Expand Down Expand Up @@ -255,7 +257,6 @@ public defn make-uncoupled-region (default:RoutingStructure, uncoupled?:Maybe<Ro

uncoupled-region = uncoupled-spec


doc: \<DOC>
Convert a Substrate into a `pcb-board` definition
@param f Substrate
Expand Down Expand Up @@ -283,3 +284,101 @@ public defn make-board-def (f:Substrate, outline:Shape -- signal-shrink:Maybe<Do
signal-boundary = value(given)
vias = vias(f)
board-def-pcb

defn check-layer (
f:Substrate,
v:Via,
start:Maybe<LayerIndex|Side>
stop:Maybe<LayerIndex|Side>
) -> True|False:
val ls = stackup(f)
val sl? = map(start, to-layer-index)
val el? = map(stop, to-layer-index)
val s = via-start(v)
val e = via-stop(v)
match(sl?, el?):
(sl:None, el:None):
true
(sl:One<LayerIndex>, el:None):
in-range?(ls, value(sl), s, e)
(sl:None, el:One<LayerIndex>):
in-range?(ls, value(el), s, e)
(sl:One<LayerIndex>, el:One<LayerIndex>):
in-range?(ls, value(sl), s, e) and in-range?(ls, value(el), s, e)

defn check-type (
v:Via,
type?:Maybe<MechanicalDrill|LaserDrill>
) -> True|False :
match(type?):
(_:None): true
(given:One<MechanicalDrill|LaserDrill>):
value(given) == via-type(v)

defn check-boolean (v:Via, spec?:Maybe<True|False>, func:(Via -> True|False)) -> True|False :
match(spec?):
(_:None): true
(given:One<True|False>):
value(given) == func(v)

val check-filled = check-boolean{_0, _1, via-filled}
val check-via-in-pad = check-boolean{_0, _1, via-in-pad}

defn check-tented (v:Via, tented?:Maybe<True|False|Side>) -> True|False :
match(tented?):
(_:None): true
(given:One<True|False|Side>):
value(given) == via-tented(v)

defn check-backdrill (f:Substrate, v:Via, backdrill?:Maybe<True|False>) -> True|False :
match(backdrill?):
(_:None): true
(given:One<True|False>):
value(given) == (via-backdrill(v) is-not False)

doc: \<DOC>
Query for a via defined in this substrate

This allows the user to query for a via that
matches some set of requirements from the substrate.
This allows us to avoid using explicit via definitions
in code for easier swapping of substrates.

If a query parameter is not provided, then it defaults
to `None()` and it will not affect the resulting via set.

@param f Substrate to query
@param start Copper layer for the start of the via
@param stop Copper layer for the end of the via
@param type Mechanical vs Laser Selector
@param filled Selects for filled state
@param tented Selects for tented state
@param via-in-pad Selects for Via-in-Pad eligibility
@param backdrill Selects for any via that is configured
for a backdrill.
<DOC>
public defn query-via (
f:Substrate --
start:LayerIndex|Side = ?
stop:LayerIndex|Side = ?,
type:MechanicalDrill|LaserDrill = ?,
filled:True|False = ?,
tented:Side|True|False = ?,
via-in-pad:True|False = ?
backdrill:True|False = ?
) -> Seq<Via> :

val vs = vias(f)
val checks = [
{check-layer(f, _0, start, stop)},
{check-type(_0, type)},
{check-filled(_0, filled)}
{check-tented(_0, tented)}
{check-via-in-pad(_0, via-in-pad)}
{check-backdrill(f, _0, backdrill)}
]
for v in vs seq?:
val ret = for ch-func in checks all?:
ch-func(v)
if ret: One(v)
else: None()

0 comments on commit 225b980

Please sign in to comment.