Since I've started getting into Rust development on Tessel I want to open this Issue to request feedback on an API rework I would like to help with.
For this I have some Goals in mind:
- A Tessel API that can transparently be used from multiple threads.
- Pins and Ports are represented by objects that can be owned in different scopes or objects
e.g. Two pins of a port are owned by scopes of two separate thread. To share a pin it needs to be wrapped in a Mutex.
- Pins and Ports should have lifetimes separate of each other. A Port just holds multiple Pins. Pins can be borrowed or taken.
- Once all Pins for a Port are no longer owned (they've been dropped) the relevant hardware port is automatically disabled.
- Not all pins apply to all communication protocols, use Rust's zero-cost abstraction to wrap pins with an object that exposes a communication interface
- Provide idioms for consistent communication interfaces (Gpio, Analog, Interrupt, Pwm, I2c, Spi, Uart)
- Idiom to convert Pin (or many Pins) to an interface
- Idiom to convert an owning interface back into Pin(s) (just dropped borrowed interfaces)
- Implement io::Read and io::Write for I2c, Spi, and Uart
- A borrowed interface and owning interface are available for each communication protocol
- Any IO related call (most of the Tessel interface) should return a Result
The API design is in this gist. It starts with examples on how using the design looks with comments on different ways to get a Pin for example and other thoughts. I included an example on how relay_mono might be reimplemented (More a thought experiment than how I think that specific module should be designed).
https://gist.github.com/mzgoddard/98d1b27979ef86cf2a7effe4bd201984
If there is a better way for me to format this issue, let me know.
cc @rwaldron @tcr
Since I've started getting into Rust development on Tessel I want to open this Issue to request feedback on an API rework I would like to help with.
For this I have some Goals in mind:
e.g. Two pins of a port are owned by scopes of two separate thread. To share a pin it needs to be wrapped in a Mutex.
The API design is in this gist. It starts with examples on how using the design looks with comments on different ways to get a Pin for example and other thoughts. I included an example on how relay_mono might be reimplemented (More a thought experiment than how I think that specific module should be designed).
https://gist.github.com/mzgoddard/98d1b27979ef86cf2a7effe4bd201984
If there is a better way for me to format this issue, let me know.
cc @rwaldron @tcr