Aufgabe 6: Synchronisation
PS/2 Controller. More...
Functions | |
void | init () |
Initialization of connected devices. More... | |
bool | fetch (Key &pressed) |
Retrieve the keyboard event. More... | |
bool | fetch (Pointer &state) |
Retrieve the mouse event. More... | |
void | setRepeatRate (Speed speed, Delay delay) |
Configure the repeat rate of the keyboard. More... | |
void | setLed (enum LED led, bool on) |
Enable or disable a keyboard LED. More... | |
void | drainBuffer () |
Empties the keyboard buffer. More... | |
Detailed Description
PS/2 Controller.
Initializes the PS/2 devices (Keyboard and optional Mouse), and determines both the scan code and ASCII character of a pressed key from the transmitted make and break codes using the KeyDecoder.
- Note
- This controller is also known as Intel 8042 (nowadays integrated in the mainboard) or Keyboard Controller. But to avoid confusion with the actual Keyboard and since we use the PS/2-compatible mode to support the Mouse as well, the name PS/2 Controller was chosen for the sake of simplicity.
- Since modern PCs sometimes don't have an PS/2 connector, USB keyboards and mice are emulated as PS/2 device with USB Legacy Support.
Enumeration Type Documentation
Flags in the PS/2 controller status register.
enum PS2Controller::KeyboardCommand : uint8_t |
Commands to be send to the Keyboard.
enum PS2Controller::Reply |
Commands for the PS/2 Controller.
These commands are processed by the controller and not send to keyboard/mouse. They have to be written into the command register.
Commands to be send to the mouse.
- See also
- ps2mouse
enum PS2Controller::Delay |
enum PS2Controller::Speed |
Repeat Rate of Characters.
- See also
- The PS/2 Keyboard Interface
enum PS2Controller::LED |
Function Documentation
void PS2Controller::init | ( | ) |
Initialization of connected devices.
All status LEDs of the keyboard are switched off and the repetition rate is set to maximum speed.
bool PS2Controller::fetch | ( | Key & | pressed | ) |
Retrieve the keyboard event.
Retrieves make and brake events from the keyboard. If a valid (non special) key was pressed, the scan code is determined using KeyDecoder::decode into a Key object. Events on special keys like Shift, Alt, CapsLock etc. are stored (in KeyDecoder) and applied on subsequent keystrokes, while no valid key is retrieved.
Mouse events are ignored.
- Parameters
-
pressed Reference to an object which will contain the pressed Key on success
- Returns
true
if a valid key was decoded
bool PS2Controller::fetch | ( | Pointer & | state | ) |
Retrieve the mouse event.
If a full mouse state was retrieved (all 3 packets have been successfully processed by the MouseDecoder) the new state is retrieved. Keyboard events are not processed.
- Note
- fetch(Key&) has to be adjusted to not process (instead of ignore) mouse packets, or events might be lost.
- Parameters
-
state Reference to an object which will contain the Mouse Pointer state on success
- Returns
true
if a valid mouse pointer state was decoded
Configure the repeat rate of the keyboard.
- Parameters
-
delay configures how long a key must be pressed before the repetition begins. speed determines how fast the key codes should follow each other. Valid values are between 0
(30 characters per second) and31
(2 characters per second).
void PS2Controller::setLed | ( | enum LED | led, |
bool | on | ||
) |
Enable or disable a keyboard LED.
- Parameters
-
led LED to enable or disable on true
will enable the specified LED,false
disable
void PS2Controller::drainBuffer | ( | ) |
Empties the keyboard buffer.
The keyboard may not send any interrupts if the buffer is not empty. To prevent unhandled keystrokes (for example during boot) the buffer should be emptied once right before allowing keyboard interrupts (even if keystrokes might be lost).