From baa0cd682aa219c4e16c6a7a8c3143931754ee01 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 18 Feb 2019 17:26:33 +0000 Subject: Simplify handling of GET_DESCRIPTOR requests Previously, we used the ControlIn::accept method and copied the generated buffer returned by HidDevice::report_descriptor to the buffer provided by usb_device::UsbClass in get_report_descriptor. But it is easier to directly pass the returned buffer to ControlIn::accept_with, so we drop the get_report_descriptor method. --- src/hid.rs | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/hid.rs b/src/hid.rs index 79ba7f0..48c683b 100644 --- a/src/hid.rs +++ b/src/hid.rs @@ -101,21 +101,6 @@ impl HidClass<'_, B, D> { } } - fn get_report_descriptor(&self, index: u8, buf: &mut [u8]) -> usb_device::Result { - if index == 0 { - let report_descriptor = self.device.report_descriptor(); - let len = report_descriptor.len(); - if len > buf.len() { - Err(UsbError::BufferOverflow) - } else { - buf[0..len].copy_from_slice(report_descriptor); - Ok(len) - } - } else { - Err(UsbError::InvalidState) - } - } - fn get_report(&mut self, xfer: ControlIn) { let req = xfer.request(); let [report_type, report_id] = req.value.to_be_bytes(); @@ -202,9 +187,9 @@ impl UsbClass for HidClass<'_, B, D> { (RequestType::Standard, Recipient::Interface) => { if req.request == control::Request::GET_DESCRIPTOR { let (dtype, index) = req.descriptor_type_index(); - if dtype == DescriptorType::Report.into() { - xfer.accept(|mut buf| self.get_report_descriptor(index, &mut buf)) - .ok(); + if dtype == DescriptorType::Report.into() && index == 0 { + let descriptor = self.device.report_descriptor(); + xfer.accept_with(descriptor).ok(); } } } -- cgit v1.2.3