From 303f09bbf8ef25b5e22ca344eb6a0a6fb5742826 Mon Sep 17 00:00:00 2001 From: Lotte Steenbrink Date: Mon, 24 Aug 2020 12:28:29 +0200 Subject: [PATCH] setup-stage.md: add values for DEVIC descriptor, clarify instructions --- embedded-workshop-book/src/setup-stage.md | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/embedded-workshop-book/src/setup-stage.md b/embedded-workshop-book/src/setup-stage.md index 4fb1fb6..8e3aa5a 100644 --- a/embedded-workshop-book/src/setup-stage.md +++ b/embedded-workshop-book/src/setup-stage.md @@ -21,23 +21,29 @@ Start with the GET_DESCRIPTOR request, which is described in detail in section 9 [usb_spec]: https://www.usb.org/document-library/usb-20-specification -The fields of a GET_DESCRIPTOR request are as follows: +We can recognize a GET_DESCRIPTOR request by the following properties: - `bmRequestType` is **0b10000000** -- `bRequest` is **6** (i.e. the GET_DESCRIPTOR Request Code, see table 9-4 in the USB spec) -- the high byte of `wValue` contains the descriptor type, whereas the low byte contains the descriptor index -- `wIndex` is set to 0 for our purposes +- `bRequest` is **6** (i.e. the GET_DESCRIPTOR Request Code, defined in table 9-4 in the USB spec) + +In this task, we only want to parse DEVICE descriptor requests. They have the following properties: + +- the descriptor type is **1** (i.e. DEVICE, defined in table 9-5 of the USB spec) +- the descriptor index is **0** +- the wIndex is **0** for our purposes +- ❗️you need to fetch the descriptor type from the high byte of `wValue`, and the descriptor index from the the low byte of `wValue` + You will also find this information in the `// TODO implement ...` comment in the `Request::parse()` function of `lib.rs` file. > NOTE: If you'd like to learn more, take a look at Section 9.4.3 Get Descriptor of the USB specification. To complete the task, proceed like this: -1. **Parse GET_DESCRIPTOR requests:** -Modify `Request::parse()` in `advanced/common/usb/src/lib.rs` to recognize a GET_DESCRIPTOR request so that the `get_descriptor_device` test passes. Note that the parser already handles SET_ADDRESS requests. +1. **Parse GET_DESCRIPTOR requests for DEVICE descriptors:** +Modify `Request::parse()` in `advanced/common/usb/src/lib.rs` to recognize a GET_DESCRIPTOR request of type DEVICE so that the `get_descriptor_device` test passes. Note that the parser already handles SET_ADDRESS requests. - remember the GET_DESCRIPTOR fields described at the start of this section - remember that you can define binary literals by prefixing them with `0b` - - you can use bit shifts (`>>`) and casts (`as u8`) to get the high/low bytes of a `u16` + - you can use bit shifts (`>>`) and casts (`as u8`) to get the high/low bytes of `wValue` See `advanced/common/usb/solution-get-descriptor-device.rs` for a solution.