···6677extern crate panic_halt;
8899-use core::arch::asm;
109use core::mem::offset_of;
1110use core::sync::atomic::Ordering;
1211use usb_device::bus::UsbBusAllocator;
1312use eepy_gui::draw_target::EpdDrawTarget;
1413use eepy_gui::element::Gui;
1515-use eepy_sys::input::{has_event, next_event, set_touch_enabled};
1414+use eepy_sys::input::{eep, next_event, set_touch_enabled};
1615use eepy_sys::misc::get_serial;
1716use eepy_sys::usb::{self, UsbBus};
1817use usb_device::prelude::*;
···101100 } else if NEEDS_REFRESH.swap(false, Ordering::Relaxed) {
102101 gui.draw_init(&mut draw_target);
103102 draw_target.refresh(false);
104104- } else if !has_event() {
105105- // has_event() is a syscall. The SVCall exception is a WFE wakeup event, so we need two
106106- // WFEs so we don't immediately wake up.
107107- unsafe { asm!("wfe", "wfe") };
103103+ } else {
104104+ eep();
108105 }
109106 }
110107 }
+14
eepy-sys/src/input.rs
···11+use core::arch::asm;
12use core::mem::MaybeUninit;
23use crate::{syscall, SafeOption};
34use crate::input_common::Event;
···4748 }
48494950 has_event != 0
5151+}
5252+5353+/// If there are no events remaining in the event queue, allow the processor to enter a sleep state
5454+/// until there is a new event ready.
5555+#[inline(always)]
5656+pub fn eep() {
5757+ if !has_event() {
5858+ // SAFETY: "wfe" only (maybe) puts the processor to sleep temporarily and doesn't access any
5959+ // memory so this specific instruction is safe
6060+ // has_event() is a syscall. The SVCall exception is a WFE wakeup event, so we need two
6161+ // WFEs so we don't immediately wake up.
6262+ unsafe { asm!("wfe", "wfe"); }
6363+ }
5064}