Skip to content

Instantly share code, notes, and snippets.

@naotaco naotaco/main.rs
Created Dec 12, 2017

Embed
What would you like to do?
main.rs
// 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
You can’t perform that action at this time.