can drawiter
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -16,6 +16,7 @@ dependencies = [
|
|||||||
name = "abi"
|
name = "abi"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"embedded-graphics",
|
||||||
"shared",
|
"shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
embedded-graphics = "0.8.1"
|
||||||
shared = { path = "../shared" }
|
shared = { path = "../shared" }
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
use core::ffi::c_void;
|
pub use embedded_graphics::{
|
||||||
|
Pixel,
|
||||||
|
geometry::Point,
|
||||||
|
pixelcolor::{Rgb565, RgbColor},
|
||||||
|
};
|
||||||
use shared::keyboard::{KeyCode, KeyEvent, KeyState, Modifiers};
|
use shared::keyboard::{KeyCode, KeyEvent, KeyState, Modifiers};
|
||||||
|
|
||||||
// Instead of extern, declare a static pointer in a dedicated section
|
// Instead of extern, declare a static pointer in a dedicated section
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
#[unsafe(link_section = ".user_reloc")]
|
#[unsafe(link_section = ".user_reloc")]
|
||||||
|
#[allow(non_upper_case_globals)]
|
||||||
pub static mut call_abi_ptr: usize = 0;
|
pub static mut call_abi_ptr: usize = 0;
|
||||||
|
|
||||||
// Helper to call it
|
// Helper to call it
|
||||||
@@ -16,5 +21,8 @@ pub unsafe fn call_abi(call: *const Syscall) {
|
|||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub enum Syscall {
|
pub enum Syscall {
|
||||||
DrawPixel { x: u32, y: u32, color: u16 },
|
DrawIter {
|
||||||
|
pixels: *const Pixel<Rgb565>,
|
||||||
|
len: usize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use defmt::info;
|
|||||||
use embassy_futures::block_on;
|
use embassy_futures::block_on;
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
Drawable,
|
Drawable,
|
||||||
|
draw_target::DrawTarget,
|
||||||
pixelcolor::Rgb565,
|
pixelcolor::Rgb565,
|
||||||
prelude::{Point, RgbColor, Size},
|
prelude::{Point, RgbColor, Size},
|
||||||
primitives::{PrimitiveStyle, Rectangle, StyledDrawable},
|
primitives::{PrimitiveStyle, Rectangle, StyledDrawable},
|
||||||
@@ -15,19 +16,17 @@ pub extern "C" fn call_abi(call: *const Syscall) {
|
|||||||
info!("called abi");
|
info!("called abi");
|
||||||
let call = unsafe { &*call };
|
let call = unsafe { &*call };
|
||||||
match call {
|
match call {
|
||||||
Syscall::DrawPixel { x, y, color } => {
|
Syscall::DrawIter { pixels, len } => {
|
||||||
draw_pixel(*x, *y, *color);
|
// SAFETY: we're trusting the user program here
|
||||||
|
let slice = unsafe { core::slice::from_raw_parts(*pixels, *len) };
|
||||||
|
|
||||||
|
let framebuffer = block_on(FRAMEBUFFER.lock());
|
||||||
|
framebuffer
|
||||||
|
.borrow_mut()
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.draw_iter(slice.iter().copied())
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_pixel(x: u32, y: u32, color: u16) {
|
|
||||||
info!("draw pixel abi called");
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
abi = { path ="../../abi" }
|
abi = { path = "../../abi" }
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use abi::{Syscall, call_abi};
|
use abi::{Pixel, Point, Rgb565, RgbColor, Syscall, call_abi};
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
@@ -11,14 +11,23 @@ fn panic(_info: &PanicInfo) -> ! {
|
|||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn _start() {
|
pub extern "C" fn _start() {
|
||||||
for i in 0..300 {
|
// Local pixel buffer
|
||||||
for o in 0..300 {
|
let mut pixels = [Pixel(Point { x: 50, y: 50 }, Rgb565::RED); 300];
|
||||||
let call = Syscall::DrawPixel {
|
for (i, p) in pixels.iter_mut().enumerate() {
|
||||||
x: i,
|
*p = Pixel(
|
||||||
y: o,
|
Point {
|
||||||
color: 0,
|
x: i as i32,
|
||||||
};
|
y: i as i32,
|
||||||
unsafe { call_abi(&call) };
|
},
|
||||||
}
|
Rgb565::RED,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Construct syscall with raw pointer + length
|
||||||
|
let call = Syscall::DrawIter {
|
||||||
|
pixels: pixels.as_ptr(), // raw pointer
|
||||||
|
len: pixels.len(), // number of elements
|
||||||
|
};
|
||||||
|
|
||||||
|
unsafe { call_abi(&call) };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user