The Pedigree Project 0.1
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
X86Keyboard Class Reference

#include <Keyboard.h>

+ Inheritance diagram for X86Keyboard:
+ Collaboration diagram for X86Keyboard:

Public Member Functions

 X86Keyboard (Ps2Controller *controller)
 
virtual void initialise ()
 Initialises the device.
 
virtual void setDebugState (bool enableDebugState)
 
virtual bool getDebugState ()
 
virtual char getChar ()
 
virtual char getCharNonBlock ()
 
virtual char getLedState ()
 
virtual void setLedState (char state)
 
void startReaderThread ()
 
void stopReaderThread ()
 

Private Types

enum  LedCommandState { LedIdle , LedCommandAck , LedDataAck }
 

Private Member Functions

void readerThread ()
 
void updateLedState (char state, bool toggle)
 
void handleLedResponse (uint8_t response)
 
char scancodeToAscii (uint8_t scancode)
 Converts a scancode into an ASCII character (for use in debug state)
 

Static Private Member Functions

static int readerThreadTrampoline (void *)
 

Private Attributes

Ps2Controllerm_pPs2Controller
 Parent PS/2 controller.
 
KeymapManager::EscapeState m_Escape
 The current escape state.
 
irq_id_t m_IrqId
 IRQ id.
 
char m_LedState
 Current LED state.
 
LedCommandState m_LedCommandState
 
uint8_t m_LedSent
 
size_t m_LedRetries
 
Mutex m_LedLock
 
OwnedThread m_ReaderThread
 The controller buffer may block this worker until teardown wakes it.
 

Additional Inherited Members

- Public Types inherited from Keyboard
enum  KeyFlags {
  Special = 1ULL << 63 , Ctrl = 1ULL << 62 , Shift = 1ULL << 61 , Alt = 1ULL << 60 ,
  AltGr = 1ULL << 59 , Special = 1ULL << 63 , Ctrl = 1ULL << 62 , Shift = 1ULL << 61 ,
  Alt = 1ULL << 60 , AltGr = 1ULL << 59
}
 
enum  KeyboardLeds {
  ScrollLock = 1 << 0 , NumLock = 1 << 1 , CapsLock = 1 << 2 , Led1 = 1 << 3 ,
  Led2 = 1 << 4 , Led3 = 1 << 5 , Led4 = 1 << 6 , Led5 = 1 << 7
}
 Bit numbers follow the same format as the PS/2 keyboard LED byte. More...
 
enum  KeyFlags {
  Special = 1ULL << 63 , Ctrl = 1ULL << 62 , Shift = 1ULL << 61 , Alt = 1ULL << 60 ,
  AltGr = 1ULL << 59 , Special = 1ULL << 63 , Ctrl = 1ULL << 62 , Shift = 1ULL << 61 ,
  Alt = 1ULL << 60 , AltGr = 1ULL << 59
}
 

Detailed Description

Keyboard device implementation

Definition at line 39 of file kernel/machine/mach_pc/Keyboard.h.

Member Enumeration Documentation

◆ LedCommandState

enum X86Keyboard::LedCommandState
private

Definition at line 81 of file kernel/machine/mach_pc/Keyboard.h.

Constructor & Destructor Documentation

◆ X86Keyboard()

X86Keyboard::X86Keyboard ( Ps2Controller controller)

Definition at line 48 of file mach_pc/Keyboard.cc.

◆ ~X86Keyboard()

X86Keyboard::~X86Keyboard ( )
virtual

Definition at line 59 of file mach_pc/Keyboard.cc.

Member Function Documentation

◆ getChar()

char X86Keyboard::getChar ( )
virtual

Retrieves a character from the keyboard. Blocking I/O. If DebugState is false this returns zero. If DebugState is true this returns the next character received, or zero if the character is non-ASCII.

Implements Keyboard.

Definition at line 73 of file mach_pc/Keyboard.cc.

References Ps2Controller::getDebugState(), m_pPs2Controller, Ps2Controller::readByte(), and scancodeToAscii().

◆ getCharNonBlock()

char X86Keyboard::getCharNonBlock ( )
virtual

Retrieves a character from the keyboard. Non blocking I/O. If DebugState is false this returns zero. If DebugState is true this returns the next character received, or zero if the character is non-ASCII.

Implements Keyboard.

Definition at line 84 of file mach_pc/Keyboard.cc.

References Ps2Controller::getDebugState(), m_pPs2Controller, and scancodeToAscii().

◆ getDebugState()

bool X86Keyboard::getDebugState ( )
virtual

Implements Keyboard.

Definition at line 105 of file mach_pc/Keyboard.cc.

◆ getLedState()

char X86Keyboard::getLedState ( )
virtual

