From 2b226bfdd87ee9f2442e2a6630c4ab19202a9a3c Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 25 Jul 2019 16:45:19 +0200 Subject: [PATCH 1/2] Use unique include for Stream.h --- drivers/USBKeyboard.h | 2 +- drivers/USBMouseKeyboard.h | 2 +- drivers/USBSerial.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/USBKeyboard.h b/drivers/USBKeyboard.h index c8ebbdd0ed4..e41d4360a1b 100644 --- a/drivers/USBKeyboard.h +++ b/drivers/USBKeyboard.h @@ -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. */ diff --git a/drivers/USBMouseKeyboard.h b/drivers/USBMouseKeyboard.h index 3ad2b987289..c7a2e346494 100644 --- a/drivers/USBMouseKeyboard.h +++ b/drivers/USBMouseKeyboard.h @@ -24,7 +24,7 @@ #include "USBMouse.h" #include "USBKeyboard.h" -#include "Stream.h" +#include "platform/Stream.h" #include "USBHID.h" #include "PlatformMutex.h" diff --git a/drivers/USBSerial.h b/drivers/USBSerial.h index ff5f5b392bc..1a8dde89cef 100644 --- a/drivers/USBSerial.h +++ b/drivers/USBSerial.h @@ -19,7 +19,7 @@ #define USBSERIAL_H #include "USBCDC.h" -#include "Stream.h" +#include "platform/Stream.h" #include "Callback.h" /** From 84e228a48fa4d6a8d916a5f3481d321f26f65c8e Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 21 Aug 2019 14:55:29 +0200 Subject: [PATCH 2/2] Allow USB endpoint_add to accept mbed::Callback In this way we can use the USBDevice infrastructure without deriving directly from USBDevice. --- drivers/internal/USBDevice.h | 7 ++++--- drivers/source/usb/USBDevice.cpp | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/internal/USBDevice.h b/drivers/internal/USBDevice.h index 91a603e6617..8d8fcf44d32 100644 --- a/drivers/internal/USBDevice.h +++ b/drivers/internal/USBDevice.h @@ -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 @@ 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 callback = NULL); /** * Add an endpoint @@ -153,7 +154,7 @@ class USBDevice: public USBPhyEvents { template 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(callback)); + return endpoint_add(endpoint, max_packet, type, mbed::callback(this, static_cast(callback))); } /** @@ -540,7 +541,7 @@ class USBDevice: public USBPhyEvents { void _complete_set_interface(); struct endpoint_info_t { - ep_cb_t callback; + mbed::Callback callback; uint16_t max_packet_size; uint16_t transfer_size; uint8_t flags; diff --git a/drivers/source/usb/USBDevice.cpp b/drivers/source/usb/USBDevice.cpp index 0ff2531f96d..3ee73c8ba7e 100644 --- a/drivers/source/usb/USBDevice.cpp +++ b/drivers/source/usb/USBDevice.cpp @@ -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 callback) { lock();