As the title says, how easy/hard is it nowadays to integrate Bluetooth support to TMK/QMK firmware - especially efficient, low power support?
EDIT: I understand that Bluefruit EZ-Key v1.2 is supported (example), but not Bluetooth LE (although it was used in keyboards, just not in TMK/QMK - here)
[Q] Status of Bluetooth support for TMK/QMK
- Phenix
- -p
- Location: Germany, Cologne
- Main keyboard: F122, soarer´d|Novatouch-s
- Main mouse: Roccat Kone Pure|Rollermouse
- Favorite switch: BS F|Topre-s
- DT Pro Member: -
look up eg the mitosis keyboard, which does at least wireless connection.
(a wireless module sends the keystrokes to a wirelessmodule soldered to a pro micro)
(a wireless module sends the keystrokes to a wirelessmodule soldered to a pro micro)
- wez
- Location: San Francisco Bay Area
- Main keyboard: ErgoDox EZ
- Main mouse: Magic Trackpad 2
- Favorite switch: MX/Gateron Browns
- DT Pro Member: -
I added support for the Adafruit Feather BLE module (https://www.adafruit.com/product/2829) to QMK.
If you're using the Feather with onboard BLE, you just need to turn on support in your keyboard's rules.mk:
https://github.com/wez/qmk_firmware/blo ... les.mk#L19
If you've purchased the standalone SPI Friend module (https://www.adafruit.com/product/2633), you can crib from this code that I haven't upstreamed to QMK yet to enable it:
https://github.com/wez/qmk_firmware/com ... 96974f9f9a
The critical things are the changes to the adafruit_ble.cpp file, and the config changes to let it know which pins are connected https://github.com/wez/qmk_firmware/blo ... .h#L40-L44
If you're using the Feather with onboard BLE, you just need to turn on support in your keyboard's rules.mk:
https://github.com/wez/qmk_firmware/blo ... les.mk#L19
If you've purchased the standalone SPI Friend module (https://www.adafruit.com/product/2633), you can crib from this code that I haven't upstreamed to QMK yet to enable it:
https://github.com/wez/qmk_firmware/com ... 96974f9f9a
The critical things are the changes to the adafruit_ble.cpp file, and the config changes to let it know which pins are connected https://github.com/wez/qmk_firmware/blo ... .h#L40-L44
- Laser
- emacs -nw
- Location: Romania
- Main keyboard: Plum TKL \w Topre domes (work) / Novatouch (home)
- DT Pro Member: 0180
So I finally made a contraption from a 5V Pro Micro and an Adafruit SPI Friend, in order to add Bluetooth to Hasu's TMK PS2->USB converter. I did manage to convert the ps2_usb converter from TMK to QMK (and it works, when BLE is not enabled), but I have problems with the Adafruit stuff. The wiring looks like this:
The connections to either PS2 (kbd) or Bluetooth module are shown in parenthesis, near each relevant pin.
In my understanding, as long as I don't define (or have) a "AdafruitBlePowerPin", current QMK has everything it needs to enable Bluetooth on SPI for a keyboard/converter firmware, I should only define the appropriate CS, IRQ and RST pins and I'm good to go, right? (I also had to use a F_CPU of 8MHz, so I had to use a clock divisor of 2, and I called adafruit_ble_enable_keyboard() or similar in my matrix init code). The actual code is here. Anything missing? Any glaring errors? Or, how should I debug it?
Code: Select all
PS2 -> PS/2 Keyboard pins
BLE -> Bluefruit BLE SPI Friend module
Pro Micro 5V
--------
TX D3 | | RAW (+5V from USB)
RX D0 | | GND
(BLE GROUND) GND | | RST
(PS2 GROUND) GND | | VCC (+5V) (PS2 VCC) (BLE VIN)
(PS2 CLOCK) SDA D1 | | F4
(PS2 DATA) SCL D0 | | F5
(BLE CS) D4 | | F6
(BLE IRQ) C6 | | F7
(BLE RESET) D7 | | B1 SCLK (BLE SCK)
E6 | | B3 MISO (BLE MISO)
B4 | | B2 MOSI (BLE MOSI)
B5 | | B6
--------
In my understanding, as long as I don't define (or have) a "AdafruitBlePowerPin", current QMK has everything it needs to enable Bluetooth on SPI for a keyboard/converter firmware, I should only define the appropriate CS, IRQ and RST pins and I'm good to go, right? (I also had to use a F_CPU of 8MHz, so I had to use a clock divisor of 2, and I called adafruit_ble_enable_keyboard() or similar in my matrix init code). The actual code is here. Anything missing? Any glaring errors? Or, how should I debug it?
- wez
- Location: San Francisco Bay Area
- Main keyboard: ErgoDox EZ
- Main mouse: Magic Trackpad 2
- Favorite switch: MX/Gateron Browns
- DT Pro Member: -
Hey, sorry for the delay in responding. Nothing obvious stands out, but I confess to not looking super deeply. Things I would try if I were you:
* Does the clock divisor of 2 impact the SPI bus speed computation in the ble code? I'm not sure, but it should be ok if the effective clock speed in F_CPU is accurate
* Are there really no differences between the qmk master and the code on the branch I shared that you might need to pick up? I think there may be some subtle differences that might make a difference
Good luck!
* Does the clock divisor of 2 impact the SPI bus speed computation in the ble code? I'm not sure, but it should be ok if the effective clock speed in F_CPU is accurate
* Are there really no differences between the qmk master and the code on the branch I shared that you might need to pick up? I think there may be some subtle differences that might make a difference
Good luck!
-
- Location: US
- Main keyboard: KISH
- Main mouse: LOGITECH
- Favorite switch: SPRING
- DT Pro Member: -
Could this work for Model F and Beamspring controllers as well?
- Laser
- emacs -nw
- Location: Romania
- Main keyboard: Plum TKL \w Topre domes (work) / Novatouch (home)
- DT Pro Member: 0180
wez wrote: Hey, sorry for the delay in responding. Nothing obvious stands out, but I confess to not looking super deeply. Things I would try if I were you:
* Does the clock divisor of 2 impact the SPI bus speed computation in the ble code? I'm not sure, but it should be ok if the effective clock speed in F_CPU is accurate
* Are there really no differences between the qmk master and the code on the branch I shared that you might need to pick up? I think there may be some subtle differences that might make a difference
Good luck!
Hello and thanks for answering!
Dividing the clock to 8MHz doesn't seem to work too well for the ps2->usb conversion too, so I reverted to 16MHz. I'll look at the differences, and I will also try to make a simple AVR project that does just SPI initialization. There also might be some issues related to the Pro Micro pins (their mapping to names like D4, C6 etc. and maybe the SS pin). But I have to read a little first. Thanks again!
![Smile :)](./images/smilies/icon_e_smile.gif)
Last edited by Laser on 17 Nov 2017, 08:53, edited 1 time in total.
- Laser
- emacs -nw
- Location: Romania
- Main keyboard: Plum TKL \w Topre domes (work) / Novatouch (home)
- DT Pro Member: 0180
- Laser
- emacs -nw
- Location: Romania
- Main keyboard: Plum TKL \w Topre domes (work) / Novatouch (home)
- DT Pro Member: 0180
I think I solved it
What put me off for a while was (as I wasn't used with microcontroller development) the different ways of accessing pins in 1) avr-gcc/libc, which uses PB0, PB1 etc, 2) Arduino IDE, which uses actual pins numbers as 1, 2, 3 etc. and dedicated functions to configure/read/write the pins and ... 3) QMK which invented a 3rd way of naming and accessing the pins: D0, B0 ("quantum/config_common.h") and functions from "quantum/pincontrol.h". Once that became clear, and after configuring SPI properly for F_CPU = 16000000 Hz (i.e. divide by 4 to get the 4000000 SPI frequency), I got it working. At least the BLE part, because I'm not at home and can't test properly the ps2 converter part (that *was* tested properly, when used without BLE). If all goes well, maybe I'll try a pull request or two to integrate Hasu's converter (TMK -> QMK) and the slightly altered Adafruit BLE file to support 16MHz.
![Smile :)](./images/smilies/icon_e_smile.gif)