BLE Micro ProでAZ1UBALLを動かす奮闘記(諦めました)

# はじめに

BLE Micro ProでAZ1UBALLを動かしたくて悪戦苦闘している記録。2024/1/2 23:00時点でまだ動いていない。
大前提としてBMPを販売しているせきごんさんとしてはAZ1UBALLはサポートしていないので、動かないのがあたり前です。自分の勉強もかねて理想のキーボードに近づけるために奮闘している個人的な記録です。

# まずはシンプルにコンパイル→エラー

以下のコマンドでせきごんさんのvial対応BMP用のqmk_firmwareをclone。

```
git clone --depth 1 -b dev/ble-micro-pro https://github.com/sekigon-gonnoc/vial-qmk.git qmk_firmware_bmp_vial
```

`keyboards/ble_micro_pro`をコピーして`keyboards/az1uball`という名前にする。

```
cp -R keyboards/ble_micro_pro  keyboards/az1uball
```

`keyboards/az1uball/rules.mk`に以下を追記。

```c
 POINTING_DEVICE_ENABLE = yes
 POINTING_DEVICE_DRIVER = pimoroni_trackball
```

以下のコマンドでcompileしてみる。az1uballというキーボードの、vialというキーマップをuf2形式でコンパイルするという意味。

```sh
make az1uball:vial:uf2
```

以下のエラーを得る。`i2c_master.h`が見つからない様だ。

```sh
fatal: No names found, cannot describe anything.
Compiling: .build/obj_az1uball_vial/src/default_keyboard.c                                         In file included from quantum/quantum.h:209,
                 from ./.build/obj_az1uball_vial/src/default_keyboard.h:27,
                 from .build/obj_az1uball_vial/src/default_keyboard.c:26:
quantum/pointing_device/pointing_device.h:50:14: fatal error: i2c_master.h: No such file or directory
 #    include "i2c_master.h"
              ^~~~~~~~~~~~~~
compilation terminated.
 [ERRORS]
 | 
 | 
 | 
make[1]: *** [.build/obj_az1uball_vial/.build/obj_az1uball_vial/src/default_keyboard.o] Error 1
make: *** [az1uball:vial:uf2] Error 1
Make finished with errors
```

# I2C_DRIVER_REQUIREDをyesにしてみる→ダメ

`keyboards/az1uball/rules.mk`に`I2C_DRIVER_REQUIRED = yes`を追記。して試してみるも同じエラーで詰まる。

```c
I2C_DRIVER_REQUIRED = yes
POINTING_DEVICE_ENABLE = yes
POINTING_DEVICE_DRIVER = pimoroni_trackball
```

# qmk_install.shやってみる→ダメ

ChatGPTに聞いてみると`./util/qmk_install.sh`を動かしてみたら？とのことだったのでやってみたが、結果はかわらず。同じエラーが出る。

# i2c_master.hの場所を確認してみる→何もわからない

ちなみにi2c_master.hの場所を確認してみる。通常のqmk_firmwareだと以下にある。sekigonさんのqmk_firmwareでも同じ場所にあった。パスが変わってるわけではなさそう。

```
./tmk_core/protocol/arm_atsam
```

# POINTING_DEVICE_DRIVERをコメントアウトしてみる→違うエラー

`POINTING_DEVICE_DRIVER`を設定しないとどうなるのか試してみる。多分デバイスが指定されてないためエラーになっていそう。

```sh
% make az1uball:vial:uf2                                                                                                                                     (git)-[dev/ble-micro-pro]
Making az1uball with keymap vial and target uf2


 * POINTING_DEVICE_DRIVER= is not a valid pointing device type                                         [ERRORS]

builddefs/common_features.mk:140: *** Invalid POINTING_DEVICE_DRIVER.  Stop.
make: *** [az1uball:vial:uf2] Error 1
```

# tmk_coreをqmk_firmwareからもってくる→ダメ

既存のtmk_coreのディレクトリ名を変更して、qmk_firmwareからコピーしてくる

```sh
% mv tmk_core tmk_core_original
% cp -R ../qmk_firmware/tmk_core ./
```

すると別のエラーになった。bmp.mkを読みにいこうとしたけれどないって感じ。

```sh
% make az1uball:vial:uf2                                                                                                                   (git)-[dev/ble-micro-pro]
Making az1uball with keymap vial and target uf2

builddefs/build_keyboard.mk:445: tmk_core/protocol/bmp/bmp.mk: No such file or directory
make[1]: *** No rule to make target `tmk_core/protocol/bmp/bmp.mk'.  Stop.
make: *** [az1uball:vial:uf2] Error 1
Make finished with errors
```

以下のコマンドでbmpフォルダを持ってくる。

```sh
cp -R tmk_core_original/protocol/bmp tmk_core/protocol/
```

するとまた`i2c_master.h`が見つからないとのこと。

```sh
% make az1uball:vial:uf2                                                                                                                   (git)-[dev/ble-micro-pro]
Making az1uball with keymap vial and target uf2

