Line 1... |
Line 1... |
//==================================================================
|
//==================================================================//
|
// File: d_MouseDriver.v
|
// File: d_MouseDriver.v //
|
// Version: 0.01
|
// Version: 0.0.0.1 //
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -//
|
// Copyright Stephen Pickett
|
// Copyright (C) Stephen Pickett //
|
// April 28, 2005
|
// Apr 28, 2005 //
|
//------------------------------------------------------------------
|
// //
|
// Revisions:
|
// This program is free software; you can redistribute it and/or //
|
// Ver 0.01 Apr 28, 2005 Initial Release
|
// modify it under the terms of the GNU General Public License //
|
//
|
// as published by the Free Software Foundation; either version 2 //
|
//==================================================================
|
// of the License, or (at your option) any later version. //
|
|
// //
|
|
// This program is distributed in the hope that it will be useful, //
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
// GNU General Public License for more details. //
|
|
// //
|
|
// If you have not received a copy of the GNU General Public License//
|
|
// along with this program; write to: //
|
|
// Free Software Foundation, Inc., //
|
|
// 51 Franklin Street, Fifth Floor, //
|
|
// Boston, MA 02110-1301, USA. //
|
|
// //
|
|
//------------------------------------------------------------------//
|
|
// Revisions: //
|
|
// Ver 0.0.0.1 Apr 28, 2005 Under Development //
|
|
// //
|
|
//==================================================================//
|
|
|
module Driver_mouse(
|
module Driver_mouse(
|
CLK_50MHZ, MASTER_RST,
|
CLK_50MHZ, MASTER_RST,
|
PS2C, PS2D,
|
PS2C, PS2D,
|
XCOORD, YCOORD,
|
XCOORD, YCOORD,
|
Line 89... |
Line 106... |
reg CLK_ps2c_debounced;
|
reg CLK_ps2c_debounced;
|
|
|
// Debounce the PS2C line.
|
// Debounce the PS2C line.
|
// The mouse is generally not outputting a nice rising clock edge.
|
// The mouse is generally not outputting a nice rising clock edge.
|
// To eliminate the false edge detection, make sure it is high/low
|
// To eliminate the false edge detection, make sure it is high/low
|
// for at least 256 counts before triggering the CLK.
|
// for at least 256 counts (5.12us off 50MHz) before triggering the CLK.
|
always @ (posedge CLK_50MHZ or posedge MASTER_RST) begin
|
always @ (posedge CLK_50MHZ or posedge MASTER_RST) begin
|
if(MASTER_RST == 1'b1) begin
|
if(MASTER_RST == 1'b1) begin
|
Counter_PS2C <= 8'b0;
|
Counter_PS2C <= 8'b0;
|
end else begin
|
end else begin
|
if(PS2C == 1'b1) begin
|
if(PS2C == 1'b1) begin
|
Line 157... |
Line 174... |
if(XCOORD <= xcoord_buf)
|
if(XCOORD <= xcoord_buf)
|
XCOORD <= 12'b0;
|
XCOORD <= 12'b0;
|
else
|
else
|
XCOORD <= XCOORD - xcoord_buf;
|
XCOORD <= XCOORD - xcoord_buf;
|
end else begin // POSITIVE
|
end else begin // POSITIVE
|
if((XCOORD + xcoord_buf) >= 11'd639)
|
if((XCOORD + xcoord_buf) >= 12'd639)
|
XCOORD <= 12'd639;
|
XCOORD <= 12'd639;
|
else
|
else
|
XCOORD <= XCOORD + xcoord_buf;
|
XCOORD <= XCOORD + xcoord_buf;
|
end
|
end
|
end else begin
|
end else begin
|
Line 172... |
Line 189... |
always @ (posedge CLK_ps2c_debounced or posedge MASTER_RST) begin
|
always @ (posedge CLK_ps2c_debounced or posedge MASTER_RST) begin
|
if(MASTER_RST == 1'b1) begin
|
if(MASTER_RST == 1'b1) begin
|
YCOORD <= 12'd199;
|
YCOORD <= 12'd199;
|
end else if(Counter_bits == 6'd32 && (data_in_buf[8] == 1'b0)) begin
|
end else if(Counter_bits == 6'd32 && (data_in_buf[8] == 1'b0)) begin
|
if(data_in_buf[6] == 1'b0) begin
|
if(data_in_buf[6] == 1'b0) begin
|
if((YCOORD + ycoord_buf) >= 11'd479)
|
if( (YCOORD < 12'd401) && ((YCOORD + ycoord_buf) >= 12'd401) )
|
YCOORD <= 12'd479;
|
YCOORD <= 12'd400;
|
|
else if( ((YCOORD >= 12'd441) /*&& (YCOORD <= 12'd520)*/) && ((YCOORD + ycoord_buf) > 12'd520) )
|
|
YCOORD <= (YCOORD + ycoord_buf) - 12'd521;
|
else
|
else
|
YCOORD <= YCOORD + ycoord_buf;
|
YCOORD <= YCOORD + ycoord_buf;
|
end else begin
|
end else begin
|
if(YCOORD <= ycoord_buf)
|
if( /*(YCOORD < 12'd401) &&*/ (YCOORD < ycoord_buf) )
|
YCOORD <= 12'd0;
|
YCOORD <= 12'd521 - ycoord_buf;
|
|
else if( (YCOORD >= 12'd441) && ((YCOORD-12'd441) < ycoord_buf) )
|
|
YCOORD <= 12'd441;
|
else
|
else
|
YCOORD <= YCOORD - ycoord_buf;
|
YCOORD <= YCOORD - ycoord_buf;
|
end
|
end
|
end else begin
|
end else begin
|
YCOORD <= YCOORD;
|
YCOORD <= YCOORD;
|