Skip to content

Commit

Permalink
works nicely with 8-bit exported difference counts
Browse files Browse the repository at this point in the history
  • Loading branch information
vk2seb committed Oct 25, 2023
1 parent cea5422 commit fc866df
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 62 deletions.
2 changes: 1 addition & 1 deletion gateware/boards/icebreaker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ADD_SRC = boards/icebreaker/sysmgr.v \
$(SRC_COMMON)

prog: $(BUILD)/$(PROJ).bin
iceprog $(BUILD)/$(PROJ).bin
sudo iceprog $(BUILD)/$(PROJ).bin
122 changes: 84 additions & 38 deletions gateware/drivers/pmod_i2c_master.sv
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ module pmod_i2c_master #(
input signed [7:0] led6,
input signed [7:0] led7,

output logic [7:0] touch0,
output logic [7:0] touch1,
output logic [7:0] touch2,
output logic [7:0] touch3,
output logic [7:0] touch4,
output logic [7:0] touch5,
output logic [7:0] touch6,
output logic [7:0] touch7,

// Jack detection outputs, 1 == inserted. (bit 0 is input 0, bit 4 is output 0).
output logic [7:0] jack,

Expand All @@ -57,12 +66,12 @@ module pmod_i2c_master #(
localparam I2C_DELAY1 = 0,
I2C_EEPROM1 = 1,
I2C_EEPROM2 = 2,
I2C_INIT_CODEC1 = 3,
I2C_INIT_CODEC2 = 4,
I2C_INIT_TOUCH1 = 5,
I2C_INIT_TOUCH2 = 6,
I2C_INIT_TOUCH3 = 7,
I2C_INIT_TOUCH4 = 8,
I2C_INIT_TOUCH1 = 3,
I2C_INIT_TOUCH2 = 4,
I2C_INIT_TOUCH3 = 5,
I2C_INIT_TOUCH4 = 6,
I2C_INIT_CODEC1 = 7,
I2C_INIT_CODEC2 = 8,
I2C_LED1 = 9, // <<--\ LED/JACK/TOUCH re-runs indefinitely.
I2C_LED2 = 10, // |
I2C_JACK1 = 11, // |
Expand Down Expand Up @@ -112,6 +121,8 @@ logic ready;
// Used for startup delay.
logic [23:0] delay_cnt;

logic [2:0] nsensor;

