Skip to content

Commit

Permalink
oled is working with embedded draw crate and strings
Browse files Browse the repository at this point in the history
  • Loading branch information
vk2seb committed Aug 28, 2023
1 parent 5864c5f commit 5bcfd8e
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 35 deletions.
140 changes: 136 additions & 4 deletions firmware/litex-fw/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion firmware/litex-fw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ edition = "2021"
[dependencies]
riscv = "*"
riscv-rt = "*"
panic-halt = "*"
litex-hal = { path = "../deps/rust-litex-hal", features = ["gpio"] }
litex-pac = { path = "../litex-pac", features = ["rt"] }
ssd1322 = { path = "../ssd1322", features = [] }
Expand All @@ -18,3 +17,5 @@ micromath = "2.0.0"
midi-types = "0.1.7"
seq-macro = "0.3.5"
paste = "1.0.14"
embedded-graphics = "0.8.1"
heapless = "0.7.16"
100 changes: 71 additions & 29 deletions firmware/litex-fw/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ use litex_pac as pac;
use riscv;
use riscv_rt::entry;
use litex_hal::hal::digital::v2::OutputPin;
use core::iter;
use heapless::String;
use core::fmt::Write;

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

use ssd1322 as oled;

Expand Down Expand Up @@ -118,11 +127,30 @@ fn main() -> ! {
timer.delay_ms(10_u16);
rstn.set_high().unwrap();

timer.delay_ms(1_u16);

disp.init(
oled::Config::new(
oled::ComScanDirection::RowZeroLast,
oled::ComLayout::DualProgressive,
).clock_fosc_divset(9, 1)
.display_enhancements(true, true)
.contrast_current(159)
.phase_lengths(5, 14)
.precharge_voltage(31)
.second_precharge_period(8)
.com_deselect_voltage(7),
).unwrap();


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

loop {
/*
defmt::info!("tick - elapsed {} sec", elapsed);
elapsed += 1.0f32;
defmt::info!("PMOD0");
defmt::info!("jack_detect {=u8:x}", peripherals.EURORACK_PMOD0.csr_jack.read().bits() as u8);
defmt::info!("input0 {}", peripherals.EURORACK_PMOD0.csr_cal_in0.read().bits() as i16);
Expand All @@ -139,38 +167,52 @@ fn main() -> ! {
defmt::info!("input3 {}", peripherals.EURORACK_PMOD1.csr_cal_in3.read().bits() as i16);
defmt::info!("serial {=u32:x}", peripherals.EURORACK_PMOD1.csr_eeprom_serial.read().bits() as u32);
timer.delay_ms(1000u32);
*/

disp.init(
oled::Config::new(
oled::ComScanDirection::RowZeroLast,
oled::ComLayout::DualProgressive,
).clock_fosc_divset(9, 1)
.display_enhancements(true, true)
.contrast_current(159)
.phase_lengths(5, 14)
.precharge_voltage(31)
.second_precharge_period(8)
.com_deselect_voltage(7),
).unwrap();
let rect_style = PrimitiveStyleBuilder::new()
.stroke_color(Gray4::new(0x5))
.stroke_width(1)
.fill_color(Gray4::BLACK)
.build();

timer.delay_ms(1000u32);
disp
.bounding_box()
.into_styled(rect_style)
.draw(&mut disp).ok();

// Get a region covering the entire display area, and clear it by writing all zeros.
{
let mut region = disp
.region(oled::PixelCoord(0, 0), oled::PixelCoord(128, 128))
.unwrap();
region.draw_packed(iter::repeat(0x0f)).unwrap();
}
let circle = Circle::new(Point::new(22, 22), 20)
.into_styled(PrimitiveStyle::with_stroke(Gray4::WHITE, 1));

{
let mut region = disp
.region(oled::PixelCoord(128, 0), oled::PixelCoord(256, 128))
.unwrap();
region.draw_packed(iter::repeat(0x10)).unwrap();
}
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();

disp.flush();

defmt::info!("tick - elapsed {} sec", elapsed);
elapsed += 1.0f32;
}
}
2 changes: 1 addition & 1 deletion firmware/ssd1322
Submodule ssd1322 updated 2 files
+1 −0 Cargo.toml
+47 −0 src/display/mod.rs

0 comments on commit 5bcfd8e

Please sign in to comment.