-
Notifications
You must be signed in to change notification settings - Fork 9
/
gpio.rs
40 lines (35 loc) · 927 Bytes
/
gpio.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#![allow(dead_code)]
pub enum Port {
PortF = 0x40025000,
}
bitflags! {
flags Pin: u32 {
const PIN0 = (1 << 0),
const PIN1 = (1 << 1),
const PIN2 = (1 << 2),
const PIN3 = (1 << 3),
const PIN4 = (1 << 4),
const PIN5 = (1 << 5),
const PIN6 = (1 << 6),
const PIN7 = (1 << 7),
}
}
extern {
fn GPIOPinTypeGPIOOutput(base: *const u32, mask: u32);
fn GPIOPinWrite(base: *const u32, mask: u32, value: u32);
}
pub fn make_output(port: Port, pin: Pin) {
let mask = pin.bits();
let base = port as u32;
unsafe {
GPIOPinTypeGPIOOutput(base as *const u32, mask);
}
}
pub fn write(port: Port, pin: Pin, value: bool) {
let base = port as u32;
let shifted_val: u32 = pin.bits();
let output_val = if value { pin.bits() } else { 0 };
unsafe {
GPIOPinWrite(base as *const u32, shifted_val, output_val);
}
}