I have a hardware abstraction layer for a peripheral of a MCU which is written in C. The application code is using the peripheral via a C++ wrapper. Now I have a low level enum ll_enum
and a function, that requires a parameter with this datatype.
My understanding of a good architecture would imply the following things:
- Low-level peripheral driver (C)
- should not know that there is a higher level
- has the definition of the enum
- C++ Wrapper
- obviously knows the low-level layer and that there is an application
- Application Code that uses the C++ Wrapper
- Just knows the C++ Wrapper
My solution right now:
I have a enum in the C++ Wrapper that has the same entries as the low level enum. The enum gets casted to the low level type in the C++ Wrapper.
// ### C++ Wrapper ###
enum hl_enum {
foo = 1,
bar = 2,
}
void Peripheral::hl_function(hl_enum param) {
ll_function((ll_enum)param);
}
// ### Low level C-file ###
typedef enum {
foo = 1,
bar = 2,
} ll_enum;
void ll_function(ll_enum param);
Obviously that is a bad solution, because you have to change code at two positions and get in trouble if you missed that.
Is there a better solution?