Skip to content

Commit

Permalink
Merge pull request #771 from ardnew/usb-emit-vtable
Browse files Browse the repository at this point in the history
USB: add pure specifiers and emit vtable
  • Loading branch information
facchinm authored Dec 4, 2023
2 parents ee9a1b0 + e81cc97 commit fcbb950
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
4 changes: 4 additions & 0 deletions cores/arduino/USB/PluggableUSBDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ uint32_t arduino::internal::PluggableUSBModule::write_finish(usb_ep_t endpoint)
return PluggableUSBD().write_finish(endpoint);
}

void arduino::internal::PluggableUSBModule::callback_reset()
{
}

arduino::PluggableUSBDevice::PluggableUSBDevice(uint16_t vendor_id, uint16_t product_id)
: USBDevice(get_usb_phy(), vendor_id, product_id, 1 << 8)
{
Expand Down
28 changes: 19 additions & 9 deletions cores/arduino/USB/PluggableUSBDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class PluggableUSBModule {
PluggableUSBModule(uint8_t numIfs) :
numInterfaces(numIfs)
{ }
virtual ~PluggableUSBModule()
{ }
void lock();
void unlock();
void assert_locked();
Expand All @@ -49,17 +51,25 @@ class PluggableUSBModule {
uint32_t write_finish(usb_ep_t endpoint);

protected:
virtual const uint8_t *configuration_desc(uint8_t index);
virtual void callback_reset() {};
virtual void callback_state_change(USBDevice::DeviceState new_state);
virtual uint32_t callback_request(const USBDevice::setup_packet_t *setup, USBDevice::RequestResult *result, uint8_t** data);
virtual bool callback_request_xfer_done(const USBDevice::setup_packet_t *setup, bool aborted);
virtual bool callback_set_configuration(uint8_t configuration);
virtual void callback_set_interface(uint16_t interface, uint8_t alternate);
virtual void init(EndpointResolver& resolver);
virtual const uint8_t *string_iinterface_desc();
virtual const uint8_t *configuration_desc(uint8_t index) = 0;
virtual void callback_state_change(USBDevice::DeviceState new_state) = 0;
virtual uint32_t callback_request(const USBDevice::setup_packet_t *setup, USBDevice::RequestResult *result, uint8_t** data) = 0;
virtual bool callback_request_xfer_done(const USBDevice::setup_packet_t *setup, bool aborted) = 0;
virtual bool callback_set_configuration(uint8_t configuration) = 0;
virtual void callback_set_interface(uint16_t interface, uint8_t alternate) = 0;
virtual void init(EndpointResolver& resolver) = 0;
virtual const uint8_t *string_iinterface_desc() = 0;
virtual uint8_t getProductVersion() = 0;

/**
* Non-pure virtual method with a non-inline definition
*
* @note This satisfies all criteria necessary for the compiler to emit a
* vtable, allowing users to safely subclass any of the derived "pluggable"
* USB device classes (USBCDC, USBHID, USBMIDI, etc).
*/
virtual void callback_reset();

uint8_t pluggedInterface;

const uint8_t numInterfaces;
Expand Down

0 comments on commit fcbb950

Please sign in to comment.