9#include "../microfmt.hpp"
24 microfmt::string_view name{};
29 uint32_t raw_value{0};
30 span<const bit_field> fields{};
31 microfmt::string_view separator{
" | "};
32 bool show_raw_hex{
true};
36[[nodiscard]]
constexpr bitfield_view bits(uint32_t raw_val, span<const bit_field> fields,
bool show_raw_hex =
true,
37 microfmt::string_view sep =
" | ") noexcept {
47#if MICROFMT_SHARED_PROVIDE_DEFINITIONS
48#include "bitfield.ipp"
56#define MICROFMT_BIT_FLAG(pos, name) \
57 ::microfmt::bit_field { (1u << (pos)), static_cast<uint8_t>(pos), (name), ::microfmt::bit_type::flag }
60#define MICROFMT_BIT_VALUE_DEC(mask, shift, name) \
61 ::microfmt::bit_field { (mask), static_cast<uint8_t>(shift), (name), ::microfmt::bit_type::value_dec }
63#define MICROFMT_BIT_VALUE_HEX(mask, shift, name) \
64 ::microfmt::bit_field { (mask), static_cast<uint8_t>(shift), (name), ::microfmt::bit_type::value_hex }
70#define MICROFMT_DEFINE_REGISTER_TYPE(TypeName, UnderlyingType, ...) \
72 UnderlyingType value{0}; \
74 constexpr TypeName() noexcept = default; \
75 constexpr TypeName(UnderlyingType v) noexcept : value(v) {} \
76 constexpr explicit operator UnderlyingType() const noexcept { return value; } \
78 static constexpr ::microfmt::bit_field fields[] = {__VA_ARGS__}; \
81 template <> struct microfmt::formatter<TypeName> { \
82 constexpr void parse(::microfmt::format_parse_context &) noexcept {} \
83 void format(const TypeName ®, const ::microfmt::sink &out) const noexcept { \
84 ::microfmt::formatter<::microfmt::bitfield_view> f; \
85 f.format(::microfmt::bits(static_cast<uint32_t>(reg.value), ::microfmt::span(TypeName::fields)), out); \
Definition microfmt.hpp:881
#define MICROFMT_API_CLASS
Definition compat.hpp:181
#define MICROFMT_API
Definition compat.hpp:135
reloco::sink sink
Type-erased, zero-allocation output sink.
Definition microfmt.hpp:46
constexpr bitfield_view bits(uint32_t raw_val, span< const bit_field > fields, bool show_raw_hex=true, microfmt::string_view sep=" | ") noexcept
Definition bitfield.hpp:36
bit_type
Definition bitfield.hpp:15
Definition bitfield.hpp:21
Definition bitfield.hpp:28