use gd32vf103_pac::Peripherals; #[derive(Clone, Copy)] pub struct LED(); impl LED { pub fn new() -> Self { let peripherals = unsafe { Peripherals::steal() }; peripherals.RCU.apb2en.modify(|_, w| { w.paen().set_bit() }); peripherals.GPIOA.ctl0.modify(|_, w| unsafe { // output mode, push-pull w.ctl7().bits(0b00); // 50 mhz output rate w.md7().bits(0b11); w }); Self() } pub fn is_on(&self) -> bool { let gpio = unsafe { Peripherals::steal() }.GPIOA; gpio.octl.read().octl7().bit() } pub fn on(&self) { let gpio = unsafe { Peripherals::steal() }.GPIOA; gpio.bop.write(|w| w.bop7().set_bit()); } pub fn off(&self) { let gpio = unsafe { Peripherals::steal() }.GPIOA; gpio.bc.write(|w| w.cr7().set_bit()); } pub fn toggle(&self) { if self.is_on() { self.off(); } else { self.on(); } } }