Open StefanoSperetta opened 8 years ago
To add to this: use simpler module references; e.g. define a 'MODULE_1' or just use the integer 1 (2 for MODULE_2, etc.) instead of using EUSCI_B1_BASE. This can be switched easily enough within the constructor.
I like maybe the plain simple number. I am not sure if it is best to have a 0-based or 1-based number.
It could be nice to make this argument optional and use module 1 as default so the "less experienced" ones are not tricked.
Partial fix in commit efdc5df365438abac3d0e04a339d734ac99e66e3: now the module is selected in the constructor but it should also be changed in a number (rather than the full memory address).
The I2C device is selected in the begin function but, by calling begin twice with 2 different devices, 2 devices would be used and the interrupt handlers would stay dangling.
It would be better to modify the constructor to accept the module parameter (uint_fast32_t module) and move also the assignment to the local variable in the constructor (this->module = module;) but leave the rest of the code in the begin method.
This way the I2C device can only be selected upon object creation but all the initialisation code only runs when begin is called.