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.rs129
1 files changed, 63 insertions, 66 deletions
diff --git a/sw/picardy/src/main.rs b/sw/picardy/src/main.rs
index 2e7d9a1..3beefee 100644
--- a/sw/picardy/src/main.rs
+++ b/sw/picardy/src/main.rs
@@ -37,13 +37,11 @@ use stm32f1xx_hal::{
pac::interrupt,
i2c,
gpio,
- delay::Delay,
- timer::{CountDownTimer, Timer, Event},
+ gpio::PinState,
+ timer::{CounterHz, Timer, Event},
qei::QeiOptions,
};
-use embedded_hal::digital::v2::OutputPin;
-use embedded_hal::digital::v2::InputPin;
use hd44780_driver::{Cursor, CursorBlink, Display, DisplayMode, HD44780};
pub mod ui;
@@ -75,7 +73,7 @@ struct SharedWithISR {
}
static mut SHARED: MaybeUninit<SharedWithISR> = MaybeUninit::uninit();
-static mut CLOCK_TIMER: MaybeUninit<CountDownTimer<pac::TIM2>> = MaybeUninit::uninit();
+static mut CLOCK_TIMER: MaybeUninit<CounterHz<pac::TIM2>> = MaybeUninit::uninit();
static mut TICK_COUNTER: MaybeUninit<u32> = MaybeUninit::uninit();
fn ticks_now() -> u32 {
@@ -94,21 +92,21 @@ fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let mut flash = dp.FLASH.constrain();
- let mut rcc = dp.RCC.constrain();
- let mut afio = dp.AFIO.constrain(&mut rcc.apb2);
+ let rcc = dp.RCC.constrain();
+ let mut afio = dp.AFIO.constrain();
let clocks = rcc.cfgr
- .use_hse(16.mhz())
- .sysclk(32.mhz())
- .pclk1(24.mhz())
- .adcclk(2.mhz())
+ .use_hse(16.MHz())
+ .sysclk(32.MHz())
+ .pclk1(24.MHz())
+ .adcclk(2.MHz())
.freeze(&mut flash.acr);
- let mut delay = Delay::new(cp.SYST, clocks);
+ let mut delay = cp.SYST.delay(&clocks);
delay.delay_ms(200u16);
- let mut gpioa = dp.GPIOA.split(&mut rcc.apb2);
- let mut gpiob = dp.GPIOB.split(&mut rcc.apb2);
- let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
+ let mut gpioa = dp.GPIOA.split();
+ let mut gpiob = dp.GPIOB.split();
+ let mut gpioc = dp.GPIOC.split();
// Buttons as analog inputs (multi-level)
let mic_sw1 = gpioa.pa3.into_analog(&mut gpioa.crl);
@@ -119,39 +117,40 @@ fn main() -> ! {
let pb13 = gpiob.pb13.into_pull_up_input(&mut gpiob.crh); // BTN3 Button G
let pc15 = gpioc.pc15.into_pull_up_input(&mut gpioc.crh);
let adc1 = dp.ADC1;
- let ui = ui::UI::new(mic_sw1, mic_sw2, pb0, pb1, adc1, &mut rcc.apb2, &clocks, pb12, pb13, pc15);
+ let ui = ui::UI::new(mic_sw1, mic_sw2, pb0, pb1, adc1, &clocks, pb12, pb13, pc15);
let cw_pwm = {
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);
- cw::CWPWM::new(pa8, tim1, &mut afio.mapr)
+ let pwm = dp.TIM1.pwm_hz(pa8, &mut afio.mapr, cw::SIDETONE_FREQ.Hz(), &clocks);
+ let channel = pwm.split();
+ cw::CWPWM::new(channel)
};
let cw_paddle_tip = gpiob.pb8.into_pull_up_input(&mut gpiob.crh); // CW paddle tip
let cw_paddle_ring = gpiob.pb9.into_pull_up_input(&mut gpiob.crh); // CW paddle ring
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 adc2 = adc::Adc::adc2(dp.ADC2, clocks);
let mut last_s_meter_update_time = 0;
// Configure PB14 as output. (LED)
let mut led = gpiob.pb14.into_push_pull_output(&mut gpiob.crh);
- led.set_low().unwrap();
+ 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, gpio::State::High);
+ let cw_key_n = pa15.into_open_drain_output_with_state(&mut gpioa.crh, PinState::High);
- let seq0n = pb3.into_push_pull_output_with_state(&mut gpiob.crl, gpio::State::High);
- let seq1_pa = pb4.into_push_pull_output_with_state(&mut gpiob.crl, gpio::State::Low);
- let seq2_switch = gpiob.pb5.into_push_pull_output_with_state(&mut gpiob.crl, gpio::State::Low);
+ let seq0n = pb3.into_push_pull_output_with_state(&mut gpiob.crl, PinState::High);
+ let seq1_pa = pb4.into_push_pull_output_with_state(&mut gpiob.crl, PinState::Low);
+ let seq2_switch = gpiob.pb5.into_push_pull_output_with_state(&mut gpiob.crl, PinState::Low);
- let mute_spkr = gpioa.pa2.into_push_pull_output_with_state(&mut gpioa.crl, gpio::State::Low);
- let mute_micn = gpioa.pa1.into_push_pull_output_with_state(&mut gpioa.crl, gpio::State::Low);
+ let mute_spkr = gpioa.pa2.into_push_pull_output_with_state(&mut gpioa.crl, PinState::Low);
+ let mute_micn = gpioa.pa1.into_push_pull_output_with_state(&mut gpioa.crl, PinState::Low);
let c1 = gpioa.pa6;
let c2 = gpioa.pa7;
- let qei = Timer::tim3(dp.TIM3, &clocks, &mut rcc.apb1)
+ let qei = Timer::new(dp.TIM3, &clocks)
.qei((c1, c2), &mut afio.mapr, QeiOptions::default());
// Configure I2C2 for display
@@ -162,11 +161,10 @@ fn main() -> ! {
dp.I2C2,
(scl2, sda2),
i2c::Mode::Fast {
- frequency: 400_000.hz(),
+ frequency: 400_000.Hz(),
duty_cycle: i2c::DutyCycle::Ratio2to1,
},
clocks,
- &mut rcc.apb1,
/* start_timeout_us */ 1000,
/* start_retries */ 10,
/* addr_timeout_us */ 1000,
@@ -205,10 +203,9 @@ fn main() -> ! {
(scl, sda),
&mut afio.mapr,
i2c::Mode::Standard {
- frequency: 100_000.hz(),
+ frequency: 100_000.Hz(),
},
clocks,
- &mut rcc.apb1,
/* start_timeout_us */ 1000,
/* start_retries */ 10,
/* addr_timeout_us */ 1000,
@@ -245,8 +242,8 @@ fn main() -> ! {
{
let timer = unsafe { &mut *CLOCK_TIMER.as_mut_ptr() };
- *timer = Timer::tim2(dp.TIM2, &clocks, &mut rcc.apb1)
- .start_count_down(TICKS_PER_SECOND.hz());
+ *timer = Timer::new(dp.TIM2, &clocks).counter_hz();
+ timer.start(TICKS_PER_SECOND.Hz()).unwrap();
timer.listen(Event::Update);
}
@@ -350,7 +347,7 @@ fn s_meter_from_adc(adc : u16) -> u8 {
#[interrupt]
fn TIM2() {
let timer = unsafe { &mut *CLOCK_TIMER.as_mut_ptr() };
- timer.clear_update_interrupt_flag();
+ timer.clear_interrupt(Event::Update);
let ticks = unsafe { &mut *TICK_COUNTER.as_mut_ptr() };
*ticks += 1;
@@ -362,8 +359,8 @@ fn TIM2() {
shared.state.update_disp_counter += 1;
}
- let cw_paddle_tip_low = shared.cw_paddle_tip.is_low().unwrap();
- let cw_paddle_ring_low = shared.cw_paddle_ring.is_low().unwrap();
+ let cw_paddle_tip_low = shared.cw_paddle_tip.is_low();
+ let cw_paddle_ring_low = shared.cw_paddle_ring.is_low();
if cw_paddle_tip_low || cw_paddle_ring_low {
shared.state.send_tone = false;
@@ -393,10 +390,10 @@ fn TIM2() {
let next_state = match shared.state.sequence_state {
SequenceState::Rx => {
- shared.mute_spkr.set_low().unwrap();
- shared.mute_micn.set_low().unwrap();
- shared.seq2_switch.set_low().unwrap();
- shared.seq0n.set_high().unwrap();
+ shared.mute_spkr.set_low();
+ shared.mute_micn.set_low();
+ shared.seq2_switch.set_low();
+ shared.seq0n.set_high();
if button_result.ptt || cw_ptt {
SequenceState::MutingSpkr
}
@@ -405,10 +402,10 @@ fn TIM2() {
}
},
SequenceState::MutingSpkr => {
- shared.mute_spkr.set_high().unwrap();
- shared.mute_micn.set_low().unwrap();
- shared.seq2_switch.set_low().unwrap();
- shared.seq0n.set_high().unwrap();
+ shared.mute_spkr.set_high();
+ shared.mute_micn.set_low();
+ shared.seq2_switch.set_low();
+ shared.seq0n.set_high();
if button_result.ptt {
SequenceState::SwitchingSSB
}
@@ -420,11 +417,11 @@ fn TIM2() {
}
},
SequenceState::SwitchingSSB => {
- shared.mute_spkr.set_high().unwrap();
- shared.seq2_switch.set_high().unwrap();
- shared.seq0n.set_low().unwrap();
- shared.seq1_pa.set_low().unwrap();
- shared.mute_micn.set_high().unwrap();
+ shared.mute_spkr.set_high();
+ shared.seq2_switch.set_high();
+ shared.seq0n.set_low();
+ shared.seq1_pa.set_low();
+ shared.mute_micn.set_high();
if button_result.ptt {
SequenceState::TxSSB
@@ -434,11 +431,11 @@ fn TIM2() {
}
},
SequenceState::SwitchingCW => {
- shared.mute_spkr.set_high().unwrap();
- shared.seq2_switch.set_high().unwrap();
- shared.seq0n.set_low().unwrap();
- shared.seq1_pa.set_low().unwrap();
- shared.mute_micn.set_low().unwrap();
+ shared.mute_spkr.set_high();
+ shared.seq2_switch.set_high();
+ shared.seq0n.set_low();
+ shared.seq1_pa.set_low();
+ shared.mute_micn.set_low();
if cw_ptt {
SequenceState::TxCW
}
@@ -447,7 +444,7 @@ fn TIM2() {
}
},
SequenceState::TxSSB => {
- shared.seq1_pa.set_high().unwrap();
+ shared.seq1_pa.set_high();
if button_result.ptt {
SequenceState::TxSSB
@@ -457,7 +454,7 @@ fn TIM2() {
}
},
SequenceState::TxCW => {
- shared.seq1_pa.set_high().unwrap();
+ shared.seq1_pa.set_high();
if cw_ptt {
SequenceState::TxCW
@@ -471,20 +468,20 @@ fn TIM2() {
match shared.state.sequence_state {
SequenceState::TxCW => {
if cw_beep {
- shared.led.set_low().unwrap();
+ shared.led.set_low();
shared.cw_pwm.on();
- shared.cw_key_n.set_low().unwrap();
+ shared.cw_key_n.set_low();
}
else {
- shared.led.set_high().unwrap();
+ shared.led.set_high();
shared.cw_pwm.off();
- shared.cw_key_n.set_high().unwrap();
+ shared.cw_key_n.set_high();
}
},
_ => {
- shared.led.set_high().unwrap();
+ shared.led.set_high();
shared.cw_pwm.off();
- shared.cw_key_n.set_high().unwrap();
+ shared.cw_key_n.set_high();
},
}
@@ -498,20 +495,20 @@ fn TIM2() {
#[allow(non_snake_case)]
#[cortex_m_rt::exception]
-fn HardFault(ef: &ExceptionFrame) -> ! {
+unsafe fn HardFault(ef: &ExceptionFrame) -> ! {
let periph = unsafe { cortex_m::Peripherals::steal() };
let hfsr = periph.SCB.hfsr.read();
let cfsr = periph.SCB.cfsr.read();
- hprintln!("Hardfault {:x} {:x} at {:x}\n", hfsr, cfsr, ef.pc).unwrap();
+ hprintln!("Hardfault {:x} {:x} at {:x}\n", hfsr, cfsr, ef.pc());
cortex_m::asm::bkpt();
loop { }
}
#[allow(non_snake_case)]
#[cortex_m_rt::exception]
-fn DefaultHandler(irqn: i16) {
- hprintln!("Unhandled exception (IRQn = {})", irqn).unwrap();
+unsafe fn DefaultHandler(irqn: i16) {
+ hprintln!("Unhandled exception (IRQn = {})", irqn);
cortex_m::asm::bkpt();
loop { }
}