Remote wakeup bug fixes
This commit is contained in:
parent
3a30b08936
commit
7fde3abd5d
@ -171,21 +171,21 @@ impl<'d, D: Driver<'d>, M: RawMutex> UsbDevice<'d, D, M> {
|
|||||||
h.reset();
|
h.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(h) = &mut self.handler {
|
if let Some(h) = &self.handler {
|
||||||
h.reset();
|
h.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Resume => {
|
Event::Resume => {
|
||||||
trace!("usb: resume");
|
trace!("usb: resume");
|
||||||
self.suspended = false;
|
self.suspended = false;
|
||||||
if let Some(h) = &mut self.handler {
|
if let Some(h) = &self.handler {
|
||||||
h.suspended(false);
|
h.suspended(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Suspend => {
|
Event::Suspend => {
|
||||||
trace!("usb: suspend");
|
trace!("usb: suspend");
|
||||||
self.suspended = true;
|
self.suspended = true;
|
||||||
if let Some(h) = &mut self.handler {
|
if let Some(h) = &self.handler {
|
||||||
h.suspended(true);
|
h.suspended(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,19 +200,25 @@ impl<'d, D: Driver<'d>, M: RawMutex> UsbDevice<'d, D, M> {
|
|||||||
trace!("usb: disable");
|
trace!("usb: disable");
|
||||||
self.bus.disable();
|
self.bus.disable();
|
||||||
self.device_state = UsbDeviceState::Disabled;
|
self.device_state = UsbDeviceState::Disabled;
|
||||||
if let Some(h) = &mut self.handler {
|
if let Some(h) = &self.handler {
|
||||||
h.disabled();
|
h.disabled();
|
||||||
}
|
}
|
||||||
self.wait_for_enable().await;
|
self.wait_for_enable().await;
|
||||||
}
|
}
|
||||||
DeviceCommand::RemoteWakeup => {
|
DeviceCommand::RemoteWakeup => {
|
||||||
if self.remote_wakeup_enabled {
|
trace!("usb: remote wakeup");
|
||||||
|
if self.suspended && self.remote_wakeup_enabled {
|
||||||
match self.bus.remote_wakeup().await {
|
match self.bus.remote_wakeup().await {
|
||||||
Ok(()) => (),
|
Ok(()) => {
|
||||||
|
self.suspended = false;
|
||||||
|
if let Some(h) = &self.handler {
|
||||||
|
h.suspended(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(Unsupported) => warn!("Remote wakeup is unsupported!"),
|
Err(Unsupported) => warn!("Remote wakeup is unsupported!"),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn!("Remote wakeup not enabled.");
|
warn!("Remote wakeup requested when not enabled or not suspended.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -250,14 +256,14 @@ impl<'d, D: Driver<'d>, M: RawMutex> UsbDevice<'d, D, M> {
|
|||||||
(RequestType::Standard, Recipient::Device) => match (req.request, req.value) {
|
(RequestType::Standard, Recipient::Device) => match (req.request, req.value) {
|
||||||
(Request::CLEAR_FEATURE, Request::FEATURE_DEVICE_REMOTE_WAKEUP) => {
|
(Request::CLEAR_FEATURE, Request::FEATURE_DEVICE_REMOTE_WAKEUP) => {
|
||||||
self.remote_wakeup_enabled = false;
|
self.remote_wakeup_enabled = false;
|
||||||
if let Some(h) = &mut self.handler {
|
if let Some(h) = &self.handler {
|
||||||
h.remote_wakeup_enabled(false);
|
h.remote_wakeup_enabled(false);
|
||||||
}
|
}
|
||||||
self.control.accept(stage)
|
self.control.accept(stage)
|
||||||
}
|
}
|
||||||
(Request::SET_FEATURE, Request::FEATURE_DEVICE_REMOTE_WAKEUP) => {
|
(Request::SET_FEATURE, Request::FEATURE_DEVICE_REMOTE_WAKEUP) => {
|
||||||
self.remote_wakeup_enabled = true;
|
self.remote_wakeup_enabled = true;
|
||||||
if let Some(h) = &mut self.handler {
|
if let Some(h) = &self.handler {
|
||||||
h.remote_wakeup_enabled(true);
|
h.remote_wakeup_enabled(true);
|
||||||
}
|
}
|
||||||
self.control.accept(stage)
|
self.control.accept(stage)
|
||||||
@ -266,7 +272,7 @@ impl<'d, D: Driver<'d>, M: RawMutex> UsbDevice<'d, D, M> {
|
|||||||
self.pending_address = addr as u8;
|
self.pending_address = addr as u8;
|
||||||
self.bus.set_device_address(self.pending_address);
|
self.bus.set_device_address(self.pending_address);
|
||||||
self.device_state = UsbDeviceState::Addressed;
|
self.device_state = UsbDeviceState::Addressed;
|
||||||
if let Some(h) = &mut self.handler {
|
if let Some(h) = &self.handler {
|
||||||
h.addressed(self.pending_address);
|
h.addressed(self.pending_address);
|
||||||
}
|
}
|
||||||
self.control.accept(stage)
|
self.control.accept(stage)
|
||||||
@ -274,7 +280,7 @@ impl<'d, D: Driver<'d>, M: RawMutex> UsbDevice<'d, D, M> {
|
|||||||
(Request::SET_CONFIGURATION, CONFIGURATION_VALUE_U16) => {
|
(Request::SET_CONFIGURATION, CONFIGURATION_VALUE_U16) => {
|
||||||
self.device_state = UsbDeviceState::Configured;
|
self.device_state = UsbDeviceState::Configured;
|
||||||
self.bus.set_configured(true);
|
self.bus.set_configured(true);
|
||||||
if let Some(h) = &mut self.handler {
|
if let Some(h) = &self.handler {
|
||||||
h.configured(true);
|
h.configured(true);
|
||||||
}
|
}
|
||||||
self.control.accept(stage)
|
self.control.accept(stage)
|
||||||
@ -284,7 +290,7 @@ impl<'d, D: Driver<'d>, M: RawMutex> UsbDevice<'d, D, M> {
|
|||||||
_ => {
|
_ => {
|
||||||
self.device_state = UsbDeviceState::Addressed;
|
self.device_state = UsbDeviceState::Addressed;
|
||||||
self.bus.set_configured(false);
|
self.bus.set_configured(false);
|
||||||
if let Some(h) = &mut self.handler {
|
if let Some(h) = &self.handler {
|
||||||
h.configured(false);
|
h.configured(false);
|
||||||
}
|
}
|
||||||
self.control.accept(stage)
|
self.control.accept(stage)
|
||||||
|
@ -121,20 +121,20 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
|
|
||||||
if SUSPENDED.load(Ordering::Acquire) {
|
if SUSPENDED.load(Ordering::Acquire) {
|
||||||
info!("Triggering remote wakeup");
|
info!("Triggering remote wakeup");
|
||||||
USB_COMMANDS.send(DeviceCommand::RemoteWakeup);
|
USB_COMMANDS.send(DeviceCommand::RemoteWakeup).await;
|
||||||
|
} else {
|
||||||
|
let report = KeyboardReport {
|
||||||
|
keycodes: [4, 0, 0, 0, 0, 0],
|
||||||
|
leds: 0,
|
||||||
|
modifier: 0,
|
||||||
|
reserved: 0,
|
||||||
|
};
|
||||||
|
match hid_in.serialize(&report).await {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(e) => warn!("Failed to send report: {:?}", e),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let report = KeyboardReport {
|
|
||||||
keycodes: [4, 0, 0, 0, 0, 0],
|
|
||||||
leds: 0,
|
|
||||||
modifier: 0,
|
|
||||||
reserved: 0,
|
|
||||||
};
|
|
||||||
match hid_in.serialize(&report).await {
|
|
||||||
Ok(()) => {}
|
|
||||||
Err(e) => warn!("Failed to send report: {:?}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
button.wait_for_high().await;
|
button.wait_for_high().await;
|
||||||
info!("RELEASED");
|
info!("RELEASED");
|
||||||
let report = KeyboardReport {
|
let report = KeyboardReport {
|
||||||
|
Loading…
Reference in New Issue
Block a user