基于EBAZ4205矿板的图像处理:10gamma变换

基于EBAZ4205矿板的图像处理:10gamma变换

项目全部文件

会上传项目全部文件,如果没传,可以私信催我一下,最近太忙了

先看效果

我的项目中的gamma的变换系数为2.2,是会让图像整体变暗的,看右图说明我的gamma变换模块生效了。

算法

gamma映射是一种简单的、常见的图像处理方法,它能够拓展图像的低亮度区域的灰度级数,让图像的低亮度区域呈现更多的细节,但同时也会让图像的整体亮度变暗,有利有弊。

算法的公式为: y = A*x^g

其中,x为像素点的像素灰度值输入,y为像素点的像素灰度值变换结果,A为归一化系数,g为gamma变换系数。

下图是不同系数的gamma变换曲线。

算法的FPGA部署

首先,gamma变换是个指数函数。用FPGA来运算指数函数相当耗时,所以为了提升速度,我们采用查表法,既将某个gamma变换系数下的0~255灰度等级的所有对应变换结果算出来,然后在需要映射时,直接查表即可。

BD

项目代码

图像处理模块

c 复制代码
module video_processor(
    (* X_INTERFACE_IGNORE = "true" *) input         frame_clk,    //cmos 像素时钟
    (* X_INTERFACE_IGNORE = "true" *) input         frame_rst_n,  
    
    //预处理图像
    (* X_INTERFACE_IGNORE = "true" *) input         pre_vsync, //预处理图像场同步信号
    (* X_INTERFACE_IGNORE = "true" *) input [23:0]  pre_data,  //预处理图像数据
    (* X_INTERFACE_IGNORE = "true" *) input         pre_href,  //预处理图像数据有效信号
    (* X_INTERFACE_IGNORE = "true" *) input         pre_frame_ce, //预处理图像时钟使能信号

        
    //处理后图像
    (* X_INTERFACE_IGNORE = "true" *) output        pos_vsync, //处理后图像场同步信号
    (* X_INTERFACE_IGNORE = "true" *) output [23:0] pos_data,  //处理后图像数据
    (* X_INTERFACE_IGNORE = "true" *) output        pos_href, //处理后图像数据有效信号
    (* X_INTERFACE_IGNORE = "true" *) output        pos_frame_ce //处理后图像时钟使能信号  
);

wire [7:0] gray_data ;
wire [7:0] post_gray_data ;

rgb2gray  u_rgb2gray(
    .cmos_frame_clk     (frame_clk      ),
    .cmos_rstn          (frame_rst_n    ),//同步复位
    .cmos_frame_vsync   (pre_vsync      ),
    .cmos_frame_data    (pre_data       ),
    .cmos_frame_href    (pre_href       ),
    .cmos_frame_ce      (pre_frame_ce   ),

    .dataout_frame_vsync(pos_vsync     ),
    .dataout_frame_data (gray_data      ),
    .dataout_frame_href (pos_href      ),
    .dataout_frame_ce   (pos_frame_ce  )
);

assign pos_data = {3{post_gray_data}};
Curve_Gamma_2P2 u_Curve_Gamma_2P2(
    .Pre_Data (gray_data),
    .Post_Data(post_gray_data)
);
endmodule 

色彩转换模块

