Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Pc_keyboard Class Reference

An implementation of the Keyboard class, representing a PS/2 or AT keyboard using the motherboard's keyboard controller. More...

#include <keyboard.h>

Inherits Keyboard.

Inheritance diagram for Pc_keyboard:

Inheritance graph
[legend]
Collaboration diagram for Pc_keyboard:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void init ()
void deinit ()
Key_event get_key ()
Key_event try_get_key ()
Key_event get_keypress ()
Key_event try_get_keypress ()
bool handle_interrupt ()

Protected Types

enum  Register { REGISTER_DATA = 0x60, REGISTER_STATUS = 0x64 }
enum  Status {
  STATUS_OUTPUT_BUFFER_FULL = (1 << 0), STATUS_INPUT_BUFFER_FULL = (1 << 1), STATUS_SYSTEM_FLAG = (1 << 2), STATUS_IS_COMMAND = (1 << 3),
  STATUS_KEYBOARD_ENABLED = (1 << 4), STATUS_AUX_PENDING = (1 << 5), STATUS_COMMAND_TIMEOUT = (1 << 6), STATUS_PARITY_ERROR = (1 << 7)
}
enum  Response {
  RESPONSE_TOO_MANY_KEY_PRESSES = 0x00, RESPONSE_SELF_TEST_SUCCEEDED = 0x55, RESPONSE_BASIC_ASSURANCE_TEST_SUCCEEDED = 0xAA, RESPONSE_COMMAND_ECHO = 0xEE,
  RESPONSE_COMMAND_ACKNOWLEDGE = 0xFA, RESPONSE_BASIC_ASSURANCE_TEST_FAILED = 0xFC, RESPONSE_RESEND_REQUEST = 0xFE, RESPONSE_KEYBOARD_ERROR = 0xFF
}
enum  Command {
  COMMAND_SET_LEDS = 0xED, COMMAND_ECHO = 0xEE, COMMAND_SELECT_SCANCODE_SET = 0xF0, COMMAND_IDENTIFY_KEYBOARD = 0xF2,
  COMMAND_TYPEMATIC_RATE = 0xF3, COMMAND_ENABLE_KEYBOARD = 0xF4, COMMAND_DISABLE_SCANNING = 0xF5, COMMAND_ENABLE_SCANNING = 0xF6,
  COMMAND_INTERNAL_DIAGNOSTICS = 0xFF, COMMAND_READ_COMMAND_BYTE = 0x20, COMMAND_WRITE_COMMAND_BYTE = 0x60, COMMAND_ENABLE_AUX_INTERFACE = 0xA7,
  COMMAND_DISABLE_AUX_INTERFACE = 0xA8, COMMAND_TEST_AUX_INTERFACE = 0xA9, COMMAND_SELF_TEST = 0xAA, COMMAND_TEST_KEYBOARD_INTERFACE = 0xAB,
  COMMAND_DEACTIVATE_KEYBOARD = 0xAD, COMMAND_ACTIVATE_KEYBOARD = 0xAE, COMMAND_WRITE_AUX_INTERFACE = 0xD4
}
enum  Command_byte {
  COMMAND_BYTE_ENABLE_KEYBOARD_INTERRUPT = (1 << 0), COMMAND_BYTE_ENABLE_AUX_INTERRUPT = (1 << 1), COMMAND_BYTE_SYSTEM_RESERVED_FLAG = (1 << 2), COMMAND_BYTE_IGNORE_KEY_LOCK = (1 << 3),
  COMMAND_BYTE_KEYBOARD_DISABLED = (1 << 4), COMMAND_BYTE_AUX_DISABLED = (1 << 5), COMMAND_BYTE_XT_SCANCODES = (1 << 6)
}
enum  Led { LED_NONE = 0, LED_SCROLL_LOCK = (1 << 0), LED_NUM_LOCK = (1 << 1), LED_CAPS_LOCK = (1 << 2) }
enum  Rate { RATE_MINIMUM = 0, RATE_MEDIUM = 15, RATE_MAXIMUM = 31 }
enum  Delay { DELAY_250 = 0, DELAY_500 = 1, DELAY_750 = 2, DELAY_1000 = 3 }
enum  Scancode_set { SCANCODE_SET_1 = 1, SCANCODE_SET_2 = 2, SCANCODE_SET_3 = 3 }

Protected Member Functions

void wait_for_write ()
Status read_status ()
Uint8 read_data ()
void write_data (Uint8 data)
void send_data (Uint8 data)
Key_event grab_key ()

