-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.stanza
131 lines (117 loc) · 4.26 KB
/
helpers.stanza
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
; ====================
; A number of helpful functions to check your designs, export to CAD,
; update your design in CAD, etc.
; ====================
#use-added-syntax(jitx)
defpackage helpers :
import core
import jitx
import jitx/commands
import jitx/parts
import jsl
; ==================
; setup-part-search
; ==================
jsl/design/settings/OPERATING-TEMPERATURE = min-max(0.0 50.0)
public var R-query
public var C-query
public defn setup-part-query (
--
vendors:Tuple<String|AuthorizedVendor> = jsl/design/settings/APPROVED-DISTRIBUTOR-LIST
) :
set-global-query-defaults!(
min-stock = 1, ; we want in stock parts
sellers! = vendors ; we want parts from these vendors
)
val all-cats = BaseQuery(
mounting = "smd", ; default mounting style for resistors and capacitors
case = ["0402", "0603"], ; default case size for resistors and capacitors
sort! = SortKey(area = Increasing) ; prefer smaller parts
)
; Must instantiate after setting global defaults.
R-query = ResistorQuery(
all-cats,
precision = (1 %) ; 1% tolerance parts, please
)
set-default-resistor-query!(R-query)
C-query = CapacitorQuery(
all-cats,
type = "ceramic", ; ceramic capacitors
temperature-coefficient_code = ["X7R", "X5R"], ; X7R and X5R dielectric capacitors
tolerance_max = 0.2, ; +/- 20% tolerance parts
rated-voltage = AtLeast(6.0) ; at least 6V rated capacitors
)
set-default-capacitor-query!(C-query)
; =================
; Setup BOM stuff
; =================
public defn setup-bill-of-materials (qty:Int, vendors:Tuple<String|AuthorizedVendor>) :
set-bom-metrics([
BOMMetric(BOMMetricLineItems, "Line Items"),
BOMMetric(BOMMetricComponentCount, "Components"),
BOMMetric(BOMMetricTotalCost, "Cost")
])
set-bom-columns([
BOMColumn(BOMFieldStatus, "Status", 10.0)
BOMColumn(BOMFieldQuantity, "Qty", 5.0)
BOMColumn(BOMFieldInsts, "References", 10.0)
BOMColumn(BOMFieldMPN, "MPN", 10.0)
BOMColumn(BOMFieldManufacturer, "Manufacturer", 10.0)
BOMColumn(BOMFieldDescription, "Description", 20.0)
BOMColumn(BOMFieldVendor, "Supplier", 10.0)
BOMColumn(BOMFieldSKU, "SKU", 10.0)
BOMColumn(BOMFieldDatasheet, "Datasheet", 10.0)
BOMColumn(BOMFieldPreferred, "Preferred", 5.0)
])
set-bom-vendors(vendors)
set-bom-design-quantity(qty)
; ====================
; Setup the board information using https://github.com/JITx-Inc/jlc-pcb.git
; JLC04161H-1080() is a stackup for a 4-layer board with 1.6mm thickness
; ====================
public val substrate = jlc-pcb/stackups/JLC04161H-1080/JLC04161H-1080()
; ============
; setup-design
; ============
public defn setup-design (name:String, board-shape:Shape
--
signal-shrink:Double = ?
vendors:Tuple<String|AuthorizedVendor> = jsl/design/settings/APPROVED-DISTRIBUTOR-LIST
quantity:Int = jsl/design/settings/DESIGN-QUANTITY
paper-size:Paper = ANSI-A
) :
; Set the current design name to the name provided in the string argument
set-current-design(name)
; Setup the part query
setup-part-query(vendors = vendors)
; Set the board definition
set-board(rf-sandbox/board/rf-board(board-shape))
; Set the design rules
set-rules(rf-sandbox/board/rf-rules)
; Setup the BOM report
setup-bill-of-materials(quantity, vendors)
; Set the paper size for the schematic and export
set-paper(paper-size)
set-use-layout-groups()
; set the CAD software for export to be kicad (also supported: `altium)
set-export-backend(`kicad)
; ====================
; Actual Export design
; ====================
public defn export-to-cad () :
; if we are exporting to Kicad for boards assembled at JLCPCB, we can add:
; ["vendor_part_numbers.lcsc" => "LCSC"] to the argument of export-cad()
; This will add the LCSC part number property to the symbols in the schematic
export-cad()
; ====================
; Export design to CAD
; ====================
public defn export-design () :
set-export-board?(true)
export-to-cad()
; ===================================
; Update CAD, keeping layout progress
; ===================================
public defn update-design () :
set-export-board?(false)
export-to-cad()