c 复制代码
`timescale 1ns / 1ps
module rgb2gray(
    
(* X_INTERFACE_IGNORE = "true" *)  input           cmos_frame_vsync,
(* X_INTERFACE_IGNORE = "true" *)  input [23:0]    cmos_frame_data,
(* X_INTERFACE_IGNORE = "true" *)  input           cmos_frame_href,

(* X_INTERFACE_IGNORE = "true" *)  input           cmos_frame_clk,
(* X_INTERFACE_IGNORE = "true" *)  input           cmos_rstn,//同步复位
(* X_INTERFACE_IGNORE = "true" *)  input           cmos_frame_ce,

(* X_INTERFACE_IGNORE = "true" *)  output          dataout_frame_vsync,
(* X_INTERFACE_IGNORE = "true" *)  output [7:0]    dataout_frame_data,
// (* X_INTERFACE_IGNORE = "true" *)  output [23:0]    dataout_frame_data,
(* X_INTERFACE_IGNORE = "true" *)  output          dataout_frame_href,
(* X_INTERFACE_IGNORE = "true" *)  output          dataout_frame_ce
    );
    // Y = 0.299R +0.587G + 0.114B
    // Y = (77 *R + 150*G + 29 *B)>>8
    reg [15:0] r_gray1;
    reg [15:0] g_gray1;
    reg [15:0] b_gray1;
    reg [15:0] y1;
    reg [7:0] y2;
    reg [2:0] dataout_frame_vsync_r;
    reg [2:0] dataout_frame_href_r;
    reg [2:0] dataout_frame_ce_r;


    always@(posedge cmos_frame_clk)begin
        if(!cmos_rstn)begin
            r_gray1 <= 8'h00;
            g_gray1 <= 8'h00;
            b_gray1 <= 8'h00;
        end
        else begin
            r_gray1 <= cmos_frame_data[23:16]  * 8'd77 ;
            g_gray1 <= cmos_frame_data[15:8]   * 8'd150;
            b_gray1 <= cmos_frame_data[7:0]    * 8'd29 ;
        end
    end

    always@(posedge cmos_frame_clk)begin
        if(!cmos_rstn)begin
            y1 <= 16'h0000;
        end
        else begin
            y1 <= r_gray1 + g_gray1 + b_gray1;
        end
    end

    always@(posedge cmos_frame_clk)begin
        if(!cmos_rstn)begin
            y2 <= 8'h0000;
        end
        else begin
            y2 <= y1[15:8];
        end
    end

    

    always@(posedge cmos_frame_clk)begin
        if(!cmos_rstn)begin
            dataout_frame_ce_r      <= 3'b000;
            dataout_frame_vsync_r   <= 3'b000;
            dataout_frame_href_r    <= 3'b000;
        end
        else begin
            dataout_frame_ce_r      <= {dataout_frame_ce_r[1:0]     ,cmos_frame_ce};
            dataout_frame_vsync_r   <= {dataout_frame_vsync_r[1:0]  ,cmos_frame_vsync};
            dataout_frame_href_r    <= {dataout_frame_href_r[1:0]   ,cmos_frame_href};
        end
    end
    // assign dataout_frame_data = {y2,y2,y2};
    assign dataout_frame_data = y2;
    assign dataout_frame_ce = dataout_frame_ce_r[2];
    assign dataout_frame_vsync = dataout_frame_vsync_r[2];
    assign dataout_frame_href = dataout_frame_href_r[2];


endmodule

gamma映射模块

c 复制代码
//Curve of Gamma = 2.2
module Curve_Gamma_2P2
(
   input		[7:0]	Pre_Data,
   output	reg	[7:0]	Post_Data
);

always@(*)
begin
	case(Pre_Data)
	8'h00 : Post_Data = 8'h00; 
	8'h01 : Post_Data = 8'h00; 
	8'h02 : Post_Data = 8'h00; 
	8'h03 : Post_Data = 8'h00; 
	8'h04 : Post_Data = 8'h00; 
	8'h05 : Post_Data = 8'h00; 
	8'h06 : Post_Data = 8'h00; 
	8'h07 : Post_Data = 8'h00; 
	8'h08 : Post_Data = 8'h00; 
	8'h09 : Post_Data = 8'h00; 
	8'h0A : Post_Data = 8'h00; 
	8'h0B : Post_Data = 8'h00; 
	8'h0C : Post_Data = 8'h00; 
	8'h0D : Post_Data = 8'h00; 
	8'h0E : Post_Data = 8'h00; 
	8'h0F : Post_Data = 8'h01; 
	8'h10 : Post_Data = 8'h01; 
	8'h11 : Post_Data = 8'h01; 
	8'h12 : Post_Data = 8'h01; 
	8'h13 : Post_Data = 8'h01; 
	8'h14 : Post_Data = 8'h01; 
	8'h15 : Post_Data = 8'h01; 
	8'h16 : Post_Data = 8'h01; 
	8'h17 : Post_Data = 8'h01; 
	8'h18 : Post_Data = 8'h01; 
	8'h19 : Post_Data = 8'h02; 
	8'h1A : Post_Data = 8'h02; 
	8'h1B : Post_Data = 8'h02; 
	8'h1C : Post_Data = 8'h02; 
	8'h1D : Post_Data = 8'h02; 
	8'h1E : Post_Data = 8'h02; 
	8'h1F : Post_Data = 8'h02; 
	8'h20 : Post_Data = 8'h03; 
	8'h21 : Post_Data = 8'h03; 
	8'h22 : Post_Data = 8'h03; 
	8'h23 : Post_Data = 8'h03; 
	8'h24 : Post_Data = 8'h03; 
	8'h25 : Post_Data = 8'h04; 
	8'h26 : Post_Data = 8'h04; 
	8'h27 : Post_Data = 8'h04; 
	8'h28 : Post_Data = 8'h04; 
	8'h29 : Post_Data = 8'h05; 
	8'h2A : Post_Data = 8'h05; 
	8'h2B : Post_Data = 8'h05; 
	8'h2C : Post_Data = 8'h05; 
	8'h2D : Post_Data = 8'h06; 
	8'h2E : Post_Data = 8'h06; 
	8'h2F : Post_Data = 8'h06; 
	8'h30 : Post_Data = 8'h06; 
	8'h31 : Post_Data = 8'h07; 
	8'h32 : Post_Data = 8'h07; 
	8'h33 : Post_Data = 8'h07; 
	8'h34 : Post_Data = 8'h08; 
	8'h35 : Post_Data = 8'h08; 
	8'h36 : Post_Data = 8'h08; 
	8'h37 : Post_Data = 8'h09; 
	8'h38 : Post_Data = 8'h09; 
	8'h39 : Post_Data = 8'h09; 
	8'h3A : Post_Data = 8'h0A; 
	8'h3B : Post_Data = 8'h0A; 
	8'h3C : Post_Data = 8'h0B; 
	8'h3D : Post_Data = 8'h0B; 
	8'h3E : Post_Data = 8'h0B; 
	8'h3F : Post_Data = 8'h0C; 
	8'h40 : Post_Data = 8'h0C; 
	8'h41 : Post_Data = 8'h0D; 
	8'h42 : Post_Data = 8'h0D; 
	8'h43 : Post_Data = 8'h0D; 
	8'h44 : Post_Data = 8'h0E; 
	8'h45 : Post_Data = 8'h0E; 
	8'h46 : Post_Data = 8'h0F; 
	8'h47 : Post_Data = 8'h0F; 
	8'h48 : Post_Data = 8'h10; 
	8'h49 : Post_Data = 8'h10; 
	8'h4A : Post_Data = 8'h11; 
	8'h4B : Post_Data = 8'h11; 
	8'h4C : Post_Data = 8'h12; 
	8'h4D : Post_Data = 8'h12; 
	8'h4E : Post_Data = 8'h13; 
	8'h4F : Post_Data = 8'h13; 
	8'h50 : Post_Data = 8'h14; 
	8'h51 : Post_Data = 8'h14; 
	8'h52 : Post_Data = 8'h15; 
	8'h53 : Post_Data = 8'h16; 
	8'h54 : Post_Data = 8'h16; 
	8'h55 : Post_Data = 8'h17; 
	8'h56 : Post_Data = 8'h17; 
	8'h57 : Post_Data = 8'h18; 
	8'h58 : Post_Data = 8'h19; 
	8'h59 : Post_Data = 8'h19; 
	8'h5A : Post_Data = 8'h1A; 
	8'h5B : Post_Data = 8'h1A; 
	8'h5C : Post_Data = 8'h1B; 
	8'h5D : Post_Data = 8'h1C; 
	8'h5E : Post_Data = 8'h1C; 
	8'h5F : Post_Data = 8'h1D; 
	8'h60 : Post_Data = 8'h1E; 
	8'h61 : Post_Data = 8'h1E; 
	8'h62 : Post_Data = 8'h1F; 
	8'h63 : Post_Data = 8'h20; 
	8'h64 : Post_Data = 8'h21; 
	8'h65 : Post_Data = 8'h21; 
	8'h66 : Post_Data = 8'h22; 
	8'h67 : Post_Data = 8'h23; 
	8'h68 : Post_Data = 8'h23; 
	8'h69 : Post_Data = 8'h24; 
	8'h6A : Post_Data = 8'h25; 
	8'h6B : Post_Data = 8'h26; 
	8'h6C : Post_Data = 8'h27; 
	8'h6D : Post_Data = 8'h27; 
	8'h6E : Post_Data = 8'h28; 
	8'h6F : Post_Data = 8'h29; 
	8'h70 : Post_Data = 8'h2A; 
	8'h71 : Post_Data = 8'h2B; 
	8'h72 : Post_Data = 8'h2B; 
	8'h73 : Post_Data = 8'h2C; 
	8'h74 : Post_Data = 8'h2D; 
	8'h75 : Post_Data = 8'h2E; 
	8'h76 : Post_Data = 8'h2F; 
	8'h77 : Post_Data = 8'h30; 
	8'h78 : Post_Data = 8'h31; 
	8'h79 : Post_Data = 8'h31; 
	8'h7A : Post_Data = 8'h32; 
	8'h7B : Post_Data = 8'h33; 
	8'h7C : Post_Data = 8'h34; 
	8'h7D : Post_Data = 8'h35; 
	8'h7E : Post_Data = 8'h36; 
	8'h7F : Post_Data = 8'h37; 
	8'h80 : Post_Data = 8'h38; 
	8'h81 : Post_Data = 8'h39; 
	8'h82 : Post_Data = 8'h3A; 
	8'h83 : Post_Data = 8'h3B; 
	8'h84 : Post_Data = 8'h3C; 
	8'h85 : Post_Data = 8'h3D; 
	8'h86 : Post_Data = 8'h3E; 
	8'h87 : Post_Data = 8'h3F; 
	8'h88 : Post_Data = 8'h40; 
	8'h89 : Post_Data = 8'h41; 
	8'h8A : Post_Data = 8'h42; 
	8'h8B : Post_Data = 8'h43; 
	8'h8C : Post_Data = 8'h44; 
	8'h8D : Post_Data = 8'h45; 
	8'h8E : Post_Data = 8'h46; 
	8'h8F : Post_Data = 8'h47; 
	8'h90 : Post_Data = 8'h49; 
	8'h91 : Post_Data = 8'h4A; 
	8'h92 : Post_Data = 8'h4B; 
	8'h93 : Post_Data = 8'h4C; 
	8'h94 : Post_Data = 8'h4D; 
	8'h95 : Post_Data = 8'h4E; 
	8'h96 : Post_Data = 8'h4F; 
	8'h97 : Post_Data = 8'h51; 
	8'h98 : Post_Data = 8'h52; 
	8'h99 : Post_Data = 8'h53; 
	8'h9A : Post_Data = 8'h54; 
	8'h9B : Post_Data = 8'h55; 
	8'h9C : Post_Data = 8'h57; 
	8'h9D : Post_Data = 8'h58; 
	8'h9E : Post_Data = 8'h59; 
	8'h9F : Post_Data = 8'h5A; 
	8'hA0 : Post_Data = 8'h5B; 
	8'hA1 : Post_Data = 8'h5D; 
	8'hA2 : Post_Data = 8'h5E; 
	8'hA3 : Post_Data = 8'h5F; 
	8'hA4 : Post_Data = 8'h61; 
	8'hA5 : Post_Data = 8'h62; 
	8'hA6 : Post_Data = 8'h63; 
	8'hA7 : Post_Data = 8'h64; 
	8'hA8 : Post_Data = 8'h66; 
	8'hA9 : Post_Data = 8'h67; 
	8'hAA : Post_Data = 8'h69; 
	8'hAB : Post_Data = 8'h6A; 
	8'hAC : Post_Data = 8'h6B; 
	8'hAD : Post_Data = 8'h6D; 
	8'hAE : Post_Data = 8'h6E; 
	8'hAF : Post_Data = 8'h6F; 
	8'hB0 : Post_Data = 8'h71; 
	8'hB1 : Post_Data = 8'h72; 
	8'hB2 : Post_Data = 8'h74; 
	8'hB3 : Post_Data = 8'h75; 
	8'hB4 : Post_Data = 8'h77; 
	8'hB5 : Post_Data = 8'h78; 
	8'hB6 : Post_Data = 8'h79; 
	8'hB7 : Post_Data = 8'h7B; 
	8'hB8 : Post_Data = 8'h7C; 
	8'hB9 : Post_Data = 8'h7E; 
	8'hBA : Post_Data = 8'h7F; 
	8'hBB : Post_Data = 8'h81; 
	8'hBC : Post_Data = 8'h82; 
	8'hBD : Post_Data = 8'h84; 
	8'hBE : Post_Data = 8'h85; 
	8'hBF : Post_Data = 8'h87; 
	8'hC0 : Post_Data = 8'h89; 
	8'hC1 : Post_Data = 8'h8A; 
	8'hC2 : Post_Data = 8'h8C; 
	8'hC3 : Post_Data = 8'h8D; 
	8'hC4 : Post_Data = 8'h8F; 
	8'hC5 : Post_Data = 8'h91; 
	8'hC6 : Post_Data = 8'h92; 
	8'hC7 : Post_Data = 8'h94; 
	8'hC8 : Post_Data = 8'h95; 
	8'hC9 : Post_Data = 8'h97; 
	8'hCA : Post_Data = 8'h99; 
	8'hCB : Post_Data = 8'h9A; 
	8'hCC : Post_Data = 8'h9C; 
	8'hCD : Post_Data = 8'h9E; 
	8'hCE : Post_Data = 8'h9F; 
	8'hCF : Post_Data = 8'hA1; 
	8'hD0 : Post_Data = 8'hA3; 
	8'hD1 : Post_Data = 8'hA5; 
	8'hD2 : Post_Data = 8'hA6; 
	8'hD3 : Post_Data = 8'hA8; 
	8'hD4 : Post_Data = 8'hAA; 
	8'hD5 : Post_Data = 8'hAC; 
	8'hD6 : Post_Data = 8'hAD; 
	8'hD7 : Post_Data = 8'hAF; 
	8'hD8 : Post_Data = 8'hB1; 
	8'hD9 : Post_Data = 8'hB3; 
	8'hDA : Post_Data = 8'hB5; 
	8'hDB : Post_Data = 8'hB6; 
	8'hDC : Post_Data = 8'hB8; 
	8'hDD : Post_Data = 8'hBA; 
	8'hDE : Post_Data = 8'hBC; 
	8'hDF : Post_Data = 8'hBE; 
	8'hE0 : Post_Data = 8'hC0; 
	8'hE1 : Post_Data = 8'hC2; 
	8'hE2 : Post_Data = 8'hC4; 
	8'hE3 : Post_Data = 8'hC5; 
	8'hE4 : Post_Data = 8'hC7; 
	8'hE5 : Post_Data = 8'hC9; 
	8'hE6 : Post_Data = 8'hCB; 
	8'hE7 : Post_Data = 8'hCD; 
	8'hE8 : Post_Data = 8'hCF; 
	8'hE9 : Post_Data = 8'hD1; 
	8'hEA : Post_Data = 8'hD3; 
	8'hEB : Post_Data = 8'hD5; 
	8'hEC : Post_Data = 8'hD7; 
	8'hED : Post_Data = 8'hD9; 
	8'hEE : Post_Data = 8'hDB; 
	8'hEF : Post_Data = 8'hDD; 
	8'hF0 : Post_Data = 8'hDF; 
	8'hF1 : Post_Data = 8'hE1; 
	8'hF2 : Post_Data = 8'hE3; 
	8'hF3 : Post_Data = 8'hE5; 
	8'hF4 : Post_Data = 8'hE7; 
	8'hF5 : Post_Data = 8'hEA; 
	8'hF6 : Post_Data = 8'hEC; 
	8'hF7 : Post_Data = 8'hEE; 
	8'hF8 : Post_Data = 8'hF0; 
	8'hF9 : Post_Data = 8'hF2; 
	8'hFA : Post_Data = 8'hF4; 
	8'hFB : Post_Data = 8'hF6; 
	8'hFC : Post_Data = 8'hF8; 
	8'hFD : Post_Data = 8'hFB; 
	8'hFE : Post_Data = 8'hFD; 
	8'hFF : Post_Data = 8'hFF; 
	endcase
end

endmodule

vitis代码

c 复制代码
//作者:抢公主的大魔王
//功能:gamma映射
//日期:24.5.27
//版本:1v0
//联系方式:2376635586@qq.com
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xil_types.h"
#include "xil_cache.h"
#include "xparameters.h"
#include "xgpiops.h"
#include "xscugic.h"
#include "xil_exception.h"
#include "xplatform_info.h"
#include "xaxivdma.h"
#include "xaxivdma_i.h"
#include "display_ctrl_hdmi/display_ctrl.h"
#include "vdma_api/vdma_api.h"
#include "emio_sccb_cfg/emio_sccb_cfg.h"
#include "ov5640/ov5640_init.h"
#include "sleep.h"

//宏定义
#define DYNCLK_BASEADDR  	XPAR_AXI_DYNCLK_0_BASEADDR  //动态时钟基地址
#define VDMA_ID          	XPAR_AXIVDMA_0_DEVICE_ID    //VDMA器件ID
#define DISP_VTC_ID      	XPAR_VTC_0_DEVICE_ID        //VTC器件ID
//#define THRESHOLD_BASEADDR 	XPAR_AXICTRLTHRESHOLD_0_S00_AXI_BASEADDR

#define EMIO_SCL_NUM 54
#define EMIO_SDA_NUM 55
#define KEY1 56 //T19
#define KEY2 57 //P19
#define KEY3 58 //U20
#define KEY4 59 //U19
#define KEY5 60 //V20
#define LED1 61 //H18
#define LED2 62 //K17
#define LED3 63 //E19

#define GPIO_DEVICE_ID  	XPAR_XGPIOPS_0_DEVICE_ID
XGpioPs Gpio;
#define GPIO_BANK	XGPIOPS_BANK0  /* Bank 0 of the GPIO Device */
#define INTC_DEVICE_ID		XPAR_SCUGIC_SINGLE_DEVICE_ID
#define GPIO_INTERRUPT_ID	XPAR_XGPIOPS_0_INTR

//全局变量
//frame buffer的起始地址
unsigned int const frame_buffer_addr = (XPAR_PS7_DDR_0_S_AXI_BASEADDR
										+ 0x1000000);
//u8 binary_threshold = 128;
XAxiVdma     vdma;
DisplayCtrl  dispCtrl;
VideoMode    vd_mode;

static XScuGic Intc; /* The Instance of the Interrupt Controller Driver */


static void IntrHandler(void *CallBackRef, u32 Bank, u32 Status)
{
	XGpioPs *Gpio_cb = (XGpioPs *)CallBackRef;
	if (XGpioPs_IntrGetStatusPin(Gpio_cb, KEY1)){
		//binary_threshold++;
		//Xil_Out32(THRESHOLD_BASEADDR, binary_threshold);
		//xil_printf("The threshold has been changed\n\rThe threshold now is %d\n\r",binary_threshold);
		XGpioPs_IntrClearPin(Gpio_cb, KEY1);
	}
	else if (XGpioPs_IntrGetStatusPin(Gpio_cb, KEY4)){
		//binary_threshold--;
		//Xil_Out32(THRESHOLD_BASEADDR, binary_threshold);
		//xil_printf("The threshold has been changed\n\rThe threshold now is %d\n\r",binary_threshold);
		XGpioPs_IntrClearPin(Gpio_cb, KEY4);
	}
	else if (XGpioPs_IntrGetStatusPin(Gpio_cb, KEY2)){
		//binary_threshold = binary_threshold+10;
		//Xil_Out32(THRESHOLD_BASEADDR, binary_threshold);
		//xil_printf("The threshold has been changed\n\rThe threshold now is %d\n\r",binary_threshold);
		XGpioPs_IntrClearPin(Gpio_cb, KEY2);
	}
	else if (XGpioPs_IntrGetStatusPin(Gpio_cb, KEY5)){
		//binary_threshold = binary_threshold-10;
		//Xil_Out32(THRESHOLD_BASEADDR, binary_threshold);
		//xil_printf("The threshold has been changed\n\rThe threshold now is %d\n\r",binary_threshold);
		XGpioPs_IntrClearPin(Gpio_cb, KEY5);
	}
	else if (XGpioPs_IntrGetStatusPin(Gpio_cb, KEY3)){
		//binary_threshold = 128;
		//Xil_Out32(THRESHOLD_BASEADDR, binary_threshold);
		//xil_printf("The threshold has been reset\n\rThe threshold now is %d\n\r",binary_threshold);
		XGpioPs_IntrClearPin(Gpio_cb, KEY3);
	}
	XGpioPs_WritePin(&Gpio, LED1, !XGpioPs_ReadPin(&Gpio, LED1));
}



void SetupInterruptSystem(XScuGic *GicInstancePtr, XGpioPs *Gpio,
				u16 GpioIntrId){

	XScuGic_Config *IntcConfig;
	Xil_ExceptionInit();

	IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);

	XScuGic_CfgInitialize(GicInstancePtr, IntcConfig,
					IntcConfig->CpuBaseAddress);

	Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
				(Xil_ExceptionHandler)XScuGic_InterruptHandler,
				GicInstancePtr);
	XScuGic_Connect(GicInstancePtr, GpioIntrId,
				(Xil_ExceptionHandler)IntrHandler,
				(void *)Gpio);


	XScuGic_Enable(GicInstancePtr, GpioIntrId);

	XGpioPs_SetIntrTypePin(Gpio, KEY1,  XGPIOPS_IRQ_TYPE_EDGE_FALLING);
	XGpioPs_SetIntrTypePin(Gpio, KEY2,  XGPIOPS_IRQ_TYPE_EDGE_FALLING);
	XGpioPs_SetIntrTypePin(Gpio, KEY3,  XGPIOPS_IRQ_TYPE_EDGE_FALLING);
	XGpioPs_SetIntrTypePin(Gpio, KEY4,  XGPIOPS_IRQ_TYPE_EDGE_FALLING);
	XGpioPs_SetIntrTypePin(Gpio, KEY5,  XGPIOPS_IRQ_TYPE_EDGE_FALLING);

	XGpioPs_IntrEnablePin(Gpio, KEY1);
	XGpioPs_IntrEnablePin(Gpio, KEY2);
	XGpioPs_IntrEnablePin(Gpio, KEY3);
	XGpioPs_IntrEnablePin(Gpio, KEY4);
	XGpioPs_IntrEnablePin(Gpio, KEY5);

	Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ);
}


void Gpio_Init(void){
	XGpioPs_Config *ConfigPtr;

	ConfigPtr = XGpioPs_LookupConfig(GPIO_DEVICE_ID);
	XGpioPs_CfgInitialize(&Gpio, ConfigPtr,ConfigPtr->BaseAddr);

	XGpioPs_SetDirectionPin(&Gpio, LED1, 1);
	XGpioPs_SetOutputEnablePin(&Gpio, LED1, 1);
	XGpioPs_WritePin(&Gpio, LED1, 0);

	XGpioPs_SetDirectionPin(&Gpio, LED2, 1);
	XGpioPs_SetOutputEnablePin(&Gpio, LED2, 1);
	XGpioPs_WritePin(&Gpio, LED2, 0);

	XGpioPs_SetDirectionPin(&Gpio, LED3, 1);
	XGpioPs_SetOutputEnablePin(&Gpio, LED3, 1);
	XGpioPs_WritePin(&Gpio, LED3, 0);

	XGpioPs_SetDirectionPin(&Gpio, KEY1, 0);
	XGpioPs_SetDirectionPin(&Gpio, KEY2, 0);
	XGpioPs_SetDirectionPin(&Gpio, KEY3, 0);
	XGpioPs_SetDirectionPin(&Gpio, KEY4, 0);
	XGpioPs_SetDirectionPin(&Gpio, KEY5, 0);

	SetupInterruptSystem(&Intc, &Gpio, GPIO_INTERRUPT_ID);

}


int main(void)
{
	u32 status;
	u16 cmos_h_pixel;                    //ov5640 DVP 输出水平像素点数
	u16 cmos_v_pixel;                    //ov5640 DVP 输出垂直像素点数
	u16 total_h_pixel;                   //ov5640 水平总像素大小
	u16 total_v_pixel;                   //ov5640 垂直总像素大小

	cmos_h_pixel = 1280;
	cmos_v_pixel = 720;
	total_h_pixel = 2570;
	total_v_pixel = 980;


	emio_init();
	status = ov5640_init( cmos_h_pixel,  //初始化ov5640
						  cmos_v_pixel,
						 total_h_pixel,
						 total_v_pixel);//设置OV5640输出分辨率为1280*720  PCLK = 72Mhz
	if(status == 0)
		xil_printf("OV5640 detected successful!\r\n");
	else
		xil_printf("OV5640 detected failed!\r\n");

	vd_mode = VMODE_1280x720;

	//配置VDMA
	run_vdma_frame_buffer(&vdma, VDMA_ID, vd_mode.width, vd_mode.height,
							frame_buffer_addr,0,0,BOTH);
    //初始化Display controller
	DisplayInitialize(&dispCtrl, DISP_VTC_ID, DYNCLK_BASEADDR);
    //设置VideoMode
	DisplaySetMode(&dispCtrl, &vd_mode);
	DisplayStart(&dispCtrl);
	Gpio_Init();
	while(1){
		XGpioPs_WritePin(&Gpio, LED3, !XGpioPs_ReadPin(&Gpio, LED3));
		sleep(1);
	}
    return 0;
}
相关推荐
audyxiao0018 分钟前
AI一周重要会议和活动概览
人工智能·计算机视觉·数据挖掘·多模态
Jeremy_lf27 分钟前
【生成模型之三】ControlNet & Latent Diffusion Models论文详解
人工智能·深度学习·stable diffusion·aigc·扩散模型
桃花键神1 小时前
AI可信论坛亮点:合合信息分享视觉内容安全技术前沿
人工智能
野蛮的大西瓜1 小时前
开源呼叫中心中,如何将ASR与IVR菜单结合,实现动态的IVR交互
人工智能·机器人·自动化·音视频·信息与通信
CountingStars6192 小时前
目标检测常用评估指标(metrics)
人工智能·目标检测·目标跟踪
tangjunjun-owen2 小时前
第四节:GLM-4v-9b模型的tokenizer源码解读
人工智能·glm-4v-9b·多模态大模型教程
冰蓝蓝2 小时前
深度学习中的注意力机制:解锁智能模型的新视角
人工智能·深度学习
橙子小哥的代码世界2 小时前
【计算机视觉基础CV-图像分类】01- 从历史源头到深度时代:一文读懂计算机视觉的进化脉络、核心任务与产业蓝图
人工智能·计算机视觉
新加坡内哥谈技术3 小时前
苏黎世联邦理工学院与加州大学伯克利分校推出MaxInfoRL:平衡内在与外在探索的全新强化学习框架
大数据·人工智能·语言模型
9527华安3 小时前
FPGA实现MIPI转FPD-Link车载同轴视频传输方案,基于IMX327+FPD953架构,提供工程源码和技术支持
fpga开发·架构·mipi·imx327·fpd-link·fpd953