2024-05-12 22:09:23 +08:00
|
|
|
module crop #(
|
2024-05-16 17:33:39 +08:00
|
|
|
parameter IN_WIDTH = 1936,
|
|
|
|
parameter IN_HEIGHT = 1088,
|
2024-05-12 22:09:23 +08:00
|
|
|
parameter OFFSET_X = 8,
|
|
|
|
parameter OFFSET_Y = 4,
|
|
|
|
parameter OUT_WIDTH = 640,
|
2024-05-13 11:29:03 +08:00
|
|
|
parameter OUT_HEIGHT = 480,
|
|
|
|
parameter COLOR_DEPTH = 8
|
2024-05-12 22:09:23 +08:00
|
|
|
) (
|
|
|
|
input clk,
|
|
|
|
input reset,
|
|
|
|
|
|
|
|
input in_en,
|
2024-05-15 16:35:17 +08:00
|
|
|
output reg in_que,
|
2024-05-12 22:09:23 +08:00
|
|
|
input [3 * COLOR_DEPTH - 1:0] data_in,
|
|
|
|
|
2024-05-15 16:35:17 +08:00
|
|
|
output reg out_en,
|
2024-05-12 22:09:23 +08:00
|
|
|
output reg [3 * COLOR_DEPTH - 1:0] data_out
|
|
|
|
);
|
2024-05-14 21:25:59 +08:00
|
|
|
localparam READ_DATA = 0;
|
|
|
|
localparam HANDLE_DATA = 1;
|
|
|
|
localparam SEND_DATA = 2;
|
2024-05-12 22:09:23 +08:00
|
|
|
|
2024-05-14 21:25:59 +08:00
|
|
|
reg [1:0] state, nextState;
|
|
|
|
reg [11:0] cnt_x, cnt_y;
|
|
|
|
reg [3 * COLOR_DEPTH - 1:0] data;
|
2024-05-12 22:09:23 +08:00
|
|
|
|
2024-05-14 21:25:59 +08:00
|
|
|
// 状态切换
|
|
|
|
always @(posedge clk or posedge reset) begin
|
|
|
|
if (reset)
|
|
|
|
state <= READ_DATA;
|
|
|
|
else
|
|
|
|
state <= nextState;
|
|
|
|
end
|
2024-05-12 22:09:23 +08:00
|
|
|
|
2024-05-14 21:25:59 +08:00
|
|
|
// 下一状态更新
|
|
|
|
always @(*) begin
|
|
|
|
case (state)
|
2024-05-15 16:35:17 +08:00
|
|
|
READ_DATA: nextState = (in_que && in_en) ? HANDLE_DATA : READ_DATA;
|
|
|
|
HANDLE_DATA: nextState = SEND_DATA;
|
|
|
|
SEND_DATA: nextState = READ_DATA;
|
2024-05-14 21:25:59 +08:00
|
|
|
endcase
|
|
|
|
end
|
2024-05-12 22:09:23 +08:00
|
|
|
|
|
|
|
always @(posedge clk or posedge reset) begin
|
|
|
|
if (reset) begin
|
|
|
|
cnt_x <= 0;
|
|
|
|
cnt_y <= 0;
|
2024-05-14 21:25:59 +08:00
|
|
|
data <= 0;
|
2024-05-12 22:09:23 +08:00
|
|
|
end
|
|
|
|
else begin
|
2024-05-14 21:25:59 +08:00
|
|
|
case (state)
|
|
|
|
READ_DATA: begin
|
|
|
|
in_que <= 1;
|
|
|
|
|
|
|
|
if (in_en) begin
|
|
|
|
data <= data_in;
|
|
|
|
in_que <= 0;
|
2024-05-13 10:49:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-05-14 21:25:59 +08:00
|
|
|
HANDLE_DATA: begin
|
|
|
|
if (OFFSET_Y <= cnt_y && cnt_y < (OFFSET_Y + OUT_HEIGHT)) begin
|
|
|
|
if (OFFSET_X <= cnt_x && cnt_x < (OFFSET_X + OUT_WIDTH)) begin
|
|
|
|
out_en <= 1;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-05-16 17:33:39 +08:00
|
|
|
if (cnt_x >= IN_WIDTH) begin
|
2024-05-14 21:25:59 +08:00
|
|
|
cnt_x <= 0;
|
2024-05-16 17:33:39 +08:00
|
|
|
if (cnt_y >= IN_HEIGHT) begin
|
2024-05-14 21:25:59 +08:00
|
|
|
cnt_y <= 0;
|
|
|
|
end
|
|
|
|
else begin
|
|
|
|
cnt_y <= cnt_y + 1;
|
|
|
|
end
|
2024-05-12 22:09:23 +08:00
|
|
|
end
|
|
|
|
else begin
|
2024-05-14 21:25:59 +08:00
|
|
|
cnt_x <= cnt_x + 1;
|
2024-05-12 22:09:23 +08:00
|
|
|
end
|
|
|
|
end
|
2024-05-14 21:25:59 +08:00
|
|
|
|
|
|
|
SEND_DATA: begin
|
|
|
|
data_out <= data;
|
|
|
|
out_en <= 0;
|
|
|
|
end
|
|
|
|
|
|
|
|
endcase
|
2024-05-12 22:09:23 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-05-13 11:29:03 +08:00
|
|
|
endmodule
|