Debian Codegraph @

texmf-dist/doc/latex/circuit-macros/examples/dpv/xcsDPV.m4

raw
1 divert(-1)
2
3 Macros defining some integrated circuits and connectors for svg
4
5 `A sequence of pins along the east or west side of a chip:
6 lg_pinseq(initial pin no, final pin no,
7 e|w, initial offset, pinnum_root, Labelroot, [N])'
8 `e.g., lg_pinseq(1,8,w)'
9 define(`lg_pinseq',`for_($1,$2,1,
10 `lg_pin( Chip.s`$3'+(0,eval($4+m4x)*lg_pinsep),
11 $6`'m4x,Pin`'eval($5`'m4x),`$3'`$7',eval($5`'m4x))') ')
12
13 define(`ic_tiny',`iflatex(`\hbox{\tiny `$1'}',ifsvg(`svg_small(`$1')',`$1'))')
14
15 define(`ic6116',`[ Chip: box wid_ lg_chipwd ht_ 15*lg_pinsep
16 lg_pin(Chip.sw_+(0,lg_pinsep),GND,Pin12,w,12)
17 lg_pin(Chip.sw_+(0,2*lg_pinsep),lg_bartxt(CS),Pin18,wN,18)
18 lg_pinseq(0,2,w,4,9+,D)
19 lg_pinseq(3,7,w,4,10+,D)
20 lg_pin(Chip.sw_+(0,13*lg_pinsep),R/lg_bartxt(W),Pin21,w,21)
21 lg_pin(Chip.sw_+(0,14*lg_pinsep),V`'ic_tiny(CC),Pin24,w,24)
22 lg_pin(Chip.se_+(0,lg_pinsep),lg_bartxt(OE),Pin20,eN,20)
23 lg_pinseq(0,7,e,3,8-,A)
24 lg_pinseq(8,9,e,3,31-,A)
25 lg_pin(Chip.se_+(0,13*lg_pinsep),A10,Pin19,e,19)
26 `$1']')
27
28 define(`ic6502',`[ Chip: box wid_ lg_chipwd ht_ 24*lg_pinsep
29 lg_pin(Chip.sw_+(0,lg_pinsep),V`'ic_tiny(SS),Pin21,w,21)
30 lg_pin(Chip.sw_+(0,2*lg_pinsep),V`'ic_tiny(SS),Pin1,w,1)
31 lg_pin(Chip.sw_+(0,4*lg_pinsep),R/lg_bartxt(W),Pin34,w,34)
32 lg_pinseq(0,7,w,6,33-,D)
33 lg_pin(Chip.sw_+(0,15*lg_pinsep),lg_bartxt(RESET),Pin40,wN,40)
34 lg_pin(Chip.sw_+(0,17*lg_pinsep),SYNC,Pin7,w,7)
35 lg_pin(Chip.sw_+(0,19*lg_pinsep),lg_bartxt(NMI),Pin6,wN,6)
36 lg_pin(Chip.sw_+(0,21*lg_pinsep),RDY,Pin2,w,2)
37 lg_pin(Chip.sw_+(0,22*lg_pinsep),SO,Pin38,w,38)
38 lg_pin(Chip.sw_+(0,23*lg_pinsep),V`'ic_tiny(CC),Pin8,w,8)
39 lg_pin(Chip.se_+(0,lg_pinsep),CK`'ic_tiny(1)(in),Pin39,e,39)
40 lg_pin(Chip.se_+(0,4*lg_pinsep), CK`'ic_tiny(2)(out),Pin37,e,37)
41 lg_pinseq(0,11,e,6,9+,A)
42 lg_pinseq(12,15,e,6,10+,A)
43 lg_pin(Chip.se+(0,23*lg_pinsep),lg_bartxt(IRQ),Pin4,eN,4)
44 `$1']')
45
46 define(`ic6522',`[ Chip: box wid_ lg_chipwd ht_ 24*lg_pinsep
47 lg_pin(Chip.sw_+(0,lg_pinsep),V`'ic_tiny(SS),Pin1,w,1)
48 lg_pin(Chip.sw_+(0,3*lg_pinsep),CS1,Pin24,w,24)
49 lg_pin(Chip.sw_+(0,4*lg_pinsep),CK,Pin25,w,25)
50 lg_pin(Chip.sw_+(0,5*lg_pinsep),lg_bartxt(CS2),Pin23,wN,23)
51 lg_pin(Chip.sw_+(0,7*lg_pinsep),RS0(A0),Pin38,w,38)
52 lg_pin(Chip.sw_+(0,8*lg_pinsep),RS1(A1),Pin37,w,37)
53 lg_pin(Chip.sw_+(0,9*lg_pinsep),RS2(A2),Pin36,w,36)
54 lg_pin(Chip.sw_+(0,10*lg_pinsep),RS3(A3),Pin35,w,35)
55 lg_pinseq(0,7,w,12,33-,D)
56 lg_pin(Chip.sw_+(0,21*lg_pinsep),R/lg_bartxt(W),Pin22,w,22)
57 lg_pin(Chip.sw_+(0,22*lg_pinsep),lg_bartxt(IRQ),Pin21,wN,21)
58 lg_pin(Chip.sw_+(0,23*lg_pinsep),V`'ic_tiny(CC),Pin20,w,20)
59 lg_pinseq(0,7,e,1,10+,PB)
60 lg_pinseq(1,2,e,8,17+,CB)
61 lg_pinseq(0,7,e,12,2+,PA)
62 lg_pinseq(1,2,e,19,41-,CA)
63 lg_pin(Chip.se_+(0,23*lg_pinsep),lg_bartxt(RESET),Pin34,eN,34)
64 `$1']')
65
66 define(`ic74LS138',`[ Chip: box wid_ lg_chipwd ht_ 11*lg_pinsep
67 lg_pin(Chip.sw_+(0,lg_pinsep),GND,Pin8,w,8)
68 lg_pin(Chip.sw_+(0,2*lg_pinsep),lg_bartxt(G2a),Pin4,wN,4)
69 lg_pin(Chip.sw_+(0,3*lg_pinsep),lg_bartxt(G2b),Pin5,wN,5)
70 lg_pin(Chip.sw_+(0,5*lg_pinsep),A,Pin1,w,1)
71 lg_pin(Chip.sw_+(0,6*lg_pinsep),B,Pin2,w,2)
72 lg_pin(Chip.sw_+(0,7*lg_pinsep),C,Pin3,w,3)
73 lg_pin(Chip.sw_+(0,9*lg_pinsep),G1,Pin6,w,6)
74 lg_pin(Chip.sw_+(0,10*lg_pinsep),V`'ic_tiny(CC),Pin16,w,16)
75 lg_pinseq(0,6,e,2,15-,Y,n)
76 lg_pin(Chip.se_+(0,9*lg_pinsep),Y7,Pin7,eN,7)
77 `$1']')
78
79 define(`ic4017DIP',`[ Chip: DIP_chip_outline(16)
80 foreach_(`x',
81 `lg_pin(Chip.nw-(0,lg_pinsep*m4Lx),x,Pin`'m4Lx,w,m4Lx)',
82 PL, Q3, I3, I0, CLE, Q0, TC, GND)
83 foreach_(`x',
84 `lg_pin(Chip.se+(0,lg_pinsep*m4Lx),x,Pin`'eval(m4Lx+8),e,eval(m4Lx+8))',
85 MR, U/D, Q1, I1, I2, Q2, CLK, Vcc)
86 `$1']')
87
88 define(`ic4510DIP',`[ Chip: DIP_chip_outline(16)
89 foreach_(`x',
90 `lg_pin(Chip.nw-(0,lg_pinsep*m4Lx),x,Pin`'m4Lx,w,m4Lx)',
91 PL, Q3, I3, I0, CLE, Q0, TC, GND)
92 foreach_(`x',
93 `lg_pin(Chip.se+(0,lg_pinsep*m4Lx),x,Pin`'eval(m4Lx+8),e,eval(m4Lx+8))',
94 MR, U/D, Q1, I1, I2, Q2, CLK, Vcc)
95 `$1']')
96
97 define(`icVS1053DIP',`[ Chip: DIP_chip_outline(32)
98 foreach_(`x',
99 `lg_pin(Chip.nw-(0,lg_pinsep*m4Lx),x,Pin`'m4Lx,w,m4Lx)',
100 LOUT,ROUT,GBUF,AGND,AGND,DREG,Vcc,3V3,GND,MISO,MOSI,sclk,RST,CS,DCS,DCS)
101 foreach_(`x',
102 `lg_pin(Chip.se+(0,lg_pinsep*m4Lx),x,Pin`'eval(m4Lx+16),e,eval(m4Lx+16))',
103 SDCD,RX,TX,7,6,5,4,3,2,1,0,GND,3V3,AGND,MIC`'svg_it(-),MIC`'svg_it(+))
104 `$1']')
105
106 `ArduinoUno( wid,ht,pinlen )'
107 define(`ArduinoUno',`[
108 define(`m4bwid',`ifelse(`$1',,`24*L_unit',`$1')')dnl
109 define(`m4bht',`ifelse(`$2',,`20*lg_pinsep',`$2')')dnl
110 #
111
112 Connector: box wid m4bwid ht m4bht
113 #
114 m4pl = ifelse(`$3',,`2*L_unit',`$3')
115 #
116 foreach_(`x',`ifelse(x,nul,,
117 `Pin`'eval(5+m4Lx): line left_ m4pl from Connector.nw-(0,(5+m4Lx)*lg_pinsep)
118 { "x" ljust at last line.start }')',
119 IOREF, RESET,svg_it(+)3V3,svg_it(+)5V, GND, GND, VIN,
120 nul, A0, A1, A2, A3, A4, A5)
121 #
122 foreach_(`x',`ifelse(x,nul,,
123 `Pin`'eval(22-m4Lx): line right_ m4pl from Connector.ne-(0,m4Lx*lg_pinsep)
124 { "x" rjust at last line.start }')',
125 SCL, SDA, AREF, GND, D13, D12, ~D11, ~D10, ~D9, D8,
126 nul, D7, ~D6, ~D5, D4, ~D3, D2, TX D1, RX D0)
127 #
128 `$4'] ')
129
130 `ArduinoLeonardo( wid,ht,pinlen )'
131 define(`ArduinoLeonardo',`[
132 define(`m4bwid',`ifelse(`$1',,`24*L_unit',`$1')')dnl
133 define(`m4bht',`ifelse(`$2',,`20*lg_pinsep',`$2')')dnl
134 #
135 Connector: box wid m4bwid ht m4bht
136 #
137 m4pl = ifelse(`$3',,`2*L_unit',`$3')
138 #
139 foreach_(`x',`ifelse(x,nul,,
140 `Pin`'eval(5+m4Lx): line left_ m4pl from Connector.nw-(0,(5+m4Lx)*lg_pinsep)
141 { "x" ljust at last line.start }')',
142 IOREF, RESET,svg_it(+)3V3,svg_it(+)5V, GND, GND, VIN,
143 nul, A0, A1, A2, A3, A4, A5)
144 #
145 foreach_(`x',`ifelse(x,nul,,
146 `Pin`'eval(22-m4Lx): line right_ m4pl from Connector.ne-(0,m4Lx*lg_pinsep)
147 { "x" rjust at last line.start }')',
148 SCL, SDA, AREF, GND,
149 ~D13, D12, ~D11, ~D10, ~D9, D8,
150 nul, D7, ~D6, ~D5, D4, ~D3, D2, TX D1, RX D0)
151 #
152 `$4'] ')
153
154 `RPi( wid,ht,pinlen )'
155 define(`RPi',`[
156 define(`m4bwid',`ifelse(`$1',,`34*L_unit',`$1')')dnl
157 define(`m4bht',`ifelse(`$2',,`21*lg_pinsep',`$2')')dnl
158 #
159 GPIO: box wid m4bwid ht m4bht
160 m4pl = ifelse(`$3',,`6*L_unit',`$3')
161 #
162 define A_LeftGPIO {
163 exec sprintf("Pin%g: line left_ m4pl from GPIO.nw-(0,%g)",\
164 2*(`$'1)-1,(`$'1)*lg_pinsep)
165 { "`$'3" ljust at last line.start }
166 "`$'2" at last line.c above }
167 #
168 foreach_(`x',`ifelse(x,nul,,`A_LeftGPIO(m4Lx,patsubst(x,;,`,'))')',
169 ;3V3,
170 2;SDA1, 3;SCL1, 4;GPIO_GCLK,
171 ;GND,
172 17;GPIO_GEN0, 27;GPIO_GEN2,
173 22;GPIO_GEN3,
174 ;3V3,
175 10;SPI_MOSI, 9;SPI_MISO,
176 11;SPI_SCLK,
177 ;GND,
178 ;ID_SD,
179 5;, 6;, 13;, 19;, 26;,
180 ;GND )
181 #
182 define A_RightGPIO {
183 exec sprintf("Pin%g: line right_ m4pl from GPIO.ne-(0,%g)",\
184 2*(`$'1),(`$'1)*lg_pinsep)
185 { "`$'3" rjust at last line.start }
186 "`$'2" at last line.c above }
187 #
188 foreach_(`x',`ifelse(x,nul,,`A_RightGPIO(m4Lx,patsubst(x,;,`,'))')',
189 ;5V,
190 ;5V,
191 ;GND,
192 14;TXD0, 15;RXD0, 18;GPIO_GEN1,
193 ;GND,
194 23;GPIO_GEN4, 24;GPIO_GEN5,
195 ;GND,
196 25;GPIO_GEN6, 8;SPI_CEO_N,
197 7;SPI_CE1_N,
198 ;ID_SC,
199 ;GND,
200 12;,
201 ;GND,
202 16;, 20;, 21; )
203 #
204 `$4'] ')
205
206 `USB_C_Socket( wid, ht, pinlen )'
207 define(`USB_C_Socket',`[
208 define(`m4bwid',`ifelse(`$1',,`18*L_unit',`$1')')dnl
209 define(`m4bht',`ifelse(`$2',,`14*lg_pinsep',`$2')')dnl
210 #
211 Base: box wid m4bwid ht m4bht rad 5/3*lg_pinsep
212 m4pl = ifelse(`$3',,`6*L_unit',`$3')
213 #
214 foreach_(`x',
215 `B`'eval(13-m4Lx): dnl
216 line left_ m4pl from Base.n-(m4bwid/2,(m4Lx+0.5)*lg_pinsep)
217 {"x" ljust at last line.start}',
218 GND, RX1`'svg_it(+), RX1`'svg_it(-), VBUS, SBU2, D`'svg_it(-),
219 D`'svg_it(+), CC2, VBUS, TX2`'svg_it(-), TX2`'svg_it(+), GND)
220 #
221 foreach_(`x',
222 `A`'m4Lx: line right_ m4pl from Base.n+(m4bwid/2,-(m4Lx+0.5)*lg_pinsep)
223 {"x" rjust at last line.start}',
224 GND, TX1`'svg_it(+), TX1`'svg_it(-), VBUS, CC1, D`'svg_it(+),
225 D`'svg_it(-), SBU1, VBUS, RX2`'svg_it(-), RX2`'svg_it(+), GND)
226 #
227 `$4']')
228
229 `HDMI_micro( wid, ht, pinlen )'
230 define(`HDMI_micro',`[
231 define(`m4bwid',`ifelse(`$1',,`16*L_unit',`$1')')dnl
232 define(`m4bht',`ifelse(`$2',,`19*lg_pinsep+m4bwid*2/3',`$2')')dnl
233 #
234 Base:[line up m4bht/2 then right m4bwid*2/3 \
235 then right m4bwid/3 down m4bwid/3 \
236 then down m4bht-2*m4bwid/3 then down m4bwid/3 left m4bwid/3 \
237 then left m4bwid*2/3 then to Here]
238 m4pl = ifelse(`$3',,`6*L_unit',`$3')
239 #
240 foreach_(`x',
241 `Pin`'m4Lx: line left_ m4pl from Base.nw-(0,m4bwid/3+(m4Lx-1/2)*lg_pinsep)
242 {"x" ljust at last line.start}
243 "m4Lx" at last line.c above',
244 HPD, UTILITY, D2`'svg_it(+), D2_SH, D2`'svg_it(-),
245 D1`'svg_it(+), D1_SH, D1`'svg_it(-),D0`'svg_it(+), D0_SH,
246 D0`'svg_it(-), CLK`'svg_it(+), CLK_SH, CLK`'svg_it(-),
247 CEC, GND, SCL, SDA,svg_it(+)5V)
248 L1: line from Base.nw+(m4bwid*2/3-lg_pinsep,0) up m4pl
249 svg_rot(90,"21",at last line.c +(-4bp__,0))
250 svg_rot(90,"SH2",at last line.start + (4bp__,-8bp__))
251 line from Base.nw+(m4bwid*2/3-2*lg_pinsep,0) up m4pl
252 svg_rot(90,"20",at last line.c+(-4bp__,0))
253 svg_rot(90,"SH1",at last line.start + (4bp__,-8bp__))
254 line from Base.sw+(m4bwid*2/3-lg_pinsep,0) down m4pl
255 svg_rot(90,"23",at last line.c+(-4bp__,0))
256 svg_rot(90,"SH4",at last line.start + (4bp__,14bp__))
257 line from Base.sw+(m4bwid*2/3-2*lg_pinsep,0) down m4pl
258 svg_rot(90,"22",at last line.c+(-4bp__,0))
259 svg_rot(90,"SH3",at last line.start + (4bp__,14bp__))
260 #
261 `$4']')
262
263 `DIP_chip_outline( pin count, wid )'
264 define(`DIP_chip_outline',
265 `[ define(`m4pinct',`ifelse(`$1',,16,`$1')')dnl
266 define(`m4chgw',`ifelse(`$2',,(18*L_unit),`$2')')dnl
267 Chip: box invis wid m4chgw ht lg_pinsep*eval((m4pinct)/2+1)
268 arcd(last box.n, lg_pinsep/2, 180, 360)
269 { line to last box.ne chop -linewid bp__/2 }
270 { line from last arc.start to last box.nw chop -linewid bp__/2 }
271 line from last box.nw to last box.sw then to last box.se then to last box.ne
272 `$3']')
273
274 `DIP( pin count, attributes)
275 Dual in-line package
276 attributes=semicolon-separated list of optional terms:
277 bodywid=expr; (default 0.25 = 5*L_unit )
278 bodylen=expr; (default pin count/2 x pinpitch)
279 pinpitch=expr; (default 0.1)
280 pinwid=expr; (default 0.06)
281 pinlen=expr; (default 0.05)
282 direct=U|D|L|R;(default U for up)
283 type=I|Q; (default I for uniform-length pins;
284 Q: staggered) '
285 define(`DIP',`[ pinct= ifelse(`$1',,8,`$1')
286 foreach_(`Z',`pushkey_(`$2',patsubst(Z,:.*),patsubst(Z,.*:))',
287 bodywid: 5*L_unit,
288 bodylen: m4pinpitch*int(pinct/2+0.5),
289 pinpitch:2*L_unit,
290 pinwid: 1.2*L_unit,
291 pinlen: L_unit)
292 foreach_(`Z',`pushkey_(`$2',patsubst(Z,:.*),patsubst(Z,.*:),N)',
293 direct:U,
294 type:I)
295 setdir_(m4direct,U)
296 Body: box ht_ m4bodywid wid_ m4bodylen
297 arcs = ifelse(m4_dir_,right,90,m4_dir_,up,180,m4_dir_,left,270,0)
298 arcd(Body.e_, 0.1/2, arcs,arcs+180)
299 np2 = int(pinct/2+0.5)
300 define(`m4bxht',`m4pinlen ifelse(m4type,Q,`*(1+(i%%2))')')dnl
301 for i=0 to np2-1 do {
302 exec sprintf("Pin%g: box ht_ m4bxht wid_ m4pinwid \
303 with .s_ at (i+0.5)/np2 between Body.ne_ and Body.nw_",i+1) }
304 for i=np2+1 to pinct do {
305 exec sprintf("Pin%g: box ht_ m4bxht wid_ m4pinwid \
306 with .n_ at (i-np2-0.5)/(pinct-np2) between Body.sw_ and Body.se_",i) }
307 `$3'; resetdir_
308 popdef(`m4bodywid',`m4bodylen',`m4pinpitch',`m4pinwid',`m4pinlen',`m4direct',
309 `m4type') ]'))
310
311 `There is more than one way to draw an IC and
312 label its pins; here is one:'
313 `LT3724( keys ) IC in a [] block
314 keys: pinsep=expr; (svg_baselineskip*2.5)
315 pincount=expr; (8 per side)
316 hght=expr; ((pincount+1)*pinsep)
317 wdth=expr; (0.6*hght)'
318 box=attributes; (shaded light blue)
319 `8 pins per side; pin labels
320 VIN, SHDN, CSS, BURST_EN, VFB, VC, SYNC, FSET,
321 SGND, SENSEM, SENSEP, PGND, VCC, SW, TG, BOOST'
322 define(`LT3724',`[ pushkeys_(`$1',`pinsep:svg_baselineskip*2.5; pincount:8;
323 hght:(m4`'m4pincount+1)*m4`'pinsep; wdth:0.6*m4`'hght;
324 box:shaded LTtmpcolr:N')dnl
325 define LTtmpcolr {rgbstring(0.9,0.96,1)} # Note: dpic macro
326 Chip: box wid m4wdth ht m4hght m4box "`LT3724'" ; undefine LTtmpcolr
327 foreach_(`m4hx',`ifelse(m4hx,nil,,
328 `patsubst(m4hx,^[^:]*:): Chip.nw-(0,m4Lx*m4hght/(m4pincount+1))
329 "patsubst(m4hx,:.*)" ljust at Chip.nw-(0,m4Lx*m4hght/(m4pincount+1))')',
330 V`'svg_sub(IN):VIN, SHDN, C`'svg_sub(SS):CSS, BURST_EN,
331 V`'svg_sub(FB):VFB, V`'svg_sub(C):VC, SYNC, f`'svg_sub(SET):FSET)
332 line right_ textht*4 from SHDN+(textoffset,textht/2+2bp__)
333 foreach_(`m4hx',`ifelse(m4hx,nil,,
334 `patsubst(m4hx,^[^:]*:): Chip.se+(0,m4Lx*m4hght/(m4pincount+1))
335 "patsubst(m4hx,:.*)" rjust at Chip.se+(0,m4Lx*m4hght/(m4pincount+1))')',
336 SGND, SENSE`'svg_sup(-):SENSEM, SENSE`'svg_sup(+):SENSEP, PGND,
337 V`'svg_sub(CC):VCC, SW, TG, BOOST)
338 `$2' popdef(`m4pinsep',`m4pincount',`m4hght',`m4wdth',`m4box') ]')
339
340
341 `Here is another way to draw an IC and
342 label its pins:'
343
344 `LT3757( keys ) IC in a [] block
345 keys: pinsep=expr; (svg_baselineskip*2.5)
346 pincount=expr; (8 per side)
347 hght=expr; ((pincount+1)*pinsep)
348 wdth=expr; (0.6*hght)'
349 `8 pins per side; pin labels
350 top: VIN; left: SHU, SYNC, RT, SS;
351 right: GATE, SENSE, FBX;
352 bottom: VC, GND, INTVCC'
353 define(`LT3757',`[ pushkeys_(`$1',
354 `pinsep:svg_baselineskip*2.5;
355 pincount:8;
356 hght:(m4`'pincount+1)*m4`'pinsep;
357 wdth:0.6*m4`'hght';)dnl
358 Chip: box wid m4wdth ht m4hght shaded rgbstring(0.9,0.96,1) \
359 "`LT3757'" above
360 VIN: Chip.n; "V`'svg_sub(IN)" at VIN below
361 foreach_(`LL',`m43757label(nw,sw,ljust,patsubst(LL,:,`,'))',
362 SHU:2:"SHDN/UVLO", SYNC:5, RT:7, SS:8)
363 line from SHU+(2bp__,5bp__) right_ 24bp__
364 foreach_(`LL',`m43757label(se,ne,rjust,patsubst(LL,:,`,'))',
365 FBX:1, SENSE:3, GATE:5)
366 foreach_(`LL',`m43757label(sw,se,+(0,textht/3) above,patsubst(LL,:,`,'))',
367 VC:2:"V`'svg_sub(C)", GND:5, INTVCC:8:"INTV`'svg_sub(CC)")
368 `$2' popdef(`m4pinsep',`m4pincount',`m4hght',`m4wdth') ]')
369 define(`m43757label',``$4': `$5'/(m4pincount+1) between Chip.`$1' and Chip.`$2'
370 ifelse(`$6',,"`$4'",`$6') at `$4' `$3'')
371
372 divert(0)dnl