diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-17 10:59:07 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-17 11:00:09 +0100 |
| commit | 9898520f721220a2af4be59fd92e8ad8afcd4287 (patch) | |
| tree | 35662af54535ccc07366b1a3a554f6296e76f4ce /Private/Builtins/PS2 | |
| parent | 45548d516ddf5e88bf80940365d151e1bd69c29f (diff) | |
Unstable: See below.
These changes are related to the current ticket regarding AHCI support.
This commit is just to upstream changes from local.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private/Builtins/PS2')
| -rw-r--r-- | Private/Builtins/PS2/PS2MouseInterface.hxx | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/Private/Builtins/PS2/PS2MouseInterface.hxx b/Private/Builtins/PS2/PS2MouseInterface.hxx new file mode 100644 index 00000000..682151e9 --- /dev/null +++ b/Private/Builtins/PS2/PS2MouseInterface.hxx @@ -0,0 +1,109 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + + 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 HCore { +/// @brief PS/2 Mouse driver interface +class PS2MouseInterface final { + public: + explicit PS2MouseInterface() = default; + ~PS2MouseInterface() = default; + + HCORE_COPY_DEFAULT(PS2MouseInterface); + + public: + Void Init() noexcept { + HCore::kcout << "HCoreKrnl.exe: Enabling PS/2 mouse...\r\n"; + + this->Write(0xFF); + + HAL::Out8(0x64, 0xA8); + + this->Wait(); + + HAL::Out8(0x64, 0x20); + + this->WaitInput(); + + UInt8 dataStatus = HAL::In8(0x60); + + dataStatus |= 0b10; + + this->Wait(); + + HAL::Out8(0x60, dataStatus); + + this->Write(0xF6); + auto f6Dat = this->Read(); + + this->Write(0xF4); + auto f4Dat = this->Read(); + + HCore::kcout << "HCoreKrnl.exe: PS/2 mouse is OK: " << hex_number(f6Dat); + HCore::kcout << ", " << hex_number(f4Dat) << end_line(); + } + + private: + Bool WaitInput() noexcept { + UInt64 timeout = 100000; + + while (timeout) { + if ((HAL::In8(0x64) & 0x1)) { + HCore::kcout << "HCoreKrnl.exe: Wait: OK\r\n"; + return true; + } + + --timeout; + } // wait until we can read + + HCore::kcout << "HCoreKrnl.exe: Wait: Timeout\r\n"; + // return the ack bit. + return false; + } + + Bool Wait() noexcept { + UInt64 timeout = 100000; + + while (timeout) { + if ((HAL::In8(0x64) & 0b10) == 0) { + HCore::kcout << "HCoreKrnl.exe: Wait: OK\r\n"; + return true; + } + + --timeout; + } // wait until we can read + + HCore::kcout << "HCoreKrnl.exe: Wait: Timeout\r\n"; + // return the ack bit. + return false; + } + + Void Write(UInt8 val) { + this->Wait(); + HAL::Out8(0x64, 0xD4); + this->Wait(); + + HAL::Out8(0x60, val); + } + + UInt8 Read() { + this->WaitInput(); + return HAL::In8(0x60); + } +}; +} // namespace HCore |
