Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------------------------
- -- Company:
- -- Engineer:
- --
- -- Create Date: 14:06:57 01/27/2020
- -- Design Name:
- -- Module Name: bitmap - Behavioral
- -- Project Name:
- -- Target Devices:
- -- Tool versions:
- -- Description:
- --
- -- Dependencies:
- --
- -- Revision:
- -- Revision 0.01 - File Created
- -- Additional Comments:
- --
- ----------------------------------------------------------------------------------
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- use IEEE.STD_LOGIC_ARITH.ALL;
- use IEEE.STD_LOGIC_UNSIGNED.ALL;
- ---- Uncomment the following library declaration if instantiating
- ---- any Xilinx primitives in this code.
- --library UNISIM;
- --use UNISIM.VComponents.all;
- entity bitmap is
- Port ( SYS_CLK : in STD_LOGIC; --Horloge du gestionnaire de la souris
- DATA : in STD_LOGIC; --Données de la souris
- X : out STD_LOGIC_VECTOR (7 downto 0); --Déplacement de la souris
- Y : out STD_LOGIC_VECTOR (7 downto 0); --Déplacement de la souris
- CLK : in STD_LOGIC; --Horloge de la souris
- COLOR : out STD_LOGIC_VECTOR (1 downto 0); --Définie si on est en écriture/suppression ou rien du tout
- W : out STD_LOGIC); --Verifier que tout est valide
- end bitmap;
- architecture Behavioral of bitmap is
- --Signaux intérmédiaires que l'on va utiliser:
- signal XX : STD_LOGIC_VECTOR (7 downto 0);
- signal YY : STD_LOGIC_VECTOR (7 downto 0);
- signal CCOLOR : STD_LOGIC_VECTOR (1 downto 0);
- signal dirX, dirY : STD_LOGIC;
- signal prevState : STD_LOGIC :='0';
- signal WW : STD_LOGIC :='0';
- signal Err : STD_LOGIC :='0';
- --Déclaration des états
- type sysState is (waitingControl, control, waitingMovX, movX, waitingMovY, movY, endState);
- signal actualState : sysState := waitingControl;
- signal positionCounter : integer range 0 to 9;
- begin
- process(SYS_CLK)
- variable i : integer := 0;
- variable Xcomp : STD_LOGIC_VECTOR (7 downto 0) := "00000000";
- variable Ycomp : STD_LOGIC_VECTOR (7 downto 0) := "00000000";
- begin
- if(rising_edge(SYS_CLK)) then
- if(WW = '1' and Err = '0') then
- --Ecriture de la couleur
- COLOR <= CCOLOR;
- --Calcul de X
- Xcomp := XX;
- if(Xcomp(7)='1')then
- Xcomp(6 downto 0) := "1111111";
- end if;
- Xcomp(7) := '0';
- if(dirX = '0') then
- Xcomp := not Xcomp;
- Xcomp := Xcomp + "00000001";
- end if;
- --Calcul de Y
- Ycomp := YY;
- if(Ycomp(7)='1')then
- Ycomp(6 downto 0) := "1111111";
- end if;
- Ycomp(7) := '0';
- if(dirY = '0') then
- Ycomp := not Ycomp;
- Ycomp := Ycomp + "00000001";
- end if;
- --Ecriture de X et de Y et indication de W
- Y<=Ycomp;
- X<=Xcomp;
- W<='1';
- else
- --Reinitialisation de W
- W<='0';
- end if;
- end if;
- end process;
- --Conversion des datas lignes en data colonnes pour les variables temporaires
- process(CLK)
- variable parity : STD_LOGIC;
- begin
- --Detection du front montant de l'horloge
- if(rising_edge(CLK)) then
- --Détection du bit de start et changement d'état
- if(prevState = '1' and DATA='0') then
- if(actualState=waitingControl) then
- CCOLOR<="00";
- actualState<=control;
- positionCounter <= 1;
- elsif(actualState=waitingMovX) then
- actualState<=movX;
- positionCounter <= 1;
- elsif(actualState=waitingMovY) then
- actualState<=movY;
- positionCounter <= 1;
- end if;
- elsif(DATA = '1') then
- prevState<='1';
- end if;
- --Raz
- if(actualState=endState) then
- actualState<=waitingControl;
- Err<='0';
- WW <= '0';
- end if;
- --Cas de la lecture des boutons de la souris
- if(actualState = control) then
- case(positionCounter) is
- when 0 =>
- when 1 =>
- if(DATA='1') then
- CCOLOR <="11";
- end if;
- parity:=DATA;
- when 2 =>
- if(CCOLOR = "11") then
- else
- if(DATA = '1') then
- CCOLOR <= "10";
- else
- CCOLOR <= "00";
- end if;
- end if;
- parity:=parity xor DATA;
- when 3 => parity:=parity xor DATA;
- when 4 => parity:=parity xor DATA;
- when 5 =>
- if(DATA = '1') then
- dirX<='1';
- else
- dirX<='0';
- end if;
- parity:=parity xor DATA;
- when 6 =>
- if(DATA = '1') then
- dirY<='1';
- else
- dirY<='0';
- end if;
- parity:=parity xor DATA;
- when 7 => parity:=parity xor DATA;
- when 8 => parity:=parity xor DATA;
- when 9 =>
- parity :=parity xor DATA;
- if(parity = '0') then
- Err<='1';
- end if;
- actualState<=waitingMovX;
- prevState<='0';
- end case;
- --Cas du déplacement de la souris dans l'axe X
- elsif(actualState = movX) then
- if(positionCounter >= 1 and positionCounter <=8) then
- XX(positionCounter-1)<=DATA;
- if(positionCounter = 1) then
- parity:= DATA;
- else
- parity := parity xor DATA;
- end if;
- elsif(positionCounter = 9) then
- parity:= parity xor DATA;
- if(parity = '0') then
- Err<='1';
- end if;
- actualState<=waitingMovY;
- prevState<='0';
- end if;
- --Cas du déplacement de la souris dans l'axe Y
- elsif(actualState = movY) then
- if(positionCounter >= 1 and positionCounter <=8) then
- YY(positionCounter-1)<=DATA;
- if(positionCounter = 1) then
- parity:= DATA;
- else
- parity := parity xor DATA;
- end if;
- elsif(positionCounter = 9) then
- parity:= parity xor DATA;
- if(parity = '0') then
- Err<='1';
- end if;
- actualState<=endState;
- prevState<='0';
- WW <= '1';
- end if;
- end if;
- --Incrémentation du compteur
- if(actualState = control or actualState = movX or actualState = movY) then
- if(positionCounter<9) then
- positionCounter <= positionCounter+1;
- else
- positionCounter<=0;
- end if;
- end if;
- end if;
- end process;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement