diff --git a/Makefile b/Makefile index 5ea9b79..d557657 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ ENABLE_BOOT_BEEPS := 0 ENABLE_COMPANDER := 1 ENABLE_SHOW_CHARGE_LEVEL := 0 ENABLE_REVERSE_BAT_SYMBOL := 1 +ENABLE_NO_SCAN_TIMEOUT := 1 ENABLE_AM_FIX := 1 ENABLE_AM_FIX_SHOW_DATA := 1 ENABLE_SQUELCH1_LOWER := 0 @@ -204,6 +205,9 @@ endif ifeq ($(ENABLE_REVERSE_BAT_SYMBOL),1) CFLAGS += -DENABLE_REVERSE_BAT_SYMBOL endif +ifeq ($(ENABLE_NO_SCAN_TIMEOUT),1) + CFLAGS += -DENABLE_NO_SCAN_TIMEOUT +endif ifeq ($(ENABLE_AM_FIX),1) CFLAGS += -DENABLE_AM_FIX endif diff --git a/README.md b/README.md index b9bf074..c4d04a4 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,10 @@ To compile directly in windows without the need of a linux virtual machine: ``` 1. Download and install "gcc-arm-none-eabi-10.3-2021.10-win32.exe" from https://developer.arm.com/downloads/-/gnu-rm 2. Download and install "gnu_make-3.81.exe" from https://gnuwin32.sourceforge.net/packages/make.htm -3. You may (or not) need to manualy add gcc path to you OS environment PATH, ie C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin + +3. You may (or not) need to manualy add gcc path to you OS environment PATH. + ie add C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin + 4. You may (or not) need to reboot your PC after installing the above ``` diff --git a/am_fix.c b/am_fix.c index b1e54dd..416bdbb 100644 --- a/am_fix.c +++ b/am_fix.c @@ -297,14 +297,11 @@ const uint8_t orig_pga = 6; // -3dB // used to simply detect we've changed our table index/register settings unsigned int am_fix_gain_table_index_prev[2] = {0, 0}; - // moving average RSSI buffer - // helps smooth out any spikey RSSI readings - struct { - unsigned int count; // - unsigned int index; // read/write buffer index - uint16_t samples[4]; // 40ms long buffer (10ms RSSI sample rate) - uint16_t sum; // sum of all samples in the buffer - } moving_avg_rssi[2] = {0}; + struct + { + unsigned int count; + uint16_t level; + } rssi[2]; // to help reduce gain hunting, provides a peak hold time delay unsigned int am_gain_hold_counter[2] = {0, 0}; @@ -315,8 +312,8 @@ const uint8_t orig_pga = 6; // -3dB void AM_fix_reset(const int vfo) { // reset the AM fixer - // reset the moving average filter - memset(&moving_avg_rssi[vfo], 0, sizeof(moving_avg_rssi[vfo])); + rssi[vfo].count = 0; + rssi[vfo].level = 0; am_gain_hold_counter[vfo] = 0; @@ -352,6 +349,8 @@ const uint8_t orig_pga = 6; // -3dB case FUNCTION_TRANSMIT: case FUNCTION_BAND_SCOPE: case FUNCTION_POWER_SAVE: + return; + case FUNCTION_FOREGROUND: return; @@ -362,21 +361,16 @@ const uint8_t orig_pga = 6; // -3dB break; } - // sample the current RSSI level - uint16_t rssi = BK4819_GetRSSI(); // supposed 9-bit value (0 .. 511) - never seen that though - -#if 1 - // compute moving average RSSI - helps smooth any sharp spikes/troughs - // but can cause gain hunting/oscillation if too long a buffer (.samples) - if (moving_avg_rssi[vfo].count < ARRAY_SIZE(moving_avg_rssi[vfo].samples)) - moving_avg_rssi[vfo].count++; - moving_avg_rssi[vfo].sum -= moving_avg_rssi[vfo].samples[moving_avg_rssi[vfo].index]; // subtract the oldest sample - moving_avg_rssi[vfo].sum += rssi; // add the newest sample - moving_avg_rssi[vfo].samples[moving_avg_rssi[vfo].index] = rssi; // save the newest sample - if (++moving_avg_rssi[vfo].index >= ARRAY_SIZE(moving_avg_rssi[vfo].samples)) // - moving_avg_rssi[vfo].index = 0; // - rssi = moving_avg_rssi[vfo].sum / moving_avg_rssi[vfo].count; // compute the average of the past 'n' samples -#endif + // sample the current RSSI level, average it with the previous rssi + if (rssi[vfo].count < 1) + { + rssi[vfo].level = BK4819_GetRSSI(); + rssi[vfo].count++; + } + else + { + rssi[vfo].level = (rssi[vfo].level + BK4819_GetRSSI()) >> 1; + } #ifdef ENABLE_AM_FIX_TEST1 @@ -388,18 +382,18 @@ const uint8_t orig_pga = 6; // -3dB { if (--am_gain_hold_counter[vfo] > 0) { - gCurrentRSSI[vfo] = rssi - (rssi_db_gain_diff[vfo] * 2); + gCurrentRSSI[vfo] = (int16_t)rssi[vfo].level - (rssi_db_gain_diff[vfo] * 2); return; } } - + am_gain_hold_counter[vfo] = 250; // 250ms hold #else // automatically choose a front end gain setting by monitoring the RSSI - if (rssi > desired_rssi) + if (rssi[vfo].level > desired_rssi) { // decrease gain if (am_fix_gain_table_index[vfo] > 1) @@ -413,14 +407,14 @@ const uint8_t orig_pga = 6; // -3dB if (am_gain_hold_counter[vfo] == 0) // hold has been released, we're free to increase gain - if (rssi < (desired_rssi - 10)) // 5dB hysterisis (helps reduce gain hunting) + if (rssi[vfo].level < (desired_rssi - 10)) // 5dB hysterisis (helps reduce gain hunting) // increase gain if (am_fix_gain_table_index[vfo] < (ARRAY_SIZE(am_fix_gain_table) - 1)) am_fix_gain_table_index[vfo]++; if (am_fix_gain_table_index[vfo] == am_fix_gain_table_index_prev[vfo]) { // no gain changes have been made - gCurrentRSSI[vfo] = rssi - (rssi_db_gain_diff[vfo] * 2); + gCurrentRSSI[vfo] = (int16_t)rssi[vfo].level - (rssi_db_gain_diff[vfo] * 2); return; } @@ -442,7 +436,7 @@ const uint8_t orig_pga = 6; // -3dB rssi_db_gain_diff[vfo] = am_dB_gain - orig_dB_gain; // shall we or sharn't we ? - gCurrentRSSI[vfo] = rssi - (rssi_db_gain_diff[vfo] * 2); + gCurrentRSSI[vfo] = (int16_t)rssi[vfo].level - (rssi_db_gain_diff[vfo] * 2); } // remember the new table index @@ -470,7 +464,7 @@ const uint8_t orig_pga = 6; // -3dB // compute the current front end gain const int16_t dB_gain = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga]; - sprintf(s, "idx %2d %4ddB %3u", am_fix_gain_table_index[vfo], dB_gain, BK4819_GetRSSI()); + sprintf(s, "idx %2d %4ddB %3u", am_fix_gain_table_index[vfo], dB_gain, rssi[vfo].level); } #endif diff --git a/app/action.c b/app/action.c index 2f67cec..724d46c 100644 --- a/app/action.c +++ b/app/action.c @@ -187,6 +187,9 @@ void ACTION_Scan(bool bRestart) AUDIO_PlaySingleVoice(true); #endif + // clear the other vfo's rssi level (to hide the antenna symbol) + gVFO_RSSI_bar_level[gEeprom.RX_CHANNEL == 0] = 0; + // let the user see DW is not active gDualWatchActive = false; gUpdateStatus = true; diff --git a/app/app.c b/app/app.c index 649bf47..b57a13d 100644 --- a/app/app.c +++ b/app/app.c @@ -65,6 +65,19 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld); +static void updateRSSI(const int vfo) +{ + int16_t rssi = BK4819_GetRSSI(); + #ifdef ENABLE_AM_FIX + // with compensation + if (gEeprom.VfoInfo[vfo].IsAM && gSetting_AM_fix) + rssi -= rssi_db_gain_diff[vfo] * 2; + #endif + gCurrentRSSI[vfo] = rssi; + + UI_UpdateRSSI(rssi, vfo); +} + static void APP_CheckForIncoming(void) { if (!g_SquelchLost) @@ -415,10 +428,11 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix) #endif #ifdef ENABLE_AM_FIX - if (reset_am_fix) + if (gEeprom.VfoInfo[gEeprom.RX_CHANNEL].IsAM && reset_am_fix) AM_fix_reset(gEeprom.RX_CHANNEL); // TODO: only reset it when moving channel/frequency #endif + // clear the other vfo's rssi level (to hide the antenna symbol) gVFO_RSSI_bar_level[gEeprom.RX_CHANNEL == 0] = 0; GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); @@ -1119,8 +1133,8 @@ void APP_Update(void) 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(); + gUpdateRSSI = false; } @@ -1133,15 +1147,7 @@ void APP_Update(void) if (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF || gScanState != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF || gUpdateRSSI) { // dual watch mode, go back to sleep - // sample the RSSI - gCurrentRSSI[gEeprom.RX_CHANNEL] = BK4819_GetRSSI(); - #ifdef ENABLE_AM_FIX - // with compensation - if (gRxVfo->IsAM && gSetting_AM_fix) - gCurrentRSSI[gEeprom.RX_CHANNEL] -= rssi_db_gain_diff[gEeprom.RX_CHANNEL] * 2; - #endif - - UI_UpdateRSSI(gCurrentRSSI[gEeprom.RX_CHANNEL], gEeprom.RX_CHANNEL); + updateRSSI(gEeprom.RX_CHANNEL); // go back to sleep @@ -1156,8 +1162,7 @@ void APP_Update(void) } else - { // no yet in power save mode - + { // toggle between the two VFO's DUALWATCH_Alternate(); @@ -1326,7 +1331,7 @@ void APP_TimeSlice10ms(void) #endif #ifdef ENABLE_AM_FIX - if (gRxVfo->IsAM && gSetting_AM_fix) + if (gEeprom.VfoInfo[gEeprom.RX_CHANNEL].IsAM && gSetting_AM_fix) AM_fix_adjust_frontEnd_10ms(gEeprom.RX_CHANNEL); #endif @@ -1659,16 +1664,7 @@ void APP_TimeSlice500ms(void) gUpdateStatus = true; if (gCurrentFunction != FUNCTION_POWER_SAVE) - { - gCurrentRSSI[gEeprom.RX_CHANNEL] = (int16_t)BK4819_GetRSSI(); - #ifdef ENABLE_AM_FIX - // with compensation - if (gRxVfo->IsAM && gSetting_AM_fix) - gCurrentRSSI[gEeprom.RX_CHANNEL] -= rssi_db_gain_diff[gEeprom.RX_CHANNEL] * 2; - #endif - - UI_UpdateRSSI(gCurrentRSSI[gEeprom.RX_CHANNEL], gEeprom.RX_CHANNEL); - } + updateRSSI(gEeprom.RX_CHANNEL); #ifdef ENABLE_FMRADIO if ((gFM_ScanState == FM_SCAN_OFF || gAskToSave) && gCssScanMode == CSS_SCAN_MODE_OFF) @@ -1759,7 +1755,7 @@ void APP_TimeSlice500ms(void) { gLowBatteryBlink = ++gLowBatteryCountdown & 1; - UI_DisplayBattery(gLowBatteryCountdown); + UI_DisplayBattery(0, gLowBatteryBlink); if (gCurrentFunction != FUNCTION_TRANSMIT) { // not transmitting @@ -1808,16 +1804,20 @@ void APP_TimeSlice500ms(void) if (gScreenToDisplay == DISPLAY_SCANNER && gScannerEditState == 0 && gScanCssState < SCAN_CSS_STATE_FOUND) { - if (++gScanProgressIndicator > 32) - { - if (gScanCssState == SCAN_CSS_STATE_SCANNING && !gScanSingleFrequency) - gScanCssState = SCAN_CSS_STATE_FOUND; - else - gScanCssState = SCAN_CSS_STATE_FAILED; - - gUpdateStatus = true; - } - + gScanProgressIndicator++; + + #ifndef ENABLE_NO_SCAN_TIMEOUT + if (gScanProgressIndicator > 32) + { + if (gScanCssState == SCAN_CSS_STATE_SCANNING && !gScanSingleFrequency) + gScanCssState = SCAN_CSS_STATE_FOUND; + else + gScanCssState = SCAN_CSS_STATE_FAILED; + + gUpdateStatus = true; + } + #endif + gUpdateDisplay = true; } diff --git a/bitmaps.c b/bitmaps.c index 57f878e..0e20602 100644 --- a/bitmaps.c +++ b/bitmaps.c @@ -29,6 +29,12 @@ const uint8_t BITMAP_PowerSave[8] = #endif }; +const uint8_t BITMAP_BatteryLevel[2] = +{ + 0b01011101, + 0b01011101 +}; + #ifndef ENABLE_REVERSE_BAT_SYMBOL // Quansheng way (+ pole to the left) const uint8_t BITMAP_BatteryLevel1[17] = @@ -51,90 +57,6 @@ const uint8_t BITMAP_PowerSave[8] = 0b01000001, 0b01111111 }; - - const uint8_t BITMAP_BatteryLevel2[17] = - { - 0b00000000, - 0b00111110, - 0b00100010, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01111111 - }; - - const uint8_t BITMAP_BatteryLevel3[17] = - { - 0b00000000, - 0b00111110, - 0b00100010, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01111111 - }; - - const uint8_t BITMAP_BatteryLevel4[17] = - { - 0b00000000, - 0b00111110, - 0b00100010, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01111111 - }; - - const uint8_t BITMAP_BatteryLevel5[17] = - { - 0b00000000, - 0b00111110, - 0b00100010, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01111111 - }; #else // reversed (+ pole to the right) const uint8_t BITMAP_BatteryLevel1[17] = @@ -157,90 +79,6 @@ const uint8_t BITMAP_PowerSave[8] = 0b00100010, 0b00111110 }; - - const uint8_t BITMAP_BatteryLevel2[17] = - { - 0b00000000, - 0b01111111, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b00100010, - 0b00111110 - }; - - const uint8_t BITMAP_BatteryLevel3[17] = - { - 0b00000000, - 0b01111111, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b00100010, - 0b00111110 - }; - - const uint8_t BITMAP_BatteryLevel4[17] = - { - 0b00000000, - 0b01111111, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01000001, - 0b01000001, - 0b01000001, - 0b00100010, - 0b00111110 - }; - - const uint8_t BITMAP_BatteryLevel5[17] = - { - 0b00000000, - 0b01111111, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b01011101, - 0b01011101, - 0b01000001, - 0b00100010, - 0b00111110 - }; #endif const uint8_t BITMAP_USB_C[9] = diff --git a/bitmaps.h b/bitmaps.h index bab8788..7e3163e 100644 --- a/bitmaps.h +++ b/bitmaps.h @@ -6,6 +6,7 @@ extern const uint8_t BITMAP_PowerSave[8]; +extern const uint8_t BITMAP_BatteryLevel[2]; extern const uint8_t BITMAP_BatteryLevel1[17]; extern const uint8_t BITMAP_BatteryLevel2[17]; extern const uint8_t BITMAP_BatteryLevel3[17]; diff --git a/driver/bk4819.c b/driver/bk4819.c index 28ef6fa..58e8fa5 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -574,7 +574,8 @@ void BK4819_SetFilterBandwidth(const BK4819_FilterBandwidth_t Bandwidth, const b BK4819_WriteRegister(BK4819_REG_43, (0u << 15) | // 0 (3u << 12) | // 3 RF filter bandwidth - (0u << 9) | // 0 RF filter bandwidth when signal is weak +// (0u << 9) | // 0 RF filter bandwidth when signal is weak + (1u << 9) | // 0 RF filter bandwidth when signal is weak (0u << 6) | // 0 AFTxLPF2 filter Band Width (2u << 4) | // 2 BW Mode Selection (1u << 3) | // 1 @@ -602,7 +603,8 @@ void BK4819_SetFilterBandwidth(const BK4819_FilterBandwidth_t Bandwidth, const b BK4819_WriteRegister(BK4819_REG_43, // 0x4048); // 0 100 000 001 00 1 0 00 (0u << 15) | // 0 (3u << 12) | // 4 RF filter bandwidth - (0u << 9) | // 0 RF filter bandwidth when signal is weak +// (0u << 9) | // 0 RF filter bandwidth when signal is weak + (1u << 9) | // 0 RF filter bandwidth when signal is weak (1u << 6) | // 1 AFTxLPF2 filter Band Width (0u << 4) | // 0 BW Mode Selection (1u << 3) | // 1 diff --git a/firmware.bin b/firmware.bin index ea4fac0..4b75d9d 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index a17a84a..8c44166 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/helper/battery.c b/helper/battery.c index b6f7754..1084fe1 100644 --- a/helper/battery.c +++ b/helper/battery.c @@ -36,28 +36,43 @@ volatile uint16_t gPowerSave_10ms; void BATTERY_GetReadings(bool bDisplayBatteryLevel) { - uint8_t PreviousBatteryLevel = gBatteryDisplayLevel; - uint16_t Voltage = (gBatteryVoltages[0] + gBatteryVoltages[1] + gBatteryVoltages[2] + gBatteryVoltages[3]) / 4; + const uint8_t PreviousBatteryLevel = gBatteryDisplayLevel; + const uint16_t Voltage = (gBatteryVoltages[0] + gBatteryVoltages[1] + gBatteryVoltages[2] + gBatteryVoltages[3]) / 4; - if (gBatteryCalibration[5] < Voltage) + gBatteryDisplayLevel = 0; + + if (Voltage >= gBatteryCalibration[5]) + gBatteryDisplayLevel = 11; + else + if (Voltage >= ((gBatteryCalibration[4] + gBatteryCalibration[5]) / 2)) + gBatteryDisplayLevel = 10; + else + if (Voltage >= gBatteryCalibration[4]) + gBatteryDisplayLevel = 9; + else + if (Voltage >= ((gBatteryCalibration[3] + gBatteryCalibration[4]) / 2)) + gBatteryDisplayLevel = 8; + else + if (Voltage >= gBatteryCalibration[3]) + gBatteryDisplayLevel = 7; + else + if (Voltage >= ((gBatteryCalibration[2] + gBatteryCalibration[3]) / 2)) gBatteryDisplayLevel = 6; else - if (gBatteryCalibration[4] < Voltage) + if (Voltage >= gBatteryCalibration[2]) gBatteryDisplayLevel = 5; else - if (gBatteryCalibration[3] < Voltage) + if (Voltage >= ((gBatteryCalibration[1] + gBatteryCalibration[2]) / 2)) gBatteryDisplayLevel = 4; else - if (gBatteryCalibration[2] < Voltage) + if (Voltage >= gBatteryCalibration[1]) gBatteryDisplayLevel = 3; else - if (gBatteryCalibration[1] < Voltage) + if (Voltage >= ((gBatteryCalibration[0] + gBatteryCalibration[1]) / 2)) gBatteryDisplayLevel = 2; else - if (gBatteryCalibration[0] < Voltage) + if (Voltage >= gBatteryCalibration[0]) gBatteryDisplayLevel = 1; - else - gBatteryDisplayLevel = 0; gBatteryVoltageAverage = (Voltage * 760) / gBatteryCalibration[3]; @@ -71,6 +86,7 @@ void BATTERY_GetReadings(bool bDisplayBatteryLevel) gUpdateStatus = true; gUpdateDisplay = true; } + gChargingWithTypeC = false; } else @@ -81,6 +97,7 @@ void BATTERY_GetReadings(bool bDisplayBatteryLevel) gUpdateDisplay = true; BACKLIGHT_TurnOn(); } + gChargingWithTypeC = true; } @@ -93,9 +110,11 @@ void BATTERY_GetReadings(bool bDisplayBatteryLevel) else { gLowBattery = false; + if (bDisplayBatteryLevel) - UI_DisplayBattery(gBatteryDisplayLevel); + UI_DisplayBattery(gBatteryDisplayLevel, gLowBatteryBlink); } + gLowBatteryCountdown = 0; } } diff --git a/misc.c b/misc.c index 227a98c..cfc96a3 100644 --- a/misc.c +++ b/misc.c @@ -52,9 +52,8 @@ const uint16_t battery_save_count_10ms = 10000 / 10; // 10 seconds const uint16_t power_save1_10ms = 100 / 10; // 100ms const uint16_t power_save2_10ms = 200 / 10; // 200ms -const uint16_t gMax_bat_v = 843; // 8.43V +const uint16_t gMax_bat_v = 840; // 8.4V const uint16_t gMin_bat_v = 660; // 6.6V -//const uint16_t gMin_bat_v = 690; // 6.9V const uint32_t gDefaultAesKey[4] = {0x4AA5CC60, 0x0312CC5F, 0xFFD2DABB, 0x6BBA7F92}; diff --git a/radio.c b/radio.c index 444e50f..a2efdb8 100644 --- a/radio.c +++ b/radio.c @@ -972,7 +972,8 @@ void RADIO_PrepareTX(void) if (gBatteryDisplayLevel == 0) State = VFO_STATE_BAT_LOW; else - if (gBatteryDisplayLevel >= 6) +// if (gBatteryDisplayLevel >= 6) + if (gBatteryDisplayLevel >= 11) State = VFO_STATE_VOLTAGE_HIGH; else goto Skip; diff --git a/ui/battery.c b/ui/battery.c index f5c93fe..3f89b93 100644 --- a/ui/battery.c +++ b/ui/battery.c @@ -15,28 +15,73 @@ */ #include +#include + #include "bitmaps.h" #include "driver/st7565.h" #include "functions.h" #include "ui/battery.h" -void UI_DisplayBattery(uint8_t Level) +void UI_DisplayBattery(const uint8_t level, const uint8_t blink) { - if (gCurrentFunction != FUNCTION_TRANSMIT) +// if (gCurrentFunction != FUNCTION_TRANSMIT) { - const unsigned int x = LCD_WIDTH - sizeof(BITMAP_BatteryLevel5); - const uint8_t *pBitmap = NULL; - switch (Level) + uint8_t bitmap[sizeof(BITMAP_BatteryLevel1)]; + +#if 1 + + if (level >= 2) { - default: - case 0: break; - case 1: pBitmap = BITMAP_BatteryLevel1; break; - case 2: pBitmap = BITMAP_BatteryLevel2; break; - case 3: pBitmap = BITMAP_BatteryLevel3; break; - case 4: pBitmap = BITMAP_BatteryLevel4; break; - case 5: pBitmap = BITMAP_BatteryLevel5; break; + memmove(bitmap, BITMAP_BatteryLevel1, sizeof(BITMAP_BatteryLevel1)); + #ifndef ENABLE_REVERSE_BAT_SYMBOL + uint8_t *pb = bitmap + sizeof(BITMAP_BatteryLevel1); + if (level >= 2) + memmove(pb - 4, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + if (level >= 5) + memmove(pb - 7, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + if (level >= 7) + memmove(pb - 10, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + if (level >= 9) + memmove(pb - 13, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + #else + if (level >= 2) + memmove(bitmap + 3, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + if (level >= 5) + memmove(bitmap + 6, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + if (level >= 7) + memmove(bitmap + 9, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + if (level >= 9) + memmove(bitmap + 12, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + #endif } - // col lne, siz, bm - ST7565_DrawLine(x, 0, 18, pBitmap); + else + if (blink == 1) + memmove(bitmap, BITMAP_BatteryLevel1, sizeof(BITMAP_BatteryLevel1)); + else + memset(bitmap, 0, sizeof(bitmap)); + +#else + + if (level > 0) + { + const uint8_t lev = (level <= 11) ? level : 11; + + memmove(bitmap, BITMAP_BatteryLevel1, sizeof(BITMAP_BatteryLevel1)); + + #ifdef ENABLE_REVERSE_BAT_SYMBOL + for (uint8_t i = 0; i < lev; i++) + bitmap[3 + i] = (i & 1u) ? 0b01011101 : 0b01011101; + #else + for (uint8_t i = 0; i < lev; i++) + bitmap[sizeof(bitmap) - 3 - i] = (i & 1u) ? 0b01011101 : 0b01011101; + #endif + } + else + memset(bitmap, 0, sizeof(bitmap)); + +#endif + + // col lne, siz, bm + ST7565_DrawLine(LCD_WIDTH - sizeof(bitmap), 0, sizeof(bitmap), bitmap); } } diff --git a/ui/battery.h b/ui/battery.h index 0071870..92e1f47 100644 --- a/ui/battery.h +++ b/ui/battery.h @@ -19,7 +19,7 @@ #include -void UI_DisplayBattery(uint8_t Level); +void UI_DisplayBattery(const uint8_t Level, const uint8_t blink); #endif diff --git a/ui/main.c b/ui/main.c index 8fc07d5..11288d0 100644 --- a/ui/main.c +++ b/ui/main.c @@ -504,8 +504,11 @@ void UI_DisplayMain(void) case FUNCTION_TRANSMIT: case FUNCTION_BAND_SCOPE: case FUNCTION_POWER_SAVE: + break; + case FUNCTION_FOREGROUND: break; + case FUNCTION_RECEIVE: case FUNCTION_MONITOR: case FUNCTION_INCOMING: diff --git a/ui/menu.c b/ui/menu.c index 145133e..39859f6 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -433,12 +433,6 @@ void UI_DisplayMenu(void) strcpy(String, (gSubMenuSelection == 0) ? "FM" : "AM"); break; - #ifdef ENABLE_AM_FIX - case MENU_AM_FIX: - strcpy(String, (gSubMenuSelection == 0) ? "OFF" : "YES'ish"); - break; - #endif - #ifdef ENABLE_AM_FIX_TEST1 case MENU_AM_FIX_TEST1: strcpy(String, gSubMenu_AM_fix_test1[gSubMenuSelection]); @@ -455,6 +449,9 @@ void UI_DisplayMenu(void) break; #endif + #ifdef ENABLE_AM_FIX + case MENU_AM_FIX: + #endif case MENU_BCL: case MENU_BEEP: case MENU_S_ADD1: diff --git a/ui/status.c b/ui/status.c index 5f32b8a..bc2dd6a 100644 --- a/ui/status.c +++ b/ui/status.c @@ -171,6 +171,7 @@ void UI_DisplayStatus(const bool test_display) { const uint16_t voltage = (gBatteryVoltageAverage < gMin_bat_v) ? gMin_bat_v : gBatteryVoltageAverage; const uint16_t percent = (100 * (voltage - gMin_bat_v)) / (gMax_bat_v - gMin_bat_v); +// const uint16_t percent = gBatteryDisplayLevel; sprintf(s, "%u%%", percent); space_needed = (7 * strlen(s)); if (x2 >= (x1 + space_needed)) @@ -181,7 +182,7 @@ void UI_DisplayStatus(const bool test_display) } // move to right side of the screen - x = LCD_WIDTH - sizeof(BITMAP_BatteryLevel5) - sizeof(BITMAP_USB_C); + x = LCD_WIDTH - sizeof(BITMAP_BatteryLevel1) - sizeof(BITMAP_USB_C); // USB-C charge indicator if (gChargingWithTypeC || test_display) @@ -189,20 +190,54 @@ void UI_DisplayStatus(const bool test_display) x += sizeof(BITMAP_USB_C); // BATTERY LEVEL indicator - if (gBatteryDisplayLevel >= 5 || test_display) - memmove(line + x, BITMAP_BatteryLevel5, sizeof(BITMAP_BatteryLevel5)); - else - if (gBatteryDisplayLevel >= 4) - memmove(line + x, BITMAP_BatteryLevel4, sizeof(BITMAP_BatteryLevel4)); - else - if (gBatteryDisplayLevel >= 3) - memmove(line + x, BITMAP_BatteryLevel3, sizeof(BITMAP_BatteryLevel3)); - else - if (gBatteryDisplayLevel >= 2) - memmove(line + x, BITMAP_BatteryLevel2, sizeof(BITMAP_BatteryLevel2)); +#if 1 + if (gBatteryDisplayLevel >= 2 && !gLowBattery) + { + line += x; + memmove(line, BITMAP_BatteryLevel1, sizeof(BITMAP_BatteryLevel1)); + #ifndef ENABLE_REVERSE_BAT_SYMBOL + line += sizeof(BITMAP_BatteryLevel1); + if (gBatteryDisplayLevel >= 2) + memmove(line - 4, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + if (gBatteryDisplayLevel >= 5) + memmove(line - 7, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + if (gBatteryDisplayLevel >= 7) + memmove(line - 10, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + if (gBatteryDisplayLevel >= 9) + memmove(line - 13, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + #else + if (gBatteryDisplayLevel >= 2) + memmove(line + 3, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + if (gBatteryDisplayLevel >= 5) + memmove(line + 6, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + if (gBatteryDisplayLevel >= 7) + memmove(line + 9, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + if (gBatteryDisplayLevel >= 9) + memmove(line + 12, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel)); + #endif + } else if (gLowBatteryBlink == 1) memmove(line + x, BITMAP_BatteryLevel1, sizeof(BITMAP_BatteryLevel1)); +#else +// UI_DisplayBattery(gBatteryDisplayLevel); + + line += x; + if (gBatteryDisplayLevel > 0) + { + const uint8_t level = (gBatteryDisplayLevel <= 11) ? gBatteryDisplayLevel : 11; + memmove(line, BITMAP_BatteryLevel1, sizeof(BITMAP_BatteryLevel1)); + #ifdef ENABLE_REVERSE_BAT_SYMBOL + for (uint8_t i = 0; i < level; i++) + line[3 + i] = (i & 1u) ? 0b01011101 : 0b01011101; + #else + for (uint8_t i = 0; i < level; i++) + line[sizeof(BITMAP_BatteryLevel1) - 3 - i] = (i & 1u) ? 0b01011101 : 0b01011101; + #endif + } + else + memset(line, 0, sizeof(BITMAP_BatteryLevel1)); +#endif // ************** diff --git a/version.c b/version.c index 78c896d..7615aa5 100644 --- a/version.c +++ b/version.c @@ -2,7 +2,7 @@ #ifdef GIT_HASH #define VER GIT_HASH #else - #define VER "230924" + #define VER "230925" #endif const char Version[] = "OEFW-"VER; diff --git a/win_make.bat b/win_make.bat index 0d4e330..bc29e68 100644 --- a/win_make.bat +++ b/win_make.bat @@ -1,10 +1,14 @@ -:: Cmpile directly in windows without the need of a linux virtual machine: +@echo off + +:: Compile directly in windows without the need of a linux virtual machine: :: :: 1. Download and install "gcc-arm-none-eabi-10.3-2021.10-win32.exe" from https://developer.arm.com/downloads/-/gnu-rm :: 2. Download and install "gnu_make-3.81.exe" from https://gnuwin32.sourceforge.net/packages/make.htm +:: :: 3. You may (or not) need to manualy add gcc path to you OS environment PATH, ie .. :: C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin +:: :: 4. You may (or not) need to reboot your PC after installing the above :: :: Then you can run this bat from the directory you saved this source code too. @@ -15,14 +19,24 @@ :: delete any left over files from any previous compile del /S /Q *.o >nul 2>nul del /S /Q *.d >nul 2>nul +del /Q firmware >nul 2>nul del /Q *.bin >nul 2>nul -:: do the compile ! -"C:\Program Files (x86)\GnuWin32\bin\make" +:: You may need to edit/change these three paths to suit your setup +:: +@set PATH="C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin";%PATH% +@set PATH="C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\arm-none-eabi\bin";%PATH% +@set PATH="C:\Program Files (x86)\GnuWin32\bin\";%PATH% + +:: do the compile +::"C:\Program Files (x86)\GnuWin32\bin\make" +make :: delete the unused created when compiling files +:: del /S /Q *.o >nul 2>nul del /S /Q *.d >nul 2>nul +del /Q firmware >nul 2>nul :: If you have python installed, you can create a 'packed' .bin from the compiled firmware.bin file. :: The Quansheng windows upload-to-radio program requires a 'packed' .bin file.