Embedded C++ classes

Hi,
what are the best practices when designing classes in embedded systems?

For example I the micro has a I2C, SPI and RS-232 to communicate to various peripherals. I then have a display and a sensor which both use the I2C.

I was thinking of making a class for the sensor and one class for the display. But the I2C is used by both. Where do I implement the I2C class to keep everything as modular and portable as possible?

Also if I have a function in the display class that uses the I2C, how do I code it so the addressing pf the I2C is as portable as possible? Do I remap or define the I2C somehow in the header file? If so, how?

Thank you :)
I would make an I2C class that can be used by both your sensor and display classes.

You could have your sensor and display classes inherit your I2C class, but it would be better to use construction. This would allow you sensor and display classes to have multiple I2C instances if necessary.

how do I code it so the addressing pf the I2C is as portable as possible?

I would pass unique properties of an I2C instance in I2C's constructor.




Topic archived. No new replies allowed.