Skip to content

Commit

Permalink
gateware: add R3.3 touch sensing support (#54)
Browse files Browse the repository at this point in the history
Clean up and bring the following changes to master:

* gateware/i2c_master: support builds with + without touch scanning
* gateware/cal: forward touch0-7 over debug uart to cal tool for debugging
* cores/touch_cv: add a simple example of controlling CV outputs with touch

example build:
```
$ make BOARD=icebreaker CORE=touch_cv HW_REV=HW_R33 TOUCH=TOUCH_SENSE_ENABLED prog
```

Users must build cores that use touch scanning with  `TOUCH=TOUCH_SENSE_ENABLED` otherwise the interface will wire all touch sense lines to zero
  • Loading branch information
vk2seb authored Mar 14, 2024
1 parent 6cb043b commit 668931a
Show file tree
Hide file tree
Showing 15 changed files with 791 additions and 74 deletions.
53 changes: 33 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ jobs:
ubuntu-build-icebreaker-r31:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: YosysHQ/setup-oss-cad-suite@v2
- uses: actions/checkout@v4
- uses: YosysHQ/setup-oss-cad-suite@v3
- run: git submodule update --init gateware/external/no2misc
- run: yosys --version
- run: make HW_REV=HW_R31 BOARD=icebreaker CORE=mirror -C gateware
Expand All @@ -19,8 +19,8 @@ jobs:
ubuntu-build-icebreaker-r33:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: YosysHQ/setup-oss-cad-suite@v2
- uses: actions/checkout@v4
- uses: YosysHQ/setup-oss-cad-suite@v3
- run: git submodule update --init gateware/external/no2misc
- run: yosys --version
- run: make HW_REV=HW_R33 BOARD=icebreaker CORE=mirror -C gateware
Expand All @@ -29,6 +29,19 @@ jobs:
name: ubuntu-build-icebreaker.bin
path: gateware/build/icebreaker/top.bin

ubuntu-build-icebreaker-r33-touch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: YosysHQ/setup-oss-cad-suite@v3
- run: git submodule update --init gateware/external/no2misc
- run: yosys --version
- run: make HW_REV=HW_R33 BOARD=icebreaker CORE=touch_cv TOUCH=TOUCH_SENSE_ENABLED -C gateware
- uses: actions/upload-artifact@v3
with:
name: ubuntu-build-icebreaker.bin
path: gateware/build/icebreaker/top.bin

windows-build-icebreaker:
runs-on: windows-latest
defaults:
Expand All @@ -40,8 +53,8 @@ jobs:
install: >-
git
make
- uses: actions/checkout@v3
- uses: YosysHQ/setup-oss-cad-suite@v2
- uses: actions/checkout@v4
- uses: YosysHQ/setup-oss-cad-suite@v3
- run: git submodule update --init gateware/external/no2misc
- run: |
export PATH=$PATH:$RUNNER_TEMP/oss-cad-suite/bin
Expand All @@ -56,8 +69,8 @@ jobs:
macos-build-icebreaker:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: YosysHQ/setup-oss-cad-suite@v2
- uses: actions/checkout@v4
- uses: YosysHQ/setup-oss-cad-suite@v3
- run: git submodule update --init gateware/external/no2misc
- run: |
yosys --version
Expand All @@ -70,8 +83,8 @@ jobs:
ubuntu-build-colorlight-i5:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: YosysHQ/setup-oss-cad-suite@v2
- uses: actions/checkout@v4
- uses: YosysHQ/setup-oss-cad-suite@v3
- run: git submodule update --init gateware/external/no2misc
- run: yosys --version
- run: make HW_REV=HW_R33 BOARD=colorlight_i5 CORE=mirror -C gateware
Expand All @@ -83,8 +96,8 @@ jobs:
ubuntu-build-colorlight-i9:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: YosysHQ/setup-oss-cad-suite@v2
- uses: actions/checkout@v4
- uses: YosysHQ/setup-oss-cad-suite@v3
- run: git submodule update --init gateware/external/no2misc
- run: yosys --version
- run: make HW_REV=HW_R33 BOARD=colorlight_i9 CORE=mirror -C gateware
Expand All @@ -96,8 +109,8 @@ jobs:
ubuntu-build-ecpix-5:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: YosysHQ/setup-oss-cad-suite@v2
- uses: actions/checkout@v4
- uses: YosysHQ/setup-oss-cad-suite@v3
- run: git submodule update --init gateware/external/no2misc
- run: yosys --version
- run: make HW_REV=HW_R33 BOARD=ecpix5 CORE=mirror -C gateware
Expand All @@ -109,8 +122,8 @@ jobs:
ubuntu-build-pico-ice:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: YosysHQ/setup-oss-cad-suite@v2
- uses: actions/checkout@v4
- uses: YosysHQ/setup-oss-cad-suite@v3
- run: git submodule update --init gateware/external/no2misc
- run: yosys --version
- run: make HW_REV=HW_R33 BOARD=pico_ice CORE=mirror -C gateware
Expand All @@ -122,17 +135,17 @@ jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: YosysHQ/setup-oss-cad-suite@v2
- uses: actions/checkout@v4
- uses: YosysHQ/setup-oss-cad-suite@v3
- run: git submodule update --init gateware/external/no2misc
- run: cocotb-config -v
- run: cd gateware/sim && ./00_run.sh

run-linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: YosysHQ/setup-oss-cad-suite@v2
- uses: actions/checkout@v4
- uses: YosysHQ/setup-oss-cad-suite@v3
- run: git submodule update --init gateware/external/no2misc
- run: verilator --version
- run: cd gateware && scripts/verilator_lint.sh
5 changes: 4 additions & 1 deletion gateware/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
ALL_BOARDS = $(shell ls boards)
ALL_CORES = $(shell basename --suffix=.sv -- cores/*.sv)
ALL_HW_REV = "HW_R31 HW_R33"
ALL_TOUCH = "TOUCH_SENSE_DISABLED TOUCH_SENSE_ENABLED"

CORE ?= mirror
TOUCH ?= TOUCH_SENSE_DISABLED

all prog:
ifeq ($(BOARD),)
@echo "Valid HW_REV values are: $(ALL_HW_REV)".
@echo "Valid BOARD values are: $(ALL_BOARDS)".
@echo "Valid CORE values are: $(ALL_CORES)".
@echo "Valid TOUCH values are: $(ALL_TOUCH) (default disabled, valid for R3.3+ only, required for any examples that use touch)".
@echo "For example:"
@echo " $$ make clean"
@echo " $$ # Build bitstream with specific core and program it"
Expand All @@ -33,7 +36,7 @@ endif
mkdir -p build/$(BOARD)
# For now we always force a re-build since we can pass different DSP cores
# through environment vars and we need a re-build to happen in this case.
$(MAKE) -B -f boards/$(BOARD)/Makefile BUILD=build/$(BOARD) CORE=$(CORE) $(MAKECMDGOALS)
$(MAKE) -B -f boards/$(BOARD)/Makefile BUILD=build/$(BOARD) CORE=$(CORE) TOUCH=$(TOUCH) $(MAKECMDGOALS)

clean:
rm -rf build/
Expand Down
10 changes: 9 additions & 1 deletion gateware/cal/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,17 @@ def run_calibration(self):
"eeprom_dev": raw[3],
"eeprom_serial": int.from_bytes(raw[4:8], "big"),
"jack": raw[8],
"touch0": raw[9],
"touch1": raw[10],
"touch2": raw[11],
"touch3": raw[12],
"touch4": raw[13],
"touch5": raw[14],
"touch6": raw[15],
"touch7": raw[16],
}
[print(k, hex(v)) for k, v in values.items()]
self._decode_raw_samples(raw[9:])
self._decode_raw_samples(raw[17:])
self._handle_user_input()
self._calculate_calibration_strings()
time.sleep(0.1)
Expand Down
50 changes: 33 additions & 17 deletions gateware/cal/debug_uart.sv
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ module debug_uart #(
input [7:0] eeprom_dev,
input [31:0] eeprom_serial,
input [7:0] jack,
input [7:0] touch0,
input [7:0] touch1,
input [7:0] touch2,
input [7:0] touch3,
input [7:0] touch4,
input [7:0] touch5,
input [7:0] touch6,
input [7:0] touch7,
input signed [W-1:0] adc0,
input signed [W-1:0] adc1,
input signed [W-1:0] adc2,
Expand Down Expand Up @@ -70,31 +78,39 @@ always_ff @(posedge clk) begin
6: dout <= eeprom_serial[32-2*8-1:32-3*8];
7: dout <= eeprom_serial[32-3*8-1: 0];
8: dout <= jack;
9: dout <= touch0;
10: dout <= touch1;
11: dout <= touch2;
12: dout <= touch3;
13: dout <= touch4;
14: dout <= touch5;
15: dout <= touch6;
16: dout <= touch7;
// Channel 0
9: dout <= adc0_ex[WM -1:WM-1*8];
10: dout <= adc0_ex[WM-1*8-1:WM-2*8];
11: dout <= adc0_ex[WM-2*8-1:WM-3*8];
12: dout <= adc0_ex[WM-3*8-1: 0];
17: dout <= adc0_ex[WM -1:WM-1*8];
18: dout <= adc0_ex[WM-1*8-1:WM-2*8];
19: dout <= adc0_ex[WM-2*8-1:WM-3*8];
20: dout <= adc0_ex[WM-3*8-1: 0];
// Channel 1
13: dout <= adc1_ex[WM -1:WM-1*8];
14: dout <= adc1_ex[WM-1*8-1:WM-2*8];
15: dout <= adc1_ex[WM-2*8-1:WM-3*8];
16: dout <= adc1_ex[WM-3*8-1: 0];
21: dout <= adc1_ex[WM -1:WM-1*8];
22: dout <= adc1_ex[WM-1*8-1:WM-2*8];
23: dout <= adc1_ex[WM-2*8-1:WM-3*8];
24: dout <= adc1_ex[WM-3*8-1: 0];
// Channel 2
17: dout <= adc2_ex[WM -1:WM-1*8];
18: dout <= adc2_ex[WM-1*8-1:WM-2*8];
19: dout <= adc2_ex[WM-2*8-1:WM-3*8];
20: dout <= adc2_ex[WM-3*8-1: 0];
25: dout <= adc2_ex[WM -1:WM-1*8];
26: dout <= adc2_ex[WM-1*8-1:WM-2*8];
27: dout <= adc2_ex[WM-2*8-1:WM-3*8];
28: dout <= adc2_ex[WM-3*8-1: 0];
// Channel 3
21: dout <= adc3_ex[WM -1:WM-1*8];
22: dout <= adc3_ex[WM-1*8-1:WM-2*8];
23: dout <= adc3_ex[WM-2*8-1:WM-3*8];
24: dout <= adc3_ex[WM-3*8-1: 0];
29: dout <= adc3_ex[WM -1:WM-1*8];
30: dout <= adc3_ex[WM-1*8-1:WM-2*8];
31: dout <= adc3_ex[WM-2*8-1:WM-3*8];
32: dout <= adc3_ex[WM-3*8-1: 0];
default: begin
// Should never get here
end
endcase
if (state != 24) state <= state + 1;
if (state != 32) state <= state + 1;
else state <= 0;
end
end
Expand Down
43 changes: 43 additions & 0 deletions gateware/cores/touch_cv.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Touch-to-CV. Touches on input jacks 1-4 are
// translated into CV outputs on outputs 1-4.
//
// When building with touch sensing, be sure to build with
// TOUCH=TOUCH_SENSE_ENABLED, for example:
//
// $ make CORE=touch_cv HW_REV=HW_R33 TOUCH=TOUCH_SENSE_ENABLED
//

`default_nettype none

module touch_cv #(
parameter W = 16
)(
input rst,
input clk,
input sample_clk,
input signed [W-1:0] sample_in0,
input signed [W-1:0] sample_in1,
input signed [W-1:0] sample_in2,
input signed [W-1:0] sample_in3,
output signed [W-1:0] sample_out0,
output signed [W-1:0] sample_out1,
output signed [W-1:0] sample_out2,
output signed [W-1:0] sample_out3,
input [7:0] jack,
input [7:0] touch0,
input [7:0] touch1,
input [7:0] touch2,
input [7:0] touch3,
input [7:0] touch4,
input [7:0] touch5,
input [7:0] touch6,
input [7:0] touch7
);

assign sample_out0 = W'(touch0) <<< (W-10);
assign sample_out1 = W'(touch1) <<< (W-10);
assign sample_out2 = W'(touch2) <<< (W-10);
assign sample_out3 = W'(touch3) <<< (W-10);

endmodule
Loading

0 comments on commit 668931a

Please sign in to comment.