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

Conversation

facchinm
Copy link
Contributor

@facchinm facchinm commented Jul 31, 2019

Description

By replacing the existing callbacks with proper mbed::callback we can use the USBDevice infrastructure without deriving directly from USBDevice.

The patch could bring a (tiny, big ?) performance hit due to the indirection, but would make the USBDevice class usable as a singleton.

A usage example can be found here https://github.com/arduino/ArduinoCore-nRF528x-mbedos/tree/master/cores/arduino/USB and https://github.com/bcmi-labs/ArduinoCore-nRF528x-mbedos/tree/master/libraries/USBHID

PluggableUSBDevice implements USBDevice and calls phy init() just once; all device drivers (derived from mbed ones) plug on it to create a composite device but they don't derive from USBDevice.

Pull request type

[ ] Fix
[x] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

Release Notes

@ciarmcom ciarmcom requested a review from a team July 31, 2019 15:00
@ciarmcom
Copy link
Member

@facchinm, thank you for your changes.
@ARMmbed/mbed-os-maintainers please review.

@0xc0170 0xc0170 changed the title [USBDevice] Avoid forcing end device to be derived from USBDevice class USBDevice: Avoid forcing end device to be derived from USBDevice class Aug 8, 2019
@0xc0170
Copy link
Contributor

0xc0170 commented Aug 8, 2019

I can see there are lot of conflicts, please review

@facchinm facchinm force-pushed the avoid_derive_needed_usbdevice branch from a0c6d9c to 811098f Compare August 8, 2019 12:35
@facchinm
Copy link
Contributor Author

facchinm commented Aug 8, 2019

Rebased upon master, thanks.

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 9, 2019

@maciejbocianski please review

Copy link
Contributor

@maciejbocianski maciejbocianski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good,
tests-usb_device-basic needs adaptation to your changes, you can use my code maciejbocianski@092b26b

@fkjagodzinski @c1728p9 what do you think

@@ -141,21 +142,6 @@ class USBDevice: public USBPhyEvents {
*/
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, ep_cb_t callback = NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're changing to Callback, could you please avoid giving it NULL - change to nullptr. Will avoid issues with some optimisation work I'm doing on Callback. Will save me touching this again later.

(That does make it a 5.14 change - we're not putting any C++11-isms into 5.13 patches. But this doesn't look like a patch anyway).

@fkjagodzinski
Copy link
Member

Yeah, I think this patch OK but can't really comment on performance aspect.

The patch could bring a (tiny, big ?) performance hit due to the indirection, but would make the USBDevice class usable as a singleton.

@c1728p9 could you comment on that, please?

Copy link
Contributor

@c1728p9 c1728p9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR seems reasonable to me. Does the use of callback increase or decrease RAM used? Also, you'll need a few more changes if you want to make USBDevice usable without inheriting from it:

  • Protected functions need to be made public so they can be called

Those changes could be made in a separate PR though as this change look good on its own merits.

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 21, 2019

CI started

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 21, 2019

@facchinm Is this breaking change or functionality change? If yes, Release Notes should be added to your first comment above.

@facchinm
Copy link
Contributor Author

@0xc0170 the only breaking change is the removal of template<typename T> bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, void (T::*callback)() overload that could affect 3rd party, out of tree USB classes (I didn't find any in the wild but they could exist of course).
I'm amending the first commit and add this information

@0xc0170 0xc0170 requested a review from bulislaw August 21, 2019 07:59
@mbed-ci
Copy link

mbed-ci commented Aug 21, 2019

Test run: FAILED

Summary: 3 of 4 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-IAR
  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-ARM

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 21, 2019

Please review build logs, there are failures

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 21, 2019

CI restarted

@facchinm
Copy link
Contributor Author

facchinm commented Aug 21, 2019

By fixing the tests I came up with another implementation, much cleaner and, more important, without breaking changes.
Should I close this PR and open another or forcepushing is ok?

In this way we can use the USBDevice infrastructure without deriving directly from USBDevice.
@0xc0170
Copy link
Contributor

0xc0170 commented Aug 21, 2019

You can force push

@facchinm facchinm force-pushed the avoid_derive_needed_usbdevice branch from f433881 to 84e228a Compare August 21, 2019 14:08
@0xc0170
Copy link
Contributor

0xc0170 commented Aug 22, 2019

Once you do force push , please update PR with the current status to notify us - what has changed.

@facchinm
Copy link
Contributor Author

Sorry, I updated the description on the top but probably this didn't trigger any notification.
Anyway, the new implementation leave everything in its place and adds the possibility to use a regular Callback as argument.

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 22, 2019

Ci restarted

@maciejbocianski Please review

@mbed-ci
Copy link

mbed-ci commented Aug 22, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 3
Build artifacts

Copy link
Contributor

@maciejbocianski maciejbocianski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fkjagodzinski
Copy link
Member

Does the use of callback increase or decrease RAM used?

FYI, this patch increased the size of the USBDevice class by 240 B. It is now 824 B.

@fkjagodzinski
Copy link
Member

@donatieng, @ARMmbed/mbed-os-hal, this information ^^^ might be useful for future reference. I think there's room for improvement if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants