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