firmware.scm (6822B)
1 (define-module (epistemia packages firmware) 2 #:use-module ((guix licenses) #:prefix license:) 3 #:use-module (guix build-system gnu) 4 #:use-module (guix git-download) 5 #:use-module (guix gexp) 6 #:use-module (guix import egg) 7 #:use-module (guix packages) 8 #:use-module (guix utils) 9 #:use-module (gnu packages embedded) 10 #:use-module (gnu packages firmware) 11 #:use-module (ice-9 format) 12 #:use-module (ice-9 regex)) 13 14 ;; originally from guix upstream, but it's old and only for avr 15 (define* (make-qmk-firmware-rp2040 keyboard keymap 16 #:key (description "") 17 keymap-json 18 keymap-source-directory 19 keyboard-source-directory) 20 "Return a package to build the QMK firmware for KEYBOARD with KEYMAP. 21 Keyboard should be the name of a sub-directory under the @file{keyboards} directory. 22 For custom keymaps, KEYMAP-JSON, a file-like object of a JSON representation of 23 KEYMAP as generated by the @url{https://config.qmk.fm/, QMK Configurator} tool or 24 KEYMAP-SOURCE-DIRECTORY, a file-like object directory containing the keymap source 25 files files such as @file{keymap.c}, can be provided. For keyboards not available in 26 upstream repository, provide a file-like object directory containing the whole 27 keyboard definition in KEYBOARD-SOURCE-DIRECTORY." 28 (package 29 (name (string-append "qmk-firmware-" 30 (regexp-substitute/global #f "[_/]" keyboard 31 'pre "-" 'post) 32 "-" 33 (string-replace-substring keymap "_" "-"))) 34 (version "0.31.9") 35 (source (origin 36 (method git-fetch) 37 (uri (git-reference 38 (url "https://github.com/qmk/qmk_firmware") 39 (commit version))) 40 (file-name (git-file-name "qmk-firmware" version)) 41 (sha256 42 (base32 43 "1vc0lp4k6816mgb8l73jmj6kv3b8ij23i9ia9y9s4f72h8z9j91c")))) 44 (build-system gnu-build-system) 45 (arguments 46 (list 47 #:modules '((guix build gnu-build-system) 48 (guix build utils) 49 (ice-9 ftw) 50 (ice-9 match) 51 (srfi srfi-26)) 52 #:target "arm-none-eabi" 53 ;; XXX: Running a test target like "test:$keyboard" doesn't seem to run 54 ;; anything and causes the .hex file to be regenerated; leave the tests 55 ;; out for now. 56 #:tests? #f 57 #:make-flags 58 #~(list #$(format #f "~a:~a" keyboard keymap) 59 (string-append "SHELL=" (search-input-file 60 %build-inputs "bin/sh")) 61 "CONVERT_TO=rp2040_ce") 62 #:phases 63 #~(modify-phases %standard-phases 64 (replace 'configure 65 (lambda _ 66 ;; Do not attempt to retrieve information from git during the 67 ;; build. 68 (setenv "SKIP_GIT" "1"))) 69 (add-after 'unpack 'copy-chibios-source 70 (lambda _ 71 (copy-recursively 72 #$(let ((commit "8bd61b804303f1614d574546c2dd735eeabb09f5")) 73 (origin 74 (method git-fetch) 75 (uri (git-reference 76 (url "https://github.com/qmk/chibios") 77 (commit commit))) 78 (file-name (git-file-name "chibios" commit)) 79 (sha256 80 (base32 81 "1waixxdgr48385k1dkf6zpvngdpp78kagkvdpag9y9pg610gqzd2")))) 82 "lib/chibios"))) 83 #$@(if keyboard-source-directory 84 #~((add-after 'unpack 'copy-keyboard-source-directory 85 (lambda _ 86 (let ((keyboard-dir #$(string-append "keyboards/" keyboard))) 87 (false-if-exception (delete-file-recursively 88 keyboard-dir)) 89 (copy-recursively #$keyboard-source-directory 90 keyboard-dir))))) 91 #~()) 92 #$@(if keymap-source-directory 93 #~((add-after 'unpack 'copy-keymap-source-directory 94 (lambda _ 95 (let ((keymap-dir #$(string-append "keyboards/" keyboard 96 "/keymaps/" keymap))) 97 (false-if-exception (delete-file-recursively 98 keymap-dir)) 99 (copy-recursively #$keymap-source-directory 100 keymap-dir))))) 101 #~()) 102 #$@(if keymap-json 103 #~((replace 'build 104 (lambda _ 105 (invoke "qmk" "compile" #$keymap-json)))) 106 #~()) 107 (replace 'install 108 (lambda _ 109 (match (scandir "." (lambda (f) 110 (false-if-exception 111 (member (string-take-right f 4) 112 '(".bin" ".hex" ".uf2"))))) 113 (() 114 (error "no built binary file found")) 115 ((hex ..1) 116 (for-each (cut install-file <> #$output) hex)))))))) 117 ;; Some of the build tools are required to be on the PATH, as the make 118 ;; files do not always operate through 'qmk'; all of qmk's inputs must 119 ;; thus be made available. 120 (native-inputs (modify-inputs (package-inputs qmk) 121 (append qmk 122 (make-newlib-nano-arm-none-eabi)))) 123 (home-page "https://qmk.fm/") 124 (synopsis "Keyboard firmware for Atmel AVR and Arm USB families") 125 (description 126 (format #f "QMK (Quantum Mechanical Keyboard Firmware) is a keyboard 127 firmware based on the @url{https://github.com/tmk/tmk_keyboard, tmk_keyboard 128 firmware} with some useful features for Atmel AVR and ARM controllers, and 129 more specifically, the @url{https://olkb.com/, OLKB product line}, the 130 @url{https://ergodox-ez.com/, ErgoDox EZ keyboard}, and the 131 @url{https://clueboard.co/, Clueboard product line}.~@[~%~%~a~]" description)) 132 (license license:gpl2+))) 133 134 (define-public qmk-crkbd 135 (make-qmk-firmware "crkbd" "default" #:description 136 "The default keymap for the Corne keyboard, a split keyboard with 3x6 vertically 137 staggered keys and 3 thumb keys.")) 138 139 (define-public qmk-ferris-sweep 140 (make-qmk-firmware-rp2040 "ferris/sweep" "default" #:description 141 "The default keymap for the Ferris Sweep keyboard, a version of the 142 Ferris 3x5+2 split keyboard with a daughterboard for MCU.")) 143 144 (define-public qmk-ploopy-adept 145 (make-qmk-firmware-rp2040 "ploopyco/madromys" "default" #:description 146 "The default keymap for the Ploopy Adept open-hardware programmable 147 trackball mouse."))