-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Implement polymorphism for CAN driver #14336
Conversation
@AGlass0fMilk, thank you for your changes. |
@pan- A possible consequence of this change is that client code referring to types previously defined inside the I experience some issues with code referring simply to |
This pull request has automatically been marked as stale because it has had no recent activity. @donatieng, @kjbracey-arm, @pan-, @ARMmbed/mbed-os-maintainers, please complete review of the changes to move the PR forward. Thank you for your contributions. |
@AGlass0fMilk Is this Major? I would expect feature update. This is also enabled only if experimental api flag is set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I would like to preserve behavior regards to enum in the original class.
Please review my solution.
|
||
namespace interface { | ||
|
||
namespace can { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't play well with code using the enum values: CAN::Reset
won't be found as a member for example. As a workaround, this can be wrapped inside a structure instead of a namespace and interface::Can
can inherit from it . If polymorphism is disabled then mbed::Can
inherits from it too.
struct can {
enum Mode {
// enum definition
};
// Prevent slicing and user creation of base class.
protected:
can() = default;
~can() = default;
can(const can&) = default;
can& operator=(const can&) = default;
};
This pull request has automatically been marked as stale because it has had no recent activity. @ARMmbed/mbed-os-maintainers, please start CI to get the PR merged. |
@AGlass0fMilk this PR is awaiting your responses... |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
This commit changes the `interface::can` namespace to a `struct`. This allows the enum types to be inherited and prevents breaking old code relying on referencing eg: `CAN::RxIrq`. When enabled, the polymorphic CAN interface class inherits from this `interface::can` struct. If not enabled, the `mbed::CAN` class inherits from `interface::can` directly. Co-authored-by: Vincent Coubard <[email protected]>
This commit adds provisions to enable using interface::CAN on targets that don't have DEVICE_CAN set to 1 (ie: they don't normally have a CAN peripheral).
@pan- @adbridge I have rebased and updated this PR with suggested edits. I have tested that this builds in several configurations:
You can review the code I built in each of these cases to verify this doesn't break any existing code using Find that demo code here: https://github.com/AGlass0fMilk/polymorphic-can-demo Let me know if this requires any other changes. |
This commit moves the deletion of copy constructor and copy assignment operators to the `mbed::interface::can` class, where both `mbed::CAN` and `mbed::interface::CAN` inherit enum types from. This allows `NonCopyable` to be removed from the inheritance list.
@pan- Updated to remove the I tested to make sure the deletion of the copy methods was working (like to double check things like this...): AGlass0fMilk/polymorphic-can-demo@63cfee2 I added these lines to my compilation example and they did indeed cause the build to fail each time:
With the following error messages:
I also tested to make sure the compilations were successful on both NUCLEO_G474RE (with and without |
Set to feature release, similar as others (new functionality, nothing breaking or?). |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 2 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
I'll merge this today if no objections |
I've tested this with existing code that takes the |
Summary of changes
This PR introduces experimental polymorphism for the
CAN
C++ API. This allows alternate implementations (eg: external CAN interfaces) that are compatible with the internal implementation.See #13209 for the surrounding discussion.
Impact of changes
None, it only affects the user if they have the
EXPERIMENTAL_API
feature enabled.Migration actions required
None
Documentation
Pull request type
Test results
Reviewers
@kjbracey-arm @pan- @donatieng