Protected Attributes

Int_handler handler
Semaphore key_grab_lock
Key_event key_buffer [key_buffer_size]
unsigned buffer_append_pos
unsigned buffer_grab_pos
bool during_extended
bool shift_pressed
bool alt_pressed
bool ctrl_pressed
bool win_pressed
bool menu_pressed

Static Protected Attributes

const unsigned key_buffer_size = 100
const int RELEASE_CODE = 0x80
const int EXTENDED_SCANCODE = 0xe0

Detailed Description

An implementation of the Keyboard class, representing a PS/2 or AT keyboard using the motherboard's keyboard controller.


Member Enumeration Documentation

enum Pc_keyboard::Command [protected]
 

Types of commands that can be sent to REGISTER_DATA.

Some commands are followed by another byte signifying a particular setting, e.g. COMMAND_SET_LEDS is follow by a byte indicating the LED state to set.

Enumeration values:
COMMAND_SET_LEDS 
COMMAND_ECHO 
COMMAND_SELECT_SCANCODE_SET 
COMMAND_IDENTIFY_KEYBOARD 
COMMAND_TYPEMATIC_RATE 
COMMAND_ENABLE_KEYBOARD 
COMMAND_DISABLE_SCANNING 
COMMAND_ENABLE_SCANNING 
COMMAND_INTERNAL_DIAGNOSTICS 
COMMAND_READ_COMMAND_BYTE 
COMMAND_WRITE_COMMAND_BYTE 
COMMAND_ENABLE_AUX_INTERFACE 
COMMAND_DISABLE_AUX_INTERFACE 
COMMAND_TEST_AUX_INTERFACE 
COMMAND_SELF_TEST 
COMMAND_TEST_KEYBOARD_INTERFACE 
COMMAND_DEACTIVATE_KEYBOARD 
COMMAND_ACTIVATE_KEYBOARD 
COMMAND_WRITE_AUX_INTERFACE 

enum Pc_keyboard::Command_byte [protected]
 

Flags that are sent in a byte to REGISTER_DATA immediately after sending COMMAND_WRITE_COMMAND_BYTE to REGISTER_DATA.

Very poorly named.

Enumeration values:
COMMAND_BYTE_ENABLE_KEYBOARD_INTERRUPT 
COMMAND_BYTE_ENABLE_AUX_INTERRUPT 
COMMAND_BYTE_SYSTEM_RESERVED_FLAG 
COMMAND_BYTE_IGNORE_KEY_LOCK 
COMMAND_BYTE_KEYBOARD_DISABLED 
COMMAND_BYTE_AUX_DISABLED 
COMMAND_BYTE_XT_SCANCODES 

enum Pc_keyboard::Delay [protected]
 

Flags that are sent in the same byte (after shifting left by 5) to REGISTER_DATA immediately after sending COMMAND_TYPEMATIC_RATE to REGISTER_DATA.

These indicate the keyboard typematic delay before repeating kicks in.

Enumeration values:
DELAY_250 
DELAY_500 
DELAY_750 
DELAY_1000 

enum Pc_keyboard::Led [protected]
 

Flags that are sent in a byte to REGISTER_DATA immediately after sending COMMAND_SET_LEDS to REGISTER_DATA.

These indicate various LED states.

Enumeration values:
LED_NONE 
LED_SCROLL_LOCK 
LED_NUM_LOCK 
LED_CAPS_LOCK 

enum Pc_keyboard::Rate [protected]
 

Flags that are sent in a byte to REGISTER_DATA immediately after sending COMMAND_TYPEMATIC_RATE to REGISTER_DATA.

These indicate the keyboard typematic repeat rate when a key is held down.

Enumeration values:
RATE_MINIMUM 
RATE_MEDIUM 
RATE_MAXIMUM 

enum Pc_keyboard::Register [protected]
 

Keyboard controller registers used for reading and writing.

Enumeration values:
REGISTER_DATA 
REGISTER_STATUS 

enum Pc_keyboard::Response [protected]
 

Types of responses that you can receive from REGISTER_DATA after sending a command to that register.

Enumeration values:
RESPONSE_TOO_MANY_KEY_PRESSES 
RESPONSE_SELF_TEST_SUCCEEDED 
RESPONSE_BASIC_ASSURANCE_TEST_SUCCEEDED 
RESPONSE_COMMAND_ECHO 
RESPONSE_COMMAND_ACKNOWLEDGE 
RESPONSE_BASIC_ASSURANCE_TEST_FAILED 
RESPONSE_RESEND_REQUEST 
RESPONSE_KEYBOARD_ERROR 

