0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 22:31:25 +03:00

Disable scan timeout compile option, updated win_make.bat to help path problems

This commit is contained in:
OneOfEleven 2023-09-25 07:12:08 +01:00
parent aa69a04310
commit ed321778c0
20 changed files with 247 additions and 289 deletions

View File

@ -22,6 +22,7 @@ ENABLE_BOOT_BEEPS := 0
ENABLE_COMPANDER := 1 ENABLE_COMPANDER := 1
ENABLE_SHOW_CHARGE_LEVEL := 0 ENABLE_SHOW_CHARGE_LEVEL := 0
ENABLE_REVERSE_BAT_SYMBOL := 1 ENABLE_REVERSE_BAT_SYMBOL := 1
ENABLE_NO_SCAN_TIMEOUT := 1
ENABLE_AM_FIX := 1 ENABLE_AM_FIX := 1
ENABLE_AM_FIX_SHOW_DATA := 1 ENABLE_AM_FIX_SHOW_DATA := 1
ENABLE_SQUELCH1_LOWER := 0 ENABLE_SQUELCH1_LOWER := 0
@ -204,6 +205,9 @@ endif
ifeq ($(ENABLE_REVERSE_BAT_SYMBOL),1) ifeq ($(ENABLE_REVERSE_BAT_SYMBOL),1)
CFLAGS += -DENABLE_REVERSE_BAT_SYMBOL CFLAGS += -DENABLE_REVERSE_BAT_SYMBOL
endif endif
ifeq ($(ENABLE_NO_SCAN_TIMEOUT),1)
CFLAGS += -DENABLE_NO_SCAN_TIMEOUT
endif
ifeq ($(ENABLE_AM_FIX),1) ifeq ($(ENABLE_AM_FIX),1)
CFLAGS += -DENABLE_AM_FIX CFLAGS += -DENABLE_AM_FIX
endif endif

View File

@ -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 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 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 4. You may (or not) need to reboot your PC after installing the above
``` ```

View File