Gets the current state of the LEDs on the keyboard. A single byte bitmap is returned with flags from KeyboardLeds identifying which LEDs are on or off.

Reimplemented from Keyboard.

Definition at line 143 of file mach_pc/Keyboard.cc.

References m_LedState.

◆ handleLedResponse()

void X86Keyboard::handleLedResponse ( uint8_t  response)
private

Definition at line 162 of file mach_pc/Keyboard.cc.

◆ initialise()

void X86Keyboard::initialise ( )
virtual

Initialises the device.

Todo:
do we need to switch into a specific scancode set?

Implements Keyboard.

Definition at line 63 of file mach_pc/Keyboard.cc.

References Hex, m_pPs2Controller, Ps2Controller::readFirstPort(), and Ps2Controller::writeFirstPort().

Referenced by Pc::initialise().

+ Here is the caller graph for this function:

◆ readerThread()

void X86Keyboard::readerThread ( )
private

Definition at line 217 of file mach_pc/Keyboard.cc.

◆ readerThreadTrampoline()

int X86Keyboard::readerThreadTrampoline ( void *  param)
staticprivate

Definition at line 211 of file mach_pc/Keyboard.cc.

◆ scancodeToAscii()

char X86Keyboard::scancodeToAscii ( uint8_t  scancode)
private

Converts a scancode into an ASCII character (for use in debug state)

Definition at line 109 of file mach_pc/Keyboard.cc.

References KeymapManager::convertPc102ScancodeToHidKeycode(), KeymapManager::instance(), m_Escape, and KeymapManager::resolveHidKeycode().

Referenced by getChar(), and getCharNonBlock().

+ Here is the caller graph for this function:

◆ setDebugState()

void X86Keyboard::setDebugState ( bool  enableDebugState)
virtual

Selects polling input while the kernel debugger owns the processor.

A debugger trap can interrupt code which owns arbitrary device or IRQ controller locks. Both this setter and getDebugState() must therefore access this mode without taking locks, waiting, allocating, logging, changing interrupt masks, or starting a device protocol. The debugger trap itself prevents ordinary interrupt delivery while this mode is active.

Implements Keyboard.

Definition at line 101 of file mach_pc/Keyboard.cc.

References m_pPs2Controller, and Ps2Controller::setDebugState().

◆ setLedState()

void X86Keyboard::setLedState ( char  state)
virtual

Sets the current state of LEDs on the keyboard. If a keyboard does not have any LEDs this is essentially a no-op.

Reimplemented from Keyboard.

Definition at line 148 of file mach_pc/Keyboard.cc.

◆ startReaderThread()

void X86Keyboard::startReaderThread ( )

Definition at line 193 of file mach_pc/Keyboard.cc.

◆ stopReaderThread()

void X86Keyboard::stopReaderThread ( )

Definition at line 207 of file mach_pc/Keyboard.cc.

◆ updateLedState()

void X86Keyboard::updateLedState ( char  state,
bool  toggle 
)
private

Definition at line 152 of file mach_pc/Keyboard.cc.

Member Data Documentation

◆ m_Escape

KeymapManager::EscapeState X86Keyboard::m_Escape
private

The current escape state.

Definition at line 73 of file kernel/machine/mach_pc/Keyboard.h.

Referenced by scancodeToAscii().

◆ m_IrqId

irq_id_t X86Keyboard::m_IrqId
private

IRQ id.

Definition at line 76 of file kernel/machine/mach_pc/Keyboard.h.

◆ m_LedCommandState

LedCommandState X86Keyboard::m_LedCommandState
private

Definition at line 82 of file kernel/machine/mach_pc/Keyboard.h.

◆ m_LedLock

Mutex X86Keyboard::m_LedLock
private

Definition at line 85 of file kernel/machine/mach_pc/Keyboard.h.

◆ m_LedRetries

size_t X86Keyboard::m_LedRetries
private

Definition at line 84 of file kernel/machine/mach_pc/Keyboard.h.

◆ m_LedSent

uint8_t X86Keyboard::m_LedSent
private

Definition at line 83 of file kernel/machine/mach_pc/Keyboard.h.

◆ m_LedState

char X86Keyboard::m_LedState
private

Current LED state.

Definition at line 79 of file kernel/machine/mach_pc/Keyboard.h.

Referenced by getLedState().

◆ m_pPs2Controller

Ps2Controller* X86Keyboard::m_pPs2Controller
private

Parent PS/2 controller.

Definition at line 70 of file kernel/machine/mach_pc/Keyboard.h.

Referenced by getChar(), getCharNonBlock(), initialise(), and setDebugState().

◆ m_ReaderThread

OwnedThread X86Keyboard::m_ReaderThread
private

The controller buffer may block this worker until teardown wakes it.

Definition at line 88 of file kernel/machine/mach_pc/Keyboard.h.


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