lib: bit_ops: Allow bit_field_set() to implicitly cast value to desired type

Signed-off-by: Rick Altherr <kc8apf@kc8apf.net>
Signed-off-by: Tim 'mithro' Ansell <mithro@mithis.com>
This commit is contained in:
Rick Altherr 2017-12-13 16:38:40 -08:00 committed by Tim 'mithro' Ansell
parent 27aa3d7892
commit e85e51514d
1 changed files with 2 additions and 2 deletions

View File

@ -31,10 +31,10 @@ constexpr UInt bit_field_get(UInt value, const int top_bit, const int bottom_bit
return (value & bit_mask_range<UInt>(top_bit, bottom_bit)) >> bottom_bit;
}
template<typename UInt>
template<typename UInt, typename ValueType>
constexpr UInt bit_field_set(const UInt reg_value,
const int top_bit, const int bottom_bit,
const UInt field_value) {
const ValueType field_value) {
return ((reg_value & ~bit_mask_range<UInt>(top_bit, bottom_bit)) |
((static_cast<UInt>(field_value) << bottom_bit) &
bit_mask_range<UInt>(top_bit, bottom_bit)));