Restore notes on portability
diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 0ee7ea1..bf111bb 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md
@@ -32,6 +32,7 @@ - [Static Guarantees](./static-guarantees/static-guarantees.md) <!-- TODO: Define Sections --> - [Portability](./portability/portability.md) + - [The Trait System](./portability/traits.md) <!-- TODO: Define more sections --> - [Concurrency](./concurrency/concurrency.md) <!-- TODO: Define Sections -->
diff --git a/src/portability/portability.md b/src/portability/portability.md index fec7a58..26fb9c2 100644 --- a/src/portability/portability.md +++ b/src/portability/portability.md
@@ -1,3 +1,14 @@ # Portability -> ❌: This section has not yet been written. Please refer to [rust-embedded/book#6](https://github.com/rust-embedded/book/issues/6) for discussion of this section. +> ❌: This section has not yet been written. Please refer to [embedded-wg#119](https://github.com/rust-lang-nursery/embedded-wg/issues/119) for discussion of this section. + +## Building something bigger + +> drivers that work for more than one chip + + + +* Device Crates (one per chip) +* HAL Implementation Crates (one per chip) +* `embedded-hal` (only one) +* Driver Crates (one per external component)
diff --git a/src/portability/traits.md b/src/portability/traits.md new file mode 100644 index 0000000..2fbf2ff --- /dev/null +++ b/src/portability/traits.md
@@ -0,0 +1,50 @@ +# The Trait System + +```rust +/// Single digital push-pull output pin +pub trait OutputPin { + /// Drives the pin low + fn set_low(&mut self); + + /// Drives the pin high + fn set_high(&mut self); +} +``` + +[rust-embedded/embedded-hal](https://github.com/rust-embedded/embedded-hal/blob/master/src/digital.rs) + +```rust +impl<MODE> OutputPin for OutputGpio<MODE> { + fn set_low(&mut self) { + self.set_pin_low() + } + + fn set_high(&mut self) { + self.set_pin_high() + } +} +``` + +> this goes in your chip crate + + +```rust +impl<SPI, CS, E> L3gd20<SPI, CS> +where + SPI: Transfer<u8, Error = E> + Write<u8, Error = E>, + CS: OutputPin, +{ + /// Creates a new driver from a SPI peripheral + /// and a NCS (active low chip select) pin + pub fn new(spi: SPI, cs: CS) -> Result<Self, E> { + // ... + } + // ... +} +``` + +[japaric/l3gd20](https://github.com/japaric/l3gd20/blob/master/src/lib.rs) + +## N\*M >>> N+M + +> to re-use a driver, just implement the embedded-hal interface \ No newline at end of file