fatal: No names found, cannot describe anything.
fatal: No names found, cannot describe anything.
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 8-2019-q3-update) 8.3.1 20190703 (release) [gcc-8-branch revision 273027]
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.

fatal: No names found, cannot describe anything.
Compiling: .build/obj_az1uball_vial/src/default_keyboard.c                                         In file included from quantum/quantum.h:209,
                 from ./.build/obj_az1uball_vial/src/default_keyboard.h:27,
                 from .build/obj_az1uball_vial/src/default_keyboard.c:26:
quantum/pointing_device/pointing_device.h:50:14: fatal error: i2c_master.h: No such file or directory
 #    include "i2c_master.h"
              ^~~~~~~~~~~~~~
compilation terminated.
 [ERRORS]
 | 
 | 
 | 
make[1]: *** [.build/obj_az1uball_vial/.build/obj_az1uball_vial/src/default_keyboard.o] Error 1
make: *** [az1uball:vial:uf2] Error 1
Make finished with errors
```

bmp.mkにパスを追加したらうまくいくのか？

# bmp.mkにパスを追記→エラーが変わる

`tmk_core/protocol/bmp/bmp.mk`の末尾に以下の行を追加

```c
VPATH += $(TMK_PATH)/$(PROTOCOL_DIR)/arm_atsam
```

エラーの内容が変わった。今度は`samd51ji18a.h`が見つからないらしい。

```sh
Making az1uball with keymap vial and target uf2

fatal: No names found, cannot describe anything.
fatal: No names found, cannot describe anything.
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 8-2019-q3-update) 8.3.1 20190703 (release) [gcc-8-branch revision 273027]
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.

fatal: No names found, cannot describe anything.
Compiling: .build/obj_az1uball_vial/src/default_keyboard.c                                         In file included from quantum/pointing_device/pointing_device.h:5,
                 from quantum/quantum.h:209,
                 from ./.build/obj_az1uball_vial/src/default_keyboard.h:27,
                 from .build/obj_az1uball_vial/src/default_keyboard.c:26:
tmk_core/protocol/arm_atsam/i2c_master.h:23:14: fatal error: samd51j18a.h: No such file or directory
 #    include "samd51j18a.h"
              ^~~~~~~~~~~~~~
compilation terminated.
 [ERRORS]
 | 
 | 
 | 
make[1]: *** [.build/obj_az1uball_vial/.build/obj_az1uball_vial/src/default_keyboard.o] Error 1
make: *** [az1uball:vial:uf2] Error 1
Make finished with errors
```

# bmp.mkにさらに追記する→エラーが変わる

bmp.mkに以下を追加。

```c
VPATH += lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/include
```

すると以下のエラー。今度は`core_cm4.h`。これじゃもぐらたたきか...

```sh
% make az1uball:vial:uf2                                                                                                                   (git)-[dev/ble-micro-pro]
Making az1uball with keymap vial and target uf2

fatal: No names found, cannot describe anything.
fatal: No names found, cannot describe anything.
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 8-2019-q3-update) 8.3.1 20190703 (release) [gcc-8-branch revision 273027]
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.

fatal: No names found, cannot describe anything.
Compiling: .build/obj_az1uball_vial/src/default_keyboard.c                                         In file included from tmk_core/protocol/arm_atsam/i2c_master.h:23,
                 from quantum/pointing_device/pointing_device.h:50,
                 from quantum/quantum.h:209,
                 from ./.build/obj_az1uball_vial/src/default_keyboard.h:27,
                 from .build/obj_az1uball_vial/src/default_keyboard.c:26:
lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/include/samd51j18a.h:546:10: fatal error: core_cm4.h: No such file or directory
 #include <core_cm4.h>
          ^~~~~~~~~~~~
compilation terminated.
 [ERRORS]
 | 
 | 
 | 
make[1]: *** [.build/obj_az1uball_vial/.build/obj_az1uball_vial/src/default_keyboard.o] Error 1
make: *** [az1uball:vial:uf2] Error 1
Make finished with errors

```

# 考察というか妄想

BLE Micro Proで左右分割キーボードを作る際はi2c通信を使う様なので、i2c_master.hを介さずにi2cをコントロールする様にあえてi2c_master関連のパスは通さない様にしているのか...?