[Q] Status of Bluetooth support for TMK/QMK

User avatar
Laser
emacs -nw

22 May 2017, 12:59

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)

User avatar
Phenix
-p

22 May 2017, 18:14

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)

User avatar
wez

25 May 2017, 05:18

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

User avatar
Laser
emacs -nw

25 May 2017, 08:24

Thanks, this is great! I'll probably buy a SPI Friend then, and come up with questions as they arise. Thanks again!

User avatar
Laser
emacs -nw

13 Nov 2017, 15:52

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:

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
                      --------
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?

User avatar
wez

17 Nov 2017, 06:17

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!

nivloM droL

17 Nov 2017, 07:18

Could this work for Model F and Beamspring controllers as well?

User avatar
Laser
emacs -nw

17 Nov 2017, 07:51

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! :)
Last edited by Laser on 17 Nov 2017, 08:53, edited 1 time in total.

User avatar
Laser
emacs -nw

17 Nov 2017, 08:50

nivloM droL wrote: Could this work for Model F and Beamspring controllers as well?
From what I understand, no - if you're talking about Soarer's controller firmware, and probably yes if you talk about firmware based on QMK.

User avatar
Laser
emacs -nw

01 Dec 2017, 13:51

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.
spi_friend_pro_micro_breadboard.jpg
spi_friend_pro_micro_breadboard.jpg (286.63 KiB) Viewed 6587 times

Post Reply

Return to “Workshop”