diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-04-06 02:18:39 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-04-06 05:38:11 +0200 |
| commit | 6d514a0b31a6e480d00a36132ccd41bebfd246cc (patch) | |
| tree | 07858cb1bc48c81a4b908b5aa345d46ea5b2a650 /examples/nrf/src | |
| parent | fa9eadcee9cbac369195fd1356ec69ecdeda2f08 (diff) | |
usb/hid: update for endpoint state changes.
Diffstat (limited to 'examples/nrf/src')
| -rw-r--r-- | examples/nrf/src/bin/usb_hid.rs | 40 |
1 files changed, 16 insertions, 24 deletions
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 | ||
