Moved development of ostd::Serial to OmniaFramework
This commit is contained in:
parent
5499674333
commit
0073ef91f9
2 changed files with 0 additions and 133 deletions
|
|
@ -1,19 +0,0 @@
|
|||
/*
|
||||
OmniaFramework - A collection of useful functionality
|
||||
Copyright (C) 2026 OmniaX-Dev
|
||||
|
||||
This file is part of OmniaFramework.
|
||||
|
||||
OmniaFramework is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OmniaFramework is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OmniaFramework. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
OmniaFramework - A collection of useful functionality
|
||||
Copyright (C) 2026 OmniaX-Dev
|
||||
|
||||
This file is part of OmniaFramework.
|
||||
|
||||
OmniaFramework is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OmniaFramework is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OmniaFramework. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ostd/data/Types.hpp>
|
||||
#include <span>
|
||||
|
||||
namespace ostd
|
||||
{
|
||||
class Serial
|
||||
{
|
||||
public: enum class Endianness : u8 { LittleEndian = 0, BigEndian };
|
||||
public: using StreamEdit = std::span<int8_t>;
|
||||
public: using StreamView = std::span<const int8_t>;
|
||||
public: class Stream
|
||||
{
|
||||
public:
|
||||
inline Stream(u64 size, Endianness endianness = Endianness::LittleEndian, bool preInitialize = false, i8 initialValue = 0) {
|
||||
if (size < 1) return;
|
||||
if constexpr (sizeof(size_t) < sizeof(uint64_t))
|
||||
{
|
||||
if (size > std::numeric_limits<size_t>::max())
|
||||
throw "Serial::Stream size can't excede UINT32_MAX on a 32bit system.";
|
||||
}
|
||||
m_data = new i8[size];
|
||||
m_size = size;
|
||||
m_endianness = endianness;
|
||||
if (preInitialize)
|
||||
{
|
||||
for (u64 i = 0; i < size; i++)
|
||||
m_data[i] = initialValue;
|
||||
}
|
||||
}
|
||||
inline ~Stream(void) {
|
||||
if (isValid())
|
||||
{
|
||||
delete[] m_data;
|
||||
m_data = nullptr;
|
||||
}
|
||||
}
|
||||
inline bool isValid(void) const { return m_size > 0 && m_data != nullptr; }
|
||||
inline StreamEdit data() {
|
||||
if (isValid())
|
||||
return { m_data, cast<std::size_t>(m_size) };
|
||||
return {};
|
||||
}
|
||||
inline StreamView data() const {
|
||||
if (isValid())
|
||||
return { m_data, cast<std::size_t>(m_size) };
|
||||
return {};
|
||||
}
|
||||
|
||||
private:
|
||||
i8* m_data { nullptr };
|
||||
u64 m_size { 0 };
|
||||
Endianness m_endianness { Endianness::LittleEndian };
|
||||
};
|
||||
|
||||
public:
|
||||
inline static void attachStream(Stream& stream) { s_openStream = stream.data(); }
|
||||
inline static void detachStrean(void) { s_openStream = {}; }
|
||||
inline static bool isStreamAttached(void) { return !s_openStream.empty(); }
|
||||
|
||||
public: struct read
|
||||
{
|
||||
std::pair<i8, bool> int8(u64 addr);
|
||||
inline i8 int8d(u64 addr, bool* outError = nullptr) { auto val = int8(addr); if (outError) *outError = val.second; return val.first; }
|
||||
std::pair<u8, bool> uint8(u64 addr);
|
||||
inline u8 uint8d(u64 addr, bool* outError = nullptr) { auto val = uint8(addr); if (outError) *outError = val.second; return val.first; }
|
||||
|
||||
std::pair<i16, bool> int16(u64 addr);
|
||||
inline i16 int16d(u64 addr, bool* outError = nullptr) { auto val = int16(addr); if (outError) *outError = val.second; return val.first; }
|
||||
std::pair<u16, bool> uint16(u64 addr);
|
||||
inline u16 uint16d(u64 addr, bool* outError = nullptr) { auto val = uint16(addr); if (outError) *outError = val.second; return val.first; }
|
||||
|
||||
std::pair<i8, bool> int32(u64 addr);
|
||||
inline i32 int32d(u64 addr, bool* outError = nullptr) { auto val = int32(addr); if (outError) *outError = val.second; return val.first; }
|
||||
std::pair<u32, bool> uint32(u64 addr);
|
||||
inline u32 uint32d(u64 addr, bool* outError = nullptr) { auto val = uint32(addr); if (outError) *outError = val.second; return val.first; }
|
||||
|
||||
std::pair<i8, bool> int64(u64 addr);
|
||||
inline i64 int64d(u64 addr, bool* outError = nullptr) { auto val = int64(addr); if (outError) *outError = val.second; return val.first; }
|
||||
std::pair<u64, bool> uint64(u64 addr);
|
||||
inline u64 uint64d(u64 addr, bool* outError = nullptr) { auto val = uint64(addr); if (outError) *outError = val.second; return val.first; }
|
||||
|
||||
private:
|
||||
read(void) = default;
|
||||
};
|
||||
|
||||
private:
|
||||
Serial(void) = default;
|
||||
|
||||
private:
|
||||
inline static StreamEdit s_openStream { };
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue