Use new fancy way to set values at build time
This commit is contained in:
parent
7071acead1
commit
181ff65c9c
|
@ -2,6 +2,13 @@
|
|||
#define __JABYENGINE_IOPORT_HPP__
|
||||
#include "../../Auxiliary/bits.hpp"
|
||||
|
||||
struct ClearBitValue {
|
||||
size_t bit;
|
||||
|
||||
constexpr ClearBitValue(size_t bit) : bit(bit) {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Bit {
|
||||
typedef T ValueType;
|
||||
|
@ -14,6 +21,10 @@ struct Bit {
|
|||
constexpr operator size_t() const {
|
||||
return this->value;
|
||||
}
|
||||
|
||||
constexpr ClearBitValue operator!() const {
|
||||
return ClearBitValue(this->value);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -28,6 +39,20 @@ struct BitRange {
|
|||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct BitRangeValue {
|
||||
T value;
|
||||
BitRange<T> range;
|
||||
|
||||
constexpr BitRangeValue(BitRange<T> range, T value) : value(value), range(range) {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
static constexpr __always_inline BitRangeValue<T> operator<<(const BitRange<T>& range, T value) {
|
||||
return BitRangeValue(range, value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class __no_align IOPort {
|
||||
private:
|
||||
|
@ -130,6 +155,22 @@ public:
|
|||
constexpr void operator=(T value) volatile {
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
// For easier constructing
|
||||
constexpr IOPort<T>& operator|(const BitRangeValue<T>& value) {
|
||||
this->set_value(value.value, value.range);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr IOPort<T>& operator|(const Bit<T>& bit) {
|
||||
this->set_bit(bit.value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr IOPort<T>& operator|(const ClearBitValue& value) {
|
||||
this->clear_bit(value.bit);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct __no_align ubus32_t {
|
||||
|
|
|
@ -91,7 +91,7 @@ namespace SPU {
|
|||
};
|
||||
|
||||
static constexpr Bit<uint16_t> Enable = 15;
|
||||
static constexpr Bit<uint16_t> Mute = 14;
|
||||
static constexpr Bit<uint16_t> Unmute = 14;
|
||||
static constexpr BitRange<Shift> NoiseFrequcenyShift = BitRange<Shift>::from_to(10, 13);
|
||||
static constexpr BitRange<Step> NoiseFrequcenyStep = BitRange<Step>::from_to(8, 9);
|
||||
static constexpr Bit<uint16_t> ReverbMasterEnable = 7;
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace SPU {
|
|||
}
|
||||
|
||||
static void clear_main_volume() {
|
||||
static constexpr auto StartVol = SweepVolume().clear_bit(SweepVolume::SweepEnable).set_value(static_cast<int16_t>(I16_MAX >> 2), SweepVolume::Volume);
|
||||
static constexpr auto StartVol = SweepVolume() | !SweepVolume::SweepEnable | (SweepVolume::Volume << static_cast<int16_t>(I16_MAX >> 2));
|
||||
|
||||
MainVolume::left.write(StartVol);
|
||||
MainVolume::right.write(StartVol);
|
||||
|
@ -19,9 +19,17 @@ namespace SPU {
|
|||
Control.write(ControlRegister());
|
||||
}
|
||||
|
||||
static void setup_control_register() {
|
||||
static constexpr auto SetupValue = ControlRegister() | ControlRegister::Enable | ControlRegister::Unmute | ControlRegister::CDAudioEnable;
|
||||
|
||||
Control.write(SetupValue);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
clear_key();
|
||||
clear_main_volume();
|
||||
clear_control_register();
|
||||
|
||||
setup_control_register();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue