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.

at a3ff1f4e4e2aaec4a4c1ec5def91c21d36dc12f7 58 lines 1.7 kB view raw
1use crate::{WithInput, WithOutput}; 2use rp2040_hal::gpio::{ 3 Function, FunctionSioInput, FunctionSioOutput, Pin, PinId, PullType, ValidFunction, 4}; 5 6/// A GPIO pin that can be configured as an input or output. 7pub struct IoPin<I, F, P> 8where 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 16impl<I, F, P> IoPin<I, F, P> 17where 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 28impl<I, F, P> WithInput for IoPin<I, F, P> 29where 30 I: PinId + ValidFunction<FunctionSioInput> + ValidFunction<FunctionSioOutput> + ValidFunction<F>, 31 F: Function, 32 P: PullType, 33{ 34 type Input = Pin<I, FunctionSioInput, P>; 35 36 fn with_input<R>(&mut self, f: impl Fn(&mut Self::Input) -> R) -> R { 37 let mut input = self.pin.take().unwrap().reconfigure(); 38 let res = f(&mut input); 39 self.pin.replace(input.reconfigure()); 40 res 41 } 42} 43 44impl<I, F, P> WithOutput for IoPin<I, F, P> 45where 46 I: PinId + ValidFunction<FunctionSioInput> + ValidFunction<FunctionSioOutput> + ValidFunction<F>, 47 F: Function, 48 P: PullType, 49{ 50 type Output = Pin<I, FunctionSioOutput, P>; 51 52 fn with_output<R>(&mut self, f: impl Fn(&mut Self::Output) -> R) -> R { 53 let mut output = self.pin.take().unwrap().reconfigure(); 54 let res = f(&mut output); 55 self.pin.replace(output.reconfigure()); 56 res 57 } 58}