performance tuning, cleanup

pull/49/head
Mikhail Yudin 2023-07-21 17:50:18 +07:00
rodzic 1bfe00edc1
commit d74995264f
3 zmienionych plików z 57 dodań i 78 usunięć

Wyświetl plik

@ -11,6 +11,7 @@ target_link_libraries(${NAME}
orginal_fw orginal_fw
uv_k5_system uv_k5_system
lcd lcd
radio
) )
target_include_directories(${NAME} PUBLIC target_include_directories(${NAME} PUBLIC

Wyświetl plik

@ -1,50 +1,34 @@
#include "system.hpp"
#include "hardware/hardware.hpp" #include "hardware/hardware.hpp"
#include "registers.hpp" #include "registers.hpp"
#include "uv_k5_display.hpp"
#include "spectrum.hpp" #include "spectrum.hpp"
#include "system.hpp"
#include "radio.hpp"
#include "uv_k5_display.hpp"
#include <string.h> #include <string.h>
Hardware::THardware Hw; Hardware::THardware Hw;
const System::TOrgFunctions& Fw = System::OrgFunc_01_26; const System::TOrgFunctions &Fw = System::OrgFunc_01_26;
const System::TOrgData& FwData = System::OrgData_01_26; const System::TOrgData &FwData = System::OrgData_01_26;
CSpectrum<System::OrgFunc_01_26, System::OrgData_01_26> Spectrum; Radio::CBK4819<System::OrgFunc_01_26> RadioDriver;
CSpectrum<System::OrgFunc_01_26, System::OrgData_01_26, RadioDriver> Spectrum;
int main() {
int main() Fw.IRQ_RESET();
{ return 0;
Fw.IRQ_RESET();
return 0;
} }
extern "C" void Reset_Handler() extern "C" void Reset_Handler() { Fw.IRQ_RESET(); }
{
Fw.IRQ_RESET(); extern "C" void SysTick_Handler() {
static bool bFirstInit = false;
if (!bFirstInit) {
System::CopyDataSection();
__libc_init_array();
bFirstInit = true;
}
Spectrum.Handle();
Fw.IRQ_SYSTICK();
} }
extern "C" void SysTick_Handler()
{
unsigned int u32Dummy;
System::TCortexM0Stacking* pStackedRegs =
(System::TCortexM0Stacking*)(((unsigned int*)&u32Dummy) + 1);
static bool bFirstInit = false;
if(!bFirstInit)
{
System::CopyDataSection();
__libc_init_array();
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
static unsigned int u32StupidCounter = 1;
if(u32StupidCounter++ > 200 && !bPreventWhileKeypadPolling)
{
Spectrum.Handle();
}
Fw.IRQ_SYSTICK();
}

Wyświetl plik

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "system.hpp" #include "system.hpp"
#include "uv_k5_display.hpp" #include "uv_k5_display.hpp"
#include "radio.hpp"
typedef unsigned char u8; typedef unsigned char u8;
typedef signed short i16; typedef signed short i16;
@ -16,10 +17,10 @@ static constexpr auto operator""_MHz(u64 KHz) { return KHz * 1000_KHz; }
static constexpr auto operator""_ms(u64 us) { return us * 1000; } static constexpr auto operator""_ms(u64 us) { return us * 1000; }
static constexpr auto operator""_s(u64 us) { return us * 1000_ms; } static constexpr auto operator""_s(u64 us) { return us * 1000_ms; }
template <const System::TOrgFunctions &Fw, const System::TOrgData &FwData> template <const System::TOrgFunctions &Fw, const System::TOrgData &FwData, Radio::CBK4819<Fw> &RadioDriver>
class CSpectrum { class CSpectrum {
public: public:
static constexpr auto EnableKey = 13; static constexpr auto ExitKey = 13;
static constexpr auto DrawingSizeY = 16 + 6 * 8; static constexpr auto DrawingSizeY = 16 + 6 * 8;
static constexpr auto DrawingEndY = 42; static constexpr auto DrawingEndY = 42;
static constexpr auto BarPos = 5 * 128; static constexpr auto BarPos = 5 * 128;
@ -31,16 +32,12 @@ public:
u8 highestPeakT = 0; u8 highestPeakT = 0;
u8 highestPeakRssi = 0; u8 highestPeakRssi = 0;
u32 highestPeakF = 0; u32 highestPeakF = 0;
u32 FStart; u32 FStart, FEnd, fMeasure;
u32 FEnd;
u32 fMeasure;
u8 rssiTriggerLevel = 65;
CSpectrum() CSpectrum()
: DisplayBuff(FwData.pDisplayBuffer), FontSmallNr(FwData.pSmallDigs), : DisplayBuff(FwData.pDisplayBuffer), FontSmallNr(FwData.pSmallDigs),
Display(DisplayBuff), bDisplayCleared(true), sampleZoom(2), Display(DisplayBuff), scanDelay(800), sampleZoom(2), scanStep(25_KHz),
scanStep(25_KHz), working(0), scanDelay(800), isUserInput(false) { rssiTriggerLevel(65) {
Display.SetFont(&FontSmallNr); Display.SetFont(&FontSmallNr);
}; };
@ -190,11 +187,13 @@ public:
} }
void Render() { void Render() {
DisplayBuff.ClearAll();
DrawTicks(); DrawTicks();
DrawArrow(highestPeakX); DrawArrow(highestPeakX);
DrawSpectrum(); DrawSpectrum();
DrawRssiTriggerLevel(); DrawRssiTriggerLevel();
DrawNums(); DrawNums();
Fw.FlushFramebufferToScreen();
} }
void Update() { void Update() {
@ -258,20 +257,26 @@ public:
} }
void Handle() { void Handle() {
if (!(GPIOC->DATA & 0b1)) { if (RadioDriver.IsLockedByOrgFw()) {
return; return;
} }
if (!FreeToDraw()) { if (!working) {
if (IsFlashLightOn()) {
working = true;
TurnOffFlashLight();
}
return;
}
u8LastBtnPressed = Fw.PollKeyboard();
if (u8LastBtnPressed == ExitKey) {
working = false;
RestoreParams(); RestoreParams();
return; return;
} }
Update(); Update();
DisplayBuff.ClearAll();
Render(); Render();
Fw.FlushFramebufferToScreen();
} }
private: private:
@ -302,24 +307,10 @@ private:
return (Fw.BK4819Read(0x39) << 16) | Fw.BK4819Read(0x38); return (Fw.BK4819Read(0x39) << 16) | Fw.BK4819Read(0x38);
} }
bool FreeToDraw() { inline bool IsFlashLightOn() { return GPIOC->DATA & GPIO_PIN_3; }
bool bFlashlight = GPIOC->DATA & GPIO_PIN_3; inline void TurnOffFlashLight() {
if (bFlashlight) { GPIOC->DATA &= ~GPIO_PIN_3;
working = true; *FwData.p8FlashLightStatus = 3;
GPIOC->DATA &= ~GPIO_PIN_3;
*FwData.p8FlashLightStatus = 3;
}
if (working) {
u8LastBtnPressed = Fw.PollKeyboard();
}
bool bPtt = !(GPIOC->DATA & GPIO_PIN_5);
if (bPtt || u8LastBtnPressed == EnableKey) {
working = false;
}
return working;
} }
inline u8 Rssi2Y(u8 rssi) { inline u8 Rssi2Y(u8 rssi) {
@ -343,14 +334,17 @@ private:
TUV_K5Display DisplayBuff; TUV_K5Display DisplayBuff;
const TUV_K5SmallNumbers FontSmallNr; const TUV_K5SmallNumbers FontSmallNr;
CDisplay<const TUV_K5Display> Display; CDisplay<const TUV_K5Display> Display;
bool bDisplayCleared;
u8 sampleZoom; u8 u8LastBtnPressed;
u32 scanStep;
u32 currentFreq; u32 currentFreq;
u16 u16OldAfSettings; u16 u16OldAfSettings;
u8 u8LastBtnPressed;
bool working;
u16 scanDelay; u16 scanDelay;
bool isUserInput; u8 sampleZoom;
u32 scanStep;
u8 rssiTriggerLevel;
bool working = false;
bool isUserInput = false;
bool bDisplayCleared = true;
}; };