Split usb_report_descriptor into usb_hid_{item,usage}
This is cleaner IMO. * usb_hid_item deals with parsing the report descriptor. * usb_hid_usage has tables that define each usage.
This commit is contained in:
63
usb_hid_usage/src/lib.rs
Normal file
63
usb_hid_usage/src/lib.rs
Normal file
@ -0,0 +1,63 @@
|
||||
//!
|
||||
//! ## References
|
||||
//!
|
||||
//! * <https://www.usb.org/sites/default/files/hut1_3_0.pdf>
|
||||
|
||||
#![no_std]
|
||||
|
||||
macro_rules! usage {
|
||||
{ [$page:literal] $($i:literal $v:ident)* } => {
|
||||
pub const PAGE: u16 = $page;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum Usage {
|
||||
$($v,)*
|
||||
}
|
||||
|
||||
impl TryFrom<u16> for Usage {
|
||||
type Error = super::UnknownUsage;
|
||||
|
||||
fn try_from(n: u16) -> Result<Self, Self::Error> {
|
||||
Ok(match n {
|
||||
$($i => Self::$v,)*
|
||||
_ => return Err(super::UnknownUsage),
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! page {
|
||||
{ $($v:ident $m:ident)* } => {
|
||||
$(pub mod $m;)*
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum UsagePage {
|
||||
$($v,)*
|
||||
}
|
||||
|
||||
impl TryFrom<u16> for UsagePage {
|
||||
type Error = UnknownPage;
|
||||
|
||||
fn try_from(n: u16) -> Result<Self, Self::Error> {
|
||||
Ok(match n {
|
||||
$($m::PAGE => Self::$v,)*
|
||||
_ => return Err(UnknownPage),
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
page! {
|
||||
GenericDesktop generic_desktop
|
||||
Button button
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UnknownUsage;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UnknownPage;
|
Reference in New Issue
Block a user