diff --git a/firmware/application/max2837.cpp b/firmware/application/max2837.cpp index e1c759c2..33e4a8b6 100644 --- a/firmware/application/max2837.cpp +++ b/firmware/application/max2837.cpp @@ -40,7 +40,7 @@ constexpr std::array lookup_8db_steps { }; static uint_fast8_t gain_ordinal(const int8_t db) { - int8_t db_sat = std::min(std::max(gain_db_min, db), gain_db_max); + const auto db_sat = gain_db_range.clip(db); return lna::lookup_8db_steps[(db_sat >> 3) & 7]; } @@ -49,7 +49,7 @@ static uint_fast8_t gain_ordinal(const int8_t db) { namespace vga { static uint_fast8_t gain_ordinal(const int8_t db) { - int8_t db_sat = std::min(std::max(gain_db_min, db), gain_db_max); + const auto db_sat = gain_db_range.clip(db); return ((db_sat >> 1) & 0b11111) ^ 0b11111; } diff --git a/firmware/application/max2837.hpp b/firmware/application/max2837.hpp index 43ffe8b2..6c91ae58 100644 --- a/firmware/application/max2837.hpp +++ b/firmware/application/max2837.hpp @@ -62,8 +62,7 @@ constexpr std::array band { { namespace lna { -constexpr int8_t gain_db_min = 0; -constexpr int8_t gain_db_max = 40; +constexpr range_t gain_db_range { 0, 40 }; constexpr int8_t gain_db_step = 8; constexpr std::array band { { @@ -77,8 +76,7 @@ constexpr std::array band { { namespace vga { -constexpr int8_t gain_db_min = 0; -constexpr int8_t gain_db_max = 62; +constexpr range_t gain_db_range { 0, 62 }; constexpr int8_t gain_db_step = 2; } /* namespace vga */ diff --git a/firmware/application/ui_receiver.cpp b/firmware/application/ui_receiver.cpp index e45c720e..87c26527 100644 --- a/firmware/application/ui_receiver.cpp +++ b/firmware/application/ui_receiver.cpp @@ -309,7 +309,7 @@ LNAGainField::LNAGainField( Point parent_pos ) : NumberField { parent_pos, 2, - { max2837::lna::gain_db_min, max2837::lna::gain_db_max }, + { max2837::lna::gain_db_range.minimum, max2837::lna::gain_db_range.maximum }, max2837::lna::gain_db_step, ' ', } diff --git a/firmware/application/ui_receiver.hpp b/firmware/application/ui_receiver.hpp index 78046e76..dac6a028 100644 --- a/firmware/application/ui_receiver.hpp +++ b/firmware/application/ui_receiver.hpp @@ -366,7 +366,7 @@ private: NumberField field_vga { { 18 * 8, 0 * 16}, 2, - { max2837::vga::gain_db_min, max2837::vga::gain_db_max }, + { max2837::vga::gain_db_range.minimum, max2837::vga::gain_db_range.maximum }, max2837::vga::gain_db_step, ' ', };