usb/hid: update for endpoint state changes.

This commit is contained in:
Dario Nieuwenhuis 2022-04-06 02:18:39 +02:00
parent fa9eadcee9
commit 6d514a0b31
2 changed files with 21 additions and 24 deletions

View file

@ -169,8 +169,11 @@ pub struct ReportReader<'d, D: Driver<'d>, const N: usize> {
offset: usize,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ReadError {
BufferOverflow,
Disabled,
Sync(Range<usize>),
}
@ -179,6 +182,7 @@ impl From<embassy_usb::driver::ReadError> for ReadError {
use embassy_usb::driver::ReadError::*;
match val {
BufferOverflow => ReadError::BufferOverflow,
Disabled => ReadError::Disabled,
}
}
}
@ -227,6 +231,7 @@ impl<'d, D: Driver<'d>, const N: usize> ReportReader<'d, D, N> {
match self.read(&mut buf).await {
Ok(len) => { handler.set_report(ReportId::Out(0), &buf[0..len]); }
Err(ReadError::BufferOverflow) => warn!("Host sent output report larger than the configured maximum output report length ({})", N),
Err(ReadError::Disabled) => self.ep_out.wait_enabled().await,
Err(ReadError::Sync(_)) => unreachable!(),
}
}

View file

@ -3,9 +3,6 @@
#![feature(generic_associated_types)]
#![feature(type_alias_impl_trait)]
#[path = "../example_common.rs"]
mod example_common;
use core::mem;
use defmt::*;
use embassy::executor::Spawner;
@ -20,6 +17,9 @@ use embassy_usb_hid::{HidClass, ReportId, RequestHandler, State};
use futures::future::join;
use usbd_hid::descriptor::{MouseReport, SerializedDescriptor};
use defmt_rtt as _; // global logger
use panic_probe as _;
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
let clock: pac::CLOCK = unsafe { mem::transmute(()) };
@ -81,30 +81,22 @@ async fn main(_spawner: Spawner, p: Peripherals) {
// Do stuff with the class!
let hid_fut = async {
let mut y: i8 = 5;
loop {
Timer::after(Duration::from_millis(500)).await;
hid.input()
.serialize(&MouseReport {
buttons: 0,
x: 0,
y: 4,
wheel: 0,
pan: 0,
})
.await
.unwrap();
Timer::after(Duration::from_millis(500)).await;
hid.input()
.serialize(&MouseReport {
y = -y;
let report = MouseReport {
buttons: 0,
x: 0,
y: -4,
y,
wheel: 0,
pan: 0,
})
.await
.unwrap();
};
match hid.input().serialize(&report).await {
Ok(()) => {}
Err(e) => warn!("Failed to send report: {:?}", e),
}
}
};