-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouse_Control.vhd
More file actions
265 lines (193 loc) · 4.43 KB
/
Mouse_Control.vhd
File metadata and controls
265 lines (193 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity Mouse_control is
port(
clk :in std_logic;
rst :in std_logic;
data_mouse :inout std_logic;
clk_mouse :inout std_logic;
valid :out std_logic;
x_move :out std_logic_vector(8 downto 0);
y_move :out std_logic_vector(8 downto 0)
);
end entity Mouse_control;
architecture arc_Mouse_control of Mouse_control is
component init is
port(
clk :in std_logic;
rst :in std_logic;
init_start :in std_logic;
set :out std_logic;
clk_12 :out std_logic;
data :out std_logic
);
end component;
component valid_check is
port(
clk :in std_logic;
rst :in std_logic;
SM_valid :in std_logic;
Rx_valid :in std_logic;
valid :out std_logic
);
end component;
component sync is
port(
clk :in std_logic;
rst :in std_logic;
d_in :in std_logic;
d_out :out std_logic
);
end component;
component Rx is
port(
clk :in std_logic;
clk_12 :in std_logic;
rst :in std_logic;
data :in std_logic;
byte_sel :in std_logic_vector(2 downto 0);
selector_3 :out std_logic_vector(2 downto 0);
x_move :out std_logic_vector(8 downto 0);
y_move :out std_logic_vector(8 downto 0);
Rx_valid :out std_logic
);
end component;
-- init signals
signal init_start : std_logic;
signal set : std_logic;
signal clk_init : std_logic;
signal data_init : std_logic;
-- sync signals
signal sync_clk :std_logic;
signal sync_data :std_logic;
-- Rx signals
signal Rx_valid :std_logic;
signal selector_3 :std_logic_vector(2 downto 0);
signal byte_sel :std_logic_vector(2 downto 0);
--SM signals
signal SM_valid :std_logic;
type SM_control is (reset , initsm , byte_1 , byte_2 , byte_3 , validsm);
signal state : SM_control ;
begin
init11 : init
port map(
clk => clk,
rst => rst,
init_start => init_start,
set => set,
clk_12 => clk_init,
data => data_init
);
Reciver : Rx
port map(
clk => clk,
rst => rst,
selector_3 => selector_3,
byte_sel => byte_sel,
clk_12 => sync_clk,
data => sync_data,
x_move => x_move,
y_move => y_move,
Rx_valid => Rx_valid
);
clk_sync : sync
port map(
clk => clk,
rst => rst,
d_in => clk_mouse,
d_out => sync_clk
);
data_sync : sync
port map(
clk => clk,
rst => rst,
d_in => data_mouse,
d_out => sync_data
);
-- Process to set 'Z' on INOUT ports when init is done
start_process: process(clk, rst)
begin
if (rst = '0') then
data_mouse <= data_init;
clk_mouse <= clk_init;
elsif falling_edge(clk) then
if (init_start = '0') then
data_mouse <= 'Z';
clk_mouse <= 'Z';
else
data_mouse <= data_init;
clk_mouse <= clk_init;
end if;
end if;
end process;
-- Process for SM control
process (clk , rst) is
begin
if (rst = '0') then
state <= reset;
elsif Falling_edge(clk) then
state<= state;
case state is
when reset =>
state <= initsm;
when initsm =>
if (set ='1') then
state <= byte_1;
end if;
when byte_1 =>
if (selector_3 ="001") then
state <= byte_2;
end if;
when byte_2 =>
if (selector_3 = "010") then
state <= byte_3;
end if;
when byte_3 =>
if (selector_3 = "100") then
state <= validsm;
end if;
when validsm =>
state <= byte_1;
when others =>
state <= reset;
end case;
end if;
end process;
process(clk, rst)
begin
if(rst = '0') then
init_start <= '0';
byte_sel <= (others=>'0');
sm_valid <= '0';
elsif falling_edge(clk) then
init_start <= '0';
byte_sel <= (others=>'0');
case state is
when initsm =>
init_start <= '1';
sm_valid <= '0';
when byte_1 =>
byte_sel(0) <= '1';
sm_valid <= '0';
when byte_2 =>
byte_sel(1) <= '1';
when byte_3 =>
byte_sel(2) <= '1';
sm_valid <= '1';
when validsm =>
sm_valid <= '1';
when others =>
end case;
end if;
end process;
valid_process: process(clk, rst)
begin
if (rst = '0') then
valid <= '0';
elsif falling_edge(clk) then
valid <= SM_valid AND Rx_valid;
end if;
end process;
end architecture arc_Mouse_control;