Skip to content

Commit

Permalink
Allow USB endpoint_add to accept mbed::Callback
Browse files Browse the repository at this point in the history
In this way we can use the USBDevice infrastructure without deriving directly from USBDevice.
  • Loading branch information
facchinm committed Aug 21, 2019
1 parent 2b226bf commit 84e228a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions drivers/internal/USBDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "USBDevice_Types.h"
#include "USBPhy.h"
#include "mbed_critical.h"
#include "Callback.h"

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

/**
* Add an endpoint
Expand All @@ -153,7 +154,7 @@ class USBDevice: public USBPhyEvents {
template<typename T>
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, void (T::*callback)())
{
return endpoint_add(endpoint, max_packet, type, static_cast<ep_cb_t>(callback));
return endpoint_add(endpoint, max_packet, type, mbed::callback(this, static_cast<ep_cb_t>(callback)));
}

/**
Expand Down Expand Up @@ -540,7 +541,7 @@ class USBDevice: public USBPhyEvents {
void _complete_set_interface();

struct endpoint_info_t {
ep_cb_t callback;
mbed::Callback<void()> callback;
uint16_t max_packet_size;
uint16_t transfer_size;
uint8_t flags;
Expand Down
6 changes: 3 additions & 3 deletions drivers/source/usb/USBDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ void USBDevice::out(usb_ep_t endpoint)
MBED_ASSERT(info->pending >= 1);
info->pending -= 1;
if (info->callback) {
(this->*(info->callback))();
info->callback();
}
}

Expand All @@ -955,7 +955,7 @@ void USBDevice::in(usb_ep_t endpoint)
MBED_ASSERT(info->pending >= 1);
info->pending -= 1;
if (info->callback) {
(this->*(info->callback))();
info->callback();
}
}

Expand Down Expand Up @@ -1051,7 +1051,7 @@ void USBDevice::sof_disable()
unlock();
}

bool USBDevice::endpoint_add(usb_ep_t endpoint, uint32_t max_packet_size, usb_ep_type_t type, ep_cb_t callback)
bool USBDevice::endpoint_add(usb_ep_t endpoint, uint32_t max_packet_size, usb_ep_type_t type, mbed::Callback<void()> callback)
{
lock();

Expand Down

0 comments on commit 84e228a

Please sign in to comment.