I'm experimenting with light-weight C++ for microcontrollers. Looking for your opinion for class(es) that represent GPIO pin behaviour
An output pin can
- accept a value and set it
- return the value it is set to
- maybe go high-z
An input can:
- return the value at its input
I may represent this
- very simple as a single class.
Getting the value would perform the "return" action above. The class would decide if it returns output state or input state internally
Setting would only succeed if the pin is an output pin, else either throw an exception or silently ignore.
Switching between the two would be simple
- as separate classes
out type pin would set the output as indicated, and return the output state if asked
in type pin would return the value at its input. It would not provide setters.
Switching between two modes would mean discarding the original object and creating one of the other kind.
(should both classes inherit from a common parent that defines the actual pin?)
How would you solve this, as OO designer / abstractor that loves simplicity?