aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2019-07-28 09:38:10 -0400
committerBrian Cully <bjc@kublai.com>2019-07-28 09:38:10 -0400
commite832ef6cc3a14701b176450f9406f5d6ff7ae321 (patch)
treeca0f3ca61c8af44bb47d05ce2d38a4c133d762a3
parent35cfd10b6a22816dbf55fe960abf61986a746b1b (diff)
downloadsamd21-demo-e832ef6cc3a14701b176450f9406f5d6ff7ae321.tar.gz
samd21-demo-e832ef6cc3a14701b176450f9406f5d6ff7ae321.zip
Remove delay field from USBHost.
It was being used for FSM timings, so put it directly on the state discriminant if required.
-rwxr-xr-xusbh/src/lib.rs23
1 files changed, 11 insertions, 12 deletions
diff --git a/usbh/src/lib.rs b/usbh/src/lib.rs
index e15f279..b0a103a 100755
--- a/usbh/src/lib.rs
+++ b/usbh/src/lib.rs
@@ -38,9 +38,9 @@ enum DetachedState {
#[derive(Clone, Copy, Debug, PartialEq)]
enum AttachedState {
- WaitForSettle,
+ WaitForSettle(usize),
WaitResetComplete,
- WaitSOF,
+ WaitSOF(usize),
}
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -73,7 +73,6 @@ where
events: EventReader,
task_state: TaskState,
- delay: usize,
// Need chunk of RAM for USB pipes, which gets used with DESCADD
// register.
@@ -113,7 +112,6 @@ where
events: eventr,
task_state: TaskState::Detached(DetachedState::Initialize),
- delay: 0,
pipe_table: PipeTable::new(),
@@ -216,8 +214,9 @@ where
}
Event::Attached => {
if let TaskState::Detached(_) = self.task_state {
- self.delay = (self.millis)() + SETTLE_DELAY;
- TaskState::Attached(AttachedState::WaitForSettle)
+ TaskState::Attached(AttachedState::WaitForSettle(
+ (self.millis)() + SETTLE_DELAY,
+ ))
} else {
self.task_state
}
@@ -303,8 +302,8 @@ where
fn attached_fsm(&mut self, s: AttachedState) {
match s {
- AttachedState::WaitForSettle => {
- if (self.millis)() >= self.delay {
+ AttachedState::WaitForSettle(until) => {
+ if (self.millis)() >= until {
self.usb.host().ctrlb.modify(|_, w| w.busreset().set_bit());
self.task_state = TaskState::Attached(AttachedState::WaitResetComplete);
}
@@ -322,15 +321,15 @@ where
// immediately after reset according to ยง32.6.3.3.
self.usb.host().ctrlb.modify(|_, w| w.sofe().set_bit());
// USB spec requires 20ms of SOF after bus reset.
- self.delay = (self.millis)() + 20;
- self.task_state = TaskState::Attached(AttachedState::WaitSOF);
+ self.task_state =
+ TaskState::Attached(AttachedState::WaitSOF((self.millis)() + 20));
}
}
- AttachedState::WaitSOF => {
+ AttachedState::WaitSOF(until) => {
if self.usb.host().intflag.read().hsof().bit_is_set() {
self.usb.host().intflag.write(|w| w.hsof().set_bit());
- if (self.millis)() >= self.delay {
+ if (self.millis)() >= until {
self.task_state = TaskState::Steady(SteadyState::Configuring);
}
}