1use crate::compat::input_id;
2use std::fmt;
3
4#[derive(Clone, Hash, Eq, PartialEq)]
5#[repr(transparent)]
6pub struct InputId(pub(crate) input_id);
7
8impl From<input_id> for InputId {
9 #[inline]
10 fn from(id: input_id) -> Self {
11 Self(id)
12 }
13}
14impl AsRef<input_id> for InputId {
15 #[inline]
16 fn as_ref(&self) -> &input_id {
17 &self.0
18 }
19}
20
21impl InputId {
22 pub fn bus_type(&self) -> BusType {
23 BusType(self.0.bustype)
24 }
25 pub fn vendor(&self) -> u16 {
26 self.0.vendor
27 }
28 pub fn product(&self) -> u16 {
29 self.0.product
30 }
31 pub fn version(&self) -> u16 {
32 self.0.version
33 }
34
35 pub fn new(bus_type: BusType, vendor: u16, product: u16, version: u16) -> Self {
37 Self::from(input_id {
38 bustype: bus_type.0,
39 vendor,
40 product,
41 version,
42 })
43 }
44}
45
46impl fmt::Debug for InputId {
47 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48 f.debug_struct("InputId")
49 .field("bus_type", &self.bus_type())
50 .field("vendor", &format_args!("{:#x}", self.vendor()))
51 .field("product", &format_args!("{:#x}", self.product()))
52 .field("version", &format_args!("{:#x}", self.version()))
53 .finish()
54 }
55}
56
57#[derive(Copy, Clone, PartialEq, Eq)]
59pub struct BusType(pub u16);
60
61evdev_enum!(
62 BusType,
63 BUS_PCI = 0x01,
64 BUS_ISAPNP = 0x02,
65 BUS_USB = 0x03,
66 BUS_HIL = 0x04,
67 BUS_BLUETOOTH = 0x05,
68 BUS_VIRTUAL = 0x06,
69 BUS_ISA = 0x10,
70 BUS_I8042 = 0x11,
71 BUS_XTKBD = 0x12,
72 BUS_RS232 = 0x13,
73 BUS_GAMEPORT = 0x14,
74 BUS_PARPORT = 0x15,
75 BUS_AMIGA = 0x16,
76 BUS_ADB = 0x17,
77 BUS_I2C = 0x18,
78 BUS_HOST = 0x19,
79 BUS_GSC = 0x1A,
80 BUS_ATARI = 0x1B,
81 BUS_SPI = 0x1C,
82 BUS_RMI = 0x1D,
83 BUS_CEC = 0x1E,
84 BUS_INTEL_ISHTP = 0x1F,
85);
86
87impl fmt::Display for BusType {
88 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
89 let s = match *self {
90 Self::BUS_PCI => "PCI",
91 Self::BUS_ISAPNP => "ISA Plug 'n Play",
92 Self::BUS_USB => "USB",
93 Self::BUS_HIL => "HIL",
94 Self::BUS_BLUETOOTH => "Bluetooth",
95 Self::BUS_VIRTUAL => "Virtual",
96 Self::BUS_ISA => "ISA",
97 Self::BUS_I8042 => "i8042",
98 Self::BUS_XTKBD => "XTKBD",
99 Self::BUS_RS232 => "RS232",
100 Self::BUS_GAMEPORT => "Gameport",
101 Self::BUS_PARPORT => "Parallel Port",
102 Self::BUS_AMIGA => "Amiga",
103 Self::BUS_ADB => "ADB",
104 Self::BUS_I2C => "I2C",
105 Self::BUS_HOST => "Host",
106 Self::BUS_GSC => "GSC",
107 Self::BUS_ATARI => "Atari",
108 Self::BUS_SPI => "SPI",
109 Self::BUS_RMI => "RMI",
110 Self::BUS_CEC => "CEC",
111 Self::BUS_INTEL_ISHTP => "Intel ISHTP",
112 _ => "Unknown",
113 };
114 f.write_str(s)
115 }
116}