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

View File

@ -113,7 +113,8 @@ public:
namespace interface { namespace interface {
namespace can { /* Having this as a struct allows interface::CAN and/or mbed::CAN to inherit the enums */
struct can {
enum Mode { enum Mode {
Reset = 0, Reset = 0,
@ -138,15 +139,19 @@ enum IrqType {
IrqCnt 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 #ifdef FEATURE_EXPERIMENTAL_API
// Pure virtual interface for CAN // Pure virtual interface for CAN
struct CAN { struct CAN : public interface::can {
using Mode = ::mbed::interface::can::Mode;
using IrqType = ::mbed::interface::can::IrqType;
virtual ~CAN() = default; virtual ~CAN() = default;
virtual int frequency(int hz) = 0; virtual int frequency(int hz) = 0;