X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Ffpga.git;a=blobdiff_plain;f=switch2usb%2Fs2usb.vhd;fp=switch2usb%2Fs2usb.vhd;h=5b80e44a1b7822802cedcd82cf14f37efc51520c;hp=0000000000000000000000000000000000000000;hb=a62a3973f707bfef2a906f6477403ad95c6090df;hpb=428f6220f2ed679f658e077d8c30cc29958e1f26 diff --git a/switch2usb/s2usb.vhd b/switch2usb/s2usb.vhd new file mode 100644 index 0000000..5b80e44 --- /dev/null +++ b/switch2usb/s2usb.vhd @@ -0,0 +1,52 @@ +library IEEE; +use IEEE.STD_LOGIC_1164.ALL; +use IEEE.STD_LOGIC_ARITH.ALL; +use IEEE.STD_LOGIC_UNSIGNED.ALL; + +entity s2usb is + Port ( switch : in STD_LOGIC_VECTOR (7 downto 0); + -- button : in STD_LOGIC; + clock : in STD_LOGIC; + usb_full : in STD_LOGIC; + usb_data : out STD_LOGIC_VECTOR (7 downto 0); + usb_fifo_addr : out STD_LOGIC_VECTOR (1 downto 0); + usb_write : out STD_LOGIC; + usb_pktend : out STD_LOGIC; + usb_cs : out STD_LOGIC; + led : out std_logic_vector(7 downto 0)); +end s2usb; + +architecture Behavioral of s2usb is + +signal prescaler : std_logic_vector(2 downto 0) := "000"; +signal state : std_logic := '1'; + +begin + +usb_send : process(clock) +begin + + if(clock'event) and (clock='1') then + prescaler <= prescaler + 1; + if(prescaler="000") then + if(usb_full='1') then + if(state='1') then + state <= '0'; + elsif(state='0') then + state <= '1'; + end if; + usb_write <= state; + end if; + end if; + end if; + +end process; + +usb_fifo_addr <= "10"; -- ep6 +usb_data <= switch; +usb_cs <= '0'; +usb_pktend <= '1'; +led <= switch; + +end Behavioral; +