Skip to content

Commit

Permalink
Add a constant for the HID class.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinling committed Oct 22, 2024
1 parent 71e32ad commit 6a7ee56
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/usb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ impl EndpointAttr {
}

impl ClassId {
pub const HID: ClassId = ClassId(0x03);

pub fn name(self) -> &'static str {
usb_ids::Class::from_id(self.0)
.map_or("Unknown", usb_ids::Class::name)
Expand Down Expand Up @@ -594,10 +596,10 @@ impl DescriptorType {
}

pub fn description_with_class(&self, class: ClassId) -> String {
if let (DescriptorType::Class(code), ClassId(class)) = (self, class) {
if let DescriptorType::Class(code) = self {
let description = match (class, code) {
(0x03, 0x21) => "HID descriptor",
(0x03, 0x22) => "HID report descriptor",
(ClassId::HID, 0x21) => "HID descriptor",
(ClassId::HID, 0x22) => "HID report descriptor",
_ => return self.description()
};
description.to_string()
Expand Down

0 comments on commit 6a7ee56

Please sign in to comment.