Skip to content

Commit 84e228a

Browse files
committed
Allow USB endpoint_add to accept mbed::Callback
In this way we can use the USBDevice infrastructure without deriving directly from USBDevice.
1 parent 2b226bf commit 84e228a

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

drivers/internal/USBDevice.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "USBDevice_Types.h"
2323
#include "USBPhy.h"
2424
#include "mbed_critical.h"
25+
#include "Callback.h"
2526

2627
/**
2728
* \defgroup drivers_USBDevice USBDevice class
@@ -139,7 +140,7 @@ class USBDevice: public USBPhyEvents {
139140
* @param callback Method pointer to be called when a packet is transferred
140141
* @returns true if successful, false otherwise
141142
*/
142-
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, ep_cb_t callback = NULL);
143+
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, mbed::Callback<void()> callback = NULL);
143144

144145
/**
145146
* Add an endpoint
@@ -153,7 +154,7 @@ class USBDevice: public USBPhyEvents {
153154
template<typename T>
154155
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, void (T::*callback)())
155156
{
156-
return endpoint_add(endpoint, max_packet, type, static_cast<ep_cb_t>(callback));
157+
return endpoint_add(endpoint, max_packet, type, mbed::callback(this, static_cast<ep_cb_t>(callback)));
157158
}
158159

159160
/**
@@ -540,7 +541,7 @@ class USBDevice: public USBPhyEvents {
540541
void _complete_set_interface();
541542

542543
struct endpoint_info_t {
543-
ep_cb_t callback;
544+
mbed::Callback<void()> callback;
544545
uint16_t max_packet_size;
545546
uint16_t transfer_size;
546547
uint8_t flags;

drivers/source/usb/USBDevice.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ void USBDevice::out(usb_ep_t endpoint)
937937
MBED_ASSERT(info->pending >= 1);
938938
info->pending -= 1;
939939
if (info->callback) {
940-
(this->*(info->callback))();
940+
info->callback();
941941
}
942942
}
943943

@@ -955,7 +955,7 @@ void USBDevice::in(usb_ep_t endpoint)
955955
MBED_ASSERT(info->pending >= 1);
956956
info->pending -= 1;
957957
if (info->callback) {
958-
(this->*(info->callback))();
958+
info->callback();
959959
}
960960
}
961961

@@ -1051,7 +1051,7 @@ void USBDevice::sof_disable()
10511051
unlock();
10521052
}
10531053

1054-
bool USBDevice::endpoint_add(usb_ep_t endpoint, uint32_t max_packet_size, usb_ep_type_t type, ep_cb_t callback)
1054+
bool USBDevice::endpoint_add(usb_ep_t endpoint, uint32_t max_packet_size, usb_ep_type_t type, mbed::Callback<void()> callback)
10551055
{
10561056
lock();
10571057

0 commit comments

Comments
 (0)