Skip to content

Commit

Permalink
Fix Suspend state transition to go back to the previous state (#96)
Browse files Browse the repository at this point in the history
- Per (https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-11100-32-bit%20Cortex-M4-Microcontroller-SAM4S_Datasheet.pdf; 40.6.3 page 1042), the state transition from Suspend should go back to the previous state
- Previously Suspend would always transition back to Default state
  • Loading branch information
haata committed Jun 10, 2022
1 parent 413b77c commit 4bda63a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
* Fixed an issue where USB devices were not enumerating on Windows ([#32](https://github.com/rust-embedded-community/usb-device/issues/82))
* Add optional support for defmt ([#76](https://github.com/rust-embedded-community/usb-device/pull/76))
* Fixed Suspend state transition so it goes back to the previous state, not just Default ([#97](https://github.com/rust-embedded-community/usb-device/pull/97))

...

Expand Down
8 changes: 7 additions & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct UsbDevice<'a, B: UsbBus> {
device_state: UsbDeviceState,
remote_wakeup_enabled: bool,
self_powered: bool,
suspended_device_state: Option<UsbDeviceState>,
pending_address: u8,
}

Expand Down Expand Up @@ -98,6 +99,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
device_state: UsbDeviceState::Default,
remote_wakeup_enabled: false,
self_powered: false,
suspended_device_state: None,
pending_address: 0,
}
}
Expand Down Expand Up @@ -169,7 +171,10 @@ impl<B: UsbBus> UsbDevice<'_, B> {
}
_ => {
self.bus.resume();
self.device_state = UsbDeviceState::Default;
self.device_state = self
.suspended_device_state
.expect("Unknown state before suspend");
self.suspended_device_state = None;
}
}
}
Expand Down Expand Up @@ -273,6 +278,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
PollResult::Resume => {}
PollResult::Suspend => {
self.bus.suspend();
self.suspended_device_state = Some(self.device_state);
self.device_state = UsbDeviceState::Suspend;
}
}
Expand Down

0 comments on commit 4bda63a

Please sign in to comment.