I have a micro controller board on which are different sub modules. Every module has an address and different registers which can be addressed. For example:
GPIO module
-Address 0x1212
-Registers:
--InputRegister
--OutputRegister
PLL module
-Address 0x2342
-Registers:
--PhaseRegister
--ErrorRegister
--LockedInRegister
These sub modules can be controlled via a UART messages which contain the address, the register and the value to be written.
I need to implement a class to communicate with the micro controller and the modules.
The simplest way would be to implement a function like so:
void send_message(int address, int parameter, int value) {
...
}
But then it is possible to issue a write to a random address which does not exist or to a register which does not belong to the selected module.
My Idea would be to implement a base class for the modules and derive a class for every sub module as follows

But then how would one declare the available registers correctly? How can this be implemented in a proper way?