kopia lustrzana https://github.com/piotr022/UV_K5_playground
fsk-tests
rodzic
bedd38fc5d
commit
cf825bca79
|
@ -9,6 +9,41 @@
|
|||
"ostream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"type_traits": "cpp"
|
||||
"type_traits": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"utility": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iostream": "cpp",
|
||||
"limits": "cpp",
|
||||
"ranges": "cpp",
|
||||
"typeinfo": "cpp"
|
||||
}
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
add_subdirectory(k5_uv_system)
|
||||
add_subdirectory(lcd)
|
||||
add_subdirectory(lcd)
|
||||
add_subdirectory(radio)
|
|
@ -55,7 +55,17 @@ namespace System
|
|||
char* (*sprintf)(char *, const char *, ...);
|
||||
void(*FillWithZero)(unsigned char* p8Data, unsigned int u32Size);
|
||||
char* (*FormatString)(char *, const char *, ...);
|
||||
|
||||
void(*PlayTone)(unsigned int u32Frequency, unsigned int u32TuningGain);
|
||||
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)();
|
||||
void(*IntDivide)(int s32Divident, int s32Divisor);
|
||||
void(*BK4819WriteFrequency)(unsigned int u32Frequency);
|
||||
void(*BK4819SetPaGain)(unsigned short u16PaBias, unsigned int u32Frequency);
|
||||
void(*BK4819ConfigureAndStartTxFsk)();
|
||||
|
||||
};
|
||||
|
||||
struct TOrgData
|
||||
|
@ -70,7 +80,7 @@ namespace System
|
|||
{
|
||||
.PrintTextOnScreen = (decltype(TOrgFunctions::PrintTextOnScreen))(0x874C + 1),
|
||||
.FillScreenMemory = (decltype(TOrgFunctions::FillScreenMemory))(0xb70c + 1),
|
||||
.DelayMs = (decltype(TOrgFunctions::DelayMs)) (0xD0EE + 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)),
|
||||
|
@ -80,6 +90,16 @@ namespace System
|
|||
.sprintf = (decltype(TOrgFunctions::sprintf) (0xc8ec + 1)),
|
||||
.FillWithZero = (decltype(TOrgFunctions::FillWithZero) (0x1AA + 1)),
|
||||
.FormatString = (decltype(TOrgFunctions::FormatString) (0xC6E8 + 1)),
|
||||
.PlayTone = (decltype(TOrgFunctions::PlayTone) (0x9F14 + 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)),
|
||||
};
|
||||
|
||||
inline const TOrgData OrgData_01_26 =
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
set(NAME radio)
|
||||
|
||||
add_library(${NAME} STATIC)
|
||||
|
||||
target_include_directories(${NAME} INTERFACE
|
||||
.
|
||||
)
|
||||
|
||||
target_include_directories(${NAME} PRIVATE
|
||||
.
|
||||
)
|
||||
|
||||
target_sources(${NAME} PRIVATE
|
||||
radio.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${NAME}
|
||||
uv_k5_system
|
||||
)
|
||||
|
||||
target_compile_options(${NAME} PRIVATE ${COMPILER_OPTIONS})
|
||||
|
|
@ -0,0 +1 @@
|
|||
#include "radio.hpp"
|
|
@ -0,0 +1,118 @@
|
|||
#pragma once
|
||||
#include "system.hpp"
|
||||
#include "registers.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace Radio
|
||||
{
|
||||
enum class eModulation : unsigned char
|
||||
{
|
||||
Ffsk,
|
||||
Fsk,
|
||||
};
|
||||
|
||||
struct TRadioConf
|
||||
{
|
||||
eModulation Modulation;
|
||||
};
|
||||
|
||||
enum class eState : unsigned char
|
||||
{
|
||||
Idle,
|
||||
RxPending,
|
||||
};
|
||||
|
||||
struct IRadioUser
|
||||
{
|
||||
virtual void RxDoneHandler(){};
|
||||
};
|
||||
|
||||
template <const System::TOrgFunctions &Fw>
|
||||
class CBK4819
|
||||
{
|
||||
public:
|
||||
CBK4819(){};
|
||||
|
||||
void SetFrequency(unsigned int u32FrequencyD10)
|
||||
{
|
||||
Fw.BK4819WriteFrequency(u32FrequencyD10);
|
||||
}
|
||||
|
||||
unsigned int GetFrequency()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SendSyncAirCopyMode72(unsigned char *p8Data)
|
||||
{
|
||||
Fw.BK4819ConfigureAndStartTxFsk();
|
||||
Fw.AirCopyFskSetup();
|
||||
Fw.AirCopy72(p8Data);
|
||||
}
|
||||
|
||||
void RecieveAsyncAirCopyMode(unsigned char *p8Data, unsigned char u8DataLen, IRadioUser* pUser)
|
||||
{
|
||||
if (!p8Data || !u8DataLen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pRadioUser = pUser;
|
||||
p8RxBuff = p8Data;
|
||||
u8RxBuffSize = u8DataLen;
|
||||
|
||||
Fw.AirCopyFskSetup();
|
||||
Fw.BK4819Write(0x59, 1 << 14); // clear rx fifo
|
||||
Fw.BK4819Write(0x59, 0b0011'0000'0110'1000); // enable rx
|
||||
Fw.BK4819Write(0x3f, 1 << 13); // enable rx done irq
|
||||
|
||||
Fw.BK4819Write(0x30, 0);
|
||||
Fw.BK4819Write(0x30, 0b1011'1101'1111'0001);
|
||||
State = eState::RxPending;
|
||||
}
|
||||
|
||||
bool IsLockedByOrgFw()
|
||||
{
|
||||
return !(GPIOC->DATA & 0b1);
|
||||
}
|
||||
|
||||
void InterruptHandler()
|
||||
{
|
||||
if (IsLockedByOrgFw())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (State == eState::RxPending)
|
||||
{
|
||||
auto const IrqReg = Fw.BK4819Read(0x02);
|
||||
if (IrqReg & (1 << 13))
|
||||
{
|
||||
State = eState::Idle;
|
||||
Fw.BK4819Write(0x2, 0);
|
||||
unsigned char u8DataLen = Fw.BK4819Read(0x02);
|
||||
u8DataLen = (u8DataLen >> 8) & 0xFF;
|
||||
if (!p8RxBuff)
|
||||
return;
|
||||
|
||||
u8DataLen = u8RxBuffSize < u8DataLen ? u8RxBuffSize : u8DataLen;
|
||||
for (unsigned char i = 0; i < u8DataLen; i++)
|
||||
{
|
||||
p8RxBuff[i] = Fw.BK4819Read(0x5F);
|
||||
}
|
||||
|
||||
if(pRadioUser)
|
||||
{
|
||||
pRadioUser->RxDoneHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
IRadioUser* pRadioUser;
|
||||
unsigned char *p8RxBuff;
|
||||
unsigned char u8RxBuffSize;
|
||||
eState State;
|
||||
};
|
||||
}
|
|
@ -11,6 +11,7 @@ target_link_libraries(${NAME}
|
|||
orginal_fw
|
||||
uv_k5_system
|
||||
lcd
|
||||
radio
|
||||
)
|
||||
|
||||
target_include_directories(${NAME} PUBLIC
|
||||
|
|
|
@ -3,11 +3,14 @@
|
|||
#include "registers.hpp"
|
||||
#include "uv_k5_display.hpp"
|
||||
#include "spectrum.hpp"
|
||||
#include "radio.hpp"
|
||||
#include <string.h>
|
||||
|
||||
extern "C" void __libc_init_array();
|
||||
|
||||
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()
|
||||
{
|
||||
|
@ -24,9 +27,11 @@ void MultiIrq_Handler(unsigned int u32IrqSource)
|
|||
__libc_init_array();
|
||||
bFirstInit = true;
|
||||
}
|
||||
|
||||
RadioDriver.InterruptHandler();
|
||||
|
||||
static unsigned int u32StupidCounter = 1;
|
||||
if((!(u32StupidCounter++ % 15) && u32StupidCounter > 200))
|
||||
if((!(u32StupidCounter++ % 64) && u32StupidCounter > 200))
|
||||
{
|
||||
Spectrum.Handle();
|
||||
}
|
||||
|
|
|
@ -1,17 +1,29 @@
|
|||
#pragma once
|
||||
#include "system.hpp"
|
||||
#include "uv_k5_display.hpp"
|
||||
#include "radio.hpp"
|
||||
|
||||
#define REVERSE_UINT16(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
|
||||
|
||||
template <const System::TOrgFunctions &Fw, const System::TOrgData &FwData>
|
||||
class CSpectrum
|
||||
template <const System::TOrgFunctions &Fw,
|
||||
const System::TOrgData &FwData,
|
||||
Radio::CBK4819<Fw>& RadioDriver>
|
||||
class CSpectrum : public Radio::IRadioUser
|
||||
{
|
||||
public:
|
||||
static constexpr auto StepSize = 0xFFFF / TUV_K5Display::SizeX;
|
||||
static constexpr auto StepSizeFreq = 10'000;
|
||||
|
||||
enum eState : unsigned char
|
||||
{
|
||||
Init,
|
||||
Idle,
|
||||
RxPending,
|
||||
SendData,
|
||||
RxDone,
|
||||
Exit,
|
||||
};
|
||||
|
||||
CSpectrum()
|
||||
: DisplayBuff(FwData.pDisplayBuffer), FontSmallNr(FwData.pSmallDigs), Display(DisplayBuff), x(DisplayBuff.SizeX/2), y(DisplayBuff.SizeY/2){};
|
||||
: DisplayBuff(FwData.pDisplayBuffer), FontSmallNr(FwData.pSmallDigs), Display(DisplayBuff), State(eState::SendData), u8RxCnt(0){};
|
||||
|
||||
void Handle()
|
||||
{
|
||||
|
@ -20,31 +32,48 @@ public:
|
|||
return;
|
||||
}
|
||||
|
||||
if (!(Fw.BK4819Read(0x0C) & 0b10))
|
||||
switch(State)
|
||||
{
|
||||
return;
|
||||
case eState::Init:
|
||||
{
|
||||
RadioDriver.RecieveAsyncAirCopyMode(U8RxBuff, sizeof(U8RxBuff), this);
|
||||
State = eState::RxPending;
|
||||
break;
|
||||
}
|
||||
|
||||
case eState::RxDone:
|
||||
{
|
||||
u8RxCnt++;
|
||||
char kupa[20];
|
||||
Fw.FormatString(kupa, "test %u", u8RxCnt);
|
||||
Fw.PrintTextOnScreen(kupa, 0, 127, 0, 8, 0);
|
||||
Fw.FlushFramebufferToScreen();
|
||||
State = eState::Init;
|
||||
break;
|
||||
}
|
||||
|
||||
case eState::SendData:
|
||||
{
|
||||
RadioDriver.SendSyncAirCopyMode72((unsigned char*)this);
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
char kupa[20];
|
||||
|
||||
Fw.FormatString(kupa, "test %u", 100);
|
||||
|
||||
|
||||
Fw.PrintTextOnScreen(kupa, 0, 127, 0, 8, 0);
|
||||
Fw.FlushFramebufferToScreen();
|
||||
void RxDoneHandler() override
|
||||
{
|
||||
State = eState::RxDone;
|
||||
}
|
||||
|
||||
private:
|
||||
void SetFrequency(unsigned int u32Freq)
|
||||
{
|
||||
u32Freq /= 10;
|
||||
Fw.BK4819Write(0x39, REVERSE_UINT16((u32Freq >> 16) & 0xFFFF));
|
||||
Fw.BK4819Write(0x38, REVERSE_UINT16(u32Freq & 0xFFFF));
|
||||
}
|
||||
|
||||
TUV_K5Display DisplayBuff;
|
||||
const TUV_K5SmallNumbers FontSmallNr;
|
||||
CDisplay<const TUV_K5Display> Display;
|
||||
|
||||
unsigned char x, y;
|
||||
eState State;
|
||||
unsigned char U8RxBuff[72];
|
||||
unsigned char u8RxCnt;
|
||||
|
||||
};
|
|
@ -194,18 +194,7 @@ private:
|
|||
{
|
||||
bEnabled = false;
|
||||
}
|
||||
// u8LastBtnPressed = Fw.PollKeyboard();
|
||||
// if (u8LastBtnPressed == EnableKey)
|
||||
// {
|
||||
// u8PressCnt++;
|
||||
// }
|
||||
|
||||
// if (u8PressCnt > (bEnabled ? 3 : PressDuration))
|
||||
// {
|
||||
// u8PressCnt = 0;
|
||||
// bEnabled = !bEnabled;
|
||||
// }
|
||||
|
||||
|
||||
return bEnabled;
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue