-
Notifications
You must be signed in to change notification settings - Fork 153
Want to make a BLE HID Keyboard #200
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
Comments
It might be also blocked by
If I understand that correctly, as it is relevant for split keyboards. |
I think the start would be to add events here as per this documentation for example to try this using this struct of data from my understanding. |
just to play around i tried to implement simple bonding by adding something like:
but i end up getting |
Commenting out the following lines will prevent a panic. @funkycode https://github.com/tinygo-org/tinygo/blob/v0.30.0/src/runtime/gc_blocks.go#L281 |
well, it;s little bit of problematic for me, i didn't build tinygo and using docker to build fw :( |
This is something I've been looking into. Implementing bonding in a secure manner, especially with LESC, is probably not trivial. Aside from that, storing the bonding data to flash might be tricky since SoftDevice has strict timing requirements. It's not clear how much effort it will be to get SoftDevice to cooperate with machine.Flash or LittleFS or something else. One option I'm considering is a dual-chip setup with Zephyr (handling Bluetooth, maybe running ZMK, on nRF52840) communicating with TinyGo over UART. This can perhaps be handled by a single chip like the dual-core Nordic nRF5340 with the Bluetooth stuff running on the network core and TinyGo running on the application core. Another option is somehow embedding TinyGo within a Zephyr application. I'm keeping an eye on tinygo-org/tinygo#254 and tinygo-org/tinygo#3067.
One workaround is having both halves be peripherals and a separate dongle be the central. |
Well, yeah, the charts in Nordic docs are simple. As per ZMK, it might work, but I think then I could simply use ZMK and avoid tinygo, I think to have purely in tinygo is the way to go IMHO |
This is because the code is running inside an interrupt, and you can't do heap allocations there. C.sd_ble_gap_sec_params_reply(gapEvent.conn_handle, C.BLE_GAP_SEC_STATUS_SUCCESS, &secParams, nil)
Don't! This is a bug, even if it might appear to work most of the time. It really needs to be fixed (as described above, for example). |
I've found that as long as you don't block the SoftDevice for a too long period, it's usually fine. for j := 0; j < len(padded); j += int(f.WriteBlockSize()) {
// write word
*(*uint32)(unsafe.Pointer(address)) = binary.LittleEndian.Uint32(padded[j : j+int(f.WriteBlockSize())])
address += uintptr(f.WriteBlockSize())
waitWhileFlashBusy()
} For that, the code in here might be helpful: https://github.com/tinygo-org/tinygo/blob/release/src/runtime/runtime_nrf_softdevice.go |
Yeah, I had a thought to take it out as global, but not sure why I didn't. I think I would make global variables for sec_params and for keys and implement global functions for changing the parameters of those, not sure if there is still need to make a pairing request as callback function to enable to handle error (according to specs if you get an error, you can resend request with different value). Will try to make simple PR for review in case someone is interested and maybe can give feedback 🙏🏽 |
Okay, I was able to connect from nice!nano to my android phone and send text input. |
The default Bluetooth MTU value 23 corresponds to 20 bytes of data. Longer data such as the report map is typically transferred in 20-byte chunks. In some cases, the peripheral and central can negotiate a larger MTU value. |
So to try to store data i need to use @sago35 If i recall correctly you implement vial support, does it use flash to write data? I would like to see some example of how data is saved and how you read it in case it is 🙏 |
In tinygo-keyboard, the following code is used to utilize machine.Flash.
Other example is here. |
@funkycode It was my misunderstanding. I had turned the XIAO-BLE into a BLE SNIFFER, and I've come to realize that this breaks various functionalities of TinyGo. In such a case, it's necessary to re-flash the softdevice. |
@funkycode |
I have a lot of mess, |
If you haven't already, I would suggest looking at the "peer manager" in the nRF5 SDK for examples of how the callbacks are used. I think It might be a good idea to start by writing an in-memory backend. The bonding data wouldn't persist between reboots but it will require less effort and help verify that you are storing and restoring the correct data. Keep in mind that erasing flash is expensive on embedded systems so most likely you'll want to implement an append-only key-value store where the last value has priority when data is read back from flash. Using something higher level like LittleFS is another option. |
I was able to successfully establish LESC communication. as well Moreover seems that public key generation is heavy, as for some reason, when I utilize I can't create simple goroutine in the keyboard logic for key press events I had working in just bond connection. |
@sago35 Something else which I don't think exists yet, is attribute descriptors which i think are required to setup a BLE HID Keyboard, right? |
You can add the notify or indicate permission which will automatically create an attribute descriptor. Other kinds of attribute descriptors aren't supported right now. |
The BLE HID Keyboard can be made to work to some extent as follows. However, it worked on Android but failed around pairing on Windows. https://github.com/sago35/tinygo-keyboard/blob/fde11c000fdef1b0c6813fffc7f0e05a13ac4a90/ble/ble.go The following value needs to be changed to a value larger than 20 (the size of the Descriptor). It may be necessary to make this value configurable. Line 60 in d0c7887
|
Perhaps Bonding is what is needed, but there may be other things needed.
Is anyone working on creating a BLE HID Keyboard?
Or, what can I make that will help me reach my goal?
I would like some hints.
The text was updated successfully, but these errors were encountered: