aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-02-18 17:26:33 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-02-18 18:31:08 +0100
commitbaa0cd682aa219c4e16c6a7a8c3143931754ee01 (patch)
tree90ebc717abdefc00fdda948004ec44e96e303d2d /src
parent6ef3740665e3b0ec4e466dc2e4b23900700b2ab3 (diff)
downloadntw-baa0cd682aa219c4e16c6a7a8c3143931754ee01.tar.gz
ntw-baa0cd682aa219c4e16c6a7a8c3143931754ee01.tar.bz2
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.
Diffstat (limited to 'src')
-rw-r--r--src/hid.rs21
1 files changed, 3 insertions, 18 deletions
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<B: UsbBus, D: HidDevice> HidClass<'_, B, D> {
}
}
- fn get_report_descriptor(&self, index: u8, buf: &mut [u8]) -> usb_device::Result<usize> {
- 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<B>) {
let req = xfer.request();
let [report_type, report_id] = req.value.to_be_bytes();
@@ -202,9 +187,9 @@ impl<B: UsbBus, D: HidDevice> UsbClass<B> 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();
}
}
}