Skip to content

Commit 74590fe

Browse files
committed
Add support for Simple Pointer
This protocol allows UEFI applications to access pointing devices like mice.
1 parent 07ebc52 commit 74590fe

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

src/proto/console/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
//! used by the user to interact with the early boot platform.
55
66
pub mod text;
7+
pub mod pointer;

src/proto/console/pointer/mod.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//! Pointer device access.
2+
3+
use {Status, Result};
4+
use core::mem;
5+
6+
/// Provides information about a pointer device.
7+
pub struct Pointer {
8+
reset: extern "C" fn(this: &mut Pointer, ext_verif: bool) -> Status,
9+
get_state: extern "C" fn(this: &Pointer, state: &mut PointerState) -> Status,
10+
wait_for_input: usize,
11+
mode: &'static PointerMode,
12+
}
13+
14+
impl Pointer {
15+
/// Resets the pointer device hardware.
16+
///
17+
/// The `extended_verification` parameter is used to request that UEFI
18+
/// performs an extended check and reset of the input device.
19+
///
20+
/// # Errors
21+
///
22+
/// - `DeviceError` if the device is malfunctioning and cannot be reset.
23+
pub fn reset(&mut self, extended_verification: bool) -> Result<()> {
24+
(self.reset)(self, extended_verification).into()
25+
}
26+
27+
/// Retrieves the pointer device's current state.
28+
///
29+
/// # Errors
30+
/// - `NotReady` is returned if the state hasn't changed since the last call.
31+
/// - `DeviceError` if there was an issue with the pointer device.
32+
pub fn state(&self) -> Result<PointerState> {
33+
let mut pointer_state = unsafe { mem::uninitialized() };
34+
35+
(self.get_state)(self, &mut pointer_state).into_with(|| pointer_state)
36+
}
37+
38+
/// Returns a reference to the pointer device information.
39+
pub fn mode(&self) -> &PointerMode {
40+
self.mode
41+
}
42+
}
43+
44+
impl_proto! {
45+
protocol Pointer {
46+
GUID = 0x31878c87, 0xb75, 0x11d5, [0x9a, 0x4f, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d];
47+
}
48+
}
49+
50+
/// Information about this pointer device.
51+
#[derive(Debug, Copy, Clone)]
52+
#[repr(C)]
53+
pub struct PointerMode {
54+
// The pointer device's resolution on the X/Y/Z axis in counts/mm.
55+
// If a value is 0, then the device does _not_ support that axis.
56+
resolution: (u64, u64, u64),
57+
/// Whether the devices has a left button / right button.
58+
has_button: (bool, bool),
59+
}
60+
61+
/// The relative change in the pointer's state.
62+
#[derive(Debug, Copy, Clone)]
63+
#[repr(C)]
64+
pub struct PointerState {
65+
/// The relative movement on the X/Y/Z axis.
66+
///
67+
/// If `PointerMode` indicates an axis is not supported, it must be ignored.
68+
pub relative_movement: (i32, i32, i32),
69+
/// Whether the left / right mouse button is currently pressed.
70+
///
71+
/// If `PointerMode` indicates a button is not supported, it must be ignored.
72+
pub button: (bool, bool),
73+
}

0 commit comments

Comments
 (0)