Created
December 12, 2017 13:19
-
-
Save naotaco/676f8e2a9b2f664882175ae1ec60f8fd to your computer and use it in GitHub Desktop.
main.rs
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
// Originally published here: https://github.com/avr-rust/blink | |
#![feature(asm, lang_items, unwind_attributes)] | |
#![no_std] | |
#![no_main] | |
extern crate arduino; | |
use arduino::{DDRB, PORTB}; | |
use core::ptr::write_volatile; | |
#[no_mangle] | |
pub extern fn main() { | |
// Set all PORTB pins up as outputs | |
unsafe { write_volatile(DDRB, 0xFF) } | |
loop { | |
// Set all pins on PORTB to high. | |
unsafe { write_volatile(PORTB, 0xFF) } | |
small_delay(); | |
// Set all pins on PORTB to low. | |
unsafe { write_volatile(PORTB, 0x00) } | |
small_delay(); | |
} | |
} | |
/// A small busy loop. | |
fn small_delay() { | |
for _ in 0..400000 { | |
unsafe { asm!("" :::: "volatile")} | |
} | |
} | |
// These do not need to be in a module, but we group them here for clarity. | |
pub mod std { | |
#[lang = "eh_personality"] | |
#[no_mangle] | |
pub unsafe extern "C" fn rust_eh_personality(_state: (), _exception_object: *mut (), _context: *mut ()) -> () { | |
} | |
#[lang = "panic_fmt"] | |
#[unwind] | |
pub extern fn rust_begin_panic(_msg: (), _file: &'static str, _line: u32) -> ! { | |
loop { } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment