Allow USB endpoint_add to accept mbed::Callback

In this way we can use the USBDevice infrastructure without deriving directly from USBDevice.
pull/11136/head
Martino Facchin 2019-08-21 14:55:29 +02:00
parent 2b226bfdd8
commit 84e228a48f
2 changed files with 7 additions and 6 deletions

View File

@ -22,6 +22,7 @@
#include "USBDevice_Types.h"
#include "USBPhy.h"
#include "mbed_critical.h"
#include "Callback.h"
/**
* \defgroup drivers_USBDevice USBDevice class
@ -139,7 +140,7 @@ public:
* @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
@ -153,7 +154,7 @@ public:
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)));
}
/**
@ -540,7 +541,7 @@ private:
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;

View File

@ -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();
}
}
@ -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();
}
}
@ -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();