-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Motivation: create an AbstractComparator class, accommodating devices with push-pull output and with open-drain (shared bus)
Current models: DigitalSource is for push-pull output, while DigitalSingleSource and DigitalBidir support open-drain / tri-stateable outputs. The port type is more tied to the electrical behavior and doesn't enable this kind of abstraction.
Idea: redefine DigitalSource / DigitalSink / DigitalBidir to reflect signaling direction instead of electrical capabilities.
DigitalSource would now include open-drain and tri-stateable outputs without signal input capability, and structurally support multiple connections on a link (the structural single-source-per-link wasn't catching too many bugs anyways). Pullups and pulldowns are treated as sources.
Note, this differs from the behavior of AnalogSource / Sink / Bidir, where Bidir still reflects tristate capability. But it could be refactored over.
Note, the new model should support:
- Push-pull (always on), incompatible with all other DigitalSource ports, but compatible with DigitalBidir ports (Bidir assumed to run in sink mode)
- Push-pull with tristate (note, push-pull with tristate that reads the signal should be DigitalBidir - the model is at a dataflow instead of electrical level). Probably super uncommon, can behave the same as the non-tristateable push-pull case.
- Push-pull with internal pullup and pulldown resistor (as is common on more modern microcontrollers, to avoid an external pull resistor).
- TODO: can model the resistance. Not used for anything for now, but maybe could be useful in the future.
- External pullup and pulldown resistor (can be a DigitalSource or DigitalPull type - realistically shares a lot of parameters with DigitalSource)
- Open-drain (and the not-common high-side equivalent), including multiple on a bus, and requiring there is a pullup
- Connectivity rules: all signals on a bus must drive the same way, with a pullup in the opposite direction. Incompatible with push-pull drivers on the same bus, but compatible with DigitalBidir (Bidir assumed to run in sink mode)
- Note, I2C should use this
- Other rules
- Link must have an active (signal) driver on at least one direction (either high or low) - can be met with Bidir.
- Link must have be able to drive both levels, even if non-active (eg, pullup / pulldown)
Less-great-idea: merge DigitalSource and DigitalSingleSource
But still using Bidir as the tri-stateable and open-drain case. Doesn't address the AbstractComparator use case (since it needs a unified push-pull and open-drain case), though probably cleans up the DigitalLink.
Potential future idea: type hierarchy on ports
Some kind of Union port between open-drain and push-pull port types. Not sure how the algebra would work out, and given the current structure it probably won't. Fundamentally, this is probably the cleanest model, but doesn't have a realistic near-term implementation path.