services/usb-device-xous: use an Option rather than bool+slice when returning a report message

This commit is contained in:
Gianguido Sora 2023-12-29 18:37:45 +01:00
parent 81772377e5
commit fe7678cff3
2 changed files with 10 additions and 16 deletions

View file

@ -174,6 +174,5 @@ impl Default for HIDReport {
#[derive(Debug, Default, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
pub struct HIDReportMessage {
pub data: HIDReport,
pub has_data: bool,
pub data: Option<HIDReport>,
}

View file

@ -1463,7 +1463,9 @@ pub(crate) fn main_hw() -> ! {
};
let data = buffer.to_original::<HIDReportDescriptorMessage, _>().unwrap();
// TODO(gsora): do something with the error
// This branch can only error if data.descriptor is longer than the
// expected maximum.
// The userland library checks this for us already.
match hidv2.set_device_report(Vec::from(&data.descriptor[..data.len])) {
Ok(_) => (),
Err(error) => {
@ -1472,31 +1474,24 @@ pub(crate) fn main_hw() -> ! {
}
}
Some(Opcode::HIDUnsetDescriptor) => {
// TODO(gsora): do something with the error
match hidv2.reset_device_report() {
Ok(_) => (),
Err(error) => log::error!("cannot reset hidv2 device report: {:?}", error),
}
}
Some(Opcode::HIDReadReport) => {
if !hidv2.descriptor_set() {
log::warn!("trying to read a HID report with no descriptor set!");
continue
}
let mut buffer = unsafe {
Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap())
};
let mut data = buffer.to_original::<HIDReportMessage, _>().unwrap();
if !hidv2.descriptor_set() {
buffer.replace(HIDReportMessage::default()).expect("couldn't serialize return");
continue
} else {
match hidv2.read_report() {
Some(report) => {
data.data = report;
data.has_data = true;
}
_ => ()
}
}
data.data = hidv2.read_report();
buffer.replace(data).expect("couldn't serialize return");
},