mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-10 16:25:37 +00:00
update log statements
This commit is contained in:
parent
901c0f7d2c
commit
d8ba808f78
5 changed files with 25 additions and 35 deletions
|
@ -1,5 +1,4 @@
|
|||
//! Some USB 2.0 data types
|
||||
// NOTE this is a partial solution to exercise `usb-2`
|
||||
|
||||
#![deny(missing_docs)]
|
||||
#![deny(warnings)]
|
||||
|
@ -51,33 +50,22 @@ impl Request {
|
|||
windex: u16,
|
||||
wlength: u16,
|
||||
) -> Result<Self, ()> {
|
||||
// Request Codes
|
||||
// see table 9-4 (USB specification)
|
||||
const SET_ADDRESS: u8 = 5;
|
||||
const GET_DESCRIPTOR: u8 = 6;
|
||||
|
||||
// TODO implement another branch handling GET_DESCRIPTOR requests:
|
||||
//
|
||||
// 1. get descriptor type and descriptor index from `wValue`
|
||||
//
|
||||
// 2. confirm that
|
||||
// - the descriptor type is DEVICE, i.e. of value 1 and
|
||||
// - the descriptor index is 0 (i.e. it is the first implemented descriptor for this type) and
|
||||
// - `wIndex` is 0 (i.e. no language ID since it's not a string descriptor)
|
||||
//
|
||||
// For more details, see https://embedded-trainings.ferrous-systems.com/setup-stage.html
|
||||
|
||||
if bmrequesttype == 0b10000000 && brequest == GET_DESCRIPTOR {
|
||||
// see table 9-5
|
||||
const DEVICE: u8 = 1;
|
||||
|
||||
// 1. get descriptor type and descriptor index from wValue
|
||||
let desc_ty = (wvalue >> 8) as u8;
|
||||
let desc_index = wvalue as u8;
|
||||
let langid = windex;
|
||||
|
||||
// 2. confirm that the descriptor
|
||||
// - is of type DEVICE and
|
||||
// - has descriptor index 0 (i.e. it is the first implemented descriptor for this type) and
|
||||
// - has wIndex 0 (i.e. no language ID since it's not a string descriptor)
|
||||
if desc_ty == DEVICE && desc_index == 0 && langid == 0 {
|
||||
Ok(Request::GetDescriptor {
|
||||
descriptor: Descriptor::Device,
|
||||
length: wlength,
|
||||
})
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
} else if bmrequesttype == 0b00000000 && brequest == SET_ADDRESS {
|
||||
if bmrequesttype == 0b00000000 && brequest == SET_ADDRESS {
|
||||
// Set the device address for all future accesses.
|
||||
// (Needed to successfully init when conected to Apple devices)
|
||||
// Section 9.4.6 Set Address of the USB specification explains which values for wvalue,
|
||||
|
@ -90,6 +78,7 @@ impl Request {
|
|||
Err(())
|
||||
}
|
||||
} else {
|
||||
defmt::println!("unhandled case in `Request` parser");
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
@ -207,5 +196,4 @@ mod tests {
|
|||
assert!(Request::parse(0b0000_0000, 0x09, 0x00_01, 0, 1).is_err());
|
||||
// ^
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -44,7 +44,7 @@ mod app {
|
|||
}
|
||||
|
||||
fn on_event(_usbd: &USBD, event: Event) {
|
||||
defmt::println!("USB: {:?} @ {:?}", event, dk::uptime());
|
||||
defmt::println!("USB: {} @ {}", event, dk::uptime());
|
||||
|
||||
match event {
|
||||
Event::UsbReset => todo!(),
|
||||
|
|
|
@ -42,7 +42,7 @@ mod app {
|
|||
}
|
||||
|
||||
fn on_event(usbd: &USBD, event: Event) {
|
||||
defmt::println!("USB: {:?} @ {:?}", event, dk::uptime());
|
||||
defmt::println!("USB: {} @ {}", event, dk::uptime());
|
||||
|
||||
match event {
|
||||
Event::UsbReset => {
|
||||
|
|
|
@ -47,7 +47,7 @@ mod app {
|
|||
}
|
||||
}
|
||||
fn on_event(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State, event: Event) {
|
||||
defmt::println!("USB: {:?} @ {:?}", event, dk::uptime());
|
||||
defmt::println!("USB: {} @ {}", event, dk::uptime());
|
||||
|
||||
match event {
|
||||
Event::UsbReset => {
|
||||
|
|
|
@ -72,12 +72,14 @@ modify `usb-2.rs` to read `USBD` registers and parse the SETUP data when an EP0S
|
|||
When you have successfully received a GET_DESCRIPTOR request for a Device descriptor you are done. You should see an output like this:
|
||||
|
||||
``` console
|
||||
INFO:usb_2 -- USB: UsbReset @ 438.842772ms
|
||||
INFO:usb_2 -- USB: UsbEp0Setup @ 514.984128ms
|
||||
...
|
||||
INFO:usb_2 -- SETUP: bmrequesttype: 128, brequest: 6, wlength: 64, windex: 0, wvalue: 256
|
||||
INFO:usb_2 -- GET_DESCRIPTOR Device [length=64]
|
||||
INFO:usb_2 -- Goal reached; move to the next section
|
||||
USB: UsbReset @ Duration { secs: 0, nanos: 361145018 }
|
||||
USB: UsbEp0Setup @ Duration { secs: 0, nanos: 402465820 }
|
||||
SETUP: bmrequesttype: 0, brequest: 5, wlength: 0, windex: 0, wvalue: 10
|
||||
USB: UsbEp0Setup @ Duration { secs: 0, nanos: 404754637 }
|
||||
SETUP: bmrequesttype: 128, brequest: 6, wlength: 8, windex: 0, wvalue: 256
|
||||
GET_DESCRIPTOR Device [length=8]
|
||||
Goal reached; move to the next section
|
||||
`dk::exit()` called; exiting ...
|
||||
```
|
||||
|
||||
> Note: `wlength` / `length` can vary depending on the OS, USB port (USB 2.0 vs USB 3.0) or the presence of a USB hub so you may see a different value.
|
||||
|
|
Loading…
Reference in a new issue