Skip to content

Commit

Permalink
m2m_keyb.vhd: Beautify
Browse files Browse the repository at this point in the history
  • Loading branch information
MJoergen committed Nov 13, 2024
1 parent aa8c36b commit 844c843
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 108 deletions.
2 changes: 1 addition & 1 deletion M2M/MEGA65-R3.xdc
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ resize_pblock pblock_MAX10 -add {SLICE_X0Y150:SLICE_X7Y174}

# Place Keyboard close to I/O pins
create_pblock pblock_m65driver
add_cells_to_pblock pblock_m65driver [get_cells [list framework_inst/m2m_keyb_inst/m65driver]]
add_cells_to_pblock pblock_m65driver [get_cells [list framework_inst/m2m_keyb_inst/mega65kbd_to_matrix_inst]]
resize_pblock pblock_m65driver -add {SLICE_X0Y225:SLICE_X7Y243}

# Place SD card controller in the middle between the left and right FPGA boundary because the output ports are at the opposide edges
Expand Down
2 changes: 1 addition & 1 deletion M2M/MEGA65-R4.xdc
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ set_property -dict {PULLUP FALSE SLEW FAST DRIVE 16} [get_ports {sdram_*}];

# Place Keyboard close to I/O pins
create_pblock pblock_m65driver
add_cells_to_pblock pblock_m65driver [get_cells [list framework_inst/m2m_keyb_inst/m65driver]]
add_cells_to_pblock pblock_m65driver [get_cells [list framework_inst/m2m_keyb_inst/mega65kbd_to_matrix_inst]]
resize_pblock pblock_m65driver -add {SLICE_X0Y225:SLICE_X7Y243}

# Place SD card controller in the middle between the left and right FPGA boundary because the output ports are at the opposide edges
Expand Down
2 changes: 1 addition & 1 deletion M2M/MEGA65-R5.xdc
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ set_property -dict {PULLUP FALSE SLEW FAST DRIVE 16} [get_ports {sdram_*}];

# Place Keyboard close to I/O pins
create_pblock pblock_m65driver
add_cells_to_pblock pblock_m65driver [get_cells [list framework_inst/m2m_keyb_inst/m65driver]]
add_cells_to_pblock pblock_m65driver [get_cells [list framework_inst/m2m_keyb_inst/mega65kbd_to_matrix_inst]]
resize_pblock pblock_m65driver -add {SLICE_X0Y225:SLICE_X7Y243}

# Place SD card controller in the middle between the left and right FPGA boundary because the output ports are at the opposide edges
Expand Down
2 changes: 1 addition & 1 deletion M2M/MEGA65-R6.xdc
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ set_property -dict {PULLUP FALSE SLEW FAST DRIVE 16} [get_ports {sdram_*}];

# Place Keyboard close to I/O pins
create_pblock pblock_m65driver
add_cells_to_pblock pblock_m65driver [get_cells [list framework_inst/m2m_keyb_inst/m65driver]]
add_cells_to_pblock pblock_m65driver [get_cells [list framework_inst/m2m_keyb_inst/mega65kbd_to_matrix_inst]]
resize_pblock pblock_m65driver -add {SLICE_X0Y225:SLICE_X7Y243}

