forked from Bananymous/banan-os
Kernel: Move PS2Device to its own file
This commit is contained in:
@@ -248,72 +248,4 @@ namespace Kernel::Input
|
||||
return {};
|
||||
}
|
||||
|
||||
PS2Device::PS2Device(PS2Controller& controller)
|
||||
: CharacterDevice(0440, 0, 901)
|
||||
, m_name(BAN::String::formatted("input{}", DevFileSystem::get().get_next_input_device()))
|
||||
, m_controller(controller)
|
||||
{ }
|
||||
|
||||
bool PS2Device::append_command_queue(uint8_t command)
|
||||
{
|
||||
if (m_command_queue.size() + 1 >= m_command_queue.capacity())
|
||||
return false;
|
||||
m_command_queue.push(command);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PS2Device::append_command_queue(uint8_t command, uint8_t data)
|
||||
{
|
||||
if (m_command_queue.size() + 2 >= m_command_queue.capacity())
|
||||
return false;
|
||||
m_command_queue.push(command);
|
||||
m_command_queue.push(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
void PS2Device::handle_irq()
|
||||
{
|
||||
uint8_t byte = IO::inb(PS2::IOPort::DATA);
|
||||
|
||||
// NOTE: This implementation does not allow using commands
|
||||
// that respond with more bytes than ACK
|
||||
switch (m_state)
|
||||
{
|
||||
case State::WaitingAck:
|
||||
{
|
||||
switch (byte)
|
||||
{
|
||||
case PS2::Response::ACK:
|
||||
m_command_queue.pop();
|
||||
m_state = State::Normal;
|
||||
break;
|
||||
case PS2::Response::RESEND:
|
||||
m_state = State::Normal;
|
||||
break;
|
||||
default:
|
||||
handle_device_command_response(byte);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case State::Normal:
|
||||
{
|
||||
handle_byte(byte);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void PS2Device::update()
|
||||
{
|
||||
if (m_state == State::WaitingAck)
|
||||
return;
|
||||
if (m_command_queue.empty())
|
||||
return;
|
||||
m_state = State::WaitingAck;
|
||||
m_controller.send_byte(this, m_command_queue.front());
|
||||
}
|
||||
|
||||
}
|
||||
80
kernel/kernel/Input/PS2Device.cpp
Normal file
80
kernel/kernel/Input/PS2Device.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include <kernel/FS/DevFS/FileSystem.h>
|
||||
#include <kernel/Input/PS2Config.h>
|
||||
#include <kernel/Input/PS2Device.h>
|
||||
#include <kernel/IO.h>
|
||||
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
namespace Kernel::Input
|
||||
{
|
||||
|
||||
PS2Device::PS2Device(PS2Controller& controller)
|
||||
: CharacterDevice(0440, 0, 901)
|
||||
, m_name(BAN::String::formatted("input{}", DevFileSystem::get().get_next_input_device()))
|
||||
, m_rdev(makedev(DevFileSystem::get().get_next_dev(), 0))
|
||||
, m_controller(controller)
|
||||
{ }
|
||||
|
||||
bool PS2Device::append_command_queue(uint8_t command)
|
||||
{
|
||||
if (m_command_queue.size() + 1 >= m_command_queue.capacity())
|
||||
return false;
|
||||
m_command_queue.push(command);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PS2Device::append_command_queue(uint8_t command, uint8_t data)
|
||||
{
|
||||
if (m_command_queue.size() + 2 >= m_command_queue.capacity())
|
||||
return false;
|
||||
m_command_queue.push(command);
|
||||
m_command_queue.push(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
void PS2Device::handle_irq()
|
||||
{
|
||||
uint8_t byte = IO::inb(PS2::IOPort::DATA);
|
||||
|
||||
// NOTE: This implementation does not allow using commands
|
||||
// that respond with more bytes than ACK
|
||||
switch (m_state)
|
||||
{
|
||||
case State::WaitingAck:
|
||||
{
|
||||
switch (byte)
|
||||
{
|
||||
case PS2::Response::ACK:
|
||||
m_command_queue.pop();
|
||||
m_state = State::Normal;
|
||||
break;
|
||||
case PS2::Response::RESEND:
|
||||
m_state = State::Normal;
|
||||
break;
|
||||
default:
|
||||
handle_device_command_response(byte);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case State::Normal:
|
||||
{
|
||||
handle_byte(byte);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void PS2Device::update()
|
||||
{
|
||||
if (m_state == State::WaitingAck)
|
||||
return;
|
||||
if (m_command_queue.empty())
|
||||
return;
|
||||
m_state = State::WaitingAck;
|
||||
m_controller.send_byte(this, m_command_queue.front());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,11 +3,8 @@
|
||||
#include <kernel/FS/DevFS/FileSystem.h>
|
||||
#include <kernel/Input/PS2Config.h>
|
||||
#include <kernel/Input/PS2Keyboard.h>
|
||||
#include <kernel/IO.h>
|
||||
#include <kernel/Timer/Timer.h>
|
||||
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
#define SET_MASK(byte, mask, on_off) ((on_off) ? ((byte) | (mask)) : ((byte) & ~(mask)))
|
||||
#define TOGGLE_MASK(byte, mask) ((byte) ^ (mask))
|
||||
|
||||
@@ -24,7 +21,6 @@ namespace Kernel::Input
|
||||
|
||||
PS2Keyboard::PS2Keyboard(PS2Controller& controller)
|
||||
: PS2Device(controller)
|
||||
, m_rdev(makedev(DevFileSystem::get().get_next_dev(), 0))
|
||||
{ }
|
||||
|
||||
void PS2Keyboard::send_initialize()
|
||||
|
||||
Reference in New Issue
Block a user