Skip to content

Commit

Permalink
begin plumbing keypad I2C #798
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Gardner-Stephen committed Apr 4, 2024
1 parent 4d4be3b commit be8dbda
Show file tree
Hide file tree
Showing 6 changed files with 433 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/tools/i2cstatemapper.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <stdio.h>

// #define MEGAPHONER1
#define MEGA65R2
#define KEYPAD

struct entry {
int addr;
Expand All @@ -18,6 +17,17 @@ struct entry e[] = {
// The IO expanders can only be read one register pair at a time,
// so we have to schedule multiple jobs.

#ifdef KEYPAD
{ 0x40, 0x00, 0x07, 0x00, "IO Expander #0" },
{ 0x42, 0x00, 0x07, 0x08, "IO Expander #1" },
{ 0x44, 0x00, 0x07, 0x10, "IO Expander #2" },
{ 0x46, 0x00, 0x07, 0x18, "IO Expander #3" },
{ 0x48, 0x00, 0x07, 0x20, "IO Expander #4" },
{ 0x4a, 0x00, 0x07, 0x28, "IO Expander #5" },
{ 0x4c, 0x00, 0x07, 0x30, "IO Expander #6" },
{ 0x4e, 0x00, 0x07, 0x38, "IO Expander #7" },
#endif

#ifdef MEGAPHONER1
// First IO expander
{ 0x72, 0x00, 0x01, 0x00, "IO Expander #0 regs 0-1" }, { 0x72, 0x02, 0x03, 0x02, "IO Expander #0 regs 2-3" },
Expand Down
31 changes: 31 additions & 0 deletions src/vhdl/iomapper.vhdl
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ entity iomapper is

i2c1SDA : inout std_logic := '0';
i2c1SCL : inout std_logic := '0';

keypadSDA : inout std_logic := '0';
keypadSCL : inout std_logic := '0';

grove_sda : inout std_logic;
grove_scl : inout std_logic;
Expand Down Expand Up @@ -479,6 +482,7 @@ architecture behavioral of iomapper is
signal cia2cs : std_logic;

signal i2cperipherals_cs : std_logic;
signal i2ckeypad_cs : std_logic;
signal i2chdmi_cs : std_logic;
signal grove_cs : std_logic;
signal sectorbuffercs : std_logic;
Expand Down Expand Up @@ -1416,6 +1420,25 @@ begin
);
end generate i2cperiph_megaphone;

i2cperiph_keypad:
if target = nexys4 generate
i2c1: entity work.keypad_i2c
generic map ( clock_frequency => cpu_frequency)
port map (
clock => cpuclock,

cs => i2ckeypad_cs,

fastio_addr => unsigned(address),
fastio_write => w,
fastio_read => r,
fastio_wdata => unsigned(data_i),

sda => keypad_sda,
scl => keypad_scl

);

i2cperiph_mega65r5_specific:
if target = mega65r5 or target = mega65r6 generate
i2c1: entity work.mega65r5_board_i2c
Expand Down Expand Up @@ -2125,6 +2148,7 @@ begin
end if;

-- @IO:GS $FFD7x00-xFF - I2C Peripherals for various targets
i2ckeypad_cs <= '0';
i2cperipherals_cs <= '0';
i2chdmi_cs <= '0';
grove_cs <= '0';
Expand Down Expand Up @@ -2161,6 +2185,13 @@ begin
end if;
end if;

if (target = nexys4) then
if address(19 downto 8) = x"D75" then
i2ckeypad_cs <= '1';
report "i2ckeypad_cs asserted";
end if;
end if;

cs_driveram <= '0';
cs_driverom <= '0';
if address(19 downto 16) = x"C" then
Expand Down
Loading

0 comments on commit be8dbda

Please sign in to comment.