Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
f3/examples/roulette.rs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42 lines (34 sloc)
1.03 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! A LED roulette! | |
#![deny(unsafe_code)] | |
#![deny(warnings)] | |
#![no_std] | |
#![no_main] | |
extern crate panic_semihosting; | |
use cortex_m_rt::entry; | |
use f3::{ | |
hal::{delay::Delay, prelude::*, stm32f30x}, | |
led::Leds, | |
}; | |
#[entry] | |
fn main() -> ! { | |
let cp = cortex_m::Peripherals::take().unwrap(); | |
let dp = stm32f30x::Peripherals::take().unwrap(); | |
let mut flash = dp.FLASH.constrain(); | |
let mut rcc = dp.RCC.constrain(); | |
let gpioe = dp.GPIOE.split(&mut rcc.ahb); | |
// clock configuration using the default settings (all clocks run at 8 MHz) | |
let clocks = rcc.cfgr.freeze(&mut flash.acr); | |
// TRY this alternate clock configuration (all clocks run at 16 MHz) | |
// let clocks = rcc.cfgr.sysclk(16.mhz()).freeze(&mut flash.acr); | |
let mut leds = Leds::new(gpioe); | |
let mut delay = Delay::new(cp.SYST, clocks); | |
let n = leds.len(); | |
loop { | |
for curr in 0..n { | |
let next = (curr + 1) % n; | |
leds[curr].off(); | |
leds[next].on(); | |
delay.delay_ms(100_u8); | |
} | |
} | |
} |