@ -297,14 +297,11 @@ const uint8_t orig_pga = 6; // -3dB
// used to simply detect we've changed our table index/register settings // used to simply detect we've changed our table index/register settings
unsigned int am_fix_gain_table_index_prev[2] = {0, 0}; unsigned int am_fix_gain_table_index_prev[2] = {0, 0};
// moving average RSSI buffer struct
// helps smooth out any spikey RSSI readings {
struct { unsigned int count;
unsigned int count; // uint16_t level;
unsigned int index; // read/write buffer index } rssi[2];
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};
// to help reduce gain hunting, provides a peak hold time delay // to help reduce gain hunting, provides a peak hold time delay
unsigned int am_gain_hold_counter[2] = {0, 0}; 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) void AM_fix_reset(const int vfo)
{ // reset the AM fixer { // reset the AM fixer
// reset the moving average filter rssi[vfo].count = 0;
memset(&moving_avg_rssi[vfo], 0, sizeof(moving_avg_rssi[vfo])); rssi[vfo].level = 0;
am_gain_hold_counter[vfo] = 0; am_gain_hold_counter[vfo] = 0;
@ -352,6 +349,8 @@ const uint8_t orig_pga = 6; // -3dB
case FUNCTION_TRANSMIT: case FUNCTION_TRANSMIT:
case FUNCTION_BAND_SCOPE: case FUNCTION_BAND_SCOPE:
case FUNCTION_POWER_SAVE: case FUNCTION_POWER_SAVE:
return;
case FUNCTION_FOREGROUND: case FUNCTION_FOREGROUND:
return; return;
@ -362,21 +361,16 @@ const uint8_t orig_pga = 6; // -3dB
break; break;
} }
// sample the current RSSI level // sample the current RSSI level, average it with the previous rssi
uint16_t rssi = BK4819_GetRSSI(); // supposed 9-bit value (0 .. 511) - never seen that though if (rssi[vfo].count < 1)
{
#if 1 rssi[vfo].level = BK4819_GetRSSI();
// compute moving average RSSI - helps smooth any sharp spikes/troughs rssi[vfo].count++;
// 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)) else
moving_avg_rssi[vfo].count++; {
moving_avg_rssi[vfo].sum -= moving_avg_rssi[vfo].samples[moving_avg_rssi[vfo].index]; // subtract the oldest sample rssi[vfo].level = (rssi[vfo].level + BK4819_GetRSSI()) >> 1;
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
#ifdef ENABLE_AM_FIX_TEST1 #ifdef ENABLE_AM_FIX_TEST1
@ -388,7 +382,7 @@ const uint8_t orig_pga = 6; // -3dB
{ {
if (--am_gain_hold_counter[vfo] > 0) 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; return;
} }
} }
@ -399,7 +393,7 @@ const uint8_t orig_pga = 6; // -3dB
// automatically choose a front end gain setting by monitoring the RSSI // automatically choose a front end gain setting by monitoring the RSSI
if (rssi > desired_rssi) if (rssi[vfo].level > desired_rssi)
{ // decrease gain { // decrease gain
if (am_fix_gain_table_index[vfo] > 1) 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) if (am_gain_hold_counter[vfo] == 0)
// hold has been released, we're free to increase gain // 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 // increase gain
if (am_fix_gain_table_index[vfo] < (ARRAY_SIZE(am_fix_gain_table) - 1)) if (am_fix_gain_table_index[vfo] < (ARRAY_SIZE(am_fix_gain_table) - 1))
am_fix_gain_table_index[vfo]++; am_fix_gain_table_index[vfo]++;
if (am_fix_gain_table_index[vfo] == am_fix_gain_table_index_prev[vfo]) if (am_fix_gain_table_index[vfo] == am_fix_gain_table_index_prev[vfo])
{ // no gain changes have been made { // 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; return;
} }
@ -442,7 +436,7 @@ const uint8_t orig_pga = 6; // -3dB
rssi_db_gain_diff[vfo] = am_dB_gain - orig_dB_gain; rssi_db_gain_diff[vfo] = am_dB_gain - orig_dB_gain;
// shall we or sharn't we ? // 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 // remember the new table index
@ -470,7 +464,7 @@ const uint8_t orig_pga = 6; // -3dB
// compute the current front end gain // 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]; 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 #endif

View File

@ -187,6 +187,9 @@ void ACTION_Scan(bool bRestart)
AUDIO_PlaySingleVoice(true); AUDIO_PlaySingleVoice(true);
#endif #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 // let the user see DW is not active
gDualWatchActive = false; gDualWatchActive = false;
gUpdateStatus = true; gUpdateStatus = true;

View File

