Initial commit
This commit is contained in:
63
src/main.rs
Normal file
63
src/main.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
use cortex_m::peripheral::{syst, Peripherals};
|
||||
use cortex_m_rt::{entry, exception};
|
||||
use cortex_m_semihosting::hprintln;
|
||||
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use nrf52832_hal as hal;
|
||||
use nrf52832_hal::gpio::Level;
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
const F_CPU:u32 = 64_000_000;
|
||||
|
||||
static mut FIRE_1S:bool = false;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
hprintln!("Hello, world!").unwrap();
|
||||
|
||||
let peripherals = Peripherals::take().unwrap();
|
||||
let mut systick = peripherals.SYST;
|
||||
systick.set_clock_source(syst::SystClkSource::Core);
|
||||
systick.set_reload(F_CPU / 1000 - 1);
|
||||
systick.clear_current();
|
||||
systick.enable_interrupt();
|
||||
systick.enable_counter();
|
||||
|
||||
let p = hal::pac::Peripherals::take().unwrap();
|
||||
let port0 = hal::gpio::p0::Parts::new(p.P0);
|
||||
let mut led = port0.p0_17.into_push_pull_output(Level::Low);
|
||||
led.set_low().unwrap();
|
||||
|
||||
let mut state:bool = false;
|
||||
loop {
|
||||
unsafe {
|
||||
if FIRE_1S {
|
||||
FIRE_1S = false;
|
||||
if state {
|
||||
hprintln!("off").unwrap();
|
||||
led.set_low().unwrap();
|
||||
state = false;
|
||||
} else {
|
||||
hprintln!("on").unwrap();
|
||||
led.set_high().unwrap();
|
||||
state = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[exception]
|
||||
fn SysTick() {
|
||||
static mut CNT:u32 = 0;
|
||||
*CNT += 1;
|
||||
if *CNT == 1000 {
|
||||
*CNT = 0;
|
||||
unsafe {
|
||||
FIRE_1S = true;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user