aboutsummaryrefslogtreecommitdiffstats
path: root/sw
diff options
context:
space:
mode:
Diffstat (limited to 'sw')
-rw-r--r--sw/eval-clock-cw-tx/src/main.rs43
-rw-r--r--sw/eval-clock-cw-tx/src/si_clock.rs15
-rw-r--r--sw/eval-clock-cw-tx/src/state.rs12
-rw-r--r--sw/eval-clock-cw-tx/src/ui.rs2
4 files changed, 44 insertions, 28 deletions
diff --git a/sw/eval-clock-cw-tx/src/main.rs b/sw/eval-clock-cw-tx/src/main.rs
index 4d2dae5..c91c545 100644
--- a/sw/eval-clock-cw-tx/src/main.rs
+++ b/sw/eval-clock-cw-tx/src/main.rs
@@ -59,13 +59,13 @@ 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_out : gpio::gpioa::PA15<gpio::Output<gpio::PushPull>>,
ui : ui::UI,
cw_pwm: cw::CWPWM,
cw_keyer: cw::Keyer,
cw_paddle_tip: gpio::gpiob::PB8<gpio::Input<gpio::PullUp>>,
cw_paddle_ring: gpio::gpiob::PB9<gpio::Input<gpio::PullUp>>,
- ptt_out_n: gpio::gpiob::PB3<gpio::Output<gpio::PushPull>>,
+ ptt_out: gpio::gpiob::PB3<gpio::Output<gpio::PushPull>>,
led : gpio::gpiob::PB14<gpio::Output<gpio::PushPull>>,
}
@@ -73,7 +73,7 @@ static mut SHARED: MaybeUninit<SharedWithISR> = MaybeUninit::uninit();
static mut CLOCK_TIMER: MaybeUninit<CountDownTimer<pac::TIM2>> = MaybeUninit::uninit();
static mut TICK_COUNTER: MaybeUninit<u32> = MaybeUninit::uninit();
-fn ticks_now() -> u32 {
+fn _ticks_now() -> u32 {
cortex_m::interrupt::free(|_cs| unsafe { *TICK_COUNTER.as_ptr() })
}
@@ -124,8 +124,8 @@ fn main() -> ! {
led.set_low().unwrap();
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, gpio::State::High);
- let ptt_out_n = pb3.into_push_pull_output_with_state(&mut gpiob.crl, gpio::State::High);
+ let cw_key_out = pa15.into_push_pull_output_with_state(&mut gpioa.crh, gpio::State::Low);
+ let ptt_out = pb3.into_push_pull_output_with_state(&mut gpiob.crl, gpio::State::Low);
let c1 = gpioa.pa6;
let c2 = gpioa.pa7;
@@ -180,14 +180,14 @@ fn main() -> ! {
state : State::new(),
last_sequence_state_change : 0,
cw_ptt_timestamp : 0,
- cw_key_n,
+ cw_key_out,
ui,
cw_pwm,
cw_keyer : cw::Keyer::new(12, TICKS_PER_SECOND),
- cw_paddle_tip, cw_paddle_ring, ptt_out_n, led
+ cw_paddle_tip, cw_paddle_ring, ptt_out, led
};
- si_clock::SiClock::new(i2c_busmanager.acquire_i2c(), 0, shared.state.vfo())
+ si_clock::SiClock::new(i2c_busmanager.acquire_i2c(), 0, shared.state.vfo_display())
};
ui::update_disp(&mut lcd, &get_state_copy(), &mut delay);
@@ -210,6 +210,7 @@ fn main() -> ! {
let mut last_disp_update_counter = 1;
let mut previous_vfo = 0;
+ let mut previous_state = SequenceState::Rx;
loop {
let mut update_disp_required = false;
@@ -229,15 +230,15 @@ fn main() -> ! {
}
});
- siclock.set_vfo(state.vfo());
update_disp_required = true;
}
- let vfo = state.vfo();
- if previous_vfo != vfo {
- siclock.set_vfo(vfo);
+ let vfo = state.vfo_display();
+ if previous_vfo != vfo || previous_state != state.sequence_state {
+ siclock.set_vfo(state.vfo_siclock());
}
previous_vfo = vfo;
+ previous_state = state.sequence_state.clone();
if last_disp_update_counter != state.update_disp_counter {
update_disp_required = true;
@@ -292,7 +293,8 @@ fn TIM2() {
let next_state = match shared.state.sequence_state {
SequenceState::Rx => {
- shared.ptt_out_n.set_high().unwrap();
+ shared.ptt_out.set_low().unwrap();
+ shared.led.set_high().unwrap();
if cw_ptt {
SequenceState::SwitchingCW
}
@@ -301,7 +303,8 @@ fn TIM2() {
}
},
SequenceState::SwitchingCW => {
- shared.ptt_out_n.set_low().unwrap();
+ shared.ptt_out.set_high().unwrap();
+ shared.led.set_low().unwrap();
if cw_ptt {
SequenceState::TxCW
}
@@ -310,7 +313,8 @@ fn TIM2() {
}
},
SequenceState::TxCW => {
- shared.ptt_out_n.set_low().unwrap();
+ shared.ptt_out.set_high().unwrap();
+ shared.led.set_low().unwrap();
if cw_ptt {
SequenceState::TxCW
}
@@ -323,20 +327,17 @@ fn TIM2() {
match shared.state.sequence_state {
SequenceState::TxCW => {
if cw_beep {
- shared.led.set_low().unwrap();
shared.cw_pwm.on();
- shared.cw_key_n.set_low().unwrap();
+ shared.cw_key_out.set_high().unwrap();
}
else {
- shared.led.set_high().unwrap();
shared.cw_pwm.off();
- shared.cw_key_n.set_high().unwrap();
+ shared.cw_key_out.set_low().unwrap();
}
},
_ => {
- shared.led.set_high().unwrap();
shared.cw_pwm.off();
- shared.cw_key_n.set_high().unwrap();
+ shared.cw_key_out.set_low().unwrap();
},
}
diff --git a/sw/eval-clock-cw-tx/src/si_clock.rs b/sw/eval-clock-cw-tx/src/si_clock.rs
index a4b0e7a..6de4c25 100644
--- a/sw/eval-clock-cw-tx/src/si_clock.rs
+++ b/sw/eval-clock-cw-tx/src/si_clock.rs
@@ -84,12 +84,17 @@ fn set_bfo(siclock: &mut dyn Si5351, freq: u32) -> Result<(), si5351::Error>
fn set_vfo(siclock: &mut dyn Si5351, freq: u32)
{
- let (div, mult, num, denom) = clock_settings_with_pll_calculation(freq);
+ if freq == 0 {
+ siclock.set_clock_enabled(si5351::ClockOutput::Clk0, false);
+ }
+ else {
+ let (div, mult, num, denom) = clock_settings_with_pll_calculation(freq);
- siclock.setup_pll(si5351::PLL::B, mult, num, denom).unwrap();
- siclock.setup_multisynth_int(si5351::Multisynth::MS0, div, si5351::OutputDivider::Div1).unwrap();
- siclock.select_clock_pll(si5351::ClockOutput::Clk0, si5351::PLL::B);
- siclock.set_clock_enabled(si5351::ClockOutput::Clk0, true);
+ siclock.setup_pll(si5351::PLL::B, mult, num, denom).unwrap();
+ siclock.setup_multisynth_int(si5351::Multisynth::MS0, div, si5351::OutputDivider::Div1).unwrap();
+ siclock.select_clock_pll(si5351::ClockOutput::Clk0, si5351::PLL::B);
+ siclock.set_clock_enabled(si5351::ClockOutput::Clk0, true);
+ }
siclock.flush_clock_control(si5351::ClockOutput::Clk0).unwrap();
}
diff --git a/sw/eval-clock-cw-tx/src/state.rs b/sw/eval-clock-cw-tx/src/state.rs
index b3b0b7b..a5891c5 100644
--- a/sw/eval-clock-cw-tx/src/state.rs
+++ b/sw/eval-clock-cw-tx/src/state.rs
@@ -66,13 +66,23 @@ impl State {
}
}
- pub fn vfo(&self) -> u32 {
+ pub fn vfo_display(&self) -> u32 {
match self.vfo_sel {
VFOSelection::A => self.vfo_a,
VFOSelection::B => self.vfo_b,
}
}
+ pub fn vfo_siclock(&self) -> u32 {
+ match self.sequence_state {
+ SequenceState::Rx => 0,
+ _ => match self.vfo_sel {
+ VFOSelection::A => self.vfo_a,
+ VFOSelection::B => self.vfo_b,
+ }
+ }
+ }
+
pub fn vfo_incr(&self) -> i32 {
match self.tune_speed {
TuneSpeed::Slow => 10,
diff --git a/sw/eval-clock-cw-tx/src/ui.rs b/sw/eval-clock-cw-tx/src/ui.rs
index 564b7d1..3cc8c90 100644
--- a/sw/eval-clock-cw-tx/src/ui.rs
+++ b/sw/eval-clock-cw-tx/src/ui.rs
@@ -239,7 +239,7 @@ pub fn update_disp<T: hd44780_driver::bus::DataBus>(lcd: &mut HD44780<T>, state:
{
let mut string = arrayvec::ArrayString::<[_; 16]>::new();
- let disp_freq = state.vfo() as i32;
+ let disp_freq = state.vfo_display() as i32;
write!(string, "{:<05}.{:<03} ", disp_freq / 1000, disp_freq % 1000).unwrap();
write!(string, " CW{:<02}", state.cw_wpm).unwrap();