aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjstrickland <[email protected]>2023-12-13 10:17:07 -0500
committerdjstrickland <[email protected]>2023-12-13 10:17:07 -0500
commitd596a1091d25e89533d08a1f96678f1c1182dc40 (patch)
treef6b99f011af56ba66472eaf75fbd0a296fe781b6
parent915423fc63f209059a2242fbc3ad3b88d796514f (diff)
add `susependable` field to `embassy_usb::builder::Config`
- allow for optional override of `Suspend` event for a UsbDevice
-rw-r--r--embassy-usb/src/builder.rs10
-rw-r--r--embassy-usb/src/lib.rs8
2 files changed, 15 insertions, 3 deletions
diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs
index c4705d041..ebc1283e6 100644
--- a/embassy-usb/src/builder.rs
+++ b/embassy-usb/src/builder.rs
@@ -94,6 +94,15 @@ pub struct Config<'a> {
94 /// Default: 100mA 94 /// Default: 100mA
95 /// Max: 500mA 95 /// Max: 500mA
96 pub max_power: u16, 96 pub max_power: u16,
97
98 /// Allow the bus to be suspended.
99 ///
100 /// If set to `true`, the bus will put itself in the suspended state
101 /// when it receives a `driver::Event::Suspend` bus event. If you wish
102 /// to override this behavior, set this field to `false`.
103 ///
104 /// Default: `true`
105 pub suspendable: bool,
97} 106}
98 107
99impl<'a> Config<'a> { 108impl<'a> Config<'a> {
@@ -114,6 +123,7 @@ impl<'a> Config<'a> {
114 supports_remote_wakeup: false, 123 supports_remote_wakeup: false,
115 composite_with_iads: false, 124 composite_with_iads: false,
116 max_power: 100, 125 max_power: 100,
126 suspendable: true,
117 } 127 }
118 } 128 }
119} 129}
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs
index 241e33a78..ff3295871 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> {
471 } 471 }
472 Event::Suspend => { 472 Event::Suspend => {
473 trace!("usb: suspend"); 473 trace!("usb: suspend");
474 self.suspended = true; 474 if self.config.suspendable {
475 for h in &mut self.handlers { 475 self.suspended = true;
476 h.suspended(true); 476 for h in &mut self.handlers {
477 h.suspended(true);
478 }
477 } 479 }
478 } 480 }
479 Event::PowerDetected => { 481 Event::PowerDetected => {