21 #include "Ps2Controller.h" 22 #include "pedigree/kernel/Log.h" 23 #include "pedigree/kernel/machine/HidInputManager.h" 24 #include "pedigree/kernel/machine/InputManager.h" 25 #include "pedigree/kernel/machine/KeymapManager.h" 26 #include "pedigree/kernel/process/Thread.h" 27 #include "pedigree/kernel/processor/Processor.h" 28 #include "pedigree/kernel/processor/ProcessorInformation.h" 29 #include "pedigree/kernel/utilities/new" 32 #ifdef TRACK_PAGE_ALLOCATIONS 33 #include "pedigree/kernel/debugger/commands/AllocationCommand.h" 36 #include "pedigree/kernel/core/SlamAllocator.h" 37 #include "pedigree/kernel/debugger/commands/SlamCommand.h" 43 extern void toggleTracingAllocations();
47 : m_pPs2Controller(controller), m_Escape(
KeymapManager::EscapeNone),
48 m_IrqId(0), m_LedState(0)
52 X86Keyboard::~X86Keyboard()
62 m_pPs2Controller->writeFirstPort(0xF4);
63 m_pPs2Controller->readFirstPort(result);
64 NOTICE(
"X86Keyboard: 'enable stream' response: " <<
Hex << result);
69 if (m_pPs2Controller->getDebugState())
72 uint8_t scancode = m_pPs2Controller->readByte();
73 return scancodeToAscii(scancode);
77 ERROR(
"Keyboard::getChar() should not be called outside debug mode");
84 if (m_pPs2Controller->getDebugState())
86 uint8_t scancode = m_pPs2Controller->readByteNonBlock();
93 return scancodeToAscii(scancode);
97 ERROR(
"Keyboard::getCharNonBlock should not be called outside debug " 105 m_pPs2Controller->setDebugState(enableDebugState);
108 bool X86Keyboard::getDebugState()
110 return m_pPs2Controller->getDebugState();
125 keyCode, !(scancode & 0x80)) &&
131 if (key & Keyboard::Special)
133 char a = key & 0xFF, b = (key >> 8) & 0xFF, c = (key >> 16) & 0xFF,
134 d = (key >> 24) & 0xFF;
136 if (a ==
'u' && b ==
'p')
139 if (a ==
'd' && b ==
'o' && c ==
'w' && d ==
'n')
142 if (a ==
'p' && b ==
'g' && c ==
'u' && d ==
'p')
145 if (a ==
'p' && b ==
'g' && c ==
'd' && d ==
'n')
149 if ((key & Keyboard::Special) || ((key & 0xFFFFFFFF) > 0x7f))
151 return static_cast<char>(key & 0x7f);
163 m_pPs2Controller->writeFirstPort(0xED);
164 m_pPs2Controller->writeFirstPort(state);
166 uint8_t response = 0;
167 if (m_pPs2Controller->readFirstPort(response))
169 NOTICE(
"X86Keyboard: setLedState response: " <<
Hex << response);
173 ERROR(
"X86Keyboard: failed to read response in setLedState");
177 void X86Keyboard::startReaderThread()
181 Thread *pThread =
new Thread(pProcess, readerThreadTrampoline,
this);
185 m_pPs2Controller->setIrqEnable(
true,
false);
188 int X86Keyboard::readerThreadTrampoline(
void *param)
191 instance->readerThread();
194 void X86Keyboard::readerThread()
199 if (!m_pPs2Controller->readFirstPort(scancode))
203 if (scancode == 0xFA || scancode == 0xFE)
211 #if CRIPPLINGLY_VIGILANT 212 if (scancode == 0x43)
213 SlamAllocator::instance().setVigilance(
true);
214 if (scancode == 0x44)
215 SlamAllocator::instance().setVigilance(
false);
217 if (scancode == 0x57)
219 #ifdef MEMORY_TRACING 220 WARNING(
"Toggling allocation tracing.");
221 toggleTracingAllocations();
223 #ifdef TRACK_PAGE_ALLOCATIONS 224 g_AllocationCommand.checkpoint();
226 g_SlamCommand.clean();
231 if (scancode == 0x58)
233 FATAL(
"User-induced breakpoint.");
240 uint8_t code = scancode & ~0x80;
243 DEBUG_LOG(
"X86Keyboard: Caps Lock toggled");
247 else if (code == 0x45)
249 DEBUG_LOG(
"X86Keyboard: Num Lock toggled");
253 else if (code == 0x46)
255 DEBUG_LOG(
"X86Keyboard: Scroll Lock toggled");
262 scancode & 0x7F, scancode & 0x80);
271 "X86Keyboard: failed to translate scancode " <<
Hex char scancodeToAscii(uint8_t scancode)
Converts a scancode into an ASCII character (for use in debug state)
virtual void setLedState(char state)
virtual char getCharNonBlock()
virtual char getLedState()
virtual void setLedState(char state)
uint64_t resolveHidKeycode(uint8_t keyCode)
static KeymapManager & instance()
Singleton design.
static ProcessorInformation & information()
uint8_t convertPc102ScancodeToHidKeycode(uint8_t scancode, EscapeState &escape)
Converts a pc102 scancode into a HID keycode.
virtual void setDebugState(bool enableDebugState)
virtual void initialise()
Initialises the device.