From 8c59a666278fa467732b52014fdb2e2cece9b4aa Mon Sep 17 00:00:00 2001 From: JP Stringham Date: Fri, 3 Apr 2026 17:06:20 -0400 Subject: [PATCH] some morse code ability --- src/main.rs | 88 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 18ce326..8216542 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,10 +72,10 @@ fn main() -> ! { pac.PLL_SYS, xosc.operating_frequency(), PLLConfig { - vco_freq: 1500.MHz(), + vco_freq: 1212.MHz(), refdiv: 1, - post_div1: 5, - post_div2: 4, + post_div1: 6, + post_div2: 1, }, &mut clocks, &mut pac.RESETS, @@ -112,10 +112,12 @@ fn main() -> ! { pwm0.set_div_frac(0); pwm0.clear_interrupt(); pwm0.enable(); + // pwm0.disable(); let mut pwm_pin = pins.gpio16; pwm_pin.set_drive_strength(rp2040_hal::gpio::OutputDriveStrength::TwelveMilliAmps); pwm0.channel_a.output_to(pwm_pin); + pwm0.channel_a.set_enabled(false); let mut on_off_input = pins.gpio15.into_pull_up_input(); @@ -125,9 +127,9 @@ fn main() -> ! { let mut tick = 0u32; let mut last_input = 0u32; - let mut broadcast_on = true; + let mut broadcast_on = false; - let mut current_tune = 65000; + let mut current_tune = 4; const MAX_TUNE: u16 = 65000u16; const MIN_TUNE: u16 = 4u16; @@ -157,7 +159,38 @@ fn main() -> ! { let mut input_mode = InputMode::default(); let mut input_mode_chg_input = pins.gpio12.into_pull_up_input(); - println!("Booted at {}MHz", pll_freq.to_MHz()); + println!("Booted at {}kHz", pll_freq.to_kHz()); + + #[rustfmt::skip] + // CQ CQ CQ VA3FWE VA3FWE + let sequence = [ + 0u8, + 2, 0, 1, 0, 2, 0, 1, 4, // C + 2, 0, 2, 0, 1, 0, 2, 4, 4, // Q + 2, 0, 1, 0, 2, 0, 1, 4, + 2, 0, 2, 0, 1, 0, 2, 4, 4, + 2, 0, 1, 0, 2, 0, 1, 4, + 2, 0, 2, 0, 1, 0, 2, 4, 4, + 4, // wait + 1, 0, 1, 0, 1, 0, 2, 4, // V + 1, 0, 2, 4, // A + 1, 0, 1, 0, 1, 0, 2, 0, 2, 4, // 3 + 1, 0, 1, 0, 2, 0, 1, 4, // F + 1, 0, 2, 0, 2, 4, // W + 1, 4, // E + 4, // wait + 1, 0, 1, 0, 1, 0, 2, 4, // V + 1, 0, 2, 4, // A + 1, 0, 1, 0, 1, 0, 2, 0, 2, 4, // 3 + 1, 0, 1, 0, 2, 0, 1, 4, // F + 1, 0, 2, 0, 2, 4, // W + 1, 4, // E + 0xFF, // wait before calling again + ]; + + let mut morse_sequence_index = 0usize; + let mut last_morse_time = 0u32; + loop { tick = tick.wrapping_add(1); @@ -201,6 +234,37 @@ fn main() -> ! { sh1106_dev.blit_framebuffer(&mut i2c, &mut gfx_buf); } + let morse_delay = match sequence[morse_sequence_index] { + 0 => 100_000, + 1 => 200_000, + 2 => 400_000, + 0xFF => 200_000_000, + _ => 400_000, + }; + + if tick.wrapping_sub(last_morse_time) > morse_delay { + morse_sequence_index = (morse_sequence_index + 1) % sequence.len(); + last_morse_time = tick; + + broadcast_on = match sequence[morse_sequence_index] { + 0 | 4 | 0xFF => false, + _ => true, + }; + + match broadcast_on { + true => { + led_pin.set_high().unwrap(); + pwm0.channel_a.set_enabled(true); + } + false => { + led_pin.set_low().unwrap(); + pwm0.channel_a.set_enabled(false); + } + } + } + + // broadcast_on = on_off_input.is_low().unwrap(); + if tick.wrapping_sub(last_input) < 500_000 { continue; } @@ -221,18 +285,6 @@ fn main() -> ! { info!("Input Mode is now {}", input_mode); } - if on_off_input.is_low().unwrap() { - info!("Broadcast toggle"); - last_input = tick; - broadcast_on = !broadcast_on; - - match broadcast_on { - true => pwm0.enable(), - false => pwm0.disable(), - } - continue; - } - if input_mode == InputMode::DisplayOnly { continue; }