@ -65,6 +65,19 @@
static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld); 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) static void APP_CheckForIncoming(void)
{ {
if (!g_SquelchLost) if (!g_SquelchLost)
@ -415,10 +428,11 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix)
#endif #endif
#ifdef ENABLE_AM_FIX #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 AM_fix_reset(gEeprom.RX_CHANNEL); // TODO: only reset it when moving channel/frequency
#endif #endif
// clear the other vfo's rssi level (to hide the antenna symbol)
gVFO_RSSI_bar_level[gEeprom.RX_CHANNEL == 0] = 0; gVFO_RSSI_bar_level[gEeprom.RX_CHANNEL == 0] = 0;
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); 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) if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF)
{ // dual watch mode, toggle between the two VFO's { // dual watch mode, toggle between the two VFO's
DUALWATCH_Alternate(); DUALWATCH_Alternate();
gUpdateRSSI = false; 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) if (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF || gScanState != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF || gUpdateRSSI)
{ // dual watch mode, go back to sleep { // dual watch mode, go back to sleep
// sample the RSSI updateRSSI(gEeprom.RX_CHANNEL);
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);
// go back to sleep // go back to sleep
@ -1156,8 +1162,7 @@ void APP_Update(void)
} }
else else
{ // no yet in power save mode {
// toggle between the two VFO's // toggle between the two VFO's
DUALWATCH_Alternate(); DUALWATCH_Alternate();
@ -1326,7 +1331,7 @@ void APP_TimeSlice10ms(void)
#endif #endif
#ifdef ENABLE_AM_FIX #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); AM_fix_adjust_frontEnd_10ms(gEeprom.RX_CHANNEL);
#endif #endif
@ -1659,16 +1664,7 @@ void APP_TimeSlice500ms(void)
gUpdateStatus = true; gUpdateStatus = true;
if (gCurrentFunction != FUNCTION_POWER_SAVE) if (gCurrentFunction != FUNCTION_POWER_SAVE)
{ updateRSSI(gEeprom.RX_CHANNEL);
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);
}
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
if ((gFM_ScanState == FM_SCAN_OFF || gAskToSave) && gCssScanMode == CSS_SCAN_MODE_OFF) if ((gFM_ScanState == FM_SCAN_OFF || gAskToSave) && gCssScanMode == CSS_SCAN_MODE_OFF)
@ -1759,7 +1755,7 @@ void APP_TimeSlice500ms(void)
{ {
gLowBatteryBlink = ++gLowBatteryCountdown & 1; gLowBatteryBlink = ++gLowBatteryCountdown & 1;
UI_DisplayBattery(gLowBatteryCountdown); UI_DisplayBattery(0, gLowBatteryBlink);
if (gCurrentFunction != FUNCTION_TRANSMIT) if (gCurrentFunction != FUNCTION_TRANSMIT)
{ // not transmitting { // not transmitting
@ -1808,7 +1804,10 @@ void APP_TimeSlice500ms(void)
if (gScreenToDisplay == DISPLAY_SCANNER && gScannerEditState == 0 && gScanCssState < SCAN_CSS_STATE_FOUND) if (gScreenToDisplay == DISPLAY_SCANNER && gScannerEditState == 0 && gScanCssState < SCAN_CSS_STATE_FOUND)
{ {
if (++gScanProgressIndicator > 32) gScanProgressIndicator++;
#ifndef ENABLE_NO_SCAN_TIMEOUT
if (gScanProgressIndicator > 32)
{ {
if (gScanCssState == SCAN_CSS_STATE_SCANNING && !gScanSingleFrequency) if (gScanCssState == SCAN_CSS_STATE_SCANNING && !gScanSingleFrequency)
gScanCssState = SCAN_CSS_STATE_FOUND; gScanCssState = SCAN_CSS_STATE_FOUND;
@ -1817,6 +1816,7 @@ void APP_TimeSlice500ms(void)
gUpdateStatus = true; gUpdateStatus = true;
} }
#endif
gUpdateDisplay = true; gUpdateDisplay = true;
} }

174
bitmaps.c
View File

@ -29,6 +29,12 @@ const uint8_t BITMAP_PowerSave[8] =
#endif #endif
}; };
const uint8_t BITMAP_BatteryLevel[2] =
{
0b01011101,
0b01011101
};
#ifndef ENABLE_REVERSE_BAT_SYMBOL #ifndef ENABLE_REVERSE_BAT_SYMBOL
// Quansheng way (+ pole to the left) // Quansheng way (+ pole to the left)
const uint8_t BITMAP_BatteryLevel1[17] = const uint8_t BITMAP_BatteryLevel1[17] =
@ -51,90 +57,6 @@ const uint8_t BITMAP_PowerSave[8] =
0b01000001, 0b01000001,
0b01111111 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 #else
// reversed (+ pole to the right) // reversed (+ pole to the right)
const uint8_t BITMAP_BatteryLevel1[17] = const uint8_t BITMAP_BatteryLevel1[17] =
@ -157,90 +79,6 @@ const uint8_t BITMAP_PowerSave[8] =
0b00100010, 0b00100010,
0b00111110 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 #endif
const uint8_t BITMAP_USB_C[9] = const uint8_t BITMAP_USB_C[9] =

View File

@ -6,6 +6,7 @@
extern const uint8_t BITMAP_PowerSave[8]; 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_BatteryLevel1[17];
extern const uint8_t BITMAP_BatteryLevel2[17]; extern const uint8_t BITMAP_BatteryLevel2[17];
extern const uint8_t BITMAP_BatteryLevel3[17]; extern const uint8_t BITMAP_BatteryLevel3[17];

View File

@ -574,7 +574,8 @@ void BK4819_SetFilterBandwidth(const BK4819_FilterBandwidth_t Bandwidth, const b
BK4819_WriteRegister(BK4819_REG_43, BK4819_WriteRegister(BK4819_REG_43,
(0u << 15) | // 0 (0u << 15) | // 0
(3u << 12) | // 3 RF filter bandwidth (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 (0u << 6) | // 0 AFTxLPF2 filter Band Width
(2u << 4) | // 2 BW Mode Selection (2u << 4) | // 2 BW Mode Selection
(1u << 3) | // 1 (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 BK4819_WriteRegister(BK4819_REG_43, // 0x4048); // 0 100 000 001 00 1 0 00
(0u << 15) | // 0 (0u << 15) | // 0
(3u << 12) | // 4 RF filter bandwidth (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 (1u << 6) | // 1 AFTxLPF2 filter Band Width
(0u << 4) | // 0 BW Mode Selection (0u << 4) | // 0 BW Mode Selection
(1u << 3) | // 1 (1u << 3) | // 1

Binary file not shown.

Binary file not shown.

View File

@ -36,28 +36,43 @@ volatile uint16_t gPowerSave_10ms;
void BATTERY_GetReadings(bool bDisplayBatteryLevel) void BATTERY_GetReadings(bool bDisplayBatteryLevel)
{ {
uint8_t PreviousBatteryLevel = gBatteryDisplayLevel; const uint8_t PreviousBatteryLevel = gBatteryDisplayLevel;
uint16_t Voltage = (gBatteryVoltages[0] + gBatteryVoltages[1] + gBatteryVoltages[2] + gBatteryVoltages[3]) / 4; 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; gBatteryDisplayLevel = 6;
else else
if (gBatteryCalibration[4] < Voltage) if (Voltage >= gBatteryCalibration[2])
gBatteryDisplayLevel = 5; gBatteryDisplayLevel = 5;
else else
if (gBatteryCalibration[3] < Voltage) if (Voltage >= ((gBatteryCalibration[1] + gBatteryCalibration[2]) / 2))
gBatteryDisplayLevel = 4; gBatteryDisplayLevel = 4;
else else
if (gBatteryCalibration[2] < Voltage) if (Voltage >= gBatteryCalibration[1])
gBatteryDisplayLevel = 3; gBatteryDisplayLevel = 3;
else else
if (gBatteryCalibration[1] < Voltage) if (Voltage >= ((gBatteryCalibration[0] + gBatteryCalibration[1]) / 2))
gBatteryDisplayLevel = 2; gBatteryDisplayLevel = 2;
else else
if (gBatteryCalibration[0] < Voltage) if (Voltage >= gBatteryCalibration[0])
gBatteryDisplayLevel = 1; gBatteryDisplayLevel = 1;
else
gBatteryDisplayLevel = 0;
gBatteryVoltageAverage = (Voltage * 760) / gBatteryCalibration[3]; gBatteryVoltageAverage = (Voltage * 760) / gBatteryCalibration[3];
@ -71,6 +86,7 @@ void BATTERY_GetReadings(bool bDisplayBatteryLevel)
gUpdateStatus = true; gUpdateStatus = true;
gUpdateDisplay = true; gUpdateDisplay = true;
} }
gChargingWithTypeC = false; gChargingWithTypeC = false;
} }
else else
@ -81,6 +97,7 @@ void BATTERY_GetReadings(bool bDisplayBatteryLevel)
gUpdateDisplay = true; gUpdateDisplay = true;
BACKLIGHT_TurnOn(); BACKLIGHT_TurnOn();
} }
gChargingWithTypeC = true; gChargingWithTypeC = true;
} }
@ -93,9 +110,11 @@ void BATTERY_GetReadings(bool bDisplayBatteryLevel)
else else
{ {
gLowBattery = false; gLowBattery = false;
if (bDisplayBatteryLevel) if (bDisplayBatteryLevel)
UI_DisplayBattery(gBatteryDisplayLevel); UI_DisplayBattery(gBatteryDisplayLevel, gLowBatteryBlink);
} }
gLowBatteryCountdown = 0; gLowBatteryCountdown = 0;
} }
} }

