Compare commits

...

4 commits

Author SHA1 Message Date
34de0948da Sticky AltGr 2021-12-13 17:14:03 -03:00
57cdf605f5 Sticky keys 2021-12-13 17:13:56 -03:00
09b85c2c2e Agregar altgr a los tests 2021-12-13 16:41:55 -03:00
6fc5ebf7a3 Indentar layout mejor 2021-12-13 16:41:41 -03:00
4 changed files with 45 additions and 53 deletions

View file

@ -1,5 +1,8 @@
;; port of usb_keyboard.h ;; port of usb_keyboard.h
; Actually ErrorUndefined
(define sticky-modifier 3)
(define key-a 4) (define key-a 4)
(define key-b 5) (define key-b 5)
(define key-c 6) (define key-c 6)
@ -56,8 +59,8 @@
(define key-quote 52) (define key-quote 52)
(define key-backslash 49) (define key-backslash 49)
(define key-backtick 53) (define key-backtick 53)
(define key-left-bracket 47) (define key-left-bracket 47) (define key-lbrack 47)
(define key-right-bracket 48) (define key-right-bracket 48) (define key-rbrack 48)
(define key-period 55) (define key-. 55) (define key-period 55) (define key-. 55)
(define key-slash 56) (define key-/ 56) (define key-slash 56) (define key-/ 56)

View file

