⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pixel_engine.v

📁 Altera的基于NIOS II的LCD控制器源代码
💻 V
字号:
// ================================================================================
// (c) 2004 Altera Corporation. All rights reserved.
// Altera products are protected under numerous U.S. and foreign patents, maskwork
// rights, copyrights and other intellectual property laws.
// 
// This reference design file, and your use thereof, is subject to and governed
// by the terms and conditions of the applicable Altera Reference Design License
// Agreement (either as signed by you, agreed by you upon download or as a
// "click-through" agreement upon installation andor found at www.altera.com).
// By using this reference design file, you indicate your acceptance of such terms
// and conditions between you and Altera Corporation.  In the event that you do
// not agree with such terms and conditions, you may not use the reference design
// file and please promptly destroy any copies you have made.
// 
// This reference design file is being provided on an "as-is" basis and as an
// accommodation and therefore all warranties, representations or guarantees of
// any kind (whether express, implied or statutory) including, without limitation,
// warranties of merchantability, non-infringement, or fitness for a particular
// purpose, are specifically disclaimed.  By making this reference design file
// available, Altera expressly does not recommend, suggest or require that this
// reference design file be used in combination with any other product not
// provided by Altera.
// ================================================================================

/*
Functionality
RGB-A Modes supported:
666-6 - direct colour mode & palette mode
565-0 - direct colour mode
555-5 - palette mode

Layers with pixel values less than the maximum defined, should align 
to the MSB
e.g.
pixel [4:0]

.pixel_r ({pixel, 1'b0}), //for a 6-bit pixel_r value

4 cycles of latency relative to pixel_clk
new value can be applied every cycle

*/

module pixel_engine (
//inputs
pixel_clk,
rst_n,

pixel_lay0,

pixel_lay1,
alpha_lay1,
const_alpha_lay1,

pixel_lay2,
alpha_lay2,
const_alpha_lay2,

pixel_lay3,
alpha_lay3,
const_alpha_lay3,

pixel_lay4,
alpha_lay4,
const_alpha_lay4,

background,

//control inputs
layer_0_on,
layer_1_on,
layer_2_on,
layer_3_on,
layer_4_on,

//outputs
lcd_data
);

//inputs
input pixel_clk;
input rst_n;

input [17:0] pixel_lay0;
input [17:0] pixel_lay1;
input [5:0] alpha_lay1;
input [5:0] const_alpha_lay1;
input [17:0] pixel_lay2;
input [5:0] alpha_lay2;
input [5:0] const_alpha_lay2;
input [17:0] pixel_lay3;
input [5:0] alpha_lay3;
input [5:0] const_alpha_lay3;
input [17:0] pixel_lay4;
input [5:0] alpha_lay4;
input [5:0] const_alpha_lay4;

input [15:0] background;

input layer_0_on;
input layer_1_on;
input layer_2_on;
input layer_3_on;
input layer_4_on;


//output
output [17:0] lcd_data;

//reg
reg [17:0] lcd_data;

//wire
wire [11:0] alpha_l1;
wire [11:0] alpha_l2;
wire [11:0] alpha_l3;
wire [11:0] alpha_l4;
wire [5:0] red_out;
wire [5:0] blue_out;
wire [5:0] green_out;

reg alpha_l1_max;
reg alpha_l2_max;
reg alpha_l3_max;
reg alpha_l4_max;

always @(posedge pixel_clk)
 if (alpha_lay1 == 'h3f && const_alpha_lay1 == 'h3f)
  alpha_l1_max <= 1;
 else
  alpha_l1_max <= 0;

always @(posedge pixel_clk)
 if (alpha_lay2 == 'h3f && const_alpha_lay2 == 'h3f)
  alpha_l2_max <= 1;
 else
  alpha_l2_max <= 0;

always @(posedge pixel_clk)
 if (alpha_lay3 == 'h3f && const_alpha_lay3 == 'h3f)
  alpha_l3_max <= 1;
 else
  alpha_l3_max <= 0;