3
misc.c
View File

@ -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_save1_10ms = 100 / 10; // 100ms
const uint16_t power_save2_10ms = 200 / 10; // 200ms 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 = 660; // 6.6V
//const uint16_t gMin_bat_v = 690; // 6.9V
const uint32_t gDefaultAesKey[4] = {0x4AA5CC60, 0x0312CC5F, 0xFFD2DABB, 0x6BBA7F92}; const uint32_t gDefaultAesKey[4] = {0x4AA5CC60, 0x0312CC5F, 0xFFD2DABB, 0x6BBA7F92};

View File

@ -972,7 +972,8 @@ void RADIO_PrepareTX(void)
if (gBatteryDisplayLevel == 0) if (gBatteryDisplayLevel == 0)
State = VFO_STATE_BAT_LOW; State = VFO_STATE_BAT_LOW;
else else
if (gBatteryDisplayLevel >= 6) // if (gBatteryDisplayLevel >= 6)
if (gBatteryDisplayLevel >= 11)
State = VFO_STATE_VOLTAGE_HIGH; State = VFO_STATE_VOLTAGE_HIGH;
else else
goto Skip; goto Skip;

View File

@ -15,28 +15,73 @@
*/ */
#include <stddef.h> #include <stddef.h>
#include <string.h>
#include "bitmaps.h" #include "bitmaps.h"
#include "driver/st7565.h" #include "driver/st7565.h"
#include "functions.h" #include "functions.h"
#include "ui/battery.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); uint8_t bitmap[sizeof(BITMAP_BatteryLevel1)];
const uint8_t *pBitmap = NULL;
switch (Level) #if 1
if (level >= 2)
{ {
default: memmove(bitmap, BITMAP_BatteryLevel1, sizeof(BITMAP_BatteryLevel1));
case 0: break; #ifndef ENABLE_REVERSE_BAT_SYMBOL
case 1: pBitmap = BITMAP_BatteryLevel1; break; uint8_t *pb = bitmap + sizeof(BITMAP_BatteryLevel1);
case 2: pBitmap = BITMAP_BatteryLevel2; break; if (level >= 2)
case 3: pBitmap = BITMAP_BatteryLevel3; break; memmove(pb - 4, BITMAP_BatteryLevel, sizeof(BITMAP_BatteryLevel));
case 4: pBitmap = BITMAP_BatteryLevel4; break; if (level >= 5)
case 5: pBitmap = BITMAP_BatteryLevel5; break; 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
} }
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 // col lne, siz, bm
ST7565_DrawLine(x, 0, 18, pBitmap); ST7565_DrawLine(LCD_WIDTH - sizeof(bitmap), 0, sizeof(bitmap), bitmap);
} }
} }

