Step 3: all the keys (except modifiers)

This commit is contained in:
Phil Hagelberg 2015-01-04 21:18:15 -08:00
parent 6833dfbf7c
commit 21d0b631c2
2 changed files with 24 additions and 21 deletions

View file

@ -1,9 +1,9 @@
(define layout (define layout
(list (list key-q key-w key-e key-r key-t 0 (vector key-q key-w key-e key-r key-t 0
key-y key-u key-i key-o key-p) key-y key-u key-i key-o key-p
(list key-a key-s key-d key-f key-g 0 key-a key-s key-d key-f key-g 0
key-h key-j key-k key-l key-semicolon) key-h key-j key-k key-l key-semicolon
(list key-z key-x key-c key-v key-b mod-alt key-z key-x key-c key-v key-b mod-alt
key-n key-m key-comma key-period key-slash) key-n key-m key-comma key-period key-slash
(list key-esc key-tab mod-gui mod-shift key-backspace mod-ctrl key-esc key-tab mod-gui mod-shift key-backspace mod-ctrl
key-space mod-fn key-dash key-quote key-enter))) key-space mod-fn key-dash key-quote key-enter))

View file

@ -1,28 +1,31 @@
(include "keycodes.scm") (include "keycodes.scm")
(include "layout.scm")
(define columns (list 0 1 2 3 4 5 6 7 8 9)) (define rows (list 0 1 2 3))
(define column-pins (vector 11 12 18 19 (define row-pins (vector 3 2 1 0))
10 7 8 9 5 6)) (define columns (list 0 1 2 3 4 5 6 7 8 9 10))
(define layout (vector key-a key-s key-d key-f key-g (define column-pins (vector 11 12 18 19 10 4 7 8 9 5 6))
key-h key-j key-k key-l key-semicolon))
(for-each output (list 0 1 2 3))
(for-each high (list 0 1 3))
(low 2)
(for-each-vector output row-pins)
(for-each-vector high row-pins)
(for-each-vector input column-pins) (for-each-vector input column-pins)
(for-each-vector high column-pins) ; activate pullup resistors (for-each-vector high column-pins) ; activate pullup resistors
(call-c-func "usb_init") (call-c-func "usb_init")
(pause 200) (pause 200)
(define (scan-column last n) (define (scan-column last offset)
(if (low? (vector-ref column-pins n)) (if (low? (vector-ref column-pins (mod offset 11)))
(vector-ref layout n) (vector-ref layout offset)
last)) last))
(define (scan-row last row)
(for-each-vector high row-pins)
(low (vector-ref row-pins row))
(fold scan-column last (map (lambda (col) (+ col (* row 11))) columns)))
(define (loop) (define (loop)
(let ((pressed (fold scan-column 0 columns))) (let ((pressed (free! (fold scan-row 0 rows))))
(call-c-func "usb_send" 0 pressed 0 0 0 0 0)) (call-c-func "usb_send" 0 pressed 0 0 0 0 0))
(loop)) (loop))