Skip to content

Add USB endpoint tests #6880

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

Next Next commit
USB: EndpointResolver: Add a generic method to get a free endpoint
  • Loading branch information
fkjagodzinski authored and Filip Jagodzinski committed Jul 3, 2018
commit 968c39bfc93e871ffadb0ae14b738808bcbb6338
21 changes: 8 additions & 13 deletions usb/device/USBDevice/EndpointResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ void EndpointResolver::endpoint_ctrl(uint32_t size)
endpoint_out(USB_EP_TYPE_CTRL, size);
}

usb_ep_t EndpointResolver::endpoint_in(usb_ep_type_t type, uint32_t size)
usb_ep_t EndpointResolver::next_free_endpoint(bool in_not_out, usb_ep_type_t type, uint32_t size)
{
int index = next_index(type, true);
int index = next_index(type, in_not_out);
if (index < 0) {
_valid = false;
return 0;
Expand All @@ -57,21 +57,16 @@ usb_ep_t EndpointResolver::endpoint_in(usb_ep_type_t type, uint32_t size)
_used |= 1 << index;

return index_to_endpoint(index);

}
usb_ep_t EndpointResolver::endpoint_in(usb_ep_type_t type, uint32_t size)
{
return next_free_endpoint(true, type, size);
}

usb_ep_t EndpointResolver::endpoint_out(usb_ep_type_t type, uint32_t size)
{
int index = next_index(type, false);
if (index < 0) {
_valid = false;
return 0;
}

const usb_ep_entry_t &entry = _table->table[index_to_logical(index)];
_cost += entry.base_cost + entry.byte_cost * size;
_used |= 1 << index;

return index_to_endpoint(index);
return next_free_endpoint(false, type, size);
}

bool EndpointResolver::valid()
Expand Down
5 changes: 5 additions & 0 deletions usb/device/USBDevice/EndpointResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class EndpointResolver {
*/
usb_ep_t endpoint_out(usb_ep_type_t type, uint32_t size);

/**
* Get next free endpoint
*/
usb_ep_t next_free_endpoint(bool in_not_out, usb_ep_type_t type, uint32_t size);

/**
* Check if the endpoint configuration created so far is valid
*
Expand Down