1use crate::hid::{CollectionType, InputFlags, OutputFeatureFlags, Unit};
7use crate::id::usage::UsagePage;
8use crate::item::usage::{ExtendedUsage, Usage};
9
10pub mod usage;
11
12#[derive(Clone)]
14#[cfg_attr(feature = "std", derive(Debug))]
15pub enum Item {
16 Long(LongItem),
22 Main(Main),
27 Global(Global),
29 Local(Local),
31 Reserved(u8),
35}
36
37impl Item {
38 #[cfg(feature = "std")]
39 pub fn type_note(&self) -> &'static str {
41 match self {
42 Item::Long(_) => "[long]",
43 Item::Main(_) => "[main]",
44 Item::Global(_) => "[global]",
45 Item::Local(_) => "[local]",
46 Item::Reserved(_) => "[reserved]",
47 }
48 }
49}
50
51#[derive(Clone)]
56#[cfg_attr(feature = "std", derive(Debug))]
57pub enum Main {
58 Input(InputFlags),
60 Output(OutputFeatureFlags),
62 Feature(OutputFeatureFlags),
64 Collection(CollectionType),
66 EndCollection,
68 Reserved(u8),
70}
71
72#[derive(Clone)]
74#[cfg_attr(feature = "std", derive(Debug))]
75pub enum Global {
76 UsagePage(UsagePage),
81 LogicalMinimum(i32),
83 LogicalMaximum(i32),
85 PhysicalMinimum(i32),
87 PhysicalMaximum(i32),
89 UnitExponent(i32),
91 Unit(Unit),
93 ReportSize(u32),
95 ReportId(u32),
97 ReportCount(u32),
99 Push,
101 Pop,
103 Reserved(u8),
105}
106
107#[derive(Clone)]
109#[cfg_attr(feature = "std", derive(Debug))]
110pub enum Local {
111 Usage(Usage),
113 ExtendedUsage(ExtendedUsage),
115 UsageMinimum(u32),
117 UsageMaximum(u32),
119 DesignatorIndex(u32),
121 DesignatorMinimum(u32),
123 DesignatorMaximum(u32),
125 StringIndex(u32),
127 StringMinimum(u32),
129 StringMaximum(u32),
131 Delimiter(bool),
133 Reserved(u8),
135}
136
137#[derive(Clone)]
143#[cfg_attr(feature = "std", derive(Debug))]
144#[expect(missing_docs)]
145pub struct LongItem {
146 pub tag: u8,
147 #[cfg(feature = "std")]
148 pub data: std::vec::Vec<u8>,
149}
150
151#[cfg(feature = "std")]
152mod std_impls {
153 use std::fmt::{self, Display};
154
155 use super::*;
156
157 impl Display for Item {
158 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
159 match self {
160 Item::Long(item) => {
161 write!(f, "tag {:#04x} [{} bytes]", item.tag, item.data.len())
162 }
163 Item::Main(item) => {
164 write!(f, "{item}")
165 }
166 Item::Global(item) => {
167 write!(f, "{item}")
168 }
169 Item::Local(item) => write!(f, "{item}"),
170 Item::Reserved(ty) => write!(f, "reserved type {ty}"),
171 }
172 }
173 }
174
175 impl Display for Main {
176 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
177 match self {
178 Main::Input(flags) => {
179 write!(f, "Input: {flags:?}")
180 }
181 Main::Output(flags) => {
182 write!(f, "Output: {flags:?}")
183 }
184 Main::Feature(flags) => {
185 write!(f, "Feature: {flags:?}")
186 }
187 Main::Collection(coll) => {
188 write!(f, "Collection: {coll:?}")
189 }
190 Main::EndCollection => {
191 write!(f, "EndCollection")
192 }
193 Main::Reserved(tag) => {
194 write!(f, "Reserved tag {tag:#04X}")
195 }
196 }
197 }
198 }
199
200 impl Display for Global {
201 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
202 match self {
203 Global::UsagePage(page) => {
204 write!(f, "Usage Page: {page:?}")
205 }
206 Global::LogicalMinimum(value) => write!(f, "Logical Minimum: {value}"),
207 Global::LogicalMaximum(value) => write!(f, "Logical Maximum: {value}"),
208 Global::PhysicalMinimum(value) => write!(f, "Physical Minimum: {value}"),
209 Global::PhysicalMaximum(value) => write!(f, "Physical Maximum: {value}"),
210 Global::UnitExponent(value) => write!(f, "Unit Exponent: {value}"),
211 Global::Unit(unit) => write!(f, "Unit: {unit:?}"),
212 Global::Push => write!(f, "Push"),
213 Global::Pop => write!(f, "Pop"),
214 Global::Reserved(tag) => write!(f, "Reserved tag {tag:#04X}"),
215 Global::ReportSize(value) => write!(f, "Report Size: {value}"),
216 Global::ReportId(value) => write!(f, "Report ID: {value}"),
217 Global::ReportCount(value) => write!(f, "Report Count: {value}"),
218 }
219 }
220 }
221
222 impl Display for Local {
223 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
224 match self {
225 Local::Usage(usage) => {
226 write!(f, "Usage: {usage}")
227 }
228 Local::ExtendedUsage(extended_usage) => {
229 write!(f, "Extended Usage: {extended_usage:?}")
230 }
231 Local::UsageMinimum(value) => {
232 write!(f, "Usage Minimum: {value}")
233 }
234 Local::UsageMaximum(value) => {
235 write!(f, "Usage Maximum: {value}")
236 }
237 Local::DesignatorIndex(value) => write!(f, "Designator Index: {value}"),
238 Local::DesignatorMinimum(value) => write!(f, "Designator Minimum: {value}"),
239 Local::DesignatorMaximum(value) => write!(f, "Designator Maximum: {value}"),
240 Local::StringIndex(value) => write!(f, "String Index: {value}"),
241 Local::StringMinimum(value) => write!(f, "String Minimum: {value}"),
242 Local::StringMaximum(value) => write!(f, "String Maximum: {value}"),
243 Local::Delimiter(value) => write!(f, "Delimiter: {value}"),
244 Local::Reserved(tag) => write!(f, "Reserved tag {tag:#04X}"),
245 }
246 }
247 }
248}