diff --git a/libs/k5_uv_system/CMakeLists.txt b/libs/k5_uv_system/CMakeLists.txt index f1c0ba8..bd6ebb2 100644 --- a/libs/k5_uv_system/CMakeLists.txt +++ b/libs/k5_uv_system/CMakeLists.txt @@ -12,6 +12,7 @@ target_include_directories(${NAME} PRIVATE target_sources(${NAME} PRIVATE system.cpp vtable.s + api.s ) target_link_libraries(${NAME} diff --git a/libs/k5_uv_system/api.s b/libs/k5_uv_system/api.s new file mode 100644 index 0000000..bf2b86c --- /dev/null +++ b/libs/k5_uv_system/api.s @@ -0,0 +1,159 @@ +.globl PrintTextOnScreen +PrintTextOnScreen = 0x874C + 1; + +.globl DelayMs +DelayMs = 0xD0EC + 1; + +.globl DelayUs +DelayUs = 0xD100 + 1; + +.globl WriteSerialData +WriteSerialData = 0xBE44 + 1; + +.globl BK4819Write +BK4819Write = 0xAF00 + 1; + +.globl BK4819Read +BK4819Read = 0xA960 + 1; + +.globl FlushFramebufferToScreen +FlushFramebufferToScreen = 0xB638 + 1; + +.globl PollKeyboard +PollKeyboard = 0xb0b8 + 1; + +.globl FormatString +FormatString = 0xC6E8 + 1; + +.globl PrintSmallDigits +PrintSmallDigits = 0x870C + 1; + +.globl PrintFrequency +PrintFrequency = 0x864C + 1; + +.globl AirCopy72 +AirCopy72 = 0xA67C + 1; + +.globl AirCopyFskSetup +AirCopyFskSetup = 0xA518 + 1; + +.globl BK4819Reset +BK4819Reset = 0xa7cc + 1; + +.globl IntDivide +IntDivide = 0x128 + 1; + +.globl BK4819WriteFrequency +BK4819WriteFrequency = 0xaabc + 1; + +.globl BK4819SetPaGain +BK4819SetPaGain = 0xaad4 + 1; + +.globl BK4819ConfigureAndStartTxFsk +BK4819ConfigureAndStartTxFsk = 0x1cd8 + 1; + +.globl BK4819ConfigureAndStartRxFsk +BK4819ConfigureAndStartRxFsk = 0xa63c + 1; + +.globl BK4819SetGpio +BK4819SetGpio = 0xa794 + 1; + +.globl FlushStatusbarBufferToScreen +FlushStatusbarBufferToScreen = 0xb6b0 + 1; + +.globl UpdateStatusBar +UpdateStatusBar = 0x9c10 + 1; + +.globl AdcReadout +AdcReadout = 0x9d7c + 1; + +.globl SomeAmStuff +SomeAmStuff = 0xc158 + 1; + +.globl IRQ_RESET +IRQ_RESET = 0xd4 + 1; + +.globl IRQ_SYSTICK +IRQ_SYSTICK = 0xc398 + 1; + +.globl ConfigureTrimValuesFromNVR +ConfigureTrimValuesFromNVR = 0x20000230 + 1; + +.globl FLASH_ReadNvrWord +FLASH_ReadNvrWord = 0x20000214 + 1; + +.globl SystemReset +SystemReset = 0x200001f8 + 1; + +.globl FLASH_SetProgramTime +FLASH_SetProgramTime = 0x200001d4 + 1; + +.globl FLASH_SetMode +FLASH_SetMode = 0x200001b4 + 1; + +.globl FLASH_WakeFromDeepSleep +FLASH_WakeFromDeepSleep = 0x20000194 + 1; + +.globl FLASH_SetEraseTime +FLASH_SetEraseTime = 0x20000170 + 1; + +.globl FLASH_SetReadMode +FLASH_SetReadMode = 0x20000148 + 1; + +.globl FLASH_Set_NVR_SEL +FLASH_Set_NVR_SEL = 0x20000128 + 1; + +.globl FLASH_ReadByAPB +FLASH_ReadByAPB = 0x200000e8 + 1; + +.globl FLASH_ReadByAHB +FLASH_ReadByAHB = 0x200000dc + 1; + +.globl FLASH_Unlock +FLASH_Unlock = 0x200000d0 + 1; + +.globl FLASH_Lock +FLASH_Lock = 0x200000c4 + 1; + +.globl FLASH_MaskUnlock +FLASH_MaskUnlock = 0x200000b0 + 1; + +.globl FLASH_SetMaskSel +FLASH_SetMaskSel = 0x20000094 + 1; + +.globl FLASH_MaskLock +FLASH_MaskLock = 0x20000080 + 1; + +.globl FLASH_Init +FLASH_Init = 0x2000005c + 1; + +.globl FLASH_Start +FLASH_Start = 0x20000044 + 1; + +.globl FLASH_IsInitBusy +FLASH_IsInitBusy = 0x2000002c + 1; + +.globl FLASH_IsBusy +FLASH_IsBusy = 0x20000014 + 1; + +.globl FLASH_RebootToBootloader +FLASH_RebootToBootloader = 0x20000000 + 1; + +.globl gDisplayBuffer +gDisplayBuffer = 0x20000704; + +.globl gSmallDigs +gSmallDigs = 0xD620; + +.globl gSmallLeters +gSmallLeters = 0xD348; + +.globl gFlashLightStatus +gFlashLightStatus = 0x200003b3; + +.globl gStatusBarData +gStatusBarData = 0x20000684; + +.globl gVoltage +gVoltage = 0x20000406; + diff --git a/libs/k5_uv_system/system.cpp b/libs/k5_uv_system/system.cpp index d716dd0..422d801 100644 --- a/libs/k5_uv_system/system.cpp +++ b/libs/k5_uv_system/system.cpp @@ -21,5 +21,5 @@ void System::CopyDataSection() extern "C" unsigned int __wrap___udivsi3(unsigned int a, unsigned int b) { - return OrgFunc_01_26.IntDivide(a, b); + return IntDivide(a, b); } diff --git a/libs/k5_uv_system/system.hpp b/libs/k5_uv_system/system.hpp index 0b32933..672b8bf 100644 --- a/libs/k5_uv_system/system.hpp +++ b/libs/k5_uv_system/system.hpp @@ -1,4 +1,70 @@ #pragma once + +extern "C" { + void PrintTextOnScreen(const char* U8Text, + unsigned int u32StartPixel, + unsigned int u32StopPixel, + unsigned int u32LineNumber, + unsigned int u32PxPerChar, + unsigned int u32Centered + ); + + void DelayMs(unsigned int u32Ms); + void DelayUs(unsigned int u32Us); + int WriteSerialData(unsigned char* p8Data, unsigned char u8Len); + void BK4819Write(unsigned int u32Address, unsigned int u32Data); + unsigned int BK4819Read(unsigned int u32Address); + void FlushFramebufferToScreen(void); + unsigned int PollKeyboard(void); + char* FormatString(char *, const char *, ...); + void PrintSmallDigits(unsigned int u32Len, const int* p32Number, int s32X, int s32Y); + void PrintFrequency(int frequency,int xpos,int ypos,int param_4,int param_5); + void AirCopy72(unsigned char*); + void AirCopyFskSetup(); + void BK4819Reset(); + int IntDivide(int s32Divident, int s32Divisor); + void BK4819WriteFrequency(unsigned int u32Frequency); + void BK4819SetPaGain(unsigned short u16PaBias, unsigned int u32Frequency); + void BK4819ConfigureAndStartTxFsk(); + void BK4819ConfigureAndStartRxFsk(); + void BK4819SetGpio(unsigned int u32Pin, bool bState); + void FlushStatusbarBufferToScreen(); + void UpdateStatusBar(); + void AdcReadout(unsigned short* p16Data1, unsigned short* p16Data2); + void SomeAmStuff(unsigned int u32Param); + void IRQ_RESET(void); + void IRQ_SYSTICK(void); + // API available in the SRAM overlay installed by FW + void ConfigureTrimValuesFromNVR(void); + unsigned int FLASH_ReadNvrWord(unsigned int u32Offset); + void SystemReset(void); + void FLASH_SetProgramTime(void); + void FLASH_SetMode(unsigned int u32Mode); + void FLASH_WakeFromDeepSleep(void); + void FLASH_SetEraseTime(void); + void FLASH_SetReadMode(unsigned int u32Mode); + void FLASH_Set_NVR_SEL(unsigned int u32Sel); + unsigned int FLASH_ReadByAPB(unsigned int u32Offset); + unsigned int FLASH_ReadByAHB(unsigned int u32Offset); + void FLASH_Unlock(void); + void FLASH_Lock(void); + void FLASH_MaskUnlock(void); + void FLASH_SetMaskSel(unsigned int u32Mask); + void FLASH_MaskLock(void); + void FLASH_Init(unsigned int u32ReadMode); + void FLASH_Start(void); + int FLASH_IsInitBusy(void); + int FLASH_IsBusy(void); + int FLASH_RebootToBootloader(void); +}; + +extern unsigned char gDisplayBuffer[]; +extern unsigned char gSmallDigs[]; +extern unsigned char gSmallLeters[]; +extern unsigned char gFlashLightStatus; +extern unsigned char gStatusBarData[]; +extern unsigned short gVoltage; + namespace System { using VoidFxPointer = void(*)(void); @@ -32,94 +98,6 @@ namespace System }; void CopyDataSection(); - - struct TOrgFunctions - { - void(*PrintTextOnScreen)(const char* U8Text, - unsigned int u32StartPixel, - unsigned int u32StopPixel, - unsigned int u32LineNumber, - unsigned int u32PxPerChar, - unsigned int u32Centered - ); - - void(*DelayMs)(unsigned int u32Ms); - void(*DelayUs)(unsigned int u32Us); - int(*WriteSerialData)(unsigned char* p8Data, unsigned char u8Len); - void(*BK4819Write)(unsigned int u32Address, unsigned int u32Data); - unsigned int(*BK4819Read)(unsigned int u32Address); - void(*FlushFramebufferToScreen)(void); - unsigned int(*PollKeyboard)(void); - char* (*FormatString)(char *, const char *, ...); - void(*PrintSmallDigits)(unsigned int u32Len, const int* p32Number, int s32X, int s32Y); - void(*PrintFrequency)(int frequency,int xpos,int ypos,int param_4,int param_5); - void(*AirCopy72)(unsigned char*); - void(*AirCopyFskSetup)(); - void(*BK4819Reset)(); - int(*IntDivide)(int s32Divident, int s32Divisor); - void(*BK4819WriteFrequency)(unsigned int u32Frequency); - void(*BK4819SetPaGain)(unsigned short u16PaBias, unsigned int u32Frequency); - void(*BK4819ConfigureAndStartTxFsk)(); - void(*BK4819ConfigureAndStartRxFsk)(); - void(*BK4819SetGpio)(unsigned int u32Pin, bool bState); - void(*FlushStatusbarBufferToScreen)(); - void(*UpdateStatusBar)(); - void(*AdcReadout)(unsigned short* p16Data1, unsigned short* p16Data2); - void(*SomeAmStuff)(unsigned int u32Param); - void (*IRQ_RESET)(void); - void (*IRQ_SYSTICK)(void); - - }; - - struct TOrgData - { - unsigned char* pDisplayBuffer; - unsigned char* pSmallDigs; - unsigned char* pSmallLeters; - unsigned char* p8FlashLightStatus; - unsigned char* pStatusBarData; - unsigned short* p16Voltage; - }; - - inline const TOrgFunctions OrgFunc_01_26 = - { - .PrintTextOnScreen = (decltype(TOrgFunctions::PrintTextOnScreen))(0x874C + 1), - .DelayMs = (decltype(TOrgFunctions::DelayMs)) (0xD0EC + 1), - .DelayUs = (decltype(TOrgFunctions::DelayUs)) (0xD100 + 1), - .WriteSerialData = (int(*)(unsigned char*, unsigned char))(0xBE44 + 1), - .BK4819Write = (decltype(TOrgFunctions::BK4819Write) (0xAF00 + 1)), - .BK4819Read = (decltype(TOrgFunctions::BK4819Read) (0xA960 + 1)), - .FlushFramebufferToScreen = (decltype(TOrgFunctions::FlushFramebufferToScreen) (0xB638 + 1)), - .PollKeyboard = (decltype(TOrgFunctions::PollKeyboard) (0xb0b8 + 1)), - .FormatString = (decltype(TOrgFunctions::FormatString) (0xC6E8 + 1)), - .PrintSmallDigits = (decltype(TOrgFunctions::PrintSmallDigits) (0x870C + 1)), - .PrintFrequency = (decltype(TOrgFunctions::PrintFrequency) (0x864C + 1)), - .AirCopy72 = (decltype(TOrgFunctions::AirCopy72) (0xA67C + 1)), - .AirCopyFskSetup = (decltype(TOrgFunctions::AirCopyFskSetup) (0xA518 + 1)), - .BK4819Reset = (decltype(TOrgFunctions::BK4819Reset) (0xa7cc + 1)), - .IntDivide = (decltype(TOrgFunctions::IntDivide) (0x128 + 1)), - .BK4819WriteFrequency = (decltype(TOrgFunctions::BK4819WriteFrequency) (0xaabc + 1)), - .BK4819SetPaGain = (decltype(TOrgFunctions::BK4819SetPaGain) (0xaad4 + 1)), - .BK4819ConfigureAndStartTxFsk = (decltype(TOrgFunctions::BK4819ConfigureAndStartTxFsk) (0x1cd8 + 1)), - .BK4819ConfigureAndStartRxFsk = (decltype(TOrgFunctions::BK4819ConfigureAndStartRxFsk) (0xa63c + 1)), - .BK4819SetGpio = (decltype(TOrgFunctions::BK4819SetGpio) (0xa794 + 1)), - .FlushStatusbarBufferToScreen = (decltype(TOrgFunctions::FlushStatusbarBufferToScreen) (0xb6b0 + 1)), - .UpdateStatusBar = (decltype(TOrgFunctions::UpdateStatusBar) (0x9c10 + 1)), - .AdcReadout = (decltype(TOrgFunctions::AdcReadout) (0x9d7c + 1)), - .SomeAmStuff = (decltype(TOrgFunctions::SomeAmStuff) (0xc158 + 1)), - .IRQ_RESET = (decltype(TOrgFunctions::IRQ_RESET) (0xd4 + 1)), - .IRQ_SYSTICK = (decltype(TOrgFunctions::IRQ_SYSTICK) (0xc398 + 1)) - }; - - inline const TOrgData OrgData_01_26 = - { - .pDisplayBuffer = (decltype(TOrgData::pDisplayBuffer)) 0x20000704, - .pSmallDigs = (decltype(TOrgData::pSmallDigs)) 0xD620, - .pSmallLeters = (decltype(TOrgData::pSmallLeters)) 0xD348, - .p8FlashLightStatus = (decltype(TOrgData::p8FlashLightStatus)) 0x200003b3, - .pStatusBarData = (decltype(TOrgData::pStatusBarData)) 0x20000684, - .p16Voltage = (decltype(TOrgData::p16Voltage)) 0x20000406, - }; } extern "C" void __libc_init_array(); diff --git a/libs/radio/radio.hpp b/libs/radio/radio.hpp index 2c04c3d..b7243a1 100644 --- a/libs/radio/radio.hpp +++ b/libs/radio/radio.hpp @@ -3,6 +3,7 @@ #include "registers.hpp" #include "system.hpp" #include +#include static constexpr auto operator""_Hz(unsigned long long Hertz) { @@ -58,7 +59,6 @@ namespace Radio }; using CallbackRxDoneType = CCallback; - template class CBK4819 { CallbackRxDoneType CallbackRxDone; @@ -70,38 +70,38 @@ namespace Radio // void SetFrequency(unsigned int u32FrequencyD10) // { - // Fw.BK4819WriteFrequency(u32FrequencyD10); + // BK4819WriteFrequency(u32FrequencyD10); // } static unsigned int GetFrequency() { - return (Fw.BK4819Read(0x39) << 16) | Fw.BK4819Read(0x38); + return (BK4819Read(0x39) << 16) | BK4819Read(0x38); } static signed short GetRssi() { - short s16Rssi = ((Fw.BK4819Read(0x67) >> 1) & 0xFF); + short s16Rssi = ((BK4819Read(0x67) >> 1) & 0xFF); return s16Rssi - 160; } - bool IsTx() { return Fw.BK4819Read(0x30) & 0b10; } + bool IsTx() { return BK4819Read(0x30) & 0b10; } - bool IsSqlOpen() { return Fw.BK4819Read(0x0C) & 0b10; } + bool IsSqlOpen() { return BK4819Read(0x0C) & 0b10; } static void SetFrequency(unsigned int u32Freq) { - Fw.BK4819Write(0x39, ((u32Freq >> 16) & 0xFFFF)); - Fw.BK4819Write(0x38, (u32Freq & 0xFFFF)); - auto OldReg = Fw.BK4819Read(0x30); - Fw.BK4819Write(0x30, 0); - Fw.BK4819Write(0x30, OldReg); + BK4819Write(0x39, ((u32Freq >> 16) & 0xFFFF)); + BK4819Write(0x38, (u32Freq & 0xFFFF)); + auto OldReg = BK4819Read(0x30); + BK4819Write(0x30, 0); + BK4819Write(0x30, OldReg); } void SetAgcTable(unsigned short *p16AgcTable) { for (unsigned char i = 0; i < 5; i++) { - Fw.BK4819Write(0x10 + i, p16AgcTable[i]); + BK4819Write(0x10 + i, p16AgcTable[i]); } } @@ -109,81 +109,75 @@ namespace Radio { for (unsigned char i = 0; i < 5; i++) { - p16AgcTable[i] = Fw.BK4819Read(0x10 + i); + p16AgcTable[i] = BK4819Read(0x10 + i); } } void SetDeviationPresent(unsigned char u8Present) { - auto Reg40 = Fw.BK4819Read(0x40); + auto Reg40 = BK4819Read(0x40); Reg40 &= ~(1 << 12); Reg40 |= (u8Present << 12); - Fw.BK4819Write(0x40, Reg40); + BK4819Write(0x40, Reg40); } void SetCalibration(unsigned char bOn) { - auto Reg30 = Fw.BK4819Read(0x31); + auto Reg30 = BK4819Read(0x31); Reg30 &= ~(1 << 3); Reg30 |= (bOn << 3); - Fw.BK4819Write(0x31, Reg30); + BK4819Write(0x31, Reg30); } - unsigned char GetAFAmplitude() { return Fw.BK4819Read(0x6F) & 0b1111111; } - - unsigned short GetVoiceAmplitude() - { - // Fw.BK4819Write(0x64, 0); - return Fw.BK4819Read(0x64); - } + unsigned char GetAFAmplitude() { return BK4819Read(0x6F) & 0b1111111; } static void ToggleAFDAC(bool enabled) { - auto Reg = Fw.BK4819Read(0x30); + auto Reg = BK4819Read(0x30); Reg &= ~(1 << 9); if (enabled) Reg |= (1 << 9); - Fw.BK4819Write(0x30, Reg); + BK4819Write(0x30, Reg); } static void ToggleRXDSP(bool enabled) { - auto Reg = Fw.BK4819Read(0x30); + auto Reg = BK4819Read(0x30); Reg &= ~1; if (enabled) Reg |= 1; - Fw.BK4819Write(0x30, Reg); + BK4819Write(0x30, Reg); } void SendSyncAirCopyMode72(unsigned char *p8Data) { - Fw.BK4819ConfigureAndStartTxFsk(); - Fw.AirCopyFskSetup(); - Fw.AirCopy72(p8Data); - Fw.BK4819SetGpio(1, false); + BK4819ConfigureAndStartTxFsk(); + AirCopyFskSetup(); + AirCopy72(p8Data); + BK4819SetGpio(1, false); } - void DisablePa() { Fw.BK4819Write(0x30, Fw.BK4819Read(0x30) & ~0b1010); } + void DisablePa() { BK4819Write(0x30, BK4819Read(0x30) & ~0b1010); } void SetFskMode(eFskMode Mode) { auto const &ModeParams = ModesBits[(int)Mode]; - auto Reg58 = Fw.BK4819Read(0x58); + auto Reg58 = BK4819Read(0x58); Reg58 &= ~((0b111 << 1) | (0b111 << 10) | (0b111 << 13)); Reg58 |= (ModeParams.u8RxBandWidthBits << 1) | (ModeParams.u8RxModeBits << 10) | (ModeParams.u8TxModeBits << 13); - Fw.BK4819Write(0x58, 0); - Fw.BK4819Write(0x58, Reg58); + BK4819Write(0x58, 0); + BK4819Write(0x58, Reg58); } void FixIrqEnRegister() // original firmware overrides IRQ_EN reg, so we need // to reenable it { - auto const OldIrqEnReg = Fw.BK4819Read(0x3F); + auto const OldIrqEnReg = BK4819Read(0x3F); if ((OldIrqEnReg & (eIrq::FifoAlmostFull | eIrq::RxDone)) != (eIrq::FifoAlmostFull | eIrq::RxDone)) { - Fw.BK4819Write(0x3F, OldIrqEnReg | eIrq::FifoAlmostFull | eIrq::RxDone); + BK4819Write(0x3F, OldIrqEnReg | eIrq::FifoAlmostFull | eIrq::RxDone); } } @@ -200,31 +194,31 @@ namespace Radio u8RxBuffSize = u8DataLen; u16RxDataLen = 0; - Fw.AirCopyFskSetup(); - Fw.BK4819ConfigureAndStartRxFsk(); + AirCopyFskSetup(); + BK4819ConfigureAndStartRxFsk(); State = eState::RxPending; } void DisableFskModem() { - auto const FskSettings = Fw.BK4819Read(0x58); - Fw.BK4819Write(0x58, FskSettings & ~1); + auto const FskSettings = BK4819Read(0x58); + BK4819Write(0x58, FskSettings & ~1); } void ClearRxFifoBuff() { - auto const Reg59 = Fw.BK4819Read(0x59); - Fw.BK4819Write(0x59, 1 << 14); - Fw.BK4819Write(0x59, Reg59); + auto const Reg59 = BK4819Read(0x59); + BK4819Write(0x59, 1 << 14); + BK4819Write(0x59, Reg59); } unsigned short GetIrqReg() { - Fw.BK4819Write(0x2, 0); - return Fw.BK4819Read(0x2); + BK4819Write(0x2, 0); + return BK4819Read(0x2); } - bool CheckCrc() { return Fw.BK4819Read(0x0B) & (1 << 4); } + bool CheckCrc() { return BK4819Read(0x0B) & (1 << 4); } bool IsLockedByOrgFw() { return !(GPIOC->DATA & 0b1); } @@ -248,7 +242,7 @@ namespace Radio if (State == eState::RxPending) { FixIrqEnRegister(); - if (!(Fw.BK4819Read(0x0C) & 1)) // irq request indicator + if (!(BK4819Read(0x0C) & 1)) // irq request indicator { return; } @@ -275,7 +269,7 @@ namespace Radio { for (unsigned char i = 0; i < 4; i++) { - auto const RxData = Fw.BK4819Read(0x5F); + auto const RxData = BK4819Read(0x5F); if (p8RxBuff && u16RxDataLen < u8RxBuffSize - 2) { memcpy(p8RxBuff + u16RxDataLen, &RxData, 2); diff --git a/libs/views/am_tx.hpp b/libs/views/am_tx.hpp index 722363c..ff72975 100644 --- a/libs/views/am_tx.hpp +++ b/libs/views/am_tx.hpp @@ -4,13 +4,11 @@ #include "hardware/adc.hpp" template < - const System::TOrgFunctions &Fw, - const System::TOrgData &FwData, TUV_K5Display &DisplayBuff, CDisplay &Display, CDisplay &DisplayStatusBar, const TUV_K5SmallNumbers &FontSmallNr, - Radio::CBK4819 &RadioDriver> + Radio::CBK4819 &RadioDriver> class CAmTx : public IView { static constexpr bool bAmpTests = true; @@ -41,7 +39,7 @@ class CAmTx : public IView HandleTests(); - if (CheckForPtt()) + if(CheckForPtt()) { return eScreenRefreshFlag::MainScreen; } @@ -55,55 +53,26 @@ class CAmTx : public IView void HandleTests() { - if constexpr(!bAmpTests) - { - return; - } - - // HandleMicInput(); - char S8DebugStr[6 * 40 + 1]; - // static constexpr auto reg = 0x6F; - DisplayBuff.ClearAll(); - - Fw.FormatString(S8DebugStr, "%05i %05i ", RadioDriver.GetVoiceAmplitude(), RadioDriver.GetAFAmplitude()); - Fw.PrintTextOnScreen(S8DebugStr, 0, 127, 0, 8, 0); - DrawMicInChart(); - } - - void DrawMicInChart() - { - static constexpr auto chartBottomY = 55; - static constexpr auto chartTopY = 16; - unsigned char u8LastYpoint; - for(unsigned short x = 0; x < 128; x++) - { - auto ypoint = RadioDriver.GetVoiceAmplitude(); - ypoint >>= 6; - if(ypoint >= chartBottomY - chartTopY) - { - ypoint = chartTopY; - } - else - { - ypoint = chartBottomY - ypoint; - } - - if(!x) u8LastYpoint = ypoint; - DisplayBuff.SetPixel(x, ypoint); - while (ypoint != u8LastYpoint) - { - u8LastYpoint += u8LastYpoint < ypoint ? 1 : -1; - DisplayBuff.SetPixel(x, u8LastYpoint); - } - - u8LastYpoint = ypoint; - } + HandleMicInput(); + char S8DebugStr[20]; + // int MicAmp = s32DeltaAmp / 8; // RadioDriver.GetAFAmplitude(); + // MicAmp = 4 + MicAmp; + // if (MicAmp > 0b111) + // MicAmp = 0b111; + // if (MicAmp < 0) + // MicAmp = 0; + unsigned short U16AdcData[2]; + AdcReadout(U16AdcData, U16AdcData+1); + FormatString(S8DebugStr, "in 1: %05i ", U16AdcData[0]); + PrintTextOnScreen(S8DebugStr, 0, 127, 0, 8, 0); + FormatString(S8DebugStr, "in 2: %05i ", U16AdcData[1]); + PrintTextOnScreen(S8DebugStr, 0, 127, 2, 8, 0); } void HandleMicInput() { - u16ActualAmp = Fw.BK4819Read(0x64); - // u16ActualAmp = Fw.BK4819Read(0x6F) & 0b1111111; + u16ActualAmp = BK4819Read(0x64); + // u16ActualAmp = BK4819Read(0x6F) & 0b1111111; s32DeltaAmp = u16OldAmp - u16ActualAmp; u16OldAmp = u16ActualAmp; } @@ -116,7 +85,7 @@ class CAmTx : public IView MicAmp = 0b111; if (MicAmp < 0) MicAmp = 0; - Fw.BK4819Write(0x36, ((MicAmp & 0b111) << 3) | (MicAmp & 0b111)); + BK4819Write(0x36, ((MicAmp & 0b111) << 3) | (MicAmp & 0b111)); } void HandleTxWfm() @@ -164,7 +133,7 @@ class CAmTx : public IView if (GPIOC->DATA & GPIO_PIN_3) { GPIOC->DATA &= ~GPIO_PIN_3; - *FwData.p8FlashLightStatus = 3; + gFlashLightStatus = 3; return true; } @@ -173,17 +142,17 @@ class CAmTx : public IView void DrawAmIcon(bool bDraw) { - memset(FwData.pStatusBarData, 0, 14); + memset(gStatusBarData, 0, 14); if (!bDraw) { return; } - memcpy(FwData.pStatusBarData, FwData.pSmallLeters + 223, 12); - unsigned char *pNegative = FwData.pStatusBarData; + memcpy(gStatusBarData, gSmallLeters + 223, 12); + unsigned char *pNegative = gStatusBarData; for (unsigned char i = 0; i < 14; i++) { *pNegative++ ^= 0xFF; } } -}; \ No newline at end of file +}; diff --git a/libs/views/heater.hpp b/libs/views/heater.hpp index 1c4955a..d3cae72 100644 --- a/libs/views/heater.hpp +++ b/libs/views/heater.hpp @@ -4,7 +4,6 @@ #include "keyboard.hpp" inline char S8Label[20]; -template class CHeater : public IMenuElement { bool bEnabled = false; @@ -28,23 +27,22 @@ class CHeater : public IMenuElement bEnabled = !bEnabled; if(bEnabled) { - Fw.BK4819SetGpio(1, true); + BK4819SetGpio(1, true); } else { - Fw.BK4819SetGpio(1, false); + BK4819SetGpio(1, false); } } }; -template class CAmRx : public IMenuElement { unsigned char u8Mode = 0; public: const char *GetLabel() override { - Fw.FormatString(S8Label, "AM RX %u", u8Mode); + FormatString(S8Label, "AM RX %u", u8Mode); return S8Label; } @@ -59,11 +57,11 @@ class CAmRx : public IMenuElement if(u8Mode > 2) u8Mode = 0; - // Fw.SomeAmStuff(u8Mode); + // SomeAmStuff(u8Mode); } }; -template &RadioDriver> +template class CMicVal : public IMenuElement { unsigned char u8Mode = 0; @@ -71,7 +69,7 @@ class CMicVal : public IMenuElement public: const char *GetLabel() override { - Fw.FormatString(S8Label, "MIC in %u", Fw.BK4819Read(0x64)); + FormatString(S8Label, "MIC in %u", BK4819Read(0x64)); return S8Label; } @@ -80,7 +78,7 @@ class CMicVal : public IMenuElement } }; -template &RadioDriver> +template class CRssiVal : public IMenuElement { unsigned char u8Mode = 0; @@ -89,11 +87,11 @@ class CRssiVal : public IMenuElement public: const char *GetLabel() override { - Fw.FormatString(S8Label, "RSSI %i", RadioDriver.GetRssi()); + FormatString(S8Label, "RSSI %i", RadioDriver.GetRssi()); return S8Label; } void HandleUserAction(unsigned char u8Button) override { } -}; \ No newline at end of file +}; diff --git a/libs/views/manager.hpp b/libs/views/manager.hpp index 6918d39..18ae194 100644 --- a/libs/views/manager.hpp +++ b/libs/views/manager.hpp @@ -4,8 +4,7 @@ #include "keyboard.hpp" #include "registers.hpp" -template @@ -48,7 +47,7 @@ class CViewManager % MainViewPrescaler)) { if(!MainViewContext.OriginalFwStatus.b1RadioSpiCommInUse) - Keyboard.Handle(Fw.PollKeyboard()); + Keyboard.Handle(PollKeyboard()); u8ScreenRefreshFlag |= pViewStackTop->HandleMainView(MainViewContext); @@ -56,12 +55,12 @@ class CViewManager if(u8ScreenRefreshFlag & eScreenRefreshFlag::MainScreen) { - Fw.FlushFramebufferToScreen(); + FlushFramebufferToScreen(); } if(u8ScreenRefreshFlag & eScreenRefreshFlag::StatusBar) { - Fw.FlushStatusbarBufferToScreen(); + FlushStatusbarBufferToScreen(); } } @@ -84,8 +83,8 @@ class CViewManager inline void CheckOriginalFwStatus() { - const auto *pMenuCheckData = (unsigned char *)(FwData.pDisplayBuffer + 2*128 + 6 * 8 + 1); - const auto *pFrequencyScanCheckData = (unsigned char *)(FwData.pDisplayBuffer + 6*128 + 3 * 8 + 2); + const auto *pMenuCheckData = (unsigned char *)(gDisplayBuffer + 2*128 + 6 * 8 + 1); + const auto *pFrequencyScanCheckData = (unsigned char *)(gDisplayBuffer + 6*128 + 3 * 8 + 2); MainViewContext.OriginalFwStatus.b1MenuDrawed = *pMenuCheckData == 0xFF; MainViewContext.OriginalFwStatus.b1FrequencyScan = *pFrequencyScanCheckData; MainViewContext.OriginalFwStatus.b1RadioSpiCommInUse = !(GPIOC->DATA & 0b1); @@ -109,4 +108,4 @@ class CViewManager pTop->HandleReleasedButton(MainViewContext, u8Key); } } -}; \ No newline at end of file +}; diff --git a/libs/views/menu.hpp b/libs/views/menu.hpp index 9850306..e19ca78 100644 --- a/libs/views/menu.hpp +++ b/libs/views/menu.hpp @@ -8,8 +8,6 @@ struct IMenuElement virtual void HandleUserAction(unsigned char u8Button) = 0; }; -template class CMenu : public IView { static constexpr auto MenuLines = 3; @@ -73,18 +71,18 @@ class CMenu : public IView void DrawMenu() { - memset(FwData.pDisplayBuffer, 0, 128*6); + memset(gDisplayBuffer, 0, 128*6); for(unsigned char u8Line = 0; u8Line < MenuLines; u8Line++) { auto* Element = GetElement(u8Selected - 1 + u8Line); if(!Element) continue; - Fw.PrintTextOnScreen(Element->GetLabel(), 0, 127, u8Line << 1, 8, 0); + PrintTextOnScreen(Element->GetLabel(), 0, 127, u8Line << 1, 8, 0); } for(auto i = 0; i < 256; i++) - FwData.pDisplayBuffer[i + 2*128] ^= 0xFF; + gDisplayBuffer[i + 2*128] ^= 0xFF; } IMenuElement* GetElement(signed char s8Idx) @@ -102,10 +100,10 @@ class CMenu : public IView if (GPIOC->DATA & GPIO_PIN_3) { GPIOC->DATA &= ~GPIO_PIN_3; - *FwData.p8FlashLightStatus = 3; + gFlashLightStatus = 3; return true; } return false; } -}; \ No newline at end of file +}; diff --git a/libs/views/messenger.hpp b/libs/views/messenger.hpp index 58ef53a..9ba9088 100644 --- a/libs/views/messenger.hpp +++ b/libs/views/messenger.hpp @@ -8,9 +8,7 @@ template < TUV_K5Display &DisplayBuff, CDisplay &Display, - const System::TOrgFunctions &Fw, - const System::TOrgData &FwData, - Radio::CBK4819 &RadioDriver> + Radio::CBK4819 &RadioDriver> class CMessenger : public IView { public: @@ -66,7 +64,7 @@ class CMessenger : public IView if (u8RxDoneLabelCnt < 100) { u8RxDoneLabelCnt++; - Fw.PrintTextOnScreen("> RX <", 0, 128, 2, 8, 1); + PrintTextOnScreen("> RX <", 0, 128, 2, 8, 1); } switch (State) @@ -100,8 +98,8 @@ class CMessenger : public IView void PrintTxData() { char C8PrintBuff[30]; - Fw.FormatString(C8PrintBuff, ">%s", T9.C8WorkingBuff); - Fw.PrintTextOnScreen(C8PrintBuff, 0, 128, 0, 8, 0); + FormatString(C8PrintBuff, ">%s", T9.C8WorkingBuff); + PrintTextOnScreen(C8PrintBuff, 0, 128, 0, 8, 0); } void PrintRxData() @@ -109,9 +107,9 @@ class CMessenger : public IView // char *tempRxBuff = S8RxBuff + MaxCharsInLine; // char C8Temp = tempRxBuff[MaxCharsInLine]; // S8RxBuff[MaxCharsInLine] = '\0'; - Fw.PrintTextOnScreen(S8RxBuff, 1, 128, 3, 8, 0); + PrintTextOnScreen(S8RxBuff, 1, 128, 3, 8, 0); // S8RxBuff[MaxCharsInLine] = C8Temp; - // Fw.PrintTextOnScreen(tempRxBuff, 1, 128, 5, 8, 0); + // PrintTextOnScreen(tempRxBuff, 1, 128, 5, 8, 0); } void HandleInitTx() @@ -124,7 +122,7 @@ class CMessenger : public IView State = eState::InitRx; } - Fw.PrintTextOnScreen("> TX <", 0, 128, 2, 8, 1); + PrintTextOnScreen("> TX <", 0, 128, 2, 8, 1); } void RxDoneHandler(unsigned char u8DataLen, bool bCrcOk) { @@ -142,12 +140,12 @@ class CMessenger : public IView { bEnabled = true; GPIOC->DATA &= ~GPIO_PIN_3; - *FwData.p8FlashLightStatus = 3; + gFlashLightStatus = 3; } if (bEnabled) { - // Keyboard.Handle(Fw.PollKeyboard()); + // Keyboard.Handle(PollKeyboard()); } return bEnabled; @@ -161,7 +159,7 @@ class CMessenger : public IView void ClearDrawings() { - memset(FwData.pDisplayBuffer, 0, (DisplayBuff.SizeX / 8) * DisplayBuff.SizeY); + memset(gDisplayBuffer, 0, (DisplayBuff.SizeX / 8) * DisplayBuff.SizeY); } void HandlePressedButton(unsigned char u8Button) override @@ -194,4 +192,4 @@ class CMessenger : public IView bool bEnabled; eState State; unsigned char u8RxDoneLabelCnt; -}; \ No newline at end of file +}; diff --git a/libs/views/rssi_printer.hpp b/libs/views/rssi_printer.hpp index f0fa8aa..7f02894 100644 --- a/libs/views/rssi_printer.hpp +++ b/libs/views/rssi_printer.hpp @@ -4,8 +4,6 @@ #include "manager.hpp" template < - System::TOrgFunctions &Fw, - System::TOrgData &FwData, TUV_K5Display &DisplayBuff, CDisplay &Display, TUV_K5SmallNumbers &FontSmallNr> @@ -25,7 +23,7 @@ class CRssiPrinter : public IView return eScreenRefreshFlag::NoRefresh; } - if (Fw.BK4819Read(0x0C) & 0b10) + if (BK4819Read(0x0C) & 0b10) { u8SqlDelayCnt = 0; } @@ -55,7 +53,7 @@ class CRssiPrinter : public IView Display.SetFont(&FontSmallNr); char C8RssiString[] = "g000"; - unsigned char u8Rssi = ((Fw.BK4819Read(0x67) >> 1) & 0xFF); + unsigned char u8Rssi = ((BK4819Read(0x67) >> 1) & 0xFF); if (!u8Rssi) { return eScreenRefreshFlag::NoRefresh; @@ -101,4 +99,4 @@ class CRssiPrinter : public IView u8ChartPosition++; return eScreenRefreshFlag::MainScreen; } -}; \ No newline at end of file +}; diff --git a/libs/views/rssi_sbar.hpp b/libs/views/rssi_sbar.hpp index 05d70e4..2c03d61 100644 --- a/libs/views/rssi_sbar.hpp +++ b/libs/views/rssi_sbar.hpp @@ -49,13 +49,11 @@ namespace Rssi } template < - const System::TOrgFunctions &Fw, - const System::TOrgData &FwData, TUV_K5Display &DisplayBuff, CDisplay &Display, CDisplay &DisplayStatusBar, const TUV_K5SmallNumbers &FontSmallNr, - Radio::CBK4819 &RadioDriver> + Radio::CBK4819 &RadioDriver> class CRssiSbar : public IView, public IMenuElement { public: @@ -67,7 +65,7 @@ class CRssiSbar : public IView, public IMenuElement static constexpr auto LinearBlocksCnt = 9; static constexpr auto VoltageOffset = 77; static constexpr auto MaxBarPoints = 13; - static inline unsigned char *const pDData = FwData.pDisplayBuffer + 128 * 3; + static inline unsigned char *const pDData = gDisplayBuffer + 128 * 3; unsigned int u32DrawVoltagePsc = 0; Rssi::TRssi RssiData; @@ -188,7 +186,7 @@ class CRssiSbar : public IView, public IMenuElement { if (bPtt) // print TX { - memcpy(pDData + 5 * 7, FwData.pSmallLeters + 128 * 2 + 8 * 3 + 2, 15); + memcpy(pDData + 5 * 7, gSmallLeters + 128 * 2 + 8 * 3 + 2, 15); unsigned char *pNegative = pDData + 5 * 7 - 2; for (unsigned char i = 0; i < 19; i++) { @@ -205,13 +203,13 @@ class CRssiSbar : public IView, public IMenuElement } else if (u8SValue > 9) { - memcpy(pDData + 5 * 7, FwData.pSmallLeters + 109 - 3 * 8, 8); + memcpy(pDData + 5 * 7, gSmallLeters + 109 - 3 * 8, 8); C8SignalString[1] = '0'; C8SignalString[0] = '0' + u8SValue - 9; } else { - memcpy(pDData + 5 * 7, FwData.pSmallLeters + 109, 8); + memcpy(pDData + 5 * 7, gSmallLeters + 109, 8); C8SignalString[0] = '0' + u8SValue; C8SignalString[1] = ' '; } @@ -234,20 +232,20 @@ class CRssiSbar : public IView, public IMenuElement void PrintBatteryVoltage() { - if(*(FwData.pStatusBarData + VoltageOffset + 4 * 6 + 1) || - *(FwData.pStatusBarData + VoltageOffset + 4 * 6 - 6)) + if(gStatusBarData[VoltageOffset + 4 * 6 + 1] || + gStatusBarData[VoltageOffset + 4 * 6 - 6]) { // disable printing when function or charging icon are printed return; } - unsigned short u16Voltage = *FwData.p16Voltage > 1000 ? 999 : *FwData.p16Voltage; + unsigned short u16Voltage = gVoltage > 1000 ? 999 : gVoltage; - memset(FwData.pStatusBarData + VoltageOffset, 0, 4 * 5); + memset(gStatusBarData + VoltageOffset, 0, 4 * 5); DisplayStatusBar.SetCoursor(0, VoltageOffset); DisplayStatusBar.PrintFixedDigitsNumber2(u16Voltage, 2, 1); - memset(FwData.pStatusBarData + VoltageOffset + 7 + 1, 0b1100000, 2); // dot + memset(gStatusBarData + VoltageOffset + 7 + 1, 0b1100000, 2); // dot DisplayStatusBar.SetCoursor(0, VoltageOffset + 7 + 4); DisplayStatusBar.PrintFixedDigitsNumber2(u16Voltage, 0, 2); - memcpy(FwData.pStatusBarData + VoltageOffset + 4 * 6 + 2, FwData.pSmallLeters + 128 * 2 + 102, 5); // V character + memcpy(gStatusBarData + VoltageOffset + 4 * 6 + 2, gSmallLeters + 128 * 2 + 102, 5); // V character } -}; \ No newline at end of file +}; diff --git a/src/am_tx/main.cpp b/src/am_tx/main.cpp index 30f62b3..d9391a8 100644 --- a/src/am_tx/main.cpp +++ b/src/am_tx/main.cpp @@ -6,17 +6,14 @@ #include "rssi_sbar.hpp" #include "manager.hpp" -const System::TOrgFunctions &Fw = System::OrgFunc_01_26; -const System::TOrgData &FwData = System::OrgData_01_26; - -TUV_K5Display DisplayBuff(FwData.pDisplayBuffer); -const TUV_K5SmallNumbers FontSmallNr(FwData.pSmallDigs); +TUV_K5Display DisplayBuff(gDisplayBuffer); +const TUV_K5SmallNumbers FontSmallNr(gSmallDigs); CDisplay Display(DisplayBuff); -TUV_K5Display StatusBarBuff(FwData.pStatusBarData); +TUV_K5Display StatusBarBuff(gStatusBarData); CDisplay DisplayStatusBar(StatusBarBuff); -Radio::CBK4819 RadioDriver; +Radio::CBK4819 RadioDriver; // CRssiSbar< // System::OrgFunc_01_26, @@ -29,8 +26,6 @@ Radio::CBK4819 RadioDriver; // RssiSbar; CAmTx< - System::OrgFunc_01_26, - System::OrgData_01_26, DisplayBuff, Display, DisplayStatusBar, @@ -40,20 +35,18 @@ CAmTx< static IView * const Views[] = {&AmTx}; CViewManager< - System::OrgFunc_01_26, - System::OrgData_01_26, 8, 1, sizeof(Views) / sizeof(*Views)> Manager(Views); int main() { - Fw.IRQ_RESET(); + IRQ_RESET(); return 0; } extern "C" void Reset_Handler() { - Fw.IRQ_RESET(); + IRQ_RESET(); } extern "C" void SysTick_Handler() @@ -67,5 +60,5 @@ extern "C" void SysTick_Handler() } Manager.Handle(); - Fw.IRQ_SYSTICK(); + IRQ_SYSTICK(); } \ No newline at end of file diff --git a/src/messenger/main.cpp b/src/messenger/main.cpp index 8a428a9..b5fa03c 100644 --- a/src/messenger/main.cpp +++ b/src/messenger/main.cpp @@ -3,26 +3,19 @@ #include "messenger.hpp" #include "radio.hpp" -const System::TOrgFunctions &Fw = System::OrgFunc_01_26; -const System::TOrgData &FwData = System::OrgData_01_26; +Radio::CBK4819 RadioDriver; -Radio::CBK4819 RadioDriver; - -CMessenger< - System::OrgFunc_01_26, - System::OrgData_01_26, - RadioDriver> - Messenger; +CMessenger Messenger; int main() { - Fw.IRQ_RESET(); + IRQ_RESET(); return 0; } extern "C" void Reset_Handler() { - Fw.IRQ_RESET(); + IRQ_RESET(); } extern "C" void SysTick_Handler() @@ -37,5 +30,5 @@ extern "C" void SysTick_Handler() RadioDriver.InterruptHandler(); Messenger.Handle(); - Fw.IRQ_SYSTICK(); -} \ No newline at end of file + IRQ_SYSTICK(); +} diff --git a/src/messenger/main_new.cpp b/src/messenger/main_new.cpp index 594be2f..e25a12b 100644 --- a/src/messenger/main_new.cpp +++ b/src/messenger/main_new.cpp @@ -5,25 +5,18 @@ #include "rssi_sbar.hpp" #include "manager.hpp" -const System::TOrgFunctions &Fw = System::OrgFunc_01_26; -const System::TOrgData &FwData = System::OrgData_01_26; - -TUV_K5Display DisplayBuff(FwData.pDisplayBuffer); -const TUV_K5SmallNumbers FontSmallNr(FwData.pSmallDigs); +TUV_K5Display DisplayBuff(gDisplayBuffer); +const TUV_K5SmallNumbers FontSmallNr(gSmallDigs); CDisplay Display(DisplayBuff); -Radio::CBK4819 RadioDriver; +Radio::CBK4819 RadioDriver; CMessenger< DisplayBuff, Display, - System::OrgFunc_01_26, - System::OrgData_01_26, RadioDriver> Messenger; CRssiSbar< - System::OrgFunc_01_26, - System::OrgData_01_26, DisplayBuff, Display, FontSmallNr> @@ -31,8 +24,6 @@ CRssiSbar< static IView * const Views[] = {&Messenger, &RssiSbar}; CViewManager< - System::OrgFunc_01_26, - System::OrgData_01_26, 16, 2, sizeof(Views) / sizeof(*Views)> Manager(Views); @@ -60,4 +51,4 @@ extern "C" void SysTick_Handler() RadioDriver.InterruptHandler(); Manager.Handle(); Fw.IRQ_SYSTICK(); -} \ No newline at end of file +} diff --git a/src/messenger/messenger.hpp b/src/messenger/messenger.hpp index 7feaf87..6737488 100644 --- a/src/messenger/messenger.hpp +++ b/src/messenger/messenger.hpp @@ -4,9 +4,7 @@ #include "radio.hpp" #include "t9.hpp" -template &RadioDriver> +template class CMessenger { public: @@ -23,7 +21,7 @@ class CMessenger }; CMessenger() - : DisplayBuff(FwData.pDisplayBuffer), + : DisplayBuff(gDisplayBuffer), Display(DisplayBuff), Keyboard(*this), T9(S8TxBuff), @@ -45,7 +43,7 @@ class CMessenger { bDisplayCleared = true; ClearDrawings(); - Fw.FlushFramebufferToScreen(); + FlushFramebufferToScreen(); } return; @@ -61,22 +59,22 @@ class CMessenger Display.DrawHLine(3, 3 + 10, 1 * 8 + T9.GetIdx() * 8 + 2); // print tx data - Fw.FormatString(C8PrintBuff, ">%s", T9.C8WorkingBuff); - Fw.PrintTextOnScreen(C8PrintBuff, 0, 128, 0, 8, 0); + FormatString(C8PrintBuff, ">%s", T9.C8WorkingBuff); + PrintTextOnScreen(C8PrintBuff, 0, 128, 0, 8, 0); // print rx data char C8Temp = S8RxBuff[MaxCharsInLine]; S8RxBuff[MaxCharsInLine] = '\0'; - Fw.PrintTextOnScreen(S8RxBuff, 1, 128, 3, 8, 0); + PrintTextOnScreen(S8RxBuff, 1, 128, 3, 8, 0); S8RxBuff[MaxCharsInLine] = C8Temp; - Fw.PrintTextOnScreen(S8RxBuff + MaxCharsInLine, 1, 128, 5, 8, 0); + PrintTextOnScreen(S8RxBuff + MaxCharsInLine, 1, 128, 5, 8, 0); Display.DrawRectangle(0, (8 * 4) - 6, 127, 24 + 6, false); if (u8RxDoneLabelCnt < 100) { u8RxDoneLabelCnt++; - Fw.PrintTextOnScreen(" >> RX << ", 0, 128, 2, 8, 1); + PrintTextOnScreen(" >> RX << ", 0, 128, 2, 8, 1); } switch (State) @@ -97,14 +95,14 @@ class CMessenger State = eState::InitRx; } - Fw.PrintTextOnScreen(" >> TX << ", 0, 128, 2, 8, 1); + PrintTextOnScreen(" >> TX << ", 0, 128, 2, 8, 1); break; } default: break; } - Fw.FlushFramebufferToScreen(); + FlushFramebufferToScreen(); } void RxDoneHandler(unsigned char u8DataLen, bool bCrcOk) @@ -123,12 +121,12 @@ class CMessenger { bEnabled = true; GPIOC->DATA &= ~GPIO_PIN_3; - *FwData.p8FlashLightStatus = 3; + gFlashLightStatus = 3; } if (bEnabled) { - Keyboard.Handle(Fw.PollKeyboard()); + Keyboard.Handle(PollKeyboard()); } return bEnabled; @@ -142,7 +140,7 @@ class CMessenger void ClearDrawings() { - memset(FwData.pDisplayBuffer, 0, (DisplayBuff.SizeX / 8) * DisplayBuff.SizeY); + memset(gDisplayBuffer, 0, (DisplayBuff.SizeX / 8) * DisplayBuff.SizeY); } void HandlePressedButton(unsigned char u8Button) @@ -178,4 +176,4 @@ class CMessenger bool bEnabled; eState State; unsigned char u8RxDoneLabelCnt; -}; \ No newline at end of file +}; diff --git a/src/most_useless_mod/main.cpp b/src/most_useless_mod/main.cpp index 4c5e9d7..9c86ac6 100644 --- a/src/most_useless_mod/main.cpp +++ b/src/most_useless_mod/main.cpp @@ -8,22 +8,18 @@ extern "C" void __libc_init_array(); -const System::TOrgFunctions& Fw = System::OrgFunc_01_26; - -Radio::CBK4819 RadioDriver; -CSpectrum - Spectrum; +Radio::CBK4819 RadioDriver; +CSpectrum Spectrum; int main() { - Fw.IRQ_RESET(); + IRQ_RESET(); return 0; } extern "C" void Reset_Handler() { - Fw.IRQ_RESET(); + IRQ_RESET(); } extern "C" void SysTick_Handler() @@ -41,5 +37,5 @@ extern "C" void SysTick_Handler() { Spectrum.Handle(); } - Fw.IRQ_SYSTICK(); -} \ No newline at end of file + IRQ_SYSTICK(); +} diff --git a/src/most_useless_mod/spectrum.hpp b/src/most_useless_mod/spectrum.hpp index 1c1d3ef..4ed2e58 100644 --- a/src/most_useless_mod/spectrum.hpp +++ b/src/most_useless_mod/spectrum.hpp @@ -3,9 +3,7 @@ #include "uv_k5_display.hpp" #include "radio.hpp" -template &RadioDriver> +template class CSpectrum { public: @@ -23,7 +21,7 @@ class CSpectrum }; CSpectrum() - : DisplayBuff(FwData.pDisplayBuffer), FontSmallNr(FwData.pSmallDigs), Display(DisplayBuff), State(eState::Init), u8RxCnt(0){}; + : DisplayBuff(gDisplayBuffer), FontSmallNr(gSmallDigs), Display(DisplayBuff), State(eState::Init), u8RxCnt(0){}; void Handle() { @@ -38,14 +36,14 @@ class CSpectrum { - Fw.DelayMs(600); + DelayMs(600); //memset(U8Buff, 0, sizeof(U8Buff)); RadioDriver.RecieveAsyncAirCopyMode(U8Buff, sizeof(U8Buff), Radio::CallbackRxDoneType(this, &CSpectrum::RxDoneHandler)); State = eState::RxPending; // while(State == eState::RxPending) // { // RadioDriver.InterruptHandler(); - // // if(Fw.PollKeyboard() != 0xFF) + // // if(PollKeyboard() != 0xFF) // // { // // break; // // } @@ -59,13 +57,13 @@ class CSpectrum char kupa[20]; U8Buff[10] = 0; DisplayBuff.ClearAll(); - Fw.FormatString(kupa, "RX DONE %u", u8RxCnt); - Fw.PrintTextOnScreen(kupa, 0, 127, 0, 8, 0); - Fw.FormatString(kupa, "LEN: %i", RadioDriver.u16RxDataLen); - Fw.PrintTextOnScreen(kupa, 0, 127, 2, 8, 0); - Fw.FormatString(kupa, "S: %s", U8Buff); - Fw.PrintTextOnScreen(kupa, 0, 127, 4, 8, 0); - Fw.FlushFramebufferToScreen(); + FormatString(kupa, "RX DONE %u", u8RxCnt); + PrintTextOnScreen(kupa, 0, 127, 0, 8, 0); + FormatString(kupa, "LEN: %i", RadioDriver.u16RxDataLen); + PrintTextOnScreen(kupa, 0, 127, 2, 8, 0); + FormatString(kupa, "S: %s", U8Buff); + PrintTextOnScreen(kupa, 0, 127, 4, 8, 0); + FlushFramebufferToScreen(); static unsigned int u32Cnt = 1; if(!(u32Cnt++%8)) @@ -74,29 +72,29 @@ class CSpectrum State = eState::Init; } - // Fw.WriteSerialData((unsigned char *)"RX packet, hex: ", 17); + // WriteSerialData((unsigned char *)"RX packet, hex: ", 17); // for (unsigned int i = 0; i < sizeof(U8Buff); i++) // { - // Fw.FormatString(kupa, "%02X", U8Buff[i]); - // Fw.WriteSerialData((unsigned char *)kupa, 1); + // FormatString(kupa, "%02X", U8Buff[i]); + // WriteSerialData((unsigned char *)kupa, 1); // } - // Fw.WriteSerialData((unsigned char *)"\n", 1); + // WriteSerialData((unsigned char *)"\n", 1); break; } case eState::RxPending: { - //Fw.AirCopyFskSetup(); + //AirCopyFskSetup(); char kupa[20]; DisplayBuff.ClearAll(); - Fw.FormatString(kupa, "Rx: %u kHz", Fw.IntDivide(RadioDriver.GetFrequency(), 100)); - Fw.PrintTextOnScreen(kupa, 0, 127, 0, 8, 0); - Fw.FormatString(kupa, "0x3F: 0x%04X", Fw.BK4819Read(0x3F)); - Fw.PrintTextOnScreen(kupa, 0, 127, 2, 8, 0); - Fw.FormatString(kupa, "len: %i", Fw.BK4819Read(0x5D) >> 8); - Fw.PrintTextOnScreen(kupa, 0, 127, 4, 8, 0); - Fw.FlushFramebufferToScreen(); + FormatString(kupa, "Rx: %u kHz", IntDivide(RadioDriver.GetFrequency(), 100)); + PrintTextOnScreen(kupa, 0, 127, 0, 8, 0); + FormatString(kupa, "0x3F: 0x%04X", BK4819Read(0x3F)); + PrintTextOnScreen(kupa, 0, 127, 2, 8, 0); + FormatString(kupa, "len: %i", BK4819Read(0x5D) >> 8); + PrintTextOnScreen(kupa, 0, 127, 4, 8, 0); + FlushFramebufferToScreen(); return; } @@ -110,18 +108,18 @@ class CSpectrum if(!(u32Cnt++%8)) { u8TxCnt++; - Fw.FormatString((char *)C8TxStr, "packet %i", u8TxCnt); + FormatString((char *)C8TxStr, "packet %i", u8TxCnt); RadioDriver.SendSyncAirCopyMode72((unsigned char *)C8TxStr); } DisplayBuff.ClearAll(); - Fw.FormatString(kupa, "TX: %u kHz", Fw.IntDivide(RadioDriver.GetFrequency(), 100)); - Fw.PrintTextOnScreen(kupa, 0, 127, 0, 8, 0); - Fw.FormatString(kupa, "Irq: 0x%04X", RadioDriver.GetIrqReg()); - Fw.PrintTextOnScreen(kupa, 0, 127, 2, 8, 0); - Fw.FormatString(kupa, "S: %s", C8TxStr); - Fw.PrintTextOnScreen(kupa, 0, 127, 4, 8, 0); - Fw.FlushFramebufferToScreen(); + FormatString(kupa, "TX: %u kHz", IntDivide(RadioDriver.GetFrequency(), 100)); + PrintTextOnScreen(kupa, 0, 127, 0, 8, 0); + FormatString(kupa, "Irq: 0x%04X", RadioDriver.GetIrqReg()); + PrintTextOnScreen(kupa, 0, 127, 2, 8, 0); + FormatString(kupa, "S: %s", C8TxStr); + PrintTextOnScreen(kupa, 0, 127, 4, 8, 0); + FlushFramebufferToScreen(); return; @@ -144,4 +142,4 @@ class CSpectrum eState State; unsigned char U8Buff[72]; unsigned char u8RxCnt; -}; \ No newline at end of file +}; diff --git a/src/pong/main.cpp b/src/pong/main.cpp index 8d4872f..d241f16 100644 --- a/src/pong/main.cpp +++ b/src/pong/main.cpp @@ -7,18 +7,17 @@ extern "C" void __libc_init_array(); -const System::TOrgFunctions& Fw = System::OrgFunc_01_26; -CSPong Pong; +CSPong Pong; int main() { - Fw.IRQ_RESET(); + IRQ_RESET(); return 0; } extern "C" void Reset_Handler() { - Fw.IRQ_RESET(); + IRQ_RESET(); } extern "C" void SysTick_Handler() @@ -36,5 +35,5 @@ extern "C" void SysTick_Handler() { Pong.Handle(); } - Fw.IRQ_SYSTICK(); -} \ No newline at end of file + IRQ_SYSTICK(); +} diff --git a/src/pong/pong.hpp b/src/pong/pong.hpp index 4548afc..8aa8784 100644 --- a/src/pong/pong.hpp +++ b/src/pong/pong.hpp @@ -3,14 +3,13 @@ #include "uv_k5_display.hpp" #include "gpt_pong.hpp" -template class CSPong { public: static constexpr auto StepSize = 0xFFFF / TUV_K5Display::SizeX; static constexpr auto StepSizeFreq = 10'000; CSPong() - : DisplayBuff(FwData.pDisplayBuffer), FontSmallNr(FwData.pSmallDigs), Display(DisplayBuff), x(DisplayBuff.SizeX / 2), y(DisplayBuff.SizeY / 2) + : DisplayBuff(gDisplayBuffer), FontSmallNr(gSmallDigs), Display(DisplayBuff), x(DisplayBuff.SizeX / 2), y(DisplayBuff.SizeY / 2) ,bEnabled(true){}; void Handle() @@ -23,7 +22,7 @@ class CSPong DisplayBuff.ClearAll(); char C8RssiString[] = "000"; - unsigned int u32Key = Fw.PollKeyboard(); + unsigned int u32Key = PollKeyboard(); if(u32Key == 13) // exit key { bEnabled = false; @@ -47,7 +46,7 @@ class CSPong u32Cnt++; if((u32Cnt >> 8) % 2) { - unsigned int* p32Buff = (unsigned int*)FwData.pDisplayBuffer; + unsigned int* p32Buff = (unsigned int*)gDisplayBuffer; for(int i = 0; i < (DisplayBuff.SizeX * DisplayBuff.SizeY) / (8*4); i++) { *p32Buff = ~(*p32Buff); @@ -56,7 +55,7 @@ class CSPong } - Fw.FlushFramebufferToScreen(); + FlushFramebufferToScreen(); } private: @@ -67,4 +66,4 @@ class CSPong unsigned char x, y; bool bEnabled; -}; \ No newline at end of file +}; diff --git a/src/rssi_printer/main.cpp b/src/rssi_printer/main.cpp index a0f3c94..87e3abd 100644 --- a/src/rssi_printer/main.cpp +++ b/src/rssi_printer/main.cpp @@ -6,18 +6,16 @@ #include Hardware::THardware Hw; -const System::TOrgFunctions& Fw = System::OrgFunc_01_26; -const System::TOrgData& FwData = System::OrgData_01_26; int main() { - Fw.IRQ_RESET(); + IRQ_RESET(); return 0; } extern "C" void Reset_Handler() { - Fw.IRQ_RESET(); + IRQ_RESET(); } extern "C" void SysTick_Handler() @@ -33,7 +31,7 @@ extern "C" void SysTick_Handler() static unsigned int u32StupidCounter = 1; if((!(u32StupidCounter++ % 15) && u32StupidCounter > 200)) // exit key { - CRssiPrinter::Handle(Fw, FwData); + CRssiPrinter::Handle(); } - Fw.IRQ_SYSTICK(); -} \ No newline at end of file + IRQ_SYSTICK(); +} diff --git a/src/rssi_printer/rssi_printer.hpp b/src/rssi_printer/rssi_printer.hpp index 5a1ff3a..9b4c848 100644 --- a/src/rssi_printer/rssi_printer.hpp +++ b/src/rssi_printer/rssi_printer.hpp @@ -6,14 +6,14 @@ class CRssiPrinter { public: static constexpr auto ChartStartX = 4*7 + 4; - static void Handle(const System::TOrgFunctions& Fw, const System::TOrgData& FwData) + static void Handle(void) { static bool bIsCleared = true; static unsigned char u8ChartPosition = 0; static unsigned char u8SqlDelayCnt = 0xFF; static unsigned char U8ScreenHistory[128 - ChartStartX] = {0}; - TUV_K5Display DisplayBuff(FwData.pDisplayBuffer); - const TUV_K5SmallNumbers FontSmallNr(FwData.pSmallDigs); + TUV_K5Display DisplayBuff(gDisplayBuffer); + const TUV_K5SmallNumbers FontSmallNr(gSmallDigs); CDisplay Display(DisplayBuff); if(!(GPIOC->DATA & 0b1)) @@ -22,7 +22,7 @@ class CRssiPrinter } auto* pMenuCheckData = (unsigned char*)DisplayBuff.GetCoursorData(DisplayBuff.GetCoursorPosition(2, 6*8 + 1)); - if(Fw.BK4819Read(0x0C) & 0b10) + if(BK4819Read(0x0C) & 0b10) { u8SqlDelayCnt = 0; } @@ -38,7 +38,7 @@ class CRssiPrinter u8ChartPosition = 0; if(*pMenuCheckData != 0xFF) { - Fw.FlushFramebufferToScreen(); + FlushFramebufferToScreen(); } } @@ -52,7 +52,7 @@ class CRssiPrinter Display.SetFont(&FontSmallNr); char C8RssiString[] = "g000"; - unsigned char u8Rssi = ((Fw.BK4819Read(0x67) >> 1) & 0xFF); + unsigned char u8Rssi = ((BK4819Read(0x67) >> 1) & 0xFF); if(!u8Rssi) { return; @@ -96,6 +96,6 @@ class CRssiPrinter memcpy(pDData, U8ScreenHistory, sizeof(U8ScreenHistory)); u8ChartPosition++; - Fw.FlushFramebufferToScreen(); + FlushFramebufferToScreen(); } -}; \ No newline at end of file +}; diff --git a/src/rssi_sbar/main.cpp b/src/rssi_sbar/main.cpp index 4aa210c..d8cb0da 100644 --- a/src/rssi_sbar/main.cpp +++ b/src/rssi_sbar/main.cpp @@ -6,21 +6,16 @@ #include "rssi_sbar.hpp" #include "manager.hpp" -const System::TOrgFunctions &Fw = System::OrgFunc_01_26; -const System::TOrgData &FwData = System::OrgData_01_26; - -TUV_K5Display DisplayBuff(FwData.pDisplayBuffer); -const TUV_K5SmallNumbers FontSmallNr(FwData.pSmallDigs); +TUV_K5Display DisplayBuff(gDisplayBuffer); +const TUV_K5SmallNumbers FontSmallNr(gSmallDigs); CDisplay Display(DisplayBuff); -TUV_K5Display StatusBarBuff(FwData.pStatusBarData); +TUV_K5Display StatusBarBuff(gStatusBarData); CDisplay DisplayStatusBar(StatusBarBuff); -Radio::CBK4819 RadioDriver; +Radio::CBK4819 RadioDriver; CRssiSbar< - System::OrgFunc_01_26, - System::OrgData_01_26, DisplayBuff, Display, DisplayStatusBar, @@ -30,8 +25,6 @@ CRssiSbar< #ifdef AM_TX CAmTx< - System::OrgFunc_01_26, - System::OrgData_01_26, DisplayBuff, Display, DisplayStatusBar, @@ -49,20 +42,18 @@ static IView *const Views[] = }; CViewManager< - System::OrgFunc_01_26, - System::OrgData_01_26, 8, 2, sizeof(Views) / sizeof(*Views)> Manager(Views); int main() { - Fw.IRQ_RESET(); + IRQ_RESET(); return 0; } extern "C" void Reset_Handler() { - Fw.IRQ_RESET(); + IRQ_RESET(); } extern "C" void SysTick_Handler() @@ -77,5 +68,5 @@ extern "C" void SysTick_Handler() RadioDriver.InterruptHandler(); Manager.Handle(); - Fw.IRQ_SYSTICK(); -} \ No newline at end of file + IRQ_SYSTICK(); +} diff --git a/src/rssi_sbar_hot/main.cpp b/src/rssi_sbar_hot/main.cpp index e7a5b79..1d86112 100644 --- a/src/rssi_sbar_hot/main.cpp +++ b/src/rssi_sbar_hot/main.cpp @@ -7,21 +7,16 @@ #include "manager.hpp" #include "heater.hpp" -const System::TOrgFunctions &Fw = System::OrgFunc_01_26; -const System::TOrgData &FwData = System::OrgData_01_26; - -TUV_K5Display DisplayBuff(FwData.pDisplayBuffer); -const TUV_K5SmallNumbers FontSmallNr(FwData.pSmallDigs); +TUV_K5Display DisplayBuff(gDisplayBuffer); +const TUV_K5SmallNumbers FontSmallNr(gSmallDigs); CDisplay Display(DisplayBuff); -TUV_K5Display StatusBarBuff(FwData.pStatusBarData); +TUV_K5Display StatusBarBuff(gStatusBarData); CDisplay DisplayStatusBar(StatusBarBuff); -Radio::CBK4819 RadioDriver; +Radio::CBK4819 RadioDriver; CRssiSbar< - System::OrgFunc_01_26, - System::OrgData_01_26, DisplayBuff, Display, DisplayStatusBar, @@ -29,8 +24,6 @@ CRssiSbar< RadioDriver> RssiSbar; // CAmTx< -// System::OrgFunc_01_26, -// System::OrgData_01_26, // DisplayBuff, // Display, // DisplayStatusBar, @@ -38,32 +31,29 @@ CRssiSbar< // RadioDriver> // AmTx; -CHeater Heater; -CAmRx AmRx; -// CMicVal MicVal; -// CRssiVal RssiVal; +CHeater Heater; +CAmRx AmRx; +// CMicVal MicVal; +// CRssiVal RssiVal; static IMenuElement * const MainMenuElements[] = {&Heater, &AmRx, &RssiSbar}; -CMenu Menu(MainMenuElements); +CMenu Menu(MainMenuElements); static IView * const Views[] = {&RssiSbar, &Menu}; CViewManager< - System::OrgFunc_01_26, - System::OrgData_01_26, 8, 1, sizeof(Views) / sizeof(*Views)> Manager(Views); int main() { - Fw.IRQ_RESET(); + IRQ_RESET(); return 0; } extern "C" void Reset_Handler() { - Fw.IRQ_RESET(); + IRQ_RESET(); } extern "C" void SysTick_Handler() @@ -78,5 +68,5 @@ extern "C" void SysTick_Handler() // RadioDriver.InterruptHandler(); Manager.Handle(); - Fw.IRQ_SYSTICK(); -} \ No newline at end of file + IRQ_SYSTICK(); +} diff --git a/src/spectrum/main.cpp b/src/spectrum/main.cpp index 6a70e94..0f32c62 100644 --- a/src/spectrum/main.cpp +++ b/src/spectrum/main.cpp @@ -6,21 +6,19 @@ #include Hardware::THardware Hw; -const System::TOrgFunctions& Fw = System::OrgFunc_01_26; -const System::TOrgData& FwData = System::OrgData_01_26; -CSpectrum Spectrum; +CSpectrum Spectrum; int main() { - Fw.IRQ_RESET(); + IRQ_RESET(); return 0; } extern "C" void Reset_Handler() { - Fw.IRQ_RESET(); + IRQ_RESET(); } extern "C" void SysTick_Handler() @@ -37,8 +35,8 @@ extern "C" void SysTick_Handler() bFirstInit = true; } - bool bPreventWhileKeypadPolling = pStackedRegs->LR > (unsigned int)Fw.PollKeyboard && - pStackedRegs->PC < (unsigned int)Fw.PollKeyboard + 0x100; // i made a mistake and compared PC and LR, but this works fine xD + bool bPreventWhileKeypadPolling = pStackedRegs->LR > (unsigned int)PollKeyboard && + pStackedRegs->PC < (unsigned int)PollKeyboard + 0x100; // i made a mistake and compared PC and LR, but this works fine xD static unsigned int u32StupidCounter = 1; if(u32StupidCounter++ > 200 && !bPreventWhileKeypadPolling) @@ -46,5 +44,5 @@ extern "C" void SysTick_Handler() Spectrum.Handle(); } - Fw.IRQ_SYSTICK(); -} \ No newline at end of file + IRQ_SYSTICK(); +} diff --git a/src/spectrum/spectrum.hpp b/src/spectrum/spectrum.hpp index 43aef82..1c14225 100644 --- a/src/spectrum/spectrum.hpp +++ b/src/spectrum/spectrum.hpp @@ -19,7 +19,6 @@ static constexpr auto operator""_MHz(unsigned long long KiloHertz) return KiloHertz * 1000_KHz; } -template class CSpectrum { public: @@ -33,8 +32,8 @@ class CSpectrum static constexpr auto PressDuration = 30; static constexpr auto BWStep = 200_KHz; CSpectrum() - : DisplayBuff(FwData.pDisplayBuffer), - FontSmallNr(FwData.pSmallDigs), + : DisplayBuff(gDisplayBuffer), + FontSmallNr(gSmallDigs), Display(DisplayBuff), bDisplayCleared(true), u32ScanRange(1_MHz), @@ -58,9 +57,9 @@ class CSpectrum { bDisplayCleared = true; ClearDrawings(); - Fw.FlushFramebufferToScreen(); + FlushFramebufferToScreen(); SetFrequency(u32OldFreq); - Fw.BK4819Write(0x47, u16OldAfSettings); // set previous AF settings + BK4819Write(0x47, u16OldAfSettings); // set previous AF settings } return; @@ -69,8 +68,8 @@ class CSpectrum if (bDisplayCleared) { u32OldFreq = GetFrequency(); - u16OldAfSettings = Fw.BK4819Read(0x47); - Fw.BK4819Write(0x47, 0); // mute AF during scan + u16OldAfSettings = BK4819Read(0x47); + BK4819Write(0x47, 0); // mute AF during scan } bDisplayCleared = false; @@ -118,7 +117,7 @@ class CSpectrum { if (!(u8Pos % (DisplayBuff.SizeX / LabelsCnt)) || u8Pos == DisplayBuff.SizeX - 1) { - *(FwData.pDisplayBuffer + 2 * DisplayBuff.SizeX + u8Pos) = 0xFF; + gDisplayBuffer[2 * DisplayBuff.SizeX + u8Pos] = 0xFF; } auto const FreqOffset = (u8Pos * u32ScanRange) >> 7; @@ -140,7 +139,7 @@ class CSpectrum } } // Display.DrawRectangle(0,0, 7, 7, 0); - memcpy(FwData.pDisplayBuffer + 8 * 2 + 10 * 6 + 2, FwData.pSmallLeters + 18 + 5, 7); + memcpy(gDisplayBuffer + 8 * 2 + 10 * 6 + 2, gSmallLeters + 18 + 5, 7); Display.SetCoursor(0, 0); Display.PrintFixedDigitsNumber2(u32OldFreq); Display.SetCoursor(1, 0); @@ -152,31 +151,31 @@ class CSpectrum Display.SetCoursor(0, 8 * 2 + 10 * 7); Display.PrintFixedDigitsNumber2(u32Peak); - memcpy(FwData.pDisplayBuffer + 128 * 2 + u8PeakPos - 3, FwData.pSmallLeters + 18 + 5, 7); - Fw.FlushFramebufferToScreen(); + memcpy(gDisplayBuffer + 128 * 2 + u8PeakPos - 3, gSmallLeters + 18 + 5, 7); + FlushFramebufferToScreen(); } private: void SetFrequency(unsigned int u32Freq) { - Fw.BK4819Write(0x39, ((u32Freq >> 16) & 0xFFFF)); - Fw.BK4819Write(0x38, (u32Freq & 0xFFFF)); - // Fw.BK4819Write(0x37,7951); - Fw.BK4819Write(0x30, 0); - Fw.BK4819Write(0x30, 0xbff1); + BK4819Write(0x39, ((u32Freq >> 16) & 0xFFFF)); + BK4819Write(0x38, (u32Freq & 0xFFFF)); + // BK4819Write(0x37,7951); + BK4819Write(0x30, 0); + BK4819Write(0x30, 0xbff1); } unsigned char GetRssi(unsigned int u32Freq) { SetFrequency(u32Freq); - Fw.DelayUs(800); - return ((Fw.BK4819Read(0x67) >> 1) & 0xFF); + DelayUs(800); + return ((BK4819Read(0x67) >> 1) & 0xFF); } unsigned int GetFrequency() { - unsigned short u16f1 = Fw.BK4819Read(0x39); - unsigned short u16f2 = Fw.BK4819Read(0x38); + unsigned short u16f1 = BK4819Read(0x39); + unsigned short u16f2 = BK4819Read(0x38); return ((u16f1 << 16) | u16f2); } @@ -187,12 +186,12 @@ class CSpectrum { bEnabled = true; GPIOC->DATA &= ~GPIO_PIN_3; - *FwData.p8FlashLightStatus = 3; + gFlashLightStatus = 3; } if (bEnabled) { - u8LastBtnPressed = Fw.PollKeyboard(); + u8LastBtnPressed = PollKeyboard(); } bool bPtt = !(GPIOC->DATA & GPIO_PIN_5); @@ -206,7 +205,7 @@ class CSpectrum void ClearDrawings() { - memset(FwData.pDisplayBuffer, 0, (DisplayBuff.SizeX / 8) * DisplayBuff.SizeY); + memset(gDisplayBuffer, 0, (DisplayBuff.SizeX / 8) * DisplayBuff.SizeY); } TUV_K5Display DisplayBuff; @@ -223,4 +222,4 @@ class CSpectrum unsigned char u8ResolutionDiv; bool bEnabled; char C8Info[20]; -}; \ No newline at end of file +}; diff --git a/src/spectrum_fagci/main.cpp b/src/spectrum_fagci/main.cpp index 1dcc680..1f9f326 100644 --- a/src/spectrum_fagci/main.cpp +++ b/src/spectrum_fagci/main.cpp @@ -7,18 +7,16 @@ #include Hardware::THardware Hw; -const System::TOrgFunctions &Fw = System::OrgFunc_01_26; -const System::TOrgData &FwData = System::OrgData_01_26; -Radio::CBK4819 RadioDriver; -CSpectrum Spectrum; +Radio::CBK4819 RadioDriver; +CSpectrum Spectrum; int main() { - Fw.IRQ_RESET(); + IRQ_RESET(); return 0; } -extern "C" void Reset_Handler() { Fw.IRQ_RESET(); } +extern "C" void Reset_Handler() { IRQ_RESET(); } extern "C" void SysTick_Handler() { static bool bFirstInit = false; @@ -30,5 +28,5 @@ extern "C" void SysTick_Handler() { Spectrum.Handle(); - Fw.IRQ_SYSTICK(); + IRQ_SYSTICK(); } diff --git a/src/spectrum_fagci/spectrum.hpp b/src/spectrum_fagci/spectrum.hpp index ef0ee1c..ab7869b 100644 --- a/src/spectrum_fagci/spectrum.hpp +++ b/src/spectrum_fagci/spectrum.hpp @@ -11,8 +11,7 @@ typedef unsigned int u32; typedef signed long long i64; typedef unsigned long long u64; -template &RadioDriver> +template class CSpectrum { public: static constexpr auto ExitKey = 13; @@ -29,7 +28,7 @@ class CSpectrum { u32 FStart, fMeasure; CSpectrum() - : DisplayBuff(FwData.pDisplayBuffer), FontSmallNr(FwData.pSmallDigs), + : DisplayBuff(gDisplayBuffer), FontSmallNr(gSmallDigs), Display(DisplayBuff), scanDelay(800), sampleZoom(2), scanStep(25_KHz), frequencyChangeStep(100_KHz), rssiTriggerLevel(65), stickyPeakTrigger(false) { Display.SetFont(&FontSmallNr); @@ -43,7 +42,7 @@ class CSpectrum { if (fMeasure != highestPeakF) { fMeasure = highestPeakF; RadioDriver.SetFrequency(fMeasure); - Fw.BK4819Write(0x47, u16OldAfSettings); + BK4819Write(0x47, u16OldAfSettings); RadioDriver.ToggleAFDAC(true); } @@ -64,7 +63,7 @@ class CSpectrum { fMeasure = FStart; RadioDriver.ToggleAFDAC(false); - Fw.BK4819Write(0x47, 0); + BK4819Write(0x47, 0); for (u8 i = 0; i < measurementsCount; ++i, fMeasure += scanStep) { rssi = rssiHistory[i] = GetRssi(fMeasure); @@ -134,15 +133,15 @@ class CSpectrum { modulo(f, 500_KHz) < step && (barValue |= 0b00100000); modulo(f, 1_MHz) < step && (barValue |= 0b11000000); - *(FwData.pDisplayBuffer + BarPos + i) |= barValue; + gDisplayBuffer[BarPos + i] |= barValue; } // center - *(FwData.pDisplayBuffer + BarPos + 64) |= 0b10101010; + gDisplayBuffer[BarPos + 64] |= 0b10101010; } inline void DrawArrow(u8 x) { - u8 *peakPos = FwData.pDisplayBuffer + BarPos + x; + u8 *peakPos = gDisplayBuffer + BarPos + x; x > 1 && (*(peakPos - 2) |= 0b01000000); x > 0 && (*(peakPos - 1) |= 0b01100000); (*(peakPos) |= 0b01110000); @@ -205,15 +204,15 @@ class CSpectrum { DrawSpectrum(); DrawRssiTriggerLevel(); DrawNums(); - Fw.FlushFramebufferToScreen(); + FlushFramebufferToScreen(); } void Update() { if (bDisplayCleared) { currentFreq = RadioDriver.GetFrequency(); OnUserInput(); - u16OldAfSettings = Fw.BK4819Read(0x47); - Fw.BK4819Write(0x47, 0); // mute AF during scan + u16OldAfSettings = BK4819Read(0x47); + BK4819Write(0x47, 0); // mute AF during scan } bDisplayCleared = false; @@ -269,7 +268,7 @@ class CSpectrum { highestPeakX = 64; highestPeakF = currentFreq; - Fw.DelayUs(90000); + DelayUs(90000); } void Handle() { @@ -285,7 +284,7 @@ class CSpectrum { return; } - lastButtonPressed = Fw.PollKeyboard(); + lastButtonPressed = PollKeyboard(); if (lastButtonPressed == ExitKey) { working = false; RestoreParams(); @@ -300,16 +299,16 @@ class CSpectrum { if (!bDisplayCleared) { bDisplayCleared = true; DisplayBuff.ClearAll(); - Fw.FlushFramebufferToScreen(); + FlushFramebufferToScreen(); RadioDriver.SetFrequency(currentFreq); - Fw.BK4819Write(0x47, u16OldAfSettings); // set previous AF settings + BK4819Write(0x47, u16OldAfSettings); // set previous AF settings } } inline void Listen(u32 duration) { for (u8 i = 0; i < 16 && lastButtonPressed == 255; ++i) { - lastButtonPressed = Fw.PollKeyboard(); - Fw.DelayUs(duration >> 4); + lastButtonPressed = PollKeyboard(); + DelayUs(duration >> 4); } } @@ -320,8 +319,8 @@ class CSpectrum { RadioDriver.ToggleRXDSP(true); } - Fw.DelayUs(scanDelay); - return Fw.BK4819Read(0x67); + DelayUs(scanDelay); + return BK4819Read(0x67); } u8 GetRssi(u32 f) { @@ -332,7 +331,7 @@ class CSpectrum { inline bool IsFlashLightOn() { return GPIOC->DATA & GPIO_PIN_3; } inline void TurnOffFlashLight() { GPIOC->DATA &= ~GPIO_PIN_3; - *FwData.p8FlashLightStatus = 3; + gFlashLightStatus = 3; } inline void ToggleBacklight() { GPIOB->DATA ^= GPIO_PIN_6; } diff --git a/src/t9_texting/main.cpp b/src/t9_texting/main.cpp index 7e95006..04f892e 100644 --- a/src/t9_texting/main.cpp +++ b/src/t9_texting/main.cpp @@ -6,20 +6,18 @@ #include Hardware::THardware Hw; -const System::TOrgFunctions& Fw = System::OrgFunc_01_26; -const System::TOrgData& FwData = System::OrgData_01_26; -CT9Texting T9Texting; +CT9Texting T9Texting; int main() { - Fw.IRQ_RESET(); + IRQ_RESET(); return 0; } extern "C" void Reset_Handler() { - Fw.IRQ_RESET(); + IRQ_RESET(); } extern "C" void SysTick_Handler() @@ -36,13 +34,13 @@ extern "C" void SysTick_Handler() bFirstInit = true; } - bool bPreventWhileKeypadPolling = pStackedRegs->LR > (unsigned int)Fw.PollKeyboard && - pStackedRegs->PC < (unsigned int)Fw.PollKeyboard + 0x100; // i made a mistake and compared PC and LR, but this works fine xD + bool bPreventWhileKeypadPolling = pStackedRegs->LR > (unsigned int)PollKeyboard && + pStackedRegs->PC < (unsigned int)PollKeyboard + 0x100; // i made a mistake and compared PC and LR, but this works fine xD static unsigned int u32StupidCounter = 1; if(u32StupidCounter++ > 200 && !bPreventWhileKeypadPolling) { T9Texting.Handle(); } - Fw.IRQ_SYSTICK(); -} \ No newline at end of file + IRQ_SYSTICK(); +} diff --git a/src/t9_texting/t9_texting.hpp b/src/t9_texting/t9_texting.hpp index 2943362..1d42452 100644 --- a/src/t9_texting/t9_texting.hpp +++ b/src/t9_texting/t9_texting.hpp @@ -3,12 +3,11 @@ #include "uv_k5_display.hpp" #include "keyboard.hpp" -template class CT9Texting { public: CT9Texting() - : DisplayBuff(FwData.pDisplayBuffer), + : DisplayBuff(gDisplayBuffer), Display(DisplayBuff), Keyboard(*this), bDisplayCleared(true), @@ -67,7 +66,7 @@ class CT9Texting // Clear cMessage memset(cMessage, 0, 30); c_index = 0; - Fw.FlushFramebufferToScreen(); + FlushFramebufferToScreen(); } return; @@ -123,8 +122,8 @@ class CT9Texting prev_key = key; // Display.DrawRectangle(0,0, 7, 7, 0); ClearDrawings(); - Fw.PrintTextOnScreen(cMessage, 0, 128, 0, 8, 0); - Fw.FlushFramebufferToScreen(); + PrintTextOnScreen(cMessage, 0, 128, 0, 8, 0); + FlushFramebufferToScreen(); } private: @@ -136,15 +135,15 @@ class CT9Texting { bEnabled = true; GPIOC->DATA &= ~GPIO_PIN_3; - *FwData.p8FlashLightStatus = 3; + gFlashLightStatus = 3; } if (bEnabled) { - u8LastBtnPressed = Fw.PollKeyboard(); + u8LastBtnPressed = PollKeyboard(); } - // u8LastBtnPressed = Fw.PollKeyboard(); + // u8LastBtnPressed = PollKeyboard(); // if (u8LastBtnPressed == EnableKey) // { // u8PressCnt++; @@ -161,7 +160,7 @@ class CT9Texting void ClearDrawings() { - memset(FwData.pDisplayBuffer, 0, (DisplayBuff.SizeX / 8) * DisplayBuff.SizeY); + memset(gDisplayBuffer, 0, (DisplayBuff.SizeX / 8) * DisplayBuff.SizeY); } TUV_K5Display DisplayBuff;