use gd32vf103_pac::Peripherals; pub struct LED(); impl LED { pub fn new(peripherals: &Peripherals) -> Self { peripherals.RCU.apb2en.write(|w| { w.paen().set_bit() }); peripherals.GPIOA.ctl0.write(|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(); } } }