Skip to content

Commit c696a0b

Browse files
committed
Map pins to micro:bit names
Taken from https://github.com/bbcmicrobit/hardware
1 parent ac65801 commit c696a0b

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

src/gpio.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//! Named GPIO pin types
2+
//!
3+
//! This module maps the GPIO pin names as described in the
4+
//! [v1.5 schematic](https://github.com/bbcmicrobit/hardware/tree/master/V1.5).
5+
//! Where appropriate the pins are restricted with the appropriate `MODE`
6+
//! from `nrf-hal`.
7+
#![allow(clippy::upper_case_acronyms)]
8+
use crate::hal::gpio::{p0, Floating, Input, Output, PushPull};
9+
10+
/* GPIO pads */
11+
pub type PAD1<MODE> = p0::P0_03<MODE>;
12+
pub type PAD2<MODE> = p0::P0_02<MODE>;
13+
pub type PAD3<MODE> = p0::P0_01<MODE>;
14+
15+
/* LED display */
16+
pub type COL1 = p0::P0_04<Output<PushPull>>;
17+
pub type COL2 = p0::P0_05<Output<PushPull>>;
18+
pub type COL3 = p0::P0_06<Output<PushPull>>;
19+
pub type COL4 = p0::P0_07<Output<PushPull>>;
20+
pub type COL5 = p0::P0_08<Output<PushPull>>;
21+
pub type COL6 = p0::P0_09<Output<PushPull>>;
22+
pub type COL7 = p0::P0_10<Output<PushPull>>;
23+
pub type COL8 = p0::P0_11<Output<PushPull>>;
24+
pub type COL9 = p0::P0_12<Output<PushPull>>;
25+
26+
pub type ROW1 = p0::P0_13<Output<PushPull>>;
27+
pub type ROW2 = p0::P0_14<Output<PushPull>>;
28+
pub type ROW3 = p0::P0_15<Output<PushPull>>;
29+
30+
/* buttons */
31+
pub type BTN_A = p0::P0_17<Input<Floating>>;
32+
pub type BTN_B = p0::P0_26<Input<Floating>>;
33+
34+
/* spi */
35+
pub type MOSI<MODE> = p0::P0_21<MODE>;
36+
pub type MISO<MODE> = p0::P0_22<MODE>;
37+
pub type SCK<MODE> = p0::P0_23<MODE>;
38+
39+
/* i2c */
40+
pub type SCL = p0::P0_00<Input<Floating>>;
41+
pub type SDA = p0::P0_30<Input<Floating>>;
42+
43+
/* uart */
44+
pub type UART_TX = p0::P0_24<Output<PushPull>>;
45+
pub type UART_RX = p0::P0_25<Input<Floating>>;
46+
47+
/* edge connector */
48+
pub type EDGE01 = COL1;
49+
pub type EDGE02<MODE> = PAD1<MODE>; // <- big pad 1
50+
pub type EDGE03 = COL2;
51+
pub type EDGE04 = BTN_A;
52+
pub type EDGE05 = COL9;
53+
pub type EDGE06 = COL8;
54+
pub type EDGE07<MODE> = PAD2<MODE>; // <- big pad 2
55+
pub type EDGE08<MODE> = p0::P0_18<MODE>;
56+
pub type EDGE09 = COL7;
57+
pub type EDGE10 = COL3;
58+
pub type EDGE11 = BTN_B;
59+
pub type EDGE12<MODE> = p0::P0_20<MODE>;
60+
pub type EDGE13<MODE> = PAD3<MODE>; // <- big pad 3
61+
pub type EDGE14<MODE> = SCK<MODE>;
62+
pub type EDGE15<MODE> = MISO<MODE>;
63+
pub type EDGE16<MODE> = MOSI<MODE>;
64+
pub type EDGE17<MODE> = p0::P0_16<MODE>;
65+
// EDGE18 -> +V
66+
// EDGE19 -> +V
67+
// EDGE20 -> +V
68+
pub type EDGE21 = SCL;
69+
pub type EDGE22 = SDA;
70+
// EDGE23 -> GND
71+
// EDGE24 -> GND
72+
// EDGE25 -> GND

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub use nrf51_hal as hal;
88
pub use nb::*;
99

1010
pub mod display;
11+
pub mod gpio;
1112
pub mod led;
1213

1314
#[macro_export]

0 commit comments

Comments
 (0)