11#ifndef TMC9660_DETAIL_HPP
12#define TMC9660_DETAIL_HPP
21namespace tmc9660::detail {
28constexpr void CopyBytes(std::span<const std::uint8_t> src, std::span<std::uint8_t> dst)
noexcept {
29 const std::size_t n = (src.size() < dst.size()) ? src.size() : dst.size();
30 for (std::size_t k = 0U; k < n; ++k) {
48template <
typename Port,
typename Sig>
49 requires std::is_class_v<Port> && std::is_function_v<Sig>
53template <
typename Port,
typename R,
typename... Args>
54 requires std::is_class_v<Port>
55struct ExactHook<Port, R(Args...) noexcept> {
57 static void Take(R (Port::*hook)(Args...) noexcept) noexcept;
59 static void Take(R (Port::*hook)(Args...) const noexcept) noexcept;
64concept ClassType = std::is_class_v<T>;
69inline constexpr bool kAlwaysFalse =
false;
73concept Enumeration = std::is_enum_v<E>;
79template <Enumeration E>
80[[nodiscard]]
constexpr std::underlying_type_t<E> ToUnderlying(E e)
noexcept {
81 return static_cast<std::underlying_type_t<E>
>(e);
88template <Enumeration E>
95template <Enumeration E>
96[[nodiscard]]
constexpr bool IsEnumerator(E e)
noexcept {
97 return static_cast<uint32_t
>(ToUnderlying(e)) <=
98 static_cast<uint32_t
>(ToUnderlying(EnumLast<E>::kValue));
106template <
typename Reg, u
int32_t Shift, u
int32_t W
idth>
107 requires std::unsigned_integral<Reg> && (Width > 0U) && (Width < 32U) &&
108 ((
Shift + Width) <=
static_cast<uint32_t
>(std::numeric_limits<Reg>::digits))
111 static constexpr uint32_t kMax = (uint32_t{1} << Width) - 1U;
113 static constexpr Reg kMask =
static_cast<Reg
>(kMax <<
Shift);
116 [[nodiscard]]
static constexpr Reg Insert(Reg reg, uint32_t value)
noexcept {
117 return static_cast<Reg
>((
static_cast<uint32_t
>(reg) & ~
static_cast<uint32_t
>(kMask)) |
118 ((value & kMax) <<
Shift));
121 [[nodiscard]]
static constexpr uint32_t Extract(Reg reg)
noexcept {
122 return (
static_cast<uint32_t
>(reg) >> Shift) & kMax;
detail::Field< uint32_t, 16U, 3U > Shift
Bits 18:16, RW: the manual's SHIFT.
Definition tmc9660_registers.hpp:1834