Skip to content

Commit eaf9709

Browse files
haataeldruin
authored andcommitted
Fix Suspend state transition to go back to the previous state (#96)
- 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
1 parent 413b77c commit eaf9709

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
### Fixed
1111
* Fixed an issue where USB devices were not enumerating on Windows ([#32](https://github.com/rust-embedded-community/usb-device/issues/82))
1212
* Add optional support for defmt ([#76](https://github.com/rust-embedded-community/usb-device/pull/76))
13+
* 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))
1314

1415
...
1516

src/device.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub struct UsbDevice<'a, B: UsbBus> {
3838
device_state: UsbDeviceState,
3939
remote_wakeup_enabled: bool,
4040
self_powered: bool,
41+
suspended_device_state: Option<UsbDeviceState>,
4142
pending_address: u8,
4243
}
4344

@@ -98,6 +99,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
9899
device_state: UsbDeviceState::Default,
99100
remote_wakeup_enabled: false,
100101
self_powered: false,
102+
suspended_device_state: None,
101103
pending_address: 0,
102104
}
103105
}
@@ -169,7 +171,10 @@ impl<B: UsbBus> UsbDevice<'_, B> {
169171
}
170172
_ => {
171173
self.bus.resume();
172-
self.device_state = UsbDeviceState::Default;
174+
self.device_state = self
175+
.suspended_device_state
176+
.expect("Unknown state before suspend");
177+
self.suspended_device_state = None;
173178
}
174179
}
175180
}
@@ -273,6 +278,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
273278
PollResult::Resume => {}
274279
PollResult::Suspend => {
275280
self.bus.suspend();
281+
self.suspended_device_state = Some(self.device_state);
276282
self.device_state = UsbDeviceState::Suspend;
277283
}
278284
}
@@ -530,6 +536,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
530536
self.bus.reset();
531537

532538
self.device_state = UsbDeviceState::Default;
539+
self.suspended_device_state = None; // We may reset during Suspend
533540
self.remote_wakeup_enabled = false;
534541
self.pending_address = 0;
535542

0 commit comments

Comments
 (0)