Skip to content

Instantly share code, notes, and snippets.

@mvirkkunen
Last active February 1, 2020 23:14
Show Gist options
  • Save mvirkkunen/0bf4d29484cc0c0b61590b8c5eede35b to your computer and use it in GitHub Desktop.
Save mvirkkunen/0bf4d29484cc0c0b61590b8c5eede35b to your computer and use it in GitHub Desktop.
use stm32_usbd::UsbCore;
use usbd_serial::SerialPort;
usb usbd_hid::HidKeyboard;
// This macro generates a constructor (pub fn new) and all the required descriptors as a bunch of
// &'static [u8] at compile time.
//
// Problem: it needs complicated information from the crates that implement SerialPort and
// HidKeyboard and it doesn't seem to be feasible to access those from a procmacro (except via
// extremely sketchy and brittle hacks such as writing to temporary files or whatnot)
#[usb_device(
core=UsbCore,
vid=0x16c0,
pid=0x27db,
manufacturer="Nonexistent Company",
product="Sample device")]
struct MyDevice {
device: UsbDevice, // required
serial: SerialPort,
keyboard: HidKeyboard,
}
fn main() -> ! {
let peripherals = Peripherals::take();
let usb_core = PlatformUsbCore::new(peripherals.USB);
let { mut device, mut serial, mut keyboard } = MyDevice::new(usb_core);
loop {
device.poll();
serial.read(...);
keyboard.type(...);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment