-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlib.rs
More file actions
50 lines (41 loc) · 1.52 KB
/
Copy pathlib.rs
File metadata and controls
50 lines (41 loc) · 1.52 KB
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
41
42
43
44
45
46
47
48
49
50
use std::{thread::sleep, time::Duration};
#[no_mangle]
pub extern "C" fn slo_main() {
println!("Starting LED blinker");
// Configure the LED port
green_led::init();
loop {
// Turn on the LED
green_led::update(true);
sleep(Duration::from_millis(200));
// Turn off the LED
green_led::update(false);
sleep(Duration::from_millis(200));
}
}
mod green_led {
use bcm2711_pac::gpio;
use tock_registers::interfaces::{ReadWriteable, Writeable};
const GPIO_NUM: usize = 42;
fn gpio_regs() -> &'static gpio::Registers {
// Safety: SOLID for RaPi4B provides an identity mapping in this area, and we don't alter
// the mapping
unsafe { &*(gpio::BASE.to_arm_pa().unwrap() as usize as *const gpio::Registers) }
}
pub fn init() {
// Configure the GPIO pin for output
gpio_regs().gpfsel[GPIO_NUM / gpio::GPFSEL::PINS_PER_REGISTER].modify(
gpio::GPFSEL::pin(GPIO_NUM % gpio::GPFSEL::PINS_PER_REGISTER).val(gpio::GPFSEL::OUTPUT),
);
}
pub fn update(new_state: bool) {
if new_state {
gpio_regs().gpset[GPIO_NUM / gpio::GPSET::PINS_PER_REGISTER]
.write(gpio::GPSET::set(GPIO_NUM % gpio::GPSET::PINS_PER_REGISTER));
} else {
gpio_regs().gpclr[GPIO_NUM / gpio::GPCLR::PINS_PER_REGISTER].write(gpio::GPCLR::clear(
GPIO_NUM % gpio::GPCLR::PINS_PER_REGISTER,
));
}
}
}