microbit_common/v2/
gpio.rs1#![allow(clippy::upper_case_acronyms, missing_docs)]
2use nrf52833_hal::gpio::{p0, p1, Floating, Input, OpenDrain, Output, Pin, PushPull};
3
4pub type PAD0<MODE> = p0::P0_02<MODE>;
6pub type PAD1<MODE> = p0::P0_03<MODE>;
7pub type PAD2<MODE> = p0::P0_04<MODE>;
8
9pub const NUM_COLS: usize = 5;
11pub type COL1 = p0::P0_28<Output<PushPull>>;
12pub type COL2 = p0::P0_11<Output<PushPull>>;
13pub type COL3 = p0::P0_31<Output<PushPull>>;
14pub type COL4 = p1::P1_05<Output<PushPull>>;
15pub type COL5 = p0::P0_30<Output<PushPull>>;
16
17pub const NUM_ROWS: usize = 5;
18pub type ROW1 = p0::P0_21<Output<PushPull>>;
19pub type ROW2 = p0::P0_22<Output<PushPull>>;
20pub type ROW3 = p0::P0_15<Output<PushPull>>;
21pub type ROW4 = p0::P0_24<Output<PushPull>>;
22pub type ROW5 = p0::P0_19<Output<PushPull>>;
23
24pub struct DisplayPins {
28 pub col1: COL1,
29 pub col2: COL2,
30 pub col3: COL3,
31 pub col4: COL4,
32 pub col5: COL5,
33 pub row1: ROW1,
34 pub row2: ROW2,
35 pub row3: ROW3,
36 pub row4: ROW4,
37 pub row5: ROW5,
38}
39
40pub struct MicrophonePins {
42 pub mic_in: p0::P0_05<Input<Floating>>,
43 pub mic_run: p0::P0_20<Output<OpenDrain>>,
44}
45
46type LED = Pin<Output<PushPull>>;
47
48impl DisplayPins {
49 pub fn degrade(self) -> ([LED; NUM_COLS], [LED; NUM_ROWS]) {
50 (
51 [
52 self.col1.degrade(),
53 self.col2.degrade(),
54 self.col3.degrade(),
55 self.col4.degrade(),
56 self.col5.degrade(),
57 ],
58 [
59 self.row1.degrade(),
60 self.row2.degrade(),
61 self.row3.degrade(),
62 self.row4.degrade(),
63 self.row5.degrade(),
64 ],
65 )
66 }
67}
68
69#[macro_export]
91macro_rules! display_pins {
92 ( $p0parts:expr, $p1parts:expr ) => {{
93 use microbit::{gpio::DisplayPins, hal::gpio::Level};
94
95 DisplayPins {
96 col1: $p0parts.p0_28.into_push_pull_output(Level::Low),
97 col2: $p0parts.p0_11.into_push_pull_output(Level::Low),
98 col3: $p0parts.p0_31.into_push_pull_output(Level::Low),
99 col4: $p1parts.p1_05.into_push_pull_output(Level::Low),
100 col5: $p0parts.p0_30.into_push_pull_output(Level::Low),
101 row1: $p0parts.p0_21.into_push_pull_output(Level::Low),
102 row2: $p0parts.p0_22.into_push_pull_output(Level::Low),
103 row3: $p0parts.p0_15.into_push_pull_output(Level::Low),
104 row4: $p0parts.p0_24.into_push_pull_output(Level::Low),
105 row5: $p0parts.p0_19.into_push_pull_output(Level::Low),
106 }
107 }};
108}
109
110pub type BTN_A = p0::P0_14<Input<Floating>>;
112pub type BTN_B = p0::P0_23<Input<Floating>>;
113
114pub type MOSI<MODE> = p0::P0_13<MODE>;
116pub type MISO<MODE> = p0::P0_01<MODE>;
117pub type SCK<MODE> = p0::P0_17<MODE>;
118
119pub type INT_SCL = p0::P0_08<Input<Floating>>;
121pub type INT_SDA = p0::P0_16<Input<Floating>>;
122
123pub type SCL = p0::P0_26<Input<Floating>>;
125pub type SDA = p1::P1_00<Input<Floating>>;
126
127pub type UART_TX = p0::P0_06<Output<PushPull>>;
129pub type UART_RX = p1::P1_08<Input<Floating>>;
130
131pub type SPEAKER = p0::P0_00<Output<PushPull>>;
133
134pub type EDGE03 = COL3;
136pub type EDGE00<MODE> = PAD0<MODE>; pub type EDGE04 = COL1;
138pub type EDGE05 = BTN_A;
139pub type EDGE06 = COL4;
140pub type EDGE07 = COL2;
141pub type EDGE01<MODE> = PAD1<MODE>; pub type EDGE08<MODE> = p0::P0_10<MODE>;
143pub type EDGE09<MODE> = p0::P0_09<MODE>;
144pub type EDGE10 = COL5;
145pub type EDGE11 = BTN_B;
146pub type EDGE12<MODE> = p0::P0_12<MODE>;
147pub type EDGE02<MODE> = PAD2<MODE>; pub type EDGE13<MODE> = SCK<MODE>;
149pub type EDGE14<MODE> = MISO<MODE>;
150pub type EDGE15<MODE> = MOSI<MODE>;
151pub type EDGE16<MODE> = p1::P1_02<MODE>;
152pub type EDGE19 = SCL;
156pub type EDGE20 = SDA;
157