60 lines
1.6 KiB
Rust
60 lines
1.6 KiB
Rust
use core::sync::atomic::AtomicU8;
|
|
|
|
use embassy_rp::clocks::RoscRng;
|
|
|
|
use embassy_rp::pwm;
|
|
use embassy_time::Timer;
|
|
use rand::RngCore;
|
|
|
|
use crate::scanner::LOCKOUT;
|
|
|
|
pub static WAGS: AtomicU8 = AtomicU8::new(0);
|
|
|
|
use embassy_rp::pwm::Pwm;
|
|
|
|
use embassy_rp::peripherals::PIN_27;
|
|
|
|
use embassy_rp::peripherals::PIN_26;
|
|
|
|
use embassy_rp::peripherals::PWM_SLICE5;
|
|
|
|
#[embassy_executor::task]
|
|
pub async fn wiggle_manager(pwm: PWM_SLICE5, head: PIN_26, tail: PIN_27) -> ! {
|
|
let mut c: pwm::Config = Default::default();
|
|
c.divider = 40.into();
|
|
c.top = 62_500; // 20ms
|
|
c.compare_a = 4687; // 1.5ms
|
|
c.compare_b = 4687; // 1.5ms
|
|
let mut pwm = Pwm::new_output_ab(pwm, head, tail, c.clone());
|
|
|
|
loop {
|
|
let mut wags;
|
|
loop {
|
|
// atomics aren't actually real
|
|
wags = WAGS.load(core::sync::atomic::Ordering::SeqCst);
|
|
if wags != 0 {
|
|
WAGS.store(0, core::sync::atomic::Ordering::SeqCst);
|
|
LOCKOUT.store(true, core::sync::atomic::Ordering::SeqCst);
|
|
break;
|
|
}
|
|
|
|
c.compare_b = 6248;
|
|
pwm.set_config(&c);
|
|
|
|
Timer::after_millis(50).await;
|
|
LOCKOUT.store(false, core::sync::atomic::Ordering::SeqCst);
|
|
}
|
|
|
|
let positions = [6200,4800,6248,4700, 5500];
|
|
|
|
let mut rng = RoscRng;
|
|
for _ in 0..wags {
|
|
|
|
let idx = rng.next_u32();
|
|
c.compare_b = positions[idx as usize % positions.len()];
|
|
pwm.set_config(&c);
|
|
|
|
Timer::after_millis(idx as u64 % 600).await;
|
|
}
|
|
}
|
|
}
|