# Place SD card controller in the middle between the left and right FPGA boundary because the output ports are at the opposide edges
Expand Down
210 changes: 106 additions & 104 deletions M2M/vhdl/m2m_keyb.vhd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
----------------------------------------------------------------------------------
-- MiSTer2MEGA65 Framework
-- MiSTer2MEGA65 Framework
--
-- MEGA65 keyboard controller
--
Expand All @@ -19,132 +19,134 @@
-- MiSTer2MEGA65 done by sy2002 and MJoergen in 2022 and licensed under GPL v3
----------------------------------------------------------------------------------

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity m2m_keyb is
generic (
SCAN_FREQUENCY : integer := 1000 -- keyboard scan frequency in Herz, default: 1 kHz
G_SCAN_FREQUENCY : integer := 1000 -- keyboard scan frequency in Hz, default: 1 kHz
);
port (
clk_main_i : in std_logic; -- core clock
clk_main_speed_i : in natural; -- speed of core clock in Hz
-- interface to the MEGA65 keyboard controller
kio8_o : out std_logic; -- clock to keyboard
kio9_o : out std_logic; -- data output to keyboard
kio10_i : in std_logic; -- data input from keyboard
clk_main_i : in std_logic; -- core clock
clk_main_speed_i : in natural; -- speed of core clock in Hz

-- interface to the MEGA65 keyboard controller
kio8_o : out std_logic; -- clock to keyboard
kio9_o : out std_logic; -- data output to keyboard
kio10_i : in std_logic; -- data input from keyboard

-- interface to the core
enable_core_i : in std_logic; -- 0 = core is decoupled from the keyboard, 1 = standard operation
key_num_o : out integer range 0 to 79; -- cycles through all keys with SCAN_FREQUENCY
key_pressed_n_o : out std_logic; -- low active: debounced feedback: is kb_key_num_o pressed right now?
enable_core_i : in std_logic; -- 0 = core is decoupled from the keyboard, 1 = standard operation
key_num_o : out integer range 0 to 79; -- cycles through all keys with G_SCAN_FREQUENCY
key_pressed_n_o : out std_logic; -- low active: debounced feedback: is kb_key_num_o pressed right now?

-- control the drive led on the MEGA65 keyboard
power_led_i : in std_logic;
power_led_col_i : in std_logic_vector(23 downto 0); -- RGB color of power led
drive_led_i : in std_logic;
drive_led_col_i : in std_logic_vector(23 downto 0); -- RGB color of drive led
power_led_i : in std_logic;
power_led_col_i : in std_logic_vector(23 downto 0); -- RGB color of power led
drive_led_i : in std_logic;
drive_led_col_i : in std_logic_vector(23 downto 0); -- RGB color of drive led

-- interface to QNICE: used by the firmware and the Shell (see sysdef.asm for details)
qnice_keys_n_o : out std_logic_vector(15 downto 0)
qnice_keys_n_o : out std_logic_vector(15 downto 0)
);
end m2m_keyb;
end entity m2m_keyb;

architecture beh of m2m_keyb is
architecture synthesis of m2m_keyb is

signal matrix_col : std_logic_vector(7 downto 0);
signal matrix_col_idx : integer range 0 to 9 := 0;
signal key_num : integer range 0 to 79;
signal key_status_n : std_logic;
signal keys_n : std_logic_vector(15 downto 0) := x"FFFF"; -- low active, "no key pressed"
signal matrix_col : std_logic_vector(7 downto 0);
signal matrix_col_idx : integer range 0 to 9 := 0;
signal key_num : integer range 0 to 79;
signal key_status_n : std_logic;
signal keys_n : std_logic_vector(15 downto 0) := x"FFFF"; -- low active, "no key pressed"

begin

-- output the keyboard interface for the core
key_num_o <= key_num;
key_pressed_n_o <= key_status_n when enable_core_i else '1';

key_num_o <= key_num;
key_pressed_n_o <= key_status_n when enable_core_i else
'1';

-- output the keyboard interface for QNICE
qnice_keys_n_o <= keys_n;

m65driver : entity work.mega65kbd_to_matrix
port map
(
ioclock => clk_main_i,
clock_frequency => clk_main_speed_i,

-- _steady means that the led stays on steadily
-- _blinking means that the led is blinking
-- The colors are specified as BGR (reverse RGB)
powerled_steady => power_led_i,
powerled_col => power_led_col_i(7 downto 0) & power_led_col_i(15 downto 8) & power_led_col_i(23 downto 16), -- RGB to BGR
driveled_steady => drive_led_i,
driveled_blinking => '0',
driveled_col => drive_led_col_i(7 downto 0) & drive_led_col_i(15 downto 8) & drive_led_col_i(23 downto 16), -- RGB to BGR

kio8 => kio8_o,
kio9 => kio9_o,
kio10 => kio10_i,

matrix_col => matrix_col,
matrix_col_idx => matrix_col_idx,

capslock_out => open
);

