Skip to main content

KeyboardController

Struct KeyboardController 

Source
pub struct KeyboardController {
    output: [u8; 8],
    output_len: u8,
    input: [u8; 32],
    input_len: u8,
    last_command: u8,
    data_reads: u32,
    reply_reads: u32,
    scancode_reads: u32,
    output_port_write: bool,
    controller_data: bool,
}
Expand description

Minimal 8042 state with a small controller-to-host output queue.

Fields§

§output: [u8; 8]

Bytes waiting for the host on the data port (controller replies).

§output_len: u8

Number of valid bytes in output (at the front).

§input: [u8; 32]

Scancodes typed by the host and not read by the guest yet.

§input_len: u8

Number of valid scancodes in input (at the front).

§last_command: u8

Last command written to port 0x64.

§data_reads: u32

Number of data-port reads the guest performed (diagnostics only).

A guest that queues scancodes but never reads 0x60 is the difference between “the interrupt never arrived” and “the handler read the port”.

§reply_reads: u32

Reads of 0x60 answered from the controller reply queue (diagnostics).

§scancode_reads: u32

Reads of 0x60 answered from the host scancode queue (diagnostics).

§output_port_write: bool

Next data-port write goes to the controller output port, not the keyboard (set by command 0xD1).

§controller_data: bool

Next data-port write is a controller parameter (config/aux), not a keyboard command, so it must not produce a keyboard ACK.

Implementations§

Source§

impl KeyboardController

Source

pub const fn new() -> Self

Creates an idle controller.

Source

pub fn push_scancode(&mut self, code: u8) -> bool

Queues one set-1 scancode as if the PS/2 keyboard sent it.

Returns false when the queue is full: the caller keeps the remaining bytes and retries after the guest has read some.

Source

pub const fn has_scancode(&self) -> bool

True while the guest has not read every queued scancode.

Source

pub const fn pending_scancodes(&self) -> u8

Number of scancodes waiting to be read by the guest.

Source

pub fn read(&mut self, port: u16) -> Option<u8>

Reads one port.

Source

pub fn write(&mut self, port: u16, value: u8)

Writes one port.

Source

pub const fn data_reads(&self) -> u32

Number of data-port reads observed so far (diagnostics only).

Source

pub const fn reply_reads(&self) -> u32

Reads of 0x60 answered from the controller reply queue.

Source

pub const fn scancode_reads(&self) -> u32

Reads of 0x60 answered from the host scancode queue.

Source

pub const fn last_command(&self) -> u8

Last command written to the status port (diagnostics).

Source

pub fn status(&self) -> u8

Current status byte.

Source

fn write_data(&mut self, value: u8)

Handles a data-port write (keyboard command or parameter).

Source

fn write_command(&mut self, value: u8)

Handles a status-port write (controller command).

Source

fn push(&mut self, value: u8)

Appends one byte to the output queue when there is room.

Source

fn pop_front(&mut self)

Drops the front byte of the output queue.

Source

fn pop_input_front(&mut self)

Drops the front scancode of the input queue.

Trait Implementations§

Source§

impl Clone for KeyboardController

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for KeyboardController

Source§

impl Debug for KeyboardController

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for KeyboardController

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for KeyboardController

Source§

impl PartialEq for KeyboardController

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for KeyboardController

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.