library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity second_digit is
    generic (CYCLES_PER_SECOND : positive := 50000000);
    port (CLOCK_50 : in std_logic;
          SW : in std_logic_vector(9 downto 0);
          HEX0 : out std_logic_vector(6 downto 0));
end entity;

architecture rtl of second_digit is
    signal interval : unsigned(25 downto 0);
    signal digit : unsigned(3 downto 0);
    signal controls_meta, controls : std_logic_vector(1 downto 0);
begin
    process(CLOCK_50)
    begin
        if rising_edge(CLOCK_50) then
            controls_meta <= SW(9 downto 8);
            controls <= controls_meta;
            if controls(0) = '1' then
                interval <= (others => '0');
                digit <= (others => '0');
            elsif controls(1) = '0' then
                -- TODO: count CLOCK_50 edges, emit one tick and wrap 9 to 0.
                interval <= interval;
                digit <= digit;
            end if;
        end if;
    end process;
    with to_integer(digit) select HEX0 <=
        "1000000" when 0,
        "1111001" when 1,
        "0100100" when 2,
        "0110000" when 3,
        "0011001" when 4,
        "0010010" when 5,
        "0000010" when 6,
        "1111000" when 7,
        "0000000" when 8,
        "0010000" when 9,
        "1111111" when others;
end architecture;
