Skip to content

Commit d6104c8

Browse files
AGlass0fMilkpan-
andcommitted
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 <[email protected]>
1 parent be07771 commit d6104c8

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

drivers/include/drivers/CAN.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CAN
4141
#ifdef FEATURE_EXPERIMENTAL_API
4242
final : public interface::CAN, private NonCopyable<CAN>
4343
#else
44-
: private NonCopyable<CAN>
44+
: private NonCopyable<CAN>, public interface::can
4545
#endif
4646
{
4747

@@ -161,8 +161,6 @@ class CAN
161161
*/
162162
void monitor(bool silent);
163163

164-
using Mode = ::mbed::interface::can::Mode;
165-
166164
/** Change CAN operation to the specified mode
167165
*
168166
* @param mode The new operation mode (CAN::Normal, CAN::Silent, CAN::LocalTest, CAN::GlobalTest, CAN::SilentTest)
@@ -198,8 +196,6 @@ class CAN
198196
*/
199197
unsigned char tderror();
200198

201-
using IrqType = ::mbed::interface::can::IrqType;
202-
203199
/** Attach a function to call whenever a CAN frame received interrupt is
204200
* generated.
205201
*

drivers/include/drivers/interfaces/InterfaceCAN.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ class CANMessage : public CAN_Message {
113113

114114
namespace interface {
115115

116-
namespace can {
116+
/* Having this as a struct allows interface::CAN and/or mbed::CAN to inherit the enums */
117+
struct can {
117118

118119
enum Mode {
119120
Reset = 0,
@@ -138,15 +139,19 @@ enum IrqType {
138139
IrqCnt
139140
};
140141

141-
} // namespace can
142+
// Prevent slicing and user creation of base class.
143+
protected:
144+
can() = default;
145+
~can() = default;
146+
can(const can&) = default;
147+
can& operator=(const can&) = default;
148+
149+
};
142150

143151
#ifdef FEATURE_EXPERIMENTAL_API
144152

145153
// Pure virtual interface for CAN
146-
struct CAN {
147-
148-
using Mode = ::mbed::interface::can::Mode;
149-
using IrqType = ::mbed::interface::can::IrqType;
154+
struct CAN : public interface::can {
150155

151156
virtual ~CAN() = default;
152157
virtual int frequency(int hz) = 0;

0 commit comments

Comments
 (0)