5.9 DVP 使用说明
本章说明 N32H49x 的 DVP 摄像头接口在开发套件中的目录组织、公开 API 与示例用法。
5.9.1 相关文件
下表列出该模块在开发套件中的头文件、驱动实现、示例根目录与一个示例的目录组成。
| 相对路径 | 作用 |
|---|---|
firmware/n32h49x_std_periph_driver/inc/n32h49x_dvp.h |
DVP 外设的寄存器定义、数据类型与公开函数声明。 |
firmware/n32h49x_std_periph_driver/src/n32h49x_dvp.c |
DVP 驱动实现:接口与捕获控制、帧缓冲与 DMA、中断与状态。 |
projects/n32h49x_EVAL/examples/DVP/Camera/ |
示例入口:OV5640 采集图像并在 800x480 的 ILI9806 LCD 上显示。 |
projects/n32h49x_EVAL/examples/DVP/Camera/src/ |
源码目录组成:main.c、dvp_demo.c、bsp_dvp.c、bsp_ov5640.c、lcd.c 与 n32h49x_it.c。 |
projects/n32h49x_EVAL/examples/DVP/Camera/inc/ |
头文件与字库、图标资源声明。 |
5.9.2 API 参考
以下 40 个公开函数按 n32h49x_dvp.h 的声明顺序分为 6 组;每个条目给出功能摘要与源码注释原文。
初始化与复位
DVP_DeInit、DVP_Init、DVP_StructInit、DVP_DMAStructInit、DVP_ConfigDma
接口与捕获控制
DVP_EnablePort、DVP_SetCaptureMode、DVP_EnableCrop、DVP_ConfigVBlankFilter、DVP_ConfigInitSKIP、DVP_ConfigRepeatSKIP、DVP_ConfigCROPStart、DVP_ConfigCROPEnd
信号极性与数据格式
DVP_ConfigPixelClockPolarity、DVP_ConfigHSyncPolarity、DVP_ConfigVSyncPolarity、DVP_EnableDataInvert、DVP_EnableDataReverse、DVP_ConfigDataMode、DVP_ConfigPixelByte、DVP_ConfigDATAByteOrder
内嵌同步
DVP_ConfigEmbSyncPos、DVP_ConfigEmbSyncData、DVP_ConfigEmbSyncDataMask、DVP_EnableEmbSyncMode
帧缓冲与 DMA
DVP_EnableBuffer1、DVP_SetBuffer1Address、DVP_EnableBuffer2、DVP_SetBuffer2Address、DVP_SetBufferSize、DVP_SetDisplayBufferStatus、DVP_GetDisplayBufferStatus1、DVP_GetDisplayBufferStatus2、DVP_EnableAcross1KBoundary、DVP_FrameBufferAddrIncrementEnable
中断与状态
DVP_ConfigInt、DVP_GetFlagStatus、DVP_ClearFlag、DVP_GetIntStatus、DVP_ClrIntPendingBit
void DVP_EnablePort(FunctionalState Cmd)使能 DVP 接口;该函数在 DVP 初始化成功后调用,用于开始搬运数据。
name DVP_EnablePort.
fun DVP interface enable. This function is called after DVP
initialization is successful to start moving data.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_SetCaptureMode(uint32_t Mode)配置捕获模式。
name DVP_SetCaptureMode.
fun Config the capture mode.
param Mode:(The input parameters must be the following values)
- DVP_CAPTURE_MODE_CONTINUE
- DVP_CAPTURE_MODE_SINGLE
return none
void DVP_EnableCrop(FunctionalState Cmd)使能 DVP 裁剪功能;应在使能并启动 DVP 接口之前调用。
name DVP_EnableCrop.
fun DVP crop feature enable. This function should be called
before to enable and start the DVP interface.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_ConfigVBlankFilter(uint8_t Filt)VSYNC 消隐毛刺滤波控制;应在使能并启动 DVP 接口之前调用。
name DVP_ConfigVBFLT.
fun VSYNC blanking glitch filtering control. This function should be called
before to enable and start the DVP interface.
param Filt:(The input parameters must be the following values)
- 0~0xF
return none
使用提示: 源码注释中的 name 字段写作 DVP_ConfigVBFLT.,与函数名 DVP_ConfigVBlankFilter 不一致,按函数名调用即可。
void DVP_ConfigInt(uint32_t DVPInt, FunctionalState Cmd)使能 DVP 中断。
name DVP_ConfigInt.
fun DVP interrupts enable.
param DVPInt (The input parameters must be the following values):
- DVP_INT_M1S
- DVP_INT_M2S
- DVP_INT_M1TC
- DVP_INT_M2TC
- DVP_INT_FO
- DVP_INT_AHBERR
- DVP_INT_MO
- DVP_INT_SKIP
- DVP_INT_CERR
- DVP_INT_SERR
- DVP_INT_FMS
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
FlagStatus DVP_GetFlagStatus(uint32_t DVP_Flag)获取 DVP 标志状态,检查 DVP 接口标志是否置位。
name DVP_GetFlagStatus.
fun Get DVP flag status. Checks whether the DVP interface flag is set or not.
param DVP_Flag (The input parameters must be the following values):
- DVP_FLAG_M1S
- DVP_FLAG_M2S
- DVP_FLAG_M1TC
- DVP_FLAG_M2TC
- DVP_FLAG_M1FO
- DVP_FLAG_M2FO
- DVP_FLAG_AHBERR1
- DVP_FLAG_AHBERR2
- DVP_FLAG_M1O
- DVP_FLAG_M2O
- DVP_FLAG_SKIP
- DVP_FLAG_CERR
- DVP_FLAG_SERR
- DVP_FLAG_FMS
return SET or RESET.
void DVP_ClearFlag(uint32_t DVP_Flag)清除 DVP 标志状态。
name DVP_ClearFlag.
fun Clears DVP flag status.
param DVP_Flag (The input parameters must be the following values):
- DVP_FLAG_M1S
- DVP_FLAG_M2S
- DVP_FLAG_M1TC
- DVP_FLAG_M2TC
- DVP_FLAG_M1FO
- DVP_FLAG_M2FO
- DVP_FLAG_AHBERR1
- DVP_FLAG_AHBERR2
- DVP_FLAG_M1O
- DVP_FLAG_M2O
- DVP_FLAG_SKIP
- DVP_FLAG_CERR
- DVP_FLAG_SERR
- DVP_FLAG_FMS
return none.
INTStatus DVP_GetIntStatus(uint32_t DVP_Int)获取 DVP 中断状态,检查 DVP 中断是否发生。
name DVP_GetIntStatus.
fun Get DVP interrupt status. Checks whether the DVP interrupt has occurred or not.
param DVP_Int (The input parameters must be the following values):
- DVP_INT_M1S
- DVP_INT_M2S
- DVP_INT_M1TC
- DVP_INT_M2TC
- DVP_INT_FO
- DVP_INT_AHBERR
- DVP_INT_MO
- DVP_INT_SKIP
- DVP_INT_CERR
- DVP_INT_SERR
- DVP_INT_FMS
return SET or RESET.
void DVP_ClrIntPendingBit(uint32_t DVP_Int)清除 DVP 中断状态位。
name DVP_ClrIntPendingBit.
fun Clear DVP interrupt status bits.
param DVP_Int (The input parameters must be the following values):
- DVP_INT_M1S
- DVP_INT_M2S
- DVP_INT_M1TC
- DVP_INT_M2TC
- DVP_INT_FO
- DVP_INT_AHBERR
- DVP_INT_MO
- DVP_INT_SKIP
- DVP_INT_CERR
- DVP_INT_SERR
- DVP_INT_FMS
return none.
void DVP_ConfigPixelClockPolarity(uint32_t PLCK_POL)配置 DVP 端口像素时钟极性。
name DVP_ConfigPixelClockPolarity.
fun DVP port pixel clock polarity control.
param PLCK_POL (The input parameters must be the following values):
- DVP_PIXEL_POLARITY_RISING
- DVP_PIXEL_POLARITY_FALLING
return none.
void DVP_ConfigHSyncPolarity(uint32_t HSYNC_POL)配置 DVP HSYNC 极性。
name DVP_ConfigHSyncPolarity.
fun DVP HSYNC polarity control.
param HSYNC_POL (The input parameters must be the following values):
- DVP_HSYNC_POLARITY_HIGH
- DVP_HSYNC_POLARITY_LOW
return none.
void DVP_ConfigVSyncPolarity(uint32_t VSYNC_POL)配置 DVP VSYNC 极性。
name DVP_ConfigVSyncPolarity.
fun DVP VSYNC polarity control.
param VSYNC_POL (The input parameters must be the following values):
- DVP_VSYNC_POLARITY_HIGH
- DVP_VSYNC_POLARITY_LOW
return none.
void DVP_EnableDataInvert(FunctionalState Cmd)使能 DVP 数据反相。
name DVP_EnableDataInvert.
fun DVP data inversion enable.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_EnableDataReverse(FunctionalState Cmd)使能 DVP 数据反转。
name DVP_EnableDataReverse.
fun DVP data Reverse enable.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_ConfigEmbSyncPos(uint32_t SYNC_Pos)配置内嵌同步码位置。
name DVP_ConfigEmbSyncPos.
fun Embedded Synchronization Code Position.
param SYNC_Pos (The input parameters must be the following values):
- DVP_EMBSYNC_LSB
- DVP_EMBSYNC_MSB
return none.
void DVP_ConfigEmbSyncData(uint8_t FrameStartValue, uint8_t FrameEndValue, uint8_t LineStartValue, uint8_t LineEndValue)配置内嵌同步码数据。
name DVP_ConfigEmbSyncData.
fun Embedded Synchronization Code Position.
param FrameStartValue/FrameEndValue/LineStartValue/LineEndValue (The input parameters must be the following values):
- 0x00 ~ 0xFF
return none.
void DVP_ConfigEmbSyncDataMask(uint8_t FrameStartMask, uint8_t FrameEndMask, uint8_t LineStartMask, uint8_t LineEndMask)配置内嵌同步码数据掩码。
name DVP_ConfigEmbSyncDataMask.
fun Embedded Synchronization Code Position.
param FrameStartMask/FrameEndMask/LineStartMask/LineEndMask (The input parameters must be the following values):
- 0x00 ~ 0xFF
return none.
void DVP_EnableEmbSyncMode(FunctionalState Cmd)使能内嵌同步模式位。
name DVP_EnableEmbSyncMode.
fun Embedded Synchronization Mode enable bit.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_ConfigDataMode(uint32_t Mode)配置 DVP 数据端口模式。
name DVP_ConfigDataMode.
fun Config DVP data port mode.
param Mode (The input parameters must be the following values):
- DVP_DATA_MODE1
- DVP_DATA_MODE2
- DVP_DATA_MODE3
- DVP_DATA_MODE4
- DVP_DATA_MODE5
- DVP_DATA_MODE6
- DVP_DATA_MODE7
- DVP_DATA_MODE8
return none.
void DVP_ConfigPixelByte(uint32_t Pixel_Byte)配置 DVP 像素字节数。
name DVP_ConfigPixelByte.
fun Config DVP pixel bytes.
param Pixel_Byte (The input parameters must be the following values):
- DVP_PIXEL_BYTE1
- DVP_PIXEL_BYTE2
return none.
void DVP_ConfigDATAByteOrder(uint32_t Byte0, uint32_t Byte1, uint32_t Byte2, uint32_t Byte3)配置 DVP 数据顺序。
name DVP_ConfigDATAByteOrder.
fun Config DVP DATA order.
param Byte0 (The input parameters must be the following values):
- DVP_BYTE0_ORDER1
- DVP_BYTE0_ORDER2
- DVP_BYTE0_ORDER3
- DVP_BYTE0_ORDER4
param Byte1 (The input parameters must be the following values):
- DVP_BYTE1_ORDER1
- DVP_BYTE1_ORDER2
- DVP_BYTE1_ORDER3
- DVP_BYTE1_ORDER4
param Byte2 (The input parameters must be the following values):
- DVP_BYTE2_ORDER1
- DVP_BYTE2_ORDER2
- DVP_BYTE2_ORDER3
- DVP_BYTE2_ORDER4
param Byte3 (The input parameters must be the following values):
- DVP_BYTE3_ORDER1
- DVP_BYTE3_ORDER2
- DVP_BYTE3_ORDER3
- DVP_BYTE3_ORDER4
return none.
void DVP_ConfigInitSKIP(uint32_t Line)配置初始帧行跳过。
name DVP_ConfigInitSKIP.
fun Config Initial Frame Line Skip .
param Line (The input parameters must be the following values):
- DVP_SKIP_LINE1
- DVP_SKIP_LINE2
- DVP_SKIP_LINE3
- DVP_SKIP_LINE4
- DVP_SKIP_LINE5
- DVP_SKIP_LINE6
- DVP_SKIP_LINE7
- DVP_SKIP_LINE8
- DVP_SKIP_LINE9
- DVP_SKIP_LINE10
- DVP_SKIP_LINE11
- DVP_SKIP_LINE12
- DVP_SKIP_LINE13
- DVP_SKIP_LINE14
- DVP_SKIP_LINE15
return none.
void DVP_ConfigRepeatSKIP(uint32_t Line)配置重复帧行跳过。
name DVP_ConfigRepeatSKIP.
fun Config Repeat Frame Line Skip .
param Line (The input parameters must be the following values):
- DVP_SKIP_LINE1
- DVP_SKIP_LINE2
- DVP_SKIP_LINE3
- DVP_SKIP_LINE4
- DVP_SKIP_LINE5
- DVP_SKIP_LINE6
- DVP_SKIP_LINE7
- DVP_SKIP_LINE8
- DVP_SKIP_LINE9
- DVP_SKIP_LINE10
- DVP_SKIP_LINE11
- DVP_SKIP_LINE12
- DVP_SKIP_LINE13
- DVP_ODD_LINE
- DVP_EVEN_LINE
return none.
void DVP_EnableBuffer1(FunctionalState Cmd)使能帧缓冲区 1。
name DVP_EnableBuffer1.
fun Frame Buffer 1 enable.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_SetBuffer1Address(uint32_t Addres)设置帧缓冲区 1 起始地址。
name DVP_SetBuffer1Address.
fun Set Frame Buffer 1 Start Address.
param Addres:(The input parameters must be the following values)
- 0x00000000~0xFFFFFFFF
return none
void DVP_EnableBuffer2(FunctionalState Cmd)使能帧缓冲区 2。
name DVP_EnableBuffer2.
fun Frame Buffer 2 enable.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_SetBuffer2Address(uint32_t Addres)设置帧缓冲区 2 起始地址。
name DVP_SetBuffer2Address.
fun Set Frame Buffer 2 Start Address.
param Addres:(The input parameters must be the following values)
- 0x00000000~0xFFFFFFFF
return none
void DVP_SetBufferSize(uint32_t Size)设置帧缓冲区大小。
name DVP_SetBufferSize.
fun Set Frame Buffer Size.
param Size:(The input parameters must be the following values)
- 0 ~ 4194303
return none
void DVP_SetDisplayBufferStatus(uint32_t State_Mode)设置当前显示帧缓冲区的状态。
name DVP_SetDisplayBufferStatus.
fun Set show current frame buffer status.
param State_Mode:(The input parameters must be the following values)
- DVP_DISPLAY_ADDRESS
- DVP_DISPLAY_NUMBER
return none
uint32_t DVP_GetDisplayBufferStatus1(void)获取当前帧缓冲区 1 状态。
name DVP_GetDisplayBufferStatus1.
fun Get current frame buffer 1 status.
param none
return Frame Buffer 1 address or Number of data bytes
uint32_t DVP_GetDisplayBufferStatus2(void)获取当前帧缓冲区 2 状态。
name DVP_GetDisplayBufferStatus2.
fun Get current frame buffer 2 status.
param none
return Frame Buffer 2 address or Number of data bytes
void DVP_EnableAcross1KBoundary(FunctionalState Cmd)允许或使能跨越 1K 边界的增量突发。
name DVP_EnableAcross1KBoundary.
fun Increamental bursting across 1K boundary is allowed/enabled
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_ConfigCROPStart(uint16_t X,uint16_t Y)配置裁剪图像起始点的 Y 坐标和 X 坐标。
name DVP_ConfigCROPStart.
fun Config Y-coordinate and X-coordinate of crop image start point.
param (X,Y):(The input parameters must be the following values)
- (0,0) ~ (2047,2047)
return none
void DVP_ConfigCROPEnd(uint16_t X,uint16_t Y)配置裁剪图像结束点的 Y 坐标和 X 坐标。
name DVP_ConfigCROPEnd.
fun Config Y-coordinate and X-coordinate of crop image end point.
param (X,Y):(The input parameters must be the following values)
- (0,0) ~ (2047,2047)
return none
void DVP_DeInit(void)将 DVP 外设寄存器复位为默认复位值。
name DVP_DeInit.
fun Deinitializes the DVP peripheral registers to their default reset values.
param none
return none
void DVP_Init(DVP_InitType* DVP_InitParam)根据 DVP_InitParam 中指定的参数初始化 DVP 外设。
name DVP_Init.
fun Initializes the DVP peripheral according to the specified
parameters in the DVP_InitParam .
param DVP_InitParam (The input parameters must be the following values):
- CaptureMode
- DVP_CAPTURE_MODE_CONTINUE
- DVP_CAPTURE_MODE_SINGLE
- CropMode
- DVP_NORMAL_MODE
- DVP_CROP_MODE
- SynchroMode
- DVP_SYNC_MODE_SOFTWARE
- DVP_SYNC_MODE_HARDWARE
- CropStartX
- CropStartY
- CropEndX
- CropEndY
- BFilter
- PixelClkPolarity
- DVP_PIXEL_POLARITY_RISING
- DVP_PIXEL_POLARITY_FALLING
- HsyncPolarity
- DVP_HSYNC_POLARITY_HIGH
- DVP_HSYNC_POLARITY_LOW
- VsyncPolarity
- DVP_VSYNC_POLARITY_HIGH
- DVP_VSYNC_POLARITY_LOW
- DataInvert
- DVP_DATA_INVERT
- DVP_DATA_NOTINVERT
- DataReverse
- DVP_DATA_REVERSE
- DVP_DATA_NOTREVERSE
- DataMode
- DVP_DATA_MODE1
- DVP_DATA_MODE2
- DVP_DATA_MODE3
- DVP_DATA_MODE4
- DVP_DATA_MODE5
- DVP_DATA_MODE6
- DVP_DATA_MODE7
- DVP_DATA_MODE8
- PixelByte
- DVP_PIXEL_BYTE1
- DVP_PIXEL_BYTE2
return none
void DVP_StructInit(DVP_InitType* DVP_InitParam)初始化用于配置 DVP 的 DVP_InitType 类型结构体参数;该函数通常在初始化 DVP_InitType 类型参数之前调用。
name DVP_StructInit.
fun Initializes the structure parameter of type DVP_InitType used to
initialize DVP. This function is usually called before initializing
a parameter of type DVP_InitType.
param DVP_InitParam :
- Pointer to the DVP_InitType structure which will be initialized.
return none
void DVP_ConfigDma(DVP_DMAInitType* DVP_DMAInitParam)初始化用于配置 DVP 的 DVP_DMAInitType 类型结构体参数;该函数通常在初始化 DVP_DMAInitType 类型参数之前调用。
name DVP_ConfigDma.
fun Initializes the structure parameter of type DVP_DMAInitType used to
initialize DVP DMA. This function is usually called before initializing
a parameter of type DVP_DMAInitType.
param DVP_DMAInitType :
- FrameBufferNum
- FrameBufferAddress1
- FrameBufferAddress2
- DisplayStatus
- DVP_DISPLAY_ADDRESS
- DVP_DISPLAY_NUMBER
- BurstSize
- DVP_BURST_SIZE_BYTE_4
- DVP_BURST_SIZE_BYTE_8
- DVP_BURST_SIZE_BYTE_12
- DVP_BURST_SIZE_BYTE_16
- DVP_BURST_SIZE_BYTE_20
- DVP_BURST_SIZE_BYTE_24
- DVP_BURST_SIZE_BYTE_28
- DVP_BURST_SIZE_BYTE_32
- FifoThreshold
- DVP_FIFO_THRSEHOLD_BYTE_4
- DVP_FIFO_THRSEHOLD_BYTE_8
- DVP_FIFO_THRSEHOLD_BYTE_16
- DVP_FIFO_THRSEHOLD_BYTE_32
- FrameBufferSize
return none
void DVP_DMAStructInit(DVP_DMAInitType* DVP_DMAInitParam)初始化用于配置 DVP DMA 的 DVP_DMAInitType 类型结构体参数;该函数通常在初始化 DVP_DMAInitType 类型参数之前调用。
name DVP_DMAStructInit.
fun Initializes the structure parameter of type DVP_DMAInitType used to
initialize DVP. This function is usually called before initializing
a parameter of type DVP_DMAInitType.
param DVP_DMAInitParam :
- Pointer to the DVP_DMAInitType structure which will be initialized.
return none
void DVP_FrameBufferAddrIncrementEnable(FunctionalState Cmd)使能 DVP 帧缓冲区地址自增。
name DVP_FrameBufferAddrIncrementEnable.
fun DVP frame buffer address increment enable.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
5.9.3 Demo 示例说明
本节说明 DVP 的 Camera 示例。
5.9.3.1 Camera OV5640 摄像头采集与 LCD 显示
工程目录: projects/n32h49x_EVAL/examples/DVP/Camera/
初始化串口与 LCD→通过 SCCB 配置 OV5640→配置 DVP 接口与 DMA→使能 DVP 开始采集→在帧中断把图像搬到 LCD 显存
| 项目 | 源码解读 |
|---|---|
| 功能 | 接收 OV5640 输出的图像数据。 通过 FEMC 把图像显示在 ILI9806 LCD 上。 |
| 源码组成 | src/main.c:调用 dvp_demo 后进入空循环。src/dvp_demo.c:LCD 初始化、显示 Logo 与示例入口。src/bsp_dvp.c:DVP 接口、DMA 与中断配置。src/bsp_ov5640.c:SCCB 时序与 OV5640 寄存器配置。src/lcd.c:基于 FEMC 的 LCD 驱动与图像搬运。src/n32h49x_it.c:DVP_IRQHandler 中断服务函数。readme.txt:功能、环境与使用说明。MDK-ARM/、EWARM/:Keil 与 IAR 工程。 |
| 关键配置 | 时钟源 HSI+PLL,系统频率 240MHz。 OV5640 采用 8 位数据接口,PCLK-PE4、HSYNC-PE2、VSYNC-PE3,SCCB 使用 PB6/PB7。 LCD 为 800x480 的 ILI9806,16 位并口经 FEMC 驱动。 帧缓冲区放在片内 SRAM,尺寸由 DVP_IMAGE_SIZE 指定。 |
| 程序与数据路径 | main 调用 dvp_demo。dvp_demo 初始化串口与 LCD 后调用 DVPDemo_Init。DVPDemo_Init 配置 NVIC、初始化 OV5640、配置 DVP 接口与 DMA 并使能。DVP_IRQHandler 在帧中断中清除标志并把一帧图像写入 LCD 显存。 |
| 主要 API | DVP_Init、DVP_ConfigDma、DVP_ConfigInt、DVP_EnableBuffer1、DVP_EnablePort |
| 验证方法 | 编译下载后复位运行,LCD 上显示摄像头画面。 串口可用于打印调试信息。 |
| 使用提示 | 评估板 J30 跳帽为 LCD RST 控制,需要连接。 开发环境为 KEIL MDK-ARM 5.34 或 IAR EWARM 8.50.1。 |
核心代码解读与移植
示例把 DVP 采集的 OV5640 图像经 FEMC 直接显示在 LCD 上,是一条从传感器到屏幕的完整数据通路。
数据路径: OV5640 输出像素 → DVP 接口与内部 DMA 搬运 → 帧缓冲区 → DVP_IRQHandler 在帧中断触发 → lcd_ov5640 把图像写入 LCD 显存
1. 示例入口先点亮屏幕再配置采集。 dvp_demo 初始化串口与 LCD、显示 Logo,然后调用 DVPDemo_Init 并最终使能接口。
void dvp_demo(void)
{
log_init();
/* LCD configuration */
LCD_Configuration();
LCD_GramScan(0);
LCD_SetColors(RED,WHITE);
LCD_Clear(0,0,lcd_width,lcd_height);
LCD_Logo_init();
/* DVP configuration */
DVPDemo_Init();
DVP_EnablePort(ENABLE);
2. 初始化顺序依次为传感器、接口与中断。 DVPDemo_Init 先配置 NVIC,再初始化 OV5640 的端口与寄存器,然后配置 DVP 接口与 DMA 并使能。
void DVPDemo_Init(void)
{
DVP_NVIC_Configuration();
OV5640_InitPort();
OV5640_Init();
OV5640_RGB565_Config();
DVP_InitInterface();
DVP_ConfigInt(DVP_INT_M1TC,ENABLE);
DVP_EnableBuffer1(ENABLE);
DVP_EnablePort(ENABLE);
3. 用结构体配置接口与 DMA。 DVP_InitInterface 打开 DVP 时钟后填充 DVP_InitType 与 DVP_DMAInitType,分别调用 DVP_Init 与 DVP_ConfigDma。
DVP_InitType DVP_InitStructure;
DVP_DMAInitType DVP_DMAInitStructure;
RCC_EnableAHBPeriphClk(RCC_AHB_PERIPHEN_DVP, ENABLE);
DVP_StructInit(&DVP_InitStructure);
DVP_InitStructure.CaptureMode = DVP_CAPTURE_MODE_CONTINUE;
DVP_InitStructure.CropMode = DVP_NORMAL_MODE;
DVP_InitStructure.VBFilter = 3;
DVP_InitStructure.PixelClkPolarity = DVP_PIXEL_POLARITY_FALLING;
DVP_InitStructure.HsyncPolarity = DVP_HSYNC_POLARITY_HIGH;
DVP_InitStructure.VsyncPolarity = DVP_VSYNC_POLARITY_LOW;
DVP_InitStructure.DataInvert = DVP_DATA_NOTINVERT;
DVP_InitStructure.DataReverse = DVP_DATA_NOTREVERSE;
DVP_InitStructure.DataMode = DVP_DATA_MODE1;
DVP_InitStructure.PixelByte = DVP_PIXEL_BYTE1;
DVP_Init(&DVP_InitStructure);
DVP_DMAStructInit(&DVP_DMAInitStructure);
DVP_DMAInitStructure.FrameBufferNum = 1;
DVP_DMAInitStructure.FrameBufferAddress1 = LCD_IMAGE_ADDRESS;
DVP_DMAInitStructure.DisplayStatus = DVP_DISPLAY_ADDRESS;
DVP_DMAInitStructure.BurstSize = DVP_BURST_SIZE_BYTE_4;
DVP_DMAInitStructure.FifoThreshold = DVP_FIFO_THRSEHOLD_BYTE_4;
DVP_DMAInitStructure.FrameBufferSize = DVP_IMAGE_SIZE;
DVP_ConfigDma(&DVP_DMAInitStructure);
4. 帧中断里搬运一帧图像。 DVP_IRQHandler 判断帧标志与中断状态,清除挂起位后把图像写入 LCD。
void DVP_IRQHandler(void)
{
if((DVP_GetFlagStatus(DVP_FLAG_M1TC)==1)&&(DVP_GetIntStatus(DVP_INT_M1TC)==1))
{
DVP_ClrIntPendingBit(DVP_INT_M1TC);
对应源码: src/main.c、src/dvp_demo.c、src/bsp_dvp.c、src/n32h49x_it.c
5.9.4 注意与排障
下表列出用户手册中与使用该外设直接相关的操作约束。
| 场景 | 检查与建议 | 来源 |
|---|---|---|
| DVP 使能晚于场同步 | DVP 端口使能位置 1 必须早于 DVP_VSYNC 有效信号至少 4 个像素时钟周期,否则当前帧会被丢弃。 | 用户手册 |
| 接口时钟不足 | AHB 接口时钟(hclk)必须等于或快于像素时钟。 | 用户手册 |
| 裁剪坐标未先写入 | 裁剪功能需在设置 CROPEN 位之前先写入起始坐标与结束坐标。 | 用户手册 |
| 帧缓冲 DMA 突发过大 | 帧缓冲区 DMA 的单次传输数据量必须大于等于 FIFO 的传输阈值。 | 用户手册 |
| 内嵌码同步数据宽度 | 内嵌码同步模式只支持 8 位、10 位和 12 位数据模式。 | 用户手册 |
| 中断标志未清除 | 使用某个中断前必须先清除 DVP_INTSTS 中相应的标志(写 0 清除),避免之前的状态影响中断上报。 | 用户手册 |
| 行间缺少间隔 | 每两行之间至少有一个像素时钟周期的间隔。 | 用户手册 |