From 4bda63aeec84b9d60b227f3c20dc4eb76af24bed Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Fri, 10 Jun 2022 12:11:37 -0700 Subject: [PATCH] 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 --- CHANGELOG.md | 1 + src/device.rs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfe438b..de615af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) ... diff --git a/src/device.rs b/src/device.rs index 5c9cf57..6d10546 100644 --- a/src/device.rs +++ b/src/device.rs @@ -38,6 +38,7 @@ pub struct UsbDevice<'a, B: UsbBus> { device_state: UsbDeviceState, remote_wakeup_enabled: bool, self_powered: bool, + suspended_device_state: Option, pending_address: u8, } @@ -98,6 +99,7 @@ impl UsbDevice<'_, B> { device_state: UsbDeviceState::Default, remote_wakeup_enabled: false, self_powered: false, + suspended_device_state: None, pending_address: 0, } } @@ -169,7 +171,10 @@ impl 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; } } } @@ -273,6 +278,7 @@ impl UsbDevice<'_, B> { PollResult::Resume => {} PollResult::Suspend => { self.bus.suspend(); + self.suspended_device_state = Some(self.device_state); self.device_state = UsbDeviceState::Suspend; } }