Added variable frequency increments for tuning
This commit is contained in:
parent
558bc0d496
commit
abde00418b
|
@ -121,6 +121,7 @@ mod app {
|
|||
gpioa.pa0.into_input(),
|
||||
gpioa.pa1.into_input(),
|
||||
cx.device.TIM2,
|
||||
gpioa.pa5.into_input(),
|
||||
gpioa.pa11.into_push_pull_output(),
|
||||
gpioa.pa12.into_push_pull_output(),
|
||||
gpioa.pa10.into_push_pull_output(),
|
||||
|
|
44
src/ui.rs
44
src/ui.rs
|
@ -29,6 +29,7 @@ use crate::si5153;
|
|||
|
||||
type EncoderA = gpio::Pin<'A', 0, Input>;
|
||||
type EncoderB = gpio::Pin<'A', 1, Input>;
|
||||
type EncoderButton = gpio::Pin<'A', 5, Input>;
|
||||
|
||||
type DisplaySPI = Spi<SPI1>;
|
||||
type DisplayRST = gpio::Pin<'A', 11, Output>;
|
||||
|
@ -47,8 +48,12 @@ pub struct UI {
|
|||
row_buffer_count: usize,
|
||||
|
||||
encoder: qei::Qei<TIM2>,
|
||||
encoder_button: EncoderButton,
|
||||
last_encoder_button: bool,
|
||||
|
||||
last_encoder_pos: u32,
|
||||
carrier_freq: u32,
|
||||
cursor_pos: u32,
|
||||
|
||||
initial_render: bool,
|
||||
}
|
||||
|
@ -60,6 +65,7 @@ impl UI {
|
|||
enc_a: EncoderA,
|
||||
enc_b: EncoderB,
|
||||
tim2: TIM2,
|
||||
encoder_button: EncoderButton,
|
||||
|
||||
disp_rst: DisplayRST,
|
||||
disp_dc: DisplayDC,
|
||||
|
@ -105,8 +111,13 @@ impl UI {
|
|||
row_buffer: [Complex::<f32>::new(0.0, 0.0); 128],
|
||||
row_buffer_count: 0,
|
||||
encoder,
|
||||
encoder_button: encoder_button,
|
||||
last_encoder_pos: 0,
|
||||
last_encoder_button: false,
|
||||
|
||||
carrier_freq: 7_100_000,
|
||||
cursor_pos: 3,
|
||||
|
||||
initial_render: true,
|
||||
}
|
||||
}
|
||||
|
@ -180,14 +191,15 @@ impl UI {
|
|||
|
||||
if diff != 0 || self.initial_render {
|
||||
if diff != 0 {
|
||||
self.carrier_freq = (self.carrier_freq as i32 + diff * 100) as u32;
|
||||
let increment = 10.pow(self.cursor_pos);
|
||||
self.carrier_freq = (self.carrier_freq as i32 + diff * increment) as u32;
|
||||
|
||||
pll.set_pll_freq(i2c, si5153::PLL::A, self.carrier_freq * 100);
|
||||
pll.set_ms_freq(i2c, si5153::Multisynth::MS0, self.carrier_freq);
|
||||
pll.set_ms_freq(i2c, si5153::Multisynth::MS1, self.carrier_freq);
|
||||
}
|
||||
|
||||
Rectangle::new(Point::new(32, 0), Size::new(160, 28))
|
||||
Rectangle::new(Point::new(32, 0), Size::new(160, 18))
|
||||
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK))
|
||||
.draw(&mut self.disp)
|
||||
.unwrap();
|
||||
|
@ -203,6 +215,34 @@ impl UI {
|
|||
defmt::info!("Carrier freq is {}", self.carrier_freq);
|
||||
}
|
||||
|
||||
let encoder_button = self.encoder_button.is_high();
|
||||
if encoder_button && !self.last_encoder_button {
|
||||
self.cursor_pos += 1;
|
||||
if self.cursor_pos >= 6 {
|
||||
self.cursor_pos = 0;
|
||||
}
|
||||
|
||||
Rectangle::new(Point::new(32, 18), Size::new(160, 2))
|
||||
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK))
|
||||
.draw(&mut self.disp)
|
||||
.unwrap();
|
||||
|
||||
let str_pos = if self.cursor_pos >= 3 {
|
||||
self.cursor_pos + 1
|
||||
} else {
|
||||
self.cursor_pos
|
||||
};
|
||||
|
||||
Rectangle::new(
|
||||
Point::new(32 + 90 - 10 * str_pos as i32, 18),
|
||||
Size::new(8, 2),
|
||||
)
|
||||
.into_styled(PrimitiveStyle::with_fill(Rgb565::WHITE))
|
||||
.draw(&mut self.disp)
|
||||
.unwrap();
|
||||
}
|
||||
self.last_encoder_button = encoder_button;
|
||||
|
||||
self.initial_render = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue