Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uefi: Use uefi_raw's SimplePointerProtocol to implement Pointer #889

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

### Changed
- `Input::wait_for_key_event` now returns an `Option<Event>`, and is no longer `const`.
- `Protocol::wait_for_input_event` now returns an `Option<Event>`, and is no longer `const`.
- `LoadedImage::device` now returns an `Option<Handle>` and is no longer `const`.
- `BootServices::get_image_file_system` now returns
`ScopedProtocol<SimpleFileSystem>` instead of `fs::FileSystem`.
Expand Down
32 changes: 14 additions & 18 deletions uefi/src/proto/console/pointer/mod.rs
Expand Up @@ -2,17 +2,12 @@

use crate::proto::unsafe_protocol;
use crate::{Event, Result, Status, StatusExt};
use core::mem::MaybeUninit;
use uefi_raw::protocol::console::SimplePointerProtocol;

/// Provides information about a pointer device.
#[repr(C)]
#[unsafe_protocol("31878c87-0b75-11d5-9a4f-0090273fc14d")]
pub struct Pointer {
reset: extern "efiapi" fn(this: &mut Pointer, ext_verif: bool) -> Status,
get_state: extern "efiapi" fn(this: &Pointer, state: *mut PointerState) -> Status,
wait_for_input: Event,
mode: *const PointerMode,
}
#[repr(transparent)]
#[unsafe_protocol(SimplePointerProtocol::GUID)]
pub struct Pointer(SimplePointerProtocol);

impl Pointer {
/// Resets the pointer device hardware.
Expand All @@ -24,7 +19,7 @@ impl Pointer {
///
/// - `DeviceError` if the device is malfunctioning and cannot be reset.
pub fn reset(&mut self, extended_verification: bool) -> Result {
(self.reset)(self, extended_verification).to_result()
unsafe { (self.0.reset)(&mut self.0, extended_verification) }.to_result()
}

/// Retrieves the pointer device's current state, if a state change occurred
Expand All @@ -36,30 +31,31 @@ impl Pointer {
/// # Errors
/// - `DeviceError` if there was an issue with the pointer device.
pub fn read_state(&mut self) -> Result<Option<PointerState>> {
let mut pointer_state = MaybeUninit::<PointerState>::uninit();
let mut pointer_state = PointerState::default();
let pointer_state_ptr: *mut _ = &mut pointer_state;

match (self.get_state)(self, pointer_state.as_mut_ptr()) {
match unsafe { (self.0.get_state)(&mut self.0, pointer_state_ptr.cast()) } {
Status::NOT_READY => Ok(None),
other => other.to_result_with_val(|| unsafe { Some(pointer_state.assume_init()) }),
other => other.to_result_with_val(|| Some(pointer_state)),
}
}

/// Event to be used with `BootServices::wait_for_event()` in order to wait
/// for input from the pointer device
#[must_use]
pub const fn wait_for_input_event(&self) -> &Event {
&self.wait_for_input
pub fn wait_for_input_event(&self) -> Option<Event> {
unsafe { Event::from_ptr(self.0.wait_for_input) }
}

/// Returns a reference to the pointer device information.
#[must_use]
pub const fn mode(&self) -> &PointerMode {
unsafe { &*self.mode }
unsafe { &*self.0.mode.cast() }
}
}

/// Information about this pointer device.
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
#[repr(C)]
pub struct PointerMode {
/// The pointer device's resolution on the X/Y/Z axis in counts/mm.
Expand All @@ -70,7 +66,7 @@ pub struct PointerMode {
}

/// The relative change in the pointer's state.
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
#[repr(C)]
pub struct PointerState {
/// The relative movement on the X/Y/Z axis.
Expand Down