diff --git a/Makefile b/Makefile index b9fd339..acd7ab9 100644 --- a/Makefile +++ b/Makefile @@ -57,7 +57,7 @@ ENABLE_CTCSS_TAIL_PHASE_SHIFT := 1 ENABLE_CONTRAST := 0 ENABLE_BOOT_BEEPS := 0 ENABLE_DTMF_CALL_FLASH_LIGHT := 1 -ENABLE_FLASH_LIGHT_SOS_TONE := 0 +ENABLE_FLASH_LIGHT_SOS_TONE := 1 ENABLE_SHOW_CHARGE_LEVEL := 0 ENABLE_REVERSE_BAT_SYMBOL := 1 ENABLE_FREQ_SEARCH_TIMEOUT := 0 diff --git a/am_fix.c b/am_fix.c index 3969bda..6b68196 100644 --- a/am_fix.c +++ b/am_fix.c @@ -28,436 +28,441 @@ #include "functions.h" #include "misc.h" -#ifdef ENABLE_AM_FIX +//#define SET_RSSI_COMP - typedef struct - { - uint16_t reg_val; - int8_t gain_dB; - } __attribute__((packed)) t_gain_table; +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 +// 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 !!! - // - // +// 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 lnas_dB[] = { -19, -16, -11, 0}; // was (but wrong) // static const int16_t lnas_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[] = - { - {0x03BE, -7}, // 3 5 3 6 .. 0dB -4dB 0dB -3dB .. -7dB original +// lookup table is hugely easier than writing code to do the same +// +static const t_gain_table gain_table[] = +{ + {0x03BE, -7}, // 3 5 3 6 .. 0dB -4dB 0dB -3dB .. -7dB 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 + // 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 .. 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 - }; + {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 +}; - static const unsigned int original_index = 1; +static const unsigned int original_index = 1; #else - {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 - }; + {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; +static const unsigned int original_index = 90; #endif +#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 display_update_tick = 0; +#endif + +#ifdef ENABLE_AM_FIX_TEST1 + // user manually sets the table index .. used to calibrate the desired dB gain table + unsigned int gain_table_index[2] = {1 + g_eeprom.config.setting.am_fix_test1, 1 + g_eeprom.config.setting.am_fix_test1}; +#else + unsigned int gain_table_index[2] = {original_index, original_index}; +#endif + +// used simply to detect a changed gain setting +unsigned int gain_table_index_prev[2] = {0, 0}; + +// to help reduce gain hunting, peak hold count down tick +unsigned int hold_counter[2] = {0, 0}; + +// holds the previous RSSI level .. we do an average of old + new RSSI reading +int16_t prev_rssi[2] = {0, 0}; + +// used to correct the RSSI readings after our RF gain adjustments +int16_t rssi_gain_diff[2] = {0, 0}; + +#ifndef ENABLE_AM_FIX_TEST1 + // -89 dBm, any higher and the AM demodulator starts to saturate/clip/distort + const int16_t desired_rssi = (-89 + 160) * 2; +#endif + +void AM_fix_init(void) +{ // called at boot-up + unsigned int vfo; + for (vfo = 0; vfo < 2; vfo++) + { + #ifdef ENABLE_AM_FIX_TEST1 + gain_table_index[vfo] = 1 + g_eeprom.config.setting.am_fix_test1; + #else + gain_table_index[vfo] = original_index; // re-start with original QS setting + #endif + //AM_fix_reset(vfo); + } +} + +void AM_fix_reset(const int vfo) +{ // reset the AM fixer upper + + if (vfo < 0 || vfo >= 2) + return; + #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 display_update_tick = 0; + display_update_tick = 0; #endif + prev_rssi[vfo] = 0; + hold_counter[vfo] = 0; + rssi_gain_diff[vfo] = 0; + gain_table_index_prev[vfo] = 0; #ifdef ENABLE_AM_FIX_TEST1 - // user manually sets the table index .. used to calibrate the desired dB gain table - unsigned int gain_table_index[2] = {1 + g_eeprom.config.setting.am_fix_test1, 1 + g_eeprom.config.setting.am_fix_test1}; + //gain_table_index[vfo] = 1 + g_eeprom.config.setting.am_fix_test1; #else - unsigned int gain_table_index[2] = {original_index, original_index}; + //gain_table_index[vfo] = original_index; // re-start with original QS setting #endif +} - // used simply to detect a changed gain setting - unsigned int gain_table_index_prev[2] = {0, 0}; +// adjust the RX gain to try and prevent the AM demodulator from +// saturating (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; - // to help reduce gain hunting, peak hold count down tick - unsigned int hold_counter[2] = {0, 0}; - - // holds the previous RSSI level .. we do an average of old + new RSSI reading - int16_t prev_rssi[2] = {0, 0}; - - // used to correct the RSSI readings after our RF gain adjustments - int16_t rssi_gain_diff[2] = {0, 0}; - - #ifndef ENABLE_AM_FIX_TEST1 - // -89 dBm, any higher and the AM demodulator starts to saturate/clip/distort - const int16_t desired_rssi = (-89 + 160) * 2; - #endif - - void AM_fix_init(void) - { // called at boot-up - unsigned int vfo; - for (vfo = 0; vfo < 2; vfo++) - { - #ifdef ENABLE_AM_FIX_TEST1 - gain_table_index[vfo] = 1 + g_eeprom.config.setting.am_fix_test1; - #else - gain_table_index[vfo] = original_index; // re-start with original QS setting + switch (g_current_function) + { + case FUNCTION_TRANSMIT: + case FUNCTION_PANADAPTER: + case FUNCTION_POWER_SAVE: + #ifdef ENABLE_AM_FIX_SHOW_DATA + display_update_tick = display_update_rate; // queue up a display update as soon as we switch to RX mode #endif -// AM_fix_reset(vfo); - } - } - - void AM_fix_reset(const int vfo) - { // reset the AM fixer upper - - if (vfo < 0 || vfo >= 2) return; - #ifdef ENABLE_AM_FIX_SHOW_DATA - display_update_tick = 0; - #endif - - prev_rssi[vfo] = 0; - hold_counter[vfo] = 0; - rssi_gain_diff[vfo] = 0; - gain_table_index_prev[vfo] = 0; - #ifdef ENABLE_AM_FIX_TEST1 -// gain_table_index[vfo] = 1 + g_eeprom.config.setting.am_fix_test1; - #else -// gain_table_index[vfo] = original_index; // re-start with original QS setting - #endif + // only adjust stuff if we're in one of these modes + case FUNCTION_FOREGROUND: + case FUNCTION_NEW_RECEIVE: + case FUNCTION_RECEIVE: + break; } - // adjust the RX gain to try and prevent the AM demodulator from - // saturating (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) + #ifdef ENABLE_AM_FIX_SHOW_DATA + if (display_update_tick > 0) + { + if (++display_update_tick >= display_update_rate) + { // trigger a display update + display_update_tick = 0; + g_update_display = true; + } + } + #endif + + { // sample the current RSSI level + // average it with the previous rssi (a teeny 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 { - int16_t diff_dB; - int16_t rssi; + const int16_t new_rssi = rssi - rssi_gain_diff[vfo]; + const uint16_t new_glitch = BK4819_GetGlitchIndicator(); + const uint16_t new_noise = BK4819_GetExNoiceIndicator(); - switch (g_current_function) + if (g_current_rssi[vfo] != new_rssi) { - case FUNCTION_TRANSMIT: - case FUNCTION_PANADAPTER: - case FUNCTION_POWER_SAVE: - #ifdef ENABLE_AM_FIX_SHOW_DATA - display_update_tick = display_update_rate; // queue up a display update as soon as we switch to RX mode - #endif - return; + g_current_rssi[vfo] = new_rssi; + g_current_glitch[vfo] = new_glitch; + g_current_noise[vfo] = new_noise; - // only adjust stuff if we're in one of these modes - case FUNCTION_FOREGROUND: - case FUNCTION_NEW_RECEIVE: - case FUNCTION_RECEIVE: - break; - } - - #ifdef ENABLE_AM_FIX_SHOW_DATA - if (display_update_tick > 0) - { - if (++display_update_tick >= display_update_rate) - { // trigger a display update - display_update_tick = 0; - g_update_display = true; - } - } - #endif - - { // sample the current RSSI level - // average it with the previous rssi (a teeny 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 (g_current_rssi[vfo] != new_rssi) - { - g_current_rssi[vfo] = new_rssi; - - if (display_update_tick == 0) - { // trigger a display update - display_update_tick = 1; - g_update_display = true; - } - } - } - #else - g_current_rssi[vfo] = rssi - rssi_gain_diff[vfo]; - #endif - -#ifdef ENABLE_AM_FIX_TEST1 - // user is manually adjusting a gain register - don't do anything automatically - - { - int i = 1 + (int)g_eeprom.config.setting.am_fix_test1; - i = (i < 1) ? 1 : (i > ((int)ARRAY_SIZE(gain_table) - 1) ? ARRAY_SIZE(gain_table) - 1 : i; - - if (gain_table_index[vfo] == i) - return; // no change - - gain_table_index[vfo] = i; - } - -#else - // 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; - - //index = (gain_table_index[vfo] + index) / 2; // easy does it - } - else - { // incrementally reduce the gain .. taking it slow improves noise/spike immunity - -// if (index >= (1 + 3) && diff_dB >= 3) -// index -= 3; // faster gain reduction -// else - if (index > 1) - index--; // slow step-by-step gain reduction - } - - index = (index < 1) ? 1 : (index > (ARRAY_SIZE(gain_table) - 1)) ? ARRAY_SIZE(gain_table) - 1 : index; - - if (gain_table_index[vfo] != index) - { - gain_table_index[vfo] = index; // save new gain setting to use - 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 < ARRAY_SIZE(gain_table)) ? index : ARRAY_SIZE(gain_table) - 1; // limit the gain level we use - } - -#endif - - { // apply the new settings to the front end registers - - const unsigned int index = gain_table_index[vfo]; - - // remember the new gain table index - gain_table_index_prev[vfo] = index; - - // set the RF front end gains - BK4819_WriteRegister(0x13, 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 - g_current_rssi[vfo] = rssi - rssi_gain_diff[vfo]; - - #ifdef ENABLE_AM_FIX_SHOW_DATA if (display_update_tick == 0) - { + { // trigger a display update display_update_tick = 1; g_update_display = true; } + } + } + #else + g_current_rssi[vfo] = rssi - rssi_gain_diff[vfo]; + #endif + +#ifdef ENABLE_AM_FIX_TEST1 + // user is manually adjusting a gain register - don't do anything automatically + + { + int i = 1 + (int)g_eeprom.config.setting.am_fix_test1; + i = (i < 1) ? 1 : (i > ((int)ARRAY_SIZE(gain_table) - 1) ? ARRAY_SIZE(gain_table) - 1 : i; + + if (gain_table_index[vfo] == i) + return; // no change + + gain_table_index[vfo] = i; + } + +#else + // 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; + + //index = (gain_table_index[vfo] + index) / 2; // easy does it + } + else + { // incrementally reduce the gain .. taking it slow improves noise/spike immunity + + //if (index >= (1 + 3) && diff_dB >= 3) + // index -= 3; // faster gain reduction + //else + if (index > 1) + index--; // slow step-by-step gain reduction + } + + index = (index < 1) ? 1 : (index > (ARRAY_SIZE(gain_table) - 1)) ? ARRAY_SIZE(gain_table) - 1 : index; + + if (gain_table_index[vfo] != index) + { + gain_table_index[vfo] = index; // save new gain setting to use + 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 < ARRAY_SIZE(gain_table)) ? index : ARRAY_SIZE(gain_table) - 1; // limit the gain level we use + } + +#endif + + { // apply the new settings to the front end registers + + const unsigned int index = gain_table_index[vfo]; + + // remember the new gain table index + gain_table_index_prev[vfo] = index; + + // set the RF front end gains + BK4819_WriteRegister(0x13, gain_table[index].reg_val); + + // offset the RSSI reading to the rest of the firmware to cancel out the gain adjustments we make + + #ifdef SET_RSSI_COMP + // 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; #endif } + // save the corrected RSSI level + g_current_rssi[vfo] = rssi - rssi_gain_diff[vfo]; + #ifdef ENABLE_AM_FIX_SHOW_DATA - - void AM_fix_print_data(const int vfo, char *s) + if (display_update_tick == 0) { - if (g_current_display_screen != DISPLAY_MAIN || g_dtmf_call_state != DTMF_CALL_STATE_NONE) - return; - - if (s != NULL && vfo >= 0 && vfo < (int)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_table[index].gain_dB, prev_rssi[vfo]); - sprintf(s, "%2u %4ddB %3u", index, gain_table[index].gain_dB, prev_rssi[vfo]); - display_update_tick = 0; - } + display_update_tick = 1; + g_update_display = true; } - #endif +} + +#ifdef ENABLE_AM_FIX_SHOW_DATA + + void AM_fix_print_data(const int vfo, char *s) + { + if (g_current_display_screen != DISPLAY_MAIN || g_dtmf_call_state != DTMF_CALL_STATE_NONE) + return; + + if (s != NULL && vfo >= 0 && vfo < (int)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_table[index].gain_dB, prev_rssi[vfo]); + sprintf(s, "%2u %4ddB %3u", index, gain_table[index].gain_dB, prev_rssi[vfo]); + display_update_tick = 0; + } + } #endif diff --git a/am_fix.h b/am_fix.h index 3c94d17..9aabb7d 100644 --- a/am_fix.h +++ b/am_fix.h @@ -16,20 +16,18 @@ */ #ifndef AM_FIXH +#define AM_FIXH #include #include -#ifdef ENABLE_AM_FIX - extern int16_t rssi_gain_diff[2]; +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 +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/app.c b/app/app.c index b8ae3e3..0c786ff 100644 --- a/app/app.c +++ b/app/app.c @@ -82,7 +82,9 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const static void APP_update_rssi(const int vfo) { - int16_t rssi = BK4819_GetRSSI(); + int16_t rssi = BK4819_GetRSSI(); + uint8_t glitch = BK4819_GetGlitchIndicator(); + uint8_t noise = BK4819_GetExNoiceIndicator(); #ifdef ENABLE_AM_FIX // add RF gain adjust compensation @@ -93,9 +95,11 @@ static void APP_update_rssi(const int vfo) if (g_current_rssi[vfo] == rssi) return; // no change - g_current_rssi[vfo] = rssi; + g_current_rssi[vfo] = rssi; + g_current_glitch[vfo] = glitch; + g_current_noise[vfo] = noise; - UI_update_rssi(rssi, vfo); + UI_update_rssi(rssi, glitch, noise, vfo); } static void APP_check_for_new_receive(void) @@ -1560,7 +1564,7 @@ void APP_process_flash_light_10ms(void) GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); #ifdef ENABLE_FLASH_LIGHT_SOS_TONE if (!g_squelch_open && !g_monitor_enabled && !GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER)) - BK4819_StartTone1(880, 50); + BK4819_StartTone1(880, 50, g_current_function == FUNCTION_TRANSMIT); #endif } } diff --git a/app/main.c b/app/main.c index 6286f9f..98fcf04 100644 --- a/app/main.c +++ b/app/main.c @@ -819,17 +819,19 @@ void MAIN_Key_STAR(bool key_pressed, bool key_held) if (g_scan_state_dir != SCAN_STATE_DIR_OFF) { // RF scanning - if (scanning_paused()) - { - FI_add_freq_ignored(g_rx_vfo->freq_config_rx.frequency); - - // immediately continue the scan - g_scan_pause_tick_10ms = 0; - g_scan_pause_time_mode = false; - g_squelch_open = false; - g_rx_reception_mode = RX_MODE_NONE; - FUNCTION_Select(FUNCTION_FOREGROUND); - } + #ifdef ENABLE_SCAN_IGNORE_LIST + if (scanning_paused()) + { + FI_add_freq_ignored(g_rx_vfo->freq_config_rx.frequency); + + // immediately continue the scan + g_scan_pause_tick_10ms = 0; + g_scan_pause_time_mode = false; + g_squelch_open = false; + g_rx_reception_mode = RX_MODE_NONE; + FUNCTION_Select(FUNCTION_FOREGROUND); + } + #endif return; } diff --git a/audio.c b/audio.c index 0213f17..151562f 100644 --- a/audio.c +++ b/audio.c @@ -173,7 +173,7 @@ void AUDIO_PlayBeep(beep_type_t Beep) } // BK4819_PlayTone(ToneFrequency, true); - BK4819_StartTone1(ToneFrequency, 96); + BK4819_StartTone1(ToneFrequency, 96, false); SYSTEM_DelayMs(2); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); diff --git a/driver/bk4819.c b/driver/bk4819.c index 46e3963..e57350d 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -881,7 +881,7 @@ void BK4819_EnableDTMF(void) (15u << BK4819_REG_24_SHIFT_MAX_SYMBOLS)); // 0 ~ 15 } -void BK4819_StartTone1(const uint16_t frequency, const unsigned int level) +void BK4819_StartTone1(const uint16_t frequency, const unsigned int level, const bool tx) { GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); SYSTEM_DelayMs(2); @@ -895,32 +895,37 @@ void BK4819_StartTone1(const uint16_t frequency, const unsigned int level) BK4819_WriteRegister(0x70, BK4819_REG_70_ENABLE_TONE1 | ((level & 0x7f) << BK4819_REG_70_SHIFT_TONE1_TUNING_GAIN)); BK4819_WriteRegister(0x30, 0); -#if 1 - BK4819_WriteRegister(0x30, - BK4819_REG_30_ENABLE_AF_DAC | - BK4819_REG_30_ENABLE_DISC_MODE | - BK4819_REG_30_ENABLE_TX_DSP); -#else - BK4819_WriteRegister(0x30, - BK4819_REG_30_ENABLE_VCO_CALIB | - BK4819_REG_30_ENABLE_UNKNOWN | -// BK4819_REG_30_ENABLE_RX_LINK | - BK4819_REG_30_ENABLE_AF_DAC | // - BK4819_REG_30_ENABLE_DISC_MODE | // - BK4819_REG_30_ENABLE_PLL_VCO | - BK4819_REG_30_ENABLE_PA_GAIN | -// BK4819_REG_30_ENABLE_MIC_ADC | - BK4819_REG_30_ENABLE_TX_DSP | // -// BK4819_REG_30_ENABLE_RX_DSP | - 0); -#endif + + if (!tx) + { + BK4819_WriteRegister(0x30, + BK4819_REG_30_ENABLE_AF_DAC | + BK4819_REG_30_ENABLE_DISC_MODE | + BK4819_REG_30_ENABLE_TX_DSP); + } + else + { + BK4819_WriteRegister(0x30, + BK4819_REG_30_ENABLE_VCO_CALIB | + BK4819_REG_30_ENABLE_UNKNOWN | +// BK4819_REG_30_ENABLE_RX_LINK | + BK4819_REG_30_ENABLE_AF_DAC | // + BK4819_REG_30_ENABLE_DISC_MODE | // + BK4819_REG_30_ENABLE_PLL_VCO | + BK4819_REG_30_ENABLE_PA_GAIN | +// BK4819_REG_30_ENABLE_MIC_ADC | + BK4819_REG_30_ENABLE_TX_DSP | // +// BK4819_REG_30_ENABLE_RX_DSP | + 0); + } BK4819_WriteRegister(0x71, scale_freq(frequency)); BK4819_ExitTxMute(); SYSTEM_DelayMs(2); - GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); + if (!tx) + GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); } void BK4819_StopTones(const bool tx) @@ -978,7 +983,7 @@ void BK4819_StopTones(const bool tx) void BK4819_PlayTone(const unsigned int tone_Hz, const unsigned int delay, const unsigned int level) { const uint16_t prev_af = BK4819_ReadRegister(0x47); - BK4819_StartTone1(tone_Hz, level); + BK4819_StartTone1(tone_Hz, level, g_current_function == FUNCTION_TRANSMIT); SYSTEM_DelayMs(delay - 2); BK4819_StopTones(g_current_function == FUNCTION_TRANSMIT); BK4819_WriteRegister(0x47, prev_af); @@ -996,9 +1001,9 @@ void BK4819_PlayRoger(void) #endif const uint16_t prev_af = BK4819_ReadRegister(0x47); - BK4819_StartTone1(tone1_Hz, 96); + BK4819_StartTone1(tone1_Hz, 96, true); SYSTEM_DelayMs(80 - 2); - BK4819_StartTone1(tone2_Hz, 96); + BK4819_StartTone1(tone2_Hz, 96, true); SYSTEM_DelayMs(80); BK4819_StopTones(true); BK4819_WriteRegister(0x47, prev_af); @@ -1553,12 +1558,12 @@ uint16_t BK4819_GetRSSI(void) return BK4819_ReadRegister(0x67) & 0x01FF; } -uint8_t BK4819_GetGlitchIndicator(void) +uint8_t BK4819_GetGlitchIndicator(void) { return BK4819_ReadRegister(0x63) & 0x00FF; } -uint8_t BK4819_GetExNoiceIndicator(void) +uint8_t BK4819_GetExNoiceIndicator(void) { return BK4819_ReadRegister(0x65) & 0x007F; } diff --git a/driver/bk4819.h b/driver/bk4819.h index 0a46064..1482fa7 100644 --- a/driver/bk4819.h +++ b/driver/bk4819.h @@ -103,7 +103,7 @@ void BK4819_SetCompander(const unsigned int mode); void BK4819_DisableVox(void); void BK4819_DisableDTMF(void); void BK4819_EnableDTMF(void); -void BK4819_StartTone1(const uint16_t frequency, const unsigned int level); +void BK4819_StartTone1(const uint16_t frequency, const unsigned int level, const bool tx); void BK4819_StopTones(const bool tx); void BK4819_PlayTone(const unsigned int tone_Hz, const unsigned int delay, const unsigned int level); void BK4819_EnterTxMute(void); diff --git a/firmware.bin b/firmware.bin index 3d6ff2b..c208b79 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index 3f20e80..985f2d8 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/freq_ignore.c b/freq_ignore.c index d870ac2..4374020 100644 --- a/freq_ignore.c +++ b/freq_ignore.c @@ -6,7 +6,7 @@ #include "misc.h" // a list of frequencies to ignore/skip when scanning -uint32_t ignore_frequencies[256]; +uint32_t ignore_frequencies[64]; int ignore_frequencies_count = 0; void FI_clear_freq_ignored(void) diff --git a/functions.c b/functions.c index 12f9450..0dbb6e3 100644 --- a/functions.c +++ b/functions.c @@ -220,7 +220,7 @@ void FUNCTION_Select(function_type_t Function) GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); SYSTEM_DelayMs(2); - BK4819_StartTone1(500, 28); + BK4819_StartTone1(500, 28, g_current_function == FUNCTION_TRANSMIT); SYSTEM_DelayMs(2); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); diff --git a/misc.c b/misc.c index 8abbae4..5b51805 100644 --- a/misc.c +++ b/misc.c @@ -234,7 +234,9 @@ volatile bool g_flag_tail_tone_elimination_complete; volatile uint16_t g_boot_tick_10ms = 4000 / 10; // 4 seconds -int16_t g_current_rssi[2] = {0, 0}; // now one per VFO +int16_t g_current_rssi[2] = {0, 0}; +uint16_t g_current_glitch[2] = {0, 0}; +uint16_t g_current_noise[2] = {0, 0}; uint8_t g_mic_sensitivity_tuning; diff --git a/misc.h b/misc.h index ec2ee92..ab2a2f5 100644 --- a/misc.h +++ b/misc.h @@ -321,7 +321,11 @@ extern volatile bool g_next_time_slice_40ms; extern volatile bool g_schedule_noaa; #endif extern volatile bool g_flag_tail_tone_elimination_complete; -extern int16_t g_current_rssi[2]; // now one per VFO + +extern int16_t g_current_rssi[2]; +extern uint16_t g_current_glitch[2]; +extern uint16_t g_current_noise[2]; + extern volatile uint16_t g_boot_tick_10ms; extern uint8_t g_mic_sensitivity_tuning; diff --git a/ui/main.c b/ui/main.c index 06200c7..a7de9e0 100644 --- a/ui/main.c +++ b/ui/main.c @@ -55,27 +55,13 @@ void draw_bar(uint8_t *line, const int len, const int max_width) for (i = 0; i < max_width; i += 2) line[i] = (i <= len) ? 0x7f : 0x41; #else - // segmented bar for (i = 0; i < max_width; i += 4) - { for (int k = i - 4; k < i && k < len; k++) - { if (k >= 0) // line[k] = (k < (i - 1)) ? 0x7f : 0x00; if (k < (i - 1)) line[k] = 0x7f; -// line[k] = 0x3e; - } - } - - #if 0 - // top/bottom lines - for (i = 0; i < len; i += 2) - line[i] |= 0x41; - for (i &= ~3u ; i < max_width; i += 4) - line[i] = 0x41; - #endif #endif } @@ -179,10 +165,14 @@ void UI_drawBars(uint8_t *p, const unsigned int level) #endif #ifdef ENABLE_RX_SIGNAL_BAR - bool UI_DisplayRSSIBar(const int16_t rssi, const bool now) + bool UI_DisplayRSSIBar(const int16_t rssi, const int16_t glitch, const int16_t noise, const bool now) { if (g_eeprom.config.setting.enable_rssi_bar) { + + (void)glitch; // TODO: + (void)noise; + // const int16_t s0_dBm = -127; // S0 .. base level const int16_t s0_dBm = -147; // S0 .. base level @@ -245,14 +235,14 @@ void UI_drawBars(uint8_t *p, const unsigned int level) } #endif -void UI_update_rssi(const int16_t rssi, const int vfo) +void UI_update_rssi(const int16_t rssi, const int16_t glitch, const int16_t noise, const int vfo) { #ifdef ENABLE_RX_SIGNAL_BAR if (g_center_line == CENTER_LINE_RSSI) { // optional larger RSSI dBm, S-point and bar level //if (g_current_function == FUNCTION_RECEIVE && g_squelch_open) if (g_current_function == FUNCTION_RECEIVE) - UI_DisplayRSSIBar(rssi, true); + UI_DisplayRSSIBar(rssi, glitch, noise, true); } #endif @@ -921,7 +911,7 @@ void UI_DisplayMain(void) if (rx && g_eeprom.config.setting.enable_rssi_bar) { g_center_line = CENTER_LINE_RSSI; - UI_DisplayRSSIBar(g_current_rssi[g_rx_vfo_num], false); + UI_DisplayRSSIBar(g_current_rssi[g_rx_vfo_num], g_current_glitch[g_rx_vfo_num], g_current_noise[g_rx_vfo_num], false); } else #endif diff --git a/ui/main.h b/ui/main.h index 4260222..09dcdb2 100644 --- a/ui/main.h +++ b/ui/main.h @@ -34,7 +34,7 @@ extern center_line_t g_center_line; #ifdef ENABLE_TX_AUDIO_BAR bool UI_DisplayAudioBar(const bool now); #endif -void UI_update_rssi(const int16_t rssi, const int vfo); +void UI_update_rssi(const int16_t rssi, const int16_t glitch, const int16_t noise, const int vfo); void UI_DisplayMain(void); #endif