答案 0 :(得分:2)
配置DCMI外围设备以获取活动的现场图像\视频:
(最好在拆分窗口中查看有关此寄存器的内容的文档的代码)
// enable DCIM peripheral clock
RCC->AHB2ENR |= RCC_AHB2ENR_DCMIEN;
// disable DCIM
DCMI->CR = 0;
// NOTE: configure AVID
DCMI->CWSTRTR = 0;
// set top margin offset (VST)
DCMI->CWSTRTR |= ((18 - 1) << 16);
// set lef margin offset (HOFFCNT)
DCMI->CWSTRTR |= ((83 * 2 - 1) << 0);
DCMI->CWSIZER = 0;
// set height of active video (VLINE)
DCMI->CWSIZER |= ((220 - 1) << 16);
// set width of active video (CAPCNT)
DCMI->CWSIZER |= ((700 * 2 - 1) << 0);
为什么将水平AVID参数乘以2,因为外设将查看PIXCLK时钟的数量,其中2个等于1个像素。
从数字化流中提取Y部分:
4:2:2格式看起来如何? 是
Y1 Cr0 Y0 Cb0
Y3 Cr2 Y2 Cb2
它们中的每一个都是8位,您可以使用Y0:Cb0:Cr0
和Y1:Cb0:Cr0
获得2像素的彩色图片。其中Y-是亮度(亮度)值->此值是您想要的灰度视频的值。
这是这部分的作用:
// set Y-only
DCMI->CR |= (0x1 << 16);
DCMI->CR |= (0x1 << 18);
我们从32位字中每隔(0x1 << 18)个字节提取(0x1 << 16)个字节。
其余部分微不足道:
// choose data mode (8-bit = 0)
DCMI->CR |= (0x0 << 10);
// capture every 4 frame ( 4frames = 2 , 2frames = 1)
DCMI->CR |= (0x0 << 8);
// set polarity for VSCLK HSCLK PXCLK (0x1 = high)
DCMI->CR |= (0x1 << 7) | (0x1 << 6) | (0x0 << 5);
// choose synchornization (hardware = 0)
DCMI->CR |= (0x0 << 4);
// set AVID (enable = 1)
DCMI->CR |= (0x1 << 2);
// set capture mode (shanpshot = 1)
DCMI->CR |= (0x0 << 1);
// configure HSYNC interrupt
DCMI->IER = 0;
// configure IT lineComplete VSYNC frameComplete
DCMI->IER |= (0x1 << 4) | (0x1 << 3) | (0x1 << 0);
// enable IT for DCMI
// NVIC_EnableIRQ(DCMI_IRQn);
// NVIC_SetPriority(DCMI_IRQn, 1);
// enable DCIM
DCMI->CR |= (0x1 << 14);
// enable Capture
DCMI->CR |= (0x1 << 0);