mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-09-29 00:54:54 +00:00
32 lines
784 B
C
32 lines
784 B
C
|
#pragma once
|
||
|
|
||
|
namespace EightBit {
|
||
|
class Device {
|
||
|
public:
|
||
|
enum class PinLevel {
|
||
|
Low, High
|
||
|
};
|
||
|
|
||
|
static constexpr auto raised(const PinLevel line) { return line == PinLevel::High; }
|
||
|
static void raise(PinLevel& line) noexcept { line = PinLevel::High; }
|
||
|
static constexpr auto lowered(const PinLevel line) { return line == PinLevel::Low; }
|
||
|
static void lower(PinLevel& line) noexcept { line = PinLevel::Low; }
|
||
|
|
||
|
static void match(PinLevel& line, int value);
|
||
|
|
||
|
virtual ~Device() {};
|
||
|
|
||
|
[[nodiscard]] auto& POWER() noexcept { return m_powerLine; }
|
||
|
|
||
|
[[nodiscard]] auto powered() noexcept { return raised(POWER()); }
|
||
|
virtual void powerOn();
|
||
|
virtual void powerOff() { lower(POWER()); }
|
||
|
|
||
|
protected:
|
||
|
Device() {};
|
||
|
|
||
|
private:
|
||
|
PinLevel m_powerLine = PinLevel::Low;
|
||
|
};
|
||
|
}
|