Fix the spectrum labels, bandscope build, OOK on F+7, save flash

- Spectrum: GUI_DisplaySmallest() now draws with gFontSmall (7 px per
  character) for the status bar; the spectrum layout needs the 3x5 font
  (4 px), so it gets its own renderer again. Its labels were overlapping.
- make BANDSCOPE=1: spectrum instead of the FM radio. Both do not fit in
  60 KB together (FM radio is 4.9 KB). Debug log off and -finline-limit=1
  in that edition; it fits with a few bytes to spare.
- OOK sender on F+7 / long 7 (the VOX key is free, VOX is not built);
  F+EXIT is back to only cancelling F.
- POCSAG deviation tuning keys behind POCSAG_DEVIATION_TUNING (default 0).
- Smaller code: shared end of SMS/POCSAG transmissions, non-inlined fast
  SPI wait, compact OOK field tables, sprintf message header, shorter OOK
  strings.
- Makefile: EXTRA_CFLAGS for passing defines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 01:24:16 +01:00
co-authored by Claude Opus 5.5
parent 183dd8fb0d
commit 4a99a21a21
11 changed files with 109 additions and 101 deletions

No files matched your search

+11
View File
@@ -15,6 +15,15 @@ ENABLE_TX1750 ?= 0
ENABLE_PWRON_PASSWORD ?= 0
ENABLE_FLASHLIGHT ?= 1
# Bandscope edition: make BANDSCOPE=1
# The spectrum and the FM radio do not fit in the flash together, so this build
# swaps the FM radio for the spectrum (and drops the POCSAG debug log).
ifeq ($(BANDSCOPE),1)
ENABLE_SPECTRUM := 1
ENABLE_FMRADIO := 0
EXTRA_CFLAGS += -DPOCSAG_DEBUG_UART=0 -finline-limit=1
endif
# ---- CUSTOM MODS ----
ENABLE_SPECTRUM ?= 0
ENABLE_BIG_FREQ ?= 0
@@ -290,6 +299,8 @@ endif
# catch any and all warnings
CFLAGS += -Wextra
# extra compiler flags from the command line, e.g. make EXTRA_CFLAGS=-DPOCSAG_DEBUG_UART=0
CFLAGS += $(EXTRA_CFLAGS)
#CFLAGS += -Wpedantic
CFLAGS += -DPRINTF_INCLUDE_CONFIG_H
-5
View File
@@ -1761,11 +1761,6 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
#else
if (gWasFKeyPressed && (Key == KEY_PTT || Key == KEY_EXIT || Key == KEY_SIDE1 || Key == KEY_SIDE2)) {
#endif
// F + EXIT on the main screen opens the OOK sender (handled here because the
// F state is cleared before the screen key handler runs)
if (Key == KEY_EXIT && bKeyPressed && !bKeyHeld && gScreenToDisplay == DISPLAY_MAIN)
gRequestDisplayScreen = DISPLAY_OOKSENDER;
// cancel the F-key
gWasFKeyPressed = false;
gUpdateStatus = true;
+27 -31
View File
@@ -92,6 +92,7 @@ static uint16_t POCSAG_Baud(void)
(2U << 4) | /* 25 kHz channel mode */ \
(1U << 3))
#if POCSAG_DEVIATION_TUNING
// Runtime-tunable TX deviation (REG_40<11:0>), keys 2/8 on the messages screen.
uint16_t gPocsagDeviation = POCSAG_DEVIATION;
@@ -110,6 +111,9 @@ void POCSAG_AdjustDeviation(const int delta)
UI_DisplayPopup(text);
gUpdateDisplay = true;
}
#else
#define gPocsagDeviation POCSAG_DEVIATION
#endif
static uint16_t POCSAG_Raw16(const uint16_t logical)
{
@@ -540,6 +544,27 @@ void MSG_EnableRX(const bool enable) {
}
}
// Common end of a data transmission (SMS and POCSAG): back to RX, FSK RX re-armed.
static void MSG_EndDataTransmission(const bool audioWasEnabled)
{
APP_EndTransmission();
FUNCTION_Select(FUNCTION_FOREGROUND);
gUpdateStatus = true;
gUpdateDisplay = true;
gFlagEndTransmission = false;
if (audioWasEnabled) {
AUDIO_AudioPathOn();
gEnableSpeaker = true;
BK4819_ExitTxMute();
}
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, false);
MSG_EnableRX(true);
gVfoConfigureMode = VFO_CONFIGURE;
dataPTR = gMessageText;
}
void MSG_POCSAGSend(const uint32_t ric, const char *text)
{
uint8_t frame[POCSAG_MAX_FRAME_SIZE];
@@ -613,22 +638,7 @@ void MSG_POCSAGSend(const uint32_t ric, const char *text)
for (unsigned int i = 0; i < ARRAY_SIZE(savedRegs); i++)
BK4819_WriteRegister(savedRegs[i], saved[i]);
APP_EndTransmission();
FUNCTION_Select(FUNCTION_FOREGROUND);
gUpdateStatus = true;
gUpdateDisplay = true;
gFlagEndTransmission = false;
if (audioWasEnabled) {
AUDIO_AudioPathOn();
gEnableSpeaker = true;
BK4819_ExitTxMute();
}
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, false);
MSG_EnableRX(true);
gVfoConfigureMode = VFO_CONFIGURE;
dataPTR = gMessageText;
MSG_EndDataTransmission(audioWasEnabled);
}
void MSG_FSKSendData(DataPacket *dataPacketIn) {
@@ -734,26 +744,12 @@ void MSG_FSKSendData(DataPacket *dataPacketIn) {
BK4819_WriteRegister(BK4819_REG_51, css_val);
SYSTEM_DelayMs(50);
APP_EndTransmission();
FUNCTION_Select(FUNCTION_FOREGROUND);
gUpdateStatus = true;
gUpdateDisplay = true;
gFlagEndTransmission = false;
if (isAudioOn) {
AUDIO_AudioPathOn();
gEnableSpeaker = true;
BK4819_ExitTxMute();
}
//if (!(dataPacketIn->flags & 0x64)) {
if (!(dataPacketIn->flags & 0x40)) {
gGotACK = false;
}
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, false);
MSG_EnableRX(true);
gVfoConfigureMode = VFO_CONFIGURE;
dataPTR = gMessageText;
MSG_EndDataTransmission(isAudioOn);
}
}
+7 -1
View File
@@ -135,8 +135,14 @@ void FSKModem_TimeSlice500ms(void);
// Transmit an alphanumeric POCSAG page to the given RIC.
void MSG_POCSAGSend(uint32_t ric, const char *text);
// POCSAG TX deviation (BK4819 REG_40<11:0>), adjustable at runtime for tuning.
// POCSAG TX deviation (BK4819 REG_40<11:0>). Build with -DPOCSAG_DEVIATION_TUNING=1
// to adjust it at runtime with keys 2 / 8 on the messages screen.
#ifndef POCSAG_DEVIATION_TUNING
#define POCSAG_DEVIATION_TUNING 0
#endif
#if POCSAG_DEVIATION_TUNING
extern uint16_t gPocsagDeviation;
void POCSAG_AdjustDeviation(int delta);
#endif
#endif //UV_K5_FIRMWARE_CUSTOM_FSKMODEM_H
+2 -5
View File
@@ -250,8 +250,8 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) {
case KEY_7:
#ifdef ENABLE_VOX
ACTION_Vox();
//#else
// toggle_chan_scanlist();
#else
gRequestDisplayScreen = DISPLAY_OOKSENDER; // the VOX key is free: OOK sender
#endif
break;
@@ -575,9 +575,6 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
}
static void MAIN_Key_EXIT(bool bKeyPressed, bool bKeyHeld) {
// F + EXIT (OOK sender) is handled in APP ProcessKey, the F state is cleared before this runs
if (gRequestDisplayScreen == DISPLAY_OOKSENDER)
return;
if (!bKeyHeld && bKeyPressed) { // exit key pressed
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
+2
View File
@@ -142,6 +142,7 @@ void MESSAGES_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
return;
}
gKeyTimeout = 1;
#if POCSAG_DEVIATION_TUNING
// POCSAG deviation tuning: 2 = more, 8 = less (send a page and check it on an SDR)
if (MODEM_IS_POCSAG(gEeprom.FSKMode) && gEnteringSMS == SMS_NOT_ENTERING &&
(Key == KEY_2 || Key == KEY_8)) {
@@ -149,6 +150,7 @@ void MESSAGES_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
POCSAG_AdjustDeviation(Key == KEY_2 ? 0x40 : -0x40);
return;
}
#endif
if (gEnteringSMS != SMS_NOT_ENTERING && Key <= KEY_9) {
if (!bKeyHeld) {
if (!dataPTR || dataPTR < gMessageText) {
+28 -16
View File
@@ -46,25 +46,37 @@ static const OOK_RcProtocol_t rcProtocols[7] = {
{150, {2, 62}, {1, 6}, {6, 1}, false}, // 7: HS2303-PT
};
static const char *const fieldLabels[OOKSENDER_PROTO_END][OOK_FIELD_COUNT] = {
[OOKSENDER_PROTO_PT2262] = {"Code", NULL, NULL, "Pulse", "Repeat"},
[OOKSENDER_PROTO_EV1527] = {"ID", "Key", NULL, "Pulse", "Repeat"},
[OOKSENDER_PROTO_RCSWITCH] = {"Code", "Bits", "Proto", "Pulse", "Repeat"},
[OOKSENDER_PROTO_INTERTECHNO] = {"ID", "Unit", "On", "Pulse", "Repeat"},
[OOKSENDER_PROTO_MANCHESTER] = {"Code", "Bits", NULL, "Half", "Repeat"},
// Field labels per protocol, index into labelText (0 = field not used)
static const char labelText[][7] = {"", "Code", "ID", "Key", "Bits", "Proto", "Unit", "On", "Pulse", "Half", "Repeat"};
static const uint8_t fieldLabels[OOKSENDER_PROTO_END][OOK_FIELD_COUNT] = {
[OOKSENDER_PROTO_PT2262] = {1, 0, 0, 8, 10},
[OOKSENDER_PROTO_EV1527] = {2, 3, 0, 8, 10},
[OOKSENDER_PROTO_RCSWITCH] = {1, 4, 5, 8, 10},
[OOKSENDER_PROTO_INTERTECHNO] = {2, 6, 7, 8, 10},
[OOKSENDER_PROTO_MANCHESTER] = {1, 4, 0, 9, 10},
};
static const uint32_t fieldMax[OOKSENDER_PROTO_END][OOK_FIELD_COUNT] = {
[OOKSENDER_PROTO_PT2262] = {0x00FFFFFF, PT2262_MAX_TRITS, 0, 5000, 100},
[OOKSENDER_PROTO_EV1527] = {0x000FFFFF, 15, 0, 5000, 100},
[OOKSENDER_PROTO_RCSWITCH] = {0xFFFFFFFF, 32, 7, 5000, 100},
[OOKSENDER_PROTO_INTERTECHNO] = {0x03FFFFFF, 15, 1, 5000, 100},
[OOKSENDER_PROTO_MANCHESTER] = {0xFFFFFFFF, 32, 0, 5000, 100},
};
// Largest value per field: code / ID in bits, the others plain
static const uint8_t codeBits[OOKSENDER_PROTO_END] = {24, 20, 32, 26, 32};
static const uint8_t argMax[OOKSENDER_PROTO_END] = {PT2262_MAX_TRITS, 15, 32, 15, 32};
static const uint8_t extraMax[OOKSENDER_PROTO_END] = {0, 0, 7, 1, 0};
static uint32_t OOK_FieldMax(const uint8_t field)
{
switch (field) {
case OOK_FIELD_CODE: return codeBits[gOOKSenderProtocol] >= 32U ? 0xFFFFFFFFU
: (1UL << codeBits[gOOKSenderProtocol]) - 1U;
case OOK_FIELD_ARG: return argMax[gOOKSenderProtocol];
case OOK_FIELD_EXTRA: return extraMax[gOOKSenderProtocol];
case OOK_FIELD_PULSE: return 5000U;
default: return 100U;
}
}
const char *OOKSENDER_FieldLabel(const uint8_t protocol, const uint8_t field)
{
return fieldLabels[protocol][field];
const uint8_t label = fieldLabels[protocol][field];
return label ? labelText[label] : NULL;
}
static void OOK_SetDefaults(void)
@@ -247,7 +259,7 @@ static void OOK_NextField(const int8_t direction)
{
for (uint8_t n = 0; n < OOK_FIELD_COUNT; n++) {
gOOKSenderField = (uint8_t) ((gOOKSenderField + OOK_FIELD_COUNT + direction) % OOK_FIELD_COUNT);
if (fieldLabels[gOOKSenderProtocol][gOOKSenderField] != NULL)
if (fieldLabels[gOOKSenderProtocol][gOOKSenderField] != 0)
return;
}
}
@@ -267,7 +279,7 @@ static void OOK_Digit(const uint8_t digit)
return;
}
const uint32_t max = fieldMax[gOOKSenderProtocol][gOOKSenderField];
const uint32_t max = OOK_FieldMax(gOOKSenderField);
if (*value > (max - digit) / 10U) { // value * 10 + digit > max, without overflow
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
return;
+19 -18
View File
@@ -217,8 +217,10 @@ static void DrawVLine(int sy, int ey, int nx, bool fill) {
}
}
#ifndef ENABLE_FEAT_F4HWN
static void GUI_DisplaySmallest(const char *pString, uint8_t x, uint8_t y,
// The spectrum layout is made for the 3x5 font (4 px per character). The shared
// GUI_DisplaySmallest() in ui/helper.c draws with gFontSmall (7 px) for the
// status bar, which makes the spectrum labels overlap, so it keeps its own.
static void SPECTRUM_DisplaySmallest(const char *pString, uint8_t x, uint8_t y,
bool statusbar, bool fill)
{
uint8_t c;
@@ -246,7 +248,6 @@ static void GUI_DisplaySmallest(const char *pString, uint8_t x, uint8_t y,
x += 4;
}
}
#endif
// Utility functions
@@ -794,7 +795,7 @@ static void DrawStatus() {
#else
sprintf(String, "%d/%d", settings.dbMin, settings.dbMax);
#endif
GUI_DisplaySmallest(String, 50, 20, true, true);
SPECTRUM_DisplaySmallest(String, 50, 20, true, true);
BOARD_ADC_GetBatteryInfo(&gBatteryVoltages[gBatteryCheckCounter++ % 4],
&gBatteryCurrent);
@@ -806,7 +807,7 @@ static void DrawStatus() {
unsigned perc = BATTERY_VoltsToPercent(voltage);
// sprintf(String, "%d %d", voltage, perc);
// GUI_DisplaySmallest(String, 48, 1, true, true);
// SPECTRUM_DisplaySmallest(String, 48, 1, true, true);
gStatusLine[116] = 0b00011100;
gStatusLine[117] = 0b00111110;
@@ -835,7 +836,7 @@ static void ShowChannelName(uint32_t f) {
SETTINGS_FetchChannelName(String, i);
if (String[0] != 0) {
UI_PrintStringSmallBufferNormal(String, gStatusLine + 36);
//GUI_DisplaySmallest(String, 127, 1, true, true);
//SPECTRUM_DisplaySmallest(String, 127, 1, true, true);
}
break;
}
@@ -860,9 +861,9 @@ static void DrawF(uint32_t f) {
UI_PrintStringSmallNormal(String, 8, 127, 0);
sprintf(String, "%3s", gModulationStr[settings.modulationType]);
GUI_DisplaySmallest(String, 95, 1, false, true);
SPECTRUM_DisplaySmallest(String, 95, 1, false, true);
sprintf(String, "%4sk", bwOptions[settings.listenBw]);
GUI_DisplaySmallest(String, 90, 10, false, true);
SPECTRUM_DisplaySmallest(String, 90, 10, false, true);
#ifdef ENABLE_FEAT_F4HWN_SPECTRUM
ShowChannelName(f);
@@ -873,26 +874,26 @@ static void DrawNums() {
if (currentState == SPECTRUM) {
sprintf(String, "%ux", GetStepsCount());
GUI_DisplaySmallest(String, 0, 1, false, true);
SPECTRUM_DisplaySmallest(String, 0, 1, false, true);
sprintf(String, "%u.%02uk", GetScanStep() / 100, GetScanStep() % 100);
GUI_DisplaySmallest(String, 0, 7, false, true);
SPECTRUM_DisplaySmallest(String, 0, 7, false, true);
}
if (IsCenterMode()) {
sprintf(String, "%lu.%05lu \x7F%lu.%02luk", currentFreq / 100000,
currentFreq % 100000, settings.frequencyChangeStep / 100,
settings.frequencyChangeStep % 100);
GUI_DisplaySmallest(String, 36, 39, false, true);
SPECTRUM_DisplaySmallest(String, 36, 39, false, true);
} else {
sprintf(String, "%lu.%05lu", GetFStart() / 100000, GetFStart() % 100000);
GUI_DisplaySmallest(String, 0, 49, false, true);
SPECTRUM_DisplaySmallest(String, 0, 49, false, true);
sprintf(String, "\x7F%lu.%02luk", settings.frequencyChangeStep / 100,
settings.frequencyChangeStep % 100);
GUI_DisplaySmallest(String, 48, 10, false, true);
SPECTRUM_DisplaySmallest(String, 48, 10, false, true);
sprintf(String, "%lu.%05lu", GetFEnd() / 100000, GetFEnd() % 100000);
GUI_DisplaySmallest(String, 93, 49, false, true);
SPECTRUM_DisplaySmallest(String, 93, 49, false, true);
}
}
@@ -1184,9 +1185,9 @@ static void RenderStill() {
int dbm = Rssi2DBm(scanInfo.rssi);
uint8_t s = DBm2S(dbm);
sprintf(String, "S: %u", s);
GUI_DisplaySmallest(String, 4, 25, false, true);
SPECTRUM_DisplaySmallest(String, 4, 25, false, true);
sprintf(String, "%d dBm", dbm);
GUI_DisplaySmallest(String, 28, 25, false, true);
SPECTRUM_DisplaySmallest(String, 28, 25, false, true);
if (!monitorMode) {
uint8_t x = Rssi2PX(settings.rssiTriggerLevel, 0, 121);
@@ -1211,10 +1212,10 @@ static void RenderStill() {
}
}
sprintf(String, "%s", registerSpecs[idx].name);
GUI_DisplaySmallest(String, offset + 2, row * 8 + 2, false,
SPECTRUM_DisplaySmallest(String, offset + 2, row * 8 + 2, false,
menuState != idx);
sprintf(String, "%u", GetRegMenuValue(idx));
GUI_DisplaySmallest(String, offset + 2, (row + 1) * 8 + 1, false,
SPECTRUM_DisplaySmallest(String, offset + 2, (row + 1) * 8 + 1, false,
menuState != idx);
}
}
+7 -2
View File
@@ -394,8 +394,13 @@ void BK4819_ToggleGpioOut(BK4819_GPIO_PIN_t Pin, bool bSet)
BK4819_WriteRegister(BK4819_REG_33, gBK4819_GpioOutState);
}
// ~250 ns at 48 MHz: keeps the bit-banged SPI clock around 1 MHz
#define BK4819_FAST_SPI_WAIT() __asm volatile ("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop")
// ~250 ns at 48 MHz (call + return + 6 nops): keeps the bit-banged SPI clock around
// 1 MHz. A real function, so the wait is not inlined at every clock edge.
static void __attribute__((noinline)) BK4819_FastSpiWait(void)
{
__asm volatile ("nop\n nop\n nop\n nop\n nop\n nop");
}
#define BK4819_FAST_SPI_WAIT() BK4819_FastSpiWait()
// BK4819_WriteRegister() without the SYSTICK_DelayUs(1) calls (their overhead makes a
// write take ~300 us).
+4 -21
View File
@@ -3,6 +3,7 @@
//
#include "messages.h"
#include "../external/printf/printf.h"
// Convert a 32-bit number to a string (10 digits, zero-padded)
@@ -74,27 +75,9 @@ void UI_DisplayMessages(void) {
gActiveMessage = (startIndex + pageOffset + ixa) % MESSAGES_COUNT;
MESSAGES_GET();
// Build the display string
if (loadedPacket.flags & MESSAGE_FLAG_POCSAG) {
char capcodeString[11];
u32_to_str(loadedPacket.src, capcodeString);
String[0] = 'P';
String[1] = ':';
memcpy(String + 2, capcodeString + 3, 7);
String[9] = ' ';
} else {
u32_to_str(loadedPacket.src, &String[0]);
}
String[10] = '-';
u8_to_str(loadedPacket.seq, &String[11]);
String[14] = '-';
// Display a visual index (0,1,2,3... not EEPROM slot)
uint8_t visualIndex = ixa + pageOffset;
String[15] = (visualIndex < 10) ? ('0' + visualIndex) : ('A' + visualIndex - 10);
String[16] = '-';
String[17] = (gActiveMessage < 10) ? ('0' + gActiveMessage) : ('A' + gActiveMessage - 10);
String[18] = 0;
// header: sender (POCSAG: "P:" + RIC), sequence, position in the list, EEPROM slot
sprintf(String, (loadedPacket.flags & MESSAGE_FLAG_POCSAG) ? "P:%07lu -%03u-%X-%X" : "%010lu-%03u-%X-%X",
(unsigned long) loadedPacket.src, loadedPacket.seq, ixa + pageOffset, gActiveMessage);
// header line, then the text wrapped over MESSAGES_TEXT_LINES lines
const uint8_t line = ixa * (1U + MESSAGES_TEXT_LINES);
+2 -2
View File
@@ -42,7 +42,7 @@ void OOKSENDER_Display(void) {
sprintf(String, "%c %s", gOOKSenderProtocol == i ? '>' : ' ', OOKPROTONAMES[i]);
UI_PrintStringSmallNormal(String, 0, 0, 1 + i);
}
UI_PrintStringSmallNormal("MENU select", 0, 0, 7);
UI_PrintStringSmallNormal("MENU = OK", 0, 0, 7);
break;
case OOKSENDER_DATA_INPUT:
@@ -61,7 +61,7 @@ void OOKSENDER_Display(void) {
sprintf(String, "%c%-6s %s", gOOKSenderField == f ? '>' : ' ', label, value);
UI_PrintStringSmallNormal(String, 0, 0, line++);
}
UI_PrintStringSmallNormal(gOOKSenderState == OOKSENDER_SENDING ? "SENDING..." : "PTT/MENU send",
UI_PrintStringSmallNormal(gOOKSenderState == OOKSENDER_SENDING ? "Sending" : "PTT send",
0, 0, 7);
break;
}