aboutsummaryrefslogtreecommitdiffstats
path: root/sw/picardy/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'sw/picardy/src/main.rs')
-rw-r--r--sw/picardy/src/main.rs102
1 files changed, 64 insertions, 38 deletions
diff --git a/sw/picardy/src/main.rs b/sw/picardy/src/main.rs
index b5efbdd..6d1d803 100644
--- a/sw/picardy/src/main.rs
+++ b/sw/picardy/src/main.rs
@@ -43,20 +43,25 @@ use stm32f1xx_hal::{
};
use embedded_hal::digital::v2::OutputPin;
+#[cfg(feature = "cw")]
+use embedded_hal::digital::v2::InputPin;
use hd44780_driver::{Cursor, CursorBlink, Display, DisplayMode, HD44780};
pub mod ui;
+pub mod cw;
pub mod state;
pub mod si_clock;
pub mod log10f;
use state::*;
+const TICKS_PER_SECOND : u32 = 50;
+
static mut CLOCK_TIMER: MaybeUninit<CountDownTimer<pac::TIM2>> = MaybeUninit::uninit();
-static mut DECISECONDS_COUNTER: MaybeUninit<usize> = MaybeUninit::uninit();
+static mut TICK_COUNTER: MaybeUninit<u32> = MaybeUninit::uninit();
-fn time_now() -> usize {
- cortex_m::interrupt::free(|_cs| unsafe { *DECISECONDS_COUNTER.as_ptr() })
+fn ticks_now() -> u32 {
+ cortex_m::interrupt::free(|_cs| unsafe { *TICK_COUNTER.as_ptr() })
}
#[cortex_m_rt::entry]
@@ -91,6 +96,16 @@ fn main() -> ! {
let adc1 = dp.ADC1;
let mut ui = ui::UI::new(mic_sw1, mic_sw2, pb0, pb1, adc1, &mut rcc.apb2, &clocks, pb12, pb13, pc15);
+
+#[cfg(feature = "cw")]
+ let (mut cwpwm, cw_paddle_tip) = {
+ let pa8 = gpioa.pa8.into_alternate_push_pull(&mut gpioa.crh); // CW PWM output using TIM1 Ch1
+ let tim1 = Timer::tim1(dp.TIM1, &clocks, &mut rcc.apb2);
+ let cwpwm = cw::CWPWM::new(pa8, tim1, &mut afio.mapr);
+ let cw_paddle_tip = gpiob.pb8.into_pull_up_input(&mut gpiob.crh); // CW paddle tip
+ (cwpwm, cw_paddle_tip)
+ };
+
let mut s_meter = gpioa.pa5.into_analog(&mut gpioa.crl);
let mut adc2 = adc::Adc::adc2(dp.ADC2, &mut rcc.apb2, clocks);
let mut last_s_meter_update_time = 0;
@@ -185,14 +200,14 @@ fn main() -> ! {
let mut last_encoder_count = qei.count();
{
- let deciseconds_counter = unsafe { &mut *DECISECONDS_COUNTER.as_mut_ptr() };
- *deciseconds_counter = 0;
+ let ticks = unsafe { &mut *TICK_COUNTER.as_mut_ptr() };
+ *ticks = 0;
}
{
let timer = unsafe { &mut *CLOCK_TIMER.as_mut_ptr() };
*timer = Timer::tim2(dp.TIM2, &clocks, &mut rcc.apb1)
- .start_count_down(50.hz());
+ .start_count_down(TICKS_PER_SECOND.hz());
timer.listen(Event::Update);
}
@@ -201,6 +216,9 @@ fn main() -> ! {
loop {
let mut update_disp_required = false;
+ let previous_vfo = state.vfo();
+ let previous_bfo = state.bfo();
+
let encoder_count : u16 = qei.count();
if encoder_count != last_encoder_count {
let delta = encoder_count.wrapping_sub(last_encoder_count);
@@ -215,63 +233,63 @@ fn main() -> ! {
let button_result = ui.handle_buttons(&mut state);
- if button_result.bfo_update {
+ if previous_bfo != state.bfo() {
state.bfo_tune_fail = !siclock.set_bfo(state.bfo()).is_ok();
}
+ if previous_vfo != state.vfo() {
+ siclock.set_vfo(state.vfo());
+ }
+
update_disp_required |= button_result.display_update;
let next_state = match state.sequence_state {
SequenceState::Rx => {
led.set_high().unwrap();
+
+ mute_spkr.set_low().unwrap();
+ mute_micn.set_low().unwrap();
+ seq2_switch.set_low().unwrap();
+ seq0n.set_high().unwrap();
+
if button_result.ptt {
- mute_spkr.set_high().unwrap();
- mute_micn.set_high().unwrap();
- seq2_switch.set_high().unwrap();
- SequenceState::ToTxStep1
+ SequenceState::Switching
}
else {
- mute_spkr.set_low().unwrap();
- mute_micn.set_low().unwrap();
SequenceState::Rx
}
},
- SequenceState::ToTxStep1 => {
- led.set_low().unwrap();
+ SequenceState::Switching => {
+ mute_spkr.set_high().unwrap();
+ mute_micn.set_high().unwrap();
+ seq2_switch.set_high().unwrap();
seq0n.set_low().unwrap();
- SequenceState::ToTxStep2
- },
- SequenceState::ToTxStep2 => {
- led.set_high().unwrap();
- seq1_pa.set_high().unwrap();
- SequenceState::Tx
+ seq1_pa.set_low().unwrap();
+
+ if button_result.ptt {
+ SequenceState::Tx
+ }
+ else {
+ SequenceState::Rx
+ }
},
SequenceState::Tx => {
led.set_low().unwrap();
+
+ seq1_pa.set_high().unwrap();
if button_result.ptt {
SequenceState::Tx
}
else {
- seq1_pa.set_low().unwrap();
- SequenceState::ToRxStep1
+ SequenceState::Switching
}
},
- SequenceState::ToRxStep1 => {
- seq0n.set_high().unwrap();
- led.set_high().unwrap();
- SequenceState::ToRxStep2
- },
- SequenceState::ToRxStep2 => {
- led.set_low().unwrap();
- seq2_switch.set_low().unwrap();
- SequenceState::Rx
- }
};
- let t_now = time_now();
+ let t_now = ticks_now();
+ const SWITCHING_DELAY : u32 = TICKS_PER_SECOND * 200 / 1000;
if state.sequence_state != next_state &&
- last_sequence_state_change + 1 <= t_now {
- update_disp_required = true;
+ last_sequence_state_change + SWITCHING_DELAY <= t_now {
state.sequence_state = next_state;
last_sequence_state_change = t_now;
}
@@ -296,6 +314,14 @@ fn main() -> ! {
last_encoder_count = encoder_count;
+#[cfg(feature = "cw")]
+ if cw_paddle_tip.is_low().unwrap() {
+ cwpwm.on();
+ }
+ else {
+ cwpwm.off();
+ }
+
cortex_m::asm::wfi();
}
}
@@ -305,8 +331,8 @@ fn TIM2() {
let timer = unsafe { &mut *CLOCK_TIMER.as_mut_ptr() };
timer.clear_update_interrupt_flag();
- let deciseconds_counter = unsafe { &mut *DECISECONDS_COUNTER.as_mut_ptr() };
- *deciseconds_counter += 1;
+ let ticks = unsafe { &mut *TICK_COUNTER.as_mut_ptr() };
+ *ticks += 1;
}
#[cortex_m_rt::exception]