rktk_drivers_nrf/keyscan/
flex_pin.rs1use embassy_nrf::{
2 Peri,
3 gpio::{Flex, OutputDrive, Pin, Pull as NrfPull},
4};
5pub use rktk_drivers_common::keyscan::duplex_matrix::ScanDir;
6use rktk_drivers_common::keyscan::flex_pin::{FlexPin, Pull};
7
8pub struct NrfFlexPin<'a> {
10 pin: Flex<'a>,
11 pull: NrfPull,
12 drive: OutputDrive,
13}
14
15impl<'a> NrfFlexPin<'a> {
16 pub fn new(pin: Peri<'a, impl Pin>) -> Self {
17 Self { pin: Flex::new(pin), pull: NrfPull::None, drive: OutputDrive::Standard }
18 }
19}
20
21impl FlexPin for NrfFlexPin<'_> {
22 fn set_as_input(&mut self) {
23 #[allow(clippy::needless_match)]
24 let pull = match self.pull {
25 NrfPull::Up => NrfPull::Up,
26 NrfPull::Down => NrfPull::Down,
27 NrfPull::None => NrfPull::None,
28 };
29 self.pin.set_as_input(pull);
30 }
31
32 fn set_as_output(&mut self) {
33 self.pin.set_as_output(self.drive);
34 }
35
36 fn set_low(&mut self) {
37 self.pin.set_low();
38 }
39
40 fn set_high(&mut self) {
41 self.pin.set_high();
42 }
43
44 fn is_high(&self) -> bool {
45 self.pin.is_high()
46 }
47
48 fn is_low(&self) -> bool {
49 self.pin.is_low()
50 }
51
52 async fn wait_for_high(&mut self) {
53 self.pin.wait_for_high().await;
54 }
55
56 async fn wait_for_low(&mut self) {
57 self.pin.wait_for_low().await;
58 }
59
60 fn set_pull(&mut self, pull: Pull) {
61 self.pull = match pull {
62 Pull::Up => NrfPull::Up,
63 Pull::Down => NrfPull::Down,
64 };
65 }
66}