Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 917484a

Browse filesBrowse files
committed
Update examples in usb_hid_item README
1 parent 7768133 commit 917484a
Copy full SHA for 917484a

File tree

Expand file treeCollapse file tree

1 file changed

+20
-22
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+20
-22
lines changed

‎usb_hid_item/README.md

Copy file name to clipboard
+20-22Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
# HID report descriptor item parser
22

3-
## Example
3+
## Examples
44

5-
### Using items directly
6-
7-
```rs
8-
const QEMU_USB_TABLET: &[u8] = &[
9-
0x05, 0x01, 0x09, 0x02, 0xa1, 0x01, 0x09, 0x01, 0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29,
10-
0x03, 0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, 0x81, 0x02, 0x95, 0x01, 0x75, 0x05,
11-
0x81, 0x01, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x15, 0x00, 0x26, 0xff, 0x7f, 0x35, 0x00,
12-
0x46, 0xff, 0x7f, 0x75, 0x10, 0x95, 0x02, 0x81, 0x02, 0x05, 0x01, 0x09, 0x38, 0x15, 0x81,
13-
0x25, 0x7f, 0x35, 0x00, 0x45, 0x00, 0x75, 0x08, 0x95, 0x01, 0x81, 0x06, 0xc0, 0xc0,
14-
];
15-
16-
dbg!(usb_hid_item::parse(QEMU_USB_TABLET).collect::<Vec<_>>());
17-
```
18-
19-
### Using the tree parser
5+
### Using the default stateful parser
206

217
```rs
228
const QEMU_USB_TABLET: &[u8] = &[
@@ -39,21 +25,33 @@ let mut usages = Usages::new();
3925

4026
fn f(val: Value, fields: &mut Vec<(Usages, Field)>, usages: &mut Usages) {
4127
match val {
42-
Value::Collection(c) => {
43-
usages.clear();
44-
c.for_each(|c| f(val.unwrap(), fields, usages));
45-
}
28+
Value::Collection(_) | Value::EndCollection => usages.clear(),
4629
Value::Usage { page, ids } => usages.push((page, ids)),
4730
Value::Field(f) => fields.push((mem::take(usages), f)),
31+
Value::StackFrame(s) => s.for_each(|s| f(val.unwrap(), fields, usages)),
4832
}
4933
}
50-
usb_hid_item::tree::parse(data)
34+
usb_hid_item::parse(data)
5135
.iter()
52-
.for_each(|c| f(c.unwrap(), &mut fields, &mut usages));
36+
.for_each(|e| f(e.unwrap(), &mut fields, &mut usages));
5337

5438
dbg!(fields);
5539
```
5640

41+
### Using items directly
42+
43+
```rs
44+
const QEMU_USB_TABLET: &[u8] = &[
45+
0x05, 0x01, 0x09, 0x02, 0xa1, 0x01, 0x09, 0x01, 0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29,
46+
0x03, 0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, 0x81, 0x02, 0x95, 0x01, 0x75, 0x05,
47+
0x81, 0x01, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x15, 0x00, 0x26, 0xff, 0x7f, 0x35, 0x00,
48+
0x46, 0xff, 0x7f, 0x75, 0x10, 0x95, 0x02, 0x81, 0x02, 0x05, 0x01, 0x09, 0x38, 0x15, 0x81,
49+
0x25, 0x7f, 0x35, 0x00, 0x45, 0x00, 0x75, 0x08, 0x95, 0x01, 0x81, 0x06, 0xc0, 0xc0,
50+
];
51+
52+
dbg!(usb_hid_item::item::parse(QEMU_USB_TABLET).collect::<Vec<_>>());
53+
```
54+
5755
## References
5856

5957
* <https://www.usb.org/sites/default/files/hid1_11.pdf>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.