Skip to content

Commit 17227f7

Browse files
uefi: Use uefi_raw's SimplePointerProtocol to implement Pointer
1 parent b867467 commit 17227f7

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Changed
66
- `Input::wait_for_key_event` now returns an `Option<Event>`, and is no longer `const`.
7-
- `Protocol::wait_for_input_event` now returns an `Option<Event>`.
7+
- `Protocol::wait_for_input_event` now returns an `Option<Event>`, and is no longer `const`.
88
- `LoadedImage::device` now returns an `Option<Handle>` and is no longer `const`.
99
- `BootServices::get_image_file_system` now returns
1010
`ScopedProtocol<SimpleFileSystem>` instead of `fs::FileSystem`.

uefi/src/proto/console/pointer/mod.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
33
use crate::proto::unsafe_protocol;
44
use crate::{Event, Result, Status, StatusExt};
5+
use uefi_raw::protocol::console::SimplePointerProtocol;
56

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

1612
impl Pointer {
1713
/// Resets the pointer device hardware.
@@ -23,7 +19,7 @@ impl Pointer {
2319
///
2420
/// - `DeviceError` if the device is malfunctioning and cannot be reset.
2521
pub fn reset(&mut self, extended_verification: bool) -> Result {
26-
unsafe { (self.reset)(self, extended_verification) }.to_result()
22+
unsafe { (self.0.reset)(&mut self.0, extended_verification) }.to_result()
2723
}
2824

2925
/// Retrieves the pointer device's current state, if a state change occurred
@@ -36,8 +32,9 @@ impl Pointer {
3632
/// - `DeviceError` if there was an issue with the pointer device.
3733
pub fn read_state(&mut self) -> Result<Option<PointerState>> {
3834
let mut pointer_state = PointerState::default();
35+
let pointer_state_ptr: *mut _ = &mut pointer_state;
3936

40-
match unsafe { (self.get_state)(self, &mut pointer_state) } {
37+
match unsafe { (self.0.get_state)(&mut self.0, pointer_state_ptr.cast()) } {
4138
Status::NOT_READY => Ok(None),
4239
other => other.to_result_with_val(|| Some(pointer_state)),
4340
}
@@ -46,14 +43,14 @@ impl Pointer {
4643
/// Event to be used with `BootServices::wait_for_event()` in order to wait
4744
/// for input from the pointer device
4845
#[must_use]
49-
pub const fn wait_for_input_event(&self) -> &Option<Event> {
50-
&self.wait_for_input
46+
pub fn wait_for_input_event(&self) -> Option<Event> {
47+
unsafe { Event::from_ptr(self.0.wait_for_input) }
5148
}
5249

5350
/// Returns a reference to the pointer device information.
5451
#[must_use]
5552
pub const fn mode(&self) -> &PointerMode {
56-
unsafe { &*self.mode }
53+
unsafe { &*self.0.mode.cast() }
5754
}
5855
}
5956

0 commit comments

Comments
 (0)