Compare commits

...

3 Commits

2 changed files with 12 additions and 25 deletions

View File

@ -4,6 +4,8 @@ version = "0.1.0"
edition = "2021"
[dependencies]
arduino-hal = { git = "https://github.com/rahix/avr-hal", features = ["arduino-uno"] }
panic-halt = "0.2.0"
[profile.release]
lto = true

View File

@ -1,34 +1,19 @@
#![feature(asm_experimental_arch)]
#![no_std]
#![no_main]
use core::arch::asm;
use core::ptr::{read_volatile, write_volatile};
use arduino_hal::delay_ms;
use panic_halt as _;
const DDRB: *mut u8 = 0x24 as *mut u8;
const PORTB: *mut u8 = 0x25 as *mut u8;
#[arduino_hal::entry]
fn main() -> ! {
let peripherals = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(peripherals);
const CPU_SPEED: u32 = 16_000_000;
#[no_mangle]
pub extern "C" fn main() -> ! {
unsafe { write_volatile(DDRB, 0b11111111) };
let mut led = pins.d13.into_output();
led.set_high();
loop {
unsafe { write_volatile(PORTB, 0b00000000) };
sleep(1);
unsafe { write_volatile(PORTB, 0b00100000) };
sleep(1);
led.toggle();
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 {}
}