View File

@ -19,7 +19,7 @@
#include <stdint.h> #include <stdint.h>
void UI_DisplayBattery(uint8_t Level); void UI_DisplayBattery(const uint8_t Level, const uint8_t blink);
#endif #endif

View File

@ -504,8 +504,11 @@ void UI_DisplayMain(void)
case FUNCTION_TRANSMIT: case FUNCTION_TRANSMIT:
case FUNCTION_BAND_SCOPE: case FUNCTION_BAND_SCOPE:
case FUNCTION_POWER_SAVE: case FUNCTION_POWER_SAVE:
break;
case FUNCTION_FOREGROUND: case FUNCTION_FOREGROUND:
break; break;
case FUNCTION_RECEIVE: case FUNCTION_RECEIVE:
case FUNCTION_MONITOR: case FUNCTION_MONITOR:
case FUNCTION_INCOMING: case FUNCTION_INCOMING:

View File

@ -433,12 +433,6 @@ void UI_DisplayMenu(void)
strcpy(String, (gSubMenuSelection == 0) ? "FM" : "AM"); strcpy(String, (gSubMenuSelection == 0) ? "FM" : "AM");
break; break;
#ifdef ENABLE_AM_FIX
case MENU_AM_FIX:
strcpy(String, (gSubMenuSelection == 0) ? "OFF" : "YES'ish");
break;
#endif
#ifdef ENABLE_AM_FIX_TEST1 #ifdef ENABLE_AM_FIX_TEST1
case MENU_AM_FIX_TEST1: case MENU_AM_FIX_TEST1:
strcpy(String, gSubMenu_AM_fix_test1[gSubMenuSelection]); strcpy(String, gSubMenu_AM_fix_test1[gSubMenuSelection]);
@ -455,6 +449,9 @@ void UI_DisplayMenu(void)
break; break;
#endif #endif
#ifdef ENABLE_AM_FIX
case MENU_AM_FIX:
#endif
case MENU_BCL: case MENU_BCL:
case MENU_BEEP: case MENU_BEEP:
case MENU_S_ADD1: case MENU_S_ADD1:

