firmware for my Touchscreen E-Paper Input Module for Framework Laptop 16
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

pervasive-spi: add rp2040::IoPin

+44 -22
+4 -4
fw16-epd-main/src/main.rs
··· 20 20 use usb_device::bus::UsbBusAllocator; 21 21 use usb_device::prelude::*; 22 22 use usbd_serial::SerialPort; 23 - use fw16_epd_bsp::{entry, hal, pac, EpdBusy, EpdCs, EpdDc, EpdReset, EpdSck, EpdSdaRead, EpdTouchInt, I2CScl, I2CSda, Pins}; 23 + use fw16_epd_bsp::{entry, hal, pac, EpdBusy, EpdCs, EpdDc, EpdReset, EpdSck, EpdSdaWrite, EpdTouchInt, I2CScl, I2CSda, Pins}; 24 24 use fw16_epd_bsp::hal::{Sio, Timer, I2C}; 25 25 use fw16_epd_bsp::hal::clocks::ClockSource; 26 26 use fw16_epd_bsp::hal::fugit::RateExtU32; ··· 28 28 use fw16_epd_bsp::hal::multicore::{Multicore, Stack}; 29 29 use fw16_epd_bsp::pac::I2C0; 30 30 use fw16_epd_bsp::pac::interrupt; 31 - use tp370pgh01::rp2040::Rp2040PervasiveSpiDelays; 31 + use tp370pgh01::rp2040::{Rp2040PervasiveSpiDelays, IoPin}; 32 32 use tp370pgh01::Tp370pgh01; 33 33 34 34 static CORE1_STACK: Stack<8192> = Stack::new(); ··· 76 76 let dc: EpdDc = pins.epd_dc.reconfigure(); 77 77 let busy: EpdBusy = pins.epd_busy.reconfigure(); 78 78 let rst: EpdReset = pins.epd_rst.reconfigure(); 79 - let sda: EpdSdaRead = pins.spi3_epd_sda.reconfigure(); 79 + let sda: EpdSdaWrite = pins.spi3_epd_sda.reconfigure(); 80 80 let sck: EpdSck = pins.spi3_epd_sck.reconfigure(); 81 81 82 82 let i2c_sda: I2CSda = pins.i2c_sda.reconfigure(); ··· 131 131 pac::NVIC::unmask(interrupt::USBCTRL_IRQ); 132 132 } 133 133 134 - let mut epd = Tp370pgh01::new(cs, Some(sda), sck, dc, busy, rst, timer, Rp2040PervasiveSpiDelays); 134 + let mut epd = Tp370pgh01::new(cs, IoPin::new(sda), sck, dc, busy, rst, timer, Rp2040PervasiveSpiDelays); 135 135 epd.hard_reset().unwrap(); 136 136 137 137 let mut prev_image = [0u8; tp370pgh01::IMAGE_BYTES];
+1 -1
pervasive-spi/Cargo.toml
··· 1 1 [package] 2 2 name = "pervasive-spi" 3 - version = "0.1.0" 3 + version = "0.1.1" 4 4 edition = "2021" 5 5 description = "Bitbang driver for the SPI-derived protocol used by Pervasive Displays e-paper displays" 6 6
+2 -4
pervasive-spi/src/lib.rs
··· 70 70 /// 71 71 /// * `cs`: The chip select pin (output). 72 72 /// * `sda`: The SDA pin. The type must implement both the `WithInput` and `WithOutput` traits. 73 - /// An implementation for both of these on the RP2040 is provided if the `rp2040` 74 - /// feature is enabled. For internal reasons, the trait is implemented on `Option<Pin>` 75 - /// instead of `Pin` on the RP2040, but reading and writing will panic if `None` is 76 - /// provided. 73 + /// If the `rp2040` feature is enabled, the [rp2040] module provides an `IoPin` type 74 + /// implementing both of these for the RP2040. 77 75 /// * `scl`: The SCL pin (output). 78 76 /// * `dc`: The D/C (data/command) pin (output). 79 77 /// * `delay`: An object implementing `PervasiveSpiDelays`, describing delays to be inserted at
+31 -9
pervasive-spi/src/rp2040.rs
··· 3 3 Function, FunctionSioInput, FunctionSioOutput, Pin, PinId, PullType, ValidFunction, 4 4 }; 5 5 6 - impl<I, F, P> WithInput for Option<Pin<I, F, P>> 6 + /// A GPIO pin that can be configured as an input or output. 7 + pub struct IoPin<I, F, P> 7 8 where 8 - I: PinId + ValidFunction<FunctionSioInput> + ValidFunction<F>, 9 + I: PinId + ValidFunction<FunctionSioInput> + ValidFunction<FunctionSioOutput> + ValidFunction<F>, 10 + F: Function, 11 + P: PullType, 12 + { 13 + pin: Option<Pin<I, F, P>>, 14 + } 15 + 16 + impl<I, F, P> IoPin<I, F, P> 17 + where 18 + I: PinId + ValidFunction<FunctionSioInput> + ValidFunction<FunctionSioOutput> + ValidFunction<F>, 19 + F: Function, 20 + P: PullType, 21 + { 22 + /// Create a new instance of `IoPin` with a GPIO pin. 23 + pub fn new(pin: Pin<I, F, P>) -> Self { 24 + Self { pin: Some(pin) } 25 + } 26 + } 27 + 28 + impl<I, F, P> WithInput for IoPin<I, F, P> 29 + where 30 + I: PinId + ValidFunction<FunctionSioInput> + ValidFunction<FunctionSioOutput> + ValidFunction<F>, 9 31 F: Function, 10 32 P: PullType, 11 33 { 12 34 type Input = Pin<I, FunctionSioInput, P>; 13 35 14 36 fn with_input<R>(&mut self, f: impl Fn(&mut Self::Input) -> R) -> R { 15 - let mut input = self.take().unwrap().reconfigure(); 37 + let mut input = self.pin.take().unwrap().reconfigure(); 16 38 let res = f(&mut input); 17 - self.replace(input.reconfigure()); 39 + self.pin.replace(input.reconfigure()); 18 40 res 19 41 } 20 42 } 21 43 22 - impl<I, F, P> WithOutput for Option<Pin<I, F, P>> 44 + impl<I, F, P> WithOutput for IoPin<I, F, P> 23 45 where 24 - I: PinId + ValidFunction<FunctionSioOutput> + ValidFunction<F>, 46 + I: PinId + ValidFunction<FunctionSioInput> + ValidFunction<FunctionSioOutput> + ValidFunction<F>, 25 47 F: Function, 26 48 P: PullType, 27 49 { 28 50 type Output = Pin<I, FunctionSioOutput, P>; 29 51 30 52 fn with_output<R>(&mut self, f: impl Fn(&mut Self::Output) -> R) -> R { 31 - let mut output = self.take().unwrap().reconfigure(); 53 + let mut output = self.pin.take().unwrap().reconfigure(); 32 54 let res = f(&mut output); 33 - self.replace(output.reconfigure()); 55 + self.pin.replace(output.reconfigure()); 34 56 res 35 57 } 36 - } 58 + }
+2 -4
tp370pgh01/src/lib.rs
··· 83 83 /// 84 84 /// * `cs` - Chip select pin (output). 85 85 /// * `sda` - SDA pin (bidirectional). This must implement both the `WithInput` and `WithOutput` 86 - /// traits from the `pervasive-spi` crate. An implementation for the RP2040 is provided 87 - /// in that crate if the `rp2040` feature is enabled. Note that on the RP2040, the pin 88 - /// must be wrapped in the Option, but all display operations will panic if None is 89 - /// provided. 86 + /// traits from the `pervasive-spi` crate. That crate provides a type implementing 87 + /// these traits for the RP2040 if the `rp2040` feature is enabled. 90 88 /// * `sck` - SCK pin (output). 91 89 /// * `dc` - D/C (data/command) pin (output). 92 90 /// * `reset` - Display reset pin (output).
+4
tp370pgh01/src/rp2040.rs
··· 1 1 use pervasive_spi::PervasiveSpiDelays; 2 2 3 + pub use pervasive_spi::rp2040::IoPin; 4 + 5 + /// A type implementing `PervasiveSpiDelays` designed for use with the TP370PGH01 display on the 6 + /// RP2040 (running at its default speed). 3 7 pub struct Rp2040PervasiveSpiDelays; 4 8 5 9 impl PervasiveSpiDelays for Rp2040PervasiveSpiDelays {