diff --git a/hardware.hpp b/hardware.hpp index 4e5f174..abbb756 100644 --- a/hardware.hpp +++ b/hardware.hpp @@ -2,9 +2,9 @@ #include "../clock.hpp" -#include +#include "../type/type.hpp" -#include "utils.hpp" +#include #define FORCE_INLINE __attribute__((always_inline)) @@ -258,7 +258,7 @@ class BlockingHardware { static bool peek(data_t &) FORCE_INLINE { - static_assert(util::always_false_v, "Peek with data is not supported in blocking mode"); + static_assert(type::always_false_v, "Peek with data is not supported in blocking mode"); return false; } diff --git a/software.hpp b/software.hpp index 2bf3ae4..fb82cbf 100644 --- a/software.hpp +++ b/software.hpp @@ -1,15 +1,15 @@ #pragma once #include "config.hpp" -#include "utils.hpp" #include "../io/io.hpp" +#include "../type/type.hpp" namespace uart { template > class Software { - static_assert(util::always_false_v, "Not implemented"); + static_assert(type::always_false_v, "Not implemented"); public: using data_t = typename cfg::data_t; diff --git a/uart.hpp b/uart.hpp index 16451b7..54f55a2 100644 --- a/uart.hpp +++ b/uart.hpp @@ -4,7 +4,6 @@ #include "config.hpp" #include "software.hpp" -#include "utils.hpp" #undef UART0_INT_VECTORS #include "hardware0.hpp" @@ -36,8 +35,8 @@ static constexpr size_t cntDigits() template static constexpr size_t maxNumDigits() { - constexpr T MinVal = util::NumericLimits::min(); - constexpr T MaxVal = util::NumericLimits::max(); + constexpr T MinVal = type::NumericLimits::min(); + constexpr T MaxVal = type::NumericLimits::max(); constexpr T MinDigits = cntDigits(); constexpr T MaxDigits = cntDigits(); @@ -115,7 +114,7 @@ class Uart { template static void txNumber(const T &val) { - static_assert(util::is_integral_v, "Only supported on integral types"); + static_assert(type::is_integral_v, "Only supported on integral types"); static_assert(Base >= 2, "Numbers with base less than 2 make no sense"); static_assert(Base <= 16, "Numbers with base higher than 16 are not supported"); static_assert(Padding <= detail::maxNumDigits(), "Cannot pad more than maximum length of number"); @@ -237,19 +236,19 @@ class Uart { template Uart &operator<<(float) const { - static_assert(util::always_false_v, "Not supported by hardware"); + static_assert(type::always_false_v, "Not supported by hardware"); } template Uart &operator<<(double) const { - static_assert(util::always_false_v, "Not supported by hardware"); + static_assert(type::always_false_v, "Not supported by hardware"); } template Uart &operator<<(long double) const { - static_assert(util::always_false_v, "Not supported by hardware"); + static_assert(type::always_false_v, "Not supported by hardware"); } Uart &operator<<(const bool &val) @@ -271,91 +270,91 @@ class Uart { template Uart &operator>>(char &) const { - static_assert(util::always_false_v, "Not implemented"); + static_assert(type::always_false_v, "Not implemented"); } template Uart &operator>>(unsigned char &) const { - static_assert(util::always_false_v, "Not implemented"); + static_assert(type::always_false_v, "Not implemented"); } template Uart &operator>>(short &) const { - static_assert(util::always_false_v, "Not implemented"); + static_assert(type::always_false_v, "Not implemented"); } template Uart &operator>>(unsigned short &) const { - static_assert(util::always_false_v, "Not implemented"); + static_assert(type::always_false_v, "Not implemented"); } template Uart &operator>>(int &) const { - static_assert(util::always_false_v, "Not implemented"); + static_assert(type::always_false_v, "Not implemented"); } template Uart &operator>>(unsigned int &) const { - static_assert(util::always_false_v, "Not implemented"); + static_assert(type::always_false_v, "Not implemented"); } template Uart &operator>>(long &) const { - static_assert(util::always_false_v, "Not implemented"); + static_assert(type::always_false_v, "Not implemented"); } template Uart &operator>>(unsigned long &) const { - static_assert(util::always_false_v, "Not implemented"); + static_assert(type::always_false_v, "Not implemented"); } template Uart &operator>>(long long &) const { - static_assert(util::always_false_v, "Not implemented"); + static_assert(type::always_false_v, "Not implemented"); } template Uart &operator>>(unsigned long long &) const { - static_assert(util::always_false_v, "Not implemented"); + static_assert(type::always_false_v, "Not implemented"); } template Uart &operator>>(float &) const { - static_assert(util::always_false_v, "Not supported by hardware"); + static_assert(type::always_false_v, "Not supported by hardware"); } template Uart &operator>>(double &) const { - static_assert(util::always_false_v, "Not supported by hardware"); + static_assert(type::always_false_v, "Not supported by hardware"); } template Uart &operator>>(long double &) const { - static_assert(util::always_false_v, "Not supported by hardware"); + static_assert(type::always_false_v, "Not supported by hardware"); } template Uart &operator>>(bool &) const { - static_assert(util::always_false_v, "Not implemented"); + static_assert(type::always_false_v, "Not implemented"); } template Uart &operator>>(const void *&) const { - static_assert(util::always_false_v, "Not implemented"); + static_assert(type::always_false_v, "Not implemented"); } }; diff --git a/utils.hpp b/utils.hpp deleted file mode 100644 index d9a7f93..0000000 --- a/utils.hpp +++ /dev/null @@ -1,143 +0,0 @@ -#pragma once - -// Fix for limits.h not exposing LLONG_MIN, LLONG_MIN, and ULLONG_MAX to C++ context -#ifdef __cplusplus -#define __STDC_VERSION__ 201112L -#endif - -#include -#include - -namespace uart { -namespace util { - -// clang-format off -template struct set_bool { static constexpr auto value = Val; }; - -struct true_type : set_bool {}; -struct false_type : set_bool {}; - -template struct always_false : false_type {}; - -template static constexpr auto always_false_v = always_false::value; - -template struct is_integral : false_type {}; -template <> struct is_integral : true_type {}; -template <> struct is_integral : true_type {}; -template <> struct is_integral : true_type {}; -template <> struct is_integral : true_type {}; -template <> struct is_integral : true_type {}; -template <> struct is_integral : true_type {}; -template <> struct is_integral : true_type {}; -template <> struct is_integral : true_type {}; -template <> struct is_integral : true_type {}; -template <> struct is_integral : true_type {}; -template <> struct is_integral : true_type {}; -template <> struct is_integral : true_type {}; - -template static constexpr auto is_integral_v = is_integral::value; - -template struct is_same : false_type {}; -template struct is_same : true_type {}; - -template static constexpr auto is_same_v = is_same::value; - -template -struct NumericLimits { - static constexpr T min() { return T(); } - static constexpr T max() { return T(); } -}; - -template <> -struct NumericLimits { - static constexpr bool min() { return false; } - static constexpr bool max() { return true; } -}; - -template <> -struct NumericLimits { - static constexpr char min() { return CHAR_MIN; } - static constexpr char max() { return CHAR_MAX; } -}; - -template <> -struct NumericLimits { - static constexpr signed char min() { return SCHAR_MIN; } - static constexpr signed char max() { return SCHAR_MAX; } -}; - -template <> -struct NumericLimits { - static constexpr unsigned char min() { return 0; } - static constexpr unsigned char max() { return UCHAR_MAX; } -}; - -template <> -struct NumericLimits { - static constexpr short min() { return SHRT_MIN; } - static constexpr short max() { return SHRT_MAX; } -}; - -template <> -struct NumericLimits { - static constexpr int min() { return INT_MIN; } - static constexpr int max() { return INT_MAX; } -}; - -template <> -struct NumericLimits { - static constexpr long int min() { return LONG_MIN; } - static constexpr long int max() { return LONG_MAX; } -}; - -template <> -struct NumericLimits { - static constexpr long long int min() { return LLONG_MIN; } - static constexpr long long int max() { return LLONG_MAX; } -}; - -template <> -struct NumericLimits { - static constexpr unsigned short min() { return 0; } - static constexpr unsigned short max() { return USHRT_MAX; } -}; - -template <> -struct NumericLimits { - static constexpr unsigned int min() { return 0; } - static constexpr unsigned int max() { return UINT_MAX; } -}; - -template <> -struct NumericLimits { - static constexpr unsigned long int min() { return 0; } - static constexpr unsigned long int max() { return ULONG_MAX; } -}; - -template <> -struct NumericLimits { - static constexpr unsigned long long int min() { return 0; } - static constexpr unsigned long long int max() { return ULLONG_MAX; } -}; - -template <> -struct NumericLimits { - template static constexpr float min() { return FLT_MIN; } - template static constexpr float max() { return FLT_MAX; } -}; - -template <> -struct NumericLimits { - template static constexpr double min() { return DBL_MIN; } - template static constexpr double max() { return DBL_MAX; } -}; - -template <> -struct NumericLimits { - template static constexpr long double min() { return LDBL_MIN; } - template static constexpr long double max() { return LDBL_MAX; } -}; -// clang-format on - -} // namespace util -} // namespace uart