aboutsummaryrefslogtreecommitdiffstats
path: root/sw
diff options
context:
space:
mode:
Diffstat (limited to 'sw')
-rw-r--r--sw/picardy/src/main.rs54
-rw-r--r--sw/picardy/src/ui.rs88
-rw-r--r--sw/pio.txt8
3 files changed, 91 insertions, 59 deletions
diff --git a/sw/picardy/src/main.rs b/sw/picardy/src/main.rs
index 071f4e9..d6f2bf9 100644
--- a/sw/picardy/src/main.rs
+++ b/sw/picardy/src/main.rs
@@ -60,9 +60,18 @@ enum TuneSpeed {
Fast
}
+enum FilterShift {
+ LSB,
+ USB,
+ Custom(u32),
+}
+
+const BFO_LSB : u32 = 4_915_940;
+const BFO_USB : u32 = 4_914_910;
+
struct State {
mode : Mode,
- bfo : u32,
+ filter_shift : FilterShift,
bfo_tune_fail : bool,
qrg : u32,
tune_speed : TuneSpeed,
@@ -71,8 +80,16 @@ struct State {
}
impl State {
+ fn bfo(&self) -> u32 {
+ match self.filter_shift {
+ FilterShift::LSB => BFO_LSB,
+ FilterShift::USB => BFO_USB,
+ FilterShift::Custom(fs) => fs,
+ }
+ }
+
fn vfo(&self) -> u32 {
- self.qrg - self.bfo
+ self.qrg - self.bfo()
}
fn vfo_incr(&self) -> i32 {
@@ -101,7 +118,13 @@ fn update_disp<T: hd44780_driver::bus::DataBus>(lcd: &mut HD44780<T>, state: &St
(false, Mode::BFO) => write!(string, ">").unwrap(),
(false, Mode::VFO) => write!(string, " ").unwrap(),
}
- write!(string, "{:<10}", state.bfo).unwrap();
+ write!(string, "{:<10}", state.bfo()).unwrap();
+
+ match state.filter_shift {
+ FilterShift::USB => write!(string, "U").unwrap(),
+ FilterShift::LSB => write!(string, "L").unwrap(),
+ FilterShift::Custom(_) => write!(string, " ").unwrap(),
+ }
if state.transmit {
write!(string, " T").unwrap();
@@ -133,7 +156,7 @@ fn update_disp<T: hd44780_driver::bus::DataBus>(lcd: &mut HD44780<T>, state: &St
fn main() -> ! {
let mut state = State {
mode : Mode::VFO,
- bfo : 4_916_550,
+ filter_shift : FilterShift::USB,
bfo_tune_fail : false,
qrg : 28_000_000,
tune_speed : TuneSpeed::Mid,
@@ -246,7 +269,7 @@ fn main() -> ! {
);
let i2c_busmanager = shared_bus::BusManagerSimple::new(i2c);
- let mut siclock = si_clock::SiClock::new(i2c_busmanager.acquire_i2c(), state.bfo, state.vfo());
+ let mut siclock = si_clock::SiClock::new(i2c_busmanager.acquire_i2c(), state.bfo(), state.vfo());
update_disp(&mut lcd, &state, &mut delay);
@@ -271,8 +294,9 @@ fn main() -> ! {
state.qrg = (state.qrg as i32 + delta * state.vfo_incr()) as u32;
},
Mode::BFO => {
- state.bfo = (state.bfo as i32 + delta * state.bfo_incr()) as u32;
- state.bfo_tune_fail = !siclock.set_bfo(state.bfo).is_ok();
+ let new_bfo = (state.bfo() as i32 + delta * state.bfo_incr()) as u32;
+ state.filter_shift = FilterShift::Custom(new_bfo);
+ state.bfo_tune_fail = !siclock.set_bfo(state.bfo()).is_ok();
},
}
@@ -292,6 +316,17 @@ fn main() -> ! {
update_disp_required = true;
}
+ if button_state.f {
+ state.filter_shift = match state.filter_shift {
+ FilterShift::USB => FilterShift::LSB,
+ FilterShift::LSB => FilterShift::USB,
+ FilterShift::Custom(_) => FilterShift::USB,
+ };
+ state.bfo_tune_fail = !siclock.set_bfo(state.bfo()).is_ok();
+ update_disp_required = true;
+ }
+
+
if button_state.g {
state.tune_speed = match state.tune_speed {
TuneSpeed::Slow => TuneSpeed::Mid,
@@ -301,9 +336,8 @@ fn main() -> ! {
update_disp_required = true;
}
- let ptt = false; //ui.read_ptt();
- update_disp_required |= state.transmit != ptt;
- state.transmit = ptt;
+ update_disp_required |= state.transmit != button_state.ptt;
+ state.transmit = button_state.ptt;
if state.transmit {
mute_spkr.set_high().unwrap();
diff --git a/sw/picardy/src/ui.rs b/sw/picardy/src/ui.rs
index 114fe1e..2e93459 100644
--- a/sw/picardy/src/ui.rs
+++ b/sw/picardy/src/ui.rs
@@ -63,6 +63,22 @@ pub struct ButtonState {
pub ptt : bool,
}
+impl Default for ButtonState {
+ fn default() -> Self {
+ ButtonState {
+ a : false,
+ b : false,
+ c : false,
+ d : false,
+ e : false,
+ f : false,
+ g : false,
+ enc : false,
+ ptt : false,
+ }
+ }
+}
+
impl fmt::Display for ButtonState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}{}{}{}{}{}{}{}{}",
@@ -85,8 +101,8 @@ pub struct UI {
btn0_ch : PB1<Analog>,
btn1_ch : PB0<Analog>,
- _mic_sw1 : PA3<Analog>,
- mic_sw2 : PA4<Analog>,
+ mic_sw1 : PA3<Analog>,
+ _mic_sw2 : PA4<Analog>,
btn2 : PB12<Input<PullUp>>,
btn3 : PB13<Input<PullUp>>,
@@ -110,91 +126,74 @@ impl UI {
btn3 : pb13,
btn_enc : pc15,
adc : adc1,
- _mic_sw1 : mic_sw1,
- mic_sw2,
+ mic_sw1,
+ _mic_sw2 : mic_sw2,
}
}
- pub fn read_ptt(&mut self) -> bool {
- let _mic_sw1_value: u16 = self.adc.read(&mut self._mic_sw1).unwrap();
- let mic_sw2_value: u16 = self.adc.read(&mut self.mic_sw2).unwrap();
- mic_sw2_value < 500
- }
-
pub fn read_buttons(&mut self) -> ButtonState {
- let mut buttons = ButtonState {
- a : false,
- b : false,
- c : false,
- d : false,
- e : false,
- f : false,
- g : false,
- enc : false,
- ptt : false,
- };
+ let mut buttons = ButtonState::default();
- // Debounce BTN0
+ // Debounce BTN0 and BTN1
let btn0_value: u16 = self.adc.read(&mut self.btn0_ch).unwrap();
-
self.btn0_hist[2] = self.btn0_hist[1];
self.btn0_hist[1] = self.btn0_hist[0];
self.btn0_hist[0] = btn0_value;
+ let btn1_value: u16 = self.adc.read(&mut self.btn1_ch).unwrap();
+ self.btn1_hist[2] = self.btn1_hist[1];
+ self.btn1_hist[1] = self.btn1_hist[0];
+ self.btn1_hist[0] = btn1_value;
+
+ let mic_sw1_value: u16 = self.adc.read(&mut self.mic_sw1).unwrap();
+ //let mic_sw2_value: u16 = self.adc.read(&mut self.mic_sw2).unwrap();
+ buttons.ptt = mic_sw1_value < 500;
+
let mut btn0 = [None; 3];
for (i, &v) in self.btn0_hist.iter().enumerate() {
btn0[i] =
if v > 3050 {
None
}
- else if v > 1650 {
- Some(Btn0Buttons::B)
- }
else if v > 675 {
- Some(Btn0Buttons::C)
+ Some(Btn1Buttons::F)
}
else {
- Some(Btn0Buttons::D)
+ Some(Btn1Buttons::A)
};
}
if btn0.iter().all(|&v| v != None && v == btn0[0]) {
match btn0[0] {
None => {},
- Some(Btn0Buttons::B) => buttons.b = true,
- Some(Btn0Buttons::C) => buttons.c = true,
- Some(Btn0Buttons::D) => buttons.d = true,
+ Some(Btn1Buttons::A) => buttons.a = true,
+ Some(Btn1Buttons::F) => buttons.f = true,
}
}
-
- // Debounce BTN1
- let btn1_value: u16 = self.adc.read(&mut self.btn1_ch).unwrap();
-
- self.btn1_hist[2] = self.btn1_hist[1];
- self.btn1_hist[1] = self.btn1_hist[0];
- self.btn1_hist[0] = btn1_value;
-
-
let mut btn1 = [None; 3];
for (i, &v) in self.btn1_hist.iter().enumerate() {
btn1[i] =
if v > 3050 {
None
}
+ else if v > 1650 {
+ Some(Btn0Buttons::B)
+ }
else if v > 675 {
- Some(Btn1Buttons::F)
+ Some(Btn0Buttons::C)
}
else {
- Some(Btn1Buttons::A)
+ Some(Btn0Buttons::D)
};
}
if btn1.iter().all(|&v| v != None && v == btn1[0]) {
match btn1[0] {
None => {},
- Some(Btn1Buttons::A) => buttons.a = true,
- Some(Btn1Buttons::F) => buttons.f = true,
+ Some(Btn0Buttons::B) => buttons.b = true,
+ Some(Btn0Buttons::C) => buttons.c = true,
+ Some(Btn0Buttons::D) => buttons.d = true,
}
}
@@ -210,7 +209,6 @@ impl UI {
buttons.enc = true;
}
- cortex_m_semihosting::hprintln!("btn {} {}: {}", btn0_value, btn1_value, buttons).unwrap();
buttons
}
}
diff --git a/sw/pio.txt b/sw/pio.txt
index c932d08..917ed7a 100644
--- a/sw/pio.txt
+++ b/sw/pio.txt
@@ -5,8 +5,8 @@ Pin mapping: see datasheet Table 5
## GPIO inputs
Analog multi-level button inputs
- * BTN0 PB1
- * BTN1 PB0
+ * BTN0 PB1 ADC12_IN9
+ * BTN1 PB0 ADC12_IN8
Digital buttons
* BTN2 PB12
@@ -22,8 +22,8 @@ CW paddle
* CW_RING PB9
Microphone switches
- * SW1 PA3
- * SW2 PA4
+ * SW1 PA3 ADC12_IN3
+ * SW2 PA4 ADC12_IN4
## GPIO outputs