This commit is contained in:
2026-03-15 09:01:02 +08:00
parent a87625df90
commit ccac60a1e9
11 changed files with 2001 additions and 616 deletions
+3 -2
View File
@@ -2,6 +2,7 @@
#include "ch32v30x_dvp.h"
#include "eth_driver.h"
#include "string.h"
#include "qdx_port.h"
__attribute__((aligned(4))) uint8_t DMA_LineBuf0[BYTES_PER_LINE];
__attribute__((aligned(4))) uint8_t DMA_LineBuf1[BYTES_PER_LINE];
@@ -63,10 +64,10 @@ void DVP_Init(void)
DVP->CR1 = RB_DVP_DMA_EN; /* DMA on, CM=0 continuous, no reset bits */
DVP->CR0 |= RB_DVP_ENABLE;
printf("[DVP] Init done CR0=0x%02x CR1=0x%02x ROW=%d COL=%d\r\n",
DBG_INIT("DVP CR0=0x%02x CR1=0x%02x ROW=%d COL=%d\r\n",
(int)(DVP->CR0 & 0xFF), (int)(DVP->CR1 & 0xFF),
(int)DVP->ROW_NUM, (int)DVP->COL_NUM);
printf("[DVP] DMA_BUF0=0x%08x DMA_BUF1=0x%08x\r\n",
DBG_INIT("DVP DMA_BUF0=0x%08x DMA_BUF1=0x%08x\r\n",
(int)DVP->DMA_BUF0, (int)DVP->DMA_BUF1);
}
+27 -26
View File
@@ -1,6 +1,7 @@
#include "mini212g2.h"
#include "debug.h"
#include "string.h"
#include "qdx_port.h"
#if SENSOR_UART_ENABLE
@@ -165,7 +166,7 @@ int Mini212G2_SendCmd(const uint8_t *cmd, uint8_t len)
if (n == ACK_LEN && memcmp(resp, ACK_PATTERN, ACK_LEN) == 0)
return 0;
printf("[Sensor] resp(%d):", n);
DBG_INIT("Sensor resp(%d):", n);
for (int j = 0; j < n; j++) printf(" %02x", resp[j]);
printf("\r\n");
return -1;
@@ -176,18 +177,18 @@ int Mini212G2_SendCmd(const uint8_t *cmd, uint8_t len)
int Mini212G2_Init(void)
{
#if !SENSOR_UART_ENABLE
printf("[Sensor] UART disabled, assuming pre-configured via USB\r\n");
printf("[Sensor] Expected: CMOS output, CMOS8(MSB), Y16, 30Hz\r\n");
DBG_INIT("Sensor: UART disabled, pre-configured via USB\r\n");
DBG_INIT("Sensor: CMOS output, CMOS8(MSB), Y16, 30Hz\r\n");
return 0;
#else
int ok = 0, fail = 0;
Sensor_UART_Init();
printf("[Sensor] UART init %d, baud=%d\r\n",
DBG_INIT("Sensor: UART%d baud=%d\r\n",
(int)(SENSOR_UART == USART3 ? 3 : 2), (int)SENSOR_UART_BAUD);
/* Sensor needs several seconds to boot after power-on */
printf("[Sensor] Waiting 3s for sensor boot...\r\n");
DBG_INIT("Sensor: Waiting 3s for boot...\r\n");
Delay_Ms(3000);
/* === Communication test: send status query === */
@@ -204,51 +205,51 @@ int Mini212G2_Init(void)
}
Delay_Ms(200);
printf("[Sensor] Configuring CMOS/DVP output...\r\n");
DBG_INIT("Sensor: Configuring CMOS/DVP output...\r\n");
/* 1. Shutter compensation */
if (Mini212G2_SendCmd(CMD_SHUTTER, sizeof(CMD_SHUTTER)) == 0)
{ ok++; printf("[Sensor] Shutter OK\r\n"); }
{ ok++; DBG_INIT("Sensor: Shutter OK\r\n"); }
else
{ fail++; printf("[Sensor] Shutter FAIL\r\n"); }
{ fail++; DBG_ERR("Sensor: Shutter FAIL\r\n"); }
Delay_Ms(200);
/* 2. Digital port → CMOS */
if (Mini212G2_SendCmd(CMD_DIGITAL_CMOS, sizeof(CMD_DIGITAL_CMOS)) == 0)
{ ok++; printf("[Sensor] Digital->CMOS OK\r\n"); }
{ ok++; DBG_INIT("Sensor: Digital->CMOS OK\r\n"); }
else
{ fail++; printf("[Sensor] Digital->CMOS FAIL\r\n"); }
{ fail++; DBG_ERR("Sensor: Digital->CMOS FAIL\r\n"); }
Delay_Ms(200);
/* 3. CMOS interface → 8-bit MSB */
if (Mini212G2_SendCmd(CMD_CMOS8_MSB, sizeof(CMD_CMOS8_MSB)) == 0)
{ ok++; printf("[Sensor] CMOS8(MSB) OK\r\n"); }
{ ok++; DBG_INIT("Sensor: CMOS8(MSB) OK\r\n"); }
else
{ fail++; printf("[Sensor] CMOS8(MSB) FAIL\r\n"); }
{ fail++; DBG_ERR("Sensor: CMOS8(MSB) FAIL\r\n"); }
Delay_Ms(200);
/* 4. CMOS content → Y16 (raw 16-bit thermal) */
if (Mini212G2_SendCmd(CMD_CONTENT_Y16, sizeof(CMD_CONTENT_Y16)) == 0)
{ ok++; printf("[Sensor] Y16 OK\r\n"); }
{ ok++; DBG_INIT("Sensor: Y16 OK\r\n"); }
else
{ fail++; printf("[Sensor] Y16 FAIL\r\n"); }
{ fail++; DBG_ERR("Sensor: Y16 FAIL\r\n"); }
Delay_Ms(200);
/* 5. Frame rate → 30Hz */
if (Mini212G2_SendCmd(CMD_FPS_30HZ, sizeof(CMD_FPS_30HZ)) == 0)
{ ok++; printf("[Sensor] 30Hz OK\r\n"); }
{ ok++; DBG_INIT("Sensor: 30Hz OK\r\n"); }
else
{ fail++; printf("[Sensor] 30Hz FAIL\r\n"); }
{ fail++; DBG_ERR("Sensor: 30Hz FAIL\r\n"); }
Delay_Ms(200);
/* 6. Save settings to flash */
if (Mini212G2_SendCmd(CMD_SAVE, sizeof(CMD_SAVE)) == 0)
{ ok++; printf("[Sensor] Save OK\r\n"); }
{ ok++; DBG_INIT("Sensor: Save OK\r\n"); }
else
{ fail++; printf("[Sensor] Save FAIL\r\n"); }
{ fail++; DBG_ERR("Sensor: Save FAIL\r\n"); }
Delay_Ms(500);
printf("[Sensor] Config result: %d ok, %d fail\r\n", ok, fail);
DBG_INIT("Sensor: %d ok, %d fail\r\n", ok, fail);
sensor_init_ok = (uint8_t)ok;
sensor_init_fail = (uint8_t)fail;
@@ -268,7 +269,7 @@ void Mini212G2_PrintDigitalVideoStatus(void)
int n = Sensor_ReadResp(resp, sizeof(resp), 500);
if (n < 24) {
printf("[Sensor] Query failed (got %d bytes)\r\n", n);
DBG_ERR("Sensor: Query failed (got %d bytes)\r\n", n);
return;
}
@@ -292,16 +293,16 @@ void Mini212G2_PrintDigitalVideoStatus(void)
uint8_t fps = resp[9];
uint8_t clk_phase = resp[11];
printf("[Sensor] Digital Video Status:\r\n");
printf(" Port: %s (%d)\r\n",
DBG_INIT("Sensor Digital Video Status:\r\n");
DBG_INIT(" Port: %s (%d)\r\n",
(port_type < 10) ? port_names[port_type] : "?", (int)port_type);
printf(" Content: %s (%d)\r\n",
DBG_INIT(" Content: %s (%d)\r\n",
(content < 6) ? content_names[content] : "?", (int)content);
printf(" Interface: %s (%d)\r\n",
DBG_INIT(" Interface: %s (%d)\r\n",
(iface < 3) ? iface_names[iface] : "?", (int)iface);
printf(" FPS: %s (%d)\r\n",
DBG_INIT(" FPS: %s (%d)\r\n",
(fps < 4) ? fps_names[fps] : "?", (int)fps);
printf(" ClkPhase: %s (%d)\r\n",
DBG_INIT(" ClkPhase: %s (%d)\r\n",
(clk_phase == 0) ? "Rising" : "Falling", (int)clk_phase);
}