diff --git a/Chapter12/cpp_hal/app/src/main_timer_peripheral.cpp b/Chapter12/cpp_hal/app/src/main_timer_peripheral.cpp index 3c4a3f0..bc810c0 100644 --- a/Chapter12/cpp_hal/app/src/main_timer_peripheral.cpp +++ b/Chapter12/cpp_hal/app/src/main_timer_peripheral.cpp @@ -59,6 +59,37 @@ struct timer3_traits { constexpr static std::uint32_t arr_bit_mask = 0xFFFF; }; +template +struct reg_bits { + using reg = Reg; + using T = reg::RegType; + + static_assert(std::is_same_v); + + static constexpr T c_position = Pos; + static constexpr T c_mask = (Mask << c_position); + + static_assert(Bits <= Mask); + + enum class value : T { + val = Bits + }; +}; + +template +struct reg_bits_enable_disable { + using reg = Reg; + using T = reg::RegType; + + static constexpr T c_position = Pos; + static constexpr T c_mask = (0x1UL << c_position); + + enum class value : T { + disable = 0, + enable = 1 + }; +}; + template struct timer { constexpr static std::uintptr_t base_address = TimerTraits::base_address; @@ -69,37 +100,6 @@ struct timer { using psc = reg; using arr = reg; - template - struct reg_bits { - using reg = Reg; - using T = reg::RegType; - - static_assert(std::is_same_v); - - static constexpr T c_position = Pos; - static constexpr T c_mask = (Mask << c_position); - - static_assert(Bits <= Mask); - - enum class value : T { - val = Bits - }; - }; - - template - struct reg_bits_enable_disable { - using reg = Reg; - using T = reg::RegType; - - static constexpr T c_position = Pos; - static constexpr T c_mask = (0x1UL << c_position); - - enum class value : T { - disable = 0, - enable = 1 - }; - }; - template using psc_bits = reg_bits(0xFFFF)>;