Skip to content

Commit ff60c29

Browse files
committed
Add endpoint_remove_all helper function
Add the helper function endpoint_remove_all which removes all added endpoints. This is useful for class drivers switching between different USB configurations.
1 parent cf29baf commit ff60c29

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

usb/device/USBDevice/USBDevice.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
/* Endpoint macros */
3737
#define EP_INDEXABLE(endpoint) (EP_VALID(endpoint) && !EP_CONTROL(endpoint))
3838
#define EP_TO_INDEX(endpoint) ((((endpoint & 0xf) << 1) | (endpoint & 0x80 ? 1 : 0)) - 2)
39+
#define INDEX_TO_EP(index) ((usb_ep_t)((((index) >> 1) | (index & 1 ? 0x80 : 0)) + 1))
3940
#define EP_VALID(endpoint) (((endpoint) & ~0x8F) == 0)
4041
#define EP_CONTROL(endpoint) (((endpoint) & 0xF) == 0)
4142
#define EP_RX(endpoint) ((endpoint) & 0x80)
@@ -1101,6 +1102,20 @@ void USBDevice::endpoint_remove(usb_ep_t endpoint)
11011102
unlock();
11021103
}
11031104

1105+
void USBDevice::endpoint_remove_all()
1106+
{
1107+
lock();
1108+
1109+
for (uint32_t i = 0; i < sizeof(_endpoint_info) / sizeof(_endpoint_info[0]); i++) {
1110+
endpoint_info_t *info = _endpoint_info + i;
1111+
if (info->flags & ENDPOINT_ENABLED) {
1112+
endpoint_remove(INDEX_TO_EP(i));
1113+
}
1114+
}
1115+
1116+
unlock();
1117+
}
1118+
11041119
void USBDevice::endpoint_stall(usb_ep_t endpoint)
11051120
{
11061121
lock();

usb/device/USBDevice/USBDevice.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ class USBDevice: public USBPhyEvents {
175175
*/
176176
void endpoint_remove(usb_ep_t endpoint);
177177

178+
/**
179+
* Remove all non-zero endpoints
180+
*/
181+
void endpoint_remove_all();
182+
178183
/**
179184
* Stall an endpoint
180185
*

0 commit comments

Comments
 (0)