From 6fc354b0bcb6ca5c008493632c8d324ac22f640b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=9CM=C3=9C=C5=9E?= <96421894+Tahinli@users.noreply.github.com> Date: Mon, 8 Jan 2024 20:27:57 +0300 Subject: [PATCH] feat: timer --- src/timer.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/timer.rs diff --git a/src/timer.rs b/src/timer.rs new file mode 100644 index 0000000..fb291d3 --- /dev/null +++ b/src/timer.rs @@ -0,0 +1,56 @@ +#![no_std] +#![no_main] + +use core::cell::RefCell; +use avr_device::interrupt; +use panic_halt as _; + +type Console = arduino_hal::hal::usart::Usart0; +static CONSOLE: interrupt::Mutex>> = interrupt::Mutex::new(RefCell::new(None)); + +macro_rules! println { + ($($t:tt)*) => { + interrupt::free( + |cs| + { + if let Some(console) = CONSOLE.borrow(cs).borrow_mut().as_mut() + { + let _ = ufmt::uwriteln!(console, $($t)*); + } + } + ) + + }; +} + +fn put_console(console:Console) + { + interrupt::free( + |cs| + { + *CONSOLE.borrow(cs).borrow_mut() = Some(console); + } + ) + } +#[arduino_hal::entry] +fn main() -> ! { + let dp = arduino_hal::Peripherals::take().unwrap(); + let pins = arduino_hal::pins!(dp); + let serial = arduino_hal::default_serial!(dp, pins, 57600); + put_console(serial); + println!("Hello World"); + + + let mut pin2 = pins.d2.into_output(); + let mut pin13 = pins.d13.into_output(); + loop { + for i in 0..60 + { + println!("{}", i); + pin2.toggle(); + arduino_hal::delay_ms(1000); + pin13.toggle(); + } + println!("Minute"); + } +}