Maker Faire Tokyo 2018でMint60のスターターキットを購入して作りました。
公式の組み立て手順がしっかりしているのと、詳細なビルドログは他の人がすでに公開されているので(例: 自作キーボード Mint60 の組立て参考例!初心者でもできたよ)、組み立てた後のキーマップ変更方法について書いてみようと思います。
組み立て時のオススメ
その前に、1点だけ組み立て時にオススメしておきたいのは、スイッチやProMicroの半田付けが終わった時点でPCに繋いで動作確認することです。アクリルケースやキートップを付けてから半田付け忘れなどが発覚すると、外すのが面倒です。自分の場合、左のzの段のキー(z, x, c, v, b, shift)が反応しなくて、バラしてみたらその段の端子とLEDテープの端子が接触していたことが発覚しました。無事に直せましたが、早めの動作確認がオススメです。
組み上がったMint60は以下のような感じになりました(VとBが入れ替わっていたのであとで直しました)。
キーマップの変更手順
キーマップの変更手順ですが、大まかに以下の手順で行いました。
- QMK Firmwareをcloneする
- QMK Firmwareのビルド環境を整える
- Mint60のデフォルトのキーマップを確認する
- Mint60のデフォルトのキーマップをコピーして、カスタムのキーマップを定義する
- Mint60のカスタムのキーマップのファームウェアをビルドする
- 左右のProMicroにファームウェアを焼く
あらかじめ自分の理想のキーマップを考えておくと、スムーズにできると思います。以降では、Macでの手順を書きます。困ったときは、QMK公式ドキュメントのThe Complete Newbs Guide To QMKを参照してください、大体書いてあります。
QMK Firmwareをcloneする
ファームウェアをGitHubからcloneしてきます。
$ git clone https://github.com/qmk/qmk_firmware
$ cd qmk_firmware
QMK Firmwareのビルド環境を整える
ビルドに必要なものをインストールしてくれるスクリプトがあるので実行します。
$ ./util/qmk_install.sh
Macだと、Homebrewがなければそれをインストールした上で、brew経由で以下のパッケージをインストールするようです。
- avr-gcc@7
- gcc-arm-none-eabi
- dfu-programmer
- avrdude
avr-gccは特に時間がかかると思います。
以前に会社の有志でfoobarキーボードを作ったときにここら辺はインストールしていたので、わたしはこのスクリプトは実行しませんでした。
foobarキーボードを作ったとき話はキーボード自作のススメで公開されているので、興味のある人はどうぞ。ついでに、キートップのノベルティを作った話なんかもどうぞ。
Mint60のデフォルトのキーマップを確認する
cloneしたQMK Firmwareには、たくさんファイルやディレクトリがありますが、mint60の設定やコード、キーマップなどが格納されているのはkeyboards/mint60
ディレクトリ以下です。
この時点で定義されているキーマップを確認してみます。
$ ls keyboards/mint60/keymaps
default eucalyn
defaultとeucalynという名前のキーマップが使えるようです。eucalyn配列は、ぼくのかんがえるさいきょうのインターフェイスに詳しく書かれていますので、興味のある人はそちらを参照してください。それぞれディレクトリ(default, eucalyn)の中のkeymap.cというファイルの中でキーマップが定義されています。
ちなみに、make <キーボード名>:<キーマップ名>
を実行すると、その設定でファームウェアをビルドできます。デフォルトのキーマップのファームウェアをビルドしてみます。
$ make mint60:default
QMK Firmware 0.6.96
WARNING:
Some git sub-modules are out of date or modified, please consider running:
make git-submodule
You can ignore this warning if you are not compiling any ChibiOS keyboards,
or if you have modified the ChibiOS libraries yourself.
Making mint60 with keymap default
avr-gcc (GCC) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Compiling: keyboards/mint60/i2c.c [OK]
Compiling: keyboards/mint60/serial.c [OK]
Compiling: keyboards/mint60/matrix.c [OK]
Compiling: keyboards/mint60/split_util.c [OK]
Compiling: keyboards/mint60/mint60.c [OK]
Compiling: keyboards/mint60/keymaps/default/keymap.c [OK]
Compiling: quantum/quantum.c [OK]
Compiling: quantum/keymap_common.c [OK]
Compiling: quantum/keycode_config.c [OK]
Compiling: quantum/process_keycode/process_leader.c [OK]
Compiling: quantum/rgblight.c [OK]
Compiling: drivers/avr/ws2812.c [OK]
Compiling: quantum/led_tables.c [OK]
Compiling: tmk_core/common/host.c [OK]
Compiling: tmk_core/common/keyboard.c [OK]
Compiling: tmk_core/common/action.c [OK]
Compiling: tmk_core/common/action_tapping.c [OK]
Compiling: tmk_core/common/action_macro.c [OK]
Compiling: tmk_core/common/action_layer.c [OK]
Compiling: tmk_core/common/action_util.c [OK]
Compiling: tmk_core/common/print.c [OK]
Compiling: tmk_core/common/debug.c [OK]
Compiling: tmk_core/common/util.c [OK]
Compiling: tmk_core/common/eeconfig.c [OK]
Compiling: tmk_core/common/report.c [OK]
Compiling: tmk_core/common/avr/suspend.c [OK]
Compiling: tmk_core/common/avr/timer.c [OK]
Compiling: tmk_core/common/avr/bootloader.c [OK]
Assembling: tmk_core/common/avr/xprintf.S [OK]
Compiling: tmk_core/common/magic.c [OK]
Compiling: tmk_core/protocol/lufa/lufa.c [OK]
Compiling: tmk_core/protocol/usb_descriptor.c [OK]
Compiling: tmk_core/protocol/lufa/outputselect.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Class/Common/HIDParser.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/ConfigDescriptors.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/DeviceStandardReq.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/Events.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/HostStandardReq.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/USBTask.c [OK]
Linking: .build/mint60_default.elf [OK]
Creating load file for flashing: .build/mint60_default.hex [OK]
Copying mint60_default.hex to qmk_firmware folder [OK]
Checking file size of mint60_default.hex [OK]
* File size is fine - 20714/28672 (7958 free)
ログに出力されている通り、ファームウェアがmint60_default.hexという名前でqmk_firmwareフォルダ直下(カレントディレクトリ)にできています。
Mint60のデフォルトのキーマップをコピーして、カスタムのキーマップを定義する
デフォルトのキーマップをコピーして、カスタムのキーマップを定義します。といっても、ディレクトリごとコピーするだけです。
$ cp -r keyboards/mint60/keymaps/default keyboards/mint60/keymaps/custom
ここでは、customという名前にしてみました。このままだと全く同じキーマップなので、変更します。今回は、MacBook ProのキーボードやHHKBとの差をできるだけなくしたいと思い、以下のような配置にしてみました。
先にAltキーとWinキーのキートップだけ入れ替えてみると、次のようになりました。
配置が決まったら、keyboards/mint60/keymaps/custom/keymap.c
を適当なエディタで開いて編集します。以下のキーマップを格納している配列keymapsの中身を変更するだけです。1段分のキーマップが1行ずつ書かれているのでわかりやすいかと思います。[0]
とか[1]
はレイヤー番号で、レイヤーを変更するキー(Fn, MO(1))もあります。
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT( \
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, \
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, \
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, MO(1), \
KC_ESC, KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_BSPC, KC_ENT, LALT(KC_GRV), KC_LEFT,KC_DOWN,KC_RGHT \
),
[1] = LAYOUT( \
KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, \
RGB_TOG, RGBRST, RGB_HUI, RGB_SAI, RGB_VAI, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
XXXXXXX, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, KC_PGUP, _______, \
XXXXXXX, _______, _______, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_HOME, KC_PGDN, KC_END \
)
};
KC_xxxという名前のマクロでキーコードが参照できます。マクロの定義はtmk_core/common/keycode.h
を見るか、公式ドキュメントを見てください。レイヤー増やしたりもできます。今回は場所を入れ替えるくらいなので、あまり詳しく見ませんでした。diffは以下のようになりました。
diff --git a/keyboards/mint60/keymaps/default/keymap.c b/keyboards/mint60/keymaps/default/keymap.c
index 42c61ffaa..0b2b28097 100644
--- a/keyboards/mint60/keymaps/default/keymap.c
+++ b/keyboards/mint60/keymaps/default/keymap.c
@@ -39,9 +39,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT( \
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, \
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, \
- KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \
+ KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, MO(1), \
- KC_ESC, KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_BSPC, KC_ENT, LALT(KC_GRV), KC_LEFT,KC_DOWN,KC_RGHT \
+ KC_ESC, MO(1), KC_LALT, KC_LGUI, KC_SPC, KC_SPC, KC_RGUI, KC_RALT, KC_LEFT,KC_DOWN,KC_RGHT \
),
[1] = LAYOUT( \
KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, \
追加したキーマップは自分でも忘れそうなので、forkしてリモートブランチにpushしました。
Mint60のカスタムのキーマップのファームウェアをビルドする
キーマップの名前をcustomにしたので、make mint60:custom
を実行して、ファームウェアをビルドします。
$ make mint60:custom
make mint60:custom
QMK Firmware 0.6.96
WARNING:
Some git sub-modules are out of date or modified, please consider running:
make git-submodule
You can ignore this warning if you are not compiling any ChibiOS keyboards,
or if you have modified the ChibiOS libraries yourself.
Making mint60 with keymap custom
avr-gcc (GCC) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Compiling: keyboards/mint60/i2c.c [OK]
Compiling: keyboards/mint60/serial.c [OK]
Compiling: keyboards/mint60/matrix.c [OK]
Compiling: keyboards/mint60/split_util.c [OK]
Compiling: keyboards/mint60/mint60.c [OK]
Compiling: keyboards/mint60/keymaps/custom/keymap.c [OK]
Compiling: quantum/quantum.c [OK]
Compiling: quantum/keymap_common.c [OK]
Compiling: quantum/keycode_config.c [OK]
Compiling: quantum/process_keycode/process_leader.c [OK]
Compiling: quantum/rgblight.c [OK]
Compiling: drivers/avr/ws2812.c [OK]
Compiling: quantum/led_tables.c [OK]
Compiling: tmk_core/common/host.c [OK]
Compiling: tmk_core/common/keyboard.c [OK]
Compiling: tmk_core/common/action.c [OK]
Compiling: tmk_core/common/action_tapping.c [OK]
Compiling: tmk_core/common/action_macro.c [OK]
Compiling: tmk_core/common/action_layer.c [OK]
Compiling: tmk_core/common/action_util.c [OK]
Compiling: tmk_core/common/print.c [OK]
Compiling: tmk_core/common/debug.c [OK]
Compiling: tmk_core/common/util.c [OK]
Compiling: tmk_core/common/eeconfig.c [OK]
Compiling: tmk_core/common/report.c [OK]
Compiling: tmk_core/common/avr/suspend.c [OK]
Compiling: tmk_core/common/avr/timer.c [OK]
Compiling: tmk_core/common/avr/bootloader.c [OK]
Assembling: tmk_core/common/avr/xprintf.S [OK]
Compiling: tmk_core/common/magic.c [OK]
Compiling: tmk_core/protocol/lufa/lufa.c [OK]
Compiling: tmk_core/protocol/usb_descriptor.c [OK]
Compiling: tmk_core/protocol/lufa/outputselect.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Class/Common/HIDParser.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/ConfigDescriptors.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/DeviceStandardReq.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/Events.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/HostStandardReq.c [OK]
Compiling: lib/lufa/LUFA/Drivers/USB/Core/USBTask.c [OK]
Linking: .build/mint60_custom.elf [OK]
Creating load file for flashing: .build/mint60_custom.hex [OK]
Copying mint60_custom.hex to qmk_firmware folder [OK]
Checking file size of mint60_custom.hex [OK]
* File size is fine - 20714/28672 (7958 free)
mint60_custom.hexという名前でファームウェアができました。
左右のProMicroにファームウェアを焼く
あとはできあがったファームウェアをProMicroに焼くだけです。左右それぞれに接続して焼くので、2回行います。
書き込まれているブートローダーによって、書き込みモードに移行する手順やコマンドが違うので、注意してください。わたしが購入したキットのProMicroには、Caterinaというブートローダーとデフォルトのキーマップでビルドしたファームウェアが書き込まれていました。以降の手順はCaterina用の手順です。
USBで左(右)のProMicroに接続し、make mint60:custom:avrdude
コマンドを叩きます。
$ make mint60:custom:avrdude
QMK Firmware 0.6.96
WARNING:
Some git sub-modules are out of date or modified, please consider running:
make git-submodule
You can ignore this warning if you are not compiling any ChibiOS keyboards,
or if you have modified the ChibiOS libraries yourself.
Making mint60 with keymap custom and target avrdude
avr-gcc (GCC) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Size before:
text data bss dec hex filename
0 20714 0 20714 50ea .build/mint60_custom.hex
Checking file size of mint60_custom.hex [OK]
* File size is fine - 20714/28672 (7958 free)
Copying mint60_custom.hex to qmk_firmware folder [OK]
Detecting USB port, reset your controller now...............
USBのデバイス検出が始まるので、キーボードの裏側にあるリセットスイッチを押します。
あとは書き込み完了を待つだけです。
Detected controller on USB port at /dev/tty.usbmodem14511
Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.
Programmer supports the following devices:
Device code: 0x44
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9587 (probably m32u4)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file ".build/mint60_custom.hex"
avrdude: input file .build/mint60_custom.hex auto detected as Intel Hex
avrdude: writing flash (20714 bytes):
Writing | ################################################## | 100% 1.60s
avrdude: 20714 bytes of flash written
avrdude: verifying flash memory against .build/mint60_custom.hex:
avrdude: load data flash data from input file .build/mint60_custom.hex:
avrdude: input file .build/mint60_custom.hex auto detected as Intel Hex
avrdude: input file .build/mint60_custom.hex contains 20714 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.23s
avrdude: verifying ...
avrdude: 20714 bytes of flash verified
avrdude: safemode: Fuses OK (E:FB, H:D8, L:FF)
avrdude done. Thank you.
USBケーブルをもう片方のProMicroに挿してもう一度焼く作業をお忘れなく。
今回は簡単なキーマップ変更しかできなかったので、もうちょっとマニアックな設定とか、QMK Firmwareの便利な機能とかを誰か書いてくれると嬉しいなあと思います。