View File

@ -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 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 = (100 * (voltage - gMin_bat_v)) / (gMax_bat_v - gMin_bat_v);
// const uint16_t percent = gBatteryDisplayLevel;
sprintf(s, "%u%%", percent); sprintf(s, "%u%%", percent);
space_needed = (7 * strlen(s)); space_needed = (7 * strlen(s));
if (x2 >= (x1 + space_needed)) if (x2 >= (x1 + space_needed))
@ -181,7 +182,7 @@ void UI_DisplayStatus(const bool test_display)
} }
// move to right side of the screen // 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 // USB-C charge indicator
if (gChargingWithTypeC || test_display) if (gChargingWithTypeC || test_display)
@ -189,20 +190,54 @@ void UI_DisplayStatus(const bool test_display)
x += sizeof(BITMAP_USB_C); x += sizeof(BITMAP_USB_C);
// BATTERY LEVEL indicator // BATTERY LEVEL indicator
if (gBatteryDisplayLevel >= 5 || test_display) #if 1
memmove(line + x, BITMAP_BatteryLevel5, sizeof(BITMAP_BatteryLevel5)); if (gBatteryDisplayLevel >= 2 && !gLowBattery)
else {
if (gBatteryDisplayLevel >= 4) line += x;
memmove(line + x, BITMAP_BatteryLevel4, sizeof(BITMAP_BatteryLevel4)); memmove(line, BITMAP_BatteryLevel1, sizeof(BITMAP_BatteryLevel1));
else #ifndef ENABLE_REVERSE_BAT_SYMBOL
if (gBatteryDisplayLevel >= 3) line += sizeof(BITMAP_BatteryLevel1);
memmove(line + x, BITMAP_BatteryLevel3, sizeof(BITMAP_BatteryLevel3));
else
if (gBatteryDisplayLevel >= 2) if (gBatteryDisplayLevel >= 2)
memmove(line + x, BITMAP_BatteryLevel2, sizeof(BITMAP_BatteryLevel2)); 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 else
if (gLowBatteryBlink == 1) if (gLowBatteryBlink == 1)
memmove(line + x, BITMAP_BatteryLevel1, sizeof(BITMAP_BatteryLevel1)); 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
// ************** // **************

View File

@ -2,7 +2,7 @@
#ifdef GIT_HASH #ifdef GIT_HASH
#define VER GIT_HASH #define VER GIT_HASH
#else #else
#define VER "230924" #define VER "230925"
#endif #endif
const char Version[] = "OEFW-"VER; const char Version[] = "OEFW-"VER;

View File

@ -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 :: 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 :: 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 .. :: 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 :: 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 :: 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. :: 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 :: delete any left over files from any previous compile
del /S /Q *.o >nul 2>nul del /S /Q *.o >nul 2>nul
del /S /Q *.d >nul 2>nul del /S /Q *.d >nul 2>nul
del /Q firmware >nul 2>nul
del /Q *.bin >nul 2>nul del /Q *.bin >nul 2>nul
:: do the compile ! :: You may need to edit/change these three paths to suit your setup
"C:\Program Files (x86)\GnuWin32\bin\make" ::
@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 :: delete the unused created when compiling files
::
del /S /Q *.o >nul 2>nul del /S /Q *.o >nul 2>nul
del /S /Q *.d >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. :: 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. :: The Quansheng windows upload-to-radio program requires a 'packed' .bin file.