added vhd (test) code switch2usb (not working for known reasons, fixed @ccc)
[my-code/fpga.git] / switch2usb / s2usb.vhd
1 library IEEE;
2 use IEEE.STD_LOGIC_1164.ALL;
3 use IEEE.STD_LOGIC_ARITH.ALL;
4 use IEEE.STD_LOGIC_UNSIGNED.ALL;
5
6 entity s2usb is
7     Port ( switch : in  STD_LOGIC_VECTOR (7 downto 0);
8            -- button : in  STD_LOGIC;
9                           clock : in STD_LOGIC;
10                           usb_full : in  STD_LOGIC;
11            usb_data : out  STD_LOGIC_VECTOR (7 downto 0);
12            usb_fifo_addr : out  STD_LOGIC_VECTOR (1 downto 0);
13            usb_write : out  STD_LOGIC;
14            usb_pktend : out  STD_LOGIC;
15                           usb_cs : out STD_LOGIC;
16                           led : out std_logic_vector(7 downto 0));
17 end s2usb;
18
19 architecture Behavioral of s2usb is
20
21 signal prescaler : std_logic_vector(2 downto 0) := "000";
22 signal state : std_logic := '1';
23
24 begin
25
26 usb_send : process(clock)
27 begin
28
29         if(clock'event) and (clock='1') then
30                 prescaler <= prescaler + 1;
31                 if(prescaler="000") then
32                         if(usb_full='1') then
33                                 if(state='1') then
34                                         state <= '0';
35                                 elsif(state='0') then
36                                         state <= '1';
37                                 end if;
38                                 usb_write <= state;
39                         end if;
40                 end if;
41         end if;
42         
43 end process;
44
45 usb_fifo_addr <= "10"; -- ep6
46 usb_data <= switch;
47 usb_cs <= '0';
48 usb_pktend <= '1';
49 led <= switch;
50
51 end Behavioral;
52