diff options
| -rw-r--r-- | embassy-usb-hid/src/lib.rs | 5 | ||||
| -rw-r--r-- | examples/nrf/src/bin/usb_hid.rs | 40 |
2 files changed, 21 insertions, 24 deletions
diff --git a/embassy-usb-hid/src/lib.rs b/embassy-usb-hid/src/lib.rs index 527f014f2..e29d485f4 100644 --- a/embassy-usb-hid/src/lib.rs +++ b/embassy-usb-hid/src/lib.rs | |||
| @@ -169,8 +169,11 @@ pub struct ReportReader<'d, D: Driver<'d>, const N: usize> { | |||
| 169 | offset: usize, | 169 | offset: usize, |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
| 173 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 172 | pub enum ReadError { | 174 | pub enum ReadError { |
| 173 | BufferOverflow, | 175 | BufferOverflow, |
| 176 | Disabled, | ||
| 174 | Sync(Range<usize>), | 177 | Sync(Range<usize>), |
| 175 | } | 178 | } |
| 176 | 179 | ||
| @@ -179,6 +182,7 @@ impl From<embassy_usb::driver::ReadError> for ReadError { | |||
| 179 | use embassy_usb::driver::ReadError::*; | 182 | use embassy_usb::driver::ReadError::*; |
| 180 | match val { | 183 | match val { |
| 181 | BufferOverflow => ReadError::BufferOverflow, | 184 | BufferOverflow => ReadError::BufferOverflow, |
| 185 | Disabled => ReadError::Disabled, | ||
| 182 | } | 186 | } |
| 183 | } | 187 | } |
| 184 | } | 188 | } |
| @@ -227,6 +231,7 @@ impl<'d, D: Driver<'d>, const N: usize> ReportReader<'d, D, N> { | |||
| 227 | match self.read(&mut buf).await { | 231 | match self.read(&mut buf).await { |
| 228 | Ok(len) => { handler.set_report(ReportId::Out(0), &buf[0..len]); } | 232 | Ok(len) => { handler.set_report(ReportId::Out(0), &buf[0..len]); } |
| 229 | Err(ReadError::BufferOverflow) => warn!("Host sent output report larger than the configured maximum output report length ({})", N), | 233 | Err(ReadError::BufferOverflow) => warn!("Host sent output report larger than the configured maximum output report length ({})", N), |
| 234 | Err(ReadError::Disabled) => self.ep_out.wait_enabled().await, | ||
| 230 | Err(ReadError::Sync(_)) => unreachable!(), | 235 | Err(ReadError::Sync(_)) => unreachable!(), |
| 231 | } | 236 | } |
| 232 | } | 237 | } |
diff --git a/examples/nrf/src/bin/usb_hid.rs b/examples/nrf/src/bin/usb_hid.rs index 6ffb1fd40..741e234b6 100644 --- a/examples/nrf/src/bin/usb_hid.rs +++ b/examples/nrf/src/bin/usb_hid.rs | |||
| @@ -3,9 +3,6 @@ | |||
| 3 | #![feature(generic_associated_types)] | 3 | #![feature(generic_associated_types)] |
| 4 | #![feature(type_alias_impl_trait)] | 4 | #![feature(type_alias_impl_trait)] |
| 5 | 5 | ||
| 6 | #[path = "../example_common.rs"] | ||
| 7 | mod example_common; | ||
| 8 | |||
| 9 | use core::mem; | 6 | use core::mem; |
| 10 | use defmt::*; | 7 | use defmt::*; |
| 11 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| @@ -20,6 +17,9 @@ use embassy_usb_hid::{HidClass, ReportId, RequestHandler, State}; | |||
| 20 | use futures::future::join; | 17 | use futures::future::join; |
| 21 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; | 18 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; |
| 22 | 19 | ||
| 20 | use defmt_rtt as _; // global logger | ||
| 21 | use panic_probe as _; | ||
| 22 | |||
| 23 | #[embassy::main] | 23 | #[embassy::main] |
| 24 | async fn main(_spawner: Spawner, p: Peripherals) { | 24 | async fn main(_spawner: Spawner, p: Peripherals) { |
| 25 | let clock: pac::CLOCK = unsafe { mem::transmute(()) }; | 25 | let clock: pac::CLOCK = unsafe { mem::transmute(()) }; |
| @@ -81,30 +81,22 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 81 | 81 | ||
| 82 | // Do stuff with the class! | 82 | // Do stuff with the class! |
| 83 | let hid_fut = async { | 83 | let hid_fut = async { |
| 84 | let mut y: i8 = 5; | ||
| 84 | loop { | 85 | loop { |
| 85 | Timer::after(Duration::from_millis(500)).await; | 86 | Timer::after(Duration::from_millis(500)).await; |
| 86 | hid.input() | ||
| 87 | .serialize(&MouseReport { | ||
| 88 | buttons: 0, | ||
| 89 | x: 0, | ||
| 90 | y: 4, | ||
| 91 | wheel: 0, | ||
| 92 | pan: 0, | ||
| 93 | }) | ||
| 94 | .await | ||
| 95 | .unwrap(); | ||
| 96 | 87 | ||
| 97 | Timer::after(Duration::from_millis(500)).await; | 88 | y = -y; |
| 98 | hid.input() | 89 | let report = MouseReport { |
| 99 | .serialize(&MouseReport { | 90 | buttons: 0, |
| 100 | buttons: 0, | 91 | x: 0, |
| 101 | x: 0, | 92 | y, |
| 102 | y: -4, | 93 | wheel: 0, |
| 103 | wheel: 0, | 94 | pan: 0, |
| 104 | pan: 0, | 95 | }; |
| 105 | }) | 96 | match hid.input().serialize(&report).await { |
| 106 | .await | 97 | Ok(()) => {} |
| 107 | .unwrap(); | 98 | Err(e) => warn!("Failed to send report: {:?}", e), |
| 99 | } | ||
| 108 | } | 100 | } |
| 109 | }; | 101 | }; |
| 110 | 102 | ||
