Closed jjcarstens closed 1 year ago
Half baked: I think that I'd want Circuits.I2C
to be the protocol, so the calls would go right to the implementation (no need for defdelegates
or passing module names). Circuits.I2C.open
would return a default backend. No one using Circuits.I2C
would need to change their code since the default backend would be match the current code. In the spirit of your PR, you'd make a MyI2CBackend
which would implement the Circuits.I2C
interface and you'd have a MyI2CBackend.open
that would create the struct for you. You'd then pass that into all of your code that could call Circuits.I2C
like normal.
I've had the same thought. I think I can make that happen
Experimented a bit. The main problem with Circuits.I2C
as the protocol is that we would then need to make all the detect_devices
and discover
functions/logic part of the protocol as well. In fact, any new functions would have to be added to the protocol whether relevant or not in order to keep the public API scoped to Circuits.I2C
. Maybe that is desired?
Closing since we're working in the configurable-backend branch now.
This essentially would let you do funciton based testing and mocking as needed in external libraries where I2C hardware testing is not a direct concern but functionality is.
I'm currently not sure if there is a performance hit using protocols here