Skip to content
Snippets Groups Projects
Select Git revision
  • 1a4afebbc29bb2feee3c5011b4e74be279a4665c
  • master default protected
2 results

main.rs

Blame
  • Forked from Per Lindgren / e7020e_2021
    Source project has a limited visibility.
    led.rs 769 B
    //! User LEDs
    //!
    //! - PC13
    
    use stm32f103xx::{GPIOC, RCC};
    
    /// LED connected to pin PC13
    pub type LED = PC13;
    
    /// Pin PC13. There's an LED connected to this pin
    pub struct PC13;
    
    /// Initializes the user LED
    pub fn init(gpioc: &GPIOC, rcc: &RCC) {
        // power on GPIOC
        rcc.apb2enr.modify(|_, w| w.iopcen().enabled());
    
        // configure PC13 as output
        gpioc.bsrr.write(|w| w.bs13().set());
        gpioc.crh.modify(|_, w| w.mode13().output().cnf13().push());
    }
    
    impl PC13 {
        /// Turns the LED on
        pub fn on(&self) {
            unsafe {
                (*GPIOC.get()).bsrr.write(|w| w.br13().reset());
            }
        }
    
        /// Turns the LED off
        pub fn off(&self) {
            unsafe {
                (*GPIOC.get()).bsrr.write(|w| w.bs13().set());
            }
        }
    }