mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
services/usb-device-xous: use an Option rather than bool+slice when returning a report message
This commit is contained in:
parent
81772377e5
commit
fe7678cff3
2 changed files with 10 additions and 16 deletions
|
|
@ -174,6 +174,5 @@ impl Default for HIDReport {
|
||||||
|
|
||||||
#[derive(Debug, Default, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
|
#[derive(Debug, Default, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
|
||||||
pub struct HIDReportMessage {
|
pub struct HIDReportMessage {
|
||||||
pub data: HIDReport,
|
pub data: Option<HIDReport>,
|
||||||
pub has_data: bool,
|
|
||||||
}
|
}
|
||||||
|
|
@ -1463,7 +1463,9 @@ pub(crate) fn main_hw() -> ! {
|
||||||
};
|
};
|
||||||
let data = buffer.to_original::<HIDReportDescriptorMessage, _>().unwrap();
|
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])) {
|
match hidv2.set_device_report(Vec::from(&data.descriptor[..data.len])) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
|
|
@ -1472,31 +1474,24 @@ pub(crate) fn main_hw() -> ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(Opcode::HIDUnsetDescriptor) => {
|
Some(Opcode::HIDUnsetDescriptor) => {
|
||||||
// TODO(gsora): do something with the error
|
|
||||||
match hidv2.reset_device_report() {
|
match hidv2.reset_device_report() {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(error) => log::error!("cannot reset hidv2 device report: {:?}", error),
|
Err(error) => log::error!("cannot reset hidv2 device report: {:?}", error),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(Opcode::HIDReadReport) => {
|
Some(Opcode::HIDReadReport) => {
|
||||||
|
if !hidv2.descriptor_set() {
|
||||||
|
log::warn!("trying to read a HID report with no descriptor set!");
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
let mut buffer = unsafe {
|
let mut buffer = unsafe {
|
||||||
Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap())
|
Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap())
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut data = buffer.to_original::<HIDReportMessage, _>().unwrap();
|
let mut data = buffer.to_original::<HIDReportMessage, _>().unwrap();
|
||||||
|
|
||||||
if !hidv2.descriptor_set() {
|
data.data = hidv2.read_report();
|
||||||
buffer.replace(HIDReportMessage::default()).expect("couldn't serialize return");
|
|
||||||
continue
|
|
||||||
} else {
|
|
||||||
match hidv2.read_report() {
|
|
||||||
Some(report) => {
|
|
||||||
data.data = report;
|
|
||||||
data.has_data = true;
|
|
||||||
}
|
|
||||||
_ => ()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.replace(data).expect("couldn't serialize return");
|
buffer.replace(data).expect("couldn't serialize return");
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue