From 35248b205cd56633e52b9e634a942e7fd987db0b Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Sat, 6 Aug 2022 12:12:37 -0400 Subject: =?UTF-8?q?Blinky=20on=20a=20hardware=20timer,=20with=20=E2=80=98w?= =?UTF-8?q?fi=E2=80=99=20in=20between.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/led.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/led.rs') diff --git a/src/led.rs b/src/led.rs index d8d9912..951a32e 100644 --- a/src/led.rs +++ b/src/led.rs @@ -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 { -- cgit v1.2.3