蓝牙
这份文档包含了关于如何通过蓝牙(低功耗)与主机设备通信的信息。
设置
必需的 Cargo 功能
您必须启用以下 rumcake
功能:
bluetooth
- 如果您使用基于 nRF 的键盘,则需要启用
nrf-ble
必需的代码
为了使您的键盘支持与蓝牙主机的通信,您必须在 #[keyboard]
宏调用中添加 bluetooth
,并且您的键盘必须实现 BluetoothKeyboard
和 BluetoothDevice
trait:
use rumcake::keyboard;
#[keyboard( // 在您的键盘宏调用中的某处 ... bluetooth)]struct MyKeyboard;
use rumcake::hw::platform::BluetoothDevice;impl BluetoothDevice for WingpairLeft { // 此地址可以是任何您想要的地址,只要它是有效的“Random Static”蓝牙地址。 // 请参阅此链接中的“Random Static Address”:https://novelbits.io/bluetooth-address-privacy-ble/ const BLUETOOTH_ADDRESS: [u8; 6] = [0x41, 0x5A, 0xE3, 0x1E, 0x83, 0xE7]; // TODO: 更改此处}
// 蓝牙配置use rumcake::bluetooth::BluetoothKeyboard;impl BluetoothKeyboard for MyKeyboard { const BLE_VID: u16 = 0x0000; // 更改此处 const BLE_PID: u16 = 0x0000; // 更改此处}
按键码
在您的 keyberon 布局中,您可以使用 HardwareCommand
中定义的任何枚举成员:
ToggleOutputOutputUSBOutputBluetooth
更多信息如下。
USB 主机通信互操作性
默认情况下,您的键盘将使用蓝牙与您的设备通信。
您可以使用 ToggleOutput
、OutputUSB
或 OutputBluetooth
按键码来在 USB 和蓝牙之间切换。
这不会断开您的键盘与 USB 或蓝牙主机的连接。它只是确定要发送键盘报告到的设备。
待办事项列表
- Multiple bluetooth profiles
- LE Secure Connections (I believe this requires
nrf-softdevice
changes) - Automatic output selection