always_ff @(posedge clk) begin
if (rst) begin
i2c_state <= I2C_DELAY1;
Expand Down Expand Up @@ -173,26 +184,6 @@ always_ff @(posedge clk) begin
i2c_config_pos <= i2c_config_pos + 1;
stb <= 1'b1;
end
I2C_INIT_CODEC1: begin
cmd <= I2CMASTER_START;
stb <= 1'b1;
i2c_state <= I2C_INIT_CODEC2;
i2c_config_pos <= 0;
end
I2C_INIT_CODEC2: begin
// Shift out all bytes in the CODEC configuration in
// one long transaction until we are finished.
if (i2c_config_pos != CODEC_CFG_BYTES) begin
data_in <= codec_config[5'(i2c_config_pos)];
cmd <= I2CMASTER_WRITE;
i2c_config_pos <= i2c_config_pos + 1;
end else begin
cmd <= I2CMASTER_STOP;
i2c_state <= I2C_LED1;
end
ack_in <= 1'b1;
stb <= 1'b1;
end
I2C_INIT_TOUCH1: begin
cmd <= I2CMASTER_START;
stb <= 1'b1;
Expand Down Expand Up @@ -311,9 +302,16 @@ always_ff @(posedge clk) begin
cmd <= I2CMASTER_WRITE;
end
10: begin
// Command register
data_in <= 8'h86;
cmd <= I2CMASTER_WRITE;
if (ack_out) begin
// Wait until ack succeeds before continuing
i2c_state <= I2C_INIT_TOUCH3;
cmd <= I2CMASTER_STOP;
end else begin
// Only issue reset if we got acknowledged
// Command register
data_in <= 8'h86;
cmd <= I2CMASTER_WRITE;
end
end
11: begin
// NVM write & reset command.
Expand All @@ -329,6 +327,26 @@ always_ff @(posedge clk) begin
ack_in <= 1'b1;
stb <= 1'b1;
end
I2C_INIT_CODEC1: begin
cmd <= I2CMASTER_START;
stb <= 1'b1;
i2c_state <= I2C_INIT_CODEC2;
i2c_config_pos <= 0;
end
I2C_INIT_CODEC2: begin
// Shift out all bytes in the CODEC configuration in
// one long transaction until we are finished.
if (i2c_config_pos != CODEC_CFG_BYTES) begin
data_in <= codec_config[5'(i2c_config_pos)];
cmd <= I2CMASTER_WRITE;
i2c_config_pos <= i2c_config_pos + 1;
end else begin
cmd <= I2CMASTER_STOP;
i2c_state <= I2C_LED1;
end
ack_in <= 1'b1;
stb <= 1'b1;
end
I2C_LED1: begin
cmd <= I2CMASTER_START;
stb <= 1'b1;
Expand Down Expand Up @@ -406,14 +424,19 @@ always_ff @(posedge clk) begin
data_in <= 8'h31;
cmd <= I2CMASTER_WRITE;
end
9: cmd <= I2CMASTER_READ;

9: begin
if (ack_out == 1'b0) begin
cmd <= I2CMASTER_READ;
end else begin
cmd <= I2CMASTER_STOP;
i2c_state <= I2C_TOUCH5;
end
end
// 4) Save the result.
10: begin
//jack <= data_out;
jack <= data_out;
cmd <= I2CMASTER_STOP;
i2c_state <= I2C_TOUCH5;
delay_cnt <= 0;
end
default: begin
// do nothing
Expand All @@ -435,7 +458,19 @@ always_ff @(posedge clk) begin
data_in <= 8'h6E;
cmd <= I2CMASTER_WRITE;
end
2: data_in <= 8'hAA;
// Sensor 0 difference counts
2: begin
case (nsensor)
0: data_in <= 8'hBA;
1: data_in <= 8'hBC;
2: data_in <= 8'hBE;
3: data_in <= 8'hC0;
4: data_in <= 8'hC2;
5: data_in <= 8'hC4;
6: data_in <= 8'hC6;
7: data_in <= 8'hC8;
endcase
end
3: cmd <= I2CMASTER_STOP;

// Read out the data
Expand All @@ -446,20 +481,31 @@ always_ff @(posedge clk) begin
end
6: begin
if (ack_out == 1'b1) begin
i2c_state <= I2C_LED1;
i2c_state <= I2C_TOUCH5;
cmd <= I2CMASTER_STOP;
end else begin
cmd <= I2CMASTER_READ;
ack_in <= 1'b0;
end
end
default: begin
jack <= data_out;
7: begin
case (nsensor)
0: touch0 <= data_out;
1: touch1 <= data_out;
2: touch2 <= data_out;
3: touch3 <= data_out;
4: touch4 <= data_out;
5: touch5 <= data_out;
6: touch6 <= data_out;
7: touch7 <= data_out;
endcase
ack_in <= 1'b1;
cmd <= I2CMASTER_STOP;
i2c_state <= I2C_LED1;
nsensor <= nsensor + 1;
end
endcase
i2c_config_pos <= i2c_config_pos + 1;
ack_in <= 1'b1;
stb <= 1'b1;
end
default: begin
Expand Down
18 changes: 9 additions & 9 deletions gateware/drivers/touch-cfg.hex
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ ff
00
00
04
9f
00
00
00
00
00
B2
94
94
00
00
00
Expand Down Expand Up @@ -77,9 +77,9 @@ ff
00
00
10
03
01
40
00
00
00
00
37
06
Expand Down Expand Up @@ -126,5 +126,5 @@ ff
00
00
00
e3
3d
52
8f
17 changes: 13 additions & 4 deletions gateware/drivers/touch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,23 @@ def CY8CMBR3xxx_CalculateCrc(configuration):

with open("touch-cfg.hex", "r") as f:
xs = []
ix = 0
for line in f.readlines():
raw = line.strip()
v = int(raw, 16)
print("hex", raw, "int", v)
if ix >= 2:
print("reg", hex(ix-2), "hex", raw, "int", v)
else:
print("hex", raw, "int", v)
xs.append(v)
ix += 1
print("total bytes in file", len(xs))
xs = xs[2:-2]
print("bytes to crc", len(xs))
crc = CY8CMBR3xxx_CalculateCrc(xs)
xs_crc = xs[2:-2]
print("bytes to crc", len(xs_crc))
crc = CY8CMBR3xxx_CalculateCrc(xs_crc)
print("crc0", hex(crc & 0x00FF))
print("crc1", hex((crc & 0xFF00)>>8))
if xs[-2] == crc & 0x00FF and xs[-1] == ((crc & 0xFF00) >> 8):
print("CRC OK")
else:
print("CRC NOT OK")
36 changes: 26 additions & 10 deletions gateware/eurorack_pmod.sv
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ ak4619 ak4619_instance (
.sample_in3 (force_dac_output == 0 ? sample_dac3 : force_dac_output)
);

logic [7:0] touch0;
logic [7:0] touch1;
logic [7:0] touch2;
logic [7:0] touch3;
logic [7:0] touch4;
logic [7:0] touch5;
logic [7:0] touch6;
logic [7:0] touch7;

// I2C transceiver and driver for all connected slaves.
pmod_i2c_master #(
.CODEC_CFG(CODEC_CFG_FILE),
Expand All @@ -136,16 +145,23 @@ pmod_i2c_master #(
.sda_oe(i2c_sda_oe),
.sda_i(i2c_sda_i),

// LEDs directly linked to input/output sample values
// for now, although they could do whatever we want.
.led0({jack[0], 5'b00000}),
.led1({jack[1], 5'b00000}),
.led2({jack[2], 5'b00000}),
.led3({jack[3], 5'b00000}),
.led4({jack[4], 5'b00000}),
.led5({jack[5], 5'b00000}),
.led6({jack[6], 5'b00000}),
.led7({jack[7], 5'b00000}),
.led0(touch0>>1),
.led1(touch1>>1),
.led2(touch2>>1),
.led3(touch3>>1),
.led4(touch4>>1),
.led5(touch5>>1),
.led6(touch6>>1),
.led7(touch7>>1),

.touch0(touch0),
.touch1(touch1),
.touch2(touch2),
.touch3(touch3),
.touch4(touch4),
.touch5(touch5),
.touch6(touch6),
.touch7(touch7),

.jack(jack),

Expand Down

0 comments on commit fc866df

Please sign in to comment.