From e057fd368e02b5a10efb7a9ee24bbba9f740feeb Mon Sep 17 00:00:00 2001 From: Erin Abicht Date: Fri, 21 Jul 2023 13:06:00 -0400 Subject: [PATCH] Channel works as an async queue im dumb --- src/main.rs | 53 +++++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/src/main.rs b/src/main.rs index a2578c9..21113c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,12 +18,12 @@ use {defmt_rtt as _, panic_probe as _}; static mut CORE1_STACK: Stack<4096> = Stack::new(); static EXECUTOR0: StaticCell = StaticCell::new(); static EXECUTOR1: StaticCell = StaticCell::new(); -static CHANNEL: Channel = Channel::new(); +static BUF_CHANNEL: Channel = Channel::new(); bind_interrupts!(struct Irqs { ADC_IRQ_FIFO => InterruptHandler; }); -const BUF_SIZE: usize = 64; +const BUF_SIZE: usize = 256; #[derive(Format)] enum State { @@ -61,15 +61,15 @@ fn main() -> ! { spawn_core1(p.CORE1, unsafe { &mut CORE1_STACK }, move || { let executor1 = EXECUTOR1.init(Executor::new()); - executor1.run(|spawner| unwrap!(spawner.spawn(core1_task()))); + executor1.run(|spawner| unwrap!(spawner.spawn(process_data()))); }); let executor0 = EXECUTOR0.init(Executor::new()); - executor0.run(|spawner| unwrap!(spawner.spawn(core0_task()))); + executor0.run(|spawner| unwrap!(spawner.spawn(read_eeg()))); } #[embassy_executor::task] -async fn core0_task() { +async fn read_eeg() { let p = embassy_rp::init(Default::default()); let mut adc = Adc::new(p.ADC, Irqs, Config::default()); let mut eeg = Pin::new(p.PIN_26, Pull::None); @@ -85,7 +85,7 @@ async fn core0_task() { // When full, send buffer to be added to the queue loop { if count >= BUF_SIZE { - CHANNEL.send(buf.clone()).await; + BUF_CHANNEL.send(buf.clone()).await; count = 0; } else { buf.0[count] = adc.read(&mut eeg).await.unwrap(); @@ -95,40 +95,21 @@ async fn core0_task() { } #[embassy_executor::task] -async fn core1_task() { - use tinyvec::ArrayVec; - let mut queue = ArrayVec::<[Buffer; 64]>::new(); - - info!("Hello from core 1"); +async fn process_data() { loop { - // Shouldn't block on waiting for message? - // Need to test - queue.push(CHANNEL.recv().await); - - match process_data(&queue[0]).await { - Some(s) => { - info!("Parsed '{}' state from EEG data", &s); - set_servo_position(s).await; - } - None => warn!("Unable to match EEG data to state"), - } - queue.remove(0); + let mut buffer = BUF_CHANNEL.recv().await; + // Low-pass filter + // FFT (w/ hanning window) + info!("Running FFT..."); } } -async fn process_data(buf: &Buffer) -> Option { - // Low-pass filter - // FFT (w/ hanning window) - info!("Running FFT..."); - return None; -} - -async fn set_servo_position(state: State) { - // Use a map of positions for each state, and move the servos towards it - // Use lerp and randomness - // I2C control board manages servos - info!("Setting position to {}", state.servo_positions()); -} +// async fn set_servo_position(state: State) { +// // Use a map of positions for each state, and move the servos towards it +// // Use lerp and randomness +// // I2C control board manages servos +// info!("Setting position to {}", state.servo_positions()); +// } #[inline] fn lerp(v0: f32, v1: f32, t: f32) -> f32 {