Skip to content

Commit

Permalink
move BluetoothCommand to the hw module and rename it to `Hardware…
Browse files Browse the repository at this point in the history
…Command`
  • Loading branch information
Univa committed Mar 30, 2024
1 parent 28946c2 commit d4ad2b2
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 321 deletions.
10 changes: 6 additions & 4 deletions docs/src/content/docs/features/feature-bluetooth-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ Also check the sections below for more information.

# Keycodes

In your keyberon layout, you can use any of the enum members defined in `BluetoothCommand`:
In your keyberon layout, you can use any of the enum members defined in `HardwareCommand`:

```rust
ToggleOutput // Only available if the `usb` feature flag is also enabled. More information below.
OutputUSB // Only available if the `usb` feature flag is also enabled. More information below.
OutputBluetooth // Only available if the `usb` feature flag is also enabled. More information below.
ToggleOutput
OutputUSB
OutputBluetooth
```

More information below.

## USB host communication interoperability

By default, your keyboard will use Bluetooth to communicate with your device.
Expand Down
36 changes: 2 additions & 34 deletions rumcake/src/bluetooth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
#[cfg(any(all(feature = "nrf", feature = "bluetooth"), doc))]
pub mod nrf_ble;

use embassy_sync::channel::Channel;
use embassy_sync::signal::Signal;

use crate::hw::platform::RawMutex;
use crate::keyboard::{Keyboard, KeyboardLayout};
use crate::keyboard::Keyboard;
use crate::State;

/// A trait that keyboards must implement to communicate with host devices over Bluetooth (LE).
pub trait BluetoothKeyboard: Keyboard + KeyboardLayout {
pub trait BluetoothKeyboard: Keyboard {
/// Vendor ID for the keyboard.
const BLE_VID: u16;

Expand All @@ -25,37 +24,6 @@ pub trait BluetoothKeyboard: Keyboard + KeyboardLayout {
const BLE_PRODUCT_VERSION: &'static str = Self::HARDWARE_REVISION;
}

#[derive(Debug, Clone, Copy)]
/// An enumeration of possible commands that will be processed by the bluetooth task.
pub enum BluetoothCommand {
#[cfg(feature = "usb")]
/// Switch between USB and Bluetooth operation.
///
/// This will **NOT** disconnect your keyboard from your host device. It
/// will simply determine which device the HID reports get sent to.
ToggleOutput,
#[cfg(feature = "usb")]
/// Switch to USB operation.
///
/// If your keyboard is connected to a bluetooth device, this will **NOT** disconnect your
/// keyboard from it. It will simply output the HID reports to the connected USB device.
OutputUSB,
#[cfg(feature = "usb")]
/// Switch to bluetooth operation.
///
/// If your keyboard is connected to a USB device, this will **NOT** disconnect your keyboard
/// from it. It will simply output the HID reports to the connected bluetooth device.
OutputBluetooth,
}

/// Channel for sending [`BluetoothCommand`]s.
///
/// Channel messages should be consumed by the bluetooth task ([`nrf_ble::nrf_ble_task`] for
/// nRF5x-based keyboards), so user-level code should **not** attempt to receive messages from the
/// channel, otherwise commands may not be processed appropriately. You should only send to this
/// channel.
pub static BLUETOOTH_COMMAND_CHANNEL: Channel<RawMutex, BluetoothCommand, 2> = Channel::new();

pub(crate) static BLUETOOTH_CONNECTED_STATE: State<bool> =
State::new(false, &[&crate::hw::BLUETOOTH_CONNECTED_STATE_LISTENER]);

Expand Down
Loading

0 comments on commit d4ad2b2

Please sign in to comment.