-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbattery_connector_jst_ph_2.js
360 lines (353 loc) · 16.4 KB
/
battery_connector_jst_ph_2.js
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
// Copyright (c) 2023 Marco Massarelli
//
// SPDX-License-Identifier: MIT
//
// To view a copy of this license, visit https://opensource.org/license/mit/
//
// Author: @ceoloide
//
// Description:
// A reversible JST PH 2.0mm footprint with support for solder jumpers and traces. This is
// the same part sold at Typeractive.xyz and LCSC.
//
// Note that the footprint's courtyard includes the space required for the male connector
// and its cables. Make sure to leave enough room in front of the connector. The silkscreen
// includes a handy reference for positive and negative terminals that remains visible
// after the connector is soldered, to ensure wire polarity is correct.
//
// Datasheet:
// https://cdn.shopify.com/s/files/1/0618/5674/3655/files/JST-S2B-PH-K.pdf?v=1670451309
//
// Params
// side: default is F for Front
// the side on which to place the single-side footprint and designator, either F or B
// reversible: default is false
// if true, the footprint will be placed on both sides so that the PCB can be
// reversible
// include_traces: default is true
// if true it will include traces that connect the jumper pads to the connector pins
// trace_width: default is 0.250mm
// allows to override the trace width that connects the jumper pads to the connector
// pins. Not recommended to go below 0.25mm.
// include_silkscreen: default is true
// if true it will include the silkscreen. Recommended to be true to ensure connector
// polarity is not reversed, which can lead to shorting and damage to the MCU
// include_fabrication: default is true
// if true it will include the outline of the connector in the fabrication layer
// include_courtyard: default is true
// if true it will include a courtyard outline around the connector and in front of it
// to also account for the male connector plug and the wires. Recommended to be true
// at least once in the development of a board to confirm sufficient clearance for the
// connector and wires.
// battery_connector_3dmodel_filename: default is ''
// Allows you to specify the path to a 3D model STEP or WRL file to be
// used when rendering the PCB. Use the ${VAR_NAME} syntax to point to
// a KiCad configured path.
// battery_connector_3dmodel_xyz_offset: default is [0, 0, 0]
// xyz offset (in mm), used to adjust the position of the 3d model
// relative the footprint.
// battery_connector_3dmodel_xyz_scale: default is [1, 1, 1]
// xyz scale, used to adjust the size of the 3d model relative to its
// original size.
// battery_connector_3dmodel_xyz_rotation: default is [0, 0, 0]
// xyz rotation (in degrees), used to adjust the orientation of the 3d
// model relative the footprint.
module.exports = {
params: {
designator: 'JST',
side: 'F',
reversible: false,
include_traces: true,
trace_width: 0.250,
include_silkscreen: true,
include_fabrication: true,
include_courtyard: true,
battery_connector_3dmodel_filename: '',
battery_connector_3dmodel_xyz_offset: [0, 0, 0],
battery_connector_3dmodel_xyz_rotation: [0, 0, 0],
battery_connector_3dmodel_xyz_scale: [1, 1, 1],
BAT_P: { type: 'net', value: 'BAT_P' },
BAT_N: { type: 'net', value: 'GND' },
},
body: p => {
let local_nets = [
p.local_net("1"),
p.local_net("2"),
];
const standard_opening = `
(footprint "ceoloide:battery_connector_jst_ph_2"
(layer "${p.side}.Cu")
${p.at}
(property "Reference" "${p.ref}"
(at 0 4.8 ${p.r})
(layer "${p.side}.SilkS")
${p.ref_hide}
(effects (font (size 1 1) (thickness 0.15)))
)
`
const front_fabrication = `
(fp_line (start -2.95 -1.35) (end -2.95 6.25) (stroke (width 0.1) (type solid)) (layer "F.Fab"))
(fp_line (start -2.95 6.25) (end 2.95 6.25) (stroke (width 0.1) (type solid)) (layer "F.Fab"))
(fp_line (start -2.25 -1.35) (end -2.95 -1.35) (stroke (width 0.1) (type solid)) (layer "F.Fab"))
(fp_line (start -2.25 0.25) (end -2.25 -1.35) (stroke (width 0.1) (type solid)) (layer "F.Fab"))
(fp_line (start 2.25 -1.35) (end 2.25 0.25) (stroke (width 0.1) (type solid)) (layer "F.Fab"))
(fp_line (start 2.25 0.25) (end -2.25 0.25) (stroke (width 0.1) (type solid)) (layer "F.Fab"))
(fp_line (start 2.95 -1.35) (end 2.25 -1.35) (stroke (width 0.1) (type solid)) (layer "F.Fab"))
(fp_line (start 2.95 6.25) (end 2.95 -1.35) (stroke (width 0.1) (type solid)) (layer "F.Fab"))
`
const front_courtyard = `
(fp_line (start -3.45 -1.85) (end -3.45 10.5) (stroke (width 0.05) (type solid)) (layer "F.CrtYd"))
(fp_line (start -3.45 10.5) (end 3.45 10.5) (stroke (width 0.05) (type solid)) (layer "F.CrtYd"))
(fp_line (start 3.45 -1.85) (end -3.45 -1.85) (stroke (width 0.05) (type solid)) (layer "F.CrtYd"))
(fp_line (start 3.45 10.5) (end 3.45 -1.85) (stroke (width 0.05) (type solid)) (layer "F.CrtYd"))
`
const front_silkscreen = `
(fp_line (start -1.5 7.40) (end -0.5 7.40) (stroke (width 0.1) (type solid)) (layer "F.SilkS"))
(fp_line (start 1.5 7.40) (end 0.5 7.40) (stroke (width 0.1) (type solid)) (layer "F.SilkS"))
(fp_line (start 1 6.90) (end 1 7.90) (stroke (width 0.1) (type solid)) (layer "F.SilkS"))
(fp_line (start -2.06 -1.46) (end -3.06 -1.46) (stroke (width 0.12) (type solid)) (layer "F.SilkS"))
(fp_line (start -3.06 -1.46) (end -3.06 -0.46) (stroke (width 0.12) (type solid)) (layer "F.SilkS"))
(fp_line (start 2.14 -1.46) (end 3.06 -1.46) (stroke (width 0.12) (type solid)) (layer "F.SilkS"))
(fp_line (start 3.06 -1.46) (end 3.06 -0.46) (stroke (width 0.12) (type solid)) (layer "F.SilkS"))
(fp_line (start -2.14 6.36) (end -3.06 6.36) (stroke (width 0.12) (type solid)) (layer "F.SilkS"))
(fp_line (start -3.06 6.36) (end -3.06 5.36) (stroke (width 0.12) (type solid)) (layer "F.SilkS"))
(fp_line (start 2.14 6.36) (end 3.06 6.36) (stroke (width 0.12) (type solid)) (layer "F.SilkS"))
(fp_line (start 3.06 6.36) (end 3.06 5.36) (stroke (width 0.12) (type solid)) (layer "F.SilkS"))
`
const back_fabrication = `
(fp_line (start -2.95 -1.35) (end -2.25 -1.35) (stroke (width 0.1) (type solid)) (layer "B.Fab"))
(fp_line (start -2.95 6.25) (end -2.95 -1.35) (stroke (width 0.1) (type solid)) (layer "B.Fab"))
(fp_line (start -2.25 -1.35) (end -2.25 0.25) (stroke (width 0.1) (type solid)) (layer "B.Fab"))
(fp_line (start -2.25 0.25) (end 2.25 0.25) (stroke (width 0.1) (type solid)) (layer "B.Fab"))
(fp_line (start 2.25 -1.35) (end 2.95 -1.35) (stroke (width 0.1) (type solid)) (layer "B.Fab"))
(fp_line (start 2.25 0.25) (end 2.25 -1.35) (stroke (width 0.1) (type solid)) (layer "B.Fab"))
(fp_line (start 2.95 -1.35) (end 2.95 6.25) (stroke (width 0.1) (type solid)) (layer "B.Fab"))
(fp_line (start 2.95 6.25) (end -2.95 6.25) (stroke (width 0.1) (type solid)) (layer "B.Fab"))
`
const back_courtyard = `
(fp_line (start -3.45 -1.85) (end -3.45 10.5) (stroke (width 0.05) (type solid)) (layer "B.CrtYd"))
(fp_line (start -3.45 10.5) (end 3.45 10.5) (stroke (width 0.05) (type solid)) (layer "B.CrtYd"))
(fp_line (start 3.45 -1.85) (end -3.45 -1.85) (stroke (width 0.05) (type solid)) (layer "B.CrtYd"))
(fp_line (start 3.45 10.5) (end 3.45 -1.85) (stroke (width 0.05) (type solid)) (layer "B.CrtYd"))
`
const back_silkscreen = `
(fp_line (start 1.5 7.40) (end 0.5 7.40) (stroke (width 0.1) (type solid)) (layer "B.SilkS"))
(fp_line (start -1.5 7.40) (end -0.5 7.40) (stroke (width 0.1) (type solid)) (layer "B.SilkS"))
(fp_line (start -1 6.90) (end -1 7.90) (stroke (width 0.1) (type solid)) (layer "B.SilkS"))
(fp_line (start -2.06 -1.46) (end -3.06 -1.46) (stroke (width 0.12) (type solid)) (layer "B.SilkS"))
(fp_line (start -3.06 -1.46) (end -3.06 -0.46) (stroke (width 0.12) (type solid)) (layer "B.SilkS"))
(fp_line (start 2.14 -1.46) (end 3.06 -1.46) (stroke (width 0.12) (type solid)) (layer "B.SilkS"))
(fp_line (start 3.06 -1.46) (end 3.06 -0.46) (stroke (width 0.12) (type solid)) (layer "B.SilkS"))
(fp_line (start -2.14 6.36) (end -3.06 6.36) (stroke (width 0.12) (type solid)) (layer "B.SilkS"))
(fp_line (start -3.06 6.36) (end -3.06 5.36) (stroke (width 0.12) (type solid)) (layer "B.SilkS"))
(fp_line (start 2.14 6.36) (end 3.06 6.36) (stroke (width 0.12) (type solid)) (layer "B.SilkS"))
(fp_line (start 3.06 6.36) (end 3.06 5.36) (stroke (width 0.12) (type solid)) (layer "B.SilkS"))
`
const front_pads = `
(pad "1" thru_hole roundrect (at -1 0 ${p.r}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") (roundrect_rratio 0.20) ${p.BAT_N.str})
(pad "2" thru_hole oval (at 1 0 ${p.r}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${p.BAT_P.str})
`
const back_pads = `
(pad "1" thru_hole roundrect (at 1 0 ${p.r}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") (roundrect_rratio 0.20) ${p.BAT_N.str})
(pad "2" thru_hole oval (at -1 0 ${p.r}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${p.BAT_P.str})
`
const reversible_pads = `
(pad "11" thru_hole oval (at -1 0 ${p.r}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${local_nets[0].str})
(pad "12" thru_hole oval (at 1 0 ${p.r}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${local_nets[1].str})
(pad "21" smd custom (at -1 1.8 ${180 + p.r}) (size 0.1 0.1) (layers "F.Cu" "F.Mask" "F.Paste")
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
(gr_poly
(pts
(xy 0.6 0.4)
(xy -0.6 0.4)
(xy -0.6 0.2)
(xy 0 -0.4)
(xy 0.6 0.2)
)
(width 0)
(fill yes)
)
)
${local_nets[0]}
)
(pad "31" smd custom (at -1 1.8 ${180 + p.r}) (size 0.1 0.1) (layers "B.Cu" "B.Mask" "B.Paste")
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
(gr_poly
(pts
(xy 0.6 0.4)
(xy -0.6 0.4)
(xy -0.6 0.2)
(xy 0 -0.4)
(xy 0.6 0.2)
)
(width 0)
(fill yes)
)
)
${local_nets[0]}
)
(pad "22" smd custom (at 1 1.8 ${180 + p.r}) (size 0.1 0.1) (layers "F.Cu" "F.Mask" "F.Paste")
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
(gr_poly
(pts
(xy 0.6 0.4)
(xy -0.6 0.4)
(xy -0.6 0.2)
(xy 0 -0.4)
(xy 0.6 0.2)
)
(width 0)
(fill yes)
)
)
${local_nets[1]}
)
(pad "32" smd custom (at 1 1.8 ${180 + p.r}) (size 0.1 0.1) (layers "B.Cu" "B.Mask" "B.Paste")
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
(gr_poly
(pts
(xy 0.6 0.4)
(xy -0.6 0.4)
(xy -0.6 0.2)
(xy 0 -0.4)
(xy 0.6 0.2)
)
(width 0)
(fill yes)
)
)
${local_nets[1]}
)
(pad "1" smd custom (at -1 2.816 ${180 + p.r}) (size 1.2 0.5) (layers "F.Cu" "F.Mask" "F.Paste") ${p.BAT_P.str}
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
(gr_poly
(pts
(xy 0.6 0)
(xy -0.6 0)
(xy -0.6 1)
(xy 0 0.4)
(xy 0.6 1)
)
(width 0)
(fill yes)
)
)
)
(pad "1" smd custom (at 1 2.816 ${180 + p.r}) (size 1.2 0.5) (layers "B.Cu" "B.Mask" "B.Paste") ${p.BAT_P.str}
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
(gr_poly
(pts
(xy 0.6 0)
(xy -0.6 0)
(xy -0.6 1)
(xy 0 0.4)
(xy 0.6 1)
)
(width 0)
(fill yes)
)
)
)
(pad "2" smd custom (at -1 2.816 ${180 + p.r}) (size 1.2 0.5) (layers "B.Cu" "B.Mask" "B.Paste") ${p.BAT_N.str}
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
(gr_poly
(pts
(xy 0.6 0)
(xy -0.6 0)
(xy -0.6 1)
(xy 0 0.4)
(xy 0.6 1)
)
(width 0)
(fill yes)
)
)
)
(pad "2" smd custom (at 1 2.816 ${180 + p.r}) (size 1.2 0.5) (layers "F.Cu" "F.Mask" "F.Paste") ${p.BAT_N.str}
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
(gr_poly
(pts
(xy 0.6 0)
(xy -0.6 0)
(xy -0.6 1)
(xy 0 0.4)
(xy 0.6 1)
)
(width 0)
(fill yes)
)
)
)
`
const standard_closing = `
)
`
const reversible_traces = `
(segment (start ${p.eaxy(-1, 1.8)}) (end ${p.eaxy(-1, 0)}) (width ${p.trace_width}) (layer "F.Cu") (net ${local_nets[0].index}))
(segment (start ${p.eaxy(-1, 1.8)}) (end ${p.eaxy(-1, 0)}) (width ${p.trace_width}) (layer "B.Cu") (net ${local_nets[0].index}))
(segment (start ${p.eaxy(1, 1.8)}) (end ${p.eaxy(1, 0)}) (width ${p.trace_width}) (layer "F.Cu") (net ${local_nets[1].index}))
(segment (start ${p.eaxy(1, 1.8)}) (end ${p.eaxy(1, 0)}) (width ${p.trace_width}) (layer "B.Cu") (net ${local_nets[1].index}))
`
const battery_connector_3dmodel = `
(model ${p.battery_connector_3dmodel_filename}
(offset (xyz ${p.battery_connector_3dmodel_xyz_offset[0]} ${p.battery_connector_3dmodel_xyz_offset[1]} ${p.battery_connector_3dmodel_xyz_offset[2]}))
(scale (xyz ${p.battery_connector_3dmodel_xyz_scale[0]} ${p.battery_connector_3dmodel_xyz_scale[1]} ${p.battery_connector_3dmodel_xyz_scale[2]}))
(rotate (xyz ${p.battery_connector_3dmodel_xyz_rotation[0]} ${p.battery_connector_3dmodel_xyz_rotation[1]} ${p.battery_connector_3dmodel_xyz_rotation[2]}))
)
`
let final = standard_opening;
if (p.side == "F" || p.reversible) {
if (p.include_fabrication) {
final += front_fabrication;
}
if (p.include_courtyard) {
final += front_courtyard;
}
if (p.include_silkscreen) {
final += front_silkscreen;
}
}
if (p.side == "B" || p.reversible) {
if (p.include_fabrication) {
final += back_fabrication;
}
if (p.include_courtyard) {
final += back_courtyard;
}
if (p.include_silkscreen) {
final += back_silkscreen;
}
}
if (p.reversible) {
final += reversible_pads;
} else if (p.side == "F") {
final += front_pads;
} else if (p.side == "B") {
final += back_pads;
}
if (p.battery_connector_3dmodel_filename) {
final += battery_connector_3dmodel
}
final += standard_closing;
if (p.reversible && p.include_traces) {
final += reversible_traces;
}
return final;
}
}