This commit is contained in:
2026-03-14 08:12:17 +08:00
parent 82d672a2d3
commit 31191a4156
61 changed files with 32384 additions and 64 deletions
+13 -32
View File
@@ -48,6 +48,12 @@ void DVP_Init(void)
DVP->CR0 |= RB_DVP_ENABLE;
}
#define PROTOCOL_HEADER_RESERVE 64
__attribute__((aligned(4))) uint8_t FrameBuffer[SENSOR_HEIGHT][BYTES_PER_LINE];
volatile uint8_t Frame_Ready_Flag = 0;
volatile uint32_t Ready_Frame_Count = 0;
void DVP_Task(void)
{
if (!Line_Ready_Flag) return;
@@ -58,41 +64,16 @@ void DVP_Task(void)
Line_Ready_Flag = 0;
NVIC_EnableIRQ(DVP_IRQn);
/* 仅发送图像行,跳过参数行,且 socket 已连接 */
if (idx < SENSOR_HEIGHT && socket[0] != 0xFF)
if (idx < SENSOR_HEIGHT)
{
/* 4字节行头:帧号(2B) + 行号(2B) */
uint8_t hdr[4] = {
(frame_count >> 8) & 0xFF, frame_count & 0xFF,
(idx >> 8) & 0xFF, idx & 0xFF
};
u32 len = 4;
WCHNET_SocketSend(socket[0], hdr, &len);
len = BYTES_PER_LINE;
WCHNET_SocketSend(socket[0], line, &len);
/* 每帧第0行打印一次,确认帧率、帧号和socket状态与数据 */
if (idx == 0) {
static uint32_t last_fps_tick = 0;
static uint32_t last_frame_count = 0;
uint32_t now = sys_tick_ms;
if (now - last_fps_tick >= 1000) {
uint32_t fps = frame_count - last_frame_count;
printf("[DVP] frame=%lu fps=%lu socket=%d tick=%lu\r\n", frame_count, fps, socket[0], now);
printf(" Row0 Data: %02X %02X %02X %02X %02X %02X %02X %02X\r\n",
line[0], line[1], line[2], line[3], line[4], line[5], line[6], line[7]);
last_fps_tick = now;
last_frame_count = frame_count;
}
memcpy(FrameBuffer[idx], line, BYTES_PER_LINE);
if (idx == SENSOR_HEIGHT - 1)
{
Frame_Ready_Flag = 1;
Ready_Frame_Count = frame_count;
}
}
else if (idx == 0 && socket[0] == 0xFF)
{
/* socket 未连接时提示 */
printf("[DVP] frame=%lu waiting for TCP...\r\n", frame_count);
}
memset(line, 0, BYTES_PER_LINE);
}
void DVP_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
+4 -1
View File
@@ -15,4 +15,7 @@ extern volatile uint32_t current_line_idx;
void DVP_Init(void);
void DVP_Task(void);
#endif
extern __attribute__((aligned(4))) uint8_t FrameBuffer[SENSOR_HEIGHT][BYTES_PER_LINE];
extern volatile uint8_t Frame_Ready_Flag;
extern volatile uint32_t Ready_Frame_Count;