(version)
"8.3"
(require racket
racket/list
racket/format
(prefix-in pict: pict))
(require bhdl)
#<procedure:parameter-procedure>
(require "BHDL-Key-lib.scm")
(define global
(make-circuit
(pin GND 3V3 5V VCC USB5V)))
;; This is a mini-language defined in BHDL-Key.scm
(define-key-matrix matrix
([(esc 1.5) 1 2 3 4 5 - - 6 7 8 9 0 (backspace 1.5)]
[(tab 1.5) Q W E R T - - Y U I O P (\\ 1.5)]
[(caps 1.5) A S D F G (lmid1 1.5) (rmid1 1.5) H J K L \; (enter 1.5)]
[(lshift 1.5) Z X C V B (lmid2 1.5) (rmid2 1.5) N M \, \. \/ (rshift 1.5)]
[lctrl lfn lsuper lalt lTBD (lspace 2.75) - - (rspace 2.75) rTBD ralt rsuper rfn rctrl]))
"DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-63-15_16388403191638840319607" "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-63-15_16388403191638840319620"
kQ
#<Composite-54291>
(show-layout kQ)
;; FIXME the size is bigger. This might create problems
(show-layout klspace)
(define matrix-module
(make-circuit
(pin row[5] col[14])
(layout (make-fitboard-layout matrix))
(wire (for/list ([x (range 5)])
(filter-not
void?
(for/list ([y (range 14)])
(let ([key (keyboard-xy matrix x y)])
(when key
(series
self.col[y]
key
self.row[x])))))))))
circuit-plot
#<procedure:circuit-plot>
(circuit-plot matrix-module)
DEBUG: (Number of conflicts: 0) generating pdf .. link: /tmp/out.pdf
(parameterize ([current-directory "./out/bhdl-key-matrix-module"])
(circuit-export matrix-module
#:auto-place #f
#:formats '(kicad pdf png)))
generating KiCAD PCB .. "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-95-15_16388403871638840387512" "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-95-15_16388403871638840387515" link: /Users/hebi/git/bhdl.org/notebooks/out/bhdl-key-matrix-module/out.kicad_pcb DEBUG: (Number of conflicts: 0) generating pdf .. link: /Users/hebi/git/bhdl.org/notebooks/out/bhdl-key-matrix-module/out.pdf link: /Users/hebi/git/bhdl.org/notebooks/out/bhdl-key-matrix-module/out.png
(show-layout matrix-module)
;; FIXME I actually should not combine two atoms into one, because
(define (icsp-header)
(make-circuit
(part [h (PinHeader2 3)]
)
(pin MOSI SCK MISO RESET VCC GND)
;; FIXME !!!!!!! should report error
(wire (bus
;; (self (MOSI SCK RESET))
(self (MISO VCC SCK MOSI RESET GND))
(h [1 2 3 4 5 6])))
(layout h)))
(show-layout (icsp-header))
"DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-63-15_16388404281638840428332"
(show-layout (ATmega32U4 #:FP "TQFP-44"))
"DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-63-15_16388404311638840431967"
(footprint->pict (lcsc->fp "C44854"))
"DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-63-15_16388404331638840433419"
(footprint->pict (uuid->fp "74ebea1b3f170a1f74baae3036bac561"))
"DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-63-15_16388404351638840435278"
(define mcu-module
(make-circuit
(part [mcu (ATmega32U4 #:FP "TQFP-44")]
[usb (USB-Micro)]
[icsp (icsp-header)]
[xtal (Crystal-4 '16MHz)])
(pin row[5] col[14])
(layout (vc-append 50 (rotate usb pi) mcu icsp))
(wire (bus (self row [0 4])
(mcu [PB0 PB4 PB5 PB6 PB7]))
(bus (self col [0 13])
(mcu [PD0 PD1 PD2 PD3 PD4 PD5 PD6 PD7 PF0 PF1 PF4 PF5 PF6 PF7]))
(series mcu.PC6 (R '1k) (LED0603 'red) global.GND)
(bus (mcu (MOSI SCLK MISO RESET VCC GND))
(icsp (MOSI SCK MISO RESET VCC GND)))
(list (*- mcu.VCC mcu.UVCC mcu.AVCC global.VCC)
(*- mcu.GND mcu.UGND global.GND)
;; reset circuit and switch
(*- mcu.RESET (*< (LL4148)
(R '10k)) global.5V)
;; FIXME [-1] because (Switch) is parsed as the index otherwise
(*- mcu.RESET[-1] (Switch) global.GND)
;; capacitors
(*- mcu.UCAP (C '1uf) global.GND)
(*- global.VCC (*< (C '1uf)
(C '100nf)
(C '100nf)
(C '100nf)
(C '100nf))
global.GND)
;; crystal
;; FIXME Crystal-2 has no 16MHz
(*- mcu.XTAL1 xtal.XIN)
(*- xtal.XOUT mcu.XTAL2)
(*- xtal.GND global.GND)
(*- mcu.XTAL1 (C '22pf) global.GND)
(*- mcu.XTAL2 (C '22pf) global.GND)
;; USB
(*- mcu.D+ (R 22) usb.D+)
(*- mcu.D- (R 22) usb.D-)
;; just use USB for supplying power
(*- mcu.VBUS usb.VBUS global.VCC)
(*- mcu.UGND usb.GND global.GND)))))
(show-layout mcu-module)
;; connect MCU with matrix
(define keyboard
(make-circuit
(layout (ct-superimpose matrix-module mcu-module))
(wire (list matrix-module mcu-module
(bus (matrix-module row[0 4])
(mcu-module row[0 4]))
(bus (matrix-module col[0 13])
(mcu-module col[0 13]))
))))
(show-layout keyboard)
(parameterize ([current-directory "./out/unplaced"])
(circuit-export fitboard
#:auto-place #f
#:formats '(kicad pdf)))
generating KiCAD PCB .. "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-95-15_16388407291638840729516" "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-95-15_16388407291638840729528" "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-95-15_16388407291638840729532" "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-95-15_16388407291638840729536" "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-95-15_16388407291638840729538" "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-95-15_16388407291638840729541" "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-95-15_16388407291638840729544" "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-95-15_16388407291638840729546" "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-95-15_16388407291638840729549" link: /Users/hebi/git/bhdl.org/notebooks/out/unplaced/out.kicad_pcb DEBUG: (Number of conflicts: 0) generating pdf .. link: /Users/hebi/git/bhdl.org/notebooks/out/unplaced/out.pdf
(placer-url "http://localhost:8082")
(parameterize ([current-directory "./out-placed"])
(circuit-export fitboard
#:auto-place #t
#:formats '(kicad pdf dsn)))
DEBUG: (sending for placement ..) DEBUG: (saving ..) generating KiCAD PCB .. link: /Users/hebi/git/bhdl.org/notebooks/out-placed/out.kicad_pcb DEBUG: (Number of conflicts: 0) generating pdf .. link: /Users/hebi/git/bhdl.org/notebooks/out-placed/out.pdf generating Spectre DSN .. link: /Users/hebi/git/bhdl.org/notebooks/out-placed/out.dsn
(parameterize ([current-directory "./out/placed-5"]
;; add more padding
;; WARNING: this might be slow
[padding-general 5])
(circuit-export fitboard
#:auto-place #t
#:formats '(kicad pdf dsn)))
DEBUG: (sending for placement ..) DEBUG: (saving ..) generating KiCAD PCB .. link: /Users/hebi/git/bhdl.org/notebooks/out/placed-5/out.kicad_pcb DEBUG: (Number of conflicts: 0) generating pdf .. link: /Users/hebi/git/bhdl.org/notebooks/out/placed-5/out.pdf generating Spectre DSN .. link: /Users/hebi/git/bhdl.org/notebooks/out/placed-5/out.dsn
Separate boards using Link!
This is fantastic. I want even further:
Now probably something easier:
I can have more benefit doing this:
;; actually I want to define the connector module
(define the-link
(make-circuit
(pin row[5] col[14])
(layout (hb-append 50
col-left
(rotate row1 (/ pi 2))
(rotate row2 (/ pi 2))
col-right))
(part [row1 (PinHeader 5)]
[row2 (PinHeader 5)]
[col-left (PinHeader 7)]
[col-right (PinHeader 7)])
(wire (list (*= (self row[0 4])
(row1 [1 2 3 4 5])
(row2 [1 2 3 4 5]))
(*= (self col [0 6])
(col-left [1 2 3 4 5 6 7]))
(*= (self col [7 13])
(col-right [1 2 3 4 5 6 7]))))))
"DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-63-15_16388411901638841190811" "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-63-15_16388411901638841190815"
(show-layout the-link)
;; connect MCU
(define mcu-board
(make-circuit
(layout (cb-superimpose mcu-module the-link))
(wire (list (*= (the-link row [0 4])
(mcu-module row [0 4]))
(*= (the-link col [0 13])
(mcu-module col [0 13]))))))
(show-layout mcu-board)
(parameterize ([current-directory "./out/mcu-board"]
[padding-general 2])
(circuit-export mcu-board
#:auto-place #t
#:formats '(kicad pdf bom)))
DEBUG: (sending for placement ..) DEBUG: (saving ..) generating KiCAD PCB .. "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-95-15_16388412431638841243613" "DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-95-15_16388412431638841243617" link: /Users/hebi/git/bhdl.org/notebooks/out/mcu-board/out.kicad_pcb Generating BOM .. DEBUG: (Number of conflicts: 0) generating pdf .. link: /Users/hebi/git/bhdl.org/notebooks/out/mcu-board/out.pdf
(mounting-hole 3)
"DEBUG: /var/folders/jd/pqbc6_7j0y5gc2kjxjntw8c40000gn/T/PKGS-src-ROOT-BHDL-syst----iVc-fpio-main.rkt-63-15_16388412451638841245792"
#<ICAtom:MountingHole-64941>
;; The matrix
(define matrix-board
(make-circuit
(layout (ct-superimpose matrix-module the-link))
(wire (list (*= (matrix-module row [0 4])
(the-link row [0 4]))
(*= (matrix-module col [0 13])
(the-link col [0 13]))))))
(show-layout matrix-board)
(parameterize ([current-directory "./out/matrix-board"]
[padding-general 2])
(circuit-export matrix-board
#:auto-place #f
#:formats '(kicad pdf dsn)))
generating KiCAD PCB .. link: /Users/hebi/git/bhdl.org/notebooks/out/matrix-board/out.kicad_pcb DEBUG: (Number of conflicts: 0) generating pdf .. link: /Users/hebi/git/bhdl.org/notebooks/out/matrix-board/out.pdf generating Spectre DSN .. link: /Users/hebi/git/bhdl.org/notebooks/out/matrix-board/out.dsn