aboutsummaryrefslogtreecommitdiffstats
path: root/sw
diff options
context:
space:
mode:
Diffstat (limited to 'sw')
-rw-r--r--sw/picardy/src/main.rs103
1 files changed, 80 insertions, 23 deletions
diff --git a/sw/picardy/src/main.rs b/sw/picardy/src/main.rs
index e6d2469..dc8d0ef 100644
--- a/sw/picardy/src/main.rs
+++ b/sw/picardy/src/main.rs
@@ -49,6 +49,7 @@ pub mod ui;
pub mod si_clock;
static mut TIMER1: MaybeUninit<CountDownTimer<pac::TIM1>> = MaybeUninit::uninit();
+static mut DECISECONDS_COUNTER: MaybeUninit<usize> = MaybeUninit::uninit();
enum Mode {
VFO,
@@ -72,6 +73,16 @@ const VHF_LO : u32 = 114_286_000;
const BFO_LSB : u32 = 4_915_940;
const BFO_USB : u32 = 4_914_910;
+#[derive(PartialEq, Eq)]
+enum SequenceState {
+ Rx,
+ ToTxStep1,
+ ToTxStep2,
+ Tx,
+ ToRxStep1,
+ ToRxStep2,
+}
+
struct State {
mode : Mode,
filter_shift : FilterShift,
@@ -79,7 +90,8 @@ struct State {
vhf_qrg : u32,
tune_speed : TuneSpeed,
- transmit : bool,
+ sequence_state : SequenceState,
+ last_sequence_state_change : usize,
}
impl State {
@@ -133,11 +145,10 @@ fn update_disp<T: hd44780_driver::bus::DataBus>(lcd: &mut HD44780<T>, state: &St
FilterShift::Custom(_) => write!(string, " ").unwrap(),
}
- if state.transmit {
- write!(string, " T").unwrap();
- }
- else {
- write!(string, " R").unwrap();
+ match state.sequence_state {
+ SequenceState::Rx => write!(string, " R").unwrap(),
+ SequenceState::Tx => write!(string, " T").unwrap(),
+ _ => write!(string, " X").unwrap(),
}
lcd.set_cursor_pos(0, delay).unwrap();
@@ -169,7 +180,8 @@ fn main() -> ! {
bfo_tune_fail : false,
vhf_qrg : VHF_BAND_EDGE,
tune_speed : TuneSpeed::Mid,
- transmit : false,
+ sequence_state : SequenceState::Rx,
+ last_sequence_state_change : 0,
};
let cp = cortex_m::Peripherals::take().unwrap();
@@ -206,8 +218,8 @@ fn main() -> ! {
let (pa15, pb3, pb4) = afio.mapr.disable_jtag(gpioa.pa15, gpiob.pb3, gpiob.pb4);
let _cw_key_n = pa15.into_push_pull_output_with_state(&mut gpioa.crh, gpio::State::High); // TODO output
let mut seq0n = pb3.into_push_pull_output_with_state(&mut gpiob.crl, gpio::State::High);
- let mut _seq1 = pb4.into_push_pull_output_with_state(&mut gpiob.crl, gpio::State::Low);
- let mut _seq2 = gpiob.pb5.into_push_pull_output_with_state(&mut gpiob.crl, gpio::State::Low);
+ let mut seq1_pa = pb4.into_push_pull_output_with_state(&mut gpiob.crl, gpio::State::Low);
+ let mut seq2_switch = gpiob.pb5.into_push_pull_output_with_state(&mut gpiob.crl, gpio::State::Low);
let mut mute_spkr = gpioa.pa2.into_push_pull_output_with_state(&mut gpioa.crl, gpio::State::Low);
let mut mute_micn = gpioa.pa1.into_push_pull_output_with_state(&mut gpioa.crl, gpio::State::Low);
@@ -284,9 +296,12 @@ fn main() -> ! {
let mut last_encoder_count = qei.count();
+ let deciseconds_counter = unsafe { &mut *DECISECONDS_COUNTER.as_mut_ptr() };
+ *deciseconds_counter = 0;
+
let timer1 = unsafe { &mut *TIMER1.as_mut_ptr() };
*timer1 = Timer::tim1(dp.TIM1, &clocks, &mut rcc.apb2)
- .start_count_down(1.hz());
+ .start_count_down(10.hz());
timer1.listen(Event::Update);
unsafe { pac::NVIC::unmask(pac::Interrupt::TIM1_UP); }
@@ -346,20 +361,59 @@ fn main() -> ! {
update_disp_required = true;
}
- update_disp_required |= state.transmit != button_state.ptt;
- state.transmit = button_state.ptt;
+ let next_state = match state.sequence_state {
+ SequenceState::Rx => {
+ led.set_high().unwrap();
+ if button_state.ptt {
+ mute_spkr.set_high().unwrap();
+ mute_micn.set_high().unwrap();
+ seq2_switch.set_high().unwrap();
+ SequenceState::ToTxStep1
+ }
+ else {
+ mute_spkr.set_low().unwrap();
+ mute_micn.set_low().unwrap();
+ SequenceState::Rx
+ }
+ },
+ SequenceState::ToTxStep1 => {
+ led.set_low().unwrap();
+ seq1_pa.set_high().unwrap();
+ SequenceState::ToTxStep2
+ },
+ SequenceState::ToTxStep2 => {
+ led.set_high().unwrap();
+ seq0n.set_low().unwrap();
+ SequenceState::Tx
+ },
+ SequenceState::Tx => {
+ led.set_low().unwrap();
+ if button_state.ptt {
+ SequenceState::Tx
+ }
+ else {
+ seq0n.set_high().unwrap();
+ SequenceState::ToRxStep1
+ }
+ },
+ SequenceState::ToRxStep1 => {
+ led.set_high().unwrap();
+ seq1_pa.set_low().unwrap();
+ SequenceState::ToRxStep2
+ },
+ SequenceState::ToRxStep2 => {
+ led.set_low().unwrap();
+ seq2_switch.set_low().unwrap();
+ SequenceState::Rx
+ }
+ };
- if state.transmit {
- mute_spkr.set_high().unwrap();
- mute_micn.set_high().unwrap();
- seq0n.set_low().unwrap();
- led.set_high().unwrap();
- }
- else {
- mute_spkr.set_low().unwrap();
- mute_micn.set_low().unwrap();
- seq0n.set_high().unwrap();
- led.set_low().unwrap();
+ let t_now = unsafe { *DECISECONDS_COUNTER.as_ptr() };
+ if state.sequence_state != next_state &&
+ state.last_sequence_state_change + 1 <= t_now {
+ update_disp_required = true;
+ state.sequence_state = next_state;
+ state.last_sequence_state_change = t_now;
}
if update_disp_required {
@@ -378,6 +432,9 @@ fn main() -> ! {
fn TIM1_UP() {
let timer1 = unsafe { &mut *TIMER1.as_mut_ptr() };
timer1.clear_update_interrupt_flag();
+
+ let deciseconds_counter = unsafe { &mut *DECISECONDS_COUNTER.as_mut_ptr() };
+ *deciseconds_counter += 1;
}
#[cortex_m_rt::exception]