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)]
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 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)]
pub extern "C" fn syscall_dispatch(call: *const Syscall) -> usize {
let call = unsafe { &*call };
match call {
Syscall::DrawPixels { x, y, color } => {
Syscall::DrawPixel { x, y, color } => {
draw_pixel(*x, *y, *color);
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 defmt::info;
use core::cell::RefCell;
use embassy_rp::{
gpio::{Level, Output},
peripherals::{PIN_13, PIN_14, PIN_15, SPI1},
spi::{Async, Spi},
};
use embassy_sync::{blocking_mutex::raw::ThreadModeRawMutex, mutex::Mutex, signal::Signal};
use embassy_time::{Delay, Instant, 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 embassy_sync::{blocking_mutex::raw::ThreadModeRawMutex, mutex::Mutex};
use embassy_time::{Delay, Timer};
use embedded_hal_bus::spi::ExclusiveDevice;
use portable_atomic::AtomicBool;
use st7365p_lcd::{FrameBuffer, ST7365P};
use static_cell::StaticCell;
@@ -44,7 +32,6 @@ pub async fn init_display(
reset: PIN_15,
) -> DISPLAY {
let spi_device = ExclusiveDevice::new(spi, Output::new(cs, Level::Low), Delay).unwrap();
defmt::info!("spi made");
let mut display = ST7365P::new(
spi_device,
Output::new(data, Level::Low),
@@ -68,7 +55,6 @@ pub async fn init_display(
pub async fn display_handler(mut display: DISPLAY) {
loop {
defmt::info!("drawing");
FRAMEBUFFER
.lock()
.await

View File

@@ -3,6 +3,7 @@
#![cfg_attr(not(test), no_std)]
#![cfg_attr(not(test), no_main)]
mod abi;
mod display;
mod peripherals;
mod scsi;
@@ -11,7 +12,7 @@ mod usb;
mod utils;
use crate::{
display::{FRAMEBUFFER, display_handler, init_display},
display::{display_handler, init_display},
peripherals::{
conf_peripherals,
keyboard::{KeyCode, KeyState, read_keyboard_fifo},
@@ -22,9 +23,8 @@ use crate::{
use {defmt_rtt as _, panic_probe as _};
use core::cell::RefCell;
use embassy_executor::Spawner;
use embassy_futures::join::{join, join3};
use embassy_futures::join::join3;
use embassy_rp::{
gpio::{Input, Level, Output, Pull},
peripherals::{I2C1, USB},
@@ -32,20 +32,9 @@ use embassy_rp::{
usb as embassy_rp_usb,
};
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 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_sdmmc::SdCard as SdmmcSdCard;
use heapless::String;
embassy_rp::bind_interrupts!(struct Irqs {
I2C1_IRQ => i2c::InterruptHandler<I2C1>;
@@ -77,7 +66,6 @@ async fn main(_spawner: Spawner) {
let display = init_display(spi, cs, data, reset).await;
display_handler(display)
};
defmt::info!("ready");
let sdcard = {
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_fut = usb_handler(usb, sdcard);
Text::new(
"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;
join3(async { loop {} }, usb_fut, display_fut).await;
}