diff options
Diffstat (limited to 'sw/dart-70/src/main.rs')
-rw-r--r-- | sw/dart-70/src/main.rs | 92 |
1 files changed, 80 insertions, 12 deletions
diff --git a/sw/dart-70/src/main.rs b/sw/dart-70/src/main.rs index 77f6044..7967b23 100644 --- a/sw/dart-70/src/main.rs +++ b/sw/dart-70/src/main.rs @@ -58,7 +58,7 @@ struct SharedWithISR { state: State, last_sequence_state_change: u32, cw_ptt_timestamp: u32, - cw_key_n: gpio::gpioa::PA15<gpio::Output<gpio::OpenDrain>>, + cw_key_n: gpio::gpioa::PA15<gpio::Output<gpio::PushPull>>, ui: ui::UI, cw_pwm: cw::CWPWM, cw_keyer: cw::Keyer, @@ -70,6 +70,7 @@ struct SharedWithISR { mute_spkr: gpio::gpioa::PA2<gpio::Output<gpio::PushPull>>, mute_micn: gpio::gpioa::PA1<gpio::Output<gpio::PushPull>>, led: gpio::gpiob::PB14<gpio::Output<gpio::OpenDrain>>, + vox_ptt_n : gpio::gpioa::PA0<gpio::Input<gpio::PullUp>>, } static mut SHARED: MaybeUninit<SharedWithISR> = MaybeUninit::uninit(); @@ -116,7 +117,7 @@ fn main() -> ! { let btn2 = gpiob.pb12.into_floating_input(&mut gpiob.crh); // BTN2 Button C let btn3 = gpiob.pb13.into_floating_input(&mut gpiob.crh); // BTN3 Button D let pc15 = gpioc.pc15.into_floating_input(&mut gpioc.crh); // ENC BTN - let ui = ui::UI::new(mic_ptt, vox_ptt_n, btn0, btn1, btn2, btn3, pc15); + let ui = ui::UI::new(mic_ptt, btn0, btn1, btn2, btn3, pc15); let cw_pwm = { let pa8 = gpioa.pa8.into_alternate_push_pull(&mut gpioa.crh); // CW PWM output using TIM1 Ch1 @@ -137,7 +138,7 @@ fn main() -> ! { led.set_low(); let (pa15, pb3, pb4) = afio.mapr.disable_jtag(gpioa.pa15, gpiob.pb3, gpiob.pb4); - let cw_key_n = pa15.into_open_drain_output_with_state(&mut gpioa.crh, PinState::High); + let cw_key_n = pa15.into_push_pull_output_with_state(&mut gpioa.crh, PinState::High); let en_pa = pb3.into_push_pull_output_with_state(&mut gpiob.crl, PinState::Low); let en_rx = pb4.into_push_pull_output_with_state(&mut gpiob.crl, PinState::Low); @@ -223,7 +224,7 @@ fn main() -> ! { ui, cw_pwm, cw_keyer : cw::Keyer::new(12, TICKS_PER_SECOND), - cw_paddle_tip, cw_paddle_ring, en_pa, en_rx, en_tx, mute_spkr, mute_micn, led + cw_paddle_tip, cw_paddle_ring, en_pa, en_rx, en_tx, mute_spkr, mute_micn, led, vox_ptt_n }; si_clock::SiClock::new(i2c_busmanager.acquire_i2c(), shared.state.bfo(), shared.state.vfo()) @@ -322,6 +323,7 @@ fn s_meter_from_adc(adc : u16) -> u8 { // ADC is 12-bit, convert to dB full-scale let adc_db = 10f32 * log10f::log10f(adc / 4092f32); + /* /* Hand-calibrated lookup table */ if adc_db <= -35f32 { 1 @@ -340,6 +342,17 @@ fn s_meter_from_adc(adc : u16) -> u8 { } else { 9 + } */ + + let fake_s = -adc_db; + if fake_s < 0.0 { + 0 + } + else if fake_s > 255.0 { + 255 + } + else { + fake_s as u8 } } @@ -351,7 +364,7 @@ fn TIM2() { let ticks = unsafe { &mut *TICK_COUNTER.as_mut_ptr() }; *ticks += 1; - let mut shared = unsafe { &mut *SHARED.as_mut_ptr() }; + let shared = unsafe { &mut *SHARED.as_mut_ptr() }; let button_result = shared.ui.handle_buttons(&mut shared.state); if button_result.display_update { @@ -380,12 +393,21 @@ fn TIM2() { _ => false, }; - let cw_beep = shared.state.send_tone || + let cw_beep = if shared.state.send_tone { + shared.cw_keyer.tick(*ticks, false, true) + } + else { match shared.state.mode { Mode::CW(CWMode::StraightKey) => cw_paddle_tip_low, Mode::CW(CWMode::Iambic) => shared.cw_keyer.tick(*ticks, cw_paddle_tip_low, cw_paddle_ring_low), _ => false, - }; + } + }; + + let dig_ptt = match shared.state.mode { + Mode::DIG => shared.vox_ptt_n.is_low(), + _ => false, + }; let next_state = match shared.state.sequence_state { SequenceState::Rx => { @@ -394,7 +416,15 @@ fn TIM2() { shared.en_rx.set_high(); shared.en_tx.set_low(); shared.en_pa.set_low(); - if button_result.ptt || cw_ptt { + shared.led.set_high(); + + let mode_relevant_ptt = match shared.state.mode { + Mode::CW(_) => cw_ptt, + Mode::DIG => dig_ptt, + _ => button_result.ptt, + }; + + if mode_relevant_ptt { SequenceState::MutingSpkr } else { @@ -413,6 +443,9 @@ fn TIM2() { else if cw_ptt { SequenceState::SwitchingCW } + else if dig_ptt { + SequenceState::SwitchingDIG + } else { SequenceState::Rx } @@ -444,10 +477,25 @@ fn TIM2() { SequenceState::Rx } }, + SequenceState::SwitchingDIG => { + shared.mute_spkr.set_high(); + shared.en_rx.set_low(); + shared.en_tx.set_high(); + shared.en_pa.set_low(); + shared.mute_micn.set_high(); + + if dig_ptt { + SequenceState::TxDIG + } + else { + SequenceState::Rx + } + }, SequenceState::TxSSB => { shared.en_rx.set_low(); shared.en_tx.set_high(); shared.en_pa.set_high(); + shared.led.set_low(); if button_result.ptt { SequenceState::TxSSB @@ -457,10 +505,19 @@ fn TIM2() { } }, SequenceState::TxCW => { + shared.mute_spkr.set_low(); shared.en_rx.set_low(); shared.en_tx.set_high(); shared.en_pa.set_high(); + if cw_beep { + shared.led.set_low(); + } + else { + shared.led.set_high(); + } + + if cw_ptt { SequenceState::TxCW } @@ -468,29 +525,40 @@ fn TIM2() { SequenceState::SwitchingCW } }, + SequenceState::TxDIG => { + shared.mute_spkr.set_high(); + shared.en_rx.set_low(); + shared.en_tx.set_high(); + shared.en_pa.set_high(); + shared.led.set_low(); + + if dig_ptt { + SequenceState::TxDIG + } + else { + SequenceState::SwitchingDIG + } + }, }; match shared.state.sequence_state { SequenceState::TxCW => { if cw_beep { - shared.led.set_low(); shared.cw_pwm.on(); shared.cw_key_n.set_low(); } else { - shared.led.set_high(); shared.cw_pwm.off(); shared.cw_key_n.set_high(); } }, _ => { - shared.led.set_high(); shared.cw_pwm.off(); shared.cw_key_n.set_high(); }, } - const SWITCHING_DELAY : u32 = TICKS_PER_SECOND * 80 / 1000; + const SWITCHING_DELAY : u32 = TICKS_PER_SECOND * 20 / 1000; if shared.state.sequence_state != next_state && shared.last_sequence_state_change + SWITCHING_DELAY <= *ticks { shared.state.sequence_state = next_state; |