From 45a1ccbc53fa951331dd83acd19cca8b7d330b61 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 3 Aug 2016 16:12:01 -0700 Subject: [PATCH] Correctly map TX gain from dB to register value. --- firmware/application/max2837.cpp | 16 ++++++++++++++-- firmware/application/max2837.hpp | 10 +++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/firmware/application/max2837.cpp b/firmware/application/max2837.cpp index 33e4a8b60..4db7bf923 100644 --- a/firmware/application/max2837.cpp +++ b/firmware/application/max2837.cpp @@ -55,6 +55,18 @@ static uint_fast8_t gain_ordinal(const int8_t db) { } /* namespace vga */ +namespace tx { + +static uint_fast8_t gain_ordinal(const int8_t db) { + const auto db_sat = gain_db_range.clip(db); + uint8_t value = db_sat & 0x0f; + value = (db_sat >= 16) ? (value | 0x20) : value; + value = (db_sat >= 32) ? (value | 0x10) : value; + return (value & 0b111111) ^ 0b111111; +} + +} /* namespace tx */ + namespace filter { static uint_fast8_t bandwidth_ordinal(const uint32_t bandwidth) { @@ -170,8 +182,8 @@ reg_t MAX2837::read(const Register reg) { return read(toUType(reg)); } -void MAX2837::set_tx_vga_gain(const int_fast8_t value) { - _map.r.tx_gain.TXVGA_GAIN_SPI = value; +void MAX2837::set_tx_vga_gain(const int_fast8_t db) { + _map.r.tx_gain.TXVGA_GAIN_SPI = tx::gain_ordinal(db); _dirty[Register::TX_GAIN] = 1; flush(); } diff --git a/firmware/application/max2837.hpp b/firmware/application/max2837.hpp index 6c91ae58d..857bb4e9b 100644 --- a/firmware/application/max2837.hpp +++ b/firmware/application/max2837.hpp @@ -83,6 +83,14 @@ constexpr int8_t gain_db_step = 2; /*************************************************************************/ +namespace tx { + +constexpr range_t gain_db_range { 0, 47 }; +constexpr int8_t gain_db_step = 1; +} + +/*************************************************************************/ + namespace filter { constexpr std::array bandwidths { @@ -829,7 +837,7 @@ public: void init(); void set_mode(const Mode mode); - void set_tx_vga_gain(const int_fast8_t value); + void set_tx_vga_gain(const int_fast8_t db); void set_lna_gain(const int_fast8_t db); void set_vga_gain(const int_fast8_t db); void set_lpf_rf_bandwidth(const uint32_t bandwidth_minimum);