2019-01-11 02:28:53 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <AK/CircularQueue.h>
|
2019-04-03 12:36:40 +02:00
|
|
|
#include <Kernel/Devices/CharacterDevice.h>
|
2019-03-05 13:59:44 +01:00
|
|
|
#include <Kernel/IRQHandler.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <Kernel/MousePacket.h>
|
2019-01-11 02:28:53 +01:00
|
|
|
|
2019-05-28 11:53:16 +02:00
|
|
|
class PS2MouseDevice final : public IRQHandler
|
|
|
|
|
, public CharacterDevice {
|
2019-01-11 02:28:53 +01:00
|
|
|
public:
|
|
|
|
|
PS2MouseDevice();
|
|
|
|
|
virtual ~PS2MouseDevice() override;
|
|
|
|
|
|
2019-01-11 03:52:09 +01:00
|
|
|
static PS2MouseDevice& the();
|
|
|
|
|
|
2019-01-12 05:20:56 +01:00
|
|
|
// ^CharacterDevice
|
2019-06-07 09:36:51 +02:00
|
|
|
virtual bool can_read(FileDescription&) const override;
|
|
|
|
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
|
|
|
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
|
|
|
|
virtual bool can_write(FileDescription&) const override { return true; }
|
2019-01-11 02:28:53 +01:00
|
|
|
|
2019-01-12 05:20:56 +01:00
|
|
|
private:
|
|
|
|
|
// ^IRQHandler
|
2019-01-11 02:28:53 +01:00
|
|
|
virtual void handle_irq() override;
|
|
|
|
|
|
2019-01-21 02:33:01 +01:00
|
|
|
// ^CharacterDevice
|
|
|
|
|
virtual const char* class_name() const override { return "PS2MouseDevice"; }
|
|
|
|
|
|
2019-01-11 02:28:53 +01:00
|
|
|
void initialize();
|
|
|
|
|
void prepare_for_input();
|
|
|
|
|
void prepare_for_output();
|
|
|
|
|
void mouse_write(byte);
|
|
|
|
|
byte mouse_read();
|
|
|
|
|
void wait_then_write(byte port, byte data);
|
|
|
|
|
byte wait_then_read(byte port);
|
2019-03-05 13:59:44 +01:00
|
|
|
void parse_data_packet();
|
2019-05-13 19:48:14 +02:00
|
|
|
void expect_ack();
|
2019-01-11 02:28:53 +01:00
|
|
|
|
2019-03-05 13:59:44 +01:00
|
|
|
CircularQueue<MousePacket, 100> m_queue;
|
2019-01-11 02:28:53 +01:00
|
|
|
byte m_data_state { 0 };
|
2019-05-13 19:48:14 +02:00
|
|
|
byte m_data[4];
|
|
|
|
|
bool m_has_wheel { false };
|
2019-01-11 02:28:53 +01:00
|
|
|
};
|