Class Keyboard_Controller
Placement in the overall structure
- Module
- machine
- Base classes
- None
- Derived classes
- Keyboard
- Time of creation
- Task 1
- Modified in
- Task 2
- Files
keyctrl.h keyctrl.cc
Description
The Keyboard_Controller class is used to initialize the PC keyboard and determine the scan and ASCII code of the pressed key from the make and break codes sent.
Public methods
Keyboard_Controller ()
- Keyboard initialization: disables all LEDs and sets the repeat rate to maximum.
Key key_hit ()
- Fetches the code of the last key press from the keyboard controller.
If a meaningful interpretation is possible, the scan code,
the "modifier" keys (Shift, Ctrl, Alt, Capslock, etc.) that may
have been pressed at the same time, and the ASCII code of the key
are returned as an object of the class
Key
. If only one of the special keys Shift, Alt, CapsLock, etc. was pressed, the method returns an invalidKey
object. Whether the result is valid or not can be checked with the methodKey::valid()
. void reboot ()
- Reboots the PC. Yes, in a PC the keyboard controller is responsible for this.
set_repeat_rate (int speed, int delay)
- Method for setting the keyboard repeat rate. The delay parameter determines how long a key has to be pressed until automatic repetition starts. Accepted values are between 0 (minimal waiting time) and 3 (maximal waiting time). The parameter speed determines how fast the key codes should come in during the repetition phase. Allowed values are between 0 (very fast) and 31 (very slow).
void set_led (char led, bool on)
- This method can be used to turn on or off one of the three keyboard LEDs
led::caps_lock
,led::num_lock
orled::scroll_lock
.
Notes
- In the context of task 2 the implementation of Keyboard_Controller should be modified for the use of interrupts. In particular, the selective interrupt disable in set_led and set_repeat_rate should be considered - otherwise very non-intuitive bugs can occur here.