21 #include "pedigree/kernel/machine/InputManager.h" 22 #include "pedigree/kernel/process/Thread.h" 23 #include "pedigree/kernel/processor/Processor.h" 24 #include "pedigree/kernel/processor/ProcessorInformation.h" 25 #include "pedigree/kernel/utilities/new" 26 #include "system/kernel/machine/mach_pc/Ps2Controller.h" 30 Ps2Mouse::Ps2Mouse(
Device *pDev)
31 : m_pController(0), m_Buffer(), m_BufferIndex(0), m_BufferLock(),
36 for (
size_t i = 0; i < m_nHandlers; ++i)
38 m_Handlers[i] =
nullptr;
39 m_HandlerParams[i] =
nullptr;
49 m_pController = pController;
56 m_pController->readSecondPort(result);
57 m_pController->writeSecondPort(MouseStream);
58 m_pController->readSecondPort(result);
61 m_pController->setIrqEnable(
true,
true);
65 Thread *pThread =
new Thread(pProcess, readerThreadTrampoline,
this);
71 void Ps2Mouse::write(
const char *bytes,
size_t len)
73 for (
size_t i = 0; i < len; ++i)
75 m_pController->writeSecondPort(bytes[i]);
79 void Ps2Mouse::subscribe(MouseHandlerFunction handler,
void *param)
81 for (
size_t i = 0; i < m_nHandlers; ++i)
88 m_Handlers[i] = handler;
89 m_HandlerParams[i] = param;
94 void Ps2Mouse::updateSubscribers(
const void *buffer,
size_t len)
96 for (
size_t i = 0; i < m_nHandlers; ++i)
103 m_Handlers[i](m_HandlerParams[i], buffer, len);
107 int Ps2Mouse::readerThreadTrampoline(
void *param)
110 instance->readerThread();
113 void Ps2Mouse::readerThread()
118 if (!m_pController->readSecondPort(byte))
123 updateSubscribers(&byte, 1);
125 if (byte == 0xFA || byte == 0xFE)
133 uint32_t buttons = 0;
134 bool needUpdate =
false;
136 m_BufferLock.acquire();
137 m_Buffer[m_BufferIndex++] = byte;
138 needUpdate = m_BufferIndex == 3;
141 xrel =
static_cast<ssize_t
>(
static_cast<int8_t
>(m_Buffer[1]));
142 yrel =
static_cast<ssize_t
>(
static_cast<int8_t
>(m_Buffer[2]));
143 buttons =
static_cast<uint32_t
>(m_Buffer[0]) & 0x3;
146 m_BufferLock.release();
virtual bool initialise(Ps2Controller *pController)
static ProcessorInformation & information()
virtual void setSpecificType(String str)
EXPORTED_PUBLIC void writeSecondPort(uint8_t byte)
Send a byte to the second port of the PS/2 controller.