@ -246,6 +246,7 @@
;; Vectors to store keycodes for the USB frame we are preparing to send. ;; Vectors to store keycodes for the USB frame we are preparing to send.
(define modifiers (vector 0 0 0 0 0)) (define modifiers (vector 0 0 0 0 0))
(define sticky-modifiers (vector 0 0 0 0 0))
(define keycodes-down (vector 0 0 0 0 0 0)) (define keycodes-down (vector 0 0 0 0 0 0))
;; For each element of the keycodes-down or modifiers vector, which physical ;; For each element of the keycodes-down or modifiers vector, which physical
@ -263,6 +264,11 @@
(vector-set! modifiers (- keycode 1) 1) (vector-set! modifiers (- keycode 1) 1)
(vector-set! keys-for-modifiers (- keycode 1) key)) (vector-set! keys-for-modifiers (- keycode 1) key))
(define (press-sticky-modifier keycode)
(vector-set! sticky-modifiers (- keycode 1) 1))
(define (release-sticky-modifier keycode)
(vector-set! sticky-modifiers (- keycode 1) 0))
;; Record that a given key resulted in a specific non-modifier press. ;; Record that a given key resulted in a specific non-modifier press.
(define (press-normal-key keycode key) (define (press-normal-key keycode key)
(let ((slot (find keycodes-down 0))) (let ((slot (find keycodes-down 0)))
@ -271,17 +277,25 @@
;; Record a key press in the modifiers/keycodes-down vectors for the layout. ;; Record a key press in the modifiers/keycodes-down vectors for the layout.
(define (press-key key) (define (press-key key)
(let ((keycode (lookup key))) (let ((keycode (lookup key))
(sticky (find sticky-modifiers 1)))
;; Sometimes "keycodes" are procedures; in that case we call them with ;; Sometimes "keycodes" are procedures; in that case we call them with
;; true when the key is pressed and false when it's released. ;; true when the key is pressed and false when it's released.
(if (procedure? keycode) (if (procedure? keycode)
(keycode #t) (keycode #t)
(if (modifier? keycode) (if (modifier? keycode)
(begin (press-modifier (unmodify keycode) key)
(if (uncombo keycode) (if (uncombo keycode)
(press-normal-key (uncombo keycode) key) (if (= (uncombo keycode) sticky-modifier)
#f)) (press-sticky-modifier (unmodify keycode))
(press-normal-key keycode key))))) (begin
(press-modifier (unmodify keycode) key)
(press-normal-key (uncombo keycode) key)))
(press-modifier (unmodify keycode) key))
(if sticky
(begin (press-modifier (+ sticky 1) key)
(press-normal-key keycode key)
(release-sticky-modifier (+ sticky 1)))
(press-normal-key keycode key))))))
;; Record that a given key being released resulted in a modifier release. ;; Record that a given key being released resulted in a modifier release.
(define (release-modifier keycode key n) (define (release-modifier keycode key n)

View file

@ -1,30 +1,13 @@
;;; this is the qwerty layout
(include "keycodes.scm") (include "keycodes.scm")
;; What are the rows and columns we care about?
(define rows (list 0 1 2 3)) (define rows (list 0 1 2 3))
(define columns (list 0 1 2 3 4 5 6 7 8 9 10 11)) (define columns (list 0 1 2 3 4 5 6 7 8 9 10 11))
;; Which GPIO pins are responsible for each row or column?
;; These are the pins used by the kit-based Atreus; the Keyboardio Atreus uses
;; a different set of pins.
(define row-pins (vector 5 9 16 10)) (define row-pins (vector 5 9 16 10))
; +#define MATRIX_ROW_PINS { C6, B5, B2, B6 } ; +#define MATRIX_ROW_PINS { C6, B5, B2, B6 }
(define column-pins (vector 21 19 20 18 15 7 6 4 3 2 0 1)) (define column-pins (vector 21 19 20 18 15 7 6 4 3 2 0 1))
; +#define MATRIX_COL_PINS { F4, F6, F5, F7, B1, E6, D7, D4, D0, D1, D2, D3 } ; +#define MATRIX_COL_PINS { F4, F6, F5, F7, B1, E6, D7, D4, D0, D1, D2, D3 }
;; If you have a kit where the PCB is installed upside-down, uncomment this:
;; (set! column-pins (vector 11 12 18 19 10 4 7 8 9 5 6))
;; ;; Upside-down PCB makes the columns backwards but also trades ctrl and alt;
;; ;; this hack only works for layouts where ctrl and alt are in standard place.
;; (set! mod-alt (modify 1))
;; (set! mod-ctrl (modify 3))
;; The above should be handled by a compile-time environment variable but that
;; isn't yet part of Microscheme:
;; https://github.com/ryansuchocki/microscheme/issues/32
;; we have to declare this up front and set it later because of circularity ;; we have to declare this up front and set it later because of circularity
(define layers #f) (define layers #f)
(define current-layer #f) (define current-layer #f)
@ -35,13 +18,6 @@
(define (set-layer n) (define (set-layer n)
(lambda (_) (set! current-layer (vector-ref layers n)))) (lambda (_) (set! current-layer (vector-ref layers n))))
;; On the Atreus Classic, we need to expose backtick on the fn layer, but on
;; the Keyboardio Atreus it has its own key, so we put percent there instead.
(define backtick-or-percent
(sft key-5)
;;key-backtick
)
;;;; layers ;;;; layers
(define noop 0) (define noop 0)
@ -57,14 +33,13 @@
mod-alt key-space fn key-dash key-quote key-enter)) mod-alt key-space fn key-dash key-quote key-enter))
(define fn-layer (define fn-layer
(vector (sft key-1) (sft key-2) key-up (sft key-4) backtick-or-percent noop (vector (sft key-1) (sft key-2) key-up (sft key-4) (sft key-5) noop
noop key-page-up key-7 key-8 key-9 key-backspace noop key-page-up key-7 key-8 key-9 key-backspace
(sft key-9) key-left key-down key-right (sft key-0) noop (sft key-9) key-left key-down key-right (sft key-0) noop
noop key-page-down key-4 key-5 key-6 (altgr key-quote) noop key-page-down key-4 key-5 key-6 (altgr sticky-modifier)
key-left-bracket key-right-bracket (sft key-3) (sft key-left-bracket) key-lbrack key-rbrack (sft key-3) (sft key-lbrack) (sft key-rbrack) (sft key-6)
(sft key-right-bracket) (sft key-6)
(sft key-7) (sft key-8) key-1 key-2 key-3 (sft key-equal) (sft key-7) (sft key-8) key-1 key-2 key-3 (sft key-equal)
;; set-layer 2 takes us to l2-layer below; doesn't need to be held ;; set-layer 2 takes us to l2-layer below; doesn't need to be held
@ -83,7 +58,6 @@
noop noop key-f1 key-f2 key-f3 key-f12 noop noop key-f1 key-f2 key-f3 key-f12
noop key-vol-down mod-super mod-shift key-backspace mod-ctrl noop key-vol-down mod-super mod-shift key-backspace mod-ctrl
;; tapping the fn key brings us back to the base layer
mod-alt key-space (set-layer 0) key-printscreen key-scroll-lock key-pause)) mod-alt key-space (set-layer 0) key-printscreen key-scroll-lock key-pause))
(set! layers (vector base-layer fn-layer l2-layer)) (set! layers (vector base-layer fn-layer l2-layer))

View file

@ -22,7 +22,8 @@
(filter symbol? (list (if (positive? (bitwise-and mods 1)) 'ctrl 0) (filter symbol? (list (if (positive? (bitwise-and mods 1)) 'ctrl 0)
(if (positive? (bitwise-and mods 2)) 'shift 0) (if (positive? (bitwise-and mods 2)) 'shift 0)
(if (positive? (bitwise-and mods 4)) 'alt 0) (if (positive? (bitwise-and mods 4)) 'alt 0)
(if (positive? (bitwise-and mods 8)) 'super 0)))) (if (positive? (bitwise-and mods 8)) 'super 0)
(if (positive? (bitwise-and mods 64)) altgr 0))))
(define (usb-save mods . args) (define (usb-save mods . args)
(set! last-usb-frame (cons (mods-list mods) args))) (set! last-usb-frame (cons (mods-list mods) args)))