diff --git a/Makefile b/Makefile index 08b83a2..dab52ef 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ ENABLE_OVERLAY := 0 ENABLE_LTO := 1 ENABLE_UART := 1 ENABLE_AIRCOPY := 0 -ENABLE_FMRADIO := 1 +ENABLE_FMRADIO := 0 ENABLE_NOAA := 0 ENABLE_VOICE := 0 ENABLE_ALARM := 0 @@ -32,7 +32,7 @@ ENABLE_SQUELCH_MORE_SENSITIVE := 1 ENABLE_FASTER_CHANNEL_SCAN := 0 ENABLE_RSSI_BAR := 1 ENABLE_AUDIO_BAR := 1 -#ENABLE_COPY_CHAN_TO_VFO := 1 +ENABLE_COPY_CHAN_TO_VFO := 1 #ENABLE_SINGLE_VFO_CHAN := 1 #ENABLE_BAND_SCOPE := 1 diff --git a/am_fix.c b/am_fix.c index 7ea9e14..51c11ae 100644 --- a/am_fix.c +++ b/am_fix.c @@ -31,24 +31,7 @@ #include "misc.h" #ifdef ENABLE_AM_FIX -/* - 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_gain_table; - //} __attribute__((packed)) t_gain_table; -*/ + typedef struct { uint16_t reg_val; @@ -113,131 +96,130 @@ // static const t_gain_table gain_table[] = { - {0x035E, -17}, // 0 .. 0dB -14dB 0dB -3dB .. -17dB original + {0x035E, -17}, // 0 .. 3 2 3 6 .. 0dB -14dB 0dB -3dB .. -17dB original #ifdef ENABLE_AM_FIX_TEST1 // test table that lets me manually set the lna-short register // to measure it's actual dB change using an RF signal generator - {0x005E, -50}, // 1 .. -33dB -14dB 0dB -3dB .. -50dB - {0x015E, -47}, // 2 .. -30dB -14dB 0dB -3dB .. -47dB - {0x025E, -41}, // 3 .. -24dB -14dB 0dB -3dB .. -41dB - {0x035E, -17}, // 4 .. 0dB -14dB 0dB -3dB .. -17dB original + {0x005E, -50}, // 1 .. 0 2 3 6 .. -33dB -14dB 0dB -3dB .. -50dB + {0x015E, -47}, // 2 .. 1 2 3 6 .. -30dB -14dB 0dB -3dB .. -47dB + {0x025E, -41}, // 3 .. 2 2 3 6 .. -24dB -14dB 0dB -3dB .. -41dB + {0x035E, -17} // 4 .. 3 2 3 6 .. 0dB -14dB 0dB -3dB .. -17dB original }; - const unsigned int original_index = 1; + static const unsigned int original_index = 1; #else - {0x0000, -98}, // 1 .. -33dB -24dB -8dB -33dB .. -98dB - {0x0008, -96}, // 2 .. -33dB -24dB -6dB -33dB .. -96dB - {0x0100, -95}, // 3 .. -30dB -24dB -8dB -33dB .. -95dB - {0x0020, -93}, // 4 .. -33dB -19dB -8dB -33dB .. -93dB - {0x0001, -92}, // 5 .. -33dB -24dB -8dB -27dB .. -92dB - {0x0028, -91}, // 6 .. -33dB -19dB -6dB -33dB .. -91dB - {0x0009, -90}, // 7 .. -33dB -24dB -6dB -27dB .. -90dB - {0x0101, -89}, // 8 .. -30dB -24dB -8dB -27dB .. -89dB - {0x0030, -88}, // 9 .. -33dB -19dB -3dB -33dB .. -88dB - {0x0118, -87}, // 10 .. -30dB -24dB 0dB -33dB .. -87dB - {0x0002, -86}, // 11 .. -33dB -24dB -8dB -21dB .. -86dB - {0x0130, -85}, // 12 .. -30dB -19dB -3dB -33dB .. -85dB - {0x0019, -84}, // 13 .. -33dB -24dB 0dB -27dB .. -84dB - {0x0060, -83}, // 14 .. -33dB -9dB -8dB -33dB .. -83dB - {0x0138, -82}, // 15 .. -30dB -19dB 0dB -33dB .. -82dB - {0x0119, -81}, // 16 .. -30dB -24dB 0dB -27dB .. -81dB - {0x0058, -80}, // 17 .. -33dB -14dB 0dB -33dB .. -80dB - {0x0141, -79}, // 18 .. -30dB -14dB -8dB -27dB .. -79dB - {0x0070, -78}, // 19 .. -33dB -9dB -3dB -33dB .. -78dB - {0x0180, -77}, // 20 .. -30dB -6dB -8dB -33dB .. -77dB - {0x0139, -76}, // 21 .. -30dB -19dB 0dB -27dB .. -76dB - {0x0013, -75}, // 22 .. -33dB -24dB -3dB -15dB .. -75dB - {0x0161, -74}, // 23 .. -30dB -9dB -8dB -27dB .. -74dB - {0x01C0, -73}, // 24 .. -30dB -2dB -8dB -33dB .. -73dB - {0x00E8, -72}, // 25 .. -33dB 0dB -6dB -33dB .. -72dB - {0x00D0, -71}, // 26 .. -33dB -2dB -3dB -33dB .. -71dB - {0x0239, -70}, // 27 .. -24dB -19dB 0dB -27dB .. -70dB - {0x006A, -69}, // 28 .. -33dB -9dB -6dB -21dB .. -69dB - {0x0006, -68}, // 29 .. -33dB -24dB -8dB -3dB .. -68dB - {0x00B1, -67}, // 30 .. -33dB -4dB -3dB -27dB .. -67dB - {0x000E, -66}, // 31 .. -33dB -24dB -6dB -3dB .. -66dB - {0x015A, -65}, // 32 .. -30dB -14dB 0dB -21dB .. -65dB - {0x022B, -64}, // 33 .. -24dB -19dB -6dB -15dB .. -64dB - {0x01F8, -63}, // 34 .. -30dB 0dB 0dB -33dB .. -63dB - {0x0163, -62}, // 35 .. -30dB -9dB -8dB -15dB .. -62dB - {0x0035, -61}, // 36 .. -33dB -19dB -3dB -6dB .. -61dB - {0x0214, -60}, // 37 .. -24dB -24dB -3dB -9dB .. -60dB - {0x01D9, -59}, // 38 .. -30dB -2dB 0dB -27dB .. -59dB - {0x0145, -58}, // 39 .. -30dB -14dB -8dB -6dB .. -58dB - {0x02A2, -57}, // 40 .. -24dB -4dB -8dB -21dB .. -57dB - {0x02D1, -56}, // 41 .. -24dB -2dB -3dB -27dB .. -56dB - {0x00B3, -55}, // 42 .. -33dB -4dB -3dB -15dB .. -55dB - {0x0216, -54}, // 43 .. -24dB -24dB -3dB -3dB .. -54dB - {0x0066, -53}, // 44 .. -33dB -9dB -8dB -3dB .. -53dB - {0x00C4, -52}, // 45 .. -33dB -2dB -8dB -9dB .. -52dB - {0x006E, -51}, // 46 .. -33dB -9dB -6dB -3dB .. -51dB - {0x015D, -50}, // 47 .. -30dB -14dB 0dB -6dB .. -50dB - {0x00AD, -49}, // 48 .. -33dB -4dB -6dB -6dB .. -49dB - {0x007D, -48}, // 49 .. -33dB -9dB 0dB -6dB .. -48dB - {0x00D4, -47}, // 50 .. -33dB -2dB -3dB -9dB .. -47dB - {0x01B4, -46}, // 51 .. -30dB -4dB -3dB -9dB .. -46dB - {0x030B, -45}, // 52 .. 0dB -24dB -6dB -15dB .. -45dB - {0x00CE, -44}, // 53 .. -33dB -2dB -6dB -3dB .. -44dB - {0x01B5, -43}, // 54 .. -30dB -4dB -3dB -6dB .. -43dB - {0x0097, -42}, // 55 .. -33dB -6dB -3dB 0dB .. -42dB - {0x0257, -41}, // 56 .. -24dB -14dB -3dB 0dB .. -41dB - {0x02B4, -40}, // 57 .. -24dB -4dB -3dB -9dB .. -40dB - {0x027D, -39}, // 58 .. -24dB -9dB 0dB -6dB .. -39dB - {0x01DD, -38}, // 59 .. -30dB -2dB 0dB -6dB .. -38dB - {0x02AE, -37}, // 60 .. -24dB -4dB -6dB -3dB .. -37dB - {0x0379, -36}, // 61 .. 0dB -9dB 0dB -27dB .. -36dB - {0x035A, -35}, // 62 .. 0dB -14dB 0dB -21dB .. -35dB - {0x02B6, -34}, // 63 .. -24dB -4dB -3dB -3dB .. -34dB - {0x030E, -33}, // 64 .. 0dB -24dB -6dB -3dB .. -33dB - {0x0307, -32}, // 65 .. 0dB -24dB -8dB 0dB .. -32dB - {0x02BE, -31}, // 66 .. -24dB -4dB 0dB -3dB .. -31dB - {0x037A, -30}, // 67 .. 0dB -9dB 0dB -21dB .. -30dB - {0x02DE, -29}, // 68 .. -24dB -2dB 0dB -3dB .. -29dB - {0x0345, -28}, // 69 .. 0dB -14dB -8dB -6dB .. -28dB - {0x03A3, -27}, // 70 .. 0dB -4dB -8dB -15dB .. -27dB - {0x0364, -26}, // 71 .. 0dB -9dB -8dB -9dB .. -26dB - {0x032F, -25}, // 72 .. 0dB -19dB -6dB 0dB .. -25dB - {0x0393, -24}, // 73 .. 0dB -6dB -3dB -15dB .. -24dB - {0x0384, -23}, // 74 .. 0dB -6dB -8dB -9dB .. -23dB - {0x0347, -22}, // 75 .. 0dB -14dB -8dB 0dB .. -22dB - {0x03EB, -21}, // 76 .. 0dB 0dB -6dB -15dB .. -21dB - {0x03D3, -20}, // 77 .. 0dB -2dB -3dB -15dB .. -20dB - {0x03BB, -19}, // 78 .. 0dB -4dB 0dB -15dB .. -19dB - {0x037C, -18}, // 79 .. 0dB -9dB 0dB -9dB .. -18dB - {0x035E, -17}, // 80 .. 0dB -14dB 0dB -3dB .. -17dB original - {0x03C5, -16}, // 81 .. 0dB -2dB -8dB -6dB .. -16dB - {0x03EC, -15}, // 82 .. 0dB 0dB -6dB -9dB .. -15dB - {0x035F, -14}, // 83 .. 0dB -14dB 0dB 0dB .. -14dB - {0x03C6, -13}, // 84 .. 0dB -2dB -8dB -3dB .. -13dB - {0x0377, -12}, // 85 .. 0dB -9dB -3dB 0dB .. -12dB - {0x03E6, -11}, // 86 .. 0dB 0dB -8dB -3dB .. -11dB - {0x03BD, -10}, // 87 .. 0dB -4dB 0dB -6dB .. -10dB - {0x03F5, -9}, // 88 .. 0dB 0dB -3dB -6dB .. -9dB - {0x03DD, -8}, // 89 .. 0dB -2dB 0dB -6dB .. -8dB - {0x03B7, -7}, // 90 .. 0dB -4dB -3dB 0dB .. -7dB - {0x03F6, -6}, // 91 .. 0dB 0dB -3dB -3dB .. -6dB - {0x03D7, -5}, // 92 .. 0dB -2dB -3dB 0dB .. -5dB - {0x03BF, -4}, // 93 .. 0dB -4dB 0dB 0dB .. -4dB - {0x03F7, -3}, // 94 .. 0dB 0dB -3dB 0dB .. -3dB - {0x03DF, -2}, // 95 .. 0dB -2dB 0dB 0dB .. -2dB - {0x03FF, 0} // 96 .. 0dB 0dB 0dB 0dB .. 0dB + {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 + {0x035E, -17}, // 80 .. 3 2 3 6 .. 0dB -14dB 0dB -3dB .. -17dB original + {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 + {0x03C6, -13}, // 84 .. 3 6 0 6 .. 0dB -2dB -8dB -3dB .. -13dB + {0x0377, -12}, // 85 .. 3 3 2 7 .. 0dB -9dB -3dB 0dB .. -12dB + {0x03E6, -11}, // 86 .. 3 7 0 6 .. 0dB 0dB -8dB -3dB .. -11dB + {0x03BD, -10}, // 87 .. 3 5 3 5 .. 0dB -4dB 0dB -6dB .. -10dB + {0x03F5, -9}, // 88 .. 3 7 2 5 .. 0dB 0dB -3dB -6dB .. -9dB + {0x03DD, -8}, // 89 .. 3 6 3 5 .. 0dB -2dB 0dB -6dB .. -8dB + {0x03B7, -7}, // 90 .. 3 5 2 7 .. 0dB -4dB -3dB 0dB .. -7dB + {0x03F6, -6}, // 91 .. 3 7 2 6 .. 0dB 0dB -3dB -3dB .. -6dB + {0x03D7, -5}, // 92 .. 3 6 2 7 .. 0dB -2dB -3dB 0dB .. -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 }; - const unsigned int original_index = 80; + static const unsigned int original_index = 80; #endif - // total RF gain for each table index -// int8_t gain_dB[ARRAY_SIZE(gain_table)] = {0}; - - // display update rate - const unsigned int display_update_rate = 250 / 10; // max 250ms display update rate - unsigned int counter = 0; + #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 #ifdef ENABLE_AM_FIX_TEST1 // user manually sets the table index .. used to calibrate the desired dB gain table @@ -279,14 +261,7 @@ gain_table_index[i] = original_index; // re-start with original QS setting #endif } -/* - // pre-compute the total gain for each table index .. saves doing it in real time - for (i = 0; i < ARRAY_SIZE(gain_table); i++) - { - const t_gain_table gains = gain_table[i]; - gain_dB[i] = lna_short_dB[gains.lna_short] + lna_dB[gains.lna] + mixer_dB[gains.mixer] + pga_dB[gains.pga]; - } -*/ + #if 0 { // set a maximum gain to use // const int16_t max_gain_dB = gain_dB[original_index]; @@ -307,7 +282,9 @@ void AM_fix_reset(const int vfo) { // reset the AM fixer upper - counter = 0; + #ifdef ENABLE_AM_FIX_SHOW_DATA + counter = 0; + #endif prev_rssi[vfo] = 0; @@ -341,7 +318,9 @@ case FUNCTION_TRANSMIT: case FUNCTION_BAND_SCOPE: case FUNCTION_POWER_SAVE: - counter = display_update_rate; // queue up a display update as soon as we switch to RX mode + #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 @@ -352,14 +331,16 @@ break; } - if (counter > 0) - { - if (++counter >= display_update_rate) - { // trigger a display update - counter = 0; - gUpdateDisplay = true; + #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) @@ -368,11 +349,14 @@ prev_rssi[vfo] = new_rssi; } - { // save the corrected RSSI level + // 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) { // trigger a display update counter = 1; @@ -380,6 +364,9 @@ } } } + #else + gCurrentRSSI[vfo] = rssi - rssi_gain_diff[vfo]; + #endif #ifdef ENABLE_AM_FIX_TEST1 // user is manually adjusting a gain register - don't do anything automatically @@ -412,11 +399,11 @@ 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_dB[index] - diff_dB + 8; // get no closer than 8dB (bit of 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_dB[--index] <= desired_gain_dB) if (gain_table[--index].gain_dB <= desired_gain_dB) break; @@ -464,36 +451,35 @@ // remember the new table index gain_table_index_prev[vfo] = index; -// const t_gain_table gains = gain_table[index]; -// BK4819_WriteRegister(BK4819_REG_13, ((uint16_t)gains.lna_short << 8) | ((uint16_t)gains.lna << 5) | ((uint16_t)gains.mixer << 3) | ((uint16_t)gains.pga << 0)); 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_dB[index] - gain_dB[original_index]) * 2; 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 - rssi_gain_diff[vfo]; - if (counter == 0) - { - counter = 1; - gUpdateDisplay = true; - } + #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) + if (s != NULL && vfo >= 0 && vfo < ARRAY_SIZE(gain_table_index)) { const unsigned int index = gain_table_index[vfo]; -// sprintf(s, "%2u.%u %4ddB %3u", index, ARRAY_SIZE(gain_table) - 1, gain_dB[index], prev_rssi[vfo]); - sprintf(s, "%2u.%u %4ddB %3u", index, ARRAY_SIZE(gain_table) - 1, gain_table[index].gain_dB, prev_rssi[vfo]); +// sprintf(s, "%2u.%u %4ddB %3u", index, ARRAY_SIZE(gain_table) - 1, gain_table[index].gain_dB, prev_rssi[vfo]); + sprintf(s, "%2u %4ddB %3u", index, gain_table[index].gain_dB, prev_rssi[vfo]); counter = 0; } } diff --git a/app/app.c b/app/app.c index 90600e7..395d331 100644 --- a/app/app.c +++ b/app/app.c @@ -519,6 +519,7 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix) gRxVfo->pRX->Frequency = NoaaFrequencyTable[gNoaaChannel]; gRxVfo->pTX->Frequency = NoaaFrequencyTable[gNoaaChannel]; gEeprom.ScreenChannel[chan] = gRxVfo->CHANNEL_SAVE; + gNOAA_Countdown_10ms = 500; // 5 sec gScheduleNOAA = false; } @@ -630,7 +631,7 @@ static void FREQ_NextChannel(void) RADIO_SetupRegisters(true); // ScanPauseDelayIn_10ms = scan_pause_delay_in_6_10ms; - ScanPauseDelayIn_10ms = 10; // 100ms + ScanPauseDelayIn_10ms = 10; // 100ms .. it don't like any faster :( bScanKeepFrequency = false; gUpdateDisplay = true; @@ -671,9 +672,7 @@ static void MR_NextChannel(void) // if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) { // chan = (gEeprom.RX_CHANNEL + 1) & 1u; -// chan = gEeprom.MrChannel[chan]; // chan = gEeprom.ScreenChannel[chan]; -// chan = gEeprom.VfoInfo[chan].CHANNEL_SAVE; // chan = 14; // if (RADIO_CheckValidChannel(chan, false, 0)) // { @@ -1214,7 +1213,9 @@ void APP_Update(void) if (gEeprom.VOX_SWITCH) BK4819_EnableVox(gEeprom.VOX1_THRESHOLD, gEeprom.VOX0_THRESHOLD); - if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF) + if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && + gScanState == SCAN_OFF && + gCssScanMode == CSS_SCAN_MODE_OFF) { // dual watch mode, toggle between the two VFO's DUALWATCH_Alternate(); diff --git a/app/main.c b/app/main.c index 7b275b0..e617c92 100644 --- a/app/main.c +++ b/app/main.c @@ -25,6 +25,7 @@ #include "app/main.h" #include "app/scanner.h" #include "audio.h" +#include "board.h" #include "driver/bk4819.h" #include "dtmf.h" #include "frequencies.h" @@ -98,11 +99,11 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) if (gEeprom.DUAL_WATCH == DUAL_WATCH_CHAN_B) gEeprom.DUAL_WATCH = DUAL_WATCH_CHAN_A; else - gEeprom.TX_CHANNEL = (Vfo == 0); + gEeprom.TX_CHANNEL = (Vfo + 1) & 1u; gRequestSaveSettings = 1; gFlagReconfigureVfos = true; - + gRequestDisplayScreen = DISPLAY_MAIN; if (beep) @@ -120,7 +121,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) uint8_t Channel; if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) - { + { // swap to frequency mode gEeprom.ScreenChannel[Vfo] = gEeprom.FreqChannel[gEeprom.TX_CHANNEL]; #ifdef ENABLE_VOICE gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE; @@ -132,7 +133,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) Channel = RADIO_FindNextChannel(gEeprom.MrChannel[gEeprom.TX_CHANNEL], 1, false, 0); if (Channel != 0xFF) - { + { // swap to channel mode gEeprom.ScreenChannel[Vfo] = Channel; #ifdef ENABLE_VOICE AUDIO_SetVoiceID(0, VOICE_ID_CHANNEL_MODE); @@ -298,7 +299,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) { // user is entering channel number - + uint16_t Channel; if (gInputBoxIndex != 3) @@ -337,7 +338,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) // #endif if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE)) { // user is entering frequency - + uint32_t Frequency; if (gInputBoxIndex < 6) @@ -369,7 +370,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { Frequency = frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper; } - + { const FREQUENCY_Band_t band = FREQUENCY_GetBand(Frequency); @@ -382,35 +383,35 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gTxVfo->Band = band; gEeprom.ScreenChannel[Vfo] = band + FREQ_CHANNEL_FIRST; gEeprom.FreqChannel[Vfo] = band + FREQ_CHANNEL_FIRST; - + SETTINGS_SaveVfoIndices(); - + RADIO_ConfigureChannel(Vfo, VFO_CONFIGURE_RELOAD); } - + // Frequency += 75; // is this meant to be rounding ? Frequency += gTxVfo->StepFrequency / 2; // no idea, but this is - + Frequency = FREQUENCY_FloorToStep(Frequency, gTxVfo->StepFrequency, frequencyBandTable[gTxVfo->Band].lower); - + if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower) { // clamp the frequency to the limit const uint32_t center = (BX4819_band1.upper + BX4819_band2.lower) / 2; Frequency = (Frequency < center) ? BX4819_band1.upper - gTxVfo->StepFrequency : BX4819_band2.lower; } - + gTxVfo->freq_config_RX.Frequency = Frequency; - + gRequestSaveChannel = 1; return; } - + } #ifdef ENABLE_NOAA else if (IS_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) { // user is entering NOAA channel - + uint8_t Channel; if (gInputBoxIndex != 2) @@ -523,7 +524,8 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) { // menu key held down (long press) if (bKeyPressed) - { + { // long press MENU key + if (gScreenToDisplay == DISPLAY_MAIN) { if (gInputBoxIndex > 0) @@ -535,34 +537,28 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) gWasFKeyPressed = false; gUpdateStatus = true; - - - // TODO: long press M-key - - - #ifdef ENABLE_COPY_CHAN_TO_VFO + if (gEeprom.VFO_OPEN && + gEeprom.DUAL_WATCH == DUAL_WATCH_OFF && + gScanState == SCAN_OFF && + gCssScanMode == CSS_SCAN_MODE_OFF) { // copy channel to VFO + int channel = -1; int vfo = -1; - //int selected = -1; - if (IS_FREQ_CHANNEL(gRxVfo->CHANNEL_SAVE)) - { // VFO mode - if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) - { // other VFO is in channel mode - channel = gTxVfo->CHANNEL_SAVE; - vfo = gRxVfo->CHANNEL_SAVE; - } + if (IS_FREQ_CHANNEL(gEeprom.ScreenChannel[0]) && + IS_MR_CHANNEL(gEeprom.ScreenChannel[1])) + { + channel = gEeprom.ScreenChannel[1]; + vfo = 0; } else - if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE)) - { // VFO mode - if (IS_MR_CHANNEL(gRxVfo->CHANNEL_SAVE)) - { // other VFO is in channel mode - channel = gRxVfo->CHANNEL_SAVE; - vfo = gTxVfo->CHANNEL_SAVE; - } + if (IS_FREQ_CHANNEL(gEeprom.ScreenChannel[1]) && + IS_MR_CHANNEL(gEeprom.ScreenChannel[0])) + { + channel = gEeprom.ScreenChannel[0]; + vfo = 1; } if (channel >= 0 && vfo >= 0) @@ -570,15 +566,29 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; + gEeprom.MrChannel[vfo] = channel; + gEeprom.ScreenChannel[vfo] = channel; + RADIO_ConfigureChannel(vfo, VFO_CONFIGURE_RELOAD); - // TODO: finish this + channel = FREQ_CHANNEL_FIRST + gEeprom.VfoInfo[vfo].Band; + gEeprom.MrChannel[vfo] = channel; + gEeprom.ScreenChannel[vfo] = channel; + gEeprom.VfoInfo[vfo].CHANNEL_SAVE = channel; - //gEeprom.RX_CHANNEL = () & 1; // swap to the VFO + // swap to the VFO + gEeprom.TX_CHANNEL = vfo; + gEeprom.RX_CHANNEL = vfo; + RADIO_SelectVfos(); + RADIO_ApplyOffset(gRxVfo); + RADIO_ConfigureSquelchAndOutputPower(gRxVfo); -// gRequestSaveVFO = true; -// gVfoConfigureMode = VFO_CONFIGURE_RELOAD; -// gRequestDisplayScreen = DISPLAY_MAIN; + RADIO_SetupRegisters(true); + +// SETTINGS_SaveChannel(gRxVfo->CHANNEL_SAVE, gEeprom.RX_CHANNEL, gRxVfo, 1); + + gUpdateStatus = true; + gUpdateDisplay = true; } } #endif @@ -595,7 +605,7 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) gInputBoxIndex = 0; gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - + if (bFlag) { gFlagRefreshSetting = true; @@ -646,7 +656,7 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld) gDTMF_InputMode = true; memmove(gDTMF_InputBox, gDTMF_String, sizeof(gDTMF_InputBox)); gDTMF_InputIndex = 0; - + gRequestDisplayScreen = DISPLAY_MAIN; return; } @@ -741,7 +751,7 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) } gTxVfo->freq_config_RX.Frequency = frequency; - + gRequestSaveChannel = 1; return; } diff --git a/firmware.bin b/firmware.bin index b0b7516..f45bd03 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index 2530583..f03947a 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/radio.c b/radio.c index 22c67e7..cde6aaa 100644 --- a/radio.c +++ b/radio.c @@ -461,16 +461,16 @@ void RADIO_ConfigureSquelchAndOutputPower(VFO_Info_t *pInfo) // // getting the best setting here is still experimental, bare with me // - // note that 'noise' and 'glitch' value are inverted compared to 'rssi' values + // note that 'noise' and 'glitch' values are inverted compared to 'rssi' values - pInfo->SquelchOpenRSSIThresh = ((uint16_t)pInfo->SquelchOpenRSSIThresh * 10) / 11; - pInfo->SquelchCloseRSSIThresh = ((uint16_t)pInfo->SquelchOpenRSSIThresh * 10) / 11; + pInfo->SquelchOpenRSSIThresh = ((uint16_t)pInfo->SquelchOpenRSSIThresh * 8) / 9; + pInfo->SquelchCloseRSSIThresh = ((uint16_t)pInfo->SquelchOpenRSSIThresh * 8) / 9; - pInfo->SquelchOpenNoiseThresh = ((uint16_t)pInfo->SquelchOpenNoiseThresh * 11) / 10; - pInfo->SquelchCloseNoiseThresh = ((uint16_t)pInfo->SquelchOpenNoiseThresh * 11) / 10; + pInfo->SquelchOpenNoiseThresh = ((uint16_t)pInfo->SquelchOpenNoiseThresh * 9) / 8; + pInfo->SquelchCloseNoiseThresh = ((uint16_t)pInfo->SquelchOpenNoiseThresh * 9) / 8; - pInfo->SquelchOpenGlitchThresh = ((uint16_t)pInfo->SquelchOpenGlitchThresh * 11) / 10; - pInfo->SquelchCloseGlitchThresh = ((uint16_t)pInfo->SquelchOpenGlitchThresh * 11) / 10; + pInfo->SquelchOpenGlitchThresh = ((uint16_t)pInfo->SquelchOpenGlitchThresh * 9) / 8; + pInfo->SquelchCloseGlitchThresh = ((uint16_t)pInfo->SquelchOpenGlitchThresh * 9) / 8; #endif if (pInfo->SquelchOpenNoiseThresh > 127) @@ -521,7 +521,7 @@ void RADIO_ApplyOffset(VFO_Info_t *pInfo) static void RADIO_SelectCurrentVfo(void) { - gCurrentVfo = (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF) ? gRxVfo : &gEeprom.VfoInfo[gEeprom.TX_CHANNEL]; + gCurrentVfo = (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF) ? gRxVfo : &gEeprom.VfoInfo[gEeprom.TX_CHANNEL]; } void RADIO_SelectVfos(void) diff --git a/utils/main.cpp b/utils/main.cpp index 433b153..ec5d917 100644 --- a/utils/main.cpp +++ b/utils/main.cpp @@ -93,7 +93,7 @@ void create_gain_table(const char *filename) mixer_dB[orig_mixer] + pga_dB[orig_pga]; - #if 0 + #if 1 // full table const uint8_t lna_short_min = 0; // 0 const uint8_t lna_min = 0; // 0 @@ -258,7 +258,7 @@ void create_gain_table(const char *filename) return; fprintf(file, "\n"); - fprintf(file, "\tconst t_am_fix_gain_table am_fix_gain_table[] =\n"); + fprintf(file, "\tstatic const t_am_fix_gain_table am_fix_gain_table[] =\n"); fprintf(file, "\t{\n"); #if 0 @@ -296,7 +296,13 @@ void create_gain_table(const char *filename) reg_val = ((uint16_t)orig_lna_short << 8) | ((uint16_t)orig_lna << 5) | ((uint16_t)orig_mixer << 3) | ((uint16_t)orig_pga << 0); sum_dB = lna_short_dB[orig_lna_short] + lna_dB[orig_lna] + mixer_dB[orig_mixer] + pga_dB[orig_pga]; - fprintf(file, "\t\t{0x%04X, %-3d}, // 0 .. 0dB -14dB 0dB -3dB .. -17dB original\n\n", reg_val, sum_dB); + fprintf(file, "\t\t{0x%04X, %-3d}, // 0 .. %u %u %u %u .. 0dB -14dB 0dB -3dB .. -17dB original\n\n", + reg_val, + sum_dB, + orig_lna_short, + orig_lna, + orig_mixer, + orig_pga); for (unsigned int i = 0; i < gain_table.size(); i++) { @@ -307,14 +313,22 @@ void create_gain_table(const char *filename) reg_val = ((uint16_t)entry.lna_short << 8) | ((uint16_t)entry.lna << 5) | ((uint16_t)entry.mixer << 3) | ((uint16_t)entry.pga << 0); sum_dB = lna_short_dB[entry.lna_short] + lna_dB[entry.lna] + mixer_dB[entry.mixer] + pga_dB[entry.pga]; - sprintf(s, "\t\t{0x%04X, %-3d}, // %3u .. %3ddB %3ddB %2ddB %3ddB .. %3ddB", + sprintf(s, "\t\t{0x%04X, %-3d}, // %3u .. %u %u %u %u .. %3ddB %3ddB %2ddB %3ddB .. %3ddB", reg_val, sum_dB, + 1 + i, + + entry.lna_short, + entry.lna, + entry.mixer, + entry.pga, + entry.lna_short_dB, entry.lna_dB, entry.mixer_dB, entry.pga_dB, + entry.sum_dB); if (i == original_index) @@ -327,7 +341,7 @@ void create_gain_table(const char *filename) fprintf(file, "\t};\n\n"); - fprintf(file, "\tconst unsigned int original_index = %u;\n", 1 + original_index); + fprintf(file, "\tstatic const unsigned int original_index = %u;\n", 1 + original_index); fclose(file); } diff --git a/utils/misc.exe b/utils/misc.exe index a6aab07..e81385a 100644 Binary files a/utils/misc.exe and b/utils/misc.exe differ diff --git a/version.c b/version.c index c10615c..6226204 100644 --- a/version.c +++ b/version.c @@ -4,7 +4,7 @@ #ifdef GIT_HASH #define VER GIT_HASH #else - #define VER "231002" + #define VER "231004" #endif #ifndef ONE_OF_ELEVEN_VER