diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-02-18 12:07:26 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-02-18 15:30:52 +0100 |
commit | ccbbf657743eb656f4e49b0204092b4450ffa7ba (patch) | |
tree | b0bec9a81a5f03743581ffb08585277dddafc3e3 /src/hid.rs | |
parent | a954a23e52a28cda7af669303f5e9404641b3b6c (diff) | |
download | ntw-ccbbf657743eb656f4e49b0204092b4450ffa7ba.tar.gz ntw-ccbbf657743eb656f4e49b0204092b4450ffa7ba.tar.bz2 |
Add HidDevice trait for device-specific information
The HID USB class needs device-specific information – currently, the
subclass and the protocol of the device, but also the report descriptors
and request handlers once we support these functions. Therefore, this
patch introduces the HidDevice trait that provides this data. It also
adds a Nitrokey struct that implements this trait for the Nitrokey Pro
device.
Diffstat (limited to 'src/hid.rs')
-rw-r--r-- | src/hid.rs | 28 |
1 files changed, 14 insertions, 14 deletions
@@ -26,31 +26,31 @@ enum_u8! { } } -pub struct HidClass<'a, B: UsbBus> { +pub trait HidDevice { + fn subclass(&self) -> Subclass; + + fn protocol(&self) -> Protocol; +} + +pub struct HidClass<'a, B: UsbBus, D: HidDevice> { + device: D, interface: InterfaceNumber, endpoint_interrupt_in: EndpointIn<'a, B>, expect_interrupt_in_complete: bool, - subclass: Subclass, - protocol: Protocol, } -impl<B: UsbBus> HidClass<'_, B> { - pub fn new( - alloc: &UsbBusAllocator<B>, - subclass: Subclass, - protocol: Protocol, - ) -> HidClass<'_, B> { +impl<B: UsbBus, D: HidDevice> HidClass<'_, B, D> { + pub fn new(device: D, alloc: &UsbBusAllocator<B>) -> HidClass<'_, B, D> { HidClass { + device, interface: alloc.interface(), endpoint_interrupt_in: alloc.interrupt(8, 10), expect_interrupt_in_complete: false, - subclass, - protocol, } } } -impl<B: UsbBus> UsbClass<B> for HidClass<'_, B> { +impl<B: UsbBus, D: HidDevice> UsbClass<B> for HidClass<'_, B, D> { fn poll(&mut self) {} fn reset(&mut self) { @@ -61,8 +61,8 @@ impl<B: UsbBus> UsbClass<B> for HidClass<'_, B> { writer.interface( self.interface, INTERFACE_CLASS_HID, - self.subclass.into(), - self.protocol.into(), + self.device.subclass().into(), + self.device.protocol().into(), )?; writer.endpoint(&self.endpoint_interrupt_in)?; |