summaryrefslogtreecommitdiff
path: root/epistemia/packages/firmware.scm
blob: 6fa49b5699858c36cc0ea527147e8c5739529c2b (plain)
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
146
(define-module (epistemia packages firmware)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix build-system gnu)
  #:use-module (guix git-download)
  #:use-module (guix gexp)
  #:use-module (guix import egg)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (gnu packages embedded)
  #:use-module (gnu packages firmware)
  #:use-module (ice-9 regex))

;; originally from guix upstream, but it's old and only for avr
(define* (make-qmk-firmware-rp2040 keyboard keymap
                            #:key (description "")
                            keymap-json
                            keymap-source-directory
                            keyboard-source-directory)
  "Return a package to build the QMK firmware for KEYBOARD with KEYMAP.
Keyboard should be the name of a sub-directory under the @file{keyboards} directory.
For custom keymaps, KEYMAP-JSON, a file-like object of a JSON representation of
KEYMAP as generated by the @url{https://config.qmk.fm/, QMK Configurator} tool or
KEYMAP-SOURCE-DIRECTORY, a file-like object directory containing the keymap source
files files such as @file{keymap.c}, can be provided.  For keyboards not available in
upstream repository, provide a file-like object directory containing the whole
keyboard definition in KEYBOARD-SOURCE-DIRECTORY."
  (package
    (name (string-append "qmk-firmware-"
                         (regexp-substitute/global #f "[_/]" keyboard
                                                   'pre "-" 'post)
                         "-"
                         (string-replace-substring keymap "_" "-")))
    (version "0.31.9")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/qmk/qmk_firmware")
                    (commit version)))
              (file-name (git-file-name "qmk-firmware" version))
              (sha256
               (base32
                "1vc0lp4k6816mgb8l73jmj6kv3b8ij23i9ia9y9s4f72h8z9j91c"))))
    (build-system gnu-build-system)
    (arguments
     (list
      #:modules '((guix build gnu-build-system)
                  (guix build utils)
                  (ice-9 ftw)
                  (ice-9 match)
                  (srfi srfi-26))
      #:target "arm-none-eabi"
      ;; XXX: Running a test target like "test:$keyboard" doesn't seem to run
      ;; anything and causes the .hex file to be regenerated; leave the tests
      ;; out for now.
      #:tests? #f
      #:make-flags
      #~(list #$(format #f "~a:~a" keyboard keymap)
              (string-append "SHELL=" (search-input-file
                                       %build-inputs "bin/sh"))
	      "CONVERT_TO=rp2040_ce")
      #:phases
      #~(modify-phases %standard-phases
          (replace 'configure
            (lambda _
              ;; Do not attempt to retrieve information from git during the
              ;; build.
              (setenv "SKIP_GIT" "1")))
	  (add-after 'unpack 'copy-chibios-source
            (lambda _
              (copy-recursively
               #$(let ((commit "8bd61b804303f1614d574546c2dd735eeabb09f5"))
                   (origin
		     (method git-fetch)
                     (uri (git-reference
                           (url "https://github.com/qmk/chibios")
                           (commit commit)))
                     (file-name (git-file-name "chibios" commit))
                     (sha256
                      (base32
                       "1waixxdgr48385k1dkf6zpvngdpp78kagkvdpag9y9pg610gqzd2"))))
               "lib/chibios")))
          #$@(if keyboard-source-directory
                 #~((add-after 'unpack 'copy-keyboard-source-directory
                      (lambda _
                        (let ((keyboard-dir #$(string-append "keyboards/" keyboard)))
                          (false-if-exception (delete-file-recursively
                                               keyboard-dir))
                          (copy-recursively #$keyboard-source-directory
                                            keyboard-dir)))))
                 #~())
          #$@(if keymap-source-directory
                 #~((add-after 'unpack 'copy-keymap-source-directory
                      (lambda _
                        (let ((keymap-dir #$(string-append "keyboards/" keyboard
                                                           "/keymaps/" keymap)))
                          (false-if-exception (delete-file-recursively
                                               keymap-dir))
                          (copy-recursively #$keymap-source-directory
                                            keymap-dir)))))
                 #~())
          #$@(if keymap-json
                 #~((replace 'build
                      (lambda _
                        (invoke "qmk" "compile" #$keymap-json))))
                 #~())
          (replace 'install
            (lambda _
              (match (scandir "." (lambda (f)
                                    (false-if-exception
                                     (member (string-take-right f 4)
                                             '(".bin" ".hex" ".uf2")))))
                (()
                 (error "no built binary file found"))
                ((hex ..1)
                 (for-each (cut install-file <> #$output) hex))))))))
    ;; Some of the build tools are required to be on the PATH, as the make
    ;; files do not always operate through 'qmk'; all of qmk's inputs must
    ;; thus be made available.
    (native-inputs (modify-inputs (package-inputs qmk)
                     (append qmk
			     (make-newlib-nano-arm-none-eabi))))
    (home-page "https://qmk.fm/")
    (synopsis "Keyboard firmware for Atmel AVR and Arm USB families")
    (description
     (format #f "QMK (Quantum Mechanical Keyboard Firmware) is a keyboard
firmware based on the @url{https://github.com/tmk/tmk_keyboard, tmk_keyboard
firmware} with some useful features for Atmel AVR and ARM controllers, and
more specifically, the @url{https://olkb.com/, OLKB product line}, the
@url{https://ergodox-ez.com/, ErgoDox EZ keyboard}, and the
@url{https://clueboard.co/, Clueboard product line}.~@[~%~%~a~]" description))
    (license license:gpl2+)))

(define-public qmk-crkbd
  (make-qmk-firmware "crkbd" "default" #:description
		     "The default keymap for the Corne keyboard, a split keyboard with 3x6 vertically
staggered keys and 3 thumb keys."))

(define-public qmk-ferris-sweep
  (make-qmk-firmware-rp2040 "ferris/sweep" "default" #:description
		     "The default keymap for the Ferris Sweep keyboard, a version of the
Ferris 3x5+2 split keyboard with a daughterboard for MCU."))

(define-public qmk-ploopy-adept
  (make-qmk-firmware-rp2040 "ploopyco/madromys" "default" #:description
		     "The default keymap for the Ploopy Adept open-hardware programmable
trackball mouse."))