pub struct Controller { /* private fields */ }
Expand description
The PS/2 controller.
Provides the functionality of an Intel 8042 chip. Many computers nowadays don’t have PS/2 connectors, but emulate the mouse and keyboard as PS/2 devices through USB. The implementation of this emulation is usually different from manufacturer to manufacturer and cannot always be relied upon to perform correctly. Therefore, if you’re writing an operating system, you should disable this legacy support once the USB controller has been initialized.
Implementations§
Source§impl Controller
impl Controller
Sourcepub const unsafe fn new() -> Self
pub const unsafe fn new() -> Self
Create a handle to the PS/2 controller. Uses a default IO timeout of 10,000 tries.
§Safety
Ensure that IO ports 0x60
and 0x64
are not accessed by any other code, and that only
one Controller
accesses those ports at any point in time.
Sourcepub const unsafe fn with_timeout(timeout: usize) -> Self
pub const unsafe fn with_timeout(timeout: usize) -> Self
Like new
, but allows specifying an IO timeout, which is the number of times an IO
operation will be attempted before returning ControllerError::Timeout
.
Sourcepub fn read_status(&mut self) -> ControllerStatusFlags
pub fn read_status(&mut self) -> ControllerStatusFlags
Read the status register of the controller.
Sourcepub fn read_data(&mut self) -> Result<u8, ControllerError>
pub fn read_data(&mut self) -> Result<u8, ControllerError>
Read a byte from the data buffer once it is full.
If there is no data available to read within the configured timeout, this will return
ControllerError::Timeout
.
Sourcepub fn write_data(&mut self, data: u8) -> Result<(), ControllerError>
pub fn write_data(&mut self, data: u8) -> Result<(), ControllerError>
Write a byte to the data buffer once it is empty.
If a write cannot be performed within the configured timeout, this will return
ControllerError::Timeout
.
Sourcepub fn read_internal_ram(
&mut self,
byte_number: u8,
) -> Result<u8, ControllerError>
pub fn read_internal_ram( &mut self, byte_number: u8, ) -> Result<u8, ControllerError>
Read a byte from the controller’s internal RAM.
The desired byte index must be between 0 and 31. Byte 0 is also known as the configuration byte or command byte.
Sourcepub fn write_internal_ram(
&mut self,
byte_number: u8,
data: u8,
) -> Result<(), ControllerError>
pub fn write_internal_ram( &mut self, byte_number: u8, data: u8, ) -> Result<(), ControllerError>
Write a byte to the controller’s internal RAM.
The desired byte index must be between 0 and 31. Byte 0 is also known as the configuration byte or command byte.
Sourcepub fn read_config(&mut self) -> Result<ControllerConfigFlags, ControllerError>
pub fn read_config(&mut self) -> Result<ControllerConfigFlags, ControllerError>
Read the configuration byte (or command byte) of the controller. This is the same as reading byte 0 of the internal RAM.
Sourcepub fn write_config(
&mut self,
config: ControllerConfigFlags,
) -> Result<(), ControllerError>
pub fn write_config( &mut self, config: ControllerConfigFlags, ) -> Result<(), ControllerError>
Write the configuration byte (or command byte) of the controller. This is the same as writing to byte 0 of the internal RAM.
Sourcepub fn disable_mouse(&mut self) -> Result<(), ControllerError>
pub fn disable_mouse(&mut self) -> Result<(), ControllerError>
Disable the mouse. Sets the ControllerConfigFlags::DISABLE_MOUSE
flag.
Sourcepub fn enable_mouse(&mut self) -> Result<(), ControllerError>
pub fn enable_mouse(&mut self) -> Result<(), ControllerError>
Enable the mouse. Clears the ControllerConfigFlags::DISABLE_MOUSE
flag.
Sourcepub fn test_mouse(&mut self) -> Result<(), ControllerError>
pub fn test_mouse(&mut self) -> Result<(), ControllerError>
Perform a self-test on the mouse.
Returns ControllerError::TestFailed
if the test fails.
Sourcepub fn test_controller(&mut self) -> Result<(), ControllerError>
pub fn test_controller(&mut self) -> Result<(), ControllerError>
Perform a self-test on the controller.
Returns ControllerError::TestFailed
if the test fails.
Sourcepub fn test_keyboard(&mut self) -> Result<(), ControllerError>
pub fn test_keyboard(&mut self) -> Result<(), ControllerError>
Perform a self-test on the keyboard.
Returns ControllerError::TestFailed
if the test fails.
Sourcepub fn diagnostic_dump(&mut self) -> Result<[u8; 32], ControllerError>
pub fn diagnostic_dump(&mut self) -> Result<[u8; 32], ControllerError>
Dump all bytes of the controller’s internal RAM.
Sourcepub fn disable_keyboard(&mut self) -> Result<(), ControllerError>
pub fn disable_keyboard(&mut self) -> Result<(), ControllerError>
Disable the keyboard.
Sets the ControllerConfigFlags::DISABLE_KEYBOARD
flag.
Sourcepub fn enable_keyboard(&mut self) -> Result<(), ControllerError>
pub fn enable_keyboard(&mut self) -> Result<(), ControllerError>
Enable the keyboard.
Clears the ControllerConfigFlags::DISABLE_KEYBOARD
flag.
Sourcepub fn read_input_port(&mut self) -> Result<InputPortFlags, ControllerError>
pub fn read_input_port(&mut self) -> Result<InputPortFlags, ControllerError>
Read the state of the controller’s input port.
Sourcepub fn write_input_low_nibble_to_status(
&mut self,
) -> Result<(), ControllerError>
pub fn write_input_low_nibble_to_status( &mut self, ) -> Result<(), ControllerError>
Write the low nibble of the controller’s input port to the low nibble of the controller status register.
Sourcepub fn write_input_high_nibble_to_status(
&mut self,
) -> Result<(), ControllerError>
pub fn write_input_high_nibble_to_status( &mut self, ) -> Result<(), ControllerError>
Write the high nibble of the controller’s input port to the high nibble of the controller status register.
Sourcepub fn read_output_port(&mut self) -> Result<OutputPortFlags, ControllerError>
pub fn read_output_port(&mut self) -> Result<OutputPortFlags, ControllerError>
Read the state of the controller’s output port.
Sourcepub fn write_output_port(
&mut self,
output: OutputPortFlags,
) -> Result<(), ControllerError>
pub fn write_output_port( &mut self, output: OutputPortFlags, ) -> Result<(), ControllerError>
Write the state of the controller’s output port.
Sourcepub fn write_keyboard_buffer(&mut self, data: u8) -> Result<(), ControllerError>
pub fn write_keyboard_buffer(&mut self, data: u8) -> Result<(), ControllerError>
Write a byte to the data buffer as if it were received from the keyboard.
This will trigger an interrupt if interrupts are enabled.
Sourcepub fn write_mouse_buffer(&mut self, data: u8) -> Result<(), ControllerError>
pub fn write_mouse_buffer(&mut self, data: u8) -> Result<(), ControllerError>
Write a byte to the data buffer as if it were received from the mouse.
This will trigger an interrupt if interrupts are enabled.
Sourcepub fn write_mouse(&mut self, data: u8) -> Result<(), ControllerError>
pub fn write_mouse(&mut self, data: u8) -> Result<(), ControllerError>
Write a byte to the mouse’s data buffer.
Sourcepub fn read_test_port(&mut self) -> Result<TestPortFlags, ControllerError>
pub fn read_test_port(&mut self) -> Result<TestPortFlags, ControllerError>
Read the state of the controller’s test port.
Sourcepub fn pulse_output_low_nibble(
&mut self,
data: u8,
) -> Result<(), ControllerError>
pub fn pulse_output_low_nibble( &mut self, data: u8, ) -> Result<(), ControllerError>
Pulse the low nibble of the given byte onto the lower nibble of the controller output port.