summaryrefslogtreecommitdiffhomepage
path: root/Kernel/Builtins/PS2
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
commitaf8a516fc22865abd80d6e26f1541fa3d6bebfdc (patch)
tree96d42a10945fc03df022389aef54708383c1d616 /Kernel/Builtins/PS2
parenta874e9cc98df994178d55996943fe81799c61d2f (diff)
MHR-23: :boom:, refactors.
- Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/Builtins/PS2')
-rw-r--r--Kernel/Builtins/PS2/PS2MouseInterface.hxx112
1 files changed, 112 insertions, 0 deletions
diff --git a/Kernel/Builtins/PS2/PS2MouseInterface.hxx b/Kernel/Builtins/PS2/PS2MouseInterface.hxx
new file mode 100644
index 00000000..ef2319d5
--- /dev/null
+++ b/Kernel/Builtins/PS2/PS2MouseInterface.hxx
@@ -0,0 +1,112 @@
+/* -------------------------------------------
+
+ Copyright SoftwareLabs
+
+ File: PS2MouseInterface.hxx
+ Purpose: PS/2 mouse.
+
+ Revision History:
+
+ 03/02/24: Added file (amlel)
+
+------------------------------------------- */
+
+#pragma once
+
+#include <ArchKit/ArchKit.hpp>
+#include <CompilerKit/CompilerKit.hxx>
+#include <NewKit/Defines.hpp>
+
+namespace NewOS
+{
+ /// @brief PS/2 Mouse driver interface
+ class PS2MouseInterface final
+ {
+ public:
+ explicit PS2MouseInterface() = default;
+ ~PS2MouseInterface() = default;
+
+ NEWOS_COPY_DEFAULT(PS2MouseInterface);
+
+ public:
+ /// @brief Enables PS2 mouse for kernel.
+ /// @return
+ Void Init() noexcept
+ {
+ HAL::rt_cli();
+
+ HAL::Out8(0x64, 0xA8); // enabling the auxiliary device - mouse
+
+ this->Wait();
+ HAL::Out8(0x64, 0x20); // tells the keyboard controller that we want to send a command to the mouse
+ this->WaitInput();
+
+ UInt8 status = HAL::In8(0x60);
+ status |= 0b10;
+
+ this->Wait();
+ HAL::Out8(0x64, 0x60);
+ this->Wait();
+ HAL::Out8(0x60, status); // setting the correct bit is the "compaq" status byte
+
+ this->Write(0xF6);
+ this->Read();
+
+ this->Write(0xF4);
+ this->Read();
+
+ HAL::rt_sti();
+ }
+
+ public:
+ Bool WaitInput() noexcept
+ {
+ UInt64 timeout = 100000;
+
+ while (timeout)
+ {
+ if ((HAL::In8(0x64) & 0x1))
+ {
+ return true;
+ }
+
+ --timeout;
+ } // wait until we can read
+
+ // return the ack bit.
+ return false;
+ }
+
+ Bool Wait() noexcept
+ {
+ UInt64 timeout = 100000;
+
+ while (timeout)
+ {
+ if ((HAL::In8(0x64) & 0b10) == 0)
+ {
+ return true;
+ }
+
+ --timeout;
+ } // wait until we can read
+
+ // return the ack bit.
+ return false;
+ }
+
+ Void Write(UInt8 val)
+ {
+ HAL::Out8(0x64, 0xD4);
+ this->Wait();
+ HAL::Out8(0x60, val);
+ this->Wait();
+ }
+
+ UInt8 Read()
+ {
+ this->WaitInput();
+ return HAL::In8(0x60);
+ }
+ };
+} // namespace NewOS