Clear Voice Keys
This commit is contained in:
@@ -2,11 +2,28 @@
|
||||
#define __JABYENGINE_IOPORT_HPP__
|
||||
#include "../../Auxiliary/bits.hpp"
|
||||
|
||||
template<typename T>
|
||||
struct Bit {
|
||||
typedef T ValueType;
|
||||
|
||||
size_t value;
|
||||
|
||||
constexpr Bit(size_t value) : value(value) {
|
||||
}
|
||||
|
||||
constexpr operator size_t() const {
|
||||
return this->value;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct BitRange {
|
||||
typedef T ValueType;
|
||||
|
||||
size_t begin;
|
||||
size_t length;
|
||||
|
||||
static constexpr BitRange from_to(size_t start, size_t end) {
|
||||
static constexpr BitRange<T> from_to(size_t start, size_t end) {
|
||||
return {start, (end - start + 1)};
|
||||
}
|
||||
};
|
||||
@@ -29,9 +46,8 @@ public:
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr volatile IOPort<T>& set_bit(S bit) volatile {
|
||||
constexpr void set_bit(S bit) volatile {
|
||||
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
@@ -41,9 +57,8 @@ public:
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr volatile IOPort<T>& clear_bit(S bit) volatile {
|
||||
constexpr void clear_bit(S bit) volatile {
|
||||
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
@@ -58,39 +73,46 @@ public:
|
||||
|
||||
//Accessing values
|
||||
template<typename S>
|
||||
constexpr IOPort<T>& set_value(S value, const BitRange& range) {
|
||||
constexpr IOPort<T>& set_value(S value, const BitRange<S>& range) {
|
||||
this->value = bit::value::set_normalized(this->value, static_cast<T>(value), range.begin, range.length);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr volatile IOPort<T>& set_value(S value, const BitRange& range) volatile {
|
||||
constexpr void set_value(S value, const BitRange<S>& range) volatile {
|
||||
this->value = bit::value::set_normalized(this->value, static_cast<T>(value), range.begin, range.length);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr IOPort<T>& clear_value(const BitRange& range) {
|
||||
constexpr IOPort<T>& clear_value(const BitRange<S>& range) {
|
||||
this->value = bit::value::clear_normalized(this->value, range.begin, range.length);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr volatile IOPort<T>& clear_value(const BitRange& range) volatile {
|
||||
constexpr void clear_value(const BitRange<S>& range) volatile {
|
||||
this->value = bit::value::clear_normalized(this->value, range.begin, range.length);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr S get_value(const BitRange& range) {
|
||||
constexpr S get_value(const BitRange<S>& range) {
|
||||
return static_cast<S>(bit::value::get_normalized(this->value, range.begin, range.length));
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr S get_value(const BitRange& range) volatile {
|
||||
constexpr S get_value(const BitRange<S>& range) volatile {
|
||||
return static_cast<S>(bit::value::get_normalized(this->value, range.begin, range.length));
|
||||
}
|
||||
|
||||
//For easy access
|
||||
constexpr T read() const {
|
||||
return const_cast<volatile IOPort<T>*>(this)->value;
|
||||
}
|
||||
|
||||
constexpr void write(T value) {
|
||||
const_cast<volatile IOPort<T>*>(this)->value = value;
|
||||
}
|
||||
|
||||
//For raw access
|
||||
constexpr operator T() const {
|
||||
return this->value;
|
||||
@@ -100,8 +122,9 @@ public:
|
||||
return this->value;
|
||||
}
|
||||
|
||||
constexpr void operator=(T value) {
|
||||
constexpr IOPort<T>& operator=(T value) {
|
||||
this->value = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr void operator=(T value) volatile {
|
||||
@@ -109,4 +132,36 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
struct __no_align ubus32_t {
|
||||
IOPort<uint16_t> low;
|
||||
IOPort<uint16_t> high;
|
||||
|
||||
constexpr ubus32_t(uint32_t value) {
|
||||
*this = value;
|
||||
}
|
||||
|
||||
constexpr operator uint32_t() const {
|
||||
return ((this->high << 16) | this->low);
|
||||
}
|
||||
|
||||
constexpr operator uint32_t() const volatile {
|
||||
return ((this->high << 16) | this->low);
|
||||
}
|
||||
|
||||
constexpr ubus32_t& operator=(uint32_t value) {
|
||||
this->low = (value & 0xFFFF);
|
||||
this->high = (value >> 16);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr void operator=(uint32_t value) volatile {
|
||||
this->low = (value & 0xFFFF);
|
||||
this->high = (value >> 16);
|
||||
}
|
||||
};
|
||||
static constexpr uintptr_t IO_Base_Mask = 0xF0000000;
|
||||
static constexpr uintptr_t IO_Base_Adr = 0x10000000;
|
||||
|
||||
#define __declare_io_port_global(type, name, adr) static __always_inline auto& name = *reinterpret_cast<IOPort<type>*>((IO_Base_Adr + (adr & ~IO_Base_Mask)))
|
||||
#endif //!__JABYENGINE_IOPORT_HPP__
|
||||
Reference in New Issue
Block a user