1 |
11 |
arniml |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- GCpad controller core
|
4 |
|
|
--
|
5 |
41 |
arniml |
-- $Id: gcpad_basic.vhd 41 2009-04-01 19:58:04Z arniml $
|
6 |
11 |
arniml |
--
|
7 |
|
|
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
|
8 |
|
|
--
|
9 |
|
|
-- All rights reserved
|
10 |
|
|
--
|
11 |
|
|
-- Redistribution and use in source and synthezised forms, with or without
|
12 |
|
|
-- modification, are permitted provided that the following conditions are met:
|
13 |
|
|
--
|
14 |
|
|
-- Redistributions of source code must retain the above copyright notice,
|
15 |
|
|
-- this list of conditions and the following disclaimer.
|
16 |
|
|
--
|
17 |
|
|
-- Redistributions in synthesized form must reproduce the above copyright
|
18 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
19 |
|
|
-- documentation and/or other materials provided with the distribution.
|
20 |
|
|
--
|
21 |
|
|
-- Neither the name of the author nor the names of other contributors may
|
22 |
|
|
-- be used to endorse or promote products derived from this software without
|
23 |
|
|
-- specific prior written permission.
|
24 |
|
|
--
|
25 |
|
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
26 |
|
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
27 |
|
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
28 |
|
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
29 |
|
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
30 |
|
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
31 |
|
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
32 |
|
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
33 |
|
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
34 |
|
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
35 |
|
|
-- POSSIBILITY OF SUCH DAMAGE.
|
36 |
|
|
--
|
37 |
|
|
-- Please report bugs to the author, but before you do so, please
|
38 |
|
|
-- make sure that this is not a derivative work and that
|
39 |
|
|
-- you have the latest version of this file.
|
40 |
|
|
--
|
41 |
|
|
-- The latest version of this file can be found at:
|
42 |
|
|
-- http://www.opencores.org/cvsweb.shtml/gamepads/
|
43 |
|
|
--
|
44 |
|
|
-- The project homepage is located at:
|
45 |
|
|
-- http://www.opencores.org/projects.cgi/web/gamepads/overview
|
46 |
|
|
--
|
47 |
|
|
-------------------------------------------------------------------------------
|
48 |
|
|
|
49 |
|
|
library ieee;
|
50 |
|
|
use ieee.std_logic_1164.all;
|
51 |
|
|
|
52 |
|
|
entity gcpad_basic is
|
53 |
|
|
|
54 |
|
|
generic (
|
55 |
23 |
arniml |
-- active level of reset_i
|
56 |
11 |
arniml |
reset_level_g : integer := 0;
|
57 |
23 |
arniml |
-- number of clk_i periods during 1us
|
58 |
11 |
arniml |
clocks_per_1us_g : integer := 2
|
59 |
|
|
);
|
60 |
|
|
port (
|
61 |
|
|
-- System Interface -------------------------------------------------------
|
62 |
|
|
clk_i : in std_logic;
|
63 |
|
|
reset_i : in std_logic;
|
64 |
|
|
pad_request_i : in std_logic;
|
65 |
|
|
pad_avail_o : out std_logic;
|
66 |
|
|
-- Gamepad Interface ------------------------------------------------------
|
67 |
|
|
pad_data_io : inout std_logic;
|
68 |
|
|
-- Buttons Interface ------------------------------------------------------
|
69 |
|
|
but_a_o : out std_logic;
|
70 |
|
|
but_b_o : out std_logic;
|
71 |
|
|
but_x_o : out std_logic;
|
72 |
|
|
but_y_o : out std_logic;
|
73 |
|
|
but_z_o : out std_logic;
|
74 |
|
|
but_start_o : out std_logic;
|
75 |
|
|
but_tl_o : out std_logic;
|
76 |
|
|
but_tr_o : out std_logic;
|
77 |
|
|
but_left_o : out std_logic;
|
78 |
|
|
but_right_o : out std_logic;
|
79 |
|
|
but_up_o : out std_logic;
|
80 |
|
|
but_down_o : out std_logic;
|
81 |
|
|
ana_joy_x_o : out std_logic_vector(7 downto 0);
|
82 |
|
|
ana_joy_y_o : out std_logic_vector(7 downto 0);
|
83 |
|
|
ana_c_x_o : out std_logic_vector(7 downto 0);
|
84 |
|
|
ana_c_y_o : out std_logic_vector(7 downto 0);
|
85 |
|
|
ana_l_o : out std_logic_vector(7 downto 0);
|
86 |
|
|
ana_r_o : out std_logic_vector(7 downto 0)
|
87 |
|
|
);
|
88 |
|
|
|
89 |
|
|
end gcpad_basic;
|
90 |
|
|
|
91 |
|
|
|
92 |
17 |
arniml |
use work.gcpad_pack.all;
|
93 |
11 |
arniml |
|
94 |
|
|
architecture struct of gcpad_basic is
|
95 |
|
|
|
96 |
|
|
component gcpad_ctrl
|
97 |
|
|
generic (
|
98 |
|
|
reset_level_g : integer := 0
|
99 |
|
|
);
|
100 |
|
|
port (
|
101 |
|
|
clk_i : in std_logic;
|
102 |
|
|
reset_i : in std_logic;
|
103 |
|
|
pad_request_i : in std_logic;
|
104 |
|
|
pad_avail_o : out std_logic;
|
105 |
18 |
arniml |
rx_timeout_o : out std_logic;
|
106 |
11 |
arniml |
tx_start_o : out boolean;
|
107 |
|
|
tx_finished_i : in boolean;
|
108 |
|
|
rx_en_o : out boolean;
|
109 |
18 |
arniml |
rx_done_i : in boolean;
|
110 |
|
|
rx_data_ok_i : in boolean
|
111 |
11 |
arniml |
);
|
112 |
|
|
end component;
|
113 |
|
|
|
114 |
|
|
component gcpad_tx
|
115 |
|
|
generic (
|
116 |
|
|
reset_level_g : natural := 0;
|
117 |
|
|
clocks_per_1us_g : natural := 2
|
118 |
|
|
);
|
119 |
|
|
port (
|
120 |
|
|
clk_i : in std_logic;
|
121 |
|
|
reset_i : in std_logic;
|
122 |
|
|
pad_data_o : out std_logic;
|
123 |
|
|
tx_start_i : in boolean;
|
124 |
|
|
tx_finished_o : out boolean;
|
125 |
12 |
arniml |
tx_size_i : in std_logic_vector( 1 downto 0);
|
126 |
11 |
arniml |
tx_command_i : in std_logic_vector(23 downto 0)
|
127 |
|
|
);
|
128 |
|
|
end component;
|
129 |
|
|
|
130 |
|
|
component gcpad_rx
|
131 |
|
|
generic (
|
132 |
|
|
reset_level_g : integer := 0;
|
133 |
|
|
clocks_per_1us_g : integer := 2
|
134 |
|
|
);
|
135 |
|
|
port (
|
136 |
|
|
clk_i : in std_logic;
|
137 |
|
|
reset_i : in std_logic;
|
138 |
|
|
rx_en_i : in boolean;
|
139 |
|
|
rx_done_o : out boolean;
|
140 |
18 |
arniml |
rx_data_ok_o : out boolean;
|
141 |
12 |
arniml |
rx_size_i : in std_logic_vector(3 downto 0);
|
142 |
11 |
arniml |
pad_data_i : in std_logic;
|
143 |
17 |
arniml |
rx_data_o : out buttons_t
|
144 |
11 |
arniml |
);
|
145 |
|
|
end component;
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
-----------------------------------------------------------------------------
|
149 |
|
|
-- constants for standard status polling
|
150 |
12 |
arniml |
constant rx_size_c : std_logic_vector( 3 downto 0) := "1000";
|
151 |
|
|
signal rx_size_s : std_logic_vector( 3 downto 0);
|
152 |
11 |
arniml |
--
|
153 |
12 |
arniml |
constant tx_size_c : std_logic_vector( 1 downto 0) := "11";
|
154 |
|
|
signal tx_size_s : std_logic_vector( 1 downto 0);
|
155 |
11 |
arniml |
--
|
156 |
|
|
constant tx_command_c : std_logic_vector(23 downto 0) := "010000000000001100000010";
|
157 |
|
|
signal tx_command_s : std_logic_vector(23 downto 0);
|
158 |
|
|
--
|
159 |
|
|
-----------------------------------------------------------------------------
|
160 |
|
|
|
161 |
|
|
signal pad_data_tx_s : std_logic;
|
162 |
|
|
|
163 |
|
|
signal tx_start_s : boolean;
|
164 |
|
|
signal tx_finished_s : boolean;
|
165 |
|
|
|
166 |
|
|
signal rx_en_s,
|
167 |
18 |
arniml |
rx_done_s,
|
168 |
|
|
rx_data_ok_s : boolean;
|
169 |
11 |
arniml |
|
170 |
17 |
arniml |
signal rx_data_s : buttons_t;
|
171 |
|
|
|
172 |
11 |
arniml |
begin
|
173 |
|
|
|
174 |
|
|
rx_size_s <= rx_size_c;
|
175 |
|
|
tx_size_s <= tx_size_c;
|
176 |
|
|
tx_command_s <= tx_command_c;
|
177 |
|
|
|
178 |
|
|
ctrl_b : gcpad_ctrl
|
179 |
|
|
generic map (
|
180 |
|
|
reset_level_g => reset_level_g
|
181 |
|
|
)
|
182 |
|
|
port map (
|
183 |
|
|
clk_i => clk_i,
|
184 |
|
|
reset_i => reset_i,
|
185 |
|
|
pad_request_i => pad_request_i,
|
186 |
|
|
pad_avail_o => pad_avail_o,
|
187 |
18 |
arniml |
rx_timeout_o => open,
|
188 |
11 |
arniml |
tx_start_o => tx_start_s,
|
189 |
|
|
tx_finished_i => tx_finished_s,
|
190 |
|
|
rx_en_o => rx_en_s,
|
191 |
18 |
arniml |
rx_done_i => rx_done_s,
|
192 |
|
|
rx_data_ok_i => rx_data_ok_s
|
193 |
11 |
arniml |
);
|
194 |
|
|
|
195 |
|
|
tx_b : gcpad_tx
|
196 |
|
|
generic map (
|
197 |
|
|
reset_level_g => reset_level_g,
|
198 |
|
|
clocks_per_1us_g => clocks_per_1us_g
|
199 |
|
|
)
|
200 |
|
|
port map (
|
201 |
|
|
clk_i => clk_i,
|
202 |
|
|
reset_i => reset_i,
|
203 |
|
|
pad_data_o => pad_data_tx_s,
|
204 |
|
|
tx_start_i => tx_start_s,
|
205 |
|
|
tx_finished_o => tx_finished_s,
|
206 |
|
|
tx_size_i => tx_size_s,
|
207 |
|
|
tx_command_i => tx_command_s
|
208 |
|
|
);
|
209 |
|
|
|
210 |
|
|
rx_b : gcpad_rx
|
211 |
|
|
generic map (
|
212 |
|
|
reset_level_g => reset_level_g,
|
213 |
|
|
clocks_per_1us_g => clocks_per_1us_g
|
214 |
|
|
)
|
215 |
|
|
port map (
|
216 |
|
|
clk_i => clk_i,
|
217 |
|
|
reset_i => reset_i,
|
218 |
|
|
rx_en_i => rx_en_s,
|
219 |
|
|
rx_done_o => rx_done_s,
|
220 |
18 |
arniml |
rx_data_ok_o => rx_data_ok_s,
|
221 |
11 |
arniml |
rx_size_i => rx_size_s,
|
222 |
|
|
pad_data_i => pad_data_io,
|
223 |
17 |
arniml |
rx_data_o => rx_data_s
|
224 |
11 |
arniml |
);
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
-----------------------------------------------------------------------------
|
228 |
|
|
-- Open collector driver to pad data
|
229 |
|
|
-----------------------------------------------------------------------------
|
230 |
|
|
pad_data_io <= '0'
|
231 |
|
|
when pad_data_tx_s = '0' else
|
232 |
|
|
'Z';
|
233 |
|
|
|
234 |
17 |
arniml |
-----------------------------------------------------------------------------
|
235 |
|
|
-- Output mapping
|
236 |
|
|
-----------------------------------------------------------------------------
|
237 |
|
|
but_a_o <= rx_data_s(pos_a_c);
|
238 |
|
|
but_b_o <= rx_data_s(pos_b_c);
|
239 |
|
|
but_x_o <= rx_data_s(pos_x_c);
|
240 |
|
|
but_y_o <= rx_data_s(pos_y_c);
|
241 |
|
|
but_z_o <= rx_data_s(pos_z_c);
|
242 |
|
|
but_start_o <= rx_data_s(pos_start_c);
|
243 |
|
|
but_tl_o <= rx_data_s(pos_tl_c);
|
244 |
|
|
but_tr_o <= rx_data_s(pos_tr_c);
|
245 |
|
|
but_left_o <= rx_data_s(pos_left_c);
|
246 |
|
|
but_right_o <= rx_data_s(pos_right_c);
|
247 |
|
|
but_up_o <= rx_data_s(pos_up_c);
|
248 |
|
|
but_down_o <= rx_data_s(pos_down_c);
|
249 |
|
|
ana_joy_x_o <= rx_data_s(joy_x_high_c downto joy_x_low_c);
|
250 |
|
|
ana_joy_y_o <= rx_data_s(joy_y_high_c downto joy_y_low_c);
|
251 |
|
|
ana_c_x_o <= rx_data_s(c_x_high_c downto c_x_low_c);
|
252 |
|
|
ana_c_y_o <= rx_data_s(c_y_high_c downto c_y_low_c);
|
253 |
|
|
ana_l_o <= rx_data_s(l_high_c downto l_low_c);
|
254 |
|
|
ana_r_o <= rx_data_s(r_high_c downto r_low_c);
|
255 |
|
|
|
256 |
11 |
arniml |
end struct;
|