Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions firmware/Cargo.lock

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

6 changes: 6 additions & 0 deletions firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ log = "0.4.27"

embassy-executor = { version = "0.9.1", features = ["log"] }
embassy-time = { version = "0.5.0", features = ["log"] }
embassy-embedded-hal = { version = "0.5.0" }
embassy-sync = { version = "0.7.2", features = ["log"] }
esp-backtrace = { version = "0.18.1", features = ["esp32c6", "panic-handler", "println"] }
esp-println = { version = "0.16.1", features = ["esp32c6", "log-04"] }
esp-alloc = { version = "0.9.0", features = ["esp32c6"] }
heapless = { version = "0.9.2" }

embedded-graphics = { version = "0.8.2" }
mipidsi = { version = "0.8", features = ["batch", "heapless"] }
display-interface-spi = { version = "0.5.0" }

critical-section = "1.2.0"
static_cell = "2.1.1"
Expand Down
108 changes: 103 additions & 5 deletions firmware/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,39 @@ use esp_alloc as _;
)]
use esp_backtrace as _;

use core::cell::RefCell;
use core::ops::Add;
use core::str::FromStr;
use embassy_embedded_hal::shared_bus::blocking::spi::SpiDevice;
use embassy_executor::{Spawner, task};
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::channel::Channel;
use embassy_sync::{
blocking_mutex::{Mutex, raw::NoopRawMutex},
channel::Channel,
};
use embassy_time::Delay;
use embassy_time::Timer;
use embedded_graphics::draw_target::DrawTarget;
use embedded_graphics::mono_font::{MonoTextStyleBuilder, ascii::FONT_10X20};
use embedded_graphics::prelude::*;
use embedded_graphics::primitives::PrimitiveStyleBuilder;
use embedded_graphics::text::{Alignment, Baseline, TextStyleBuilder};
use embedded_graphics::{pixelcolor::Rgb565, text::Text};
use esp_hal::Async;
use esp_hal::clock::CpuClock;
use esp_hal::gpio::{Level, Output, OutputConfig};
use esp_hal::spi::master::Spi;
use esp_hal::time::Rate;
use esp_hal::timer::timg::TimerGroup;
use esp_hal::uart::{Config as UartConfig, DataBits, Parity, StopBits, Uart, UartRx, UartTx};
use esp_println::println;
use firmware::layout::DisplayLayout;
use firmware::midi::{MidiPacket, MidiParser};
use heapless::String;
use log::info;
use mipidsi::models::ST7789;
use mipidsi::options::Rotation::Deg270;
use mipidsi::options::{ColorInversion, Orientation};

// This creates a default app-descriptor required by the esp-idf bootloader.
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
Expand Down Expand Up @@ -70,8 +92,7 @@ async fn midi_out_task(mut uart: UartTx<'static, Async>) {
async fn main(spawner: Spawner) -> ! {
esp_println::logger::init_logger_from_env();

let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
let peripherals = esp_hal::init(esp_hal::Config::default().with_cpu_clock(CpuClock::max()));

let timg0 = TimerGroup::new(peripherals.TIMG0);
let sw_interrupt =
Expand All @@ -80,6 +101,83 @@ async fn main(spawner: Spawner) -> ! {

info!("Embassy initialized!");

let spi = Spi::new(
peripherals.SPI2,
esp_hal::spi::master::Config::default().with_frequency(Rate::from_mhz(40)),
)
.expect("Failed to initialise SPI2 peripheral")
.with_sck(peripherals.GPIO18)
.with_mosi(peripherals.GPIO19)
.with_cs(peripherals.GPIO20);

let cs = Output::new(peripherals.GPIO5, Level::High, OutputConfig::default());
let spi_bus: Mutex<NoopRawMutex, _> = Mutex::new(RefCell::new(spi));
let spi_device = SpiDevice::new(&spi_bus, cs);

let dc = Output::new(peripherals.GPIO21, Level::Low, OutputConfig::default());
let di = display_interface_spi::SPIInterface::new(spi_device, dc);
let mut display = mipidsi::Builder::new(ST7789, di)
.display_size(240, 280)
.orientation(Orientation::default().rotate(Deg270))
.display_offset(0, 20)
.invert_colors(ColorInversion::Inverted)
// TODO: Add reset pin
.init(&mut Delay)
.expect("Failed to initialise ST7789 display");

display.clear(Rgb565::BLACK).unwrap();

embedded_graphics::primitives::Rectangle::new(
Point::zero(),
Size::new(display.size().width, display.size().height / 3),
)
.into_styled(
PrimitiveStyleBuilder::new()
.fill_color(Rgb565::CSS_ORANGE)
.build(),
)
.draw(&mut display)
.unwrap();
embedded_graphics::primitives::Rectangle::new(
Point::new(
0,
display.size().height as i32 - display.size().height as i32 / 3,
),
Size::new(display.size().width, display.size().height / 3),
)
.into_styled(
PrimitiveStyleBuilder::new()
.fill_color(Rgb565::BLUE)
.build(),
)
.draw(&mut display)
.unwrap();

let text_style = TextStyleBuilder::new()
.alignment(Alignment::Center)
.baseline(Baseline::Middle)
.build();
let character_style = MonoTextStyleBuilder::new()
.font(&FONT_10X20)
.text_color(Rgb565::GREEN)
.build();
Text::with_text_style(
"Hello, world!",
display
.bounding_box()
.top_left
.add(Point::new(display.size().width as i32 / 2, 60)),
character_style,
text_style,
)
.draw(&mut display)
.unwrap();

let mut layout = DisplayLayout::new(&mut display);
layout.set_top_text(String::from_str("Foo").unwrap());
layout.set_bottom_text(String::from_str("Bar").unwrap());
layout.draw().unwrap();

let uart = Uart::new(
peripherals.UART1,
UartConfig::default()
Expand All @@ -88,7 +186,7 @@ async fn main(spawner: Spawner) -> ! {
.with_parity(Parity::None)
.with_stop_bits(StopBits::_1),
)
.expect("Failed to initialize UART0")
.expect("Failed to initialise UART1")
.with_rx(peripherals.GPIO7)
.with_tx(peripherals.GPIO8)
.into_async();
Expand All @@ -106,7 +204,7 @@ async fn main(spawner: Spawner) -> ! {
info!("Startup complete.");

loop {
Timer::after_secs(1).await;
Timer::after_secs(5).await;
println!("Heartbeat");
}
}
Loading