How to configure DCMI peripheral on STM32H7

不问归期 提交于 2019-12-11 06:35:13

问题


  1. How to configure DCMI peripheral for getting active field image\video?
  2. How to get only Y-part (gray-scale video) from digitized stream?
  3. How to setup the external decoder?
  4. How to determine the resolution of a camera?

回答1:


Configure DCMI peripheral for getting active field image\video:

(it's better looking on this code with documentation on what this registers do in a split window)

// 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);

why for horizontal AVID parameters we multiply by 2, because peripheral will look at number of PIXCLK clocks and 2 of them equal to 1 pixel.

Extract Y-part from digitized stream:

how does 4:2:2 format looks like? it's

Y1 Cr0 Y0 Cb0
Y3 Cr2 Y2 Cb2

each of them is 8 bit, you get the 2 pixel color picture by using Y0:Cb0:Cr0 and Y1:Cb0:Cr0. Where Y - is a luma (brightness) value -> this value is what you want for a gray-scale video. This is what this part do:

// set Y-only
DCMI->CR |= (0x1 << 16);
DCMI->CR |= (0x1 << 18);

We extract every other (0x1 << 16) even (0x1 << 18) byte from 32 bit word.

The remaining part is trivial:

// 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);


来源:https://stackoverflow.com/questions/53410894/how-to-configure-dcmi-peripheral-on-stm32h7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!