From f3297c29cb3f2ab707fc6354dc06198303b24682 Mon Sep 17 00:00:00 2001 From: Krzysiek Egzmont Date: Mon, 4 Dec 2023 22:58:27 +0100 Subject: [PATCH] AGC debugging option --- Makefile | 8 +++++++- app/app.c | 1 + driver/st7565.c | 8 ++++++++ driver/st7565.h | 1 + ui/main.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ ui/main.h | 1 + 6 files changed, 70 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8ed8dea..57d2a85 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,6 @@ ENABLE_SHOW_CHARGE_LEVEL := 0 ENABLE_REVERSE_BAT_SYMBOL := 0 ENABLE_NO_CODE_SCAN_TIMEOUT := 1 ENABLE_AM_FIX := 1 -ENABLE_AM_FIX_SHOW_DATA := 0 ENABLE_SQUELCH_MORE_SENSITIVE := 1 ENABLE_FASTER_CHANNEL_SCAN := 1 ENABLE_RSSI_BAR := 1 @@ -46,6 +45,10 @@ ENABLE_BYP_RAW_DEMODULATORS := 0 ENABLE_BLMIN_TMP_OFF := 0 ENABLE_SCAN_RANGES := 1 +# ---- DEBUGGING ---- +ENABLE_AM_FIX_SHOW_DATA := 0 +ENABLE_AGC_SHOW_DATA := 0 + ############################################################# TARGET = firmware @@ -358,6 +361,9 @@ endif ifeq ($(ENABLE_DTMF_CALLING),1) CFLAGS += -DENABLE_DTMF_CALLING endif +ifeq ($(ENABLE_AGC_SHOW_DATA),1) + CFLAGS += -DENABLE_AGC_SHOW_DATA +endif LDFLAGS = ifeq ($(ENABLE_CLANG),0) diff --git a/app/app.c b/app/app.c index 0f2f321..42d88aa 100644 --- a/app/app.c +++ b/app/app.c @@ -1564,6 +1564,7 @@ void APP_TimeSlice500ms(void) BATTERY_TimeSlice500ms(); SCANNER_TimeSlice500ms(); + UI_MAIN_TimeSlice500ms(); #ifdef ENABLE_DTMF_CALLING if (gCurrentFunction != FUNCTION_TRANSMIT) diff --git a/driver/st7565.c b/driver/st7565.c index 832f18d..c7070c1 100644 --- a/driver/st7565.c +++ b/driver/st7565.c @@ -56,6 +56,14 @@ void ST7565_BlitFullScreen(void) SPI_ToggleMasterMode(&SPI0->CR, true); } +void ST7565_BlitLine(unsigned line) +{ + SPI_ToggleMasterMode(&SPI0->CR, false); + ST7565_WriteByte(0x40); // start line ? + DrawLine(0, line+1, gFrameBuffer[line], LCD_WIDTH); + SPI_ToggleMasterMode(&SPI0->CR, true); +} + void ST7565_BlitStatusLine(void) { // the top small text line on the display SPI_ToggleMasterMode(&SPI0->CR, false); diff --git a/driver/st7565.h b/driver/st7565.h index c063734..69060bf 100644 --- a/driver/st7565.h +++ b/driver/st7565.h @@ -29,6 +29,7 @@ extern uint8_t gFrameBuffer[FRAME_LINES][LCD_WIDTH]; void ST7565_DrawLine(const unsigned int Column, const unsigned int Line, const uint8_t *pBitmap, const unsigned int Size); void ST7565_BlitFullScreen(void); +void ST7565_BlitLine(unsigned line); void ST7565_BlitStatusLine(void); void ST7565_FillScreen(uint8_t Value); void ST7565_Init(void); diff --git a/ui/main.c b/ui/main.c index c7424b1..9990621 100644 --- a/ui/main.c +++ b/ui/main.c @@ -249,6 +249,53 @@ void UI_UpdateRSSI(const int16_t rssi, const int vfo) } +#ifdef ENABLE_AGC_SHOW_DATA +static void PrintAGC(bool now) +{ + char buf[20]; + memset(gFrameBuffer[3], 0, 128); + union { + struct { + uint16_t _ : 5; + uint16_t agcSigStrength : 7; + int16_t gainIdx : 3; + uint16_t agcEnab : 1; + }; + uint16_t __raw; + } reg7e; + reg7e.__raw = BK4819_ReadRegister(0x7E); + uint8_t gainAddr = reg7e.gainIdx < 0 ? 0x14 : 0x10 + reg7e.gainIdx; + union { + struct { + uint16_t pga:3; + uint16_t mixer:2; + uint16_t lna:3; + uint16_t lnaS:2; + }; + uint16_t __raw; + } agcGainReg; + agcGainReg.__raw = BK4819_ReadRegister(gainAddr); + int8_t lnaShortTab[] = {-28, -24, -19, 0}; + int8_t lnaTab[] = {-24, -19, -14, -9, -6, -4, -2, 0}; + int8_t mixerTab[] = {-8, -6, -3, 0}; + int8_t pgaTab[] = {-33, -27, -21, -15, -9, -6, -3, 0}; + int16_t agcGain = lnaShortTab[agcGainReg.lnaS] + lnaTab[agcGainReg.lna] + mixerTab[agcGainReg.mixer] + pgaTab[agcGainReg.pga]; + + sprintf(buf, "%d%2d %2d %2d %3d", reg7e.agcEnab, reg7e.gainIdx, -agcGain, reg7e.agcSigStrength, BK4819_GetRSSI()); + UI_PrintStringSmall(buf, 2, 0, 3); + if(now) + ST7565_BlitLine(3); +} +#endif + +void UI_MAIN_TimeSlice500ms(void) +{ +#ifdef ENABLE_AGC_SHOW_DATA +if(gScreenToDisplay==DISPLAY_MAIN) + PrintAGC(true); +#endif +} + // *************************************************************************** void UI_DisplayMain(void) @@ -672,6 +719,11 @@ void UI_DisplayMain(void) UI_PrintStringSmall("SCR", LCD_WIDTH + 106, 0, line + 1); } +#ifdef ENABLE_AGC_SHOW_DATA + center_line = CENTER_LINE_IN_USE; + PrintAGC(false); +#endif + if (center_line == CENTER_LINE_NONE) { // we're free to use the middle line diff --git a/ui/main.h b/ui/main.h index 05205aa..6198dc7 100644 --- a/ui/main.h +++ b/ui/main.h @@ -33,6 +33,7 @@ extern const int8_t dBmCorrTable[7]; void UI_DisplayAudioBar(void); void UI_UpdateRSSI(const int16_t rssi, const int vfo); +void UI_MAIN_TimeSlice500ms(void); void UI_DisplayMain(void); #endif