From a537d9ea69daf0cecbe97386a9e288e365f2f34d Mon Sep 17 00:00:00 2001 From: sawyer bristol Date: Sat, 12 Jul 2025 13:43:25 -0600 Subject: [PATCH] kinda working --- Cargo.lock | 13 +++++++------ Cargo.toml | 1 + src/display.rs | 37 ++++++++++++++++++++++--------------- src/main.rs | 40 +++++++++++++++++++++++++++++----------- src/peripherals/mod.rs | 6 ++---- 5 files changed, 61 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1dc6e45..7826c31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1006,9 +1006,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" dependencies = [ "equivalent", "hashbrown", @@ -1355,6 +1355,7 @@ dependencies = [ "embedded-hal-async", "embedded-hal-bus", "embedded-sdmmc", + "heapless", "panic-probe", "portable-atomic", "spin", @@ -1606,9 +1607,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rgb" -version = "0.8.50" +version = "0.8.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a" +checksum = "a457e416a0f90d246a4c3288bd7a25b2304ca727f253f95be383dd17af56be8f" dependencies = [ "bytemuck", ] @@ -1740,8 +1741,8 @@ dependencies = [ [[package]] name = "st7365p-lcd" -version = "0.10.0" -source = "git+https://github.com/legitcamper/st7365p-lcd-rs?branch=async#f826038c0c8e4150be8581d30a8c6fe480947f66" +version = "0.11.0" +source = "git+https://github.com/legitcamper/st7365p-lcd-rs?branch=async#c0928418608cbd88096c7e2535063f6afb49a122" dependencies = [ "embedded-graphics-core", "embedded-hal 1.0.0", diff --git a/Cargo.toml b/Cargo.toml index 01e4fec..6477884 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,3 +77,4 @@ static_cell = "2.1.1" bitflags = "2.9.1" talc = "4.4.3" spin = "0.10.0" +heapless = "0.8.0" diff --git a/src/display.rs b/src/display.rs index 06273fc..6d6550f 100644 --- a/src/display.rs +++ b/src/display.rs @@ -1,3 +1,4 @@ +use defmt::info; use embassy_rp::{ gpio::{Level, Output}, peripherals::{PIN_13, PIN_14, PIN_15, SPI1}, @@ -17,8 +18,12 @@ use st7365p_lcd::{FrameBuffer, ST7365P}; const SCREEN_WIDTH: usize = 320; const SCREEN_HEIGHT: usize = 320; -#[embassy_executor::task] -pub async fn display_task(spi: Spi<'static, SPI1, Async>, cs: PIN_13, data: PIN_14, reset: PIN_15) { +pub async fn display_handler( + spi: Spi<'static, SPI1, Async>, + cs: PIN_13, + data: PIN_14, + reset: PIN_15, +) { let spi_device = ExclusiveDevice::new(spi, Output::new(cs, Level::Low), Delay).unwrap(); let mut display = ST7365P::new( spi_device, @@ -26,23 +31,25 @@ pub async fn display_task(spi: Spi<'static, SPI1, Async>, cs: PIN_13, data: PIN_ Some(Output::new(reset, Level::High)), false, true, + Delay, ); - display.init(&mut Delay).await.unwrap(); - display.set_custom_orientation(0x60).await.unwrap(); - let mut framebuffer: FrameBuffer = FrameBuffer::new(); - - Text::with_alignment( - "Hello!", - Point::new(160, 160), - MonoTextStyle::new(&FONT_10X20, Rgb565::RED), - embedded_graphics::text::Alignment::Center, - ) - .draw(&mut framebuffer) - .unwrap(); + display.init().await.unwrap(); + display.set_custom_orientation(0x60).await.unwrap(); + framebuffer.draw(&mut display).await.unwrap(); + display.set_on().await.unwrap(); loop { + Text::with_alignment( + &crate::STRING.lock().await.as_str(), + Point::new(160, 160), + MonoTextStyle::new(&FONT_10X20, Rgb565::RED), + embedded_graphics::text::Alignment::Center, + ) + .draw(&mut framebuffer) + .unwrap(); + framebuffer.draw(&mut display).await.unwrap(); - Timer::after_millis(500).await; + Timer::after_millis(100).await } } diff --git a/src/main.rs b/src/main.rs index 2c1fd32..0bb41bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,42 +3,60 @@ #![no_std] #![no_main] +use crate::peripherals::keyboard::{KeyCode, read_keyboard_fifo}; + use {defmt_rtt as _, panic_probe as _}; use embassy_executor::Spawner; +use embassy_futures::join::join; use embassy_rp::peripherals::I2C1; -use embassy_rp::{ - i2c, - i2c::I2c, - spi, -}; +use embassy_rp::{i2c, i2c::I2c, spi}; +use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; +use embassy_sync::mutex::Mutex; +use embassy_time::Timer; +use heapless::String; mod peripherals; use peripherals::conf_peripherals; mod display; -use display::display_task; +use display::display_handler; embassy_rp::bind_interrupts!(struct Irqs { I2C1_IRQ => i2c::InterruptHandler; }); +static STRING: Mutex> = Mutex::new(String::new()); + #[embassy_executor::main] -async fn main(spawner: Spawner) { +async fn main(_spawner: Spawner) { let p = embassy_rp::init(Default::default()); + STRING.lock().await.push_str("T: ").unwrap(); + // configure keyboard event handler let mut config = i2c::Config::default(); config.frequency = 100_000; let i2c1 = I2c::new_async(p.I2C1, p.PIN_7, p.PIN_6, Irqs, config); conf_peripherals(i2c1).await; - // configure display handler let mut config = spi::Config::default(); config.frequency = 16_000_000; let spi1 = spi::Spi::new( p.SPI1, p.PIN_10, p.PIN_11, p.PIN_12, p.DMA_CH0, p.DMA_CH1, config, ); - spawner - .spawn(display_task(spi1, p.PIN_13, p.PIN_14, p.PIN_15)) - .unwrap(); + + join( + async { + loop { + Timer::after_millis(100).await; + if let Some(key) = read_keyboard_fifo().await { + if let KeyCode::Char(c) = key.key { + STRING.lock().await.push(c).unwrap(); + } + } + } + }, + display_handler(spi1, p.PIN_13, p.PIN_14, p.PIN_15), + ) + .await; } diff --git a/src/peripherals/mod.rs b/src/peripherals/mod.rs index bdef798..df5ab23 100644 --- a/src/peripherals/mod.rs +++ b/src/peripherals/mod.rs @@ -5,9 +5,7 @@ use embassy_rp::{ i2c::{Async, I2c}, peripherals::I2C1, }; -use embassy_sync::{ - blocking_mutex::raw::NoopRawMutex, lazy_lock::LazyLock, mutex::Mutex, -}; +use embassy_sync::{blocking_mutex::raw::NoopRawMutex, lazy_lock::LazyLock, mutex::Mutex}; use embassy_time::Timer; pub mod keyboard; @@ -30,7 +28,7 @@ pub async fn conf_peripherals(i2c: I2CBUS) { PERIPHERAL_BUS.get().lock().await.replace(i2c); configure_keyboard(200, 100).await; - set_lcd_backlight(255).await; + // set_lcd_backlight(255).await; set_key_backlight(0).await; }