From 4fe99744e1a6ce310c02331de55012e5418d84b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Mon, 10 Mar 2025 21:48:58 +0100 Subject: [PATCH] Do some stuff --- app/action.c | 9 +++++++++ app/app.c | 6 +++--- app/main.c | 2 +- driver/bk4819.c | 2 +- driver/bk4819.h | 2 ++ functions.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ misc.h | 3 ++- settings.h | 1 + ui/menu.c | 1 + 9 files changed, 71 insertions(+), 6 deletions(-) diff --git a/app/action.c b/app/action.c index 38f4c48..aa7ff5c 100644 --- a/app/action.c +++ b/app/action.c @@ -42,6 +42,8 @@ #include "settings.h" #include "ui/inputbox.h" #include "ui/ui.h" +#include "driver/st7565.h" + #ifdef ENABLE_REGA #include "app/rega.h" #endif @@ -58,6 +60,11 @@ static void ACTION_Scan_FM(bool bRestart); static void ACTION_AlarmOr1750(bool b1750); inline static void ACTION_Alarm() { ACTION_AlarmOr1750(false); } inline static void ACTION_1750() { ACTION_AlarmOr1750(true); }; + +inline static void ACTION_SSTV() { + gFlagPrepareTX = gAlarmState != ALARM_STATE_OFF; + gAlarmState = ALARM_STATE_SSTV; +}; #endif inline static void ACTION_ScanRestart() { ACTION_Scan(true); }; @@ -102,6 +109,8 @@ void (*action_opt_table[])(void) = { [ACTION_OPT_1750] = &FUNCTION_NOP, #endif + [ACTION_REQ_SSTV] = &ACTION_SSTV, + #ifdef ENABLE_BLMIN_TMP_OFF [ACTION_OPT_BLMIN_TMP_OFF] = &ACTION_BlminTmpOff, #else diff --git a/app/app.c b/app/app.c index 09ac9c3..af2fdd3 100644 --- a/app/app.c +++ b/app/app.c @@ -1395,9 +1395,9 @@ void APP_TimeSlice10ms(void) { SCANNER_TimeSlice10ms(); - if (gEnteringSMS == SMS_NOT_ENTERING) { - MSG_FSKReceiveData(); - } +// if (gEnteringSMS == SMS_NOT_ENTERING) { +// MSG_FSKReceiveData(); +// } #ifdef ENABLE_AIRCOPY if (gScreenToDisplay == DISPLAY_AIRCOPY && gAircopyState == AIRCOPY_TRANSFER && gAirCopyIsSendMode == 1) { diff --git a/app/main.c b/app/main.c index ca081f4..bd67470 100644 --- a/app/main.c +++ b/app/main.c @@ -977,7 +977,7 @@ void MAIN_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, true); MSG_FSKSendData(&dataPacket); BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, false); - MSG_EnableRX(true); + //MSG_EnableRX(true); gVfoConfigureMode = VFO_CONFIGURE; dataPTR = dataPacket.data; memset(dataPacket.data, 0, DataPacketDataSize); diff --git a/driver/bk4819.c b/driver/bk4819.c index 45800e8..ee643ad 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -42,7 +42,7 @@ static uint16_t gBK4819_GpioOutState; bool gRxIdleMode; -__inline uint16_t scale_freq(const uint16_t freq) +__inline uint16_t scale_freq(uint16_t freq) { // return (((uint32_t)freq * 1032444u) + 50000u) / 100000u; // with rounding return (((uint32_t)freq * 1353245u) + (1u << 16)) >> 17; // with rounding diff --git a/driver/bk4819.h b/driver/bk4819.h index b7e3de4..963afa3 100644 --- a/driver/bk4819.h +++ b/driver/bk4819.h @@ -65,6 +65,8 @@ typedef enum BK4819_CssScanResult_t BK4819_CssScanResult_t; // radio is asleep, not listening extern bool gRxIdleMode; +uint16_t scale_freq(uint16_t freq); + void BK4819_Init(void); uint16_t BK4819_ReadRegister(BK4819_REGISTER_t Register); void BK4819_WriteRegister(BK4819_REGISTER_t Register, uint16_t Data); diff --git a/functions.c b/functions.c index 2e8362e..e9cbe2b 100644 --- a/functions.c +++ b/functions.c @@ -48,6 +48,7 @@ #include "ui/status.h" #include "ui/ui.h" #include "app/app.h" +#include "driver/systick.h" FUNCTION_Type_t gCurrentFunction; @@ -150,6 +151,52 @@ void FUNCTION_PowerSave() { GUI_SelectNextDisplay(DISPLAY_MAIN); } +#define SSTV_MULT 1 + +#define SCALE_FREQ(freq) ((((uint32_t)(freq) * 1353245u) + (1u << 16)) >> 17) + +void BK4819_PlaySSTV_Robot8() { + + + BK4819_EnterTxMute(); + BK4819_SetAF(gEeprom.DTMF_SIDE_TONE); + BK4819_TransmitTone(true, 1000); + SYSTEM_DelayMs(100); + BK4819_WriteRegister(BK4819_REG_70, + BK4819_REG_70_MASK_ENABLE_TONE1 | (66u << BK4819_REG_70_SHIFT_TONE1_TUNING_GAIN)); + BK4819_EnableTXLink(); + + SYSTEM_DelayMs(50); + // **Send 9x Vertical Sync Pulses (1,900 Hz, 50ms each)** + + // **Send 3x Vertical Sync Pulses (1,900 Hz, 30ms each)** + for (int i = 0; i < 3; i++) { + BK4819_WriteRegister(BK4819_REG_71, SCALE_FREQ(1900)); + SYSTEM_DelayMs(30); + } + + // **Transmit Image Data** + for (uint8_t y = 0; y < 8; y++) { + for (uint8_t rep = 0; rep < 2; rep++) { + BK4819_WriteRegister(BK4819_REG_71, SCALE_FREQ(1200)); + SYSTEM_DelayMs(5); + for (uint8_t bit = 0; bit < 8; bit++) { + for (uint8_t x = 0; x < 128; x++) { + uint8_t byte = gFrameBuffer[y][x]; + uint8_t bitV = byte & (1 << bit); + uint16_t freq = (bitV) ? 2300 : 1200; + BK4819_WriteRegister(BK4819_REG_71, SCALE_FREQ(freq)); + SYSTICK_DelayUs(432); // Pixel time = ~0.432ms + } + } + } + } + + BK4819_WriteRegister(BK4819_REG_70, 0x0000); + // **End Transmission: Mute Transmitter** + BK4819_ExitTxMute(); +} + void FUNCTION_Transmit() { // if DTMF is enabled when TX'ing, it changes the TX audio filtering !! .. 1of11 @@ -216,6 +263,10 @@ void FUNCTION_Transmit() { } #endif + if (gAlarmState == ALARM_STATE_SSTV) { + BK4819_PlaySSTV_Robot8(); + gAlarmState = ALARM_STATE_OFF; + } #ifdef ENABLE_ALARM if (gAlarmState == ALARM_STATE_TXALARM) BK4819_TransmitTone(true, 500); diff --git a/misc.h b/misc.h index aae2082..a560c92 100644 --- a/misc.h +++ b/misc.h @@ -61,7 +61,8 @@ enum AlarmState_t { ALARM_STATE_OFF = 0, ALARM_STATE_TXALARM, ALARM_STATE_SITE_ALARM, - ALARM_STATE_TX1750 + ALARM_STATE_TX1750, + ALARM_STATE_SSTV }; typedef enum AlarmState_t AlarmState_t; diff --git a/settings.h b/settings.h index 6415838..4f4f49b 100644 --- a/settings.h +++ b/settings.h @@ -139,6 +139,7 @@ enum ACTION_OPT_t { ACTION_OPT_REGA_ALARM, ACTION_OPT_REGA_TEST, #endif + ACTION_REQ_SSTV, ACTION_OPT_LEN }; diff --git a/ui/menu.c b/ui/menu.c index db22fa1..deaf0fc 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -398,6 +398,7 @@ const t_sidefunction gSubMenu_SIDEFUNCTIONS[] = {"REMOVE\nOFFSET", ACTION_OPT_REMOVE_OFFSET}, #endif #endif + {"SSTV", ACTION_REQ_SSTV}, }; const uint8_t gSubMenu_SIDEFUNCTIONS_size = ARRAY_SIZE(gSubMenu_SIDEFUNCTIONS);