~technomancy/menelaus

menelaus/multidvorak.scm -rw-r--r-- 5.3 KiB
71e98173Phil Hagelberg Fix reset function. 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
;;; This is the multidvorak layout.

;; It is written with the assumption that the host OS is set to dvorak mode, so
;; it sends keycodes with the assumption that the OS will apply the dvorak
;; mapping; for instance it sends [ as -, which the OS then turns back into [.
;; There is also a "hard dvorak" layer you can activate when you plug into
;; a computer that isn't set to dvorak in the OS.

;; It will work for the 44-key Keyboardio Atreus or the 42-key Atreus Classic.

(include "keycodes.scm")

;; What are the rows and columns we care about? (Atreus Classic pinout)
(define rows (list 0 1 2 3))
(define columns (list 0 1 2 3 4 5 6 7 8 9 10))

;; 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 3 2 1 0))
(define column-pins (vector 6 5 9 8 7 4 10 19 18 12 11))

;; 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)
(define momentary-layer #f)

(define (fn on?) (set! momentary-layer (and on? (vector-ref layers 1))))

(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

;; NB: the middle keys (ctrl and alt on the 42-key, also ~ and \ on the 44-key
;; variant) are physically in two separate columns, but electrically they are
;; both wired in to the same middle column.

;;; physical location:

;;   ~    \
;; ctrl  alt

;;; electrical arrangement:

;;   ~
;;   \
;;  ctrl
;;  alt

;; This is why it looks like the top two rows should have 10 columns and the
;; bottom should have 12; in reality there are electrically 11 columns.

(define base-layer
  (vector key-q key-w key-e key-r key-t key-backtick
          key-y key-u key-i key-o key-p

          key-a key-s key-d key-f key-g key-backslash
          key-h key-j key-k key-l key-semicolon

          key-z key-x key-c key-v key-b mod-ctrl
          key-n key-m key-comma key-period key-slash

          key-esc key-tab mod-super mod-shift key-backspace mod-alt
          ;; fn takes us to fn-layer below while it is held down
          key-space fn key-quote key-left-bracket key-enter))

(define fn-layer
  (vector (sft key-1) (sft key-2) key-up (sft key-4) backtick-or-percent
          (sft key-6) key-page-up key-7 key-8 key-9 key-backspace

          (sft key-9) key-left key-down key-right (sft key-0) (sft key-7)
          key-page-down key-4 key-5 key-6 key-backslash

          key-dash key-equal (sft key-3) (sft key-dash) (sft key-equal) mod-ctrl
          (sft key-8) key-1 key-2 key-3 (sft key-right-bracket)

          ;; 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-alt
          key-space fn key-e key-0 key-right-bracket))

(define l2-layer
  (vector key-insert key-home key-up key-end key-page-up 0
          key-up key-f7 key-f8 key-f9 key-f10

          key-delete key-left key-down key-right key-page-down 0
          key-down key-f4 key-f5 key-f6 key-f11

          ;; the B key enters the bootloader
          0 key-vol-up 0 0 reset mod-ctrl
          ;; the N key switches to hardware dvorak mode
          (set-layer 4) key-f1 key-f2 key-f3 key-f12

          0 key-vol-down mod-super mod-shift key-backspace mod-alt
          ;; tapping the fn key brings us back to the base layer
          key-space (set-layer 0) key-printscreen key-scroll-lock key-pause))

(define hard-dvorak-layer
  (vector key-quote key-comma key-period key-p key-y key-backslash
          key-f key-g key-c key-r key-l

          key-a key-o key-e key-u key-i key-backtick
          key-d key-h key-t key-n key-s

          key-semicolon key-q key-j key-k key-x mod-ctrl
          key-b key-m key-w key-v key-z

          key-esc key-tab mod-super mod-shift key-backspace mod-alt
          key-space fn key-quote key-left-bracket key-enter))

(define hard-dvorak-fn-layer
  (vector (sft key-1) (sft key-2) key-up (sft key-4) backtick-or-percent (sft key-6)
          key-page-up key-7 key-8 key-9 (sft key-backspace)

          (sft key-3) key-left key-down key-right (sft key-4) 0
          key-page-down key-4 key-5 key-6 (sft key-equal)

          key-left-bracket key-right-bracket (sft key-9) (sft key-0) (sft key-7)
          mod-ctrl key-backtick key-1 key-2 key-3 key-backslash

          (set-layer 2) key-insert mod-super mod-shift key-backspace mod-alt
          key-space fn key-e key-0 key-right-bracket))

(set! layers (vector base-layer fn-layer l2-layer
                     hard-dvorak-layer hard-dvorak-fn-layer))
(set! current-layer (vector-ref layers 0))

(include "menelaus.scm")