m65matrix_to_keynum : entity work.matrix_to_keynum
generic map
(
scan_frequency => SCAN_FREQUENCY
)
port map
(
clk => clk_main_i,
clock_frequency => clk_main_speed_i,
reset_in => '0',

matrix_col => matrix_col,
matrix_col_idx => matrix_col_idx,

m65_key_num => key_num,
m65_key_status_n => key_status_n,

suppress_key_glitches => '1',
suppress_key_retrigger => '0',

bucky_key => open
);

matrix_col_idx_handler : process(clk_main_i)
qnice_keys_n_o <= keys_n;

mega65kbd_to_matrix_inst : entity work.mega65kbd_to_matrix
port map (
ioclock => clk_main_i,
clock_frequency => clk_main_speed_i,

-- _steady means that the led stays on steadily
-- _blinking means that the led is blinking
-- The colors are specified as BGR (reverse RGB)
powerled_steady => power_led_i,
powerled_col => power_led_col_i(7 downto 0) & power_led_col_i(15 downto 8) & power_led_col_i(23 downto 16), -- RGB to BGR
driveled_steady => drive_led_i,
driveled_blinking => '0',
driveled_col => drive_led_col_i(7 downto 0) & drive_led_col_i(15 downto 8) & drive_led_col_i(23 downto 16), -- RGB to BGR

kio8 => kio8_o,
kio9 => kio9_o,
kio10 => kio10_i,

matrix_col => matrix_col,
matrix_col_idx => matrix_col_idx,

capslock_out => open
); -- mega65kbd_to_matrix_inst

matrix_to_keynum_inst : entity work.matrix_to_keynum
generic map (
SCAN_FREQUENCY => G_SCAN_FREQUENCY
)
port map (
clk => clk_main_i,
clock_frequency => clk_main_speed_i,
reset_in => '0',

matrix_col => matrix_col,
matrix_col_idx => matrix_col_idx,

m65_key_num => key_num,
m65_key_status_n => key_status_n,

suppress_key_glitches => '1',
suppress_key_retrigger => '0',

bucky_key => open
); -- matrix_to_keynum_ins

matrix_col_idx_proc : process (clk_main_i)
begin
if rising_edge(clk_main_i) then
if matrix_col_idx < 9 then
matrix_col_idx <= matrix_col_idx + 1;
matrix_col_idx <= matrix_col_idx + 1;
else
matrix_col_idx <= 0;
end if;
matrix_col_idx <= 0;
end if;
end if;
end process;
end process matrix_col_idx_proc;

-- make qnice_keys_o a register and fill it
-- see sysdef.asm for the key-to-bit mapping
handle_qnice_keys : process(clk_main_i)
-- see sysdef.asm for the key-to-bit mapping
keys_n_proc : process (clk_main_i)
begin
if rising_edge(clk_main_i) then
if rising_edge(clk_main_i) then
case key_num is
when 73 => keys_n(0) <= key_status_n; -- Cursor up
when 7 => keys_n(1) <= key_status_n; -- Cursor down
when 74 => keys_n(2) <= key_status_n; -- Cursor left
when 2 => keys_n(3) <= key_status_n; -- Cursor right
when 1 => keys_n(4) <= key_status_n; -- Return
when 60 => keys_n(5) <= key_status_n; -- Space
when 63 => keys_n(6) <= key_status_n; -- Run/Stop
when 67 => keys_n(7) <= key_status_n; -- Help
when 4 => keys_n(8) <= key_status_n; -- F1
when 5 => keys_n(9) <= key_status_n; -- F3
when others => null;
when 73 => keys_n(0) <= key_status_n; -- Cursor up
when 7 => keys_n(1) <= key_status_n; -- Cursor down
when 74 => keys_n(2) <= key_status_n; -- Cursor left
when 2 => keys_n(3) <= key_status_n; -- Cursor right
when 1 => keys_n(4) <= key_status_n; -- Return
when 60 => keys_n(5) <= key_status_n; -- Space
when 63 => keys_n(6) <= key_status_n; -- Run/Stop
when 67 => keys_n(7) <= key_status_n; -- Help
when 4 => keys_n(8) <= key_status_n; -- F1
when 5 => keys_n(9) <= key_status_n; -- F3
when others =>
null;
end case;
end if;
end process;
end beh;
end process keys_n_proc;

end architecture synthesis;

0 comments on commit 844c843

Please sign in to comment.