forked from gatecat/CSI2Rx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David Shah <[email protected]>
- Loading branch information
Showing
5 changed files
with
145 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.blif | ||
*.json | ||
*.asc | ||
*.bin | ||
*.rpt | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
SOURCES = $(wildcard ../../csi/*.v ../../phy/*.v ../../link/*.v top.v) | ||
PROJ=camera | ||
PIN_DEF=icecam.pcf | ||
DEVICE=up5k | ||
|
||
all: $(PROJ).rpt $(PROJ).bin | ||
|
||
%.blif: $(SOURCES) | ||
yosys -p 'synth_ice40 -top top -blif $@' $(SOURCES) | ||
|
||
%.asc: $(PIN_DEF) %.blif | ||
arachne-pnr -d 5k -o $@ -p $^ | ||
|
||
%.bin: %.asc | ||
icepack $< $@ | ||
|
||
%.rpt: %.asc | ||
icetime -d $(DEVICE) -mtr $@ $< | ||
|
||
prog: $(PROJ).bin | ||
iceprog $< | ||
|
||
sudo-prog: $(PROJ).bin | ||
@echo 'Executing prog as root!!!' | ||
sudo iceprog $< | ||
|
||
clean: | ||
rm -f $(PROJ).blif $(PROJ).asc $(PROJ).rpt $(PROJ).bin | ||
|
||
.SECONDARY: | ||
.PHONY: all prog clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
set_io mpsse_sda 6 #FTDI D0 | ||
set_io mpsse_scl 9 #FTDI D1 | ||
|
||
set_io cam_enable 3 #P1A7 | ||
set_io cam_sda 34 #P1B3 | ||
set_io cam_scl 28 #P1B10 | ||
|
||
set_io dphy_clk 32 #P1B9 | ||
set_io dphy_data[0] 42 #P1B7 | ||
set_io dphy_data[1] 43 #P1B1 | ||
set_io dphy_lp 48 #P1A8 | ||
|
||
set_io BTN_N 10 | ||
set_io LEDR_N 11 | ||
set_io LEDG_N 37 | ||
|
||
set_io LED2 27 | ||
set_io LED3 25 | ||
set_io LED5 21 | ||
set_io BTN2 19 | ||
set_io LED1 26 | ||
set_io LED4 23 | ||
set_io BTN1 20 | ||
set_io BTN3 18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* The MIT License | ||
* Copyright (c) 2018 David Shah | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
module top(input mpsse_sda, mpsse_scl, inout cam_sda, cam_scl, output cam_enable, | ||
input dphy_clk, input [1:0] dphy_data, input dphy_lp, | ||
output LEDR_N, LEDG_N, LED1, LED2, LED3, LED4, LED5, | ||
input BTN_N, BTN1, BTN2, BTN3); | ||
|
||
wire areset = !BTN_N; | ||
assign cam_scl = mpsse_scl ? 1'bz : 1'b0; | ||
assign cam_sda = mpsse_sda ? 1'bz : 1'b0; | ||
assign cam_enable = 1'b1; | ||
wire sys_clk; | ||
wire in_line, in_frame; | ||
wire [31:0] payload_data; | ||
wire payload_valid; | ||
|
||
csi_rx_ice40 #( | ||
.LANES(2), // lane count | ||
.PAIRSWAP(2'b10), // lane pair swap (inverts data for given lane) | ||
|
||
.VC(2'b00), // MIPI CSI-2 "virtual channel" | ||
.FS_DT(6'h00), // Frame start data type | ||
.FE_DT(6'h00), // Frame end data type | ||
.VIDEO_DT(6'h2A), // Video payload data type (6'h2A = 8-bit raw, 6'h2B = 10-bit raw, 6'h2C = 12-bit raw) | ||
.MAX_LEN(8192) // Max expected packet len, used as timeout | ||
) csi_rx_i ( | ||
.dphy_clk_lane(dphy_clk), | ||
.dphy_data_lane(dphy_data), | ||
.dphy_lp_sense(dphy_lp), | ||
|
||
.areset(areset), | ||
|
||
.word_clk(sys_clk), | ||
.payload_data(payload_data), | ||
.payload_enable(payload_valid), | ||
.payload_frame(), | ||
|
||
.vsync(), | ||
.in_line(in_line), | ||
.in_frame(in_frame) | ||
); | ||
|
||
|
||
reg [22:0] sclk_div; | ||
always @(posedge sys_clk) | ||
sclk_div <= sclk_div + 1'b1; | ||
|
||
assign {LEDR_N, LEDG_N} = ~(sclk_div[22:21]); | ||
assign LED1 = in_frame; | ||
assign LED2 = !in_frame; | ||
assign {LED5, LED4, LED3} = payload_valid ? payload_data[7:5] : 3'b000; | ||
endmodule |