13#ifndef ADS9324_DETAIL_HPP
14#define ADS9324_DETAIL_HPP
21namespace ads9324::detail {
28void LiteralOutOfRange() noexcept;
37consteval std::uint8_t operator""_u8(
unsigned long long v) noexcept {
41 return static_cast<std::uint8_t
>(v);
50consteval std::uint16_t
operator""_u16(
unsigned long long v)
noexcept {
54 return static_cast<std::uint16_t
>(v);
64consteval std::uint32_t
operator""_u32(
unsigned long long v)
noexcept {
65 if (v > 0xFFFF'FFFFULL) {
68 return static_cast<std::uint32_t
>(v);
86template <
typename Port,
typename Sig>
87 requires std::is_class_v<Port> && std::is_function_v<Sig>
91template <
typename Port,
typename R,
typename... Args>
92 requires std::is_class_v<Port>
93struct ExactHook<Port, R(Args...) noexcept> {
95 static void Take(R (Port::*hook)(Args...) noexcept) noexcept;
97 static void Take(R (Port::*hook)(Args...) const noexcept) noexcept;
103concept ClassType = std::is_class_v<T>;
108inline constexpr bool kAlwaysFalse =
false;
113concept Enumeration = std::is_enum_v<E>;
119template <Enumeration E>
120[[nodiscard]]
constexpr std::underlying_type_t<E> ToUnderlying(E e)
noexcept {
121 return static_cast<std::underlying_type_t<E>
>(e);
129template <Enumeration E>
137template <Enumeration E>
138[[nodiscard]]
constexpr bool IsEnumerator(E e)
noexcept {
139 return static_cast<uint32_t
>(ToUnderlying(e)) <=
140 static_cast<uint32_t
>(ToUnderlying(EnumLast<E>::kValue));
148template <
typename Reg, u
int32_t Shift, u
int32_t W
idth>
149 requires std::unsigned_integral<Reg> && (Width > 0U) && (Width < 32U) &&
150 ((Shift + Width) <=
static_cast<uint32_t
>(std::numeric_limits<Reg>::digits))
153 static constexpr uint32_t kMax = (uint32_t{1} << Width) - 1U;
155 static constexpr Reg kMask =
static_cast<Reg
>(kMax << Shift);
159 [[nodiscard]]
static constexpr Reg Insert(Reg reg, uint32_t value)
noexcept {
160 return static_cast<Reg
>((
static_cast<uint32_t
>(reg) & ~
static_cast<uint32_t
>(kMask)) |
161 ((value & kMax) << Shift));
164 [[nodiscard]]
static constexpr uint32_t Extract(Reg reg)
noexcept {
165 return (
static_cast<uint32_t
>(reg) >> Shift) & kMax;