I have been implementing a software driver for an external (from my microcontroller point of view) chip communicating with my microcontroller over I2C. From the higher perspective the chip is a collection of some registers which can be read or written. This idea bring me to the following driver design:
The chip requires some kind of configuration after power-up. This configuration basically consists of writting given data into specified registers. Unfortunatelly the writting process occurs via communication channel where the written data can be corrupted. So it is not sufficient to blindly send the data. Instead it is necessary to read them back and check to see that the written data equals the sent of them to be sure the writting operation has been successfully done. I have decided to encapsulate this configuration algorithm into special class:
The intention is that the
configureDevice method of the
Configurator will be invoked from the
update method which is invoked in periodic manner. What I am now thinking about is how to ensure the access of the
Configurator object to the private
Register objects for the configuration.
My first idea was to create
Configurator object as a private member inside the
Configurator as a friend of
Device and pass pointer to the
Device into the
idea was the visitor design pattern. Which is probably cleaner solution. Do you think that visitor
design pattern usage is justified in this case?