Enable inheritance of CAN enum types

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 <vincent.coubard@arm.com>
pull/14336/head
George Beckstein 2021-05-04 01:25:16 -04:00
parent be077713b3
commit d6104c8194
2 changed files with 12 additions and 11 deletions

View File

@ -41,7 +41,7 @@ class CAN
#ifdef FEATURE_EXPERIMENTAL_API
final : public interface::CAN, private NonCopyable<CAN>
#else
: private NonCopyable<CAN>
: private NonCopyable<CAN>, public interface::can
#endif
{
@ -161,8 +161,6 @@ public:
*/
void monitor(bool silent);
using Mode = ::mbed::interface::can::Mode;
/** Change CAN operation to the specified mode
*
* @param mode The new operation mode (CAN::Normal, CAN::Silent, CAN::LocalTest, CAN::GlobalTest, CAN::SilentTest)
@ -198,8 +196,6 @@ public:
*/
unsigned char tderror();
using IrqType = ::mbed::interface::can::IrqType;
/** Attach a function to call whenever a CAN frame received interrupt is
* generated.
*

View File

@ -113,7 +113,8 @@ public:
namespace interface {
namespace can {
/* Having this as a struct allows interface::CAN and/or mbed::CAN to inherit the enums */
struct can {
enum Mode {
Reset = 0,
@ -138,15 +139,19 @@ enum IrqType {
IrqCnt
};
} // namespace can
// Prevent slicing and user creation of base class.
protected:
can() = default;
~can() = default;
can(const can&) = default;
can& operator=(const can&) = default;
};
#ifdef FEATURE_EXPERIMENTAL_API
// Pure virtual interface for CAN
struct CAN {
using Mode = ::mbed::interface::can::Mode;
using IrqType = ::mbed::interface::can::IrqType;
struct CAN : public interface::can {
virtual ~CAN() = default;
virtual int frequency(int hz) = 0;