-
-
Notifications
You must be signed in to change notification settings - Fork 40.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor bluetooth support. Add support for Adafruit Bluefruit LE UART Friend. #8982
Conversation
c86e5d7
to
60f8c5a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is adding a lot of duplicate and extra code; I would rather the existing BLE code be refactored to pull up the AT and SDEP stuff, so that the transport can be swapped out more easily.
EDIT: By the way, the SPI friend is already supported with the current implementation.
I tried that first and it turned out quite badly, very messy and difficult to reason about (e.g. the event system for detecting connection and disconnection). The adafruit base makes it very easy to switch transports. Maybe I wasn’t clear, but I’d like the existing BLE code to be deprecated in favor of integrating the SPI bits of the adafruit code. I just didn’t want to make an even larger change right off the bat. That’s why I suggested doing it in another, follow up, PR. Further, I think you’ll find that the new code is far more feature full and easier to develop with. The uart’s bt capability here far surpasses what the existing spi code was capable of (e.g. real battery level indication, bt disconnection and reconnection when usb is plugged in and out, proper rgblight resumption and more). Adding the spi parts next will give it the same level of capability. Once the existing spi bt code is removed (in favor of the adafruit stuff), the only redundant bits will be the small ‘serial_uart’ files and the standard ‘serial’ files which are also quite small. Both could be deprecated without a ton of work. I have a board with spi too, so it will be no problem testing that. |
|
60f8c5a
to
a42eee7
Compare
I've refactored the bluetooth support under a single interface. One interface now supports the adafruit ble protocol (now over both uart and spi). The other, bluetooth_classic, for RN-42 and adafruit ezkey. |
Why did you delete the SPI driver? |
I'm kind of driving blind here. Nothing else was using it. I can certainly add it back. I was just trying to keep everything clean. The arduino libraries (currently under I'm not trying to make any waves. I'd love to get this merged. I'm happy to do whatever the team needs to move forward. |
7f35811
to
27f0df1
Compare
I added spi_master because of the need for a generic API matching i2c_master: #8299
This is the main issue I have with including the Arduino libraries - they are very AVR-specific and the exact opposite of what spi_master is trying to achieve. |
27f0df1
to
3768aa6
Compare
OK, no worries. I added spi_master back.
The only "AVR-specific" parts I've added are:
Each of those should be pretty easy to write for other mcus. Alternatively, now that I have things working, I can look into replacing the arduino spi backend with spi_master. However, I'd be really hesitant to rip out such well tested code. |
For clarity, Additionally, there is support for other SPI devices in the development pipeline, and
Please do - choosing AVR over ARM is becoming less and less enticing, and with the addition of any new external peripherals I'd be reluctant to limit support just for AVR. We're slowly trying to convert existing peripherals to equivalent abstracted implementations in order to support both architectures transparently, so tying this even stronger to AVR feels like a regression. |
|
quote
Looking forward to your uart mode code.Sir great job! |
What can I do to keep this moving forward? |
@latincompass please do not attempt to speak for the project. |
@joshuarubin Great work, I really appreciate what you did here. I'd really love to this merged! I've just tested it and I maybe found an issue: I'm just able to configure QMK and unfortunately unable to develop QMK so I cannot provide a fix myself, sorry. |
@cmaier thanks for trying it out! I could have sworn that this was working over bt, but I just tested and you're right. I'll look into it. Thanks for reporting! |
OK, well I'm really stumped here. The KC_LOCK key is being registered while disconnected from usb (e.g. if you lock the keyboard while on usb, then unplug it, press KC_LOCK again, plug it back into usb, it will now be unlocked). It's funny that when The actual keycodes are being sent right next to each other (one to bt, the other to usb) in I'd appreciate anyone explaining how this is the case. Thank you! |
@cmaier I just pushed a change that fixes the keyboard lock over bluetooth. let me know if you have any issues with it. |
Working like a charm. 🎉 Another thing I'm experiencing is this: Whenever I'm typing a little bit more than just a few words I can see that some KC's are being send multiple times while I'm connected via Bluetooth. That's can also happen while using copy/paste. Text ist then pasted several times as if I have pressed
Feels like there is something filling up and then it happens. |
I’ve experienced that too when there isn’t a solid connection to the Bluetooth module. Are you using a G60BLE? If so, I had to resolder the bt module in order to get things working well. A way you can test if this is the case is to try squeezing the bt module against the pcb and see if things improve. Seems like just bad qc. |
Signed-off-by: Joshua Rubin <[email protected]>
Signed-off-by: Joshua Rubin <[email protected]>
Signed-off-by: Joshua Rubin <[email protected]>
Signed-off-by: Joshua Rubin <[email protected]>
Signed-off-by: Joshua Rubin <[email protected]>
Signed-off-by: Joshua Rubin <[email protected]>
Signed-off-by: Joshua Rubin <[email protected]>
Signed-off-by: Joshua Rubin <[email protected]>
Signed-off-by: Joshua Rubin <[email protected]>
880298e
to
f1588c3
Compare
Rebased on latest |
Somehow qmk/directors was removed from the reviewers list |
Ping. How can I keep this alive? |
I think I'd prefer to go with a slightly different approach, that doesn't involve adding a huge chunk of Arduino-derived code. What I have so far looks similar to your bluetooth.[ch], however my goal is to also make it platform-agnostic, and it might even evolve into being a general wireless API, not just Bluetooth. I also need to tweak how output selection is done a bit, and I'm going to drop support for the Adafruit EZ-Key as the module is discontinued and there are no boards in the repo that use it. |
@fauxpark ok, is that code available somewhere? can I help get it across the line? |
I think what @fauxpark is getting at, is less C++ code, more C code, and more hardware agnostic code (such as using the hooks for drivers/(arch)/serial.h`, so that this will work on both ARM and AVR boards. |
Thank you for your contribution! |
The C++ code is just the arduino stuff. I can rewrite that into C if necessary. In addition to the arduino code though, there are new abstractions that would enable adding support for other bluetooth backends much easier. I think this would have a large benefit on the codebase. Further, the support in this patch is simply a huge improvement over what's currently in master. Let's not let "perfect" be the enemy of "good enough". I'd be happy to make changes and fix the conflicts if I could get some direction on how to proceed. |
Thank you for your contribution! |
Description
This adds support for the Adafruit Bluefruit LE UART Friend.
It depends first on getting #8952 merged as that's what I used for testing. Once that is merged, I will rebase this PR.
This particular keyboard (BIOI G60 BLE) does not actually use the Adafruit module in whole, rather it just uses the MDBT40 (pdf) module that the Adafruit uses and is flashed (at the factory) with the Adafruit firmware. The QMK source for this keyboard, from the factory, is unreleased. I am in no way affiliated with BIOI and this is a clean room implementation.
The code for this came primarily from the Adafruit source code which in turn depends on parts from the Arduino source code. Additionally, some inspiration came from the, still unmerged, TMK Pull Request.
I intend to add support for the Adafruit Bluefruit LE SPI Friend to replace the existing support in QMK, but felt that this should be merged first.
This particular implementation only works with hardware serial support and without hardware (or software) flow control. Adding support for software serial and hardware flow control, since they were originally in the Adafruit source code, should be pretty easy. I omitted this support initially in order to facilitate simpler configuration in QMK (just a single
#define
required in most cases) and to keep the code size small (though it still compiles larger than I'd like). Further, the included support for hardware serial, without flow control, occupies only 2 pins on the MCU. This is obviously advantageous for keyboards where the number of available pins is always at a premium. The existing SPI support, for example, requires at least 5 pins.QMK configuration to affect this:
rules.mk
:BLUETOOTH = AdafruitBLEUART
(not so fond of this, open to suggestions, maybeAdafruitBLE_UART
?#define AdafruitBleBaud 76800
is necessary for the G60 BLE because it's factory configured at this rate even though the Adafruit default is9600
.#define AdafruitBleBattery
is supported, in that, it will enable the bluetooth le battery service, however, adding support for each keyboard will require a method of reading the analog battery voltage, somehow, and converting it to a percentage.#define OUTPUT_AUTO_ENABLE
is supported and will automatically start and stop broadcasting depending on if it is plugged into usb or not. This means, for example, that your software keyboard will reappear on your phone when you plug the keyboard into your computer.Items still on my TODO list:
(likely in another PR)Types of Changes
Checklist