Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USBDevice: Avoid forcing end device to be derived from USBDevice class #11136

Merged
merged 2 commits into from Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/USBKeyboard.h
Expand Up @@ -19,7 +19,7 @@
#define USBKEYBOARD_H

#include "USBHID.h"
#include "Stream.h"
#include "platform/Stream.h"
#include "PlatformMutex.h"

/* Modifiers, left keys then right keys. */
Expand Down
2 changes: 1 addition & 1 deletion drivers/USBMouseKeyboard.h
Expand Up @@ -24,7 +24,7 @@

#include "USBMouse.h"
#include "USBKeyboard.h"
#include "Stream.h"
#include "platform/Stream.h"
#include "USBHID.h"
#include "PlatformMutex.h"

Expand Down
2 changes: 1 addition & 1 deletion drivers/USBSerial.h
Expand Up @@ -19,7 +19,7 @@
#define USBSERIAL_H

#include "USBCDC.h"
#include "Stream.h"
#include "platform/Stream.h"
#include "Callback.h"

/**
Expand Down
7 changes: 4 additions & 3 deletions drivers/internal/USBDevice.h
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
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