Added display task
This commit is contained in:
parent
6323020528
commit
0f3892fd51
|
@ -9,7 +9,7 @@ cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
|
|||
defmt = { version = "0.3", features = ["encoding-rzcobs"] }
|
||||
defmt-brtt = { version = "0.1", default-features = false, features = ["rtt"] }
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
rtic = { version = "2.0.0-alpha.1", features = [ "thumbv7-backend" ] }
|
||||
rtic = { version = "2.0.1", features = [ "thumbv7-backend" ] }
|
||||
defmt-rtt = "0.4"
|
||||
stm32f4xx-hal = { version = "0.16.2", features = ["stm32f401"] }
|
||||
embedded-hal = {version = "0.2.3"}
|
||||
|
|
59
src/main.rs
59
src/main.rs
|
@ -1,5 +1,6 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
use defmt_rtt as _; // global logger
|
||||
|
||||
use panic_probe as _;
|
||||
|
@ -78,6 +79,7 @@ mod app {
|
|||
disp_led: gpioa::PA10<Output<PushPull>>,
|
||||
disp_cs: gpioa::PA15<Output<PushPull>>,
|
||||
disp: ST7735<Spi<SPI1>, gpio::Pin<'A', 12, Output>, gpio::Pin<'A', 11, Output>>,
|
||||
col_pos: u16,
|
||||
}
|
||||
|
||||
#[init]
|
||||
|
@ -117,20 +119,19 @@ mod app {
|
|||
);
|
||||
|
||||
let mut pll = si5153::Si5153::new(&i2c);
|
||||
/*
|
||||
pll.init(&mut i2c, 25000000, 800000000, 800000000);
|
||||
pll.set_ms_source(&mut i2c, si5153::Multisynth::MS0, si5153::PLL::A);
|
||||
pll.set_ms_source(&mut i2c, si5153::Multisynth::MS1, si5153::PLL::A);
|
||||
pll.set_ms_source(&mut i2c, si5153::Multisynth::MS2, si5153::PLL::B);
|
||||
|
||||
pll.set_ms_freq(&mut i2c, si5153::Multisynth::MS0, 8_000_000);
|
||||
pll.set_ms_phase(&mut i2c, si5153::Multisynth::MS0, 0);
|
||||
pll.enable_ms_output(&mut i2c, si5153::Multisynth::MS0);
|
||||
pll.init(&mut i2c, 25000000, 800000000, 800000000);
|
||||
pll.set_ms_source(&mut i2c, si5153::Multisynth::MS0, si5153::PLL::A);
|
||||
pll.set_ms_source(&mut i2c, si5153::Multisynth::MS1, si5153::PLL::A);
|
||||
pll.set_ms_source(&mut i2c, si5153::Multisynth::MS2, si5153::PLL::B);
|
||||
|
||||
pll.set_ms_freq(&mut i2c, si5153::Multisynth::MS1, 8_000_000);
|
||||
pll.set_ms_phase(&mut i2c, si5153::Multisynth::MS1, 100);
|
||||
pll.enable_ms_output(&mut i2c, si5153::Multisynth::MS1);
|
||||
*/
|
||||
pll.set_ms_freq(&mut i2c, si5153::Multisynth::MS0, 8_000_000);
|
||||
pll.set_ms_phase(&mut i2c, si5153::Multisynth::MS0, 0);
|
||||
pll.enable_ms_output(&mut i2c, si5153::Multisynth::MS0);
|
||||
|
||||
pll.set_ms_freq(&mut i2c, si5153::Multisynth::MS1, 8_000_000);
|
||||
pll.set_ms_phase(&mut i2c, si5153::Multisynth::MS1, 100);
|
||||
pll.enable_ms_output(&mut i2c, si5153::Multisynth::MS1);
|
||||
|
||||
defmt::info!("PLL chip setup done");
|
||||
|
||||
|
@ -210,7 +211,7 @@ mod app {
|
|||
|
||||
disp.init(&mut delay).unwrap();
|
||||
disp.set_orientation(&Orientation::Landscape).unwrap();
|
||||
disp.clear(Rgb565::GREEN).unwrap();
|
||||
disp.clear(Rgb565::BLUE).unwrap();
|
||||
|
||||
(
|
||||
Shared {},
|
||||
|
@ -233,10 +234,38 @@ mod app {
|
|||
disp_led,
|
||||
disp_cs,
|
||||
disp,
|
||||
col_pos: 0,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[task(priority = 0, local = [disp, col_pos])]
|
||||
async fn update_display(cx: update_display::Context, col: [Complex<f32>; 128]) {
|
||||
let mut max_intens = 0.0;
|
||||
for samp in col {
|
||||
let intens = (samp.re.pow(2) + samp.im.pow(2)) as f32;
|
||||
max_intens = if intens > max_intens {
|
||||
intens
|
||||
} else {
|
||||
max_intens
|
||||
};
|
||||
}
|
||||
|
||||
for y in 0..128 {
|
||||
let norm_intens = (col[y].re.pow(2) + col[y].im.pow(2)) / max_intens;
|
||||
Pixel(
|
||||
Point::new(*cx.local.col_pos as i32, y as i32),
|
||||
Rgb565::new(0, (norm_intens * 64.0f32) as u8, 0),
|
||||
)
|
||||
.draw(cx.local.disp)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
*cx.local.col_pos = (*cx.local.col_pos + 1) % 160;
|
||||
|
||||
defmt::info!("Position is {}", cx.local.col_pos);
|
||||
}
|
||||
|
||||
#[task(binds = DMA2_STREAM0, local = [transfer, iq_buffer, board_led, i_offset, q_offset, usb_filter])]
|
||||
fn dma2_stream0(cx: dma2_stream0::Context) {
|
||||
let (buffer, _) = cx
|
||||
|
@ -264,12 +293,14 @@ mod app {
|
|||
|
||||
let mut fft_input = [Complex::<f32>::default(); 128];
|
||||
for idx in 0..samples.len() / 2 {
|
||||
let _filtered = cx.local.usb_filter.compute(samples[idx]) * 2.0;
|
||||
let _filtered = cx.local.usb_filter.compute(samples[idx]);
|
||||
fft_input[idx] = samples[idx];
|
||||
}
|
||||
|
||||
let spectrum = cfft_128(&mut fft_input);
|
||||
|
||||
update_display::spawn(spectrum.clone()).unwrap();
|
||||
|
||||
let mut max_idx: usize = 0;
|
||||
let mut max_mag = 0.0;
|
||||
for idx in 0..spectrum.len() {
|
||||
|
|
Loading…
Reference in New Issue