usb/hid: update for endpoint state changes.
This commit is contained in:
parent
fa9eadcee9
commit
6d514a0b31
@ -169,8 +169,11 @@ pub struct ReportReader<'d, D: Driver<'d>, const N: usize> {
|
|||||||
offset: usize,
|
offset: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub enum ReadError {
|
pub enum ReadError {
|
||||||
BufferOverflow,
|
BufferOverflow,
|
||||||
|
Disabled,
|
||||||
Sync(Range<usize>),
|
Sync(Range<usize>),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,6 +182,7 @@ impl From<embassy_usb::driver::ReadError> for ReadError {
|
|||||||
use embassy_usb::driver::ReadError::*;
|
use embassy_usb::driver::ReadError::*;
|
||||||
match val {
|
match val {
|
||||||
BufferOverflow => ReadError::BufferOverflow,
|
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 {
|
match self.read(&mut buf).await {
|
||||||
Ok(len) => { handler.set_report(ReportId::Out(0), &buf[0..len]); }
|
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::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!(),
|
Err(ReadError::Sync(_)) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,6 @@
|
|||||||
#![feature(generic_associated_types)]
|
#![feature(generic_associated_types)]
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
#[path = "../example_common.rs"]
|
|
||||||
mod example_common;
|
|
||||||
|
|
||||||
use core::mem;
|
use core::mem;
|
||||||
use defmt::*;
|
use defmt::*;
|
||||||
use embassy::executor::Spawner;
|
use embassy::executor::Spawner;
|
||||||
@ -20,6 +17,9 @@ use embassy_usb_hid::{HidClass, ReportId, RequestHandler, State};
|
|||||||
use futures::future::join;
|
use futures::future::join;
|
||||||
use usbd_hid::descriptor::{MouseReport, SerializedDescriptor};
|
use usbd_hid::descriptor::{MouseReport, SerializedDescriptor};
|
||||||
|
|
||||||
|
use defmt_rtt as _; // global logger
|
||||||
|
use panic_probe as _;
|
||||||
|
|
||||||
#[embassy::main]
|
#[embassy::main]
|
||||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||||
let clock: pac::CLOCK = unsafe { mem::transmute(()) };
|
let clock: pac::CLOCK = unsafe { mem::transmute(()) };
|
||||||
@ -81,30 +81,22 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
|
|
||||||
// Do stuff with the class!
|
// Do stuff with the class!
|
||||||
let hid_fut = async {
|
let hid_fut = async {
|
||||||
|
let mut y: i8 = 5;
|
||||||
loop {
|
loop {
|
||||||
Timer::after(Duration::from_millis(500)).await;
|
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;
|
y = -y;
|
||||||
hid.input()
|
let report = MouseReport {
|
||||||
.serialize(&MouseReport {
|
buttons: 0,
|
||||||
buttons: 0,
|
x: 0,
|
||||||
x: 0,
|
y,
|
||||||
y: -4,
|
wheel: 0,
|
||||||
wheel: 0,
|
pan: 0,
|
||||||
pan: 0,
|
};
|
||||||
})
|
match hid.input().serialize(&report).await {
|
||||||
.await
|
Ok(()) => {}
|
||||||
.unwrap();
|
Err(e) => warn!("Failed to send report: {:?}", e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user