Skip to content

Commit

Permalink
print PMOD values and rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
vk2seb committed Aug 28, 2023
1 parent 5bcfd8e commit eab139b
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 36 deletions.
151 changes: 116 additions & 35 deletions firmware/litex-fw/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use core::fmt::Write;

use embedded_graphics::{
pixelcolor::{Gray4, GrayColor},
primitives::{Circle, PrimitiveStyle, PrimitiveStyleBuilder},
mono_font::{ascii::FONT_6X10, MonoTextStyle},
primitives::{Circle, PrimitiveStyle, PrimitiveStyleBuilder, Rectangle},
mono_font::{ascii::FONT_4X6, ascii::FONT_5X7, MonoTextStyle},
prelude::*,
text::Text,
text::{Alignment, Text},
};

use ssd1322 as oled;
Expand Down Expand Up @@ -81,6 +81,64 @@ fn do_write(bytes: &[u8]) {
}
}

fn draw_titlebox<D>(d: &mut D, sy: u32, title: &str, fields: &[&str], values: &[u32]) -> Result<(), D::Error>
where
D: DrawTarget<Color = Gray4>,
{

let thin_stroke = PrimitiveStyle::with_stroke(Gray4::WHITE, 1);
let thin_stroke_grey = PrimitiveStyle::with_stroke(Gray4::new(0x3), 1);
let character_style = MonoTextStyle::new(&FONT_4X6, Gray4::WHITE);
let character_style_h = MonoTextStyle::new(&FONT_5X7, Gray4::WHITE);
let dy = 7u32;
let title_y = 10u32;
let box_y = (title_y + 3u32 + (fields.len() as u32) * dy);

Rectangle::new(Point::new(2, sy as i32), Size::new(60, box_y))
.into_styled(thin_stroke_grey)
.draw(d)?;

Rectangle::new(Point::new(2, sy as i32), Size::new(60, title_y))
.into_styled(thin_stroke)
.draw(d)?;

Text::with_alignment(
title,
Point::new(d.bounding_box().center().x, (sy as i32)+7),
character_style_h,
Alignment::Center,
)
.draw(d)?;

let mut sy = sy + title_y + 6;

for (f, v) in fields.iter().zip(values) {

let mut s: String<32> = String::new();
write!(&mut s, "{:#06x}", v).ok();

Text::with_alignment(
f,
Point::new(5, sy as i32),
character_style,
Alignment::Left,
)
.draw(d)?;

Text::with_alignment(
&s,
Point::new(60, sy as i32),
character_style,
Alignment::Right,
)
.draw(d)?;
sy += dy;
}

Ok(())
}


#[entry]
fn main() -> ! {
let peripherals = unsafe { pac::Peripherals::steal() };
Expand Down Expand Up @@ -145,6 +203,8 @@ fn main() -> ! {

defmt::info!("Starting main loop --");

let character_style = MonoTextStyle::new(&FONT_5X7, Gray4::WHITE);

loop {
/*
Expand All @@ -169,8 +229,9 @@ fn main() -> ! {
timer.delay_ms(1000u32);
*/


let rect_style = PrimitiveStyleBuilder::new()
.stroke_color(Gray4::new(0x5))
.stroke_color(Gray4::new(0x2))
.stroke_width(1)
.fill_color(Gray4::BLACK)
.build();
Expand All @@ -180,37 +241,57 @@ fn main() -> ! {
.into_styled(rect_style)
.draw(&mut disp).ok();

let circle = Circle::new(Point::new(22, 22), 20)
.into_styled(PrimitiveStyle::with_stroke(Gray4::WHITE, 1));

circle.draw(&mut disp).unwrap();

let style = MonoTextStyle::new(&FONT_6X10, Gray4::WHITE);

Text::new("Hello,\nRust!", Point::new(0, 12), style).draw(&mut disp).ok();

let mut s: String<128> = String::new();
write!(&mut s, "serial0 {:#06x}", peripherals.EURORACK_PMOD0.csr_eeprom_serial.read().bits() as u32).ok();

Text::new(&s, Point::new(128, 12), style).draw(&mut disp).ok();

s.clear();

write!(&mut s, "serial1 {:#06x}", peripherals.EURORACK_PMOD1.csr_eeprom_serial.read().bits() as u32).ok();

Text::new(&s, Point::new(128, 24), style).draw(&mut disp).ok();

s.clear();

write!(&mut s, "jack0 {:#06x}", peripherals.EURORACK_PMOD0.csr_jack.read().bits() as u32).ok();

Text::new(&s, Point::new(128, 36), style).draw(&mut disp).ok();

s.clear();

write!(&mut s, "jack1 {:#06x}", peripherals.EURORACK_PMOD1.csr_jack.read().bits() as u32).ok();

Text::new(&s, Point::new(128, 48), style).draw(&mut disp).ok();
Text::with_alignment(
"<TEST UTIL>",
Point::new(disp.bounding_box().center().x, 10),
character_style,
Alignment::Center,
)
.draw(&mut disp).ok();

draw_titlebox(&mut disp, 16, "PMOD1", &[
"ser:",
"jck:",
"in0:",
"in1:",
"in2:",
"in3:",
], &[
peripherals.EURORACK_PMOD0.csr_eeprom_serial.read().bits().into(),
peripherals.EURORACK_PMOD0.csr_jack.read().bits().into(),
peripherals.EURORACK_PMOD0.csr_cal_in0.read().bits().into(),
peripherals.EURORACK_PMOD0.csr_cal_in1.read().bits().into(),
peripherals.EURORACK_PMOD0.csr_cal_in2.read().bits().into(),
peripherals.EURORACK_PMOD0.csr_cal_in3.read().bits().into(),
]).ok();

draw_titlebox(&mut disp, 74, "PMOD2", &[
"ser:",
"jck:",
"in0:",
"in1:",
"in2:",
"in3:",
], &[
peripherals.EURORACK_PMOD1.csr_eeprom_serial.read().bits().into(),
peripherals.EURORACK_PMOD1.csr_jack.read().bits().into(),
peripherals.EURORACK_PMOD1.csr_cal_in0.read().bits().into(),
peripherals.EURORACK_PMOD1.csr_cal_in1.read().bits().into(),
peripherals.EURORACK_PMOD1.csr_cal_in2.read().bits().into(),
peripherals.EURORACK_PMOD1.csr_cal_in3.read().bits().into(),
]).ok();

draw_titlebox(&mut disp, 132, "ENCODER", &[
"tick:",
"btn:",
], &[0, 0]).ok();

draw_titlebox(&mut disp, 213, "MIDI", &[
"---",
"---",
"---",
"---",
], &[0, 0, 0, 0]).ok();

disp.flush();

Expand Down
2 changes: 1 addition & 1 deletion firmware/ssd1322
Submodule ssd1322 updated 1 files
+3 −3 src/display/mod.rs

0 comments on commit eab139b

Please sign in to comment.