mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2024-05-28 21:28:20 +00:00
respond to comments: ignore set_address for now
This commit is contained in:
parent
a72886059f
commit
2b3e9a73b7
|
@ -6,12 +6,11 @@ use dk::{
|
||||||
usbd::{self, Event},
|
usbd::{self, Event},
|
||||||
};
|
};
|
||||||
use panic_log as _; // panic handler
|
use panic_log as _; // panic handler
|
||||||
use usb::{Address, Descriptor, DeviceState, Request};
|
use usb::{Descriptor, Request};
|
||||||
|
|
||||||
#[rtic::app(device = dk)]
|
#[rtic::app(device = dk)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
struct Resources {
|
struct Resources {
|
||||||
state: DeviceState,
|
|
||||||
usbd: USBD,
|
usbd: USBD,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,22 +22,20 @@ const APP: () = {
|
||||||
|
|
||||||
init::LateResources {
|
init::LateResources {
|
||||||
usbd: board.usbd,
|
usbd: board.usbd,
|
||||||
state: DeviceState::Default,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = USBD, resources = [state, usbd])]
|
#[task(binds = USBD, resources = [usbd])]
|
||||||
fn main(cx: main::Context) {
|
fn main(cx: main::Context) {
|
||||||
let usbd = cx.resources.usbd;
|
let usbd = cx.resources.usbd;
|
||||||
let state = cx.resources.state; // used to store the device address sent by the host
|
|
||||||
|
|
||||||
while let Some(event) = usbd::next_event(usbd) {
|
while let Some(event) = usbd::next_event(usbd) {
|
||||||
on_event(usbd, state, event)
|
on_event(usbd, event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn on_event(usbd: &USBD, state: &mut DeviceState, event: Event) {
|
fn on_event(usbd: &USBD, event: Event) {
|
||||||
log::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
log::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
|
@ -78,24 +75,13 @@ fn on_event(usbd: &USBD, state: &mut DeviceState, event: Event) {
|
||||||
log::info!("Goal reached; move to the next section");
|
log::info!("Goal reached; move to the next section");
|
||||||
dk::exit()
|
dk::exit()
|
||||||
}
|
}
|
||||||
Request::SetAddress { address } => set_device_address(state, address),
|
Request::SetAddress { .. } => {
|
||||||
|
// On Mac OS you'll get this request before the GET_DESCRIPTOR request so we
|
||||||
|
// need to catch it here. We'll properly handle this request later
|
||||||
|
// but for now it's OK to do nothing.
|
||||||
|
},
|
||||||
_ => unreachable!(), // we don't handle any other Requests
|
_ => unreachable!(), // we don't handle any other Requests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_device_address(state: &mut DeviceState, address: Option<Address>) {
|
|
||||||
match state {
|
|
||||||
DeviceState::Default | DeviceState::Address(..) => {
|
|
||||||
if let Some(address) = address {
|
|
||||||
log::info!("SETUP: assigning device address {}", address);
|
|
||||||
*state = DeviceState::Address(address);
|
|
||||||
} else {
|
|
||||||
log::info!("SETUP: address was None; assigning Default");
|
|
||||||
*state = DeviceState::Default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DeviceState::Configured { .. } => panic!(), // unspecified behavior
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -60,20 +60,24 @@ fn on_event(_usbd: &USBD, event: Event) {
|
||||||
wvalue
|
wvalue
|
||||||
);
|
);
|
||||||
|
|
||||||
// FIXME modify `advanced/common/usb` to make this work
|
// TODO modify `advanced/common/usb` to make this work
|
||||||
if let Ok(Request::GetDescriptor { descriptor, length }) =
|
let request = Request::parse(bmrequesttype, brequest, wvalue, windex, wlength)
|
||||||
Request::parse(bmrequesttype, brequest, wvalue, windex, wlength)
|
.expect("Error parsing request");
|
||||||
{
|
match request {
|
||||||
match descriptor {
|
Request::GetDescriptor { descriptor, length }
|
||||||
Descriptor::Device => {
|
if descriptor == Descriptor::Device =>
|
||||||
log::info!("GET_DESCRIPTOR Device [length={}]", length);
|
{
|
||||||
|
log::info!("GET_DESCRIPTOR Device [length={}]", length);
|
||||||
|
|
||||||
log::info!("Goal reached; move to the next section");
|
log::info!("Goal reached; move to the next section");
|
||||||
dk::exit()
|
dk::exit()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
Request::SetAddress { .. } => {
|
||||||
unreachable!() // don't care about this for now
|
// On Mac OS you'll get this request before the GET_DESCRIPTOR request so we
|
||||||
|
// need to catch it here. We'll properly handle this request later
|
||||||
|
// but for now it's OK to do nothing.
|
||||||
|
},
|
||||||
|
_ => unreachable!(), // we don't handle any other Requests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue