Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix facedancer unittests #203

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions firmware/lunasoc-hal/src/usb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ macro_rules! impl_usb {
// disable endpoint events
self.disable_events();

// un-prime all OUT endpoints and disable interface
for endpoint_number in 0..smolusb::EP_MAX_ENDPOINTS as u8 {
self.ep_out
.epno()
.write(|w| unsafe { w.epno().bits(endpoint_number) });
self.ep_out.prime().write(|w| w.prime().bit(false));
}
self.ep_out.enable().write(|w| w.enable().bit(false));

// reset FIFOs
self.ep_control.reset().write(|w| w.reset().bit(true));
self.ep_in.reset().write(|w| w.reset().bit(true));
Expand All @@ -180,6 +189,15 @@ macro_rules! impl_usb {
// disconnect device controller
self.controller.connect().write(|w| w.connect().bit(false));

// un-prime all OUT endpoints and disable interface
for endpoint_number in 0..smolusb::EP_MAX_ENDPOINTS as u8 {
self.ep_out
.epno()
.write(|w| unsafe { w.epno().bits(endpoint_number) });
self.ep_out.prime().write(|w| w.prime().bit(false));
}
self.ep_out.enable().write(|w| w.enable().bit(false));

// reset FIFOs
self.ep_control.reset().write(|w| w.reset().bit(true));
self.ep_in.reset().write(|w| w.reset().bit(true));
Expand Down
36 changes: 35 additions & 1 deletion firmware/moondancer/src/gcp/moondancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl Moondancer {
let direction = setup_packet.direction();
let request_type = setup_packet.request_type();
let request = setup_packet.request();

if matches!(
(direction, request_type, request),
(
Expand Down Expand Up @@ -586,6 +587,24 @@ impl Moondancer {
Ok([].into_iter())
}

pub fn ep_out_interface_enable(
&mut self,
_arguments: &[u8],
) -> GreatResult<impl Iterator<Item = u8>> {
// 0. clear receive fifo in case the previous transaction wasn't handled
if self.usb0.ep_out.have().read().have().bit() {
log::warn!("Re-enabling interface with unread data: Usb0");
self.usb0.ep_out.reset().write(|w| w.reset().bit(true));
}

// 1. re-enable ep_out interface
self.usb0.ep_out.enable().write(|w| w.enable().bit(true));

debug!("MD moondancer::ep_out_interface_enable()");

Ok([].into_iter())
}

pub fn write_control_endpoint(
&mut self,
arguments: &[u8],
Expand Down Expand Up @@ -885,7 +904,7 @@ pub static CLASS_DOCS: &str = "API for fine-grained control of the Target USB po
///
/// Fields are `"\0"` where C implementation has `""`
/// Fields are `"*\0"` where C implementation has `NULL`
pub static VERBS: [Verb; 18] = [
pub static VERBS: [Verb; 19] = [
// - device connection --
Verb {
id: 0x00,
Expand Down Expand Up @@ -1025,6 +1044,15 @@ pub static VERBS: [Verb; 18] = [
out_signature: "<H\0",
out_param_names: "bitmask\0",
},
Verb {
id: 0x0f,
name: "ep_out_interface_enable\0",
doc: "\0", //"Enable OUT endpoints to resume receiving packets.\0",
in_signature: "\0",
in_param_names: "*\0",
out_signature: "\0",
out_param_names: "*\0",
},
// - tests --
Verb {
id: 0x28,
Expand Down Expand Up @@ -1167,6 +1195,12 @@ impl GreatDispatch for Moondancer {
let response = iter_to_response(iter, response_buffer);
Ok(response)
}
0x0f => {
// moondancer::ep_out_interface_enable
let iter = self.ep_out_interface_enable(arguments)?;
let response = iter_to_response(iter, response_buffer);
Ok(response)
}

// test APIs
0x28 => {
Expand Down
Loading