···11[package]
22name = "pervasive-spi"
33-version = "0.1.0"
33+version = "0.1.1"
44edition = "2021"
55description = "Bitbang driver for the SPI-derived protocol used by Pervasive Displays e-paper displays"
66
+2-4
pervasive-spi/src/lib.rs
···7070 ///
7171 /// * `cs`: The chip select pin (output).
7272 /// * `sda`: The SDA pin. The type must implement both the `WithInput` and `WithOutput` traits.
7373- /// An implementation for both of these on the RP2040 is provided if the `rp2040`
7474- /// feature is enabled. For internal reasons, the trait is implemented on `Option<Pin>`
7575- /// instead of `Pin` on the RP2040, but reading and writing will panic if `None` is
7676- /// provided.
7373+ /// If the `rp2040` feature is enabled, the [rp2040] module provides an `IoPin` type
7474+ /// implementing both of these for the RP2040.
7775 /// * `scl`: The SCL pin (output).
7876 /// * `dc`: The D/C (data/command) pin (output).
7977 /// * `delay`: An object implementing `PervasiveSpiDelays`, describing delays to be inserted at
+31-9
pervasive-spi/src/rp2040.rs
···33 Function, FunctionSioInput, FunctionSioOutput, Pin, PinId, PullType, ValidFunction,
44};
5566-impl<I, F, P> WithInput for Option<Pin<I, F, P>>
66+/// A GPIO pin that can be configured as an input or output.
77+pub struct IoPin<I, F, P>
78where
88- I: PinId + ValidFunction<FunctionSioInput> + ValidFunction<F>,
99+ I: PinId + ValidFunction<FunctionSioInput> + ValidFunction<FunctionSioOutput> + ValidFunction<F>,
1010+ F: Function,
1111+ P: PullType,
1212+{
1313+ pin: Option<Pin<I, F, P>>,
1414+}
1515+1616+impl<I, F, P> IoPin<I, F, P>
1717+where
1818+ I: PinId + ValidFunction<FunctionSioInput> + ValidFunction<FunctionSioOutput> + ValidFunction<F>,
1919+ F: Function,
2020+ P: PullType,
2121+{
2222+ /// Create a new instance of `IoPin` with a GPIO pin.
2323+ pub fn new(pin: Pin<I, F, P>) -> Self {
2424+ Self { pin: Some(pin) }
2525+ }
2626+}
2727+2828+impl<I, F, P> WithInput for IoPin<I, F, P>
2929+where
3030+ I: PinId + ValidFunction<FunctionSioInput> + ValidFunction<FunctionSioOutput> + ValidFunction<F>,
931 F: Function,
1032 P: PullType,
1133{
1234 type Input = Pin<I, FunctionSioInput, P>;
13351436 fn with_input<R>(&mut self, f: impl Fn(&mut Self::Input) -> R) -> R {
1515- let mut input = self.take().unwrap().reconfigure();
3737+ let mut input = self.pin.take().unwrap().reconfigure();
1638 let res = f(&mut input);
1717- self.replace(input.reconfigure());
3939+ self.pin.replace(input.reconfigure());
1840 res
1941 }
2042}
21432222-impl<I, F, P> WithOutput for Option<Pin<I, F, P>>
4444+impl<I, F, P> WithOutput for IoPin<I, F, P>
2345where
2424- I: PinId + ValidFunction<FunctionSioOutput> + ValidFunction<F>,
4646+ I: PinId + ValidFunction<FunctionSioInput> + ValidFunction<FunctionSioOutput> + ValidFunction<F>,
2547 F: Function,
2648 P: PullType,
2749{
2850 type Output = Pin<I, FunctionSioOutput, P>;
29513052 fn with_output<R>(&mut self, f: impl Fn(&mut Self::Output) -> R) -> R {
3131- let mut output = self.take().unwrap().reconfigure();
5353+ let mut output = self.pin.take().unwrap().reconfigure();
3254 let res = f(&mut output);
3333- self.replace(output.reconfigure());
5555+ self.pin.replace(output.reconfigure());
3456 res
3557 }
3636-}
5858+}
+2-4
tp370pgh01/src/lib.rs
···8383 ///
8484 /// * `cs` - Chip select pin (output).
8585 /// * `sda` - SDA pin (bidirectional). This must implement both the `WithInput` and `WithOutput`
8686- /// traits from the `pervasive-spi` crate. An implementation for the RP2040 is provided
8787- /// in that crate if the `rp2040` feature is enabled. Note that on the RP2040, the pin
8888- /// must be wrapped in the Option, but all display operations will panic if None is
8989- /// provided.
8686+ /// traits from the `pervasive-spi` crate. That crate provides a type implementing
8787+ /// these traits for the RP2040 if the `rp2040` feature is enabled.
9088 /// * `sck` - SCK pin (output).
9189 /// * `dc` - D/C (data/command) pin (output).
9290 /// * `reset` - Display reset pin (output).
+4
tp370pgh01/src/rp2040.rs
···11use pervasive_spi::PervasiveSpiDelays;
2233+pub use pervasive_spi::rp2040::IoPin;
44+55+/// A type implementing `PervasiveSpiDelays` designed for use with the TP370PGH01 display on the
66+/// RP2040 (running at its default speed).
37pub struct Rp2040PervasiveSpiDelays;
4859impl PervasiveSpiDelays for Rp2040PervasiveSpiDelays {