enum Pc_keyboard::Scancode_set [protected]
 

Flags that are sent in a byte to REGISTER_DATA immediately after sending COMMAND_SELECT_SCANCODE_SET to REGISTER_DATA.

These indicate which set of scancodes we want to receive from the keyboard when a key is pressed. Old keyboards only support scancode set 1, all modern keyboards support set 2, and only some keyboards support set 3.

Enumeration values:
SCANCODE_SET_1 
SCANCODE_SET_2 
SCANCODE_SET_3 

enum Pc_keyboard::Status [protected]
 

Represents various possible states of the keyboard as read from KEYBOARD_STATUS.

Enumeration values:
STATUS_OUTPUT_BUFFER_FULL 
STATUS_INPUT_BUFFER_FULL 
STATUS_SYSTEM_FLAG 
STATUS_IS_COMMAND 
STATUS_KEYBOARD_ENABLED 
STATUS_AUX_PENDING 
STATUS_COMMAND_TIMEOUT 
STATUS_PARITY_ERROR 


Member Function Documentation

void Pc_keyboard::deinit  )  [virtual]
 

Deinitialize this keyboard device and unregister its interrupt.

Implements Keyboard.

Key_event Pc_keyboard::get_key  )  [virtual]
 

Return a key event (press or release) from our keyboard buffer.

If no key event is currently available, then block until the next event.

Implements Keyboard.

Key_event Pc_keyboard::get_keypress  )  [virtual]
 

Return a keypress event from our keyboard buffer.

If no key event is currently available, then block until the next event.

Implements Keyboard.

Key_event Pc_keyboard::grab_key  )  [protected]
 

Grab the next key out of the buffer and return it.

Used by the public get_key() functions.

bool Pc_keyboard::handle_interrupt  )  [virtual]
 

Read incoming data from the keyboard and store it in our buffer.

Implements Keyboard.

void Pc_keyboard::init  )  [virtual]
 

Initialize this keyboard device and register it to start handling keyboard interrupts.

Implements Keyboard.

Uint8 Pc_keyboard::read_data  )  [inline, protected]
 

Read a byte of data from the keyboard and return it.

Status Pc_keyboard::read_status  )  [inline, protected]
 

Return the keyboard's current status.

void Pc_keyboard::send_data Uint8  data  )  [protected]
 

Send the given data to the keyboard controller, first waiting until it's safe to write it.

If necessary, retry the send.

Key_event Pc_keyboard::try_get_key  )  [virtual]
 

Return a key event (press or release) from our keyboard buffer.

If no key event is currently available, then immediately return an event with KEY_NONE.

Implements Keyboard.

Key_event Pc_keyboard::try_get_keypress  )  [virtual]
 

Return a keypress event from our keyboard buffer.

If no key event is currently available, then immediately return an event with KEY_NONE.

Implements Keyboard.

void Pc_keyboard::wait_for_write  )  [inline, protected]
 

Busy-wait until controller has finished eating through its input buffer.

void Pc_keyboard::write_data Uint8  data  )  [inline, protected]
 

Send the given data to the keyboard controller.


Member Data Documentation

bool Pc_keyboard::alt_pressed [protected]
 

whether alt is pressed now

unsigned Pc_keyboard::buffer_append_pos [protected]
 

where next key will be added

unsigned Pc_keyboard::buffer_grab_pos [protected]
 

where get_key() grabs from

bool Pc_keyboard::ctrl_pressed [protected]
 

whether ctrl is pressed now

bool Pc_keyboard::during_extended [protected]
 

now processing extended code

const int Pc_keyboard::EXTENDED_SCANCODE = 0xe0 [static, protected]
 

Int_handler Pc_keyboard::handler [protected]
 

keyboard interrupt handler

Key_event Pc_keyboard::key_buffer[key_buffer_size] [protected]
 

incoming key buffer

const unsigned Pc_keyboard::key_buffer_size = 100 [static, protected]
 

Semaphore Pc_keyboard::key_grab_lock [protected]
 

maximum keys held in buffer

bool Pc_keyboard::menu_pressed [protected]
 

whether menu is pressed now

const int Pc_keyboard::RELEASE_CODE = 0x80 [static, protected]
 

bool Pc_keyboard::shift_pressed [protected]
 

whether shift is pressed now

bool Pc_keyboard::win_pressed [protected]
 

whether win is pressed now


The documentation for this class was generated from the following files:

Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman