diff --git a/Makefile b/Makefile index cdd5b5b13..bbfb98338 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,6 @@ ENABLE_PWRON_PASSWORD := 0 ENABLE_DTMF_CALLING := 0 #---- DEBUG ---- -ENABLE_AM_FIX_SHOW_DATA := 0 ENABLE_ULTRA_LOW_POWER_TX := 0 # ---- CUSTOM MODS ---- @@ -37,7 +36,6 @@ ENABLE_BOOT_BEEPS := 0 ENABLE_SHOW_CHARGE_LEVEL := 1 ENABLE_REVERSE_BAT_SYMBOL := 0 ENABLE_NO_CODE_SCAN_TIMEOUT := 1 -ENABLE_AM_FIX := 1 ENABLE_SQUELCH_MORE_SENSITIVE := 0 ENABLE_FASTER_CHANNEL_SCAN := 1 ENABLE_RSSI_BAR := 1 @@ -130,9 +128,6 @@ OBJS += app/scanner.o ifeq ($(ENABLE_UART),1) OBJS += app/uart.o endif -ifeq ($(ENABLE_AM_FIX), 1) - OBJS += am_fix.o -endif OBJS += audio.o OBJS += bitmaps.o OBJS += board.o @@ -320,12 +315,6 @@ endif ifeq ($(ENABLE_NO_CODE_SCAN_TIMEOUT),1) CFLAGS += -DENABLE_CODE_SCAN_TIMEOUT endif -ifeq ($(ENABLE_AM_FIX),1) - CFLAGS += -DENABLE_AM_FIX -endif -ifeq ($(ENABLE_AM_FIX_SHOW_DATA),1) - CFLAGS += -DENABLE_AM_FIX_SHOW_DATA -endif ifeq ($(ENABLE_SQUELCH_MORE_SENSITIVE),1) CFLAGS += -DENABLE_SQUELCH_MORE_SENSITIVE endif diff --git a/README.md b/README.md index 524110dcb..28d3d58e5 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Anyway, have fun. * `ENABLE_ADJUSTABLE_RX_GAIN_SETTINGS` keeps the rx gain settings set in spectrum mode after exit (otherwise these are always overwritten to default value), this makes much more sense considering that we have a radio with user adjustable gain so why not use it to adjust to current radio conditions, maximum gain allows to greatly increase reception in scan memory channels mode (in this configuration default gain settings are only set at boot and when exiting AM modulation mode to set it to sane value after am fix) * `ENABLE_SPECTRUM_CHANNEL_SCAN` this enables spectrum channel scan mode (enter by going into memory mode and press F+5, this allows SUPER fast channel scanning (4.5x faster than regular scanning), regular scan of 200 memory channels takes roughly 18 seconds, spectrum memory scan takes roughly 4 seconds, if you have less channels stored i.e 50 - the spectrum memory scan will take only **1 second** * `VOXSen` fixed and improved VOX sensitivity setting from menu. Added `VoxDel` - VOX delay setting allowing to set value to `0` for no VOX delay which might be useful for packet radio enthusiasts (APRS etc.). + * Fixed AM AGC so **AM demodulation is crystal clear**, no audible clicks, no need for `AM_FIX`. ## Keyboard shortcuts * In `VFO mode` long press `5` to enter `scan range mode` @@ -133,8 +134,6 @@ ENABLE_BOOT_BEEPS := 0 gives user audio feedback on volum ENABLE_SHOW_CHARGE_LEVEL := 1 show the charge level when the radio is on charge ENABLE_REVERSE_BAT_SYMBOL := 0 mirror the battery symbol on the status bar (+ pole on the right) ENABLE_NO_CODE_SCAN_TIMEOUT := 1 disable 32-sec CTCSS/DCS scan timeout (press exit butt instead of time-out to end scan) -ENABLE_AM_FIX := 1 dynamically adjust the front end gains when in AM mode to help prevent AM demodulator saturation, ignore the on-screen RSSI level (for now) -ENABLE_AM_FIX_SHOW_DATA := 0 show debug data for the AM fix ENABLE_SQUELCH_MORE_SENSITIVE := 0 make squelch levels a little bit more sensitive - this has been reported to cause radio freeze in presence of strong signals ENABLE_FASTER_CHANNEL_SCAN := 1 increases the channel scan speed, but the squelch is also made more twitchy ENABLE_RSSI_BAR := 1 enable a dBm/Sn RSSI bar graph level in place of the little antenna symbols @@ -236,9 +235,3 @@ You may obtain a copy of the License at

- -Video showing the AM fix working .. - - - - diff --git a/am_fix.c b/am_fix.c deleted file mode 100644 index bfde70d7c..000000000 --- a/am_fix.c +++ /dev/null @@ -1,399 +0,0 @@ - -/* Copyright 2023 OneOfEleven - * https://github.com/DualTachyon - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// code to 'try' and reduce the AM demodulator saturation problem -// -// that is until someone works out how to properly configure the BK chip ! - -#include - -#include "am_fix.h" -#include "app/main.h" -#include "board.h" -#include "driver/bk4819.h" -#include "external/printf/printf.h" -#include "frequencies.h" -#include "functions.h" -#include "misc.h" - -#ifdef ENABLE_AM_FIX - -typedef struct -{ - uint16_t reg_val; - int8_t gain_dB; -} __attribute__((packed)) t_gain_table; - -// REG_10 AGC gain table -// -// <15:10> ??? -// -// <9:8> = LNA Gain Short -// 3 = 0dB < original value -// 2 = -24dB // was -11 -// 1 = -30dB // was -16 -// 0 = -33dB // was -19 -// -// <7:5> = LNA Gain -// 7 = 0dB -// 6 = -2dB -// 5 = -4dB < original value -// 4 = -6dB -// 3 = -9dB -// 2 = -14dB -// 1 = -19dB -// 0 = -24dB -// -// <4:3> = MIXER Gain -// 3 = 0dB < original value -// 2 = -3dB -// 1 = -6dB -// 0 = -8dB -// -// <2:0> = PGA Gain -// 7 = 0dB -// 6 = -3dB < original value -// 5 = -6dB -// 4 = -9dB -// 3 = -15dB -// 2 = -21dB -// 1 = -27dB -// 0 = -33dB - -// front end register dB values -// -// these values need to be accurate for the code to properly/reliably switch -// between table entries when adjusting the front end registers. -// -// these 4 tables need a measuring/calibration update -// -// -// QUESTION: why do I have to surround the negative numbers in brackets ??? -// if I don't add the brackets, reading the table returns unexpected/different values !!! -// -// -//// static const int16_t lna_short_dB[] = { -19, -16, -11, 0}; // was (but wrong) -// static const int16_t lna_short_dB[] = { (-33), (-30), (-24), 0}; // corrected'ish -// static const int16_t lna_dB[] = { (-24), (-19), (-14), ( -9), (-6), (-4), (-2), 0}; -// static const int16_t mixer_dB[] = { ( -8), ( -6), ( -3), 0}; -// static const int16_t pga_dB[] = { (-33), (-27), (-21), (-15), (-9), (-6), (-3), 0}; - -// lookup table is hugely easier than writing code to do the same -// -static const t_gain_table gain_table[] = -{ - {0x035E, -17}, // 0 .. 3 2 3 6 .. 0dB -14dB 0dB -3dB .. -17dB original - - {0x0000, -98}, // 1 .. 0 0 0 0 .. -33dB -24dB -8dB -33dB .. -98dB - {0x0008, -96}, // 2 .. 0 0 1 0 .. -33dB -24dB -6dB -33dB .. -96dB - {0x0100, -95}, // 3 .. 1 0 0 0 .. -30dB -24dB -8dB -33dB .. -95dB - {0x0020, -93}, // 4 .. 0 1 0 0 .. -33dB -19dB -8dB -33dB .. -93dB - {0x0001, -92}, // 5 .. 0 0 0 1 .. -33dB -24dB -8dB -27dB .. -92dB - {0x0028, -91}, // 6 .. 0 1 1 0 .. -33dB -19dB -6dB -33dB .. -91dB - {0x0009, -90}, // 7 .. 0 0 1 1 .. -33dB -24dB -6dB -27dB .. -90dB - {0x0101, -89}, // 8 .. 1 0 0 1 .. -30dB -24dB -8dB -27dB .. -89dB - {0x0030, -88}, // 9 .. 0 1 2 0 .. -33dB -19dB -3dB -33dB .. -88dB - {0x0118, -87}, // 10 .. 1 0 3 0 .. -30dB -24dB 0dB -33dB .. -87dB - {0x0002, -86}, // 11 .. 0 0 0 2 .. -33dB -24dB -8dB -21dB .. -86dB - {0x0130, -85}, // 12 .. 1 1 2 0 .. -30dB -19dB -3dB -33dB .. -85dB - {0x0019, -84}, // 13 .. 0 0 3 1 .. -33dB -24dB 0dB -27dB .. -84dB - {0x0060, -83}, // 14 .. 0 3 0 0 .. -33dB -9dB -8dB -33dB .. -83dB - {0x0138, -82}, // 15 .. 1 1 3 0 .. -30dB -19dB 0dB -33dB .. -82dB - {0x0119, -81}, // 16 .. 1 0 3 1 .. -30dB -24dB 0dB -27dB .. -81dB - {0x0058, -80}, // 17 .. 0 2 3 0 .. -33dB -14dB 0dB -33dB .. -80dB - {0x0141, -79}, // 18 .. 1 2 0 1 .. -30dB -14dB -8dB -27dB .. -79dB - {0x0070, -78}, // 19 .. 0 3 2 0 .. -33dB -9dB -3dB -33dB .. -78dB - {0x0180, -77}, // 20 .. 1 4 0 0 .. -30dB -6dB -8dB -33dB .. -77dB - {0x0139, -76}, // 21 .. 1 1 3 1 .. -30dB -19dB 0dB -27dB .. -76dB - {0x0013, -75}, // 22 .. 0 0 2 3 .. -33dB -24dB -3dB -15dB .. -75dB - {0x0161, -74}, // 23 .. 1 3 0 1 .. -30dB -9dB -8dB -27dB .. -74dB - {0x01C0, -73}, // 24 .. 1 6 0 0 .. -30dB -2dB -8dB -33dB .. -73dB - {0x00E8, -72}, // 25 .. 0 7 1 0 .. -33dB 0dB -6dB -33dB .. -72dB - {0x00D0, -71}, // 26 .. 0 6 2 0 .. -33dB -2dB -3dB -33dB .. -71dB - {0x0239, -70}, // 27 .. 2 1 3 1 .. -24dB -19dB 0dB -27dB .. -70dB - {0x006A, -69}, // 28 .. 0 3 1 2 .. -33dB -9dB -6dB -21dB .. -69dB - {0x0006, -68}, // 29 .. 0 0 0 6 .. -33dB -24dB -8dB -3dB .. -68dB - {0x00B1, -67}, // 30 .. 0 5 2 1 .. -33dB -4dB -3dB -27dB .. -67dB - {0x000E, -66}, // 31 .. 0 0 1 6 .. -33dB -24dB -6dB -3dB .. -66dB - {0x015A, -65}, // 32 .. 1 2 3 2 .. -30dB -14dB 0dB -21dB .. -65dB - {0x022B, -64}, // 33 .. 2 1 1 3 .. -24dB -19dB -6dB -15dB .. -64dB - {0x01F8, -63}, // 34 .. 1 7 3 0 .. -30dB 0dB 0dB -33dB .. -63dB - {0x0163, -62}, // 35 .. 1 3 0 3 .. -30dB -9dB -8dB -15dB .. -62dB - {0x0035, -61}, // 36 .. 0 1 2 5 .. -33dB -19dB -3dB -6dB .. -61dB - {0x0214, -60}, // 37 .. 2 0 2 4 .. -24dB -24dB -3dB -9dB .. -60dB - {0x01D9, -59}, // 38 .. 1 6 3 1 .. -30dB -2dB 0dB -27dB .. -59dB - {0x0145, -58}, // 39 .. 1 2 0 5 .. -30dB -14dB -8dB -6dB .. -58dB - {0x02A2, -57}, // 40 .. 2 5 0 2 .. -24dB -4dB -8dB -21dB .. -57dB - {0x02D1, -56}, // 41 .. 2 6 2 1 .. -24dB -2dB -3dB -27dB .. -56dB - {0x00B3, -55}, // 42 .. 0 5 2 3 .. -33dB -4dB -3dB -15dB .. -55dB - {0x0216, -54}, // 43 .. 2 0 2 6 .. -24dB -24dB -3dB -3dB .. -54dB - {0x0066, -53}, // 44 .. 0 3 0 6 .. -33dB -9dB -8dB -3dB .. -53dB - {0x00C4, -52}, // 45 .. 0 6 0 4 .. -33dB -2dB -8dB -9dB .. -52dB - {0x006E, -51}, // 46 .. 0 3 1 6 .. -33dB -9dB -6dB -3dB .. -51dB - {0x015D, -50}, // 47 .. 1 2 3 5 .. -30dB -14dB 0dB -6dB .. -50dB - {0x00AD, -49}, // 48 .. 0 5 1 5 .. -33dB -4dB -6dB -6dB .. -49dB - {0x007D, -48}, // 49 .. 0 3 3 5 .. -33dB -9dB 0dB -6dB .. -48dB - {0x00D4, -47}, // 50 .. 0 6 2 4 .. -33dB -2dB -3dB -9dB .. -47dB - {0x01B4, -46}, // 51 .. 1 5 2 4 .. -30dB -4dB -3dB -9dB .. -46dB - {0x030B, -45}, // 52 .. 3 0 1 3 .. 0dB -24dB -6dB -15dB .. -45dB - {0x00CE, -44}, // 53 .. 0 6 1 6 .. -33dB -2dB -6dB -3dB .. -44dB - {0x01B5, -43}, // 54 .. 1 5 2 5 .. -30dB -4dB -3dB -6dB .. -43dB - {0x0097, -42}, // 55 .. 0 4 2 7 .. -33dB -6dB -3dB 0dB .. -42dB - {0x0257, -41}, // 56 .. 2 2 2 7 .. -24dB -14dB -3dB 0dB .. -41dB - {0x02B4, -40}, // 57 .. 2 5 2 4 .. -24dB -4dB -3dB -9dB .. -40dB - {0x027D, -39}, // 58 .. 2 3 3 5 .. -24dB -9dB 0dB -6dB .. -39dB - {0x01DD, -38}, // 59 .. 1 6 3 5 .. -30dB -2dB 0dB -6dB .. -38dB - {0x02AE, -37}, // 60 .. 2 5 1 6 .. -24dB -4dB -6dB -3dB .. -37dB - {0x0379, -36}, // 61 .. 3 3 3 1 .. 0dB -9dB 0dB -27dB .. -36dB - {0x035A, -35}, // 62 .. 3 2 3 2 .. 0dB -14dB 0dB -21dB .. -35dB - {0x02B6, -34}, // 63 .. 2 5 2 6 .. -24dB -4dB -3dB -3dB .. -34dB - {0x030E, -33}, // 64 .. 3 0 1 6 .. 0dB -24dB -6dB -3dB .. -33dB - {0x0307, -32}, // 65 .. 3 0 0 7 .. 0dB -24dB -8dB 0dB .. -32dB - {0x02BE, -31}, // 66 .. 2 5 3 6 .. -24dB -4dB 0dB -3dB .. -31dB - {0x037A, -30}, // 67 .. 3 3 3 2 .. 0dB -9dB 0dB -21dB .. -30dB - {0x02DE, -29}, // 68 .. 2 6 3 6 .. -24dB -2dB 0dB -3dB .. -29dB - {0x0345, -28}, // 69 .. 3 2 0 5 .. 0dB -14dB -8dB -6dB .. -28dB - {0x03A3, -27}, // 70 .. 3 5 0 3 .. 0dB -4dB -8dB -15dB .. -27dB - {0x0364, -26}, // 71 .. 3 3 0 4 .. 0dB -9dB -8dB -9dB .. -26dB - {0x032F, -25}, // 72 .. 3 1 1 7 .. 0dB -19dB -6dB 0dB .. -25dB - {0x0393, -24}, // 73 .. 3 4 2 3 .. 0dB -6dB -3dB -15dB .. -24dB - {0x0384, -23}, // 74 .. 3 4 0 4 .. 0dB -6dB -8dB -9dB .. -23dB - {0x0347, -22}, // 75 .. 3 2 0 7 .. 0dB -14dB -8dB 0dB .. -22dB - {0x03EB, -21}, // 76 .. 3 7 1 3 .. 0dB 0dB -6dB -15dB .. -21dB - {0x03D3, -20}, // 77 .. 3 6 2 3 .. 0dB -2dB -3dB -15dB .. -20dB - {0x03BB, -19}, // 78 .. 3 5 3 3 .. 0dB -4dB 0dB -15dB .. -19dB - {0x037C, -18}, // 79 .. 3 3 3 4 .. 0dB -9dB 0dB -9dB .. -18dB - {0x03CC, -17}, // 80 .. 3 6 1 4 .. 0dB -2dB -6dB -9dB .. -17dB - {0x03C5, -16}, // 81 .. 3 6 0 5 .. 0dB -2dB -8dB -6dB .. -16dB - {0x03EC, -15}, // 82 .. 3 7 1 4 .. 0dB 0dB -6dB -9dB .. -15dB - {0x035F, -14}, // 83 .. 3 2 3 7 .. 0dB -14dB 0dB 0dB .. -14dB - {0x03BC, -13}, // 84 .. 3 5 3 4 .. 0dB -4dB 0dB -9dB .. -13dB - {0x038F, -12}, // 85 .. 3 4 1 7 .. 0dB -6dB -6dB 0dB .. -12dB - {0x03E6, -11}, // 86 .. 3 7 0 6 .. 0dB 0dB -8dB -3dB .. -11dB - {0x03AF, -10}, // 87 .. 3 5 1 7 .. 0dB -4dB -6dB 0dB .. -10dB - {0x03F5, -9 }, // 88 .. 3 7 2 5 .. 0dB 0dB -3dB -6dB .. -9dB - {0x03D6, -8 }, // 89 .. 3 6 2 6 .. 0dB -2dB -3dB -3dB .. -8dB - {0x03BE, -7 }, // 90 .. 3 5 3 6 .. 0dB -4dB 0dB -3dB .. -7dB original - {0x03F6, -6 }, // 91 .. 3 7 2 6 .. 0dB 0dB -3dB -3dB .. -6dB - {0x03DE, -5 }, // 92 .. 3 6 3 6 .. 0dB -2dB 0dB -3dB .. -5dB - {0x03BF, -4 }, // 93 .. 3 5 3 7 .. 0dB -4dB 0dB 0dB .. -4dB - {0x03F7, -3 }, // 94 .. 3 7 2 7 .. 0dB 0dB -3dB 0dB .. -3dB - {0x03DF, -2 }, // 95 .. 3 6 3 7 .. 0dB -2dB 0dB 0dB .. -2dB - {0x03FF, 0 }, // 96 .. 3 7 3 7 .. 0dB 0dB 0dB 0dB .. 0dB -}; - -static const unsigned int original_index = 90; - -#ifdef ENABLE_AM_FIX_SHOW_DATA - // display update rate - static const unsigned int display_update_rate = 250 / 10; // max 250ms display update rate - unsigned int counter = 0; -#endif - -unsigned int gain_table_index[2] = {original_index, original_index}; - - -// used simply to detect a changed gain setting -unsigned int gain_table_index_prev[2] = {0, 0}; - -// holds the previous RSSI level .. we do an average of old + new RSSI reading -int16_t prev_rssi[2] = {0, 0}; - -// to help reduce gain hunting, peak hold count down tick -unsigned int hold_counter[2] = {0, 0}; - -// used to correct the RSSI readings after our RF gain adjustments -int16_t rssi_gain_diff[2] = {0, 0}; - -// used to limit the max RF gain -unsigned int max_index = ARRAY_SIZE(gain_table) - 1; - -// -110dBm, any higher and the AM demodulator starts to saturate/clip/distort -const int16_t desired_rssi = (-110 + 180) * 2; - -void AM_fix_init(void) -{ // called at boot-up - for (int i = 0; i < 2; i++) { - gain_table_index[i] = original_index; // re-start with original QS setting - } - - // use the full range of available gains - max_index = ARRAY_SIZE(gain_table) - 1; -} - -void AM_fix_reset(const int vfo) -{ // reset the AM fixer upper - #ifdef ENABLE_AM_FIX_SHOW_DATA - counter = 0; - #endif - - prev_rssi[vfo] = 0; - hold_counter[vfo] = 0; - rssi_gain_diff[vfo] = 0; - gain_table_index_prev[vfo] = 0; -} - -// adjust the RX gain to try and prevent the AM demodulator from -// saturating/overloading/clipping (distorted AM audio) -// -// we're actually doing the BK4819's job for it here, but as the chip -// won't/don't do it for itself, we're left to bodging it ourself by -// playing with the RF front end gain setting -// -void AM_fix_10ms(const int vfo) -{ - int16_t diff_dB; - int16_t rssi; - - switch (gCurrentFunction) - { - case FUNCTION_TRANSMIT: - case FUNCTION_BAND_SCOPE: - case FUNCTION_POWER_SAVE: - #ifdef ENABLE_AM_FIX_SHOW_DATA - counter = display_update_rate; // queue up a display update as soon as we switch to RX mode - #endif - return; - - // only adjust stuff if we're in one of these modes - case FUNCTION_FOREGROUND: - case FUNCTION_RECEIVE: - case FUNCTION_MONITOR: - case FUNCTION_INCOMING: - break; - } - -#ifdef ENABLE_AM_FIX_SHOW_DATA - if (counter > 0) { - if (++counter >= display_update_rate) { // trigger a display update - counter = 0; - gUpdateDisplay = true; - } - } -#endif - - { // sample the current RSSI level - // average it with the previous rssi (a bit of noise/spike immunity) - const int16_t new_rssi = BK4819_GetRSSI(); - rssi = (prev_rssi[vfo] > 0) ? (prev_rssi[vfo] + new_rssi) / 2 : new_rssi; - prev_rssi[vfo] = new_rssi; - } - - // save the corrected RSSI level -#ifdef ENABLE_AM_FIX_SHOW_DATA - { - const int16_t new_rssi = rssi - rssi_gain_diff[vfo]; - if (gCurrentRSSI[vfo] != new_rssi) { - gCurrentRSSI[vfo] = new_rssi; - - if (counter == 0) { - counter = 1; - gUpdateDisplay = true; // trigger a display update - } - } - } -#else - gCurrentRSSI[vfo] = rssi; -#endif - - - // automatically adjust the RF RX gain - - // update the gain hold counter - if (hold_counter[vfo] > 0) - hold_counter[vfo]--; - - // dB difference between actual and desired RSSI level - diff_dB = (rssi - desired_rssi) / 2; - - if (diff_dB > 0) { // decrease gain - unsigned int index = gain_table_index[vfo]; // current position we're at - - if (diff_dB >= 10) { // jump immediately to a new gain setting - // this greatly speeds up initial gain reduction (but reduces noise/spike immunity) - - const int16_t desired_gain_dB = (int16_t)gain_table[index].gain_dB - diff_dB + 8; // get no closer than 8dB (bit of noise/spike immunity) - - // scan the table to see what index to jump straight too - while (index > 1) - if (gain_table[--index].gain_dB <= desired_gain_dB) - break; - } - else - { // incrementally reduce the gain .. taking it slow improves noise/spike immunity - if (index > 1) - index--; // slow step-by-step gain reduction - } - - index = (index < 1) ? 1 : (index > max_index) ? max_index : index; - - if (gain_table_index[vfo] != index) - { - gain_table_index[vfo] = index; - hold_counter[vfo] = 30; // 300ms hold - } - } - - if (diff_dB >= -6) // 6dB hysterisis (help reduce gain hunting) - hold_counter[vfo] = 30; // 300ms hold - - if (hold_counter[vfo] == 0) - { // hold has been released, we're free to increase gain - const unsigned int index = gain_table_index[vfo] + 1; // move up to next gain index - gain_table_index[vfo] = (index <= max_index) ? index : max_index; // limit the gain index - } - - - { // apply the new settings to the front end registers - - const unsigned int index = gain_table_index[vfo]; - - // remember the new table index - gain_table_index_prev[vfo] = index; - - BK4819_WriteRegister(BK4819_REG_13, gain_table[index].reg_val); - - // offset the RSSI reading to the rest of the firmware to cancel out the gain adjustments we make - - // RF gain difference from original QS setting - rssi_gain_diff[vfo] = ((int16_t)gain_table[index].gain_dB - gain_table[original_index].gain_dB) * 2; - } - - // save the corrected RSSI level - gCurrentRSSI[vfo] = rssi; - -#ifdef ENABLE_AM_FIX_SHOW_DATA - if (counter == 0) { - counter = 1; - gUpdateDisplay = true; - } -#endif -} - -#ifdef ENABLE_AM_FIX_SHOW_DATA - -void AM_fix_print_data(const int vfo, char *s) { - if (s != NULL && vfo >= 0 && vfo < (int)ARRAY_SIZE(gain_table_index)) { - const unsigned int index = gain_table_index[vfo]; - sprintf(s, "%2u %4ddB %3u", index, gain_table[index].gain_dB, prev_rssi[vfo]); - counter = 0; - } -} - -#endif - -#endif diff --git a/am_fix.h b/am_fix.h deleted file mode 100644 index 3c94d17ef..000000000 --- a/am_fix.h +++ /dev/null @@ -1,35 +0,0 @@ - -/* Copyright 2023 OneOfEleven - * https://github.com/DualTachyon - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AM_FIXH - -#include -#include - -#ifdef ENABLE_AM_FIX - extern int16_t rssi_gain_diff[2]; - - void AM_fix_init(void); - void AM_fix_reset(const int vfo); - void AM_fix_10ms(const int vfo); - #ifdef ENABLE_AM_FIX_SHOW_DATA - void AM_fix_print_data(const int vfo, char *s); - #endif - -#endif - -#endif diff --git a/app/action.c b/app/action.c index df9285c9a..3b72c3e2a 100644 --- a/app/action.c +++ b/app/action.c @@ -81,7 +81,7 @@ void ACTION_Monitor(void) gNoaaChannel = gRxVfo->CHANNEL_SAVE - NOAA_CHANNEL_FIRST; #endif RADIO_SetupRegisters(true); - APP_StartListening(FUNCTION_MONITOR, false); + APP_StartListening(FUNCTION_MONITOR); return; } @@ -301,11 +301,6 @@ void ACTION_Scan(bool bRestart) void ACTION_SwitchDemodul(void) { - #if defined(ENABLE_ADJUSTABLE_RX_GAIN_SETTINGS) && defined(ENABLE_AM_FIX) - //if we switch back from AM modulation fix set gain to default values - if(gTxVfo->Modulation==MODULATION_AM) - BK4819_SetDefaultAmplifierSettings(); - #endif gTxVfo->Modulation++; if(gTxVfo->Modulation == MODULATION_UKNOWN) gTxVfo->Modulation = MODULATION_FM; diff --git a/app/app.c b/app/app.c index a3465c919..143f11fd2 100644 --- a/app/app.c +++ b/app/app.c @@ -44,7 +44,6 @@ #include "driver/keyboard.h" #include "driver/st7565.h" #include "driver/system.h" -#include "am_fix.h" #include "dtmf.h" #include "external/printf/printf.h" #include "frequencies.h" @@ -71,12 +70,6 @@ static void UpdateRSSI(const int vfo) { int16_t rssi = BK4819_GetRSSI(); - // #ifdef ENABLE_AM_FIX - // // add RF gain adjust compensation - // if (gEeprom.VfoInfo[vfo].Modulation == MODULATION_AM && gSetting_AM_fix) - // rssi -= rssi_gain_diff[vfo]; - // #endif - if (gCurrentRSSI[vfo] == rssi) return; // no change @@ -231,7 +224,7 @@ static void HandleIncoming(void) } #endif - APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, false); + APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE); } static void HandleReceive(void) @@ -426,7 +419,7 @@ static void HandleFunction(void) } } -void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix) +void APP_StartListening(FUNCTION_Type_t Function) { const unsigned int chan = gEeprom.RX_VFO; // const unsigned int chan = gRxVfo->CHANNEL_SAVE; @@ -481,37 +474,8 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix) gUpdateStatus = true; } - { - -#ifdef ENABLE_AM_FIX - - BK4819_SetAGC(!gSetting_AM_fix); - - if (gRxVfo->Modulation == MODULATION_AM) { // AM RX mode - if(gSetting_AM_fix) - { - if (reset_am_fix) - AM_fix_reset(chan); // TODO: only reset it when moving channel/frequency - AM_fix_10ms(chan); - } - else - { - // if not getting AM fix restore gain settings to sane values after AM fix has been turned off - BK4819_SetDefaultAmplifierSettings(); - } - } - else { // FM RX mode - #ifndef ENABLE_ADJUSTABLE_RX_GAIN_SETTINGS - BK4819.BK4819_SetDefaultAmplifierSettings(); - #endif - } -#else - (void)reset_am_fix; - #ifndef ENABLE_ADJUSTABLE_RX_GAIN_SETTINGS - BK4819.BK4819_SetDefaultAmplifierSettings(); - #endif -#endif - } + BK4819_InitAGC(gEeprom.RX_AGC); + BK4819_SetAGC(gEeprom.RX_AGC!=RX_AGC_OFF); // AF gain - original QS values // if (gRxVfo->Modulation != MODULATION_FM){ @@ -1183,12 +1147,6 @@ void APP_TimeSlice10ms(void) AUDIO_PlayBeep(BEEP_880HZ_40MS_OPTIONAL); #endif - #ifdef ENABLE_AM_FIX -// if (gEeprom.VfoInfo[gEeprom.RX_VFO].Modulation != MODULATION_FM && gSetting_AM_fix) - if (gRxVfo->Modulation == MODULATION_AM && gSetting_AM_fix) - AM_fix_10ms(gEeprom.RX_VFO); - #endif - if (UART_IsCommandAvailable()) { __disable_irq(); @@ -1205,7 +1163,7 @@ void APP_TimeSlice10ms(void) if (gCurrentFunction == FUNCTION_TRANSMIT) { // transmitting #ifdef ENABLE_AUDIO_BAR - if (gSetting_mic_bar && (gFlashLightBlinkCounter % (150 / 10)) == 0) // once every 150ms + if ((gFlashLightBlinkCounter % (150 / 10)) == 0) // once every 150ms UI_DisplayAudioBar(); #endif } diff --git a/app/app.h b/app/app.h index ef3b70676..1a7da7c4a 100644 --- a/app/app.h +++ b/app/app.h @@ -24,7 +24,7 @@ #include "radio.h" void APP_EndTransmission(void); -void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix); +void APP_StartListening(FUNCTION_Type_t Function); uint32_t APP_SetFreqByStepAndLimits(VFO_Info_t *pInfo, int8_t direction, uint32_t lower, uint32_t upper); uint32_t APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t direction); void APP_Update(void); diff --git a/app/chFrScanner.c b/app/chFrScanner.c index 01b03b340..33b50dd95 100644 --- a/app/chFrScanner.c +++ b/app/chFrScanner.c @@ -72,14 +72,14 @@ void CHFRSCANNER_ContinueScanning(void) if (IS_FREQ_CHANNEL(gNextMrChannel)) { if (gCurrentFunction == FUNCTION_INCOMING) - APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true); + APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE); else NextFreqChannel(); // switch to next frequency } else { if (gCurrentCodeType == CODE_TYPE_OFF && gCurrentFunction == FUNCTION_INCOMING) - APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true); + APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE); else NextMemChannel(); // switch to next channel } diff --git a/app/menu.c b/app/menu.c index 8f2465b88..89c54b6cd 100644 --- a/app/menu.c +++ b/app/menu.c @@ -47,8 +47,6 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #endif -uint8_t gUnlockAllTxConfCnt; - #ifdef ENABLE_F_CAL_MENU void writeXtalFreqCal(const int32_t value, const bool update_eeprom) { @@ -224,12 +222,6 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax) *pMax = ARRAY_SIZE(gSubMenu_RX_TX) - 1; break; - #ifdef ENABLE_AM_FIX - case MENU_AM_FIX: - #endif - #ifdef ENABLE_AUDIO_BAR - case MENU_MIC_BAR: - #endif case MENU_BCL: case MENU_BEEP: case MENU_AUTOLK: @@ -258,6 +250,11 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax) *pMax = ARRAY_SIZE(gModulationStr) - 1; break; + case MENU_RX_AGC: + *pMin = 0; + *pMax = ARRAY_SIZE(gSubMenu_RX_AGC) - 1; + break; + case MENU_SCR: *pMin = 0; *pMax = ARRAY_SIZE(gSubMenu_SCRAMBLER) - 1; @@ -285,12 +282,6 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax) *pMax = MR_CHANNEL_LAST; break; - case MENU_SLIST1: - case MENU_SLIST2: - *pMin = -1; - *pMax = MR_CHANNEL_LAST; - break; - case MENU_SAVE: *pMin = 0; *pMax = ARRAY_SIZE(gSubMenu_SAVE) - 1; @@ -301,10 +292,6 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax) *pMax = 4; break; - case MENU_S_LIST: - *pMin = 0; - *pMax = 2; - break; #ifdef ENABLE_DTMF_CALLING case MENU_D_RSP: @@ -637,12 +624,6 @@ void MENU_AcceptSetting(void) gFlagReconfigureVfos = true; break; - #ifdef ENABLE_AUDIO_BAR - case MENU_MIC_BAR: - gSetting_mic_bar = gSubMenuSelection; - break; - #endif - case MENU_COMPAND: gTxVfo->Compander = gSubMenuSelection; SETTINGS_UpdateChannel(gTxVfo->CHANNEL_SAVE, gTxVfo, true); @@ -655,10 +636,6 @@ void MENU_AcceptSetting(void) gEeprom.CHAN_1_CALL = gSubMenuSelection; break; - case MENU_S_LIST: - gEeprom.SCAN_LIST_DEFAULT = gSubMenuSelection; - break; - #ifdef ENABLE_ALARM case MENU_AL_MOD: gEeprom.ALARM_MODE = gSubMenuSelection; @@ -735,13 +712,11 @@ void MENU_AcceptSetting(void) gRequestSaveChannel = 1; return; - #ifdef ENABLE_AM_FIX - case MENU_AM_FIX: - gSetting_AM_fix = gSubMenuSelection; - gVfoConfigureMode = VFO_CONFIGURE_RELOAD; - gFlagResetVfos = true; - break; - #endif + case MENU_RX_AGC: + gEeprom.RX_AGC = gSubMenuSelection; + gVfoConfigureMode = VFO_CONFIGURE_RELOAD; + gFlagResetVfos = true; + break; #ifdef ENABLE_NOAA case MENU_NOAA_S: @@ -765,14 +740,6 @@ void MENU_AcceptSetting(void) break; case MENU_F_LOCK: { - if(gSubMenuSelection == F_LOCK_NONE) { // select 10 times to enable - gUnlockAllTxConfCnt++; - if(gUnlockAllTxConfCnt < 10) - return; - } - else - gUnlockAllTxConfCnt = 0; - gSetting_F_LOCK = gSubMenuSelection; break; } @@ -1039,12 +1006,6 @@ void MENU_ShowCurrentSetting(void) gSubMenuSelection = gEeprom.MIC_SENSITIVITY; break; -#ifdef ENABLE_AUDIO_BAR - case MENU_MIC_BAR: - gSubMenuSelection = gSetting_mic_bar; - break; -#endif - case MENU_COMPAND: gSubMenuSelection = gTxVfo->Compander; return; @@ -1053,18 +1014,6 @@ void MENU_ShowCurrentSetting(void) gSubMenuSelection = gEeprom.CHAN_1_CALL; break; - case MENU_S_LIST: - gSubMenuSelection = gEeprom.SCAN_LIST_DEFAULT; - break; - - case MENU_SLIST1: - gSubMenuSelection = RADIO_FindNextChannel(0, 1, true, 0); - break; - - case MENU_SLIST2: - gSubMenuSelection = RADIO_FindNextChannel(0, 1, true, 1); - break; - #ifdef ENABLE_ALARM case MENU_AL_MOD: gSubMenuSelection = gEeprom.ALARM_MODE; @@ -1121,11 +1070,10 @@ void MENU_ShowCurrentSetting(void) gSubMenuSelection = gTxVfo->Modulation; break; -#ifdef ENABLE_AM_FIX - case MENU_AM_FIX: - gSubMenuSelection = gSetting_AM_fix; + case MENU_RX_AGC: + gSubMenuSelection = gEeprom.RX_AGC; break; -#endif + #ifdef ENABLE_NOAA case MENU_NOAA_S: gSubMenuSelection = gEeprom.NOAA_AUTO_SCAN; @@ -1717,13 +1665,6 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) bCheckScanList = false; break; - case MENU_SLIST2: - VFO = 1; - [[fallthrough]]; - case MENU_SLIST1: - bCheckScanList = true; - break; - default: MENU_ClampSelection(Direction); gRequestDisplayScreen = DISPLAY_MENU; diff --git a/app/menu.h b/app/menu.h index 0b8a15c55..8c46f2fc5 100644 --- a/app/menu.h +++ b/app/menu.h @@ -23,8 +23,6 @@ void writeXtalFreqCal(const int32_t value, const bool update_eeprom); #endif -extern uint8_t gUnlockAllTxConfCnt; - int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax); void MENU_AcceptSetting(void); void MENU_ShowCurrentSetting(void); diff --git a/board.c b/board.c index 8626d261b..f1c24253d 100644 --- a/board.c +++ b/board.c @@ -605,10 +605,11 @@ void BOARD_EEPROM_Init(void) memmove(&gEeprom.POWER_ON_PASSWORD, Data, 4); // 0EA0..0EA7 + EEPROM_ReadBuffer(0x0EA0, Data, 8); #ifdef ENABLE_VOX - EEPROM_ReadBuffer(0x0EA0, Data, 8); gEeprom.VOX_DELAY = (Data[0] < 11) ? Data[0] : 4; #endif + gEeprom.RX_AGC = (Data[1] < RX_AGC_LEN) ? Data[1] : RX_AGC_SLOW; // 0EA8..0EAF EEPROM_ReadBuffer(0x0EA8, Data, 8); @@ -619,7 +620,7 @@ void BOARD_EEPROM_Init(void) gEeprom.REPEATER_TAIL_TONE_ELIMINATION = (Data[2] < 11) ? Data[2] : 0; gEeprom.TX_VFO = (Data[3] < 2) ? Data[3] : 0; gEeprom.BATTERY_TYPE = (Data[4] < BATTERY_TYPE_UNKNOWN) ? Data[4] : BATTERY_TYPE_1600_MAH; - + // 0ED0..0ED7 EEPROM_ReadBuffer(0x0ED0, Data, 8); gEeprom.DTMF_SIDE_TONE = (Data[0] < 2) ? Data[0] : true; @@ -720,12 +721,6 @@ void BOARD_EEPROM_Init(void) //gSetting_TX_EN = (Data[7] & (1u << 0)) ? true : false; gSetting_live_DTMF_decoder = (Data[7] & (1u << 1)) ? true : false; gSetting_battery_text = (((Data[7] >> 2) & 3u) <= 2) ? (Data[7] >> 2) & 3 : 2; - #ifdef ENABLE_AUDIO_BAR - gSetting_mic_bar = (Data[7] & (1u << 4)) ? true : false; - #endif - #ifdef ENABLE_AM_FIX - gSetting_AM_fix = (Data[7] & (1u << 5)) ? true : false; - #endif gSetting_backlight_on_tx_rx = (Data[7] >> 6) & 3u; // Read RxOffset setting EEPROM_ReadBuffer(RX_OFFSET_ADDR, Data, 4); diff --git a/docs/UV K5 EEPROM.xlsx b/docs/UV K5 EEPROM.xlsx index 5c2ffb4c4..c037c5f19 100644 Binary files a/docs/UV K5 EEPROM.xlsx and b/docs/UV K5 EEPROM.xlsx differ diff --git a/driver/bk4819.c b/driver/bk4819.c index e80be7db7..fd0186b03 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -23,6 +23,7 @@ #include "driver/gpio.h" #include "driver/system.h" #include "driver/systick.h" +#include "settings.h" #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) @@ -55,8 +56,10 @@ void BK4819_Init(void) BK4819_WriteRegister(BK4819_REG_37, 0x1D0F); BK4819_WriteRegister(BK4819_REG_36, 0x0022); - BK4819_InitAGC(); - BK4819_SetAGC(true); + BK4819_SetDefaultAmplifierSettings(); + + BK4819_InitAGC(gEeprom.RX_AGC); + BK4819_SetAGC(gEeprom.RX_AGC!=RX_AGC_OFF); BK4819_WriteRegister(BK4819_REG_19, 0b0001000001000001); // <15> MIC AGC 1 = disable 0 = enable @@ -263,7 +266,7 @@ void BK4819_SetAGC(bool enable) // } } -void BK4819_InitAGC() +void BK4819_InitAGC(const uint8_t agcType) { // REG_10, REG_11, REG_12 REG_13, REG_14 // @@ -304,7 +307,17 @@ void BK4819_InitAGC() // 0 = -33dB // - BK4819_SetDefaultAmplifierSettings(); // 0x03BE / 000000 11 101 11 110 / -7dB + switch(agcType) + { + case RX_AGC_SLOW: + BK4819_WriteRegister(BK4819_REG_49, (0b00 << 14) | (50 << 7) | (15 << 0)); + break; + case RX_AGC_FAST: + BK4819_WriteRegister(BK4819_REG_49, (0b00 << 14) | (45 << 7) | (25 << 0)); + break; + default: + return; + } BK4819_WriteRegister(BK4819_REG_12, 0x037B); // 0x037B / 000000 11 011 11 011 / -24dB BK4819_WriteRegister(BK4819_REG_11, 0x027B); // 0x027B / 000000 10 011 11 011 / -43dB @@ -315,8 +328,8 @@ void BK4819_InitAGC() //50, 15, - SOFT - signal doesn't fall too low - works best for now //45, 25 - AGRESSIVE - lower histeresis, but volume jumps heavily, not good for music, might be good for aviation //1 << 14 - way better, seems to open squelch and match squelch as opposed to 0 - BK4819_WriteRegister(BK4819_REG_49, (0b00 << 14) | (50 << 7) | (15 << 0)); //0x2A38 / 00 1010100 0111000 / 84, 56 - BK4819_WriteRegister(BK4819_REG_7B, 0x8420); + + BK4819_WriteRegister(BK4819_REG_7B, 0x8420); // ? } diff --git a/driver/bk4819.h b/driver/bk4819.h index 511c5b725..f1f01b618 100644 --- a/driver/bk4819.h +++ b/driver/bk4819.h @@ -75,7 +75,7 @@ void BK4819_WriteU8(uint8_t Data); void BK4819_WriteU16(uint16_t Data); void BK4819_SetAGC(bool enable); -void BK4819_InitAGC(); +void BK4819_InitAGC(const uint8_t agcType); void BK4819_ToggleGpioOut(BK4819_GPIO_PIN_t Pin, bool bSet); diff --git a/frequencies.c b/frequencies.c index b582e64d5..3981338c8 100644 --- a/frequencies.c +++ b/frequencies.c @@ -207,12 +207,6 @@ int TX_freq_check(const uint32_t Frequency) case F_LOCK_ALL: break; - - case F_LOCK_NONE: - for (uint8_t i = 0; i < ARRAY_SIZE(frequencyBandTable); i++) - if (Frequency >= frequencyBandTable[i].lower && Frequency < frequencyBandTable[i].upper) - return 0; - break; } // dis-allowed TX frequency diff --git a/main.c b/main.c index c539c3a55..d1fcaaf10 100644 --- a/main.c +++ b/main.c @@ -17,9 +17,6 @@ #include #include // NULL -#ifdef ENABLE_AM_FIX - #include "am_fix.h" -#endif #include "app/app.h" #include "app/dtmf.h" #include "audio.h" @@ -79,12 +76,12 @@ void Main(void) memset(gDTMF_String, '-', sizeof(gDTMF_String)); gDTMF_String[sizeof(gDTMF_String) - 1] = 0; - BK4819_Init(); - BOARD_ADC_GetBatteryInfo(&gBatteryCurrentVoltage, &gBatteryCurrent); BOARD_EEPROM_Init(); + BK4819_Init(); + BOARD_EEPROM_LoadCalibration(); RADIO_ConfigureChannel(0, VFO_CONFIGURE_RELOAD); @@ -99,10 +96,6 @@ void Main(void) BATTERY_GetReadings(false); - #ifdef ENABLE_AM_FIX - AM_fix_init(); - #endif - BootMode = BOOT_GetMode(); if (BootMode == BOOT_MODE_F_LOCK) diff --git a/misc.c b/misc.c index 22b18bf1d..37c3d94b1 100644 --- a/misc.c +++ b/misc.c @@ -91,13 +91,6 @@ bool gSetting_ScrambleEnable; uint8_t gSetting_backlight_on_tx_rx; -#ifdef ENABLE_AM_FIX - bool gSetting_AM_fix; -#endif - -#ifdef ENABLE_AUDIO_BAR - bool gSetting_mic_bar; -#endif bool gSetting_live_DTMF_decoder; uint8_t gSetting_battery_text; diff --git a/misc.h b/misc.h index 98ef1f38f..08a901e26 100644 --- a/misc.h +++ b/misc.h @@ -159,13 +159,6 @@ extern bool gSetting_ScrambleEnable; extern uint8_t gSetting_backlight_on_tx_rx; -#ifdef ENABLE_AM_FIX - extern bool gSetting_AM_fix; -#endif - -#ifdef ENABLE_AUDIO_BAR - extern bool gSetting_mic_bar; -#endif extern bool gSetting_live_DTMF_decoder; extern uint8_t gSetting_battery_text; diff --git a/settings.c b/settings.c index dbf850d19..d502b7db7 100644 --- a/settings.c +++ b/settings.c @@ -127,11 +127,13 @@ void SETTINGS_SaveSettings(void) EEPROM_WriteBuffer(0x0E98, State, true); memset(State, 0xFF, sizeof(State)); -#ifdef ENABLE_VOX - State[0] = gEeprom.VOX_DELAY; + #ifdef ENABLE_VOX + State[0] = gEeprom.VOX_DELAY; + #endif + State[1] = gEeprom.RX_AGC; EEPROM_WriteBuffer(0x0EA0, State, true); -#endif - + + memset(State, 0xFF, sizeof(State)); #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) State[0] = gEeprom.ALARM_MODE; #else @@ -186,12 +188,6 @@ void SETTINGS_SaveSettings(void) //if (!gSetting_TX_EN) State[7] &= ~(1u << 0); if (!gSetting_live_DTMF_decoder) State[7] &= ~(1u << 1); State[7] = (State[7] & ~(3u << 2)) | ((gSetting_battery_text & 3u) << 2); - #ifdef ENABLE_AUDIO_BAR - if (!gSetting_mic_bar) State[7] &= ~(1u << 4); - #endif - #ifdef ENABLE_AM_FIX - if (!gSetting_AM_fix) State[7] &= ~(1u << 5); - #endif State[7] = (State[7] & ~(3u << 6)) | ((gSetting_backlight_on_tx_rx & 3u) << 6); EEPROM_WriteBuffer(0x0F40, State, true); diff --git a/settings.h b/settings.h index 6d0e78f7a..6b8107a50 100644 --- a/settings.h +++ b/settings.h @@ -40,8 +40,7 @@ enum { F_LOCK_GB, F_LOCK_430, F_LOCK_438, - F_LOCK_ALL, // disable TX on all frequencies - F_LOCK_NONE, // enable TX on all frequencies + F_LOCK_ALL, // disable TX on all frequencies, scanner mode F_LOCK_LEN }; @@ -75,6 +74,13 @@ enum { OUTPUT_POWER_HIGH }; +enum { + RX_AGC_OFF = 0, + RX_AGC_SLOW, + RX_AGC_FAST, + RX_AGC_LEN +}; + enum { ACTION_OPT_NONE = 0, ACTION_OPT_FLASHLIGHT, @@ -253,6 +259,7 @@ typedef struct { uint8_t BACKLIGHT_MAX; BATTERY_Type_t BATTERY_TYPE; uint32_t RX_OFFSET; + uint8_t RX_AGC; } EEPROM_Config_t; extern EEPROM_Config_t gEeprom; diff --git a/ui/main.c b/ui/main.c index 1cd3f4b8f..84f13f515 100644 --- a/ui/main.c +++ b/ui/main.c @@ -19,9 +19,6 @@ #include "app/chFrScanner.h" #include "app/dtmf.h" -#ifdef ENABLE_AM_FIX_SHOW_DATA - #include "am_fix.h" -#endif #include "bitmaps.h" #include "board.h" #include "driver/bk4819.h" @@ -100,42 +97,40 @@ unsigned int sqrt16(unsigned int value) void UI_DisplayAudioBar(void) { - if (gSetting_mic_bar) - { - if(gLowBattery && !gLowBatteryConfirmed) - return; + if(gLowBattery && !gLowBatteryConfirmed) + return; - const unsigned int line = 3; + const unsigned int line = 3; - if (gCurrentFunction != FUNCTION_TRANSMIT || - gScreenToDisplay != DISPLAY_MAIN -#ifdef ENABLE_DTMF_CALLING - || gDTMF_CallState != DTMF_CALL_STATE_NONE -#endif - ) - { - return; // screen is in use - } - -#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) + if (gCurrentFunction != FUNCTION_TRANSMIT || + gScreenToDisplay != DISPLAY_MAIN + #ifdef ENABLE_DTMF_CALLING + || gDTMF_CallState != DTMF_CALL_STATE_NONE + #endif + ) + { + return; // screen is in use + } + + #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) if (gAlarmState != ALARM_STATE_OFF) return; -#endif - const unsigned int voice_amp = BK4819_GetVoiceAmplitudeOut(); // 15:0 + #endif + const unsigned int voice_amp = BK4819_GetVoiceAmplitudeOut(); // 15:0 - // make non-linear to make more sensitive at low values - const unsigned int level = MIN(voice_amp * 8, 65535u); - const unsigned int sqrt_level = MIN(sqrt16(level), 124u); - uint8_t bars = 13 * sqrt_level / 124; + // make non-linear to make more sensitive at low values + const unsigned int level = MIN(voice_amp * 8, 65535u); + const unsigned int sqrt_level = MIN(sqrt16(level), 124u); + uint8_t bars = 13 * sqrt_level / 124; - uint8_t *p_line = gFrameBuffer[line]; - memset(p_line, 0, LCD_WIDTH); + uint8_t *p_line = gFrameBuffer[line]; + memset(p_line, 0, LCD_WIDTH); - DrawLevelBar(62, line, bars); + DrawLevelBar(62, line, bars); + + if (gCurrentFunction == FUNCTION_TRANSMIT) + ST7565_BlitFullScreen(); - if (gCurrentFunction == FUNCTION_TRANSMIT) - ST7565_BlitFullScreen(); - } } #endif @@ -661,30 +656,13 @@ void UI_DisplayMain(void) gCurrentFunction == FUNCTION_INCOMING); #ifdef ENABLE_AUDIO_BAR - if (gSetting_mic_bar && gCurrentFunction == FUNCTION_TRANSMIT) { + if (gCurrentFunction == FUNCTION_TRANSMIT) { center_line = CENTER_LINE_AUDIO_BAR; UI_DisplayAudioBar(); } else #endif -#if defined(ENABLE_AM_FIX) && defined(ENABLE_AM_FIX_SHOW_DATA) - if (rx && gEeprom.VfoInfo[gEeprom.RX_VFO].Modulation == MODULATION_AM && gSetting_AM_fix) - { - if (gScreenToDisplay != DISPLAY_MAIN -#ifdef ENABLE_DTMF_CALLING - || gDTMF_CallState != DTMF_CALL_STATE_NONE -#endif - ) - return; - - center_line = CENTER_LINE_AM_FIX_DATA; - AM_fix_print_data(gEeprom.RX_VFO, String); - UI_PrintStringSmall(String, 2, 0, 3); - } - else -#endif - #ifdef ENABLE_RSSI_BAR if (rx) { center_line = CENTER_LINE_RSSI; diff --git a/ui/main.h b/ui/main.h index 80024f92d..1ee4063cb 100644 --- a/ui/main.h +++ b/ui/main.h @@ -22,7 +22,6 @@ enum center_line_t { CENTER_LINE_IN_USE, CENTER_LINE_AUDIO_BAR, CENTER_LINE_RSSI, - CENTER_LINE_AM_FIX_DATA, CENTER_LINE_DTMF_DEC, CENTER_LINE_CHARGE_DATA }; diff --git a/ui/menu.c b/ui/menu.c index 582c6d827..50efa649c 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -53,33 +53,25 @@ const t_menu_item MenuList[] = {"BusyCL", VOICE_ID_BUSY_LOCKOUT, MENU_BCL }, // was "BCL" {"Compnd", VOICE_ID_INVALID, MENU_COMPAND }, {"Demodu", VOICE_ID_INVALID, MENU_AM }, // was "AM" + {"RxAGC", VOICE_ID_INVALID, MENU_RX_AGC }, // RX Auto Gain Control {"ScAdd1", VOICE_ID_INVALID, MENU_S_ADD1 }, {"ScAdd2", VOICE_ID_INVALID, MENU_S_ADD2 }, {"ChSave", VOICE_ID_MEMORY_CHANNEL, MENU_MEM_CH }, // was "MEM-CH" {"ChDele", VOICE_ID_DELETE_CHANNEL, MENU_DEL_CH }, // was "DEL-CH" {"ChName", VOICE_ID_INVALID, MENU_MEM_NAME }, - - {"SList", VOICE_ID_INVALID, MENU_S_LIST }, - {"SList1", VOICE_ID_INVALID, MENU_SLIST1 }, - {"SList2", VOICE_ID_INVALID, MENU_SLIST2 }, {"ScnRev", VOICE_ID_INVALID, MENU_SC_REV }, #ifdef ENABLE_NOAA {"NOAA-S", VOICE_ID_INVALID, MENU_NOAA_S }, #endif - {"F1Shrt", VOICE_ID_INVALID, MENU_F1SHRT }, {"F1Long", VOICE_ID_INVALID, MENU_F1LONG }, {"F2Shrt", VOICE_ID_INVALID, MENU_F2SHRT }, {"F2Long", VOICE_ID_INVALID, MENU_F2LONG }, {"M Long", VOICE_ID_INVALID, MENU_MLONG }, - {"KeyLck", VOICE_ID_INVALID, MENU_AUTOLK }, // was "AUTOLk" {"TxTOut", VOICE_ID_TRANSMIT_OVER_TIME, MENU_TOT }, // was "TOT" {"BatSav", VOICE_ID_SAVE_MODE, MENU_SAVE }, // was "SAVE" - {"Mic", VOICE_ID_INVALID, MENU_MIC }, -#ifdef ENABLE_AUDIO_BAR - {"MicBar", VOICE_ID_INVALID, MENU_MIC_BAR }, -#endif + {"Mic", VOICE_ID_INVALID, MENU_MIC }, {"ChDisp", VOICE_ID_INVALID, MENU_MDF }, // was "MDF" {"POnMsg", VOICE_ID_INVALID, MENU_PONMSG }, {"BatTxt", VOICE_ID_INVALID, MENU_BAT_TXT }, @@ -111,9 +103,6 @@ const t_menu_item MenuList[] = {"D List", VOICE_ID_INVALID, MENU_D_LIST }, #endif {"D Live", VOICE_ID_INVALID, MENU_D_LIVE_DEC }, // live DTMF decoder -#ifdef ENABLE_AM_FIX - {"AM Fix", VOICE_ID_INVALID, MENU_AM_FIX }, -#endif #ifdef ENABLE_VOX {"VOXSen", VOICE_ID_VOX, MENU_VOX }, // VOX Sensibility or OFF {"VOXDel", VOICE_ID_VOX, MENU_VOX_DELAY }, // VOX delay @@ -121,7 +110,6 @@ const t_menu_item MenuList[] = {"BatVol", VOICE_ID_INVALID, MENU_VOL }, // was "VOL" {"RxMode", VOICE_ID_DUAL_STANDBY, MENU_TDR }, {"Sql", VOICE_ID_SQUELCH, MENU_SQL }, - // hidden menu items from here on // enabled if pressing both the PTT and upper side button at power-on {"F Lock", VOICE_ID_INVALID, MENU_F_LOCK }, @@ -175,10 +163,17 @@ const char gSubMenu_OFF_ON[][4] = const char gSubMenu_SAVE[][4] = { "OFF", - "1:1", - "1:2", - "1:3", - "1:4" + "50%", + "67%", + "75%", + "80%" +}; + +const char gSubMenu_RX_AGC[][6] = +{ + "OFF", + "SLOW", + "FAST" }; const char gSubMenu_TOT[][7] = @@ -284,8 +279,7 @@ const char * const gSubMenu_F_LOCK[] = "GB HAM\n144-148\n430-440", "137-174\n400-430", "137-174\n400-438", - "DISABLE\nALL", - "UNLOCK\nALL", + "DISABLE\nALL" }; const char gSubMenu_BACKLIGHT[][7] = @@ -513,12 +507,6 @@ void UI_DisplayMenu(void) } break; - #ifdef ENABLE_AUDIO_BAR - case MENU_MIC_BAR: - strcpy(String, gSubMenu_OFF_ON[gSubMenuSelection]); - break; - #endif - case MENU_STEP: { uint16_t step = gStepFrequencyTable[FREQUENCY_GetStepIdxFromSortedIdx(gSubMenuSelection)]; sprintf(String, "%d.%02ukHz", step / 100, step % 100); @@ -615,6 +603,10 @@ void UI_DisplayMenu(void) case MENU_AM: strcpy(String, gModulationStr[gSubMenuSelection]); break; + + case MENU_RX_AGC: + strcpy(String, gSubMenu_RX_AGC[gSubMenuSelection]); + break; case MENU_AUTOLK: strcpy(String, (gSubMenuSelection == 0) ? "OFF" : "AUTO"); @@ -625,9 +617,6 @@ void UI_DisplayMenu(void) strcpy(String, gSubMenu_RX_TX[gSubMenuSelection]); break; - #ifdef ENABLE_AM_FIX - case MENU_AM_FIX: - #endif case MENU_BCL: case MENU_BEEP: case MENU_S_ADD1: @@ -740,13 +729,6 @@ void UI_DisplayMenu(void) sprintf(String, "%d*100ms", gSubMenuSelection); break; - case MENU_S_LIST: - if (gSubMenuSelection < 2) - sprintf(String, "LIST%u", 1 + gSubMenuSelection); - else - strcpy(String, "ALL"); - break; - #ifdef ENABLE_ALARM case MENU_AL_MOD: sprintf(String, gSubMenu_AL_MOD[gSubMenuSelection]); @@ -816,10 +798,7 @@ void UI_DisplayMenu(void) break; case MENU_F_LOCK: - if(!gIsInSubMenu && gUnlockAllTxConfCnt>0 && gUnlockAllTxConfCnt<10) - strcpy(String, "READ\nMANUAL"); - else - strcpy(String, gSubMenu_F_LOCK[gSubMenuSelection]); + strcpy(String, gSubMenu_F_LOCK[gSubMenuSelection]); break; #ifdef ENABLE_F_CAL_MENU @@ -913,53 +892,6 @@ void UI_DisplayMenu(void) } } - if (UI_MENU_GetCurrentMenuId() == MENU_SLIST1 || UI_MENU_GetCurrentMenuId() == MENU_SLIST2) - { - i = (UI_MENU_GetCurrentMenuId() == MENU_SLIST1) ? 0 : 1; - -// if (gSubMenuSelection == 0xFF) - if (gSubMenuSelection < 0) - strcpy(String, "NULL"); - else - UI_GenerateChannelStringEx(String, true, gSubMenuSelection); - -// if (gSubMenuSelection == 0xFF || !gEeprom.SCAN_LIST_ENABLED[i]) - if (gSubMenuSelection < 0 || !gEeprom.SCAN_LIST_ENABLED[i]) - { - // channel number - UI_PrintString(String, menu_item_x1, menu_item_x2, 0, 8); - - // channel name - SETTINGS_FetchChannelName(String, gSubMenuSelection); - if (String[0] == 0) - strcpy(String, "--"); - UI_PrintString(String, menu_item_x1, menu_item_x2, 2, 8); - } - else - { - // channel number - UI_PrintString(String, menu_item_x1, menu_item_x2, 0, 8); - - // channel name - SETTINGS_FetchChannelName(String, gSubMenuSelection); - if (String[0] == 0) - strcpy(String, "--"); - UI_PrintStringSmall(String, menu_item_x1, menu_item_x2, 2); - - if (IS_MR_CHANNEL(gEeprom.SCANLIST_PRIORITY_CH1[i])) - { - sprintf(String, "PRI1:%u", gEeprom.SCANLIST_PRIORITY_CH1[i] + 1); - UI_PrintString(String, menu_item_x1, menu_item_x2, 3, 8); - } - - if (IS_MR_CHANNEL(gEeprom.SCANLIST_PRIORITY_CH2[i])) - { - sprintf(String, "PRI2:%u", gEeprom.SCANLIST_PRIORITY_CH2[i] + 1); - UI_PrintString(String, menu_item_x1, menu_item_x2, 5, 8); - } - } - } - if ((UI_MENU_GetCurrentMenuId() == MENU_R_CTCS || UI_MENU_GetCurrentMenuId() == MENU_R_DCS) && gCssBackgroundScan) UI_PrintString("SCAN", menu_item_x1, menu_item_x2, 4, 8); diff --git a/ui/menu.h b/ui/menu.h index be3dccd7b..e0dc1cf56 100644 --- a/ui/menu.h +++ b/ui/menu.h @@ -70,14 +70,8 @@ enum MENU_STE, MENU_RP_STE, MENU_MIC, -#ifdef ENABLE_AUDIO_BAR - MENU_MIC_BAR, -#endif MENU_COMPAND, MENU_1_CALL, - MENU_S_LIST, - MENU_SLIST1, - MENU_SLIST2, #ifdef ENABLE_ALARM MENU_AL_MOD, #endif @@ -103,9 +97,6 @@ enum MENU_VOL, MENU_BAT_TXT, MENU_AM, -#ifdef ENABLE_AM_FIX - MENU_AM_FIX, -#endif #ifdef ENABLE_NOAA MENU_NOAA_S, #endif @@ -125,7 +116,8 @@ enum MENU_F2SHRT, MENU_F2LONG, MENU_MLONG, - MENU_BATTYP + MENU_BATTYP, + MENU_RX_AGC }; extern const uint8_t FIRST_HIDDEN_MENU_ITEM; @@ -160,6 +152,7 @@ extern const char gSubMenu_RX_TX[4][6]; extern const char gSubMenu_BAT_TXT[3][8]; extern const char gSubMenu_BATTYP[2][9]; extern const char gSubMenu_SCRAMBLER[11][7]; +extern const char gSubMenu_RX_AGC[3][6]; typedef struct {char* name; uint8_t id;} t_sidefunction; extern const uint8_t gSubMenu_SIDEFUNCTIONS_size; diff --git a/utils/main.cpp b/utils/main.cpp index ec5d917a7..960d8bc0e 100644 --- a/utils/main.cpp +++ b/utils/main.cpp @@ -234,25 +234,6 @@ void create_gain_table(const char *filename) // *************************** // save the table to a file -/* - typedef struct - { - #if 1 - // bitfields take up less flash bytes - uint8_t lna_short:2; // 0 ~ 3 - uint8_t lna:3; // 0 ~ 7 - uint8_t mixer:2; // 0 ~ 3 - uint8_t pga:3; // 0 ~ 7 - #else - uint8_t lna_short; // 0 ~ 3 - uint8_t lna; // 0 ~ 7 - uint8_t mixer; // 0 ~ 3 - uint8_t pga; // 0 ~ 7 - #endif - } t_am_fix_gain_table; - //} __attribute__((packed)) t_am_fix_gain_table; -*/ - FILE *file = fopen(filename, "w"); if (file == NULL) return;