Skip to content

Commit

Permalink
more clean up and test
Browse files Browse the repository at this point in the history
  • Loading branch information
vk2seb committed Nov 17, 2023
1 parent 5690fc9 commit 43b35d5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 55 deletions.
2 changes: 1 addition & 1 deletion firmware/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ cargo clippy --target=riscv32imac-unknown-none-elf
cargo build --target=riscv32imac-unknown-none-elf --release

# Copy it into a binary that litex_term can upload.
${OBJCOPY} target/riscv32imac-unknown-none-elf/release/litex-fw -O binary $BUILD_DIR/rust-fw.bin
${OBJCOPY} target/riscv32imac-unknown-none-elf/release/polyvec_main -O binary $BUILD_DIR/rust-fw.bin
121 changes: 67 additions & 54 deletions firmware/litex-fw/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,52 @@ use embedded_graphics::{
use crate::voice::*;
use crate::opt;

fn draw_voice<D>(d: &mut D, sx: i32, sy: u32, ix: u32, voice: &Voice) -> Result<(), D::Error>
fn draw_title_box<D>(d: &mut D, title: &String<16>, top_left: Point, size: Size) -> Result<(), D::Error>
where
D: DrawTarget<Color = Gray4>,
{
let title_y = 10u32;
let font_height = 7i32;

let character_style_h = MonoTextStyle::new(&FONT_5X7, Gray4::WHITE);
let thin_stroke = PrimitiveStyle::with_stroke(Gray4::WHITE, 1);
let thin_stroke_grey = PrimitiveStyleBuilder::new()
.stroke_color(Gray4::new(0x3))
.stroke_width(1)
.build();
let character_style_h = MonoTextStyle::new(&FONT_5X7, Gray4::WHITE);
let font_small_white = MonoTextStyle::new(&FONT_4X6, Gray4::WHITE);
let title_y = 10u32;
let box_h = 20u32;
let box_y = title_y + 3u32 + box_h;

let mut s: String<32> = String::new();

// Voice box
Rectangle::new(Point::new(sx, sy as i32), Size::new(30, box_y))
// Outer box
Rectangle::new(top_left, size)
.into_styled(thin_stroke_grey)
.draw(d)?;

// Title box
Rectangle::new(Point::new(sx, sy as i32), Size::new(30, title_y))
Rectangle::new(top_left, Size::new(size.width, title_y))
.into_styled(thin_stroke)
.draw(d)?;

// Channel title
ufmt::uwrite!(&mut s, "CH {}", ix).ok();
Text::with_alignment(
&s,
Point::new(sx+5, (sy as i32)+7),
&title,
Point::new(top_left.x + (size.width as i32)/2, top_left.y + font_height),
character_style_h,
Alignment::Left,
Alignment::Center,
)
.draw(d)?;

Ok(())
}

fn draw_voice<D>(d: &mut D, sx: i32, sy: u32, ix: u32, voice: &Voice) -> Result<(), D::Error>
where
D: DrawTarget<Color = Gray4>,
{
let font_small_white = MonoTextStyle::new(&FONT_4X6, Gray4::WHITE);

// Channel title
let mut s: String<16> = String::new();
ufmt::uwrite!(&mut s, "CH {}", ix).ok();
draw_title_box(d, &s, Point::new(sx, sy as i32), Size::new(30, 33))?;

let mut stroke_gain = PrimitiveStyleBuilder::new()
.stroke_color(Gray4::new(0x1))
Expand Down Expand Up @@ -130,17 +138,27 @@ where

let opts_view = opts.view().options();

let vy: usize = 205;
let vy: usize = 152;

let screen_hl = match (opts.view().selected(), opts.modify) {
(None, _) => true,
_ => false,
};

draw_title_box(d, &String::new(), Point::new(1, (vy-17) as i32), Size::new(62, 85))?;

// Draw the current screen text
Text::with_alignment(
opts.screen.value.into(),
Point::new(5, (vy-10) as i32),
match (opts.view().selected(), opts.modify) {
(None, _) => font_small_white,
_ => font_small_grey,
},
Alignment::Left,
Point::new(40, (vy-10) as i32),
if screen_hl { font_small_white } else { font_small_grey },
Alignment::Left
).draw(d)?;

Text::with_alignment(
"OPTIONS: ",
Point::new(4, (vy-10) as i32),
if screen_hl { font_small_white } else { font_small_grey },
Alignment::Left
).draw(d)?;

for (n, opt) in opts_view.iter().enumerate() {
Expand Down Expand Up @@ -175,13 +193,13 @@ where
Ok(())
}

fn draw_ms<D, S, C>(d: &mut D, us: u32, pos: Point, style: S) -> Result<(), D::Error>
fn draw_ms<D, S, C>(d: &mut D, name: &str, us: u32, pos: Point, style: S) -> Result<(), D::Error>
where
D: DrawTarget<Color = C>,
S: TextRenderer<Color = C>,
{
let mut s: String<64> = String::new();
ufmt::uwrite!(&mut s, "{}.", us / 1_000u32).ok();
ufmt::uwrite!(&mut s, "{}: {}.", name, us / 1_000u32).ok();
ufmt::uwrite!(&mut s, "{}ms\n", us % 1_000u32).ok();
Text::with_alignment(
&s,
Expand All @@ -204,45 +222,40 @@ where
D: DrawTarget<Color = Gray4>,
{

let character_style = MonoTextStyle::new(&FONT_5X7, Gray4::WHITE);
let font_small_white = MonoTextStyle::new(&FONT_4X6, Gray4::WHITE);
let thin_stroke = PrimitiveStyle::with_stroke(Gray4::WHITE, 1);


/*
Text::with_alignment(
"POLYPHONIZER",
Point::new(d.bounding_box().center().x, 10),
character_style,
Alignment::Center,
)
.draw(d)?;
*/

if opts.screen.value == opt::Screen::Adsr {
for (n_voice, voice) in voices.iter().enumerate() {
if n_voice % 2 == 0 {
draw_voice(d, 1, (1+35*n_voice/2) as u32,
n_voice as u32, voice)?;
} else {
draw_voice(d, 33, (1+35*(n_voice/2)) as u32,
n_voice as u32, voice)?;
}
for (n_voice, voice) in voices.iter().enumerate() {
if n_voice % 2 == 0 {
draw_voice(d, 1, (1+35*n_voice/2) as u32,
n_voice as u32, voice)?;
} else {
draw_voice(d, 33, (1+35*(n_voice/2)) as u32,
n_voice as u32, voice)?;
}
}

draw_options(d, &opts)?;

draw_ms(d, trace_main_len_us,
Point::new(5, 255), character_style)?;
draw_ms(d, irq0_len_us,
Point::new(5, 245), character_style)?;
let mut s: String<16> = String::new();
ufmt::uwrite!(&mut s, "STATS").ok();
draw_title_box(d, &s, Point::new(1, 222), Size::new(62, 32))?;

draw_ms(d, "main", trace_main_len_us,
Point::new(5, 249), font_small_white)?;
draw_ms(d, "irq0", irq0_len_us,
Point::new(5, 239), font_small_white)?;

{
let mut s: String<16> = String::new();
ufmt::uwrite!(&mut s, "SCOPE").ok();
draw_title_box(d, &s, Point::new(1, 71), Size::new(62, 62))?;

if opts.screen.value == opt::Screen::Scope {
let mut points: [Point; 64] = [Point::new(0, 0); 64];
let mut points: [Point; 60] = [Point::new(0, 0); 60];
for (n, point) in points.iter_mut().enumerate() {
if n < scope_samples.len() {
point.x = n as i32;
point.y = 30 + (scope_samples[n] >> 10) as i32;
point.x = 2 + n as i32;
point.y = 105 + (scope_samples[n] >> 10) as i32;
}
}
Polyline::new(&points)
Expand Down
1 change: 1 addition & 0 deletions firmware/litex-fw/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(not(test))]
#![allow(unused_imports)]

#![no_std]
Expand Down

0 comments on commit 43b35d5

Please sign in to comment.