Skip to content

Commit 6e2b0a0

Browse files
fkjagodzinskic1728p9
authored andcommitted
USB: EndpointResolver: Add a generic method to get a free endpoint
1 parent 4379ffa commit 6e2b0a0

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

usb/device/USBDevice/EndpointResolver.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ void EndpointResolver::endpoint_ctrl(uint32_t size)
4444
endpoint_out(USB_EP_TYPE_CTRL, size);
4545
}
4646

47-
usb_ep_t EndpointResolver::endpoint_in(usb_ep_type_t type, uint32_t size)
47+
usb_ep_t EndpointResolver::next_free_endpoint(bool in_not_out, usb_ep_type_t type, uint32_t size)
4848
{
49-
int index = next_index(type, true);
49+
int index = next_index(type, in_not_out);
5050
if (index < 0) {
5151
_valid = false;
5252
return 0;
@@ -57,21 +57,16 @@ usb_ep_t EndpointResolver::endpoint_in(usb_ep_type_t type, uint32_t size)
5757
_used |= 1 << index;
5858

5959
return index_to_endpoint(index);
60+
61+
}
62+
usb_ep_t EndpointResolver::endpoint_in(usb_ep_type_t type, uint32_t size)
63+
{
64+
return next_free_endpoint(true, type, size);
6065
}
6166

6267
usb_ep_t EndpointResolver::endpoint_out(usb_ep_type_t type, uint32_t size)
6368
{
64-
int index = next_index(type, false);
65-
if (index < 0) {
66-
_valid = false;
67-
return 0;
68-
}
69-
70-
const usb_ep_entry_t &entry = _table->table[index_to_logical(index)];
71-
_cost += entry.base_cost + entry.byte_cost * size;
72-
_used |= 1 << index;
73-
74-
return index_to_endpoint(index);
69+
return next_free_endpoint(false, type, size);
7570
}
7671

7772
bool EndpointResolver::valid()

usb/device/USBDevice/EndpointResolver.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class EndpointResolver {
6262
*/
6363
usb_ep_t endpoint_out(usb_ep_type_t type, uint32_t size);
6464

65+
/**
66+
* Get next free endpoint
67+
*/
68+
usb_ep_t next_free_endpoint(bool in_not_out, usb_ep_type_t type, uint32_t size);
69+
6570
/**
6671
* Check if the endpoint configuration created so far is valid
6772
*

0 commit comments

Comments
 (0)