-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathblinky_generic.rs
58 lines (48 loc) · 1.46 KB
/
blinky_generic.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Blinks several LEDs stored in an array
#![deny(unsafe_code)]
#![no_std]
#![no_main]
use panic_halt as _;
use core::hint::spin_loop;
use cortex_m_rt::entry;
use embedded_hal::digital::OutputPin;
use gd32f1x0_hal::{pac, prelude::*, timer::Timer};
#[entry]
fn main() -> ! {
let cp = cortex_m::Peripherals::take().unwrap();
let dp = pac::Peripherals::take().unwrap();
let mut rcu = dp.rcu.constrain();
let mut flash = dp.fmc.constrain();
let clocks = rcu.cfgr.freeze(&mut flash.ws);
// Acquire the GPIO peripherals
let mut gpioa = dp.gpioa.split(&mut rcu.ahb);
let mut gpioc = dp.gpioc.split(&mut rcu.ahb);
// Configure the syst timer to trigger an update every second
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz());
// Create an array of LEDS to blink
let mut leds = [
gpioc
.pc13
.into_push_pull_output(&mut gpioc.config)
.downgrade(),
gpioa
.pa1
.into_push_pull_output(&mut gpioa.config)
.downgrade(),
];
// Wait for the timer to trigger an update and change the state of the LED
loop {
while !timer.has_elapsed() {
spin_loop();
}
for led in leds.iter_mut() {
led.set_high().unwrap();
}
while !timer.has_elapsed() {
spin_loop();
}
for led in leds.iter_mut() {
led.set_low().unwrap();
}
}
}