-
Notifications
You must be signed in to change notification settings - Fork 131
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
microbit-dal: Minimalist Keyboard HID Service #249
base: master
Are you sure you want to change the base?
Conversation
This commit introduces a lightweight HID service that has very simple send operations to the host. This HID service has only been tested using Just works pairing, and should be considered an initial implementation, pending review.
@jamesadevine The spec recommends certain AD fields be included in advertising from a device that implements the HID over GATT Profile. |
@bluetooth-mdw I was more concerned with the new Device Information service. Is it bad to advertise the PnpID all the time regardless of whether you are a HID? |
OK. No, I wouldn't say it's bad, just unnecessary. Per our discussion the other day, Characteristics can be optional and that one is defined as such should you could exploit this and only add the characteristic when the HID Service is included. |
* Added a special send for characters outside the ascii keyset * redesigned the interface, to include locks, and fiber blocking on all calls. * at 1:30am, I reimplemented fiber_sleep, I've undone that... ;)
Some comments from me and Thomas (@Lord-Nazdar) inc/bluetooth/MicrobitKeyboardService.h --> MicroBitKeyboardService.h Because it isn't bondable by default, it's weird to connect from a Mac, etc. Perhaps instead when pairing_mode (config.json version of the name) is 0 then we should be bondable in the default uBit instance of BLEManager |
…rvice.h My fs is case-insensitive, so I didn't realise the file was incorrectly named. Used git mv to rename the file.
Now that there are nice game controller addons out like https://sciencescope.uk/product/microbit-gvs-controller-kit/ it feels like time to re-asses this. @jamesadevine was there a reason other than time it didn't make it in? @Lord-Nazdar are you interested in picking it up and running with it? |
It was a number of things:
It was close, I think it had something to do with security settings (I think it has to be secured by pairing on Windows, but that's not required on Mac OS) and broadcasting as a keyboard at all times, including the pairing process. It did work on Mac OS, but it wasn't exactly usable, I had to force pairing and connection using the Lightblue App for Mac. |
@ukBaz this is the PR we were discussing today - would be amazing for game controllers and similar! |
index 2ea54a3..44e34ac 100644
--- a/inc/core/MicroBitConfig.h
+++ b/inc/core/MicroBitConfig.h
@@ -123,14 +123,14 @@ extern uint32_t __etext;
// The amount of memory reused depends upon whether or not BLE is enabled using MICROBIT_BLE_ENABLED.
// Set '1' to enable.
#ifndef MICROBIT_HEAP_REUSE_SD
-#define MICROBIT_HEAP_REUSE_SD 1
+#define MICROBIT_HEAP_REUSE_SD 0
#endif
// The amount of memory allocated to Soft Device to hold its BLE GATT table.
// For standard S110 builds, this should be word aligned and in the range 0x300 - 0x700.
// Any unused memory will be automatically reclaimed as HEAP memory if both MICROBIT_HEAP_REUSE_SD and MICROBIT_HEAP_ALLOCATOR are enabled.
#ifndef MICROBIT_SD_GATT_TABLE_SIZE
-#define MICROBIT_SD_GATT_TABLE_SIZE 0x300
+#define MICROBIT_SD_GATT_TABLE_SIZE 0x700
#endif
//
@@ -235,14 +235,14 @@ extern uint32_t __etext;
// SECURITY_MODE_ENCRYPTION_WITH_MITM: Bonding, encrytion and whitelisting with passkey authentication.
//
#ifndef MICROBIT_BLE_SECURITY_LEVEL
-#define MICROBIT_BLE_SECURITY_LEVEL SECURITY_MODE_ENCRYPTION_WITH_MITM
+#define MICROBIT_BLE_SECURITY_LEVEL SECURITY_MODE_ENCRYPTION_NO_MITM
#endif
// Enable/Disable the use of BLE whitelisting.
// If enabled, the micro:bit will only respond to connection requests from
// known, bonded devices.
#ifndef MICROBIT_BLE_WHITELIST
-#define MICROBIT_BLE_WHITELIST 1
+#define MICROBIT_BLE_WHITELIST 0
#endif
// Define the period of time for which the BLE stack will advertise (seconds)
@@ -261,7 +261,7 @@ extern uint32_t __etext;
// Based on trials undertaken by the BBC, the radio is normally set to its lowest power level
// to best protect children's privacy.
#ifndef MICROBIT_BLE_DEFAULT_TX_POWER
-#define MICROBIT_BLE_DEFAULT_TX_POWER 0
+#define MICROBIT_BLE_DEFAULT_TX_POWER 7
#endif
// Enable/Disable BLE Service: MicroBitDFU
@@ -301,7 +301,7 @@ extern uint32_t __etext;
// This enables the standard BLE HID keyboard service.
// Set '1' to enable.
#ifndef MICROBIT_BLE_KEYBOARD_SERVICE
-#define MICROBIT_BLE_KEYBOARD_SERVICE 0
+#define MICROBIT_BLE_KEYBOARD_SERVICE 1
#endif |
This works well on Mac, @finneyj says does not work on Windows. |
Would use the send member function rather than putc.
I built a working Windows binary using the Nordic SDK, so we can have a bit of a look to see if there's anything missing from your implementation here that Windows needs, @jamesadevine The hex attached works on Windows 10 on a micro:bit. You first pair, then every time you press 'A' it prints a character. ble_app_hids_keyboard_gcc_combined_s130_hack.zip It's based on https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v12.3.0%2Fble_sdk_app_hids_keyboard.html&cp=4_0_5_4_2_2_12 with hacks to make it compile for micro:bit (16k, different pinout). (this example also prints capson and capsof when the capslock is turned on or off, in case anyone thinks they're losing it!) |
(Whatever this example does, it also shows up on macOS as a 'real' keyboard as opposed to a generic Bluetooth device in the device selector) |
It looks like the missing services are the Boot Keyboard Input Report and Boot Keyboard Output Reports... I notice JP never implemented them in his original sample: https://github.com/jpbrucker/BLE_HID/blob/fc151647888329df66ca6985cd240631b965fa4d/BLE_HID/KeyboardService.h#L382 |
I gave @jamesadevine some feedback on 13th December 2016 about this. I compared a working HID implementation from Cypress Semiconductor with his and said:
I also provided screenshots of nRF Connect connected to the Cypress implementation: |
@bluetooth-mdw I'm not sure how much your analysis still holds true, since I made changes according to your diagnostics. In any case, it's good to have it up here rather than in Skype 😄 Also @jaustin the micro:bit appears as a keyboard to my mac on the latest revision. |
@jamesadevine yep, was just sharing in case it was useful. @jaustin noted the same missing services and I'd noted a few others differences. |
Hi all, First of all, I wanted to thank you for all the effort and the good work. <3 Otherwise I wanted to bump this thread... (I would if I could help out, but this is just out of my league and a little overwhelming...) The hex-file by @jaustin is not exactly working on my PC (Win10). It does give me a 'Nordic keyboard', so that's good... but it doesn't seem to 'connect': it does not react as a keyboard... (or typing 'hello, as I assume it would do). ->> The Scratch guys pulled it off though: https://scratch.mit.edu/microbit Is there someone actively importing this feature into MakeCode? Could this be a lead? I think a 'bluetooth keyboard' is a logical extension for the Microbit, if possible.
And well, Jonathan, I think I met you 2 years ago on the EU 'Maker Faire' in the EU Parliament in Brussels where you just convinced me of the beauty of Microbit :-) (Wasn't that you?) Let me know? |
I flash this hex (ble_app_hids_keyboard_gcc_combined_s130_hack.zip) to my microbit, it works by first paring with my Mac, and then press |
Strong recommendation: someone needs to test the HID implementation with the Bluetooth SIG's Profile Tuning Suite, which despite the name is actually a testing tool. It could be it's just not fully compliant with the specification (HID is surprisingly complicated). See https://www.bluetooth.com/develop-with-bluetooth/qualification-listing/qualification-test-tools/profile-tuning-suite @jamesadevine FYI @finneyj FYI |
@jaustin |
Would be nice to resurect this eventually... |
This commit introduces a lightweight Keyboard HID service that has very simple send operations to the host.
Inspired by the initial pull request of @matthewelse and the sterling work by @jpbrucker .
Points to note: