Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ categories = ["embedded", "no-std"]
license = "MIT"
readme = "README.md"

[features]
default = ["usb"]
usb = ["dep:usb-device"]

[dependencies]
keyberon-macros = { version = "0.1.0", path = "./keyberon-macros" }
either = { version = "1.9.0", default-features = false }
embedded-hal = { version = "1.0" }
usb-device = "0.3"
usb-device = { version = "0.3", optional = true }
heapless = "0.8"
arraydeque = { version = "0.5.1", default-features = false }
46 changes: 8 additions & 38 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,24 @@
//! a given MCU, you need GPIO throw the [embedded hal
//! crate](https://crates.io/crates/embedded-hal) to read the key
//! states, and the [usb-device
//! crate](https://crates.io/crates/usb-device) for USB communication.
//! crate](https://crates.io/crates/usb-device) for USB communication
//! if the `usb` feature is enabled.

#![no_std]
#![deny(missing_docs)]

use usb_device::bus::UsbBusAllocator;
use usb_device::device::StringDescriptors;
use usb_device::prelude::*;

pub mod action;
pub mod chording;
pub mod debounce;
#[cfg(feature = "usb")]
pub mod hid;
pub mod key_code;
#[cfg(feature = "usb")]
pub mod keyboard;
pub mod layout;
pub mod matrix;
#[cfg(feature = "usb")]
mod usb;

/// A handly shortcut for the keyberon USB class type.
pub type Class<'a, B, L> = hid::HidClass<'a, B, keyboard::Keyboard<L>>;

/// USB VIP for a generic keyboard from
/// https://github.com/obdev/v-usb/blob/master/usbdrv/USB-IDs-for-free.txt
const VID: u16 = 0x16c0;

/// USB PID for a generic keyboard from
/// https://github.com/obdev/v-usb/blob/master/usbdrv/USB-IDs-for-free.txt
const PID: u16 = 0x27db;

/// Constructor for `Class`.
pub fn new_class<B, L>(bus: &UsbBusAllocator<B>, leds: L) -> Class<'_, B, L>
where
B: usb_device::bus::UsbBus,
L: keyboard::Leds,
{
hid::HidClass::new(keyboard::Keyboard::new(leds), bus)
}

/// Constructor for a keyberon USB device.
pub fn new_device<B>(bus: &UsbBusAllocator<B>) -> usb_device::device::UsbDevice<'_, B>
where
B: usb_device::bus::UsbBus,
{
UsbDeviceBuilder::new(bus, UsbVidPid(VID, PID))
.strings(&[StringDescriptors::default()
.manufacturer("RIIR Task Force")
.product("Keyberon")
.serial_number(env!("CARGO_PKG_VERSION"))])
.expect("Failed to configure UsbDeviceBuilder")
.build()
}
#[cfg(feature = "usb")]
pub use usb::{new_class, new_device, Class};
40 changes: 40 additions & 0 deletions src/usb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! Keyberon USB constructors.

use crate::{hid, keyboard};
use usb_device::bus::UsbBusAllocator;
use usb_device::device::StringDescriptors;
use usb_device::prelude::*;

/// A handly shortcut for the keyberon USB class type.
pub type Class<'a, B, L> = hid::HidClass<'a, B, keyboard::Keyboard<L>>;

/// USB VIP for a generic keyboard from
/// https://github.com/obdev/v-usb/blob/master/usbdrv/USB-IDs-for-free.txt
const VID: u16 = 0x16c0;

/// USB PID for a generic keyboard from
/// https://github.com/obdev/v-usb/blob/master/usbdrv/USB-IDs-for-free.txt
const PID: u16 = 0x27db;

/// Constructor for `Class`.
pub fn new_class<B, L>(bus: &UsbBusAllocator<B>, leds: L) -> Class<'_, B, L>
where
B: usb_device::bus::UsbBus,
L: keyboard::Leds,
{
hid::HidClass::new(keyboard::Keyboard::new(leds), bus)
}

/// Constructor for a keyberon USB device.
pub fn new_device<B>(bus: &UsbBusAllocator<B>) -> usb_device::device::UsbDevice<'_, B>
where
B: usb_device::bus::UsbBus,
{
UsbDeviceBuilder::new(bus, UsbVidPid(VID, PID))
.strings(&[StringDescriptors::default()
.manufacturer("RIIR Task Force")
.product("Keyberon")
.serial_number(env!("CARGO_PKG_VERSION"))])
.expect("Failed to configure UsbDeviceBuilder")
.build()
}