Fully tested step 2: scanning one row.

This commit is contained in:
Phil Hagelberg 2015-01-04 15:06:19 -08:00
parent 5f629927fb
commit 6833dfbf7c

View file

@ -1,44 +1,29 @@
(include "keycodes.scm")
(include "layout.scm")
(define row-pins (list 0 1 2 3))
(define column-pins (list 11 12 18 19 10 4 7 8 9 5 6))
(define columns (list 0 1 2 3 4 5 6 7 8 9))
(define column-pins (vector 11 12 18 19
10 7 8 9 5 6))
(define layout (vector key-a key-s key-d key-f key-g
key-h key-j key-k key-l key-semicolon))
(define (scan-column columns row-layout pressed)
(if (null? columns)
pressed
(scan-column (cdr columns)
(cdr row-layout)
(if (low? (car columns))
(car row-layout)
pressed))))
(for-each output (list 0 1 2 3))
(for-each high (list 0 1 3))
(low 2)
(define (scan-rows rows layout-rows pressed)
(if (null? rows)
pressed
(begin
(for-each high row-pins)
(low (car rows)) ; activate row
(scan-rows (cdr rows) (cdr layout-rows)
(scan-column column-pins (car layout-rows) 0)))))
(for-each-vector input column-pins)
(for-each-vector high column-pins) ; activate pullup resistors
(call-c-func "usb_init")
(pause 200)
(define (scan-column last n)
(if (low? (vector-ref column-pins n))
(vector-ref layout n)
last))
(define (loop)
(let ((pressed (scan-rows row-pins layout 0)))
(let ((pressed (fold scan-column 0 columns)))
(call-c-func "usb_send" 0 pressed 0 0 0 0 0))
(loop))
(define (init)
;; leonardo pins only go up to 13, but a-star goes to 19
(set! arduino-ports (vector #x29 #x29 #x29 #x29 #x29 #x26 #x29 #x2C
#x23 #x23 #x23 #x23 #x29 #x26
#x23 #x23 #x23 #x29 #x2D #x2D))
(set! arduino-pins (vector 4 8 2 1 16 64 128 64 16 32 64 128 64 128
8 2 4 32 65 128))
(for-each output row-pins)
(for-each input column-pins)
(for-each high column-pins) ; activate pullup resistors
(call-c-func "usb_init")
(pause 200))
(init)
(loop)