diff --git a/2sem_sem2/src/bin/main.rs b/2sem_sem2/src/bin/main.rs index 58dd020..35dede4 100644 --- a/2sem_sem2/src/bin/main.rs +++ b/2sem_sem2/src/bin/main.rs @@ -5,8 +5,9 @@ use core::sync::atomic::{AtomicBool, Ordering}; use defmt::info; use embassy_executor::Spawner; +use embassy_stm32::exti; use embassy_stm32::gpio; -use embassy_stm32::gpio::Output; +use embassy_stm32::gpio::{Input, Output, Pull}; use embassy_stm32::usart::{Config, InterruptHandler, Uart, UartRx, UartTx}; use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_sync::channel::Channel; @@ -26,8 +27,7 @@ async fn main(spawner: Spawner) { let p = embassy_stm32::init(Default::default()); let mut tx = Output::new(p.PF2, gpio::Level::High, gpio::Speed::VeryHigh); - // let _rx = Input::new(p.PA3, Pull::Up); - // let _tx = Output::new(p.PA2, Level::High, Speed::VeryHigh); + let rx = Input::new(p.PA3, Pull::Up); let config = Config::default(); let sender = PIPE.sender(); @@ -38,9 +38,6 @@ async fn main(spawner: Spawner) { info!("starting echo"); let mut v: Vec = Vec::new(); - // let data = b"filip\r\n"; - // let idle = &[0x13u8]; - loop { let slovko = "ahoj"; info!("slovo: {}", slovko); @@ -49,19 +46,7 @@ async fn main(spawner: Spawner) { info!("enkodovane, posielame do pipy..."); nrz(&v, &sender).await; - // let current_send_allowed = SEND_ALLOWED.load(Ordering::Relaxed); - // let current_rec_allowed = REC_ALLOWED.load(Ordering::Relaxed); - // if current_rec_allowed == true { - // if current_send_allowed { - // if let Ok(stored_byte) = receiver.try_receive() { - // // TODO - // // let _ = tx.write(&[stored_byte]).await; - // } else { - // // TODO - // // let _ = tx.write(data).await; - // } - // } - // } + let _ = Timer::after(Duration::from_millis(1000)); embassy_time::block_for(Duration::from_millis(1000)); } @@ -121,3 +106,12 @@ async fn bit_send(mut pin: Output<'static>) { ticker.next().await; } } + +#[embassy_executor::task] +async fn bit_receive(mut pin: Input<'static>) { + let mut ticker = Ticker::every(Duration::from_millis(10)); + loop { + // bitrate + ticker.next().await; + } +}