35 lines
889 B
C++
35 lines
889 B
C++
|
#include "fs/devices/KeyboardDevice.h"
|
||
|
|
||
|
SharedPtr<KeyboardDevice> KeyboardDevice::s_keyboard_device = {};
|
||
|
|
||
|
Result<void> KeyboardDevice::create()
|
||
|
{
|
||
|
auto device = TRY(make_shared<KeyboardDevice>());
|
||
|
s_keyboard_device = device;
|
||
|
return DeviceRegistry::register_special_device(DeviceRegistry::Input, 1, device, 0600);
|
||
|
}
|
||
|
|
||
|
Result<usize> KeyboardDevice::read(u8* buf, usize, usize length) const
|
||
|
{
|
||
|
length = m_packet_buffer.dequeue_data(buf, length);
|
||
|
|
||
|
return length;
|
||
|
}
|
||
|
|
||
|
Result<usize> KeyboardDevice::write(const u8* buf, usize, usize length)
|
||
|
{
|
||
|
TRY(m_packet_buffer.append_data(buf, length));
|
||
|
|
||
|
return length;
|
||
|
}
|
||
|
|
||
|
void KeyboardDevice::add_keyboard_event(const moon::KeyboardPacket& packet)
|
||
|
{
|
||
|
if (s_keyboard_device) s_keyboard_device->write((const u8*)&packet, 0, sizeof(packet));
|
||
|
}
|
||
|
|
||
|
bool KeyboardDevice::will_block_if_read() const
|
||
|
{
|
||
|
return !m_packet_buffer.size();
|
||
|
}
|