getting simple display abi

This commit is contained in:
2025-07-30 18:00:47 -06:00
parent 078e1f6931
commit 602e47f57b
4 changed files with 28 additions and 43 deletions

View File

@@ -5,5 +5,5 @@ use shared::keyboard::{KeyCode, KeyEvent, KeyState, Modifiers};
#[repr(C)] #[repr(C)]
pub enum Syscall { pub enum Syscall {
DrawPixels { x: u32, y: u32, color: u32 }, DrawPixel { x: u32, y: u32, color: u16 },
} }

View File

@@ -1,12 +1,31 @@
use abi::Syscall; use abi::Syscall;
use embassy_futures::block_on;
use embedded_graphics::{
Drawable,
pixelcolor::Rgb565,
prelude::{Point, RgbColor, Size},
primitives::{PrimitiveStyle, Rectangle, StyledDrawable},
};
use crate::display::FRAMEBUFFER;
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
pub extern "C" fn syscall_dispatch(call: *const Syscall) -> usize { pub extern "C" fn syscall_dispatch(call: *const Syscall) -> usize {
let call = unsafe { &*call }; let call = unsafe { &*call };
match call { match call {
Syscall::DrawPixels { x, y, color } => { Syscall::DrawPixel { x, y, color } => {
draw_pixel(*x, *y, *color); draw_pixel(*x, *y, *color);
0 0
} }
} }
} }
fn draw_pixel(x: u32, y: u32, color: u16) {
let framebuffer = block_on(FRAMEBUFFER.lock());
Rectangle::new(Point::new(x as i32, y as i32), Size::new(1, 1))
.draw_styled(
&PrimitiveStyle::with_fill(Rgb565::RED),
*framebuffer.borrow_mut().as_mut().unwrap(),
)
.unwrap();
}

View File

@@ -1,24 +1,12 @@
use core::{cell::RefCell, sync::atomic::Ordering}; use core::cell::RefCell;
use defmt::info;
use embassy_rp::{ use embassy_rp::{
gpio::{Level, Output}, gpio::{Level, Output},
peripherals::{PIN_13, PIN_14, PIN_15, SPI1}, peripherals::{PIN_13, PIN_14, PIN_15, SPI1},
spi::{Async, Spi}, spi::{Async, Spi},
}; };
use embassy_sync::{blocking_mutex::raw::ThreadModeRawMutex, mutex::Mutex, signal::Signal}; use embassy_sync::{blocking_mutex::raw::ThreadModeRawMutex, mutex::Mutex};
use embassy_time::{Delay, Instant, Timer}; use embassy_time::{Delay, Timer};
use embedded_graphics::{
Drawable,
draw_target::DrawTarget,
mono_font::{MonoTextStyle, ascii::FONT_10X20},
pixelcolor::Rgb565,
prelude::{Dimensions, Point, RgbColor, Size},
primitives::Rectangle,
text::{Alignment, Text},
};
use embedded_hal_bus::spi::ExclusiveDevice; use embedded_hal_bus::spi::ExclusiveDevice;
use portable_atomic::AtomicBool;
use st7365p_lcd::{FrameBuffer, ST7365P}; use st7365p_lcd::{FrameBuffer, ST7365P};
use static_cell::StaticCell; use static_cell::StaticCell;
@@ -44,7 +32,6 @@ pub async fn init_display(
reset: PIN_15, reset: PIN_15,
) -> DISPLAY { ) -> DISPLAY {
let spi_device = ExclusiveDevice::new(spi, Output::new(cs, Level::Low), Delay).unwrap(); let spi_device = ExclusiveDevice::new(spi, Output::new(cs, Level::Low), Delay).unwrap();
defmt::info!("spi made");
let mut display = ST7365P::new( let mut display = ST7365P::new(
spi_device, spi_device,
Output::new(data, Level::Low), Output::new(data, Level::Low),
@@ -68,7 +55,6 @@ pub async fn init_display(
pub async fn display_handler(mut display: DISPLAY) { pub async fn display_handler(mut display: DISPLAY) {
loop { loop {
defmt::info!("drawing");
FRAMEBUFFER FRAMEBUFFER
.lock() .lock()
.await .await

View File

@@ -3,6 +3,7 @@
#![cfg_attr(not(test), no_std)] #![cfg_attr(not(test), no_std)]
#![cfg_attr(not(test), no_main)] #![cfg_attr(not(test), no_main)]
mod abi;
mod display; mod display;
mod peripherals; mod peripherals;
mod scsi; mod scsi;
@@ -11,7 +12,7 @@ mod usb;
mod utils; mod utils;
use crate::{ use crate::{
display::{FRAMEBUFFER, display_handler, init_display}, display::{display_handler, init_display},
peripherals::{ peripherals::{
conf_peripherals, conf_peripherals,
keyboard::{KeyCode, KeyState, read_keyboard_fifo}, keyboard::{KeyCode, KeyState, read_keyboard_fifo},
@@ -22,9 +23,8 @@ use crate::{
use {defmt_rtt as _, panic_probe as _}; use {defmt_rtt as _, panic_probe as _};
use core::cell::RefCell;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_futures::join::{join, join3}; use embassy_futures::join::join3;
use embassy_rp::{ use embassy_rp::{
gpio::{Input, Level, Output, Pull}, gpio::{Input, Level, Output, Pull},
peripherals::{I2C1, USB}, peripherals::{I2C1, USB},
@@ -32,20 +32,9 @@ use embassy_rp::{
usb as embassy_rp_usb, usb as embassy_rp_usb,
}; };
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::{Delay, Timer}; use embassy_time::{Delay, Timer};
use embedded_graphics::{
Drawable,
mono_font::{MonoTextStyle, ascii::FONT_6X10},
pixelcolor::{BinaryColor, Rgb565},
prelude::{Point, RgbColor},
primitives::Rectangle,
text::{Text, TextStyle},
};
use embedded_hal_bus::spi::ExclusiveDevice; use embedded_hal_bus::spi::ExclusiveDevice;
use embedded_sdmmc::SdCard as SdmmcSdCard; use embedded_sdmmc::SdCard as SdmmcSdCard;
use heapless::String;
embassy_rp::bind_interrupts!(struct Irqs { embassy_rp::bind_interrupts!(struct Irqs {
I2C1_IRQ => i2c::InterruptHandler<I2C1>; I2C1_IRQ => i2c::InterruptHandler<I2C1>;
@@ -77,7 +66,6 @@ async fn main(_spawner: Spawner) {
let display = init_display(spi, cs, data, reset).await; let display = init_display(spi, cs, data, reset).await;
display_handler(display) display_handler(display)
}; };
defmt::info!("ready");
let sdcard = { let sdcard = {
let mut config = spi::Config::default(); let mut config = spi::Config::default();
@@ -100,13 +88,5 @@ async fn main(_spawner: Spawner) {
let usb = embassy_rp_usb::Driver::new(p.USB, Irqs); let usb = embassy_rp_usb::Driver::new(p.USB, Irqs);
let usb_fut = usb_handler(usb, sdcard); let usb_fut = usb_handler(usb, sdcard);
Text::new( join3(async { loop {} }, usb_fut, display_fut).await;
"Framebuffer works",
Point::new(100, 100),
MonoTextStyle::new(&FONT_6X10, Rgb565::GREEN),
)
.draw(*FRAMEBUFFER.lock().await.get_mut().as_mut().unwrap())
.unwrap();
display_fut.await;
} }