diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-03-30 02:01:09 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-04-06 05:38:11 +0200 |
| commit | a435d78cf78deb1a93682d9ff2632706eaa1b951 (patch) | |
| tree | 580f4ac3aba6ede0a3021982c9725a6d3055b251 /embassy-usb/src/lib.rs | |
| parent | 60d3d111972f462c1f38d1d4fd27e89713974fc6 (diff) | |
usb: cleanup and simplify error handling.
Diffstat (limited to 'embassy-usb/src/lib.rs')
| -rw-r--r-- | embassy-usb/src/lib.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index 2287267b6..32b67a766 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs | |||
| @@ -158,7 +158,13 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | |||
| 158 | 158 | ||
| 159 | // If the request has a data state, we must read it. | 159 | // If the request has a data state, we must read it. |
| 160 | let data = if req.length > 0 { | 160 | let data = if req.length > 0 { |
| 161 | let size = self.control.data_out(self.control_buf).await.unwrap(); | 161 | let size = match self.control.data_out(self.control_buf).await { |
| 162 | Ok(size) => size, | ||
| 163 | Err(_) => { | ||
| 164 | warn!("usb: failed to read CONTROL OUT data stage."); | ||
| 165 | return; | ||
| 166 | } | ||
| 167 | }; | ||
| 162 | &self.control_buf[0..size] | 168 | &self.control_buf[0..size] |
| 163 | } else { | 169 | } else { |
| 164 | &[] | 170 | &[] |
| @@ -311,7 +317,6 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | |||
| 311 | if index == 0 { | 317 | if index == 0 { |
| 312 | self.control_in_accept_writer(req, |w| { | 318 | self.control_in_accept_writer(req, |w| { |
| 313 | w.write(descriptor_type::STRING, &lang_id::ENGLISH_US.to_le_bytes()) | 319 | w.write(descriptor_type::STRING, &lang_id::ENGLISH_US.to_le_bytes()) |
| 314 | .unwrap(); | ||
| 315 | }) | 320 | }) |
| 316 | .await | 321 | .await |
| 317 | } else { | 322 | } else { |
| @@ -328,8 +333,7 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | |||
| 328 | }; | 333 | }; |
| 329 | 334 | ||
| 330 | if let Some(s) = s { | 335 | if let Some(s) = s { |
| 331 | self.control_in_accept_writer(req, |w| w.string(s).unwrap()) | 336 | self.control_in_accept_writer(req, |w| w.string(s)).await; |
| 332 | .await; | ||
| 333 | } else { | 337 | } else { |
| 334 | self.control.reject() | 338 | self.control.reject() |
| 335 | } | 339 | } |