always @(posedge pixel_clk)
 if (alpha_lay4 == 'h3f && const_alpha_lay4 == 'h3f)
  alpha_l4_max <= 1;
 else
  alpha_l4_max <= 0;


//alpha generation - start
mult_6bit u_alpha_l1 (
	.dataa  (alpha_lay1),
	.datab  (const_alpha_lay1),
	.result  (alpha_l1)
	);

mult_6bit u_alpha_l2 (
	.dataa  (alpha_lay2),
	.datab  (const_alpha_lay2),
	.result  (alpha_l2)
	);

mult_6bit u_alpha_l3 (
	.dataa  (alpha_lay3),
	.datab  (const_alpha_lay3),
	.result  (alpha_l3)
	);

mult_6bit u_alpha_l4 (
	.dataa  (alpha_lay4),
	.datab  (const_alpha_lay4),
	.result  (alpha_l4)
	);
	
//alpha generation - end


//The red datapath
DPath DPath_blue (
//inputs
.pixel_clk (pixel_clk),
.layer0 (pixel_lay0[5:0]),
.layer1 (pixel_lay1[5:0]),
.layer2 (pixel_lay2[5:0]),
.layer3 (pixel_lay3[5:0]),
.layer4 (pixel_lay4[5:0]),
.alpha_l1 (alpha_l1[11:6]),
.alpha_l2 (alpha_l2[11:6]),
.alpha_l3 (alpha_l3[11:6]),
.alpha_l4 (alpha_l4[11:6]),
.alpha_l1_max (alpha_l1_max),
.alpha_l2_max (alpha_l2_max),
.alpha_l3_max (alpha_l3_max),
.alpha_l4_max (alpha_l4_max),
//outputs
.result (blue_out)
);

//The green datapath
DPath DPath_green (
//inputs
.pixel_clk (pixel_clk),
.layer0 (pixel_lay0[11:6]),
.layer1 (pixel_lay1[11:6]),
.layer2 (pixel_lay2[11:6]),
.layer3 (pixel_lay3[11:6]),
.layer4 (pixel_lay4[11:6]),
.alpha_l1 (alpha_l1[11:6]),
.alpha_l2 (alpha_l2[11:6]),
.alpha_l3 (alpha_l3[11:6]),
.alpha_l4 (alpha_l4[11:6]),
.alpha_l1_max (alpha_l1_max),
.alpha_l2_max (alpha_l2_max),
.alpha_l3_max (alpha_l3_max),
.alpha_l4_max (alpha_l4_max),
//outputs
.result (green_out)
);

//The blue datapath
DPath DPath_red (
//inputs
.pixel_clk (pixel_clk),
.layer0 (pixel_lay0[17:12]),
.layer1 (pixel_lay1[17:12]),
.layer2 (pixel_lay2[17:12]),
.layer3 (pixel_lay3[17:12]),
.layer4 (pixel_lay4[17:12]),
.alpha_l1 (alpha_l1[11:6]),
.alpha_l2 (alpha_l2[11:6]),
.alpha_l3 (alpha_l3[11:6]),
.alpha_l4 (alpha_l4[11:6]),
.alpha_l1_max (alpha_l1_max),
.alpha_l2_max (alpha_l2_max),
.alpha_l3_max (alpha_l3_max),
.alpha_l4_max (alpha_l4_max),
//outputs
.result (red_out)
);


always @(red_out or blue_out or green_out or background[15:0] or layer_0_on or layer_1_on or layer_2_on or layer_3_on or layer_4_on)
 begin
  if (~layer_0_on && ~layer_1_on && ~layer_2_on && ~layer_3_on && ~layer_4_on)
   begin   
    lcd_data[5:0] <= ({background[4:0],1'b0}); //blue, background 5-bits
    lcd_data[11:6] <= (background[10:5]); //green, background 6-bits
    lcd_data[17:12] <= ({background[15:11],1'b0}); //red, background 5-bits
   end
  else
   begin
    lcd_data[5:0] <= blue_out; //blue
    lcd_data[11:6] <= green_out; //green
    lcd_data[17:12] <= red_out; //red
   end
 end



endmodule

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -