Switch to ControlHandler owned bufs for control_in()

This commit is contained in:
alexmoon
2022-03-28 20:10:13 -04:00
committed by Dario Nieuwenhuis
parent a22639ad92
commit c53bb7394a
3 changed files with 15 additions and 17 deletions

View File

@ -133,8 +133,8 @@ pub enum OutResponse {
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum InResponse {
Accepted(usize),
pub enum InResponse<'a> {
Accepted(&'a [u8]),
Rejected,
}
@ -164,8 +164,7 @@ pub trait ControlHandler {
/// # Arguments
///
/// * `req` - The request from the SETUP packet.
/// * `resp` - The buffer for you to write the response.
fn control_in(&mut self, req: Request, resp: &mut [u8]) -> InResponse {
fn control_in(&mut self, req: Request) -> InResponse<'_> {
InResponse::Rejected
}
}

View File

@ -284,13 +284,10 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> {
.find(|(i, _)| req.index == *i as _)
.map(|(_, h)| h);
match handler {
Some(handler) => {
let mut buf = [0; 128];
match handler.control_in(req, &mut buf) {
InResponse::Accepted(len) => self.control.accept_in(&buf[..len]).await,
InResponse::Rejected => self.control.reject(),
}
}
Some(handler) => match handler.control_in(req) {
InResponse::Accepted(data) => self.control.accept_in(data).await,
InResponse::Rejected => self.control.reject(),
},
None => self.control.reject(),
}
}