From d596a1091d25e89533d08a1f96678f1c1182dc40 Mon Sep 17 00:00:00 2001 From: djstrickland <96876452+dstric-aqueduct@users.noreply.github.com> Date: Wed, 13 Dec 2023 10:17:07 -0500 Subject: [PATCH 1/3] add `susependable` field to `embassy_usb::builder::Config` - allow for optional override of `Suspend` event for a UsbDevice --- embassy-usb/src/builder.rs | 10 ++++++++++ embassy-usb/src/lib.rs | 8 +++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index c4705d04..ebc1283e 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs @@ -94,6 +94,15 @@ pub struct Config<'a> { /// Default: 100mA /// Max: 500mA pub max_power: u16, + + /// Allow the bus to be suspended. + /// + /// If set to `true`, the bus will put itself in the suspended state + /// when it receives a `driver::Event::Suspend` bus event. If you wish + /// to override this behavior, set this field to `false`. + /// + /// Default: `true` + pub suspendable: bool, } impl<'a> Config<'a> { @@ -114,6 +123,7 @@ impl<'a> Config<'a> { supports_remote_wakeup: false, composite_with_iads: false, max_power: 100, + suspendable: true, } } } diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index 241e33a7..ff329587 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs @@ -471,9 +471,11 @@ impl<'d, D: Driver<'d>> Inner<'d, D> { } Event::Suspend => { trace!("usb: suspend"); - self.suspended = true; - for h in &mut self.handlers { - h.suspended(true); + if self.config.suspendable { + self.suspended = true; + for h in &mut self.handlers { + h.suspended(true); + } } } Event::PowerDetected => { From 6bf70e14fb14882ce6adf0d47179b7408bdcb184 Mon Sep 17 00:00:00 2001 From: djstrickland <96876452+dstric-aqueduct@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:50:13 -0500 Subject: [PATCH 2/3] Update usb.rs - add check of `dev_resume_from_host` interrupt register to catch wake event --- embassy-rp/src/usb.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs index 4ab881f6..4a74ee6f 100644 --- a/embassy-rp/src/usb.rs +++ b/embassy-rp/src/usb.rs @@ -363,7 +363,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { let siestatus = regs.sie_status().read(); let intrstatus = regs.intr().read(); - if siestatus.resume() { + if siestatus.resume() || intrstatus.dev_resume_from_host() { regs.sie_status().write(|w| w.set_resume(true)); return Poll::Ready(Event::Resume); } From a5379e708cab6e284a00f8b01e9db3d5c2eb400c Mon Sep 17 00:00:00 2001 From: djstrickland <96876452+dstric-aqueduct@users.noreply.github.com> Date: Sat, 16 Dec 2023 08:19:52 -0500 Subject: [PATCH 3/3] remove `suspendable` field from `embassy_usb::builder::Config` --- embassy-usb/src/builder.rs | 10 ---------- embassy-usb/src/lib.rs | 8 +++----- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index ebc1283e..c4705d04 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs @@ -94,15 +94,6 @@ pub struct Config<'a> { /// Default: 100mA /// Max: 500mA pub max_power: u16, - - /// Allow the bus to be suspended. - /// - /// If set to `true`, the bus will put itself in the suspended state - /// when it receives a `driver::Event::Suspend` bus event. If you wish - /// to override this behavior, set this field to `false`. - /// - /// Default: `true` - pub suspendable: bool, } impl<'a> Config<'a> { @@ -123,7 +114,6 @@ impl<'a> Config<'a> { supports_remote_wakeup: false, composite_with_iads: false, max_power: 100, - suspendable: true, } } } diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index ff329587..241e33a7 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs @@ -471,11 +471,9 @@ impl<'d, D: Driver<'d>> Inner<'d, D> { } Event::Suspend => { trace!("usb: suspend"); - if self.config.suspendable { - self.suspended = true; - for h in &mut self.handlers { - h.suspended(true); - } + self.suspended = true; + for h in &mut self.handlers { + h.suspended(true); } } Event::PowerDetected => {