forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IRQHandler class that can be subclasses to handle an IRQ.
Also move Keyboard to a class implementation using this pattern.
- Loading branch information
1 parent
8f94156
commit a9ca75c
Showing
8 changed files
with
152 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "IRQHandler.h" | ||
#include "i386.h" | ||
#include "PIC.h" | ||
|
||
IRQHandler::IRQHandler(byte irq) | ||
: m_irqNumber(irq) | ||
{ | ||
registerIRQHandler(m_irqNumber, *this); | ||
} | ||
|
||
IRQHandler::~IRQHandler() | ||
{ | ||
unregisterIRQHandler(m_irqNumber, *this); | ||
} | ||
|
||
void IRQHandler::enableIRQ() | ||
{ | ||
PIC::enable(m_irqNumber); | ||
} | ||
|
||
void IRQHandler::disableIRQ() | ||
{ | ||
PIC::disable(m_irqNumber); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <AK/Types.h> | ||
|
||
class IRQHandler { | ||
public: | ||
virtual ~IRQHandler(); | ||
virtual void handleIRQ() = 0; | ||
|
||
byte irqNumber() const { return m_irqNumber; } | ||
|
||
void enableIRQ(); | ||
void disableIRQ(); | ||
|
||
protected: | ||
explicit IRQHandler(byte irq); | ||
|
||
private: | ||
byte m_irqNumber { 0 }; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
#pragma once | ||
|
||
namespace Keyboard { | ||
#include <AK/Types.h> | ||
#include "IRQHandler.h" | ||
|
||
enum class LED { | ||
ScrollLock = 1 << 0, | ||
NumLock = 1 << 1, | ||
CapsLock = 1 << 2, | ||
}; | ||
class Keyboard final : public IRQHandler { | ||
public: | ||
virtual ~Keyboard() override; | ||
Keyboard(); | ||
|
||
private: | ||
virtual void handleIRQ() override; | ||
|
||
void initialize(); | ||
void setLED(LED); | ||
void unsetLED(LED); | ||
void handleInterrupt(); | ||
byte m_modifiers { 0 }; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.