Compare commits

..

3 Commits

2 changed files with 12 additions and 39 deletions

View File

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

View File

@ -1,48 +1,19 @@
#![feature(asm_experimental_arch)]
#![no_std] #![no_std]
#![no_main] #![no_main]
use core::arch::asm; use arduino_hal::delay_ms;
use core::ptr::{read_volatile, write_volatile}; use panic_halt as _;
/* #[arduino_hal::entry]
PORTC{0..5} Analog fn main() -> ! {
PORTC6 Reset let peripherals = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(peripherals);
PORTB{0..5} Digital {8..13} let mut led = pins.d13.into_output();
PORTD{0..7} Digital {0..7} led.set_high();
PORTB5 LED_BUILTIN
*/
const DDRB: *mut u8 = 0x24 as *mut u8;
const PORTB: *mut u8 = 0x25 as *mut u8;
// ATmega328p cycle speed
const CPU_SPEED: u32 = 16_000_000;
#[no_mangle]
pub extern "C" fn main() -> ! {
// Set all the B pins on OUTPUT mode
unsafe { write_volatile(DDRB, 0b11111111) };
loop { loop {
// if pin[5] == 1: 1^1 = 0 led.toggle();
// if pin[5] == 0: 0^1 = 1 delay_ms(1000);
let mut portb_value = unsafe { read_volatile(PORTB) };
portb_value = portb_value ^ (1 << 5);
unsafe { write_volatile(PORTB, portb_value) };
sleep(1);
} }
} }
fn sleep(time: u32) {
for _ in 0..(CPU_SPEED / 10 * time) {
unsafe { asm!("nop") }
}
}
#[panic_handler]
fn panic(_info: &::core::panic::PanicInfo) -> ! {
loop {}
}