Now blink using a HAL
parent
fa6f69cab4
commit
5b2648440f
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
ruduino = { git = "https://github.com/avr-rust/ruduino", branch = "master" }
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
|
32
src/main.rs
32
src/main.rs
|
@ -1,34 +1,18 @@
|
|||
#![feature(asm_experimental_arch)]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use core::arch::asm;
|
||||
use core::ptr::{read_volatile, write_volatile};
|
||||
|
||||
const DDRB: *mut u8 = 0x24 as *mut u8;
|
||||
const PORTB: *mut u8 = 0x25 as *mut u8;
|
||||
|
||||
const CPU_SPEED: u32 = 16_000_000;
|
||||
use ruduino::cores::current::port::B5 as led;
|
||||
use ruduino::delay::delay_ms;
|
||||
use ruduino::Pin;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn main() -> ! {
|
||||
unsafe { write_volatile(DDRB, 0b11111111) };
|
||||
led::set_output();
|
||||
|
||||
loop {
|
||||
unsafe { write_volatile(PORTB, 0b00000000) };
|
||||
sleep(1);
|
||||
unsafe { write_volatile(PORTB, 0b00100000) };
|
||||
sleep(1);
|
||||
led::set_high();
|
||||
delay_ms(1000);
|
||||
led::set_low();
|
||||
delay_ms(1000);
|
||||
}
|
||||
}
|
||||
|
||||
fn sleep(time: u32) {
|
||||
for _ in 0..(CPU_SPEED / 10 * time) {
|
||||
unsafe { asm!("nop") }
|
||||
}
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &::core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue