mirror of
https://github.com/armel/uv-k1-k5v3-firmware-custom.git
synced 2026-10-02 03:15:37 +00:00
Add screenshot USB-C support
This commit is contained in:
1 parent
095c6f9bca
commit
05ea1efe3d
6 files changed
+69
-9
No files matched your search
+22
-3
@@ -677,14 +677,26 @@ bool UART_IsCommandAvailable(uint32_t Port)
|
||||
return false;
|
||||
}
|
||||
|
||||
while (1)
|
||||
// Limit iterations to prevent long loops when buffer is full of non-command data
|
||||
uint16_t maxIterations = ReadBufSize + 1;
|
||||
|
||||
while (maxIterations--)
|
||||
{
|
||||
if ((*pReadPointer) == DmaLength)
|
||||
return false;
|
||||
|
||||
while ((*pReadPointer) != DmaLength && ReadBuf[*pReadPointer] != 0xABU)
|
||||
// Find 0xAB with iteration limit
|
||||
uint16_t searchLimit = ReadBufSize;
|
||||
while ((*pReadPointer) != DmaLength && ReadBuf[*pReadPointer] != 0xABU && searchLimit--)
|
||||
*pReadPointer = DMA_INDEX((*pReadPointer), 1, ReadBufSize);
|
||||
|
||||
if (searchLimit == 0)
|
||||
{
|
||||
// Too many bytes without finding 0xAB - sync to current position and exit
|
||||
*pReadPointer = DmaLength;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((*pReadPointer) == DmaLength)
|
||||
return false;
|
||||
|
||||
@@ -702,6 +714,13 @@ bool UART_IsCommandAvailable(uint32_t Port)
|
||||
*pReadPointer = DMA_INDEX(*pReadPointer, 1, ReadBufSize);
|
||||
}
|
||||
|
||||
if (maxIterations == 0)
|
||||
{
|
||||
// Safety: too many outer loop iterations
|
||||
*pReadPointer = DmaLength;
|
||||
return false;
|
||||
}
|
||||
|
||||
Index = DMA_INDEX(*pReadPointer, 2, ReadBufSize);
|
||||
Size = (ReadBuf[DMA_INDEX(Index, 1, ReadBufSize)] << 8) | ReadBuf[Index];
|
||||
|
||||
@@ -847,4 +866,4 @@ void UART_HandleCommand(uint32_t Port)
|
||||
#ifdef ENABLE_FEAT_F4HWN_SCREENSHOT
|
||||
gUART_LockScreenshot = 20; // lock screenshot
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -37,3 +37,25 @@ void VCP_Init()
|
||||
NVIC_SetPriority(USBD_IRQn, 3);
|
||||
NVIC_EnableIRQ(USBD_IRQn);
|
||||
}
|
||||
|
||||
bool VCP_ScreenshotPing(void)
|
||||
{
|
||||
static uint32_t read_ptr = 0;
|
||||
|
||||
uint32_t write_ptr = VCP_RxBufPointer;
|
||||
|
||||
while (read_ptr != write_ptr)
|
||||
{
|
||||
uint8_t b = VCP_RxBuf[read_ptr];
|
||||
|
||||
read_ptr++;
|
||||
if (read_ptr >= VCP_RX_BUF_SIZE)
|
||||
read_ptr = 0;
|
||||
|
||||
if (b == 0x55)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "usb_config.h"
|
||||
|
||||
#define VCP_RX_BUF_SIZE 256
|
||||
@@ -27,6 +28,7 @@ extern uint8_t VCP_RxBuf[VCP_RX_BUF_SIZE];
|
||||
extern volatile uint32_t VCP_RxBufPointer;
|
||||
|
||||
void VCP_Init();
|
||||
bool VCP_ScreenshotPing(void);
|
||||
|
||||
static inline void VCP_Send(const uint8_t *Buf, uint32_t Size)
|
||||
{
|
||||
|
||||
+2
-1
@@ -202,7 +202,8 @@ volatile bool gTxTimeoutReached;
|
||||
volatile uint16_t gRxTimerCountdown_500ms;
|
||||
#endif
|
||||
#ifdef ENABLE_FEAT_F4HWN_SCREENSHOT
|
||||
volatile uint8_t gUART_LockScreenshot = 0; // lock screenshot if Chirp is used
|
||||
volatile uint8_t gUART_LockScreenshot = 0; // lock screenshot if Chirp is used
|
||||
bool gUSB_ScreenshotEnabled = false;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -321,6 +321,7 @@ extern volatile bool gTxTimeoutReached;
|
||||
#endif
|
||||
#ifdef ENABLE_FEAT_F4HWN_SCREENSHOT
|
||||
extern volatile uint8_t gUART_LockScreenshot; // lock screenshot if Chirp is used
|
||||
extern bool gUSB_ScreenshotEnabled;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
+20
-5
@@ -18,7 +18,16 @@
|
||||
#include "driver/st7565.h"
|
||||
#include "screenshot.h"
|
||||
#include "misc.h"
|
||||
#include <string.h>
|
||||
#include "driver/vcp.h"
|
||||
|
||||
static void Screenshot_Send(const uint8_t *buf, uint16_t len)
|
||||
{
|
||||
if (gUSB_ScreenshotEnabled) {
|
||||
cdc_acm_data_send_with_dtr(buf, len);
|
||||
} else {
|
||||
UART_Send(buf, len);
|
||||
}
|
||||
}
|
||||
|
||||
// SRAM optimization: minimize static allocations
|
||||
// - previousFrame: 1024 bytes (REQUIRED - need to compare for delta)
|
||||
@@ -43,6 +52,12 @@ void getScreenShot(bool force)
|
||||
|
||||
if (UART_IsCableConnected()) {
|
||||
keepAlive = 10;
|
||||
gUSB_ScreenshotEnabled = false;
|
||||
}
|
||||
|
||||
if (VCP_ScreenshotPing()) {
|
||||
keepAlive = 10;
|
||||
gUSB_ScreenshotEnabled = true;
|
||||
}
|
||||
|
||||
if (keepAlive > 0) {
|
||||
@@ -114,7 +129,7 @@ void getScreenShot(bool force)
|
||||
// New format: sends 0xFF before header
|
||||
// Old format: doesn't exist, so viewers can differentiate
|
||||
uint8_t versionMarker = 0xFF;
|
||||
UART_Send(&versionMarker, 1);
|
||||
Screenshot_Send(&versionMarker, 1);
|
||||
|
||||
// ==== Send header ====
|
||||
uint8_t header[5] = {
|
||||
@@ -123,7 +138,7 @@ void getScreenShot(bool force)
|
||||
(uint8_t)(deltaLen & 0xFF)
|
||||
};
|
||||
|
||||
UART_Send(header, 5);
|
||||
Screenshot_Send(header, 5);
|
||||
|
||||
// ==== SECOND PASS: Send only changed chunks ====
|
||||
uint8_t chunk[9];
|
||||
@@ -136,12 +151,12 @@ void getScreenShot(bool force)
|
||||
chunk[0] = chunkIdx;
|
||||
memcpy(&chunk[1], cur, 8);
|
||||
|
||||
UART_Send(chunk, 9);
|
||||
Screenshot_Send(chunk, 9);
|
||||
|
||||
// Update previousFrame for next comparison
|
||||
memcpy(prev, cur, 8);
|
||||
}
|
||||
|
||||
uint8_t end = 0x0A;
|
||||
UART_Send(&end, 1);
|
||||
Screenshot_Send(&end, 1);
|
||||
}
|
||||
Reference in new issue
Block a user