firmware for my Touchscreen E-Paper Input Module for Framework Laptop 16
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

initial syscall implementation

+90 -4
+1
eepy-sys/src/lib.rs
··· 1 1 #![no_std] 2 2 3 3 pub mod header; 4 + pub mod syscall; 4 5 5 6 use core::fmt::{Display, Formatter}; 6 7 pub use tp370pgh01::IMAGE_BYTES;
+24
eepy-sys/src/syscall/mod.rs
··· 1 + /// Perform a raw system call. 2 + #[macro_export] 3 + macro_rules! syscall { 4 + ( 5 + $syscall_num:expr, 6 + $( out $r0out:ident )? $( in $r0in:expr )?, 7 + $( out $r1out:ident )? $( in $r1in:expr )?, 8 + $( out $r2out:ident )? $( in $r2in:expr )?, 9 + $( out $r3out:ident )? $( in $r3in:expr )?, 10 + ) => { 11 + asm!( 12 + "svc #{syscall_num}", 13 + $( in("r0") $r0in, )? 14 + $( lateout("r0") $r0out, )? 15 + $( in("r1") $r1in, )? 16 + $( lateout("r1") $r1out, )? 17 + $( in("r2") $r2in, )? 18 + $( lateout("r2") $r2out, )? 19 + $( in("r3") $r3in, )? 20 + $( lateout("r3") $r3out, )? 21 + syscall_num = const $syscall_num, 22 + ); 23 + } 24 + }
+19 -1
eepy/src/main.rs
··· 5 5 mod gui; 6 6 mod serial; 7 7 mod ringbuffer; 8 + mod syscall; 8 9 10 + use core::arch::asm; 9 11 #[allow(unused_imports)] 10 12 use panic_probe as _; 11 13 #[allow(unused_imports)] ··· 37 39 use fw16_epd_bsp::pac::I2C0; 38 40 use fw16_epd_bsp::pac::interrupt; 39 41 use eepy_gui::draw_target::EpdDrawTarget; 40 - use eepy_sys::{Event, RefreshBlockMode, SafeOption, TouchEvent, TouchEventType}; 42 + use eepy_sys::{syscall as do_syscall, Event, RefreshBlockMode, SafeOption, TouchEvent, TouchEventType}; 41 43 use tp370pgh01::rp2040::{Rp2040PervasiveSpiDelays, IoPin}; 42 44 use tp370pgh01::{Tp370pgh01, IMAGE_BYTES}; 43 45 use crate::ringbuffer::RingBuffer; ··· 325 327 program.entry()(&pft); 326 328 } 327 329 }*/ 330 + 331 + // Test syscall 332 + unsafe { 333 + let mut r0: usize; 334 + let mut r1: usize; 335 + let mut r2: usize; 336 + let mut r3: usize; 337 + do_syscall!( 338 + 31, 339 + out r0 in 0, 340 + out r1 in 1, 341 + out r2 in 2, 342 + out r3 in 3, 343 + ); 344 + debug!("{} {} {} {}", r0, r1, r2, r3); 345 + } 328 346 329 347 let draw_target = EpdDrawTarget::new(write_image, refresh); 330 348 gui::gui_main(draw_target);
+28
eepy/src/syscall.rs
··· 1 + use core::arch::{asm, global_asm}; 2 + use cortex_m_rt::exception; 3 + use defmt::debug; 4 + 5 + global_asm!(include_str!("syscall.s")); 6 + 7 + /// Main syscall (SVC) handler. 8 + /// 9 + /// This function is called by the assembly trampoline code in `syscall.s`. 10 + /// 11 + /// `sp` contains the caller's stack pointer value (taken from either MSP or PSP depending on which 12 + /// stack was active). This is where the register values are pushed when the exception is triggered, 13 + /// so this is where we need to read/write to interface with the caller. 14 + /// This stack location contains (in order): r0, r1, r2, r3, r12, lr, pc, xPSR. 15 + /// The pc value from the stack can be used to extract the literal operand from the SVC instruction 16 + /// which triggered the syscall. 17 + #[no_mangle] 18 + extern "C" fn syscall(sp: *mut usize) { 19 + // Stack contains R0, R1, R2, R3, R12, LR, ReturnAddress, xPSR 20 + let stack_values = unsafe { core::slice::from_raw_parts_mut(sp, 8) }; 21 + let svc_operand = unsafe { (stack_values[6] as *const u8).sub(2).read() }; 22 + debug!("{:x}", svc_operand); 23 + 24 + // Increase the value of R0-R3 by 1 25 + for i in 0..4 { 26 + stack_values[i] += 1; 27 + } 28 + }
+15
eepy/src/syscall.s
··· 1 + .global SVCall 2 + .equ SVCall, _SVCall + 1 /* thumb bit */ 3 + 4 + _SVCall: 5 + movs r0, #4 6 + mov r1, lr 7 + tst r0, r1 8 + beq .use_msp 9 + mrs r0, psp 10 + ldr r1, =syscall 11 + bx r1 12 + .use_msp: 13 + mrs r0, msp 14 + ldr r1, =syscall 15 + bx r1
+1 -1
fw16-epd-gui/src/element/button.rs eepy-gui/src/element/button.rs
··· 4 4 use embedded_graphics::primitives::{CornerRadii, PrimitiveStyle, Rectangle, RoundedRectangle}; 5 5 use embedded_graphics::text::{Alignment, Baseline, Text, TextStyle, TextStyleBuilder}; 6 6 use embedded_graphics::text::renderer::TextRenderer; 7 - use fw16_epd_program_interface::{Event, TouchEventType}; 7 + use eepy_sys::{Event, TouchEventType}; 8 8 use crate::draw_target::EpdDrawTarget; 9 9 use crate::element::{Gui, DEFAULT_PRIMITIVE_STYLE, DEFAULT_TEXT_STYLE}; 10 10
+1 -1
fw16-epd-gui/src/element/mod.rs eepy-gui/src/element/mod.rs
··· 6 6 use embedded_graphics::pixelcolor::BinaryColor; 7 7 use embedded_graphics::prelude::*; 8 8 use embedded_graphics::primitives::{PrimitiveStyle, PrimitiveStyleBuilder, Rectangle}; 9 - use fw16_epd_program_interface::Event; 9 + use eepy_sys::Event; 10 10 use tp370pgh01::{DIM_X, DIM_Y}; 11 11 use crate::draw_target::EpdDrawTarget; 12 12
+1 -1
fw16-epd-gui/src/element/slider.rs eepy-gui/src/element/slider.rs
··· 2 2 use embedded_graphics::geometry::Point; 3 3 use embedded_graphics::pixelcolor::BinaryColor; 4 4 use embedded_graphics::primitives::{Circle, Line, PrimitiveStyle, Rectangle}; 5 - use fw16_epd_program_interface::{Event, TouchEventType}; 5 + use eepy_sys::{Event, TouchEventType}; 6 6 use crate::draw_target::EpdDrawTarget; 7 7 use crate::element::{Gui, DEFAULT_PRIMITIVE_STYLE}; 8 8