Started work on a more usefull display
This commit is contained in:
parent
35ad5dcb9f
commit
eaee903172
86
src/main.rs
86
src/main.rs
|
@ -91,7 +91,9 @@ 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,
|
||||
row_pos: u16,
|
||||
row_buffer: [Complex<f32>; 128],
|
||||
row_buffer_count: usize,
|
||||
max_mag: f32,
|
||||
|
||||
encoder: qei::Qei<TIM2>,
|
||||
|
@ -199,7 +201,7 @@ mod app {
|
|||
|
||||
disp.init(&mut delay).unwrap();
|
||||
disp.set_orientation(&Orientation::Landscape).unwrap();
|
||||
disp.clear(Rgb565::BLUE).unwrap();
|
||||
disp.clear(Rgb565::BLACK).unwrap();
|
||||
|
||||
defmt::info!("Display setup done");
|
||||
|
||||
|
@ -307,7 +309,9 @@ mod app {
|
|||
disp_led,
|
||||
disp_cs,
|
||||
disp,
|
||||
col_pos: 0,
|
||||
row_pos: 0,
|
||||
row_buffer: [Complex::<f32>::new(0.0, 0.0); 128],
|
||||
row_buffer_count: 0,
|
||||
max_mag: 0.0,
|
||||
|
||||
encoder,
|
||||
|
@ -317,37 +321,55 @@ mod app {
|
|||
)
|
||||
}
|
||||
|
||||
#[task(priority = 0, local = [disp, col_pos, max_mag, encoder, last_encoder_pos, carrier_freq, pll, i2c])]
|
||||
async fn update_display(cx: update_display::Context, col: [Complex<f32>; 128]) {
|
||||
for samp in col {
|
||||
let mag = (samp.re.pow(2) as f32 + samp.im.pow(2) as f32).sqrt() as f32;
|
||||
*cx.local.max_mag = if mag > *cx.local.max_mag {
|
||||
mag
|
||||
} else {
|
||||
*cx.local.max_mag
|
||||
};
|
||||
#[task(priority = 0, local = [disp, row_pos, row_buffer, row_buffer_count, max_mag, encoder, last_encoder_pos, carrier_freq, pll, i2c])]
|
||||
async fn update_display(cx: update_display::Context, mut row: [Complex<f32>; 128]) {
|
||||
let buffers_per_row = 4;
|
||||
|
||||
let row = cfft_128(&mut row);
|
||||
|
||||
for idx in 0..row.len() {
|
||||
cx.local.row_buffer[idx] += row[idx] / buffers_per_row as f32;
|
||||
}
|
||||
|
||||
let gradient = colorous::TURBO;
|
||||
*cx.local.row_buffer_count += 1;
|
||||
|
||||
for idx in 0..128 {
|
||||
let norm_intens = (col[idx].re.pow(2) + col[idx].im.pow(2)) / *cx.local.max_mag;
|
||||
let color = gradient.eval_continuous(norm_intens as f64);
|
||||
if *cx.local.row_buffer_count > buffers_per_row {
|
||||
*cx.local.row_buffer_count = 0;
|
||||
|
||||
let y = if idx < 64 { 64 + idx } else { idx - 64 };
|
||||
Pixel(
|
||||
Point::new(*cx.local.col_pos as i32, y as i32),
|
||||
Rgb565::new(color.r >> 3, color.g >> 2, color.b >> 3),
|
||||
)
|
||||
.draw(cx.local.disp)
|
||||
.unwrap();
|
||||
for samp in cx.local.row_buffer.iter() {
|
||||
let mag = (samp.re.pow(2) as f32 + samp.im.pow(2) as f32).sqrt() as f32;
|
||||
*cx.local.max_mag = if mag > *cx.local.max_mag {
|
||||
mag
|
||||
} else {
|
||||
*cx.local.max_mag
|
||||
};
|
||||
}
|
||||
|
||||
let gradient = colorous::TURBO;
|
||||
|
||||
for idx in 0..128 {
|
||||
let norm_intens = (cx.local.row_buffer[idx].re.pow(2)
|
||||
+ cx.local.row_buffer[idx].im.pow(2))
|
||||
/ *cx.local.max_mag;
|
||||
let color = gradient.eval_continuous(norm_intens as f64);
|
||||
|
||||
let x = if idx < 64 { 64 + idx } else { idx - 64 };
|
||||
Pixel(
|
||||
Point::new(32 + x as i32, 28 + *cx.local.row_pos as i32),
|
||||
Rgb565::new(color.r >> 3, color.g >> 2, color.b >> 3),
|
||||
)
|
||||
.draw(cx.local.disp)
|
||||
.unwrap();
|
||||
|
||||
cx.local.row_buffer[idx] = Complex::new(0.0, 0.0);
|
||||
}
|
||||
|
||||
*cx.local.row_pos = (*cx.local.row_pos + 1) % 100;
|
||||
*cx.local.max_mag *= 0.999;
|
||||
|
||||
defmt::info!("Position is {}", cx.local.row_pos);
|
||||
}
|
||||
|
||||
*cx.local.col_pos = (*cx.local.col_pos + 1) % 160;
|
||||
*cx.local.max_mag *= 0.999;
|
||||
|
||||
defmt::info!("Position is {}", cx.local.col_pos);
|
||||
|
||||
let encoder_pos = cx.local.encoder.count();
|
||||
let diff = encoder_pos.wrapping_sub(*cx.local.last_encoder_pos) as i32;
|
||||
|
||||
|
@ -405,8 +427,8 @@ mod app {
|
|||
cx.shared.audio_buffer.lock(|buffer| {
|
||||
let audio_buffer = buffer.take().unwrap();
|
||||
for idx in 0..samples.len() {
|
||||
let filtered = usb_filter.compute(samples[idx]);
|
||||
//let filtered = usb_filter.compute(Complex::new(samples[idx].im, samples[idx].re));
|
||||
//let filtered = usb_filter.compute(samples[idx]);
|
||||
let filtered = usb_filter.compute(Complex::new(samples[idx].im, samples[idx].re));
|
||||
fft_input[idx] = samples[idx];
|
||||
|
||||
audio_buffer[idx] = ((filtered.re * (audio_max_duty as f32)) * 3.0f32) as u16;
|
||||
|
@ -415,9 +437,7 @@ mod app {
|
|||
*buffer = Some(audio_buffer);
|
||||
});
|
||||
|
||||
let spectrum = cfft_128(&mut fft_input);
|
||||
|
||||
update_display::spawn(spectrum.clone()).unwrap();
|
||||
update_display::spawn(fft_input).unwrap();
|
||||
|
||||
*cx.local.iq_buffer = Some(buffer);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue