12 (define column-offsets '(8 5 0 6 11 15))
14 (define (switch-module x y rotation label net-pos net-neg)
15 `(module MX_FLIP (layer Front) (tedit 4FD81CDD) (tstamp 543EF801)
18 (fp_text reference ,label (at 0 3.302 ,rotation) (layer F.SilkS)
19 (effects (font (size 1.524 1.778) (thickness 0.254))))
20 (fp_line (start -6.35 -6.35) (end 6.35 -6.35)
21 (layer F.SilkS) (width 0.381))
22 (fp_line (start 6.35 -6.35) (end 6.35 6.35)
23 (layer F.SilkS) (width 0.381))
24 (fp_line (start 6.35 6.35) (end -6.35 6.35)
25 (layer F.SilkS) (width 0.381))
26 (fp_line (start -6.35 6.35) (end -6.35 -6.35)
27 (layer F.SilkS) (width 0.381))
28 (pad 0 np_thru_hole circle (at 0 0) (size 3.9878 3.9878)
29 (drill 3.9878)) ; switch hole, no copper
30 (pad 0 np_thru_hole circle (at -5.08 0) (size 1.7018 1.7018)
31 (drill 1.7018)) ; board-mount hole, no copper
32 (pad 0 np_thru_hole circle (at 5.08 0) (size 1.7018 1.7018)
33 (drill 1.7018)) ; board-mount hole, no copper
34 (pad 1 thru_hole circle (at 2.54 -5.08) (size 2.286 2.286) (drill 1.4986)
35 (layers *.Cu *.SilkS *.Mask) ,net-pos)
36 (pad 1 thru_hole circle (at 3.81 -2.54) (size 2.286 2.286) (drill 1.4986)
37 (layers *.Cu *.SilkS *.Mask) ,net-pos)
38 (pad 2 thru_hole circle (at -2.54 -5.08) (size 2.286 2.286) (drill 1.4986)
39 (layers *.Cu *.SilkS *.Mask) ,net-neg)
40 (pad 2 thru_hole circle (at -3.81 -2.54) (size 2.286 2.286) (drill 1.4986)
41 (layers *.Cu *.SilkS *.Mask) ,net-neg)))
43 (define (diode-module x y rotation label net-pos net-neg)
44 `(module DIODE (layer Front) (tedit 4E0F7A99) (tstamp 543EF854)
45 (at ,x ,y ,(+ 90 rotation))
47 (fp_text reference D2:2 (at 0 0 180) (layer F.SilkS) hide
48 (effects (font (size 1.016 1.016) (thickness 0.2032))))
49 (fp_line (start -1.524 -1.143) (end 1.524 -1.143)
50 (layer F.SilkS) (width 0.2032))
51 (fp_line (start 1.524 -1.143) (end 1.524 1.143)
52 (layer F.SilkS) (width 0.2032))
53 (fp_line (start 0 -1.143) (end 0 1.143)
54 (layer F.SilkS) (width 0.2032))
55 (fp_line (start 0 -1.143) (end -1.524 0)
56 (layer F.SilkS) (width 0.2032))
57 (fp_line (start -1.524 0) (end 0 1.143)
58 (layer F.SilkS) (width 0.2032))
59 (fp_line (start 1.524 1.143) (end -1.524 1.143)
60 (layer F.SilkS) (width 0.2032))
61 (fp_line (start -1.524 1.143) (end -1.524 -1.143)
62 (layer F.SilkS) (width 0.2032))
63 (fp_line (start -3.81 0) (end -1.6637 0) (layer Back) (width 0.6096))
64 (fp_line (start 1.6637 0) (end 3.81 0) (layer Back) (width 0.6096))
65 (fp_line (start -3.81 0) (end -1.6637 0) (layer Front) (width 0.6096))
66 (fp_line (start 1.6637 0) (end 3.81 0) (layer Front) (width 0.6096))
68 (pad 1 thru_hole circle (at -3.81 0 180) (size 1.651 1.651)
69 (drill 0.9906) (layers *.Cu *.SilkS *.Mask) ,net-neg)
70 (pad 2 thru_hole rect (at 3.81 0 ,rotation) (size 1.651 1.651)
71 (drill 0.9906) (layers *.Cu *.SilkS *.Mask) ,net-pos)
72 (pad 99 smd rect (at -1.6637 0 ,rotation) (size 0.8382 0.8382)
73 (layers Front F.Paste F.Mask))
74 (pad 99 smd rect (at -1.6637 0 ,rotation) (size 0.8382 0.8382)
75 (layers Back B.Paste B.Mask))
76 (pad 99 smd rect (at 1.6637 0 ,rotation) (size 0.8382 0.8382)
77 (layers Front F.Paste F.Mask))
78 (pad 99 smd rect (at 1.6637 0 ,rotation) (size 0.8382 0.8382)
79 (layers Back B.Paste B.Mask))))
81 (define microcontroller-module
82 `(module A_STAR (layer Front) (tedit 4FDC31C8) (tstamp 543EF800)
85 (fp_line (start -15.24 7.62) (end 10.1 7.62) (layer F.SilkS) (width 0.381))
88 (pad B5 thru_hole circle (at -13.97 6.35 270) (size 1.7526 1.7526)
89 (drill 1.0922) (layers *.Cu *.SilkS *.Mask) (net 7 N-col-2))
90 (pad B4 thru_hole circle (at -11.43 6.35 270) (size 1.7526 1.7526)
91 (drill 1.0922) (layers *.Cu *.SilkS *.Mask) (net 8 N-col-3))
92 (pad E6 thru_hole circle (at -8.89 6.35 270) (size 1.7526 1.7526)
93 (drill 1.0922) (layers *.Cu *.SilkS *.Mask) (net 9 N-col-4))
94 (pad D7 thru_hole circle (at -6.35 6.35 270) (size 1.7526 1.7526)
95 (drill 1.0922) (layers *.Cu *.SilkS *.Mask) (net 5 N-col-0))
96 (pad C6 thru_hole circle (at -3.81 6.35 270) (size 1.7526 1.7526)
97 (drill 1.0922) (layers *.Cu *.SilkS *.Mask) (net 6 N-col-1))
98 (pad D4 thru_hole circle (at -1.27 6.35 270) (size 1.7526 1.7526)
99 (drill 1.0922) (layers *.Cu *.SilkS *.Mask) (net 10 N-col-5))
102 (pad D0 thru_hole circle (at 1.27 6.35 270) (size 1.7526 1.7526)
103 (drill 1.0922) (layers *.Cu *.SilkS *.Mask) (net 1 N-row-0))
104 (pad D1 thru_hole circle (at 3.81 6.35 270) (size 1.7526 1.7526)
105 (drill 1.0922) (layers *.Cu *.SilkS *.Mask) (net 2 N-row-1))
106 (pad D3 thru_hole circle (at 6.35 6.35 270) (size 1.7526 1.7526)
107 (drill 1.0922) (layers *.Cu *.SilkS *.Mask) (net 3 N-row-2))
108 (pad D2 thru_hole circle (at 8.89 6.35 270) (size 1.7526 1.7526)
109 (drill 1.0922) (layers *.Cu *.SilkS *.Mask) (net 4 N-row-3))))
123 ,@(for/list ([s (in-range 42)])
124 (list 'net (+ 11 s) (string->symbol (format "N-diode-~s" s))))))
126 (define (net-class nets)
127 (append '(net_class Default "This is the default net class."
135 (list 'add_net (last n)))))
137 (define (switch row col)
138 (let* ([x (+ (* (+ 1 col) spacing) x-offset)]
139 [y (+ (list-ref column-offsets col) (* spacing row) y-offset)]
140 [label (format "SW~a:~a" col row)]
141 [diode (+ row (* col 4))]
142 [diode-net `(net ,(+ 11 diode)
143 ,(string->symbol (format "N-diode-~s" diode)))]
144 [column-net `(net ,(+ col 5)
145 ,(string->symbol (format "N-col-~s" col)))])
146 (switch-module x y 0 label diode-net column-net)))
148 (define (diode row col)
149 (let* ([x (if (= col 5)
151 (+ (* (+ 1 col) spacing) x-offset 9))]
152 [y (cond [(and (= col 5) (= row 2)) 81]
153 [(and (= col 5) (= row 3)) 84]
154 [#t (+ (list-ref column-offsets col) (* spacing row) y-offset)])]
155 [r (if (= col 5) 270 0)]
156 [label (format "D~a:~a" col row)]
157 [diode (+ row (* col 4))])
158 (diode-module x y r label
160 ,(string->symbol (format "N-diode-~s" diode)))
162 ,(string->symbol (format "N-row-~s" row))))))
164 (define switches+diodes
165 (for/list ([col (in-range cols)] #:when true
166 [row (if (or (= 5 col) (= 6 col))
167 '(2 3) (in-range rows))])
168 (list (switch row col) (diode row col))))
175 (list (net-class nets))
176 (list microcontroller-module)
179 (define (write-placement filename)
180 (when (file-exists? filename) (delete-file filename))
181 (call-with-output-file filename
183 (display (call-with-input-file "header.rktd"
184 (curry read-string 9999)) op)
185 ;; kicad has this terrible bug where it's whitespace-sensitive here =(
188 (pretty-print f op 1))
190 (display (call-with-input-file "traces.rktd"
191 (curry read-string 999999)) op)
194 (write-placement "atreus.kicad_pcb")