mirror of
https://github.com/MCKero6423/uv-k5-v3-emulator.git
synced 2026-10-02 03:15:36 +00:00
Adds a QEMU machine for the Puya PY32F071 (Cortex-M0+) so Quansheng UV-K5 V3 firmware can run on a PC. The firmware boots to its main loop in about five seconds and the LCD contents are readable. Register layouts come from the vendor CMSIS header shipped with the firmware rather than guesswork. Modelled: RCC, GPIO, ADC, both SPI controllers, DMA1 and the PY25Q16 flash; everything else answers through a logging catch-all, which is how the next thing worth modelling gets identified. Seven things had to be right before it would boot, each found by watching where the firmware stopped: flash aliased at the application offset, clock ready bits, self-clearing ADC calibration, SPI transfer flags, DMA-driven flash reads, SysTick poll acceleration, and the bit-banged transceiver bus idling low. SysTick needs explanation. SYSTICK_DelayUs polls the counter and accumulates differences; under emulation a register read costs far more relative to guest time, so a measured 120 ms delay would have taken about 7.7 hours. Lowering the clock does not help because the bottleneck is loop iterations, not counter speed. Reporting a value that runs ahead of the real counter does, via a new poll-boost property on SysTick. Guest time therefore runs fast during delays: fine for exercising menus and control flow, wrong for judging signal timing. Also includes the host build of the CW timing chain (harness, stubs, shim, tests), which compiles app/cwkeyer.c and app/cwmacro.c unmodified against stub drivers with a virtual clock and scripted paddle input. Known gap: keypad rows reach the firmware's scan and KEYBOARD_Poll returns the right key code, but the UI does not react yet. Not modelled, and not intended to be: radio behaviour. The transceiver chip has no public datasheet, so keying envelopes and emissions need real hardware.
61 lines
1.2 KiB
C
61 lines
1.2 KiB
C
#include "sim_paddle.h"
|
|
|
|
#include "sim_clock.h"
|
|
|
|
#define SIM_PADDLE_MAX_STEPS 512
|
|
|
|
typedef struct {
|
|
uint32_t contacts;
|
|
uint32_t until_ms; // absolute virtual time this step ends
|
|
} Step_t;
|
|
|
|
static Step_t s_steps[SIM_PADDLE_MAX_STEPS];
|
|
static uint32_t s_count;
|
|
static uint32_t s_end_ms;
|
|
|
|
void SIM_PaddleReset(void)
|
|
{
|
|
s_count = 0;
|
|
s_end_ms = 0;
|
|
}
|
|
|
|
void SIM_PaddleHold(uint32_t contacts, uint32_t duration_ms)
|
|
{
|
|
if (s_count >= SIM_PADDLE_MAX_STEPS)
|
|
return;
|
|
|
|
s_end_ms += duration_ms;
|
|
s_steps[s_count].contacts = contacts;
|
|
s_steps[s_count].until_ms = s_end_ms;
|
|
s_count++;
|
|
}
|
|
|
|
void SIM_PaddleTap(uint32_t contacts, uint32_t hold_ms, uint32_t gap_ms)
|
|
{
|
|
SIM_PaddleHold(contacts, hold_ms);
|
|
if (gap_ms > 0)
|
|
SIM_PaddleHold(SIM_CONTACT_NONE, gap_ms);
|
|
}
|
|
|
|
uint32_t SIM_PaddleState(void)
|
|
{
|
|
const uint32_t now = SIM_ClockNow();
|
|
|
|
for (uint32_t i = 0; i < s_count; i++) {
|
|
if (now < s_steps[i].until_ms)
|
|
return s_steps[i].contacts;
|
|
}
|
|
// Past the end of the script: everything released.
|
|
return SIM_CONTACT_NONE;
|
|
}
|
|
|
|
bool SIM_PaddleDrained(void)
|
|
{
|
|
return SIM_ClockNow() >= s_end_ms;
|
|
}
|
|
|
|
uint32_t SIM_PaddleTotalMs(void)
|
|
{
|
|
return s_end_ms;
|
|
}
|