(version) (require racket racket/list racket/format (prefix-in pict: pict)) (require bhdl) (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])) kQ (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 (circuit-plot matrix-module) (parameterize ([current-directory "./out/bhdl-key-matrix-module"]) (circuit-export matrix-module #:auto-place #f #:formats '(kicad pdf 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)) (show-layout (ATmega32U4 #:FP "TQFP-44")) (footprint->pict (lcsc->fp "C44854")) (footprint->pict (uuid->fp "74ebea1b3f170a1f74baae3036bac561")) (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))) (placer-url "http://localhost:8082") (parameterize ([current-directory "./out-placed"]) (circuit-export fitboard #:auto-place #t #:formats '(kicad pdf 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))) ;; 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])))))) (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))) (mounting-hole 3) ;; 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)))