alpha
Login
or
Join now
arthomnix.dev
/
eepy
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
firmware for my Touchscreen E-Paper Input Module for Framework Laptop 16
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
eepy: reorganise syscall handlers
author
arthomnix
date
1 year ago
(Jan 25, 2025, 7:47 PM UTC)
commit
ba9dfeb2
ba9dfeb21c7eeecfa26c5d9fb98dd8869762d164
parent
b2714331
b271433151915ff9abc7a08e245f1b28cd7bd2eb
+92
-80
1 changed file
Expand all
Collapse all
Unified
Split
eepy
src
syscall.rs
+92
-80
eepy/src/syscall.rs
Reviewed
···
1
1
use core::arch::global_asm;
2
2
-
use core::sync::atomic::Ordering;
3
2
use defmt::trace;
4
4
-
use eepy_sys::image::{ImageSyscall, RefreshBlockMode};
5
5
-
use eepy_sys::input::{Event, InputSyscall, ScEventType, TouchEvent, TouchEventType};
6
6
-
use eepy_sys::misc::MiscSyscall;
7
3
use eepy_sys::syscall::SyscallNumber;
8
8
-
use tp370pgh01::IMAGE_BYTES;
9
9
-
use crate::{DO_REFRESH, EVENT_QUEUE, FAST_REFRESH, IMAGE_BUFFER, REFRESHING, SERIAL_NUMBER, TOUCH_ENABLED};
10
4
11
5
global_asm!(include_str!("syscall.s"));
12
6
···
41
35
);
42
36
43
37
match SyscallNumber::try_from(syscall_num) {
44
44
-
Ok(SyscallNumber::Misc) => handle_misc(stack_values),
45
45
-
Ok(SyscallNumber::Image) => handle_image(stack_values),
46
46
-
Ok(SyscallNumber::Input) => handle_input(stack_values),
38
38
+
Ok(SyscallNumber::Misc) => misc::handle_misc(stack_values),
39
39
+
Ok(SyscallNumber::Image) => image::handle_image(stack_values),
40
40
+
Ok(SyscallNumber::Input) => input::handle_input(stack_values),
47
41
Ok(SyscallNumber::Usb) => todo!("usb syscalls"),
48
42
_ => panic!("illegal syscall"),
49
43
}
50
44
}
51
45
52
52
-
fn handle_misc(stack_values: &mut [usize]) {
53
53
-
match MiscSyscall::try_from(stack_values[0]) {
54
54
-
Ok(MiscSyscall::GetSerial) => handle_get_serial(stack_values),
55
55
-
_ => panic!("illegal syscall"),
46
46
+
mod misc {
47
47
+
use eepy_sys::misc::MiscSyscall;
48
48
+
use crate::SERIAL_NUMBER;
49
49
+
50
50
+
pub(super) fn handle_misc(stack_values: &mut [usize]) {
51
51
+
match MiscSyscall::try_from(stack_values[0]) {
52
52
+
Ok(MiscSyscall::GetSerial) => handle_get_serial(stack_values),
53
53
+
_ => panic!("illegal syscall"),
54
54
+
}
55
55
+
}
56
56
+
57
57
+
fn handle_get_serial(stack_values: &mut [usize]) {
58
58
+
stack_values[0] = (&raw const *SERIAL_NUMBER.get().unwrap()) as usize;
56
59
}
57
60
}
58
61
59
59
-
fn handle_get_serial(stack_values: &mut [usize]) {
60
60
-
stack_values[0] = (&raw const *SERIAL_NUMBER.get().unwrap()) as usize;
61
61
-
}
62
62
+
mod image {
63
63
+
use core::sync::atomic::Ordering;
64
64
+
use eepy_sys::image::{ImageSyscall, RefreshBlockMode};
65
65
+
use tp370pgh01::IMAGE_BYTES;
66
66
+
use crate::{DO_REFRESH, FAST_REFRESH, IMAGE_BUFFER, REFRESHING};
62
67
63
63
-
fn handle_image(stack_values: &mut [usize]) {
64
64
-
match ImageSyscall::try_from(stack_values[0]) {
65
65
-
Ok(ImageSyscall::WriteImage) => handle_write_image(stack_values),
66
66
-
Ok(ImageSyscall::Refresh) => handle_refresh(stack_values),
67
67
-
_ => panic!("illegal syscall"),
68
68
+
pub(super) fn handle_image(stack_values: &mut [usize]) {
69
69
+
match ImageSyscall::try_from(stack_values[0]) {
70
70
+
Ok(ImageSyscall::WriteImage) => handle_write_image(stack_values),
71
71
+
Ok(ImageSyscall::Refresh) => handle_refresh(stack_values),
72
72
+
_ => panic!("illegal syscall"),
73
73
+
}
68
74
}
69
69
-
}
70
75
71
71
-
fn handle_write_image(stack_values: &mut [usize]) {
72
72
-
let image: &[u8; IMAGE_BYTES] = unsafe { &*(stack_values[1] as *const [u8; IMAGE_BYTES]) };
73
73
-
critical_section::with(|cs| IMAGE_BUFFER.borrow_ref_mut(cs).copy_from_slice(image));
74
74
-
}
76
76
+
fn handle_write_image(stack_values: &mut [usize]) {
77
77
+
let image: &[u8; IMAGE_BYTES] = unsafe { &*(stack_values[1] as *const [u8; IMAGE_BYTES]) };
78
78
+
critical_section::with(|cs| IMAGE_BUFFER.borrow_ref_mut(cs).copy_from_slice(image));
79
79
+
}
75
80
76
76
-
fn handle_refresh(stack_values: &mut [usize]) {
77
77
-
let fast_refresh = stack_values[1] != 0;
78
78
-
let blocking_mode = RefreshBlockMode::try_from(stack_values[2]).expect("illegal refresh blocking mode");
81
81
+
fn handle_refresh(stack_values: &mut [usize]) {
82
82
+
let fast_refresh = stack_values[1] != 0;
83
83
+
let blocking_mode = RefreshBlockMode::try_from(stack_values[2]).expect("illegal refresh blocking mode");
79
84
80
80
-
DO_REFRESH.store(true, Ordering::Relaxed);
81
81
-
FAST_REFRESH.store(fast_refresh, Ordering::Relaxed);
82
82
-
cortex_m::asm::sev();
85
85
+
DO_REFRESH.store(true, Ordering::Relaxed);
86
86
+
FAST_REFRESH.store(fast_refresh, Ordering::Relaxed);
87
87
+
cortex_m::asm::sev();
83
88
84
84
-
if matches!(blocking_mode, RefreshBlockMode::BlockAcknowledge | RefreshBlockMode::BlockFinish) {
85
85
-
while DO_REFRESH.load(Ordering::Relaxed) {}
86
86
-
}
89
89
+
if matches!(blocking_mode, RefreshBlockMode::BlockAcknowledge | RefreshBlockMode::BlockFinish) {
90
90
+
while DO_REFRESH.load(Ordering::Relaxed) {}
91
91
+
}
87
92
88
88
-
if matches!(blocking_mode, RefreshBlockMode::BlockFinish) {
89
89
-
while REFRESHING.load(Ordering::Relaxed) {}
93
93
+
if matches!(blocking_mode, RefreshBlockMode::BlockFinish) {
94
94
+
while REFRESHING.load(Ordering::Relaxed) {}
95
95
+
}
90
96
}
91
97
}
92
98
93
93
-
fn handle_input(stack_values: &mut [usize]) {
94
94
-
match InputSyscall::try_from(stack_values[0]) {
95
95
-
Ok(InputSyscall::NextEvent) => handle_next_event(stack_values),
96
96
-
Ok(InputSyscall::SetTouchEnabled) => handle_set_touch_enabled(stack_values),
97
97
-
Ok(InputSyscall::HasEvent) => handle_has_event(stack_values),
98
98
-
_ => panic!("illegal syscall"),
99
99
+
mod input {
100
100
+
use core::sync::atomic::Ordering;
101
101
+
use eepy_sys::input::{Event, InputSyscall, ScEventType, TouchEvent, TouchEventType};
102
102
+
use crate::{EVENT_QUEUE, TOUCH_ENABLED};
103
103
+
104
104
+
pub(super) fn handle_input(stack_values: &mut [usize]) {
105
105
+
match InputSyscall::try_from(stack_values[0]) {
106
106
+
Ok(InputSyscall::NextEvent) => handle_next_event(stack_values),
107
107
+
Ok(InputSyscall::SetTouchEnabled) => handle_set_touch_enabled(stack_values),
108
108
+
Ok(InputSyscall::HasEvent) => handle_has_event(stack_values),
109
109
+
_ => panic!("illegal syscall"),
110
110
+
}
99
111
}
100
100
-
}
101
112
102
102
-
fn handle_next_event(stack_values: &mut [usize]) {
103
103
-
let next_event = critical_section::with(|cs| EVENT_QUEUE.borrow_ref_mut(cs).pop());
104
104
-
let mut x = 0;
105
105
-
let mut y = 0;
106
106
-
let sc_ev_type = match next_event {
107
107
-
None => ScEventType::NoEvent,
108
108
-
Some(Event::Touch(TouchEvent { ev_type: TouchEventType::Down, x: px, y: py })) => {
109
109
-
x = px;
110
110
-
y = py;
111
111
-
ScEventType::TouchDown
112
112
-
},
113
113
-
Some(Event::Touch(TouchEvent { ev_type: TouchEventType::Up, x: px, y: py })) => {
114
114
-
x = px;
115
115
-
y = py;
116
116
-
ScEventType::TouchUp
117
117
-
},
118
118
-
Some(Event::Touch(TouchEvent { ev_type: TouchEventType::Move, x: px, y: py })) => {
119
119
-
x = px;
120
120
-
y = py;
121
121
-
ScEventType::TouchMove
122
122
-
},
123
123
-
Some(Event::RefreshFinished) => ScEventType::RefreshFinished,
124
124
-
};
125
125
-
stack_values[0] = sc_ev_type as usize;
126
126
-
stack_values[1] = x as usize;
127
127
-
stack_values[2] = y as usize;
128
128
-
}
113
113
+
fn handle_next_event(stack_values: &mut [usize]) {
114
114
+
let next_event = critical_section::with(|cs| EVENT_QUEUE.borrow_ref_mut(cs).pop());
115
115
+
let mut x = 0;
116
116
+
let mut y = 0;
117
117
+
let sc_ev_type = match next_event {
118
118
+
None => ScEventType::NoEvent,
119
119
+
Some(Event::Touch(TouchEvent { ev_type: TouchEventType::Down, x: px, y: py })) => {
120
120
+
x = px;
121
121
+
y = py;
122
122
+
ScEventType::TouchDown
123
123
+
},
124
124
+
Some(Event::Touch(TouchEvent { ev_type: TouchEventType::Up, x: px, y: py })) => {
125
125
+
x = px;
126
126
+
y = py;
127
127
+
ScEventType::TouchUp
128
128
+
},
129
129
+
Some(Event::Touch(TouchEvent { ev_type: TouchEventType::Move, x: px, y: py })) => {
130
130
+
x = px;
131
131
+
y = py;
132
132
+
ScEventType::TouchMove
133
133
+
},
134
134
+
Some(Event::RefreshFinished) => ScEventType::RefreshFinished,
135
135
+
};
136
136
+
stack_values[0] = sc_ev_type as usize;
137
137
+
stack_values[1] = x as usize;
138
138
+
stack_values[2] = y as usize;
139
139
+
}
129
140
130
130
-
fn handle_set_touch_enabled(stack_values: &mut [usize]) {
131
131
-
let enable = stack_values[1] != 0;
132
132
-
TOUCH_ENABLED.store(enable, Ordering::Relaxed);
133
133
-
if !enable {
134
134
-
critical_section::with(|cs| EVENT_QUEUE.borrow_ref_mut(cs).clear());
141
141
+
fn handle_set_touch_enabled(stack_values: &mut [usize]) {
142
142
+
let enable = stack_values[1] != 0;
143
143
+
TOUCH_ENABLED.store(enable, Ordering::Relaxed);
144
144
+
if !enable {
145
145
+
critical_section::with(|cs| EVENT_QUEUE.borrow_ref_mut(cs).clear());
146
146
+
}
135
147
}
136
136
-
}
137
148
138
138
-
fn handle_has_event(stack_values: &mut [usize]) {
139
139
-
let empty = critical_section::with(|cs| EVENT_QUEUE.borrow_ref(cs).is_empty());
140
140
-
stack_values[0] = (!empty) as usize;
149
149
+
fn handle_has_event(stack_values: &mut [usize]) {
150
150
+
let empty = critical_section::with(|cs| EVENT_QUEUE.borrow_ref(cs).is_empty());
151
151
+
stack_values[0] = (!empty) as usize;
152
152
+
}
141
153
}