diff options
author | Brian Cully <bjc@kublai.com> | 2022-08-06 12:12:37 -0400 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2022-08-06 12:12:37 -0400 |
commit | 35248b205cd56633e52b9e634a942e7fd987db0b (patch) | |
tree | 37c9fd21e52e7cb0a7c547065a52d73d19d925b9 /src/led.rs | |
parent | 8f9bc49bb40e2972cf0c0bf1b61eb8127a9397df (diff) | |
download | luchie-35248b205cd56633e52b9e634a942e7fd987db0b.tar.gz luchie-35248b205cd56633e52b9e634a942e7fd987db0b.zip |
Blinky on a hardware timer, with ‘wfi’ in between.
Diffstat (limited to 'src/led.rs')
-rw-r--r-- | src/led.rs | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -1,21 +1,23 @@ use gd32vf103_pac::Peripherals; +#[derive(Clone, Copy)] pub struct LED(); impl LED { - pub fn new(peripherals: &Peripherals) -> Self { - peripherals.RCU.apb2en.write(|w| { + pub fn new() -> Self { + let peripherals = unsafe { Peripherals::steal() }; + peripherals.RCU.apb2en.modify(|_, w| { w.paen().set_bit() }); - peripherals.GPIOA.ctl0.write(|w| unsafe { + peripherals.GPIOA.ctl0.modify(|_, w| unsafe { // output mode, push-pull w.ctl7().bits(0b00); // 50 mhz output rate w.md7().bits(0b11); w }); - Self {} + Self() } pub fn is_on(&self) -> bool { |