Compare commits

...

4 commits

Author SHA1 Message Date
Cat /dev/Nulo 34de0948da Sticky AltGr 2021-12-13 17:14:03 -03:00
Cat /dev/Nulo 57cdf605f5 Sticky keys 2021-12-13 17:13:56 -03:00
Cat /dev/Nulo 09b85c2c2e Agregar altgr a los tests 2021-12-13 16:41:55 -03:00
Cat /dev/Nulo 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
; Actually ErrorUndefined
(define sticky-modifier 3)
(define key-a 4)
(define key-b 5)
(define key-c 6)
@ -56,8 +59,8 @@
(define key-quote 52)
(define key-backslash 49)
(define key-backtick 53)
(define key-left-bracket 47)
(define key-right-bracket 48)
(define key-left-bracket 47) (define key-lbrack 47)
(define key-right-bracket 48) (define key-rbrack 48)
(define key-period 55) (define key-. 55)
(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.
(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))
;; For each element of the keycodes-down or modifiers vector, which physical
@ -263,6 +264,11 @@
(vector-set! modifiers (- keycode 1) 1)
(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.
(define (press-normal-key keycode key)
(let ((slot (find keycodes-down 0)))
@ -271,17 +277,25 @@
;; Record a key press in the modifiers/keycodes-down vectors for the layout.
(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
;; true when the key is pressed and false when it's released.
(if (procedure? keycode)
(keycode #t)
(if (modifier? keycode)
(begin (press-modifier (unmodify keycode) key)
(if (uncombo keycode)
(press-normal-key (uncombo keycode) key)
#f))
(press-normal-key keycode key)))))
(if (uncombo keycode)
(if (= (uncombo keycode) sticky-modifier)
(press-sticky-modifier (unmodify keycode))
(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.
(define (release-modifier keycode key n)

View file

@ -1,30 +1,13 @@
;;; this is the qwerty layout
(include "keycodes.scm")
;; What are the rows and columns we care about?
(define rows (list 0 1 2 3))
(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 MATRIX_ROW_PINS { C6, B5, B2, B6 }
(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 }
;; 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
(define layers #f)
(define current-layer #f)
@ -35,56 +18,47 @@
(define (set-layer 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
(define noop 0)
(define base-layer
(vector key-q key-w key-e key-r key-t noop noop key-y key-u key-i key-o key-p
(vector key-q key-w key-e key-r key-t noop noop key-y key-u key-i key-o key-p
key-a key-s key-d key-f key-g noop noop key-h key-j key-k key-l key-semicolon
key-a key-s key-d key-f key-g noop noop key-h key-j key-k key-l key-semicolon
key-z key-x key-c key-v key-b key-backtick key-backslash key-n key-m key-comma key-period key-slash
key-esc key-tab mod-super mod-shift key-backspace mod-ctrl
mod-alt key-space fn key-dash key-quote key-enter))
key-esc key-tab mod-super mod-shift key-backspace mod-ctrl
mod-alt key-space fn key-dash key-quote key-enter))
(define fn-layer
(vector (sft key-1) (sft key-2) key-up (sft key-4) backtick-or-percent noop
noop key-page-up key-7 key-8 key-9 key-backspace
(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
(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)
(sft key-9) key-left key-down key-right (sft key-0) noop
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)
(sft key-right-bracket) (sft key-6)
(sft key-7) (sft key-8) key-1 key-2 key-3 (sft key-equal)
key-lbrack key-rbrack (sft key-3) (sft key-lbrack) (sft key-rbrack) (sft key-6)
(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) key-insert mod-super mod-shift key-backspace mod-ctrl
mod-alt key-space fn key-period key-0 key-equal))
(set-layer 2) key-insert mod-super mod-shift key-backspace mod-ctrl
mod-alt key-space fn key-period key-0 key-equal))
(define l2-layer
(vector key-insert key-home key-up key-end key-page-up noop
noop key-up key-f7 key-f8 key-f9 key-f10
noop key-up key-f7 key-f8 key-f9 key-f10
key-delete key-left key-down key-right key-page-down noop
noop key-down key-f4 key-f5 key-f6 key-f11
noop key-down key-f4 key-f5 key-f6 key-f11
;; the B key enters the bootloader
noop key-vol-up noop noop reset noop
noop noop key-f1 key-f2 key-f3 key-f12
noop key-vol-up noop noop reset noop
noop noop key-f1 key-f2 key-f3 key-f12
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))
noop key-vol-down mod-super mod-shift key-backspace mod-ctrl
mod-alt key-space (set-layer 0) key-printscreen key-scroll-lock key-pause))
(set! layers (vector base-layer fn-layer l2-layer))
(set! current-layer (vector-ref layers 0))

View file

@ -22,7 +22,8 @@
(filter symbol? (list (if (positive? (bitwise-and mods 1)) 'ctrl 0)
(if (positive? (bitwise-and mods 2)) 'shift 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)
(set! last-usb-frame (cons (mods-list mods) args)))