SAIFIINDUSTRIES commited on
Commit
0086871
·
verified ·
1 Parent(s): d79380c

Add Repo: Lichee-Pi_Tang_FPGA_Examples

Browse files
Files changed (34) hide show
  1. Lichee-Pi_Tang_FPGA_Examples/0.LED/src/led.v +46 -0
  2. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_fifo.v +59 -0
  3. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_fifo_sim.v +283 -0
  4. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_pll.v +85 -0
  5. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_pll_sim.v +111 -0
  6. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_ram.v +71 -0
  7. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_ram_sim.v +0 -0
  8. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_rom.v +60 -0
  9. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_rom_sim.v +0 -0
  10. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_sdram.v +44 -0
  11. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/cameraReader.v +91 -0
  12. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/lcd_sync.v +137 -0
  13. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/sccb_v1/camera_init.v +444 -0
  14. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/sccb_v1/i2c_module.v +1069 -0
  15. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/sccb_v2/I2C_Interface.v +175 -0
  16. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/sccb_v2/OV7670_Controller.v +68 -0
  17. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/sccb_v2/OV7670_Registers.v +260 -0
  18. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/test_cmera.v +145 -0
  19. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/Imagedata_send.v +11 -0
  20. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/UartTx.v +82 -0
  21. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/big_lcd.v +80 -0
  22. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/cameraReader.v +93 -0
  23. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/div_2.v +12 -0
  24. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/sdram_ctrl.v +405 -0
  25. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/spi_slave.v +161 -0
  26. Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/top.v +117 -0
  27. Lichee-Pi_Tang_FPGA_Examples/2.LCD/Imagedata_send.v +100 -0
  28. Lichee-Pi_Tang_FPGA_Examples/2.LCD/al_ip/ip_pll.v +75 -0
  29. Lichee-Pi_Tang_FPGA_Examples/2.LCD/al_ip/ip_pll_sim.v +112 -0
  30. Lichee-Pi_Tang_FPGA_Examples/2.LCD/data_out.v +92 -0
  31. Lichee-Pi_Tang_FPGA_Examples/2.LCD/lcd_sync.v +139 -0
  32. Lichee-Pi_Tang_FPGA_Examples/2.LCD/test_lcd.sdc +6 -0
  33. Lichee-Pi_Tang_FPGA_Examples/2.LCD/test_lcd.v +68 -0
  34. Lichee-Pi_Tang_FPGA_Examples/README.md +8 -0
Lichee-Pi_Tang_FPGA_Examples/0.LED/src/led.v ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module led
2
+ (
3
+ input wire CLK_IN,
4
+ input wire RST_N,
5
+ output wire [2:0]RGB_LED
6
+ );
7
+
8
+ parameter time1 = 25'd24_000_000;//¾§ÕñΪ24Mhz
9
+
10
+ reg [2:0]rledout;
11
+ reg [24:0] count;
12
+ reg [1:0]shift_cnt;
13
+
14
+ initial
15
+ begin
16
+ count=25'b0;
17
+ rledout=3'b1;
18
+ shift_cnt=2'b0;
19
+ end
20
+
21
+ always @(posedge CLK_IN)begin
22
+ if(RST_N==0)begin
23
+ count <= 25'b0;
24
+ rledout <= 3'b1;
25
+ shift_cnt <=2'b0;
26
+ end
27
+
28
+ if(count == time1)
29
+ begin
30
+ count<= 25'd0;
31
+
32
+ if(shift_cnt==2'b10)begin
33
+ rledout <= 3'b1;
34
+ shift_cnt <=2'b0;
35
+ end
36
+ else begin
37
+ rledout <= {rledout[1:0],1'b0};
38
+ shift_cnt <= shift_cnt + 1'b1;
39
+ end
40
+ end
41
+ else
42
+ count <= count + 1'b1;
43
+ end
44
+
45
+ assign RGB_LED = rledout;
46
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_fifo.v ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /************************************************************\
2
+ ** Copyright (c) 2011-2021 Anlogic, Inc.
3
+ ** All Right Reserved.
4
+ \************************************************************/
5
+ /************************************************************\
6
+ ** Log : This file is generated by Anlogic IP Generator.
7
+ ** File : H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/al_ip/ip_fifo.v
8
+ ** Date : 2018 07 25
9
+ ** TD version : 4.2.217
10
+ \************************************************************/
11
+
12
+ `timescale 1ns / 1ps
13
+
14
+ module img_fifo (
15
+ rst,
16
+ di, clkw, we,
17
+ do, clkr, re,
18
+ empty_flag,
19
+ full_flag
20
+ );
21
+
22
+ input rst;
23
+ input [7:0] di;
24
+ input clkw, we;
25
+ input clkr,re;
26
+
27
+ output [15:0] do;
28
+ output empty_flag;
29
+ output full_flag;
30
+
31
+ EG_LOGIC_FIFO #(
32
+ .DATA_WIDTH_W(8),
33
+ .DATA_WIDTH_R(16),
34
+ .DATA_DEPTH_W(8192),
35
+ .DATA_DEPTH_R(4096),
36
+ .ENDIAN("BIG"),
37
+ .RESETMODE("ASYNC"),
38
+ .E(0),
39
+ .F(8192),
40
+ .ASYNC_RESET_RELEASE("SYNC"))
41
+ logic_fifo(
42
+ .rst(rst),
43
+ .di(di),
44
+ .clkw(clkw),
45
+ .we(we),
46
+ .csw(3'b111),
47
+ .do(do),
48
+ .clkr(clkr),
49
+ .re(re),
50
+ .csr(3'b111),
51
+ .ore(1'b0),
52
+ .empty_flag(empty_flag),
53
+ .aempty_flag(),
54
+ .full_flag(full_flag),
55
+ .afull_flag()
56
+
57
+ );
58
+
59
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_fifo_sim.v ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Verilog netlist created by TD v4.2.217
2
+ // Wed Jul 25 09:49:21 2018
3
+
4
+ `timescale 1ns / 1ps
5
+ module img_fifo // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/al_ip/ip_fifo.v(14)
6
+ (
7
+ clkr,
8
+ clkw,
9
+ di,
10
+ re,
11
+ rst,
12
+ we,
13
+ do,
14
+ empty_flag,
15
+ full_flag
16
+ );
17
+
18
+ input clkr; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/al_ip/ip_fifo.v(25)
19
+ input clkw; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/al_ip/ip_fifo.v(24)
20
+ input [7:0] di; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/al_ip/ip_fifo.v(23)
21
+ input re; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/al_ip/ip_fifo.v(25)
22
+ input rst; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/al_ip/ip_fifo.v(22)
23
+ input we; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/al_ip/ip_fifo.v(24)
24
+ output [15:0] do; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/al_ip/ip_fifo.v(27)
25
+ output empty_flag; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/al_ip/ip_fifo.v(28)
26
+ output full_flag; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/al_ip/ip_fifo.v(29)
27
+
28
+ wire empty_flag_neg;
29
+ wire full_flag_neg;
30
+
31
+ EG_PHY_CONFIG #(
32
+ .DONE_PERSISTN("ENABLE"),
33
+ .INIT_PERSISTN("ENABLE"),
34
+ .JTAG_PERSISTN("DISABLE"),
35
+ .PROGRAMN_PERSISTN("DISABLE"))
36
+ config_inst ();
37
+ not empty_flag_inv (empty_flag_neg, empty_flag);
38
+ not full_flag_inv (full_flag_neg, full_flag);
39
+ EG_PHY_FIFO #(
40
+ .AE(32'b00000000000000000000000000001101),
41
+ .AEP1(32'b00000000000000000000000000001111),
42
+ .AF(32'b00000000000000000001111111111010),
43
+ .AFM1(32'b00000000000000000001111111111001),
44
+ .ASYNC_RESET_RELEASE("SYNC"),
45
+ .DATA_WIDTH_A("1"),
46
+ .DATA_WIDTH_B("2"),
47
+ .E(32'b00000000000000000000000000000001),
48
+ .EP1(32'b00000000000000000000000000000011),
49
+ .F(32'b00000000000000000010000000000000),
50
+ .FM1(32'b00000000000000000001111111111111),
51
+ .GSR("DISABLE"),
52
+ .MODE("FIFO8K"),
53
+ .REGMODE_A("NOREG"),
54
+ .REGMODE_B("NOREG"),
55
+ .RESETMODE("ASYNC"))
56
+ logic_fifo_0 (
57
+ .clkr(clkr),
58
+ .clkw(clkw),
59
+ .csr({2'b11,empty_flag_neg}),
60
+ .csw({2'b11,full_flag_neg}),
61
+ .dia({open_n47,open_n48,open_n49,open_n50,open_n51,open_n52,open_n53,di[0],open_n54}),
62
+ .orea(1'b0),
63
+ .oreb(1'b0),
64
+ .re(re),
65
+ .rprst(rst),
66
+ .rst(rst),
67
+ .we(we),
68
+ .dob({open_n75,open_n76,open_n77,open_n78,open_n79,open_n80,open_n81,do[0],do[8]}),
69
+ .empty_flag(empty_flag),
70
+ .full_flag(full_flag));
71
+ EG_PHY_FIFO #(
72
+ .AE(32'b00000000000000000000000000001101),
73
+ .AEP1(32'b00000000000000000000000000001111),
74
+ .AF(32'b00000000000000000001111111111010),
75
+ .AFM1(32'b00000000000000000001111111111001),
76
+ .ASYNC_RESET_RELEASE("SYNC"),
77
+ .DATA_WIDTH_A("1"),
78
+ .DATA_WIDTH_B("2"),
79
+ .E(32'b00000000000000000000000000000001),
80
+ .EP1(32'b00000000000000000000000000000011),
81
+ .F(32'b00000000000000000010000000000000),
82
+ .FM1(32'b00000000000000000001111111111111),
83
+ .GSR("DISABLE"),
84
+ .MODE("FIFO8K"),
85
+ .REGMODE_A("NOREG"),
86
+ .REGMODE_B("NOREG"),
87
+ .RESETMODE("ASYNC"))
88
+ logic_fifo_1 (
89
+ .clkr(clkr),
90
+ .clkw(clkw),
91
+ .csr({2'b11,empty_flag_neg}),
92
+ .csw({2'b11,full_flag_neg}),
93
+ .dia({open_n82,open_n83,open_n84,open_n85,open_n86,open_n87,open_n88,di[1],open_n89}),
94
+ .orea(1'b0),
95
+ .oreb(1'b0),
96
+ .re(re),
97
+ .rprst(rst),
98
+ .rst(rst),
99
+ .we(we),
100
+ .dob({open_n110,open_n111,open_n112,open_n113,open_n114,open_n115,open_n116,do[1],do[9]}));
101
+ EG_PHY_FIFO #(
102
+ .AE(32'b00000000000000000000000000001101),
103
+ .AEP1(32'b00000000000000000000000000001111),
104
+ .AF(32'b00000000000000000001111111111010),
105
+ .AFM1(32'b00000000000000000001111111111001),
106
+ .ASYNC_RESET_RELEASE("SYNC"),
107
+ .DATA_WIDTH_A("1"),
108
+ .DATA_WIDTH_B("2"),
109
+ .E(32'b00000000000000000000000000000001),
110
+ .EP1(32'b00000000000000000000000000000011),
111
+ .F(32'b00000000000000000010000000000000),
112
+ .FM1(32'b00000000000000000001111111111111),
113
+ .GSR("DISABLE"),
114
+ .MODE("FIFO8K"),
115
+ .REGMODE_A("NOREG"),
116
+ .REGMODE_B("NOREG"),
117
+ .RESETMODE("ASYNC"))
118
+ logic_fifo_2 (
119
+ .clkr(clkr),
120
+ .clkw(clkw),
121
+ .csr({2'b11,empty_flag_neg}),
122
+ .csw({2'b11,full_flag_neg}),
123
+ .dia({open_n119,open_n120,open_n121,open_n122,open_n123,open_n124,open_n125,di[2],open_n126}),
124
+ .orea(1'b0),
125
+ .oreb(1'b0),
126
+ .re(re),
127
+ .rprst(rst),
128
+ .rst(rst),
129
+ .we(we),
130
+ .dob({open_n147,open_n148,open_n149,open_n150,open_n151,open_n152,open_n153,do[2],do[10]}));
131
+ EG_PHY_FIFO #(
132
+ .AE(32'b00000000000000000000000000001101),
133
+ .AEP1(32'b00000000000000000000000000001111),
134
+ .AF(32'b00000000000000000001111111111010),
135
+ .AFM1(32'b00000000000000000001111111111001),
136
+ .ASYNC_RESET_RELEASE("SYNC"),
137
+ .DATA_WIDTH_A("1"),
138
+ .DATA_WIDTH_B("2"),
139
+ .E(32'b00000000000000000000000000000001),
140
+ .EP1(32'b00000000000000000000000000000011),
141
+ .F(32'b00000000000000000010000000000000),
142
+ .FM1(32'b00000000000000000001111111111111),
143
+ .GSR("DISABLE"),
144
+ .MODE("FIFO8K"),
145
+ .REGMODE_A("NOREG"),
146
+ .REGMODE_B("NOREG"),
147
+ .RESETMODE("ASYNC"))
148
+ logic_fifo_3 (
149
+ .clkr(clkr),
150
+ .clkw(clkw),
151
+ .csr({2'b11,empty_flag_neg}),
152
+ .csw({2'b11,full_flag_neg}),
153
+ .dia({open_n156,open_n157,open_n158,open_n159,open_n160,open_n161,open_n162,di[3],open_n163}),
154
+ .orea(1'b0),
155
+ .oreb(1'b0),
156
+ .re(re),
157
+ .rprst(rst),
158
+ .rst(rst),
159
+ .we(we),
160
+ .dob({open_n184,open_n185,open_n186,open_n187,open_n188,open_n189,open_n190,do[3],do[11]}));
161
+ EG_PHY_FIFO #(
162
+ .AE(32'b00000000000000000000000000001101),
163
+ .AEP1(32'b00000000000000000000000000001111),
164
+ .AF(32'b00000000000000000001111111111010),
165
+ .AFM1(32'b00000000000000000001111111111001),
166
+ .ASYNC_RESET_RELEASE("SYNC"),
167
+ .DATA_WIDTH_A("1"),
168
+ .DATA_WIDTH_B("2"),
169
+ .E(32'b00000000000000000000000000000001),
170
+ .EP1(32'b00000000000000000000000000000011),
171
+ .F(32'b00000000000000000010000000000000),
172
+ .FM1(32'b00000000000000000001111111111111),
173
+ .GSR("DISABLE"),
174
+ .MODE("FIFO8K"),
175
+ .REGMODE_A("NOREG"),
176
+ .REGMODE_B("NOREG"),
177
+ .RESETMODE("ASYNC"))
178
+ logic_fifo_4 (
179
+ .clkr(clkr),
180
+ .clkw(clkw),
181
+ .csr({2'b11,empty_flag_neg}),
182
+ .csw({2'b11,full_flag_neg}),
183
+ .dia({open_n193,open_n194,open_n195,open_n196,open_n197,open_n198,open_n199,di[4],open_n200}),
184
+ .orea(1'b0),
185
+ .oreb(1'b0),
186
+ .re(re),
187
+ .rprst(rst),
188
+ .rst(rst),
189
+ .we(we),
190
+ .dob({open_n221,open_n222,open_n223,open_n224,open_n225,open_n226,open_n227,do[4],do[12]}));
191
+ EG_PHY_FIFO #(
192
+ .AE(32'b00000000000000000000000000001101),
193
+ .AEP1(32'b00000000000000000000000000001111),
194
+ .AF(32'b00000000000000000001111111111010),
195
+ .AFM1(32'b00000000000000000001111111111001),
196
+ .ASYNC_RESET_RELEASE("SYNC"),
197
+ .DATA_WIDTH_A("1"),
198
+ .DATA_WIDTH_B("2"),
199
+ .E(32'b00000000000000000000000000000001),
200
+ .EP1(32'b00000000000000000000000000000011),
201
+ .F(32'b00000000000000000010000000000000),
202
+ .FM1(32'b00000000000000000001111111111111),
203
+ .GSR("DISABLE"),
204
+ .MODE("FIFO8K"),
205
+ .REGMODE_A("NOREG"),
206
+ .REGMODE_B("NOREG"),
207
+ .RESETMODE("ASYNC"))
208
+ logic_fifo_5 (
209
+ .clkr(clkr),
210
+ .clkw(clkw),
211
+ .csr({2'b11,empty_flag_neg}),
212
+ .csw({2'b11,full_flag_neg}),
213
+ .dia({open_n230,open_n231,open_n232,open_n233,open_n234,open_n235,open_n236,di[5],open_n237}),
214
+ .orea(1'b0),
215
+ .oreb(1'b0),
216
+ .re(re),
217
+ .rprst(rst),
218
+ .rst(rst),
219
+ .we(we),
220
+ .dob({open_n258,open_n259,open_n260,open_n261,open_n262,open_n263,open_n264,do[5],do[13]}));
221
+ EG_PHY_FIFO #(
222
+ .AE(32'b00000000000000000000000000001101),
223
+ .AEP1(32'b00000000000000000000000000001111),
224
+ .AF(32'b00000000000000000001111111111010),
225
+ .AFM1(32'b00000000000000000001111111111001),
226
+ .ASYNC_RESET_RELEASE("SYNC"),
227
+ .DATA_WIDTH_A("1"),
228
+ .DATA_WIDTH_B("2"),
229
+ .E(32'b00000000000000000000000000000001),
230
+ .EP1(32'b00000000000000000000000000000011),
231
+ .F(32'b00000000000000000010000000000000),
232
+ .FM1(32'b00000000000000000001111111111111),
233
+ .GSR("DISABLE"),
234
+ .MODE("FIFO8K"),
235
+ .REGMODE_A("NOREG"),
236
+ .REGMODE_B("NOREG"),
237
+ .RESETMODE("ASYNC"))
238
+ logic_fifo_6 (
239
+ .clkr(clkr),
240
+ .clkw(clkw),
241
+ .csr({2'b11,empty_flag_neg}),
242
+ .csw({2'b11,full_flag_neg}),
243
+ .dia({open_n267,open_n268,open_n269,open_n270,open_n271,open_n272,open_n273,di[6],open_n274}),
244
+ .orea(1'b0),
245
+ .oreb(1'b0),
246
+ .re(re),
247
+ .rprst(rst),
248
+ .rst(rst),
249
+ .we(we),
250
+ .dob({open_n295,open_n296,open_n297,open_n298,open_n299,open_n300,open_n301,do[6],do[14]}));
251
+ EG_PHY_FIFO #(
252
+ .AE(32'b00000000000000000000000000001101),
253
+ .AEP1(32'b00000000000000000000000000001111),
254
+ .AF(32'b00000000000000000001111111111010),
255
+ .AFM1(32'b00000000000000000001111111111001),
256
+ .ASYNC_RESET_RELEASE("SYNC"),
257
+ .DATA_WIDTH_A("1"),
258
+ .DATA_WIDTH_B("2"),
259
+ .E(32'b00000000000000000000000000000001),
260
+ .EP1(32'b00000000000000000000000000000011),
261
+ .F(32'b00000000000000000010000000000000),
262
+ .FM1(32'b00000000000000000001111111111111),
263
+ .GSR("DISABLE"),
264
+ .MODE("FIFO8K"),
265
+ .REGMODE_A("NOREG"),
266
+ .REGMODE_B("NOREG"),
267
+ .RESETMODE("ASYNC"))
268
+ logic_fifo_7 (
269
+ .clkr(clkr),
270
+ .clkw(clkw),
271
+ .csr({2'b11,empty_flag_neg}),
272
+ .csw({2'b11,full_flag_neg}),
273
+ .dia({open_n304,open_n305,open_n306,open_n307,open_n308,open_n309,open_n310,di[7],open_n311}),
274
+ .orea(1'b0),
275
+ .oreb(1'b0),
276
+ .re(re),
277
+ .rprst(rst),
278
+ .rst(rst),
279
+ .we(we),
280
+ .dob({open_n332,open_n333,open_n334,open_n335,open_n336,open_n337,open_n338,do[7],do[15]}));
281
+
282
+ endmodule
283
+
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_pll.v ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /************************************************************\
2
+ ** Copyright (c) 2011-2021 Anlogic, Inc.
3
+ ** All Right Reserved.
4
+ \************************************************************/
5
+ /************************************************************\
6
+ ** Log : This file is generated by Anlogic IP Generator.
7
+ ** File : H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/project/al_ip/ip_pll.v
8
+ ** Date : 2018 08 10
9
+ ** TD version : 4.2.217
10
+ \************************************************************/
11
+
12
+ ///////////////////////////////////////////////////////////////////////////////
13
+ // Input frequency: 24.000Mhz
14
+ // Clock multiplication factor: 7
15
+ // Clock division factor: 5
16
+ // Clock information:
17
+ // Clock name | Frequency | Phase shift
18
+ // C0 | 33.600 MHZ | 0 DEG
19
+ // C1 | 12.062 MHZ | 0 DEG
20
+ // C2 | 4.021 MHZ | 0 DEG
21
+ ///////////////////////////////////////////////////////////////////////////////
22
+ `timescale 1 ns / 100 fs
23
+
24
+ module ip_pll(refclk,
25
+ clk0_out,
26
+ clk1_out,
27
+ clk2_out);
28
+
29
+ input refclk;
30
+ output clk0_out;
31
+ output clk1_out;
32
+ output clk2_out;
33
+
34
+ wire clk0_buf;
35
+
36
+ EG_LOGIC_BUFG bufg_feedback( .i(clk0_buf), .o(clk0_out) );
37
+
38
+ EG_PHY_PLL #(.DPHASE_SOURCE("DISABLE"),
39
+ .DYNCFG("DISABLE"),
40
+ .FIN("24.000"),
41
+ .FEEDBK_MODE("NORMAL"),
42
+ .FEEDBK_PATH("CLKC0_EXT"),
43
+ .STDBY_ENABLE("DISABLE"),
44
+ .PLLRST_ENA("DISABLE"),
45
+ .SYNC_ENABLE("DISABLE"),
46
+ .DERIVE_PLL_CLOCKS("DISABLE"),
47
+ .GEN_BASIC_CLOCK("DISABLE"),
48
+ .GMC_GAIN(6),
49
+ .ICP_CURRENT(3),
50
+ .KVCO(6),
51
+ .LPF_CAPACITOR(3),
52
+ .LPF_RESISTOR(2),
53
+ .REFCLK_DIV(5),
54
+ .FBCLK_DIV(7),
55
+ .CLKC0_ENABLE("ENABLE"),
56
+ .CLKC0_DIV(14),
57
+ .CLKC0_CPHASE(14),
58
+ .CLKC0_FPHASE(0),
59
+ .CLKC1_ENABLE("ENABLE"),
60
+ .CLKC1_DIV(39),
61
+ .CLKC1_CPHASE(39),
62
+ .CLKC1_FPHASE(0),
63
+ .CLKC2_ENABLE("ENABLE"),
64
+ .CLKC2_DIV(117),
65
+ .CLKC2_CPHASE(117),
66
+ .CLKC2_FPHASE(0) )
67
+ pll_inst (.refclk(refclk),
68
+ .reset(1'b0),
69
+ .stdby(1'b0),
70
+ .extlock(open),
71
+ .psclk(1'b0),
72
+ .psdown(1'b0),
73
+ .psstep(1'b0),
74
+ .psclksel(3'b000),
75
+ .psdone(open),
76
+ .dclk(1'b0),
77
+ .dcs(1'b0),
78
+ .dwe(1'b0),
79
+ .di(8'b00000000),
80
+ .daddr(6'b000000),
81
+ .do({open, open, open, open, open, open, open, open}),
82
+ .fbclk(clk0_out),
83
+ .clkc({open, open, clk2_out, clk1_out, clk0_buf}));
84
+
85
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_pll_sim.v ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Verilog netlist created by TD v4.2.217
2
+ // Fri Aug 10 17:39:33 2018
3
+
4
+ `timescale 1ns / 1ps
5
+ module ip_pll // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/project/al_ip/ip_pll.v(24)
6
+ (
7
+ refclk,
8
+ clk0_out,
9
+ clk1_out,
10
+ clk2_out
11
+ );
12
+
13
+ input refclk; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/project/al_ip/ip_pll.v(29)
14
+ output clk0_out; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/project/al_ip/ip_pll.v(30)
15
+ output clk1_out; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/project/al_ip/ip_pll.v(31)
16
+ output clk2_out; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/project/al_ip/ip_pll.v(32)
17
+
18
+ wire clk0_buf; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/project/al_ip/ip_pll.v(34)
19
+
20
+ EG_PHY_GCLK bufg_feedback (
21
+ .clki(clk0_buf),
22
+ .clko(clk0_out)); // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/project/al_ip/ip_pll.v(36)
23
+ EG_PHY_CONFIG #(
24
+ .DONE_PERSISTN("ENABLE"),
25
+ .INIT_PERSISTN("ENABLE"),
26
+ .JTAG_PERSISTN("DISABLE"),
27
+ .PROGRAMN_PERSISTN("DISABLE"))
28
+ config_inst ();
29
+ EG_PHY_PLL #(
30
+ .CLKC0_CPHASE(14),
31
+ .CLKC0_DIV(14),
32
+ .CLKC0_DIV2_ENABLE("DISABLE"),
33
+ .CLKC0_ENABLE("ENABLE"),
34
+ .CLKC0_FPHASE(0),
35
+ .CLKC1_CPHASE(39),
36
+ .CLKC1_DIV(39),
37
+ .CLKC1_DIV2_ENABLE("DISABLE"),
38
+ .CLKC1_ENABLE("ENABLE"),
39
+ .CLKC1_FPHASE(0),
40
+ .CLKC2_CPHASE(117),
41
+ .CLKC2_DIV(117),
42
+ .CLKC2_DIV2_ENABLE("DISABLE"),
43
+ .CLKC2_ENABLE("ENABLE"),
44
+ .CLKC2_FPHASE(0),
45
+ .CLKC3_CPHASE(1),
46
+ .CLKC3_DIV(1),
47
+ .CLKC3_DIV2_ENABLE("DISABLE"),
48
+ .CLKC3_ENABLE("DISABLE"),
49
+ .CLKC3_FPHASE(0),
50
+ .CLKC4_CPHASE(1),
51
+ .CLKC4_DIV(1),
52
+ .CLKC4_DIV2_ENABLE("DISABLE"),
53
+ .CLKC4_ENABLE("DISABLE"),
54
+ .CLKC4_FPHASE(0),
55
+ .DERIVE_PLL_CLOCKS("DISABLE"),
56
+ .DPHASE_SOURCE("DISABLE"),
57
+ .DYNCFG("DISABLE"),
58
+ .FBCLK_DIV(7),
59
+ .FEEDBK_MODE("NORMAL"),
60
+ .FEEDBK_PATH("CLKC0_EXT"),
61
+ .FIN("24.000"),
62
+ .FREQ_LOCK_ACCURACY(2),
63
+ .GEN_BASIC_CLOCK("DISABLE"),
64
+ .GMC_GAIN(6),
65
+ .GMC_TEST(14),
66
+ .ICP_CURRENT(3),
67
+ .IF_ESCLKSTSW("DISABLE"),
68
+ .INTFB_WAKE("DISABLE"),
69
+ .KVCO(6),
70
+ .LPF_CAPACITOR(3),
71
+ .LPF_RESISTOR(2),
72
+ .NORESET("DISABLE"),
73
+ .ODIV_MUXC0("DIV"),
74
+ .ODIV_MUXC1("DIV"),
75
+ .ODIV_MUXC2("DIV"),
76
+ .ODIV_MUXC3("DIV"),
77
+ .ODIV_MUXC4("DIV"),
78
+ .PLLC2RST_ENA("DISABLE"),
79
+ .PLLC34RST_ENA("DISABLE"),
80
+ .PLLMRST_ENA("DISABLE"),
81
+ .PLLRST_ENA("DISABLE"),
82
+ .PLL_LOCK_MODE(0),
83
+ .PREDIV_MUXC0("VCO"),
84
+ .PREDIV_MUXC1("VCO"),
85
+ .PREDIV_MUXC2("VCO"),
86
+ .PREDIV_MUXC3("VCO"),
87
+ .PREDIV_MUXC4("VCO"),
88
+ .REFCLK_DIV(5),
89
+ .REFCLK_SEL("INTERNAL"),
90
+ .STDBY_ENABLE("DISABLE"),
91
+ .STDBY_VCO_ENA("DISABLE"),
92
+ .SYNC_ENABLE("DISABLE"),
93
+ .VCO_NORESET("DISABLE"))
94
+ pll_inst (
95
+ .daddr(6'b000000),
96
+ .dclk(1'b0),
97
+ .dcs(1'b0),
98
+ .di(8'b00000000),
99
+ .dwe(1'b0),
100
+ .fbclk(clk0_out),
101
+ .psclk(1'b0),
102
+ .psclksel(3'b000),
103
+ .psdown(1'b0),
104
+ .psstep(1'b0),
105
+ .refclk(refclk),
106
+ .reset(1'b0),
107
+ .stdby(1'b0),
108
+ .clkc({open_n47,open_n48,clk2_out,clk1_out,clk0_buf})); // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/project/al_ip/ip_pll.v(83)
109
+
110
+ endmodule
111
+
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_ram.v ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /************************************************************\
2
+ ** Copyright (c) 2011-2021 Anlogic, Inc.
3
+ ** All Right Reserved.
4
+ \************************************************************/
5
+ /************************************************************\
6
+ ** Log : This file is generated by Anlogic IP Generator.
7
+ ** File : H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/project/al_ip/ip_ram.v
8
+ ** Date : 2018 07 28
9
+ ** TD version : 4.2.217
10
+ \************************************************************/
11
+
12
+ `timescale 1ns / 1ps
13
+
14
+ module img_cache (
15
+ dia, addra, cea, clka, rsta,
16
+ dob, addrb, ceb, clkb, rstb
17
+ );
18
+
19
+ output [15:0] dob;
20
+
21
+
22
+ input [15:0] dia;
23
+ input [15:0] addra;
24
+ input [15:0] addrb;
25
+ input cea;
26
+ input ceb;
27
+ input clka;
28
+ input clkb;
29
+ input rsta;
30
+ input rstb;
31
+
32
+
33
+
34
+
35
+ EG_LOGIC_BRAM #( .DATA_WIDTH_A(16),
36
+ .DATA_WIDTH_B(16),
37
+ .ADDR_WIDTH_A(16),
38
+ .ADDR_WIDTH_B(16),
39
+ .DATA_DEPTH_A(32800),
40
+ .DATA_DEPTH_B(32800),
41
+ .MODE("PDPW"),
42
+ .REGMODE_A("NOREG"),
43
+ .REGMODE_B("NOREG"),
44
+ .WRITEMODE_A("NORMAL"),
45
+ .WRITEMODE_B("NORMAL"),
46
+ .RESETMODE("SYNC"),
47
+ .IMPLEMENT("9K"),
48
+ .INIT_FILE("NONE"),
49
+ .FILL_ALL("NONE"))
50
+ inst(
51
+ .dia(dia),
52
+ .dib({16{1'b0}}),
53
+ .addra(addra),
54
+ .addrb(addrb),
55
+ .cea(cea),
56
+ .ceb(ceb),
57
+ .ocea(1'b0),
58
+ .oceb(1'b0),
59
+ .clka(clka),
60
+ .clkb(clkb),
61
+ .wea(1'b1),
62
+ .web(1'b0),
63
+ .bea(1'b0),
64
+ .beb(1'b0),
65
+ .rsta(rsta),
66
+ .rstb(rstb),
67
+ .doa(),
68
+ .dob(dob));
69
+
70
+
71
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_ram_sim.v ADDED
The diff for this file is too large to render. See raw diff
 
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_rom.v ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /************************************************************\
2
+ ** Copyright (c) 2011-2021 Anlogic, Inc.
3
+ ** All Right Reserved.
4
+ \************************************************************/
5
+ /************************************************************\
6
+ ** Log : This file is generated by Anlogic IP Generator.
7
+ ** File : H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/project/al_ip/ip_rom.v
8
+ ** Date : 2018 07 25
9
+ ** TD version : 4.2.217
10
+ \************************************************************/
11
+
12
+ `timescale 1ns / 1ps
13
+
14
+ module img ( doa, addra, clka, rsta );
15
+
16
+ output [15:0] doa;
17
+
18
+ input [13:0] addra;
19
+ input clka;
20
+ input rsta;
21
+
22
+
23
+
24
+
25
+ EG_LOGIC_BRAM #( .DATA_WIDTH_A(16),
26
+ .ADDR_WIDTH_A(14),
27
+ .DATA_DEPTH_A(9700),
28
+ .DATA_WIDTH_B(16),
29
+ .ADDR_WIDTH_B(14),
30
+ .DATA_DEPTH_B(9700),
31
+ .MODE("SP"),
32
+ .REGMODE_A("NOREG"),
33
+ .RESETMODE("SYNC"),
34
+ .IMPLEMENT("9K"),
35
+ .DEBUGGABLE("NO"),
36
+ .PACKABLE("NO"),
37
+ .INIT_FILE("../../al_ip/CrazyBird.mif"),
38
+ .FILL_ALL("NONE"))
39
+ inst(
40
+ .dia({16{1'b0}}),
41
+ .dib({16{1'b0}}),
42
+ .addra(addra),
43
+ .addrb({14{1'b0}}),
44
+ .cea(1'b1),
45
+ .ceb(1'b0),
46
+ .ocea(1'b0),
47
+ .oceb(1'b0),
48
+ .clka(clka),
49
+ .clkb(1'b0),
50
+ .wea(1'b0),
51
+ .web(1'b0),
52
+ .bea(1'b0),
53
+ .beb(1'b0),
54
+ .rsta(rsta),
55
+ .rstb(1'b0),
56
+ .doa(doa),
57
+ .dob());
58
+
59
+
60
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_rom_sim.v ADDED
The diff for this file is too large to render. See raw diff
 
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/project/al_ip/ip_sdram.v ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /************************************************************\
2
+ ** Copyright (c) 2011-2021 Anlogic, Inc.
3
+ ** All Right Reserved.
4
+ \************************************************************/
5
+ /************************************************************\
6
+ ** Log : This file is generated by Anlogic IP Generator.
7
+ ** File : H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd_camera/test_camera/al_ip/ip_sdram.v
8
+ ** Date : 2018 07 20
9
+ ** TD version : 4.2.217
10
+ \************************************************************/
11
+
12
+ `timescale 1ns / 1ps
13
+
14
+ module ip_sdram ( clk, ras_n, cas_n, we_n, addr, ba, dq, cs_n, dm0, dm1, dm2, dm3, cke );
15
+ input clk;
16
+ input ras_n;
17
+ input cas_n;
18
+ input we_n;
19
+ input [10:0] addr;
20
+ input [1:0] ba;
21
+ inout [31:0] dq;
22
+ input cs_n;
23
+ input dm0;
24
+ input dm1;
25
+ input dm2;
26
+ input dm3;
27
+ input cke;
28
+
29
+ EG_PHY_SDRAM_2M_32 sdram(
30
+ .clk(clk),
31
+ .ras_n(ras_n),
32
+ .cas_n(cas_n),
33
+ .we_n(we_n),
34
+ .addr(addr),
35
+ .ba(ba),
36
+ .dq(dq),
37
+ .cs_n(cs_n),
38
+ .dm0(dm0),
39
+ .dm1(dm1),
40
+ .dm2(dm2),
41
+ .dm3(dm3),
42
+ .cke(cke));
43
+
44
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/cameraReader.v ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module cameraReader
2
+ (
3
+ input clk,
4
+ input reset_n,
5
+
6
+ output csi_xclk,
7
+
8
+ input csi_pclk,
9
+ input [7:0] csi_data,
10
+ input csi_vsync,
11
+ input csi_hsync,
12
+
13
+ output reg [15:0] data_out = 0,
14
+ output wire wrreq,
15
+ output wire wrclk,
16
+ output reg [19:0]wraddr
17
+ );
18
+
19
+ reg [19:0] pixel_counter = 0;
20
+
21
+ assign csi_xclk = (reset_n == 1) ? clk : 0;
22
+
23
+ reg vsync_passed = 0;
24
+ reg write_pixel = 0;
25
+
26
+ reg wrclk1 = 0;
27
+
28
+ always@(posedge csi_pclk)
29
+ wrclk1 <= ~wrclk1;
30
+
31
+ always@(negedge wrclk1)
32
+ begin
33
+ if(csi_hsync == 1)
34
+ write_pixel <= 1;
35
+ else
36
+ write_pixel <= 0;
37
+ end
38
+
39
+ reg [7:0] subpixel;
40
+ reg [15:0] current_pixel;
41
+
42
+ always@(posedge wrreq )
43
+ begin
44
+ data_out <= current_pixel;
45
+ end
46
+
47
+ always@(posedge csi_pclk)
48
+ begin
49
+ if(reset_n == 0)
50
+ begin
51
+ pixel_counter <= 0;
52
+ vsync_passed <= 0;
53
+ end
54
+ else
55
+ begin
56
+ if(csi_vsync == 1)
57
+ begin
58
+ pixel_counter <= 0;
59
+ vsync_passed <= 1;
60
+ wraddr <= 0;
61
+ end
62
+ else
63
+ if(csi_hsync == 1 && vsync_passed == 1)
64
+ begin
65
+ if(pixel_counter[0] == 0)
66
+ begin
67
+ pixel_counter <= pixel_counter + 1;
68
+ subpixel <= csi_data;
69
+ end
70
+ else
71
+ begin
72
+ // current_pixel <= { subpixel, csi_data};
73
+ current_pixel <= { csi_data, subpixel};
74
+ pixel_counter <= pixel_counter + 1;
75
+ wraddr <= wraddr + 1;
76
+ end
77
+ end
78
+ else
79
+ begin
80
+ if(write_pixel == 1)
81
+ pixel_counter <= pixel_counter + 1;
82
+ else
83
+ pixel_counter <= 0;
84
+ end
85
+ end
86
+ end
87
+
88
+ assign wrreq = (write_pixel == 1) && pixel_counter > 2 ? wrclk1 : 0;
89
+ assign wrclk = ~csi_pclk;
90
+
91
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/lcd_sync.v ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module lcd_sync
3
+ #(
4
+ //display image at pos
5
+ parameter IMG_W = 100, //图片行像素点个数
6
+ parameter IMG_H = 100, //图片场像素点个数
7
+ parameter IMG_X = 0,
8
+ parameter IMG_Y = 0
9
+ )
10
+ (
11
+ input wire clk,
12
+ input wire rest_n,
13
+ output wire lcd_clk,
14
+ output wire lcd_pwm,
15
+ output wire lcd_hsync,
16
+ output wire lcd_vsync,
17
+ output wire lcd_de,
18
+ output wire [10:0] hsync_cnt,
19
+ output wire [10:0] vsync_cnt,
20
+ output wire img_ack,
21
+ output wire [15:0]addr
22
+ );
23
+
24
+ `define LCD_480800
25
+ `ifdef LCD_480800
26
+ //800*480
27
+ // localparam TFT_H = 800; //TFT屏行像素点个数
28
+ // localparam TFT_V = 480; //TFT屏场像素点个数
29
+
30
+ // localparam thb = 256;
31
+ // localparam th = 1056 + thb;
32
+
33
+ // localparam tvb = 45;
34
+ // localparam tv = 525 + tvb;
35
+ //640*480
36
+ localparam TFT_H = 640; //TFT屏行像素点个数
37
+ localparam TFT_V = 480; //TFT屏场像素点个数
38
+
39
+ localparam thb = 160;
40
+ localparam th = 640 + thb;
41
+
42
+ localparam tvb = 45;
43
+ localparam tv = 525 + tvb;
44
+ `else
45
+
46
+ localparam TFT_H = 480; //TFT屏行像素点个数
47
+ localparam TFT_V = 272; //TFT屏场像素点个数
48
+
49
+ localparam thb = 41;
50
+ localparam th = 533 + thb;
51
+
52
+ localparam tvb = 10;
53
+ localparam tv = 288 + tvb;
54
+ `endif
55
+
56
+ reg [10:0] counter_hs;
57
+ reg [10:0] counter_vs;
58
+
59
+ always@(posedge clk)begin
60
+ if(rest_n == 1'b0)begin
61
+ counter_hs <= 0;
62
+ counter_vs <= 0;
63
+ end
64
+ else begin
65
+ if(counter_hs == th )begin
66
+ if(counter_vs == tv)
67
+ counter_vs <= 0;
68
+ else
69
+ counter_vs <= counter_vs + 1;
70
+ counter_hs <= 0;
71
+ end
72
+ else
73
+ counter_hs <= counter_hs + 1;
74
+ end
75
+ end
76
+
77
+ reg [10:0]img_hbegin = 0; //图片左上角第一个像素点在TFT屏的行向坐标
78
+ reg [10:0]img_vbegin = 0; //图片左上角第一个像素点在TFT屏的场向坐标
79
+
80
+ assign lcd_clk = (rest_n == 1) ? clk : 1'b0;
81
+ assign lcd_pwm = (rest_n == 1) ? 1'b1 : 1'b0;
82
+ assign lcd_hsync = (counter_hs >= (thb+4) && counter_hs < (th-5)) ? 0 : 1;
83
+ assign lcd_vsync = (counter_vs >= (tvb+2) && counter_vs < (tv-5)) ? 0 : 1;
84
+ assign lcd_de = (counter_hs >= thb && counter_hs <= th && counter_vs >= tvb && counter_vs < tv) ? 1 : 0;
85
+ assign hsync_cnt = counter_hs;
86
+ assign vsync_cnt = counter_vs;
87
+
88
+ assign img_ack = lcd_de &&
89
+ ((counter_hs - thb) >= IMG_X && (counter_hs - thb) < (IMG_X + IMG_W)) &&
90
+ ((counter_vs - tvb) >= IMG_Y && (counter_vs - tvb) < (IMG_Y + IMG_H))?1'b1:1'b0;
91
+
92
+ reg [15:0]read_addr; //读图片数据rom地址
93
+ // wire [15:0]img_data; //读出图片数据
94
+ /*
95
+ img mif_img
96
+ (
97
+ .doa(img_data),
98
+ .addra(addr),
99
+ .clka(clk),
100
+ .rsta(!rest_n)
101
+ );
102
+ */
103
+
104
+ assign addr = read_addr;
105
+
106
+ always@(posedge clk or negedge rest_n)
107
+ begin
108
+ if(!rest_n)
109
+ read_addr <= 16'd0;
110
+ else if(img_ack)
111
+ read_addr <= (counter_hs - IMG_X - thb) + (counter_vs - IMG_Y - tvb)*IMG_W;
112
+ else
113
+ read_addr <= 16'd0;
114
+ end
115
+
116
+
117
+ // reg [20:0] pixel_counter;
118
+ //always@(posedge clk)
119
+ //begin
120
+ //if(reset == 1'b0)
121
+ // begin
122
+ // pixel_counter <= 0;
123
+ // end
124
+ // else
125
+ // begin
126
+ // if(counter_hs >= 46 && counter_hs <= 686 && counter_vs >= 23 && counter_vs < 503)
127
+ // begin
128
+ // pixel_counter <= pixel_counter + 1;
129
+ // end
130
+ // else
131
+ // if(counter_vs == 504)
132
+ // pixel_counter <= 0;
133
+ // end
134
+ //end
135
+
136
+
137
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/sccb_v1/camera_init.v ADDED
@@ -0,0 +1,444 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module camera_init (
2
+
3
+ input clk,
4
+ input reset_n,
5
+
6
+ output reg ready,
7
+
8
+ output wire sda_oe,
9
+ output wire sda,
10
+ input wire sda_in,
11
+ output scl
12
+ );
13
+
14
+ parameter REGS_TO_INIT = 200;
15
+
16
+ localparam CAMERA_INIT_1 = 11;
17
+ localparam CAMERA_INIT_2 = 12;
18
+ localparam CAMERA_INIT_3 = 13;
19
+ localparam CAMERA_INIT_4 = 14;
20
+ localparam CAMERA_INIT_5 = 15;
21
+ localparam CAMERA_INIT_6 = 16;
22
+ localparam CAMERA_INIT_7 = 17;
23
+ localparam CAMERA_IDLE = 18;
24
+
25
+ localparam CONTROL_REG = 3'b000;
26
+ localparam SLAVE_ADDRESS = 3'b001;
27
+ localparam SLAVE_REG_ADDRESS = 3'b010;
28
+ localparam SLAVE_DATA_1 = 3'b011;
29
+ localparam SLAVE_DATA_2 = 3'b100;
30
+
31
+ //I2C//////////////////////////////////////////
32
+ reg[7:0] data_in_bus = 0;
33
+ reg [2:0] reg_address = 0;
34
+ reg bus_write = 0;
35
+ wire ready_out;
36
+ wire success_out;
37
+
38
+ i2c_module i2c_write_module(.clk(clk), .reset_n(reset_n), .scl_out(scl),
39
+ .writedata(data_in_bus), .address(reg_address),
40
+ .write(bus_write), .ready(ready_out), .success_out(success_out), .sda_in(sda_in), .sda(sda), .sda_oe(sda_oe) );
41
+
42
+ /////////////////////////////////////////
43
+
44
+ wire[7:0] regs_addr;
45
+ wire[7:0] data_to_write;
46
+ reg[7:0] counter = 0;
47
+
48
+ reg[7:0] state_next;
49
+
50
+
51
+ wire [15:0] regs_data =
52
+ counter == 0 ? 16'hff_01:
53
+ counter == 1 ? 16'h12_80:
54
+ counter == 2 ? 16'hff_00:
55
+ counter == 3 ? 16'h2c_ff:
56
+ counter == 4 ? 16'h2e_df:
57
+ counter == 5 ? 16'hff_01:
58
+ counter == 6 ? 16'h3c_32:
59
+ counter == 7 ? 16'h11_00:
60
+ counter == 8 ? 16'h09_02:
61
+ counter == 9 ? 16'h04_d8:
62
+ counter == 10 ? 16'h13_e5:
63
+ counter == 11 ? 16'h14_48:
64
+ counter == 12 ? 16'h2c_0c:
65
+ counter == 13 ? 16'h33_78:
66
+ counter == 14 ? 16'h3a_33:
67
+ counter == 15 ? 16'h3b_fb:
68
+ counter == 16 ? 16'h3e_00:
69
+ counter == 17 ? 16'h43_11:
70
+ counter == 18 ? 16'h16_10:
71
+ counter == 19 ? 16'h39_92:
72
+ counter == 20 ? 16'h35_da:
73
+ counter == 21 ? 16'h22_1a:
74
+ counter == 22 ? 16'h37_c3:
75
+ counter == 23 ? 16'h23_00:
76
+ counter == 24 ? 16'h34_c0:
77
+ counter == 25 ? 16'h36_1a:
78
+ counter == 26 ? 16'h06_88:
79
+ counter == 27 ? 16'h07_c0:
80
+ counter == 28 ? 16'h0d_87:
81
+ counter == 29 ? 16'h0e_41:
82
+ counter == 30 ? 16'h4c_00:
83
+ counter == 31 ? 16'h48_00:
84
+ counter == 32 ? 16'h5b_00:
85
+ counter == 33 ? 16'h42_03:
86
+ counter == 34 ? 16'h4a_81:
87
+ counter == 35 ? 16'h21_99:
88
+ counter == 36 ? 16'h24_40:
89
+ counter == 37 ? 16'h25_38:
90
+ counter == 38 ? 16'h26_82:
91
+ counter == 39 ? 16'h5c_00:
92
+ counter == 40 ? 16'h63_00:
93
+ counter == 41 ? 16'h46_00:
94
+ counter == 42 ? 16'h0c_3c:
95
+ counter == 43 ? 16'h61_70:
96
+ counter == 44 ? 16'h62_80:
97
+ counter == 45 ? 16'h7c_05:
98
+ counter == 46 ? 16'h20_80:
99
+ counter == 47 ? 16'h28_30:
100
+ counter == 48 ? 16'h6c_00:
101
+ counter == 49 ? 16'h6d_80:
102
+ counter == 50 ? 16'h6e_00:
103
+ counter == 51 ? 16'h70_02:
104
+ counter == 52 ? 16'h71_94:
105
+ counter == 53 ? 16'h73_c1:
106
+ counter == 54 ? 16'h3d_34:
107
+ counter == 55 ? 16'h5a_57:
108
+ counter == 56 ? 16'h12_00:
109
+ counter == 57 ? 16'h17_11:
110
+ counter == 58 ? 16'h18_75:
111
+ counter == 59 ? 16'h19_01:
112
+ counter == 60 ? 16'h1a_97:
113
+ counter == 61 ? 16'h32_36:
114
+ counter == 62 ? 16'h03_0f:
115
+ counter == 63 ? 16'h37_40:
116
+ counter == 64 ? 16'h4f_ca:
117
+ counter == 65 ? 16'h50_a8:
118
+ counter == 66 ? 16'h5a_23:
119
+ counter == 67 ? 16'h6d_00:
120
+ counter == 68 ? 16'h6d_38:
121
+ counter == 69 ? 16'hff_00:
122
+ counter == 70 ? 16'he5_7f:
123
+ counter == 71 ? 16'hf9_c0:
124
+ counter == 72 ? 16'h41_24:
125
+ counter == 73 ? 16'he0_14:
126
+ counter == 74 ? 16'h76_ff:
127
+ counter == 75 ? 16'h33_a0:
128
+ counter == 76 ? 16'h42_20:
129
+ counter == 77 ? 16'h43_18:
130
+ counter == 78 ? 16'h4c_00:
131
+ counter == 79 ? 16'h87_d5:
132
+ counter == 80 ? 16'h88_3f:
133
+ counter == 81 ? 16'hd7_03:
134
+ counter == 82 ? 16'hd9_10:
135
+ counter == 83 ? 16'hd3_82:
136
+ counter == 84 ? 16'hc8_08:
137
+ counter == 85 ? 16'hc9_80:
138
+ counter == 86 ? 16'h7c_00:
139
+ counter == 87 ? 16'h7d_00:
140
+ counter == 88 ? 16'h7c_03:
141
+ counter == 89 ? 16'h7d_48:
142
+ counter == 90 ? 16'h7d_48:
143
+ counter == 91 ? 16'h7c_08:
144
+ counter == 92 ? 16'h7d_20:
145
+ counter == 93 ? 16'h7d_10:
146
+ counter == 94 ? 16'h7d_0e:
147
+ counter == 95 ? 16'h90_00:
148
+ counter == 96 ? 16'h91_0e:
149
+ counter == 97 ? 16'h91_1a:
150
+ counter == 98 ? 16'h91_31:
151
+ counter == 99 ? 16'h91_5a:
152
+ counter == 100 ? 16'h91_69:
153
+ counter == 101 ? 16'h91_75:
154
+ counter == 102 ? 16'h91_7e:
155
+ counter == 103 ? 16'h91_88:
156
+ counter == 104 ? 16'h91_8f:
157
+ counter == 105 ? 16'h91_96:
158
+ counter == 106 ? 16'h91_a3:
159
+ counter == 107 ? 16'h91_af:
160
+ counter == 108 ? 16'h91_c4:
161
+ counter == 109 ? 16'h91_d7:
162
+ counter == 110 ? 16'h91_e8:
163
+ counter == 111 ? 16'h91_20:
164
+ counter == 112 ? 16'h92_00:
165
+ counter == 113 ? 16'h93_06:
166
+ counter == 114 ? 16'h93_e3:
167
+ counter == 115 ? 16'h93_05:
168
+ counter == 116 ? 16'h93_05:
169
+ counter == 117 ? 16'h93_00:
170
+ counter == 118 ? 16'h93_04:
171
+ counter == 119 ? 16'h93_00:
172
+ counter == 120 ? 16'h93_00:
173
+ counter == 121 ? 16'h93_00:
174
+ counter == 122 ? 16'h93_00:
175
+ counter == 123 ? 16'h93_00:
176
+ counter == 124 ? 16'h93_00:
177
+ counter == 125 ? 16'h93_00:
178
+ counter == 126 ? 16'h96_00:
179
+ counter == 127 ? 16'h97_08:
180
+ counter == 128 ? 16'h97_19:
181
+ counter == 129 ? 16'h97_02:
182
+ counter == 130 ? 16'h97_0c:
183
+ counter == 131 ? 16'h97_24:
184
+ counter == 132 ? 16'h97_30:
185
+ counter == 133 ? 16'h97_28:
186
+ counter == 134 ? 16'h97_26:
187
+ counter == 135 ? 16'h97_02:
188
+ counter == 136 ? 16'h97_98:
189
+ counter == 137 ? 16'h97_80:
190
+ counter == 138 ? 16'h97_00:
191
+ counter == 139 ? 16'h97_00:
192
+ counter == 140 ? 16'hc3_ef:
193
+ counter == 141 ? 16'ha4_00:
194
+ counter == 142 ? 16'ha8_00:
195
+ counter == 143 ? 16'hc5_11:
196
+ counter == 144 ? 16'hc6_51:
197
+ counter == 145 ? 16'hbf_80:
198
+ counter == 146 ? 16'hc7_10:
199
+ counter == 147 ? 16'hb6_66:
200
+ counter == 148 ? 16'hb8_a5:
201
+ counter == 149 ? 16'hb7_64:
202
+ counter == 150 ? 16'hb9_7c:
203
+ counter == 151 ? 16'hb3_af:
204
+ counter == 152 ? 16'hb4_97:
205
+ counter == 153 ? 16'hb5_ff:
206
+ counter == 154 ? 16'hb0_c5:
207
+ counter == 155 ? 16'hb1_94:
208
+ counter == 156 ? 16'hb2_0f:
209
+ counter == 157 ? 16'hc4_5c:
210
+ counter == 158 ? 16'hc0_c8:
211
+ counter == 159 ? 16'hc1_96:
212
+ counter == 160 ? 16'h8c_00:
213
+ counter == 161 ? 16'h86_3d:
214
+ counter == 162 ? 16'h50_00:
215
+ counter == 163 ? 16'h51_90:
216
+ counter == 164 ? 16'h52_2c:
217
+ counter == 165 ? 16'h53_00:
218
+ counter == 166 ? 16'h54_00:
219
+ counter == 167 ? 16'h55_88:
220
+ counter == 168 ? 16'h5a_90:
221
+ counter == 169 ? 16'h5b_2c:
222
+ counter == 170 ? 16'h5c_05:
223
+ counter == 171 ? 16'hd3_02:
224
+ counter == 172 ? 16'hc3_ed:
225
+ counter == 173 ? 16'h7f_00:
226
+ counter == 174 ? 16'hda_09:
227
+ counter == 175 ? 16'he5_1f:
228
+ counter == 176 ? 16'he1_67:
229
+ counter == 177 ? 16'he0_00:
230
+ counter == 178 ? 16'hdd_7f:
231
+ counter == 179 ? 16'h05_00:
232
+ //Set OV2640 to RGB565 Mode
233
+ counter == 180 ? 16'hff_00:
234
+ counter == 181 ? 16'hda_09:
235
+ counter == 182 ? 16'hd7_03:
236
+ counter == 183 ? 16'hdf_02:
237
+ counter == 184 ? 16'h33_a0:
238
+ counter == 185 ? 16'h3c_00:
239
+ counter == 186 ? 16'he1_67:
240
+ counter == 187 ? 16'hff_01:
241
+ counter == 188 ? 16'he0_00:
242
+ counter == 189 ? 16'he1_00:
243
+ counter == 190 ? 16'he5_00:
244
+ counter == 191 ? 16'hd7_00:
245
+ counter == 192 ? 16'hda_00:
246
+ counter == 193 ? 16'he0_00:
247
+ //[OV2640_OutSize_Set] width:480 height:272
248
+ counter == 194 ? 16'hff_00:
249
+ counter == 195 ? 16'he0_04:
250
+ counter == 196 ? 16'h5a_32: //OUTW/4&0xff
251
+ counter == 197 ? 16'h5b_29: //OUTH/4&0xff
252
+ counter == 198 ? 16'h5c_00:
253
+ counter == 199 ? 16'he0_00:
254
+ 16'hFF;
255
+
256
+ //assign regs_addr = counter == 0 ? 8'h12 :
257
+ // counter == 1 ? 8'h12 :
258
+ // counter == 2 ? 8'h12 :
259
+ // counter == 3 ? 8'h40 :
260
+ // counter == 4 ? 8'h58 :
261
+ // counter == 5 ? 8'h1e :
262
+ // counter == 6 ? 8'h3c :
263
+ // 8'hFF;
264
+
265
+ //assign data_to_write = counter == 0 ? 8'h80 :
266
+ // counter == 1 ? 8'h04 :
267
+ // counter == 2 ? 8'h04 :
268
+ // counter == 3 ? 8'hd0 :
269
+ // counter == 4 ? 8'h9e :
270
+ // counter == 5 ? 8'h01 :
271
+ // counter == 6 ? 8'h78 :
272
+ // 8'hFF;
273
+
274
+ always@(posedge clk)
275
+ begin
276
+ if(state_next == CAMERA_IDLE)
277
+ ready <= 1'b1;
278
+ else
279
+ ready <= 1'b0;
280
+ end
281
+
282
+ always@(posedge clk)
283
+ begin
284
+
285
+ if(reset_n == 1'b0)
286
+ begin
287
+ state_next <= CAMERA_INIT_1;
288
+ end
289
+ else
290
+ begin
291
+ case(state_next)
292
+
293
+ CAMERA_INIT_1:
294
+ begin
295
+ state_next <= CAMERA_INIT_2;
296
+ end
297
+
298
+ CAMERA_INIT_2:
299
+ begin
300
+ state_next <= CAMERA_INIT_3;
301
+ end
302
+
303
+ CAMERA_INIT_3:
304
+ begin
305
+ state_next <= CAMERA_INIT_4;
306
+
307
+ end
308
+
309
+ CAMERA_INIT_4:
310
+ begin
311
+ state_next <= CAMERA_INIT_7;
312
+ end
313
+
314
+ //wait until ready_out is set to 0
315
+ CAMERA_INIT_7:
316
+ begin
317
+ if(ready_out == 1'b0)
318
+ state_next <= CAMERA_INIT_5;
319
+ end
320
+
321
+ CAMERA_INIT_5:
322
+ begin
323
+ if(ready_out == 1'b1)
324
+ begin
325
+ if(success_out == 1'b1)
326
+ begin
327
+ if(counter == REGS_TO_INIT - 1)
328
+ begin
329
+ state_next <= CAMERA_IDLE;
330
+ end
331
+ else
332
+ state_next <= CAMERA_INIT_6;
333
+ end
334
+ else
335
+ state_next <= CAMERA_INIT_2;
336
+ end
337
+ end
338
+
339
+ CAMERA_INIT_6:
340
+ begin
341
+ state_next <= CAMERA_INIT_2;
342
+ end
343
+
344
+ CAMERA_IDLE:
345
+ begin
346
+ state_next <= CAMERA_IDLE;
347
+ end
348
+
349
+ endcase
350
+ end
351
+ end
352
+
353
+ //always@(posedge clk)
354
+ //begin
355
+ // if(state_next == CAMERA_INIT_6)
356
+ // counter <= counter + 1'b1;
357
+ // else
358
+ // counter <= counter;
359
+ //
360
+ //end
361
+ //
362
+ always@(posedge clk)
363
+ begin
364
+ if(reset_n == 1'b0)
365
+ begin
366
+ reg_address <= 0;
367
+ data_in_bus <= 0;
368
+ bus_write <= 1'b0;
369
+ counter <= 0;
370
+ end
371
+ else
372
+ begin
373
+ case(state_next)
374
+
375
+ CAMERA_INIT_1:
376
+ begin
377
+ reg_address <= SLAVE_ADDRESS;
378
+ data_in_bus <= 8'h60; // slave address
379
+ bus_write <= 1'b1;
380
+ end
381
+
382
+ CAMERA_INIT_2:
383
+ begin
384
+ reg_address <= SLAVE_REG_ADDRESS;
385
+ data_in_bus <= regs_data[15:8];
386
+ bus_write <= 1'b1;
387
+ end
388
+
389
+ CAMERA_INIT_3:
390
+ begin
391
+ reg_address <= SLAVE_DATA_1;
392
+ data_in_bus <= regs_data[7:0];
393
+ bus_write <= 1'b1;
394
+ end
395
+
396
+ CAMERA_INIT_4:
397
+ begin
398
+ reg_address <= CONTROL_REG;
399
+ data_in_bus <= 3'b001;
400
+ bus_write <= 1'b1;
401
+ end
402
+
403
+ CAMERA_INIT_5:
404
+ begin
405
+ reg_address <= 0;
406
+ data_in_bus <= 0;
407
+ bus_write <= 1'b0;
408
+ end
409
+
410
+ CAMERA_INIT_6:
411
+ begin
412
+ bus_write <= 1'b0;
413
+
414
+ reg_address <= 0;
415
+ data_in_bus <= 0;
416
+
417
+ counter <= counter + 1'b1;
418
+ end
419
+
420
+ CAMERA_INIT_7:
421
+ begin
422
+ reg_address <= 0;
423
+ data_in_bus <= 0;
424
+ bus_write <= 1'b0;
425
+ end
426
+
427
+ CAMERA_IDLE:
428
+ begin
429
+ reg_address <= 0;
430
+ data_in_bus <= 0;
431
+ bus_write <= 1'b0;
432
+ end
433
+
434
+ default:
435
+ begin
436
+ bus_write <= 1'b0;
437
+ reg_address <= 3'd0;
438
+ data_in_bus <= 8'd0;
439
+ end
440
+ endcase
441
+ end
442
+ end
443
+
444
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/sccb_v1/i2c_module.v ADDED
@@ -0,0 +1,1069 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module i2c_module(
3
+ input clk, //50MHz
4
+ input reset_n,
5
+
6
+ output reg sda_oe = 1,
7
+ input wire sda_in,
8
+ output reg sda = 1,
9
+
10
+ output reg scl_out,
11
+
12
+ input[7:0] writedata,
13
+ input write,
14
+ input[2:0] address,
15
+
16
+ output reg ready = 1,
17
+ output reg success_out = 0
18
+
19
+ );
20
+
21
+ reg[7:0] state_next = 0;
22
+
23
+ localparam STATE_IDLE = 0;
24
+ localparam STATE_ADDRESS_START = 1;
25
+ localparam STATE_ADDRESS_START_2 = 111;
26
+ localparam STATE_ADDRESS_START_3 = 112;
27
+ localparam STATE_ADDRESS_BIT_1 = 2;
28
+ localparam STATE_ADDRESS_BIT_2 = 3;
29
+ localparam STATE_ADDRESS_BIT_3 = 4;
30
+ localparam STATE_ADDRESS_BIT_4 = 5;
31
+ localparam STATE_ADDRESS_BIT_5 = 6;
32
+ localparam STATE_ADDRESS_BIT_6 = 7;
33
+ localparam STATE_ADDRESS_BIT_7 = 8;
34
+ localparam STATE_ADDRESS_BIT_8 = 9;
35
+ localparam STATE_ADDRESS_ACK = 10;
36
+ //localparam STATE_ADDRESS_ACK_2 = 101;
37
+
38
+ localparam STATE_TRANSIT_1 = 102;
39
+
40
+ localparam STATE_REG_BIT_1 = 11;
41
+ localparam STATE_REG_BIT_2 = 12;
42
+ localparam STATE_REG_BIT_3 = 13;
43
+ localparam STATE_REG_BIT_4 = 14;
44
+ localparam STATE_REG_BIT_5 = 15;
45
+ localparam STATE_REG_BIT_6 = 16;
46
+ localparam STATE_REG_BIT_7 = 17;
47
+ localparam STATE_REG_BIT_8 = 18;
48
+ localparam STATE_REG_ACK = 19;
49
+ //localparam STATE_REG_ACK_2 = 191;
50
+
51
+ localparam STATE_TRANSIT_2 = 192;
52
+
53
+ localparam STATE_DATA_BIT_1 = 20;
54
+ localparam STATE_DATA_BIT_2 = 21;
55
+ localparam STATE_DATA_BIT_3 = 22;
56
+ localparam STATE_DATA_BIT_4 = 23;
57
+ localparam STATE_DATA_BIT_5 = 24;
58
+ localparam STATE_DATA_BIT_6 = 25;
59
+ localparam STATE_DATA_BIT_7 = 26;
60
+ localparam STATE_DATA_BIT_8 = 27;
61
+ localparam STATE_DATA_ACK = 28;
62
+ //localparam STATE_DATA_ACK_2 = 32;
63
+
64
+ localparam STATE_STOP = 29;
65
+ localparam STATE_STOP_1 = 30;
66
+ localparam STATE_STOP_2 = 31;
67
+
68
+ //reg[16:0] divider = 0;
69
+ reg clk_div = 0;
70
+ wire clk_div_2;
71
+ reg[7:0] divider2 = 0;
72
+
73
+ always@(posedge clk_div_2)
74
+ begin
75
+ clk_div <= ~clk_div;
76
+ end
77
+
78
+ always@(posedge clk)
79
+ begin
80
+ divider2 <= divider2 + 8'b1;
81
+ end
82
+
83
+ assign clk_div_2 = divider2[7];
84
+
85
+ reg [7:0] control_reg = 0;
86
+ reg [7:0] slave_address = 0;
87
+ reg [7:0] slave_reg_address = 0;
88
+ reg [7:0] slave_data_1 = 0;
89
+ reg [7:0] slave_data_2 = 0;
90
+
91
+ always@(posedge clk)
92
+ begin
93
+ if(reset_n == 0)
94
+ begin
95
+ control_reg <= 0;
96
+ slave_address <= 0;
97
+ slave_reg_address <= 0;
98
+ slave_data_1 <= 0;
99
+ slave_data_2 <= 0;
100
+ end
101
+ else
102
+ begin
103
+ if(write == 1'b1)
104
+ begin
105
+ case(address)
106
+ 3'b000: control_reg <= writedata;
107
+ 3'b001: slave_address <= writedata;
108
+ 3'b010: slave_reg_address <= writedata;
109
+ 3'b011: slave_data_1 <= writedata;
110
+ 3'b100: slave_data_2 <= writedata;
111
+ endcase
112
+ end
113
+
114
+ if(state_next != STATE_IDLE)
115
+ control_reg <= 0;
116
+ end
117
+ end
118
+
119
+
120
+ reg scl_output_enable = 0;
121
+ reg scl_output_zero = 0;
122
+
123
+ always@(posedge clk_div_2)
124
+ begin
125
+ if(scl_output_enable == 1)
126
+ begin
127
+ scl_out <= ~scl_out;
128
+ end
129
+ else
130
+ begin
131
+ if(scl_output_zero == 0)
132
+ scl_out <= 1'b1;
133
+ else
134
+ scl_out <= 1'b0;
135
+ end
136
+
137
+ end
138
+
139
+ //assign scl_out = scl_output_enable == 1 ? clk_div : scl_output_zero == 0 ? 1'b1 : 1'b0;
140
+
141
+ reg success = 0;
142
+
143
+ reg ack_ok = 0;
144
+
145
+ always@(posedge clk_div_2)
146
+ begin
147
+ if( (state_next == STATE_ADDRESS_ACK || state_next == STATE_REG_ACK || state_next == STATE_DATA_ACK) && sda_in == 1'b0 && clk_div == 1)
148
+ begin
149
+ ack_ok <= 1'b1;
150
+ end
151
+ else
152
+ ack_ok <= 1'b0;
153
+ end
154
+
155
+
156
+ always@(negedge clk_div_2)
157
+ begin
158
+ if(clk_div == 1)
159
+ begin
160
+ if(state_next == STATE_STOP && success == 1'b1)
161
+ success_out <= 1'b1;
162
+ else
163
+ if(state_next == STATE_ADDRESS_START)
164
+ success_out <= 1'b0;
165
+ end
166
+
167
+ end
168
+
169
+ always@(negedge clk_div_2)
170
+ begin
171
+ if(reset_n == 0)
172
+ begin
173
+ state_next <= STATE_IDLE;
174
+ end
175
+ else
176
+ begin
177
+
178
+ case(state_next)
179
+ STATE_IDLE:
180
+ begin
181
+ if(control_reg[0] == 1'b1 )
182
+ begin
183
+ state_next <= STATE_ADDRESS_START;
184
+ end
185
+ end
186
+
187
+ STATE_ADDRESS_START:
188
+ begin
189
+ if(clk_div == 0)
190
+ begin
191
+ state_next <= STATE_ADDRESS_START_2;
192
+ end
193
+ end
194
+
195
+ STATE_ADDRESS_START_2:
196
+ begin
197
+ if(clk_div == 1)
198
+ begin
199
+ state_next <= STATE_ADDRESS_START_3;
200
+ end
201
+ end
202
+
203
+ STATE_ADDRESS_START_3:
204
+ begin
205
+ if(clk_div == 0)
206
+ begin
207
+ state_next <= STATE_ADDRESS_BIT_1;
208
+ end
209
+ end
210
+
211
+ STATE_ADDRESS_BIT_1:
212
+ begin
213
+ if(clk_div == 0)
214
+ begin
215
+ state_next <= STATE_ADDRESS_BIT_2;
216
+ end
217
+ end
218
+
219
+ STATE_ADDRESS_BIT_2:
220
+ begin
221
+ if(clk_div == 0)
222
+ begin
223
+ state_next <= STATE_ADDRESS_BIT_3;
224
+ end
225
+ end
226
+
227
+ STATE_ADDRESS_BIT_3:
228
+ begin
229
+ if(clk_div == 0)
230
+ begin
231
+ state_next <= STATE_ADDRESS_BIT_4;
232
+ end
233
+ end
234
+
235
+ STATE_ADDRESS_BIT_4:
236
+ begin
237
+ if(clk_div == 0)
238
+ begin
239
+ state_next <= STATE_ADDRESS_BIT_5;
240
+ end
241
+ end
242
+
243
+ STATE_ADDRESS_BIT_5:
244
+ begin
245
+ if(clk_div == 0)
246
+ begin
247
+ state_next <= STATE_ADDRESS_BIT_6;
248
+ end
249
+ end
250
+
251
+ STATE_ADDRESS_BIT_6:
252
+ begin
253
+ if(clk_div == 0)
254
+ begin
255
+ state_next <= STATE_ADDRESS_BIT_7;
256
+ end
257
+ end
258
+
259
+ STATE_ADDRESS_BIT_7:
260
+ begin
261
+ if(clk_div == 0)
262
+ begin
263
+ state_next <= STATE_ADDRESS_BIT_8;
264
+ end
265
+ end
266
+
267
+ STATE_ADDRESS_BIT_8:
268
+ begin
269
+ if(clk_div == 0)
270
+ begin
271
+ state_next <= STATE_ADDRESS_ACK;
272
+ end
273
+ end
274
+
275
+ STATE_ADDRESS_ACK:
276
+ begin
277
+ if(clk_div == 0)
278
+ begin
279
+ if(ack_ok == 1'b1)
280
+ begin
281
+ state_next <= STATE_TRANSIT_1;
282
+ end
283
+ else
284
+ begin
285
+ state_next <= STATE_STOP;
286
+ end
287
+ end
288
+ end
289
+
290
+ STATE_TRANSIT_1:
291
+ begin
292
+ if(clk_div == 0)
293
+ begin
294
+ state_next <= STATE_REG_BIT_1;
295
+ end
296
+ end
297
+
298
+ // STATE_ADDRESS_ACK_2:
299
+ // begin
300
+ // if(clk_div == 0)
301
+ // begin
302
+ // state_next <= STATE_REG_BIT_1;
303
+ // end
304
+ // end
305
+
306
+ STATE_REG_BIT_1:
307
+ begin
308
+ if(clk_div == 0)
309
+ begin
310
+ state_next <= STATE_REG_BIT_2;
311
+ end
312
+ end
313
+
314
+ STATE_REG_BIT_2:
315
+ begin
316
+ if(clk_div == 0)
317
+ begin
318
+ state_next <= STATE_REG_BIT_3;
319
+ end
320
+ end
321
+
322
+ STATE_REG_BIT_3:
323
+ begin
324
+ if(clk_div == 0)
325
+ begin
326
+ state_next <= STATE_REG_BIT_4;
327
+ end
328
+ end
329
+
330
+ STATE_REG_BIT_4:
331
+ begin
332
+ if(clk_div == 0)
333
+ begin
334
+ state_next <= STATE_REG_BIT_5;
335
+ end
336
+ end
337
+
338
+ STATE_REG_BIT_5:
339
+ begin
340
+ if(clk_div == 0)
341
+ begin
342
+ state_next <= STATE_REG_BIT_6;
343
+ end
344
+ end
345
+
346
+ STATE_REG_BIT_6:
347
+ begin
348
+ if(clk_div == 0)
349
+ begin
350
+ state_next <= STATE_REG_BIT_7;
351
+ end
352
+ end
353
+
354
+ STATE_REG_BIT_7:
355
+ begin
356
+ if(clk_div == 0)
357
+ begin
358
+ state_next <= STATE_REG_BIT_8;
359
+ end
360
+ end
361
+
362
+ STATE_REG_BIT_8:
363
+ begin
364
+ if(clk_div == 0)
365
+ begin
366
+ state_next <= STATE_REG_ACK;
367
+ end
368
+ end
369
+
370
+ STATE_REG_ACK:
371
+ begin
372
+ if(clk_div == 0)
373
+ begin
374
+ if(ack_ok == 1'b1)
375
+ begin
376
+ state_next <= STATE_TRANSIT_2;
377
+ end
378
+ else
379
+ begin
380
+ state_next <= STATE_STOP;
381
+ end
382
+ end
383
+ end
384
+
385
+ // STATE_REG_ACK_2:
386
+ // begin
387
+ // if(clk_div == 0)
388
+ // begin
389
+ // state_next <= STATE_DATA_BIT_1;
390
+ // end
391
+ // end
392
+
393
+ STATE_TRANSIT_2:
394
+ begin
395
+ if(clk_div == 0)
396
+ begin
397
+ state_next <= STATE_DATA_BIT_1;
398
+ end
399
+ end
400
+
401
+
402
+ STATE_DATA_BIT_1:
403
+ begin
404
+ if(clk_div == 0)
405
+ begin
406
+ state_next <= STATE_DATA_BIT_2;
407
+ end
408
+ end
409
+
410
+ STATE_DATA_BIT_2:
411
+ begin
412
+ if(clk_div == 0)
413
+ begin
414
+ state_next <= STATE_DATA_BIT_3;
415
+ end
416
+ end
417
+
418
+ STATE_DATA_BIT_3:
419
+ begin
420
+ if(clk_div == 0)
421
+ begin
422
+ state_next <= STATE_DATA_BIT_4;
423
+ end
424
+ end
425
+
426
+ STATE_DATA_BIT_4:
427
+ begin
428
+ if(clk_div == 0)
429
+ begin
430
+ state_next <= STATE_DATA_BIT_5;
431
+ end
432
+ end
433
+
434
+ STATE_DATA_BIT_5:
435
+ begin
436
+ if(clk_div == 0)
437
+ begin
438
+ state_next <= STATE_DATA_BIT_6;
439
+ end
440
+ end
441
+
442
+ STATE_DATA_BIT_6:
443
+ begin
444
+ if(clk_div == 0)
445
+ begin
446
+ state_next <= STATE_DATA_BIT_7;
447
+ end
448
+ end
449
+
450
+ STATE_DATA_BIT_7:
451
+ begin
452
+ if(clk_div == 0)
453
+ begin
454
+ state_next <= STATE_DATA_BIT_8;
455
+ end
456
+ end
457
+
458
+ STATE_DATA_BIT_8:
459
+ begin
460
+ if(clk_div == 0)
461
+ begin
462
+ state_next <= STATE_DATA_ACK;
463
+ end
464
+ end
465
+
466
+ STATE_DATA_ACK:
467
+ begin
468
+ if(clk_div == 0)
469
+ begin
470
+ state_next <= STATE_STOP;
471
+ end
472
+ end
473
+
474
+ ////////////////////////////////
475
+ // STATE_DATA_ACK_2:
476
+ // begin
477
+ // if(clk_div == 1)
478
+ // begin
479
+ // state_next <= STATE_STOP;
480
+ // end
481
+ // end
482
+ ////////////////////////////////
483
+
484
+ STATE_STOP:
485
+ begin
486
+ if(clk_div == 1)
487
+ begin
488
+ state_next <= STATE_STOP_1;
489
+ end
490
+ end
491
+
492
+ STATE_STOP_1:
493
+ begin
494
+ if(clk_div == 0)
495
+ begin
496
+ state_next <= STATE_IDLE;
497
+ end
498
+ end
499
+
500
+ STATE_STOP_2:
501
+ begin
502
+ if(clk_div == 1)
503
+ begin
504
+ state_next <= STATE_IDLE;
505
+ end
506
+ end
507
+
508
+ endcase
509
+ end
510
+ end
511
+
512
+ always@(negedge clk_div_2)
513
+ begin
514
+ if(reset_n == 1'b0)
515
+ begin
516
+ sda <= 1'b1;
517
+ sda_oe <= 1'b1;
518
+ scl_output_enable <= 1'b0;
519
+ ready <= 1;
520
+ success <= 0;
521
+ end
522
+ else
523
+ begin
524
+ case(state_next)
525
+ STATE_IDLE:
526
+ begin
527
+ sda <= 1'b1;
528
+ sda_oe <= 1'b1;
529
+ scl_output_enable <= 1'b0;
530
+ ready <= 1;
531
+ success <= 0;
532
+ scl_output_zero = 0;
533
+ end
534
+
535
+ STATE_ADDRESS_START:
536
+ begin
537
+ if(clk_div == 0)
538
+ begin
539
+ scl_output_zero <= 0;
540
+ scl_output_enable <= 0;
541
+ sda_oe <= 1;
542
+ sda <= 0;
543
+ ready <= 0;
544
+ success <= 0;
545
+ end
546
+ end
547
+
548
+ STATE_ADDRESS_START_2:
549
+ begin
550
+ if(clk_div == 1)
551
+ begin
552
+ scl_output_zero <= 1;
553
+ scl_output_enable <= 0;
554
+ sda_oe <= 1;
555
+ sda <= 0;
556
+ ready <= 0;
557
+ success <= 0;
558
+ end
559
+ end
560
+
561
+ STATE_ADDRESS_START_3:
562
+ begin
563
+ if(clk_div == 0)
564
+ begin
565
+ scl_output_zero <= 0;
566
+ scl_output_enable <= 1;
567
+ sda_oe <= 1;
568
+ sda <= slave_address[7];
569
+ ready <= 0;
570
+ success <= 0;
571
+ end
572
+ end
573
+
574
+ STATE_ADDRESS_BIT_1:
575
+ begin
576
+ if(clk_div == 0)
577
+ begin
578
+ scl_output_zero <= 0;
579
+ scl_output_enable <= 1;
580
+ sda_oe <= 1;
581
+ sda <= slave_address[6];
582
+ ready <= 0;
583
+ success <= 0;
584
+ end
585
+ end
586
+
587
+ STATE_ADDRESS_BIT_2:
588
+ begin
589
+ if(clk_div == 0)
590
+ begin
591
+ scl_output_zero <= 0;
592
+ scl_output_enable <= 1;
593
+ sda_oe <= 1;
594
+ sda <= slave_address[5];
595
+ ready <= 0;
596
+ success <= 0;
597
+ end
598
+ end
599
+
600
+ STATE_ADDRESS_BIT_3:
601
+ begin
602
+ if(clk_div == 0)
603
+ begin
604
+ scl_output_zero <= 0;
605
+ scl_output_enable <= 1;
606
+ sda_oe <= 1;
607
+ sda <= slave_address[4];
608
+ ready <= 0;
609
+ success <= 0;
610
+ end
611
+ end
612
+
613
+ STATE_ADDRESS_BIT_4:
614
+ begin
615
+ if(clk_div == 0)
616
+ begin
617
+ scl_output_zero <= 0;
618
+ scl_output_enable <= 1;
619
+ sda_oe <= 1;
620
+ sda <= slave_address[3];
621
+ ready <= 0;
622
+ success <= 0;
623
+ end
624
+ end
625
+
626
+ STATE_ADDRESS_BIT_5:
627
+ begin
628
+ if(clk_div == 0)
629
+ begin
630
+ scl_output_zero <= 0;
631
+ scl_output_enable <= 1;
632
+ sda_oe <= 1;
633
+ sda <= slave_address[2];
634
+ ready <= 0;
635
+ success <= 0;
636
+ end
637
+ end
638
+
639
+ STATE_ADDRESS_BIT_6:
640
+ begin
641
+ if(clk_div == 0)
642
+ begin
643
+ scl_output_zero <= 0;
644
+ scl_output_enable <= 1;
645
+ sda_oe <= 1;
646
+ sda <= slave_address[1];
647
+ ready <= 0;
648
+ success <= 0;
649
+ end
650
+ end
651
+
652
+ STATE_ADDRESS_BIT_7:
653
+ begin
654
+ if(clk_div == 0)
655
+ begin
656
+ scl_output_zero <= 0;
657
+ scl_output_enable <= 1;
658
+ sda_oe <= 1;
659
+ sda <= slave_address[0];
660
+ ready <= 0;
661
+ success <= 0;
662
+ end
663
+ end
664
+
665
+ STATE_ADDRESS_BIT_8:
666
+ begin
667
+ if(clk_div == 0)
668
+ begin
669
+ scl_output_zero <= 0;
670
+ ready <= 0;
671
+ scl_output_enable <= 1;
672
+ sda_oe = 0;
673
+ sda <= 0;
674
+ success <= 0;
675
+ end
676
+ end
677
+
678
+ STATE_ADDRESS_ACK:
679
+ begin
680
+ if(clk_div == 0)
681
+ begin
682
+ if(ack_ok == 1'b1)
683
+ begin
684
+ scl_output_zero <= 1;
685
+ ready <= 0;
686
+ sda_oe <= 1'b1;
687
+ scl_output_enable <= 0;
688
+ sda <= 0;
689
+ success <= 0;
690
+ end
691
+ else
692
+ begin
693
+ sda_oe <= 1'b1;
694
+ sda <= 1'b0;
695
+ scl_output_enable = 1'b0;
696
+ ready <= 0;
697
+ success <= 0;
698
+ scl_output_zero <= 1;
699
+ end
700
+ end
701
+ end
702
+
703
+ ////////////////////////////////
704
+ // STATE_ADDRESS_ACK_2:
705
+ // begin
706
+ // if(clk_div == 1)
707
+ // begin
708
+ // ready <= 0;
709
+ // scl_output_enable <= 1;
710
+ // sda_oe = 1;
711
+ // sda <= 0;
712
+ // success <= 0;
713
+ // end
714
+ // end
715
+ //////////////////////////////
716
+
717
+ STATE_TRANSIT_1:
718
+ begin
719
+ if(clk_div == 0)
720
+ begin
721
+ scl_output_zero <= 0;
722
+ scl_output_enable <= 1;
723
+ sda_oe <= 1;
724
+ sda <= slave_reg_address[7];
725
+ ready <= 0;
726
+ success <= 0;
727
+ end
728
+ end
729
+
730
+ STATE_REG_BIT_1:
731
+ begin
732
+ if(clk_div == 0)
733
+ begin
734
+ scl_output_zero <= 0;
735
+ scl_output_enable <= 1;
736
+ sda_oe <= 1;
737
+ sda <= slave_reg_address[6];
738
+ ready <= 0;
739
+ success <= 0;
740
+ end
741
+ end
742
+
743
+ STATE_REG_BIT_2:
744
+ begin
745
+ if(clk_div == 0)
746
+ begin
747
+ scl_output_zero <= 0;
748
+ scl_output_enable <= 1;
749
+ sda_oe <= 1;
750
+ sda <= slave_reg_address[5];
751
+ ready <= 0;
752
+ success <= 0;
753
+ end
754
+ end
755
+
756
+ STATE_REG_BIT_3:
757
+ begin
758
+ if(clk_div == 0)
759
+ begin
760
+ scl_output_enable <= 1;
761
+ sda_oe <= 1;
762
+ sda <= slave_reg_address[4];
763
+ ready <= 0;
764
+ success <= 0;
765
+ scl_output_zero <= 0;
766
+ end
767
+ end
768
+
769
+ STATE_REG_BIT_4:
770
+ begin
771
+ if(clk_div == 0)
772
+ begin
773
+ scl_output_enable <= 1;
774
+ sda_oe <= 1;
775
+ sda <= slave_reg_address[3];
776
+ ready <= 0;
777
+ success <= 0;
778
+ scl_output_zero <= 0;
779
+ end
780
+ end
781
+
782
+ STATE_REG_BIT_5:
783
+ begin
784
+ if(clk_div == 0)
785
+ begin
786
+ scl_output_enable <= 1;
787
+ sda_oe <= 1;
788
+ sda <= slave_reg_address[2];
789
+ ready <= 0;
790
+ success <= 0;
791
+ scl_output_zero <= 0;
792
+ end
793
+ end
794
+
795
+ STATE_REG_BIT_6:
796
+ begin
797
+ if(clk_div == 0)
798
+ begin
799
+ scl_output_enable <= 1;
800
+ sda_oe <= 1;
801
+ sda <= slave_reg_address[1];
802
+ ready <= 0;
803
+ success <= 0;
804
+ scl_output_zero <= 0;
805
+ end
806
+ end
807
+
808
+ STATE_REG_BIT_7:
809
+ begin
810
+ if(clk_div == 0)
811
+ begin
812
+ scl_output_enable <= 1;
813
+ sda_oe <= 1;
814
+ sda <= slave_reg_address[0];
815
+ ready <= 0;
816
+ success <= 0;
817
+ scl_output_zero <= 0;
818
+ end
819
+ end
820
+
821
+ STATE_REG_BIT_8:
822
+ begin
823
+ if(clk_div == 0)
824
+ begin
825
+ ready <= 0;
826
+ scl_output_enable <= 1;
827
+ sda_oe = 0;
828
+ sda <= 0;
829
+ success <= 0;
830
+ scl_output_zero <= 0;
831
+ end
832
+ end
833
+
834
+ STATE_REG_ACK:
835
+ begin
836
+ if(clk_div == 0)
837
+ begin
838
+ if(ack_ok == 1'b1)
839
+ begin
840
+ ready <= 0;
841
+ sda_oe <= 1'b1;
842
+ scl_output_enable <= 0;
843
+ sda <= 0;
844
+ success <= 0;
845
+ scl_output_zero <= 1;
846
+ end
847
+ else
848
+ begin
849
+ sda_oe <= 1'b1;
850
+ sda <= 1'b0;
851
+ scl_output_enable = 1'b0;
852
+ ready <= 0;
853
+ success <= 0;
854
+ scl_output_zero <= 1;
855
+ end
856
+ end
857
+ end
858
+
859
+ // STATE_REG_ACK_2:
860
+ // begin
861
+ // ready <= 0;
862
+ // scl_output_enable <= 0;
863
+ // sda_oe = 0;
864
+ // sda <= 0;
865
+ // success <= 0;
866
+ // end
867
+
868
+ STATE_TRANSIT_2:
869
+ begin
870
+ if(clk_div == 0)
871
+ begin
872
+ scl_output_enable <= 1;
873
+ sda_oe <= 1;
874
+ sda <= slave_data_1[7];
875
+ ready <= 0;
876
+ success <= 0;
877
+ scl_output_zero <= 0;
878
+ end
879
+ end
880
+
881
+ STATE_DATA_BIT_1:
882
+ begin
883
+ if(clk_div == 0)
884
+ begin
885
+ scl_output_enable <= 1;
886
+ sda_oe <= 1;
887
+ sda <= slave_data_1[6];
888
+ ready <= 0;
889
+ success <= 0;
890
+ scl_output_zero <= 0;
891
+ end
892
+ end
893
+
894
+ STATE_DATA_BIT_2:
895
+ begin
896
+ if(clk_div == 0)
897
+ begin
898
+ scl_output_enable <= 1;
899
+ sda_oe <= 1;
900
+ sda <= slave_data_1[5];
901
+ ready <= 0;
902
+ success <= 0;
903
+ scl_output_zero <= 0;
904
+ end
905
+ end
906
+
907
+ STATE_DATA_BIT_3:
908
+ begin
909
+ if(clk_div == 0)
910
+ begin
911
+ scl_output_enable <= 1;
912
+ sda_oe <= 1;
913
+ sda <= slave_data_1[4];
914
+ ready <= 0;
915
+ success <= 0;
916
+ scl_output_zero <= 0;
917
+ end
918
+ end
919
+
920
+ STATE_DATA_BIT_4:
921
+ begin
922
+ if(clk_div == 0)
923
+ begin
924
+ scl_output_enable <= 1;
925
+ sda_oe <= 1;
926
+ sda <= slave_data_1[3];
927
+ ready <= 0;
928
+ success <= 0;
929
+ scl_output_zero <= 0;
930
+ end
931
+ end
932
+
933
+ STATE_DATA_BIT_5:
934
+ begin
935
+ if(clk_div == 0)
936
+ begin
937
+ scl_output_enable <= 1;
938
+ sda_oe <= 1;
939
+ sda <= slave_data_1[2];
940
+ ready <= 0;
941
+ success <= 0;
942
+ scl_output_zero <= 0;
943
+ end
944
+ end
945
+
946
+ STATE_DATA_BIT_6:
947
+ begin
948
+ if(clk_div == 0)
949
+ begin
950
+ scl_output_enable <= 1;
951
+ sda_oe <= 1;
952
+ sda <= slave_data_1[1];
953
+ ready <= 0;
954
+ success <= 0;
955
+ scl_output_zero <= 0;
956
+ end
957
+ end
958
+
959
+ STATE_DATA_BIT_7:
960
+ begin
961
+ if(clk_div == 0)
962
+ begin
963
+ scl_output_enable <= 1;
964
+ sda_oe <= 1;
965
+ sda <= slave_data_1[0];
966
+ ready <= 0;
967
+ success <= 0;
968
+ scl_output_zero <= 0;
969
+ end
970
+ end
971
+
972
+ STATE_DATA_BIT_8:
973
+ begin
974
+ if(clk_div == 0)
975
+ begin
976
+ ready <= 0;
977
+ scl_output_enable <= 1;
978
+ sda_oe <= 0;
979
+ sda <= 0;
980
+ success <= 0;
981
+ scl_output_zero <= 0;
982
+ end
983
+ end
984
+
985
+ STATE_DATA_ACK:
986
+ begin
987
+ if(clk_div == 0)
988
+ begin
989
+ if(ack_ok == 1'b1)
990
+ begin
991
+ sda_oe <= 1'b1;
992
+ sda <= 1'b0;
993
+ scl_output_enable = 1'b1;
994
+ ready <= 0;
995
+ scl_output_zero = 1;
996
+
997
+ success <= 1;
998
+ end
999
+ else
1000
+ begin
1001
+ sda_oe <= 1'b1;
1002
+ sda <= 1'b0;
1003
+ scl_output_enable = 1'b0;
1004
+ ready <= 0;
1005
+ success <= 0;
1006
+ scl_output_zero = 1;
1007
+ end
1008
+ end
1009
+ end
1010
+
1011
+ // STATE_DATA_ACK_2:
1012
+ // begin
1013
+ // ready <= 0;
1014
+ // scl_output_enable <= 0;
1015
+ // sda_oe = 0;
1016
+ // sda <= 0;
1017
+ // success <= 0;
1018
+ // end
1019
+
1020
+ STATE_STOP:
1021
+ begin
1022
+ if(clk_div == 1)
1023
+ begin
1024
+ ready <= 0;
1025
+ sda_oe <= 1'b1;
1026
+ sda <= 1'b0;
1027
+ scl_output_enable <= 1'b0;
1028
+ success <= 0;
1029
+ scl_output_zero <= 0;
1030
+ end
1031
+ end
1032
+
1033
+ STATE_STOP_1:
1034
+ begin
1035
+ if(clk_div == 0)
1036
+ begin
1037
+ ready <= 0;
1038
+ sda <= 1'b1;
1039
+ sda_oe <= 1'b1;
1040
+ scl_output_enable = 1'b0;
1041
+ success <= 0;
1042
+ scl_output_zero <= 0;
1043
+ end
1044
+ end
1045
+
1046
+ STATE_STOP_2:
1047
+ begin
1048
+ if(clk_div == 1)
1049
+ begin
1050
+
1051
+ end
1052
+ end
1053
+
1054
+ default:
1055
+ begin
1056
+ sda <= 1'b1;
1057
+ sda_oe <= 1'b1;
1058
+ scl_output_enable <= 1'b0;
1059
+ ready <= 1;
1060
+ scl_output_zero <= 0;
1061
+ success <= 0;
1062
+ end
1063
+
1064
+ endcase
1065
+ end
1066
+ end
1067
+
1068
+
1069
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/sccb_v2/I2C_Interface.v ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////
2
+ // I2C_Interface.v
3
+ //
4
+ // Author: Thanh Tien Truong
5
+ //
6
+ // Description:
7
+ // ------------
8
+ // SCCB interface to communicate with OV7670
9
+ // - Implementing two-wire data transmission of SCCB protocol
10
+ // - Using 3-phase write transmission cycle of SCCB protocol
11
+ //
12
+ //////////////////////////////////////////////////////////////////////////////////////////////////////
13
+ `include "global.h"
14
+ `ifndef SCCB_V1
15
+ module I2C_Interface (
16
+ input clk, // 50Mhz clock signal
17
+ inout siod, // Data signal for SCCB
18
+ output sioc, // Clock signal for SCCB
19
+ output taken, // Flag to go to next address of LUT
20
+ input send, // Flag to indicate if configuration is finshed
21
+ input [7:0] rega, // Resgister address
22
+ input [7:0] value); // Data to write into a regsiter address
23
+
24
+
25
+ // Internal signals
26
+ reg [7:0] divider = 8'b00000001;
27
+ reg [31:0] busy_sr = {32{1'b0}};
28
+ reg [31:0] data_sr = {32{1'b1}};
29
+ reg sioc_temp;
30
+ reg taken_temp;
31
+ reg siod_temp;
32
+
33
+ // ID of an OV7670 for SCCB protocol
34
+ // localparam id = 8'h42;
35
+ // ID of an OV2640 for SCCB protocol
36
+ localparam id = 8'h60;
37
+
38
+ // Assign value for outputs
39
+ assign siod = siod_temp;
40
+ assign sioc = sioc_temp;
41
+ assign taken = taken_temp;
42
+
43
+ always @ (busy_sr or data_sr[31]) begin
44
+ // when the bus is idle SIOD must be tri-state
45
+ if(busy_sr[11:10] == 2'b10 || busy_sr[20:19] == 2'b10 || busy_sr[29:28] == 2'b10) begin
46
+ siod_temp <= 1'bZ;
47
+ end
48
+ // else SIOD will be driven my master (FPGA board)
49
+ else begin
50
+ siod_temp <= data_sr[31];
51
+ end
52
+ end
53
+
54
+ always @ (posedge clk) begin
55
+ taken_temp <= 1'b0;
56
+
57
+ // If all 31 bits are transmitted
58
+ if(busy_sr[31] == 0) begin
59
+ // Assert SIOC high for starting new transmission
60
+ sioc_temp <= 1;
61
+
62
+ // If New data is arrived from LUT
63
+ if(send == 1) begin
64
+ if(divider == 8'b00000000) begin
65
+ // Create an data to send through the data signal of the SCCB
66
+ // The data is created using 3-phase write transmission cycle of SCCB protocol
67
+ //
68
+ // Data:
69
+ // 3'b100 --> SIOD will go from 1 to 0 to indicate a start transmission
70
+ // the last bit is an don't care bit
71
+ // id --> the ID of a slave (8'h60). The last bit of the slave is 0 inidicate a write transaction
72
+ // 1'b0 --> don't care bit to seperate phases
73
+ // rega --> register address that want to write into
74
+ // 1'b0 --> don't care bit to seperate phases
75
+ // value --> data to write into the register address
76
+ // 1'b0 --> don't care bit to seperate phases
77
+ // 2'b01 --> SIOD will go from 0 to 1 to indicate a stop tranmission
78
+
79
+ data_sr <= {3'b100, id, 1'b0, rega, 1'b0, value, 1'b0, 2'b01};
80
+ busy_sr <= {3'b111, 9'b111111111, 9'b111111111, 9'b111111111, 2'b11};
81
+ taken_temp <= 1'b1;
82
+ end
83
+ else begin
84
+ divider <= divider + 1;
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ // Implement two-write data transmission of SCCB protocol
91
+ else begin
92
+ case ({busy_sr[31:29],busy_sr[2:0]}) // Checking for the start and stop condition
93
+ // For START condition
94
+ 6'b111_111: begin // bit 31th of data_sr is transmitted, SIOC must be high
95
+ case (divider[7:6]) // --> SIOD goes from tri-state to high
96
+ 2'b00: sioc_temp <= 1;
97
+ 2'b01: sioc_temp <= 1;
98
+ 2'b10: sioc_temp <= 1;
99
+ default: sioc_temp <= 1;
100
+ endcase
101
+ end
102
+
103
+ 6'b111_110: begin // bit 30th of data_sr is transmitted
104
+ case (divider[7:6]) // --> SIOD goes from high to low, SIOC must be high
105
+ 2'b00: sioc_temp <= 1; // --> complete START condition
106
+ 2'b01: sioc_temp <= 1;
107
+ 2'b10: sioc_temp <= 1;
108
+ default: sioc_temp <= 1;
109
+ endcase
110
+ end
111
+
112
+ 6'b111_100: begin // bit 29th of data_sr is transmitted (don't care bit)
113
+ case (divider[7:6]) // --> SIOD goes from tri-state to high, then high to low
114
+ 2'b00: sioc_temp <= 0; // after SIOC goes from high to low
115
+ 2'b01: sioc_temp <= 0; // --> Ready for first transmission from Master to Slave
116
+ 2'b10: sioc_temp <= 0;
117
+ default: sioc_temp <= 0;
118
+ endcase
119
+ end
120
+
121
+ // For STOP condition
122
+ 6'b110_000: begin // bit 2nd of data_sr is transmitted (don't care bit)
123
+ case (divider[7:6]) // SIOC waits for 1 clock cyle of 200Khz then go high
124
+ 2'b00: sioc_temp <= 0;
125
+ 2'b01: sioc_temp <= 1;
126
+ 2'b10: sioc_temp <= 1;
127
+ default: sioc_temp <= 1;
128
+ endcase
129
+ end
130
+
131
+ 6'b100_000: begin // bit 1st of data_sr is transmitted
132
+ case (divider[7:6]) // SIOD is low
133
+ 2'b00: sioc_temp <= 1; // SIOC must be high
134
+ 2'b01: sioc_temp <= 1;
135
+ 2'b10: sioc_temp <= 1;
136
+ default: sioc_temp <= 1;
137
+ endcase
138
+ end
139
+
140
+ 6'b000_000: begin // bit 0th of data_sr is transmitted
141
+ case (divider[7:6]) // SIOD is high
142
+ 2'b00: sioc_temp <= 1; // --> SIOD goes from low to high while SIOC is high
143
+ 2'b01: sioc_temp <= 1; // --> complete STOP condition for SCCB protocol
144
+ 2'b10: sioc_temp <= 1;
145
+ default: sioc_temp <= 1;
146
+ endcase
147
+ end
148
+
149
+ // Between START and STOP condition
150
+ // SIOC is high on 2 cycles of 400Khz and low on 2 cycle of 400Khz
151
+ // --> SIOC is 200Khz
152
+ default: begin
153
+ case (divider[7:6])
154
+ 2'b00: sioc_temp <= 0;
155
+ 2'b01: sioc_temp <= 1;
156
+ 2'b10: sioc_temp <= 1;
157
+ default: sioc_temp <= 0;
158
+ endcase
159
+ end
160
+ endcase
161
+
162
+ // Create a frequency for SCCB with is 200KHz
163
+ if(divider == 8'b11111111) begin
164
+ busy_sr <= {busy_sr[30:0], 1'b0}; // Update number of bit that get transmitted
165
+ data_sr <= {data_sr[30:0], 1'b1}; // Update new bit 31th by bit 30th
166
+ divider <= {8{1'b0}}; // Reset counter for clock divider
167
+ end
168
+ else begin
169
+ divider <= divider + 1;
170
+ end
171
+
172
+ end
173
+ end
174
+ endmodule
175
+ `endif
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/sccb_v2/OV7670_Controller.v ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //////////////////////////////////////////////////////////////////////////////////
2
+ // OV7670_Controller.v
3
+ //
4
+ // Author: Thanh Tien Truong
5
+ //
6
+ // Description:
7
+ // ------------
8
+ // - Sending data to OV7670 registers through SCCB interface
9
+ // to configure the mode of the OV7670
10
+ //
11
+ // - The module has 2 instances:
12
+ // OV7670_Registers - Like a LUT containing all the registers address
13
+ // and data to write into a registers
14
+ // I2C_Interface - SCCB interface to communicate with OV7670
15
+ //
16
+ //////////////////////////////////////////////////////////////////////////////////
17
+ `include "global.h"
18
+ `ifndef SCCB_V1
19
+ module OV7670_Controller (
20
+ input clk, // 50Mhz clock signal
21
+ input resend, // Reset signal
22
+ output config_finished, // Flag to indicate that the configuration is finished
23
+ output sioc, // SCCB interface - clock signal
24
+ inout siod, // SCCB interface - data signal
25
+ output reset, // RESET signal for OV7670
26
+ output pwdn // PWDN signal for OV7670
27
+ );
28
+
29
+ // Internal signals
30
+ wire [15:0] command;
31
+ wire finished;
32
+ wire taken;
33
+ reg send = 0;
34
+
35
+ // Signal for testing
36
+ assign config_finished = finished;
37
+
38
+ // Signals for RESET and PWDN OV7670
39
+ assign reset = 1'b1;
40
+ assign pwdn = 1'b0;
41
+
42
+ // Signal to indicate that the configuration is finshied
43
+ always @ (finished) begin
44
+ send = ~finished;
45
+ end
46
+
47
+ // Create an instance of a LUT table
48
+ OV7670_Registers u_OV7670_Registers(
49
+ .clk(clk), // 50Mhz clock signal
50
+ .advance(taken), // Flag to advance to next register
51
+ .command(command), // register value and data for OV7670
52
+ .finished(finished), // Flag to indicate the configuration is finshed
53
+ .resend(resend) // Re-configure flag for OV7670
54
+ );
55
+
56
+ // Create an instance of a SCCB interface
57
+ I2C_Interface u_I2C_Interface(
58
+ .clk(clk), // 50Mhz clock signal
59
+ .taken(taken), // Flag to advance to next register
60
+ .siod(siod), // Clock signal for SCCB interface
61
+ .sioc(sioc), // Data signal for SCCB interface
62
+ .send(send), // Continue to configure OV7670
63
+ .rega(command[15:8]), // Register address
64
+ .value(command[7:0]) // Data to write into register
65
+ );
66
+
67
+ endmodule
68
+ `endif
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/sccb_v2/OV7670_Registers.v ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //////////////////////////////////////////////////////////////////////////////////
2
+ // OV7670_Registers.v
3
+ //
4
+ // Author: Thanh Tien Truong
5
+ //
6
+ // Description:
7
+ // ------------
8
+ // LUT containing all the registers address and values
9
+ //
10
+ //////////////////////////////////////////////////////////////////////////////////
11
+ `include "global.h"
12
+
13
+ `ifndef SCCB_V1
14
+ module OV7670_Registers (
15
+ input clk,
16
+ input resend,
17
+ input advance,
18
+ output [15:0] command,
19
+ output finished
20
+ );
21
+
22
+ // Internal signals
23
+ reg [15:0] sreg;
24
+ reg finished_temp;
25
+ reg [7:0] address = {8{1'b0}};
26
+
27
+ // Assign values to outputs
28
+ assign command = sreg;
29
+ assign finished = finished_temp;
30
+
31
+ // When register and value is FFFF
32
+ // a flag is asserted indicating the configuration is finished
33
+ always @ (sreg) begin
34
+ if(sreg == 16'hFFFF) begin
35
+ finished_temp <= 1;
36
+ end
37
+ else begin
38
+ finished_temp <= 0;
39
+ end
40
+ end
41
+
42
+ // Get value out of the LUT
43
+ always @ (posedge clk) begin
44
+ if(resend == 0) begin // reset the configuration
45
+ address <= {8{1'b0}};
46
+ end
47
+ else if(advance == 1) begin // Get the next value
48
+ address <= address+1;
49
+ end
50
+
51
+ case (address)
52
+
53
+ 0 : sreg <= 16'hff_01;
54
+ 1 : sreg <= 16'h12_80;
55
+ 2 : sreg <= 16'hff_00;
56
+ 3 : sreg <= 16'h2c_ff;
57
+ 4 : sreg <= 16'h2e_df;
58
+ 5 : sreg <= 16'hff_01;
59
+ 6 : sreg <= 16'h3c_32;
60
+ 7 : sreg <= 16'h11_00;
61
+ 8 : sreg <= 16'h09_02;
62
+ 9 : sreg <= 16'h04_d8;
63
+ 10 : sreg <= 16'h13_e5;
64
+ 11 : sreg <= 16'h14_48;
65
+ 12 : sreg <= 16'h2c_0c;
66
+ 13 : sreg <= 16'h33_78;
67
+ 14 : sreg <= 16'h3a_33;
68
+ 15 : sreg <= 16'h3b_fb;
69
+ 16 : sreg <= 16'h3e_00;
70
+ 17 : sreg <= 16'h43_11;
71
+ 18 : sreg <= 16'h16_10;
72
+ 19 : sreg <= 16'h39_92;
73
+ 20 : sreg <= 16'h35_da;
74
+ 21 : sreg <= 16'h22_1a;
75
+ 22 : sreg <= 16'h37_c3;
76
+ 23 : sreg <= 16'h23_00;
77
+ 24 : sreg <= 16'h34_c0;
78
+ 25 : sreg <= 16'h36_1a;
79
+ 26 : sreg <= 16'h06_88;
80
+ 27 : sreg <= 16'h07_c0;
81
+ 28 : sreg <= 16'h0d_87;
82
+ 29 : sreg <= 16'h0e_41;
83
+ 30 : sreg <= 16'h4c_00;
84
+ 31 : sreg <= 16'h48_00;
85
+ 32 : sreg <= 16'h5b_00;
86
+ 33 : sreg <= 16'h42_03;
87
+ 34 : sreg <= 16'h4a_81;
88
+ 35 : sreg <= 16'h21_99;
89
+ 36 : sreg <= 16'h24_40;
90
+ 37 : sreg <= 16'h25_38;
91
+ 38 : sreg <= 16'h26_82;
92
+ 39 : sreg <= 16'h5c_00;
93
+ 40 : sreg <= 16'h63_00;
94
+ 41 : sreg <= 16'h46_22;
95
+ 42 : sreg <= 16'h0c_3c;
96
+ 43 : sreg <= 16'h61_70;
97
+ 44 : sreg <= 16'h62_80;
98
+ 45 : sreg <= 16'h7c_05;
99
+ 46 : sreg <= 16'h20_80;
100
+ 47 : sreg <= 16'h28_30;
101
+ 48 : sreg <= 16'h6c_00;
102
+ 49 : sreg <= 16'h6d_80;
103
+ 50 : sreg <= 16'h6e_00;
104
+ 51 : sreg <= 16'h70_02;
105
+ 52 : sreg <= 16'h71_94;
106
+ 53 : sreg <= 16'h73_c1;
107
+ 54 : sreg <= 16'h3d_34;
108
+ 55 : sreg <= 16'h5a_57;
109
+ 56 : sreg <= 16'h12_40;
110
+ 57 : sreg <= 16'h17_11;
111
+ 58 : sreg <= 16'h18_43;
112
+ 59 : sreg <= 16'h19_00;
113
+ 60 : sreg <= 16'h1a_4b;
114
+ 61 : sreg <= 16'h32_09;
115
+ 62 : sreg <= 16'h37_c0;
116
+ 63 : sreg <= 16'h4f_ca;
117
+ 64 : sreg <= 16'h50_a8;
118
+ 65 : sreg <= 16'h5a_23;
119
+ 66 : sreg <= 16'h6d_00;
120
+ 67 : sreg <= 16'h3d_38;
121
+ 68 : sreg <= 16'hff_00;
122
+ 69 : sreg <= 16'he5_7f;
123
+ 70 : sreg <= 16'hf9_c0;
124
+ 71 : sreg <= 16'h41_24;
125
+ 72 : sreg <= 16'he0_14;
126
+ 73 : sreg <= 16'h76_ff;
127
+ 74 : sreg <= 16'h33_a0;
128
+ 75 : sreg <= 16'h42_20;
129
+ 76 : sreg <= 16'h43_18;
130
+ 77 : sreg <= 16'h4c_00;
131
+ 78 : sreg <= 16'h87_d5;
132
+ 79 : sreg <= 16'h88_3f;
133
+ 80 : sreg <= 16'hd7_03;
134
+ 81 : sreg <= 16'hd9_10;
135
+ 82 : sreg <= 16'hd3_82;
136
+ 83 : sreg <= 16'hc8_08;
137
+ 84 : sreg <= 16'hc9_80;
138
+ 85 : sreg <= 16'h7c_00;
139
+ 86 : sreg <= 16'h7d_00;
140
+ 87 : sreg <= 16'h7c_03;
141
+ 88 : sreg <= 16'h7d_48;
142
+ 89 : sreg <= 16'h7d_48;
143
+ 90 : sreg <= 16'h7c_08;
144
+ 91 : sreg <= 16'h7d_20;
145
+ 92 : sreg <= 16'h7d_10;
146
+ 93 : sreg <= 16'h7d_0e;
147
+ 94 : sreg <= 16'h90_00;
148
+ 95 : sreg <= 16'h91_0e;
149
+ 96 : sreg <= 16'h91_1a;
150
+ 97 : sreg <= 16'h91_31;
151
+ 98 : sreg <= 16'h91_5a;
152
+ 99 : sreg <= 16'h91_69;
153
+ 100 : sreg <= 16'h91_75;
154
+ 101 : sreg <= 16'h91_7e;
155
+ 102 : sreg <= 16'h91_88;
156
+ 103 : sreg <= 16'h91_8f;
157
+ 104 : sreg <= 16'h91_96;
158
+ 105 : sreg <= 16'h91_a3;
159
+ 106 : sreg <= 16'h91_af;
160
+ 107 : sreg <= 16'h91_c4;
161
+ 108 : sreg <= 16'h91_d7;
162
+ 109 : sreg <= 16'h91_e8;
163
+ 110 : sreg <= 16'h91_20;
164
+ 111 : sreg <= 16'h92_00;
165
+ 112 : sreg <= 16'h93_06;
166
+ 113 : sreg <= 16'h93_e3;
167
+ 114 : sreg <= 16'h93_05;
168
+ 115 : sreg <= 16'h93_05;
169
+ 116 : sreg <= 16'h93_00;
170
+ 117 : sreg <= 16'h93_04;
171
+ 118 : sreg <= 16'h93_00;
172
+ 119 : sreg <= 16'h93_00;
173
+ 120 : sreg <= 16'h93_00;
174
+ 121 : sreg <= 16'h93_00;
175
+ 122 : sreg <= 16'h93_00;
176
+ 123 : sreg <= 16'h93_00;
177
+ 124 : sreg <= 16'h93_00;
178
+ 125 : sreg <= 16'h96_00;
179
+ 126 : sreg <= 16'h97_08;
180
+ 127 : sreg <= 16'h97_19;
181
+ 128 : sreg <= 16'h97_02;
182
+ 129 : sreg <= 16'h97_0c;
183
+ 130 : sreg <= 16'h97_24;
184
+ 131 : sreg <= 16'h97_30;
185
+ 132 : sreg <= 16'h97_28;
186
+ 133 : sreg <= 16'h97_26;
187
+ 134 : sreg <= 16'h97_02;
188
+ 135 : sreg <= 16'h97_98;
189
+ 136 : sreg <= 16'h97_80;
190
+ 137 : sreg <= 16'h97_00;
191
+ 138 : sreg <= 16'h97_00;
192
+ 139 : sreg <= 16'hc3_ed;
193
+ 140 : sreg <= 16'ha4_00;
194
+ 141 : sreg <= 16'ha8_00;
195
+ 142 : sreg <= 16'hc5_11;
196
+ 143 : sreg <= 16'hc6_51;
197
+ 144 : sreg <= 16'hbf_80;
198
+ 145 : sreg <= 16'hc7_10;
199
+ 146 : sreg <= 16'hb6_66;
200
+ 147 : sreg <= 16'hb8_a5;
201
+ 148 : sreg <= 16'hb7_64;
202
+ 149 : sreg <= 16'hb9_7c;
203
+ 150 : sreg <= 16'hb3_af;
204
+ 151 : sreg <= 16'hb4_97;
205
+ 152 : sreg <= 16'hb5_ff;
206
+ 153 : sreg <= 16'hb0_c5;
207
+ 154 : sreg <= 16'hb1_94;
208
+ 155 : sreg <= 16'hb2_0f;
209
+ 156 : sreg <= 16'hc4_5c;
210
+ 157 : sreg <= 16'hc0_64;
211
+ 158 : sreg <= 16'hc1_4b;
212
+ 159 : sreg <= 16'h8c_00;
213
+ 160 : sreg <= 16'h86_3d;
214
+ 161 : sreg <= 16'h50_00;
215
+ 162 : sreg <= 16'h51_c8;
216
+ 163 : sreg <= 16'h52_96;
217
+ 164 : sreg <= 16'h53_00;
218
+ 165 : sreg <= 16'h54_00;
219
+ 166 : sreg <= 16'h55_00;
220
+ 167 : sreg <= 16'h5a_c8;
221
+ 168 : sreg <= 16'h5b_96;
222
+ 169 : sreg <= 16'h5c_00;
223
+ 170 : sreg <= 16'hd3_02;
224
+ 171 : sreg <= 16'hc3_ed;
225
+ 172 : sreg <= 16'h7f_00;
226
+ 173 : sreg <= 16'hda_09;
227
+ 174 : sreg <= 16'he5_1f;
228
+ 175 : sreg <= 16'he1_67;
229
+ 176 : sreg <= 16'he0_00;
230
+ 177 : sreg <= 16'hdd_7f;
231
+ 178 : sreg <= 16'h05_00;
232
+ 179 : sreg <= 16'hff_00;
233
+ 180 : sreg <= 16'hda_09;
234
+ 181 : sreg <= 16'hd7_03;
235
+ 182 : sreg <= 16'hdf_02;
236
+ 183 : sreg <= 16'h33_a0;
237
+ 184 : sreg <= 16'h3c_00;
238
+ 185 : sreg <= 16'he1_67;
239
+ 186 : sreg <= 16'hff_01;
240
+ 187 : sreg <= 16'he0_00;
241
+ 188 : sreg <= 16'he1_00;
242
+ 189 : sreg <= 16'he5_00;
243
+ 190 : sreg <= 16'hd7_00;
244
+ 191 : sreg <= 16'hda_00;
245
+ 192 : sreg <= 16'he0_00;
246
+ 193 : sreg <= 16'hff_00;
247
+ 194 : sreg <= 16'he0_04;
248
+ 195 : sreg <= 16'h5a_2d;
249
+ 196 : sreg <= 16'h5b_2d;
250
+ 197 : sreg <= 16'h5c_00;
251
+ 198 : sreg <= 16'he0_00;
252
+ // 199 : sreg <= 16'hff_01;
253
+ // 200 : sreg <= 16'h12_42;
254
+
255
+
256
+ default : sreg <= 16'hFF_FF; // End configuration
257
+ endcase
258
+ end
259
+ endmodule
260
+ `endif
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/src/test_cmera.v ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module test_cmera
3
+ (
4
+ input wire CLK_IN, //ϵͳʱ
5
+ input wire RST_N, //λ,Ĭ
6
+ //camera
7
+ input wire CSI_PCLK, //CSIʱ
8
+ output wire CSI_XCLK, //CSIϵͳʱ
9
+ input wire CSI_HREF, //ͬ
10
+ input wire CSI_VSYNC, //֡ͬ
11
+ output wire CSI_PWDN, //ģʽ
12
+ output wire CSI_RST, //λ
13
+ output wire CSI_SOIC, //SCCB,ʱ
14
+ inout wire CSI_SOID, //SCCB,
15
+ input wire [7:0]CSI_D, //
16
+ //lcd
17
+ output wire [7:0] R,
18
+ output wire [7:0] G,
19
+ output wire [7:0] B,
20
+ output wire LCD_CLK,
21
+ output wire LCD_HSYNC,
22
+ output wire LCD_VSYNC,
23
+ output wire LCD_DEN,
24
+ output wire LCD_PWM, //backlight,set to high
25
+ //test
26
+ output wire TESTA,
27
+ output wire TESTB,
28
+ output wire TESTC,
29
+ output wire TESTD,
30
+ output wire TESTE,
31
+ output wire TESTF,
32
+ output wire [0:7]OD
33
+ );
34
+
35
+ wire clk_lcd;
36
+ wire clk_cam;
37
+ wire clk_sccb;
38
+
39
+ ip_pll pll(
40
+ .refclk(CLK_IN), //24M
41
+ .clk0_out(clk_lcd), //lcd clk
42
+ .clk1_out(clk_cam), //12m,for cam xclk
43
+ .clk2_out(clk_sccb) //4m,for sccb init
44
+ );
45
+
46
+ reg init_state;
47
+ wire init_ready;
48
+ wire sda_oe;
49
+ wire sda;
50
+ wire sda_in;
51
+ wire scl;
52
+
53
+ camera_init u_camera_init
54
+ (
55
+ .clk(clk_sccb),
56
+ .reset_n(RST_N),
57
+ .ready(init_ready),
58
+ .sda_oe(sda_oe),
59
+ .sda(sda),
60
+ .sda_in(sda_in),
61
+ .scl(scl)
62
+ );
63
+ assign CSI_SOID = (sda_oe == 1'b1) ? sda : 1'bz;
64
+ assign sda_in = CSI_SOID;
65
+ assign CSI_SOIC = scl;
66
+ assign CSI_PWDN = 1'b0;
67
+ assign CSI_RST = 1'b1;
68
+ //test
69
+ // assign TESTE = (sda_oe == 1'b1) ? sda : 1'bz;
70
+ // assign TESTF = scl;
71
+
72
+ //lcd display
73
+ wire [10:0] hsync_cnt;
74
+ wire [10:0] vsync_cnt;
75
+ wire lcd_rden;
76
+ wire [15:0]lcd_rddat; //lcd read
77
+ wire [15:0]lcd_rdaddr;
78
+
79
+ lcd_sync
80
+ #(
81
+ .IMG_W(200),
82
+ .IMG_H(164),
83
+ .IMG_X(50),
84
+ .IMG_Y(50)
85
+ )
86
+ u_lcd_sync
87
+ (
88
+ .clk (clk_lcd),
89
+ .rest_n (RST_N),
90
+ .lcd_clk (LCD_CLK),
91
+ .lcd_pwm (LCD_PWM),
92
+ .lcd_hsync (LCD_HSYNC),
93
+ .lcd_vsync (LCD_VSYNC),
94
+ .lcd_de (LCD_DEN),
95
+ .hsync_cnt (hsync_cnt),
96
+ .vsync_cnt (vsync_cnt),
97
+ .img_ack (lcd_rden),
98
+ .addr (lcd_rdaddr)
99
+ );
100
+
101
+ wire camera_wrreq,camera_wclk;
102
+ wire [15:0]camera_wrdat;
103
+ wire [19:0]camera_addr;
104
+
105
+ cameraReader u_cameraReader
106
+ (
107
+ .clk(clk_cam),
108
+ .reset_n(RST_N),
109
+ .csi_xclk(CSI_XCLK),
110
+ .csi_pclk(CSI_PCLK),
111
+ .csi_data(CSI_D),
112
+ .csi_vsync(!CSI_VSYNC),
113
+ .csi_hsync(CSI_HREF),
114
+ .data_out(camera_wrdat),
115
+ .wrreq(camera_wrreq),
116
+ .wrclk(camera_wclk),
117
+ .wraddr(camera_addr)
118
+ );
119
+
120
+ img_cache uimg
121
+ (
122
+ //write 45000*8
123
+ .dia(camera_wrdat),
124
+ .addra(camera_addr),
125
+ .cea(camera_wrreq),
126
+ .clka(camera_wclk),
127
+ .rsta(!RST_N),
128
+ //read 22500*16
129
+ .dob(lcd_rddat),
130
+ .addrb(lcd_rdaddr),
131
+ .ceb(lcd_rden),
132
+ .clkb(clk_lcd),
133
+ .rstb(!RST_N)
134
+ );
135
+
136
+ // assign TESTA = fifo_we;
137
+ // assign TESTB = CSI_PCLK;
138
+ // assign TESTC = CSI_VSYNC;
139
+ // assign TESTD = CSI_HREF;
140
+ // assign OD = CSI_D;
141
+
142
+ assign R = lcd_rden ? {lcd_rddat[15:11], lcd_rddat[15:13]} : 8'h00;
143
+ assign G = lcd_rden ? {lcd_rddat[10:5], lcd_rddat[10:9]} : 8'h00;
144
+ assign B = lcd_rden ? {lcd_rddat[4:0], lcd_rddat[4:2]} : 8'h00;
145
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/Imagedata_send.v ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module Imgdata_send(
2
+ input wire clk,
3
+ input wire tft_de,
4
+ input wire hcount,
5
+ input wire vcount,
6
+ output wire img_ack
7
+ );
8
+
9
+
10
+
11
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/UartTx.v ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //--------------------------------------------------------------------------------
2
+ // UartTx.v
3
+ // Konstantin Pavlov, pavlovconst@gmail.com
4
+ //--------------------------------------------------------------------------------
5
+
6
+ // INFO --------------------------------------------------------------------------------
7
+ // Straightforward yet simple UART transmitter implementation for FPGA written in Verilog
8
+ // One stop bit setting is hardcoded
9
+ // Features continuous data output at BAUD levels up to CLK_HZ / 2
10
+ // Features early asynchronous 'busy' set and reset to gain time to prepare new data
11
+ // If multiple UartTX instances should be inferred - make tx_sample_cntr logic common for all TX instances for effective chip area usage
12
+
13
+
14
+ /* --- INSTANTIATION TEMPLATE BEGIN ---
15
+ UartTx UT1 (
16
+ .clk(),
17
+ .nrst( 1'b1 ),
18
+ //.tx_do_sample(),
19
+ .tx_data(),
20
+ .tx_start(),
21
+ .tx_busy(),
22
+ .txd()
23
+ );
24
+ defparam UT1.CLK_HZ = 200_000_000;
25
+ defparam UT1.BAUD = 9600; // max. BAUD is CLK_HZ / 2
26
+ --- INSTANTIATION TEMPLATE END ---*/
27
+
28
+
29
+ module UartTx(clk, nrst, tx_data, tx_start, tx_busy, txd);
30
+ //module UartTx(clk, nrst, tx_do_sample, tx_data, tx_start, tx_busy, txd);
31
+
32
+ parameter CLK_HZ = 200_000_000;
33
+ parameter BAUD = 9600;
34
+ parameter BAUD_DIVISOR = CLK_HZ / BAUD;
35
+
36
+ input wire clk;
37
+ input wire nrst;
38
+ //input wire tx_do_sample;
39
+
40
+ input wire [7:0] tx_data;
41
+ input wire tx_start; // write strobe
42
+ output reg tx_busy = 0;
43
+ output reg txd = 1;
44
+
45
+
46
+ reg [9:0] tx_shifter = 0;
47
+ reg [15:0] tx_sample_cntr = 0;
48
+ always @ (posedge clk) begin
49
+ if ((~nrst) || (tx_sample_cntr[15:0] == 0)) begin
50
+ tx_sample_cntr[15:0] <= (BAUD_DIVISOR-1);
51
+ end else begin
52
+ tx_sample_cntr[15:0] <= tx_sample_cntr[15:0] - 1;
53
+ end
54
+ end
55
+ wire tx_do_sample = (tx_sample_cntr[15:0] == 0);
56
+
57
+
58
+ always @ (posedge clk) begin
59
+ if (~nrst) begin
60
+ tx_busy <= 0;
61
+ tx_shifter[9:0] <= 0;
62
+ txd <= 1;
63
+ end else begin
64
+ if (~tx_busy) begin
65
+ if (tx_start) begin // asynchronous data load and 'busy' set
66
+ tx_shifter[9:0] <= {1'b1,tx_data[7:0],1'b0};
67
+ tx_busy <= 1;
68
+ end
69
+ end else begin
70
+
71
+ if (tx_do_sample) begin // next bit
72
+ {tx_shifter[9:0],txd} <= {tx_shifter[9:0],txd} >> 1; // txd MUST change only on tx_do_sample although data may be loaded earlier
73
+ if (~|tx_shifter[9:1]) begin // early asynchronous 'busy' reset
74
+ tx_busy <= 0; // txd still holds data, but shifter is ready to get new info
75
+ end
76
+ end // tx_do_sample
77
+
78
+ end // ~tx_busy
79
+ end // ~nrst
80
+ end
81
+
82
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/big_lcd.v ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module big_lcd(
2
+
3
+ input clk,
4
+ input reset,
5
+ input [15:0] lcd_readdata,
6
+ output lcd_read,
7
+
8
+ output wire [7:0] R,
9
+ output wire [7:0] G,
10
+ output wire [7:0] B,
11
+ output wire HSYNC,
12
+ output wire VSYNC,
13
+ output wire LCD_CLK
14
+
15
+ );
16
+
17
+ reg [10:0] counter_hs;
18
+ reg [10:0] counter_vs;
19
+
20
+ reg [20:0] pixel_counter;
21
+
22
+ assign LCD_CLK = (reset == 1) ? clk : 0;
23
+
24
+ always@(posedge clk)
25
+ begin
26
+ if(reset == 1'b0)
27
+ begin
28
+ counter_hs <= 0;
29
+ counter_vs <= 0;
30
+ end
31
+ else
32
+ begin
33
+ if(counter_hs == 1055 )
34
+ begin
35
+
36
+ if(counter_vs == 524)
37
+ counter_vs <= 0;
38
+ else
39
+ counter_vs <= counter_vs + 1;
40
+
41
+ counter_hs <= 0;
42
+ end
43
+ else
44
+ counter_hs <= counter_hs + 1;
45
+ end
46
+ end
47
+
48
+ wire data_en;
49
+
50
+ assign lcd_read = (counter_hs >= 42 && counter_hs <= 681 && counter_vs >= 23 && counter_vs < 503) ? 1 : 0;
51
+
52
+ assign data_en = (counter_hs >= 46 && counter_hs <= 686 && counter_vs >= 23 && counter_vs < 503) ? 1 : 0;
53
+
54
+ assign VSYNC = (counter_vs >= 0 && counter_vs < 10) ? 0 : 1;
55
+ assign HSYNC = (counter_hs >= 0 && counter_hs < 10) ? 0 : 1;
56
+
57
+ assign R = data_en == 1 ? {lcd_readdata[15:11], lcd_readdata[15:13]} : 8'hff;
58
+ assign G = data_en == 1 ? {lcd_readdata[10:5], lcd_readdata[10:9]} : 8'h00;
59
+ assign B = data_en == 1 ? {lcd_readdata[4:0], lcd_readdata[4:2]} : 8'h0f;
60
+
61
+
62
+ //always@(posedge clk)
63
+ //begin
64
+ //if(reset == 1'b0)
65
+ // begin
66
+ // pixel_counter <= 0;
67
+ // end
68
+ // else
69
+ // begin
70
+ // if(counter_hs >= 46 && counter_hs <= 686 && counter_vs >= 23 && counter_vs < 503)
71
+ // begin
72
+ // pixel_counter <= pixel_counter + 1;
73
+ // end
74
+ // else
75
+ // if(counter_vs == 504)
76
+ // pixel_counter <= 0;
77
+ // end
78
+ //end
79
+
80
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/cameraReader.v ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module cameraReader
2
+ #(
3
+ parameter x_size = 800,
4
+ parameter y_size = 480
5
+ )
6
+ (
7
+ input clk_in,
8
+ input reset_n,
9
+
10
+ output xclk,
11
+
12
+ input pclk,
13
+ input [7:0] data,
14
+ input vsync,
15
+ input hsync,
16
+
17
+ output reg [15:0] data_out = 0,
18
+ output wire wrreq,
19
+ output wire wrclk
20
+ );
21
+
22
+ reg [19:0] pixel_counter = 0;
23
+
24
+ assign xclk = reset_n == 1 ? clk_in : 0;
25
+
26
+ reg vsync_passed = 0;
27
+ reg write_pixel = 0;
28
+
29
+ reg wrclk1 = 0;
30
+
31
+ //2��Ƶ
32
+ always@(posedge pclk)
33
+ wrclk1 <= ~wrclk1;
34
+
35
+ always@(negedge wrclk1)
36
+ begin
37
+ if(hsync == 1)
38
+ write_pixel <= 1;
39
+ else
40
+ write_pixel <= 0;
41
+ end
42
+
43
+ reg [7:0] subpixel;
44
+ reg [15:0] current_pixel;
45
+
46
+ always@(posedge wrreq )
47
+ begin
48
+ data_out <= current_pixel;
49
+ end
50
+
51
+ always@(posedge pclk)
52
+ begin
53
+ if(reset_n == 0)
54
+ begin
55
+ pixel_counter <= 0;
56
+ vsync_passed <= 0;
57
+ end
58
+ else
59
+ begin
60
+ if(vsync == 1)
61
+ begin
62
+ pixel_counter <= 0;
63
+ vsync_passed <= 1;
64
+ end
65
+ else
66
+ if(hsync == 1 && vsync_passed == 1)
67
+ begin
68
+ if(pixel_counter[0] == 0)
69
+ begin
70
+ pixel_counter <= pixel_counter + 1;
71
+ subpixel <= data;
72
+ end
73
+ else
74
+ begin
75
+ current_pixel <= { subpixel, data};
76
+ pixel_counter <= pixel_counter + 1;
77
+ end
78
+ end
79
+ else
80
+ begin
81
+ if(write_pixel == 1)
82
+ pixel_counter <= pixel_counter + 1;
83
+ else
84
+ pixel_counter <= 0;
85
+ end
86
+ end
87
+ end
88
+
89
+ assign wrreq = write_pixel == 1 && pixel_counter > 2 ? wrclk1 : 0;
90
+
91
+ assign wrclk = wrclk1;
92
+
93
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/div_2.v ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module div_2 (q,clk,reset); // ���q������ʱ��CLK��ͬ����λ�ź�RESET.
2
+ output q;
3
+ input reset;
4
+ input clk;
5
+ reg q;
6
+ always @ (posedge clk or posedge reset)
7
+ if (reset==0)
8
+ q<=1'b0; // �����
9
+ else
10
+ q<=~q; // ����q�źŷ�ת
11
+ endmodule
12
+
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/sdram_ctrl.v ADDED
@@ -0,0 +1,405 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module sys_sdram (
2
+ input wire clk,
3
+ input wire rst_n,
4
+ input wire i_valid,
5
+ output reg o_ready,
6
+ input wire [31:0] i_addr,
7
+ input wire [15:0] i_wdata,
8
+ input wire [3:0] i_wstrb,
9
+ output reg [15:0] o_rdata
10
+ );
11
+
12
+ parameter CLK_CYCLE_NS = 20;
13
+ parameter POWERON_DELAY_NS = 200000;
14
+ parameter REFRESH_INTERVAL_NS = 15000;
15
+ parameter T_RC = 3+1;
16
+ parameter T_RP = 1+1;
17
+ parameter T_WR = 2+1;
18
+ parameter T_MRD = 2+1;
19
+ parameter T_RFC = 3+1;
20
+ parameter T_RCD = 1+1;
21
+ parameter T_RRD = 1+1;
22
+ parameter CL = 3+1;
23
+
24
+ reg sdram_ras_n;
25
+ reg sdram_cas_n;
26
+ reg sdram_we_n;
27
+ reg [10:0] sdram_addr;
28
+ reg [1:0] sdram_ba;
29
+
30
+ wire [15:0] sdram_dq;
31
+ reg [15:0] sdram_dq_r;
32
+ reg sdram_dq_ie;
33
+ assign sdram_dq = sdram_dq_ie ? sdram_dq_r : 'hz;
34
+
35
+ reg sdram_cs_n;
36
+ reg [3:0] sdram_dm;
37
+ reg sdram_cke;
38
+
39
+ /*
40
+ */
41
+ EG_PHY_SDRAM_2M_32 sdr_sdram(
42
+ .clk(clk),
43
+ .ras_n(sdram_ras_n),
44
+ .cas_n(sdram_cas_n),
45
+ .we_n(sdram_we_n),
46
+ .addr(sdram_addr),
47
+ .ba(sdram_ba),
48
+ .dq(sdram_dq),
49
+ .cs_n(sdram_cs_n),
50
+ .dm0(sdram_dm[0]),
51
+ .dm1(sdram_dm[1]),
52
+ .dm2(1'b1),
53
+ .dm3(1'b1),
54
+ .cke(sdram_cke)
55
+ );
56
+
57
+ reg [31:0] counter;
58
+ reg [31:0] counter_refresh;
59
+ // 0: power up wait
60
+ // 1: power up precharge all banks
61
+ // 2: power up auto refresh 2 times
62
+ // 3: power up set mode
63
+ // 4: idle
64
+ // 5: refresh
65
+ // 6: reada
66
+ // 7: writea
67
+ reg [4:0] stage;
68
+
69
+ always @ (posedge clk) begin
70
+ if (!rst_n) begin
71
+ counter <= 0;
72
+ counter_refresh <= 0;
73
+ stage <= 0;
74
+ end
75
+ if (rst_n) begin
76
+ counter_refresh <= counter_refresh + 1;
77
+ if (stage == 'h0) begin
78
+ // nop
79
+ sdram_cke <= 1;
80
+ sdram_cs_n <= 0;
81
+ sdram_ras_n <= 1;
82
+ sdram_cas_n <= 1;
83
+ sdram_we_n <= 1;
84
+
85
+ sdram_dm <= 4'b1;
86
+ // wait for 200us
87
+ if (counter < POWERON_DELAY_NS/CLK_CYCLE_NS) begin
88
+ counter <= counter + 1;
89
+ end else begin
90
+ counter <= 0;
91
+ // nop
92
+ sdram_cke <= 1;
93
+ sdram_cs_n <= 0;
94
+ sdram_ras_n <= 1;
95
+ sdram_cas_n <= 1;
96
+ sdram_we_n <= 1;
97
+ // next stage
98
+ stage <= 1;
99
+ end
100
+ end
101
+ if (stage == 'h1) begin
102
+ if (counter == 0) begin
103
+ // precharge all
104
+ sdram_cke <= 1;
105
+ sdram_addr[10] <= 1;
106
+ sdram_cs_n <= 0;
107
+ sdram_ras_n <= 0;
108
+ sdram_cas_n <= 1;
109
+ sdram_we_n <= 0;
110
+ end else begin
111
+ // nop
112
+ sdram_cke <= 1;
113
+ sdram_cs_n <= 0;
114
+ sdram_ras_n <= 1;
115
+ sdram_cas_n <= 1;
116
+ sdram_we_n <= 1;
117
+ end
118
+ if (counter < T_RP) begin
119
+ counter <= counter + 1;
120
+ end else begin
121
+ counter <= 0;
122
+ // nop
123
+ sdram_cke <= 1;
124
+ sdram_cs_n <= 0;
125
+ sdram_ras_n <= 1;
126
+ sdram_cas_n <= 1;
127
+ sdram_we_n <= 1;
128
+ // next stage
129
+ stage <= 2;
130
+ end
131
+ end
132
+ if (stage == 'h2) begin
133
+ if (counter == 0) begin
134
+ // auto refresh
135
+ sdram_cke <= 1;
136
+ sdram_cs_n <= 0;
137
+ sdram_ras_n <= 0;
138
+ sdram_cas_n <= 0;
139
+ sdram_we_n <= 1;
140
+ end else if (counter == T_RFC) begin
141
+ // auto refresh
142
+ sdram_cke <= 1;
143
+ sdram_cs_n <= 0;
144
+ sdram_ras_n <= 0;
145
+ sdram_cas_n <= 0;
146
+ sdram_we_n <= 1;
147
+ end else begin
148
+ // nop
149
+ sdram_cke <= 1;
150
+ sdram_cs_n <= 0;
151
+ sdram_ras_n <= 1;
152
+ sdram_cas_n <= 1;
153
+ sdram_we_n <= 1;
154
+ end
155
+ if (counter < T_RFC*2) begin
156
+ counter <= counter + 1;
157
+ end else begin
158
+ counter <= 0;
159
+ // nop
160
+ sdram_cke <= 1;
161
+ sdram_cs_n <= 0;
162
+ sdram_ras_n <= 1;
163
+ sdram_cas_n <= 1;
164
+ sdram_we_n <= 1;
165
+ // next stage
166
+ stage <= 3;
167
+ end
168
+ end
169
+ if (stage == 'h3) begin
170
+ if (counter == 0) begin
171
+ // Mode Register Set
172
+ sdram_cke <= 1;
173
+ sdram_cs_n <= 0;
174
+ sdram_ras_n <= 0;
175
+ sdram_cas_n <= 0;
176
+ sdram_we_n <= 0;
177
+
178
+ // reserved
179
+ sdram_ba <= 2'b00;
180
+ sdram_addr[10] <= 1'b0;
181
+ // Write Burst Length: Single Bit
182
+ sdram_addr[9] <= 1;
183
+ // Test Mode: Normal
184
+ sdram_addr[8:7] <= 2'b00;
185
+ // CAS Latency: 3
186
+ sdram_addr[6:4] <= 3'b011;
187
+ // Burst Type: Sequential
188
+ sdram_addr[3] <= 1'b0;
189
+ // Burst Length: 1
190
+ sdram_addr[2:0] <= 3'b000;
191
+ end else begin
192
+ // nop
193
+ sdram_cke <= 1;
194
+ sdram_cs_n <= 0;
195
+ sdram_ras_n <= 1;
196
+ sdram_cas_n <= 1;
197
+ sdram_we_n <= 1;
198
+ end
199
+ if (counter < T_MRD) begin
200
+ counter <= counter + 1;
201
+ end else begin
202
+ counter <= 0;
203
+ counter_refresh <= 0;
204
+ // nop
205
+ sdram_cke <= 1;
206
+ sdram_cs_n <= 0;
207
+ sdram_ras_n <= 1;
208
+ sdram_cas_n <= 1;
209
+ sdram_we_n <= 1;
210
+ // next stage
211
+ stage <= 4;
212
+ end
213
+ end
214
+ if (stage == 'h4) begin
215
+ if (counter_refresh > REFRESH_INTERVAL_NS/CLK_CYCLE_NS) begin
216
+ // goto refresh
217
+ counter <= 0;
218
+ counter_refresh <= 0;
219
+ // nop
220
+ sdram_cke <= 1;
221
+ sdram_cs_n <= 0;
222
+ sdram_ras_n <= 1;
223
+ sdram_cas_n <= 1;
224
+ sdram_we_n <= 1;
225
+ // next stage
226
+ stage <= 5;
227
+ end else if (i_valid) begin
228
+ if (i_wstrb == 'h0) begin
229
+ // goto read
230
+ counter <= 0;
231
+ // nop
232
+ sdram_cke <= 1;
233
+ sdram_cs_n <= 0;
234
+ sdram_ras_n <= 1;
235
+ sdram_cas_n <= 1;
236
+ sdram_we_n <= 1;
237
+ // next stage
238
+ stage <= 6;
239
+ end else begin
240
+ // goto write
241
+ counter <= 0;
242
+ // nop
243
+ sdram_cke <= 1;
244
+ sdram_cs_n <= 0;
245
+ sdram_ras_n <= 1;
246
+ sdram_cas_n <= 1;
247
+ sdram_we_n <= 1;
248
+ // next stage
249
+ stage <= 7;
250
+ end
251
+ end else begin
252
+ // nop
253
+ sdram_cke <= 1;
254
+ sdram_cs_n <= 0;
255
+ sdram_ras_n <= 1;
256
+ sdram_cas_n <= 1;
257
+ sdram_we_n <= 1;
258
+ end
259
+ end
260
+ if (stage == 'h5) begin
261
+ if (counter == 0) begin
262
+ // PrechargeAll
263
+ sdram_cke <= 1;
264
+ sdram_addr[10] <= 1;
265
+ sdram_cs_n <= 0;
266
+ sdram_ras_n <= 0;
267
+ sdram_cas_n <= 1;
268
+ sdram_we_n <= 0;
269
+
270
+ sdram_dm <= 4'b0;
271
+ end else if (counter == T_RP) begin
272
+ // AutoRefresh
273
+ sdram_cke <= 1;
274
+ sdram_cs_n <= 0;
275
+ sdram_ras_n <= 0;
276
+ sdram_cas_n <= 0;
277
+ sdram_we_n <= 1;
278
+ end else begin
279
+ // nop
280
+ sdram_cke <= 1;
281
+ sdram_cs_n <= 0;
282
+ sdram_ras_n <= 1;
283
+ sdram_cas_n <= 1;
284
+ sdram_we_n <= 1;
285
+ end
286
+ if (counter < T_RP+T_RFC) begin
287
+ counter <= counter + 1;
288
+ end else begin
289
+ counter <= 0;
290
+ // nop
291
+ sdram_cke <= 1;
292
+ sdram_cs_n <= 0;
293
+ sdram_ras_n <= 1;
294
+ sdram_cas_n <= 1;
295
+ sdram_we_n <= 1;
296
+ // next stage
297
+ stage <= 4;
298
+ end
299
+ end
300
+ if (stage == 'h6) begin
301
+ if (counter == 0) begin
302
+ // BankActivate
303
+ sdram_cke <= 1;
304
+ sdram_ba <= i_addr[3:2];
305
+ sdram_addr <= i_addr[22:12];
306
+ sdram_cs_n <= 0;
307
+ sdram_ras_n <= 0;
308
+ sdram_cas_n <= 1;
309
+ sdram_we_n <= 1;
310
+
311
+ sdram_dm <= 4'b0;
312
+ end else if (counter == T_RCD) begin
313
+ // Read and Autoprecharge
314
+ sdram_cke <= 1;
315
+ sdram_dm <= 4'b0;
316
+ sdram_ba <= i_addr[3:2];
317
+ sdram_addr[10] <= 1;
318
+ sdram_addr[7:0] <= i_addr[11:4];
319
+ sdram_cs_n <= 0;
320
+ sdram_ras_n <= 1;
321
+ sdram_cas_n <= 0;
322
+ sdram_we_n <= 1;
323
+
324
+ sdram_dq_ie <= 0;
325
+ end else if (counter == T_RCD+CL) begin
326
+ // read complete
327
+ o_rdata <= sdram_dq;
328
+ o_ready <= 1;
329
+ end else begin
330
+ o_ready <= 0;
331
+ // nop
332
+ sdram_cke <= 1;
333
+ sdram_cs_n <= 0;
334
+ sdram_ras_n <= 1;
335
+ sdram_cas_n <= 1;
336
+ sdram_we_n <= 1;
337
+ end
338
+ if (counter < T_RCD+CL+T_RP) begin
339
+ counter <= counter + 1;
340
+ end else begin
341
+ counter <= 0;
342
+ // nop
343
+ sdram_cke <= 1;
344
+ sdram_cs_n <= 0;
345
+ sdram_ras_n <= 1;
346
+ sdram_cas_n <= 1;
347
+ sdram_we_n <= 1;
348
+ // next stage
349
+ stage <= 4;
350
+ end
351
+ end
352
+ if (stage == 'h7) begin
353
+ if (counter == 0) begin
354
+ // BankActivate
355
+ sdram_cke <= 1;
356
+ sdram_ba <= i_addr[3:2];
357
+ sdram_addr <= i_addr[22:12];
358
+ sdram_cs_n <= 0;
359
+ sdram_ras_n <= 0;
360
+ sdram_cas_n <= 1;
361
+ sdram_we_n <= 1;
362
+
363
+ sdram_dm <= ~i_wstrb;
364
+ end else if (counter == T_RCD) begin
365
+ // Write and Autoprecharge
366
+ sdram_cke <= 1;
367
+ sdram_dm <= ~i_wstrb;
368
+ sdram_ba <= i_addr[3:2];
369
+ sdram_addr[10] <= 1;
370
+ sdram_addr[7:0] <= i_addr[11:4];
371
+ sdram_cs_n <= 0;
372
+ sdram_ras_n <= 1;
373
+ sdram_cas_n <= 0;
374
+ sdram_we_n <= 0;
375
+
376
+ sdram_dq_ie <= 1;
377
+ sdram_dq_r <= i_wdata;
378
+ o_ready <= 1;
379
+ end else begin
380
+ o_ready <= 0;
381
+ // nop
382
+ sdram_cke <= 1;
383
+ sdram_cs_n <= 0;
384
+ sdram_ras_n <= 1;
385
+ sdram_cas_n <= 1;
386
+ sdram_we_n <= 1;
387
+ end
388
+ if (counter < T_RCD+T_WR+T_RP) begin
389
+ counter <= counter + 1;
390
+ end else begin
391
+ counter <= 0;
392
+ // nop
393
+ sdram_cke <= 1;
394
+ sdram_cs_n <= 0;
395
+ sdram_ras_n <= 1;
396
+ sdram_cas_n <= 1;
397
+ sdram_we_n <= 1;
398
+ // next stage
399
+ stage <= 4;
400
+ end
401
+ end
402
+ end
403
+ end
404
+
405
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/spi_slave.v ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /******************************************************************************
2
+ Copyright 2017 Gnarly Grey LLC
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ ******************************************************************************/
22
+
23
+ module spi_slave (
24
+ input clk,
25
+ input reset_n,
26
+
27
+ input sclk,
28
+ input mosi,
29
+ input ssel,
30
+ output miso,
31
+
32
+ output [16:0] mem_addr,
33
+ input [7:0] mem_data
34
+ );
35
+
36
+
37
+ reg [1:0] sclk_reg;
38
+ reg [1:0] mosi_reg;
39
+ reg [2:0] bit_cnt;
40
+ wire [7:0] data_to_send;
41
+ reg [7:0] data_to_send_buf;
42
+ reg [7:0] data_received;
43
+ reg byte_received;
44
+ reg addr_data_flag;
45
+
46
+ reg [16:0] rd_addr_reg;
47
+
48
+ wire sclk_rising_edge = (sclk_reg == 2'b01);
49
+ wire sclk_falling_edge = (sclk_reg == 2'b10);
50
+ wire mosi_data = mosi_reg[1];
51
+
52
+ assign miso = data_to_send_buf[7];
53
+ assign mem_addr = rd_addr_reg;
54
+
55
+ always @ (posedge clk or negedge reset_n)
56
+ begin
57
+ if (!reset_n)
58
+ sclk_reg <= 2'b00;
59
+ else
60
+ if (ssel)
61
+ sclk_reg <= 2'b00;
62
+ else
63
+ sclk_reg <= {sclk_reg[0], sclk};
64
+ end
65
+
66
+ always @ (posedge clk or negedge reset_n)
67
+ begin
68
+ if (!reset_n)
69
+ mosi_reg <= 2'b00;
70
+ else
71
+ if (ssel)
72
+ mosi_reg <= 2'b00;
73
+ else
74
+ mosi_reg <= {mosi_reg[0], mosi};
75
+ end
76
+
77
+ always @ (posedge clk or negedge reset_n)
78
+ begin
79
+ if (!reset_n)
80
+ begin
81
+ bit_cnt <= 3'h0;
82
+ data_received <= 8'h00;
83
+ end
84
+ else
85
+ if (ssel)
86
+ begin
87
+ bit_cnt <= 3'h0;
88
+ data_received <= 8'h00;
89
+ end
90
+ else
91
+ if (sclk_rising_edge)
92
+ begin
93
+ bit_cnt <= bit_cnt + 3'h1;
94
+ data_received <= {data_received[6:0], mosi_data};
95
+ end
96
+ else
97
+ begin
98
+ bit_cnt <= bit_cnt;
99
+ data_received <= data_received;
100
+ end
101
+ end
102
+
103
+ always @ (posedge clk or negedge reset_n)
104
+ begin
105
+ if (!reset_n)
106
+ byte_received <= 1'b0;
107
+ else
108
+ if ((!ssel) && sclk_rising_edge && (bit_cnt == 3'h7))
109
+ byte_received <= 1'b1;
110
+ else
111
+ byte_received <= 1'b0;
112
+ end
113
+
114
+ always @ (posedge clk or negedge reset_n)
115
+ begin
116
+ if (!reset_n)
117
+ data_to_send_buf <= 8'h00;
118
+ else
119
+ if (ssel)
120
+ data_to_send_buf <= 8'h00;
121
+ else
122
+ if ((bit_cnt == 3'h0) && sclk_falling_edge)
123
+ data_to_send_buf <= data_to_send;
124
+ else
125
+ if (sclk_falling_edge)
126
+ data_to_send_buf <= {data_to_send_buf[6:0], 1'b0};
127
+ else
128
+ data_to_send_buf <= data_to_send_buf;
129
+ end
130
+
131
+ always @ (posedge clk or negedge reset_n)
132
+ begin
133
+ if (!reset_n)
134
+ addr_data_flag <= 1'b0;
135
+ else
136
+ if (ssel)
137
+ addr_data_flag <= 1'b0;
138
+ else
139
+ if ((!ssel) && byte_received)
140
+ addr_data_flag <= 1'b1;
141
+ else
142
+ addr_data_flag <= addr_data_flag;
143
+ end
144
+
145
+ always @ (posedge clk or negedge reset_n)
146
+ begin
147
+ if (!reset_n)
148
+ rd_addr_reg <= 17'h00000;
149
+ else
150
+ if ((!addr_data_flag) && byte_received)
151
+ rd_addr_reg <= {9'h000, data_received};
152
+ else
153
+ if (addr_data_flag && byte_received)
154
+ rd_addr_reg <= rd_addr_reg + 17'h00001;
155
+ else
156
+ rd_addr_reg <= rd_addr_reg;
157
+ end
158
+
159
+ assign data_to_send = mem_data;
160
+
161
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/1.CAM2LCD/test/top.v ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /******************************************************************************
2
+ Copyright 2017 Gnarly Grey LLC
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ ******************************************************************************/
22
+
23
+ module top
24
+ (
25
+ input wire CLK_IN, //24M
26
+ input wire RST_N,
27
+
28
+ output xclk,
29
+ input pclk,
30
+ input vsync,
31
+ input href,
32
+ input [7:0] pdata,
33
+ output cam_reset_n,
34
+ output cam_pwrdn,
35
+
36
+ output sioc,
37
+ inout siod
38
+
39
+ );
40
+
41
+ wire clk_24m /* synthesis syn_keep=1 */;
42
+
43
+ reg [17:0] pixel_cnt;
44
+ reg pixel_wr_disable;
45
+ wire cam_config_done;
46
+
47
+ wire [16:0] mem_rd_addr;
48
+ wire [7:0] mem_rd_data;
49
+ wire reset_n = 1'b1;
50
+
51
+ //considering two bytes per pixel, taking only one byte out of two by having condition (pixel_cnt[0] == 1'b0)
52
+ wire pixel_wr = q_href && (!pixel_wr_disable) && (pixel_cnt[0]==0);
53
+ wire xclk_in;
54
+
55
+ reg [7:0] q_pdata;
56
+ reg q_vsync, q_href;
57
+ reg [15:0] pix_per_line;
58
+
59
+ always @(posedge pclk)
60
+ begin
61
+ q_pdata <= pdata;
62
+ q_vsync <= vsync;
63
+ q_href <= href & (pix_per_line < (320*2));
64
+ end
65
+
66
+ assign xclk = clk_24m;
67
+
68
+ always @ (posedge pclk)
69
+ begin
70
+ pix_per_line <= href ? pix_per_line+1 : 0;
71
+ end
72
+
73
+ //Manage address for writing in DPRAM through pixel counter
74
+ always @ (posedge pclk)
75
+ begin
76
+ if (!reset_n)
77
+ begin
78
+ pixel_cnt <= 18'h00000;
79
+ end
80
+ else
81
+ if (q_vsync)
82
+ begin
83
+ pixel_cnt <= 18'h00000;
84
+ end
85
+ else
86
+ if (q_href)
87
+ begin
88
+ pixel_cnt <= (pixel_cnt<(320*400*2)) ? pixel_cnt + 18'h00001 : pixel_cnt;
89
+ end
90
+ else
91
+ begin
92
+ pixel_cnt <= pixel_cnt;
93
+ end
94
+ end
95
+
96
+ /*
97
+ //Disable pixel data write from next frame if SPI transfer has been initiated
98
+ always @ (posedge pclk)
99
+ begin
100
+ if (q_vsync)
101
+ pixel_wr_disable <= !ssel;
102
+ else
103
+ pixel_wr_disable <= pixel_wr_disable;
104
+ end
105
+ */
106
+
107
+ OV7670_Controller u_OV7670_Controller(
108
+ .clk (clk_24m), // 24Mhz clock signal
109
+ .resend (1'b0), // Reset signal
110
+ .config_finished (cam_config_done), // Flag to indicate that the configuration is finished
111
+ .sioc (sioc), // SCCB interface - clock signal
112
+ .siod (siod), // SCCB interface - data signal
113
+ .reset (cam_reset_n), // RESET signal for OV7670
114
+ .pwdn (cam_pwrdn) // PWDN signal for OV7670
115
+ );
116
+
117
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/2.LCD/Imagedata_send.v ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ `ifdef IMGTEST
3
+ module Imagedata_send
4
+ (
5
+ input wire clk_lcd, //ϵͳʱ�ӣ�Ĭ��50M
6
+ input wire rst_n, //��λ�źţ��͵�ƽ��Ч
7
+ input wire den, //TFT����ʹ��
8
+ input wire [10:0] hcount, //TFT��ɨ�������
9
+ input wire [10:0] vcount, //TFT��ɨ�������
10
+ input wire clk,
11
+ output wire [7:0] R,
12
+ output wire [7:0] G,
13
+ output wire [7:0] B
14
+ );
15
+
16
+ parameter HSYNC_BLANK_WIDTH = 256; // thb
17
+ parameter VSYNC_BLANK_WIDTH = 45; //tvb
18
+
19
+ wire img_ack; //ͼƬ����ʹ��
20
+ wire [23:0]img_data; //����ͼƬ����
21
+ reg [23:0]imgd;
22
+
23
+ localparam IMG_H = 100, //ͼƬ�����ص����
24
+ IMG_V = 100; //ͼƬ�����ص����
25
+
26
+ localparam TFT_H = 800, //TFT�������ص����
27
+ TFT_V = 480; //TFT�������ص����
28
+
29
+ localparam IMG_HM = TFT_H - IMG_H, //ͼƬ�з�����ƶ����ص����
30
+ IMG_VM = TFT_V - IMG_V; //ͼƬ��������ƶ����ص����
31
+
32
+ reg [10:0]img_hbegin = 100; //ͼƬ���Ͻǵ�һ�����ص���TFT������������
33
+ reg [10:0]img_vbegin = 100; //ͼƬ���Ͻǵ�һ�����ص���TFT���ij�������
34
+
35
+ assign img_ack = den && ((hcount - HSYNC_BLANK_WIDTH) >= img_hbegin && (hcount - HSYNC_BLANK_WIDTH) < img_hbegin + IMG_H) &&
36
+ ((vcount - VSYNC_BLANK_WIDTH) >= img_vbegin && (vcount - VSYNC_BLANK_WIDTH) < img_vbegin + IMG_V)?1'b1:1'b0;
37
+
38
+
39
+ // reg [31:0]timecnt;
40
+ // reg [10:0]plus;
41
+ // reg vdir,hdir;
42
+
43
+ // initial
44
+ // begin
45
+ // plus<=1;
46
+ // hdir<=1;;
47
+ // vdir<=1;
48
+ // end
49
+
50
+ // always@(posedge clk)
51
+ // begin
52
+ // timecnt <= timecnt + 1'b1;
53
+ // if(timecnt == 2_400_000)
54
+ // begin
55
+ // timecnt <= 0;
56
+
57
+ // if(hdir==1)
58
+ // begin
59
+ // img_hbegin <= img_hbegin + plus;
60
+ // end
61
+ // else
62
+ // begin
63
+ // img_hbegin <= img_hbegin - plus;
64
+ // end
65
+
66
+ // if(vdir==1)
67
+ // begin
68
+ // img_vbegin <= img_vbegin + plus;
69
+ // end
70
+ // else
71
+ // begin
72
+ // img_vbegin <= img_vbegin - plus;
73
+ // end
74
+ // /*
75
+ // if((img_vbegin == 0) || (img_vbegin == IMG_VM))
76
+ // begin
77
+ // vdir = ~vdir;
78
+ // plus<=5;
79
+ // imgd<=24'hff0000;
80
+ // end
81
+
82
+ // if((img_hbegin == 0) || (img_hbegin == IMG_HM))
83
+ // begin
84
+ // hdir = ~hdir;
85
+ // plus<=10;
86
+ // imgd<=24'h0000ff;
87
+ // end
88
+ // */
89
+ // end
90
+ // end
91
+
92
+ // assign imgd = 24'h00ff00;
93
+ assign img_data = img_ack ? 24'h00ff00 : 24'h0;
94
+
95
+ assign B = img_data[7:0];
96
+ assign G = img_data[15:8];
97
+ assign R = img_data[23:16];
98
+
99
+ endmodule
100
+ `endif
Lichee-Pi_Tang_FPGA_Examples/2.LCD/al_ip/ip_pll.v ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /************************************************************\
2
+ ** Copyright (c) 2011-2021 Anlogic, Inc.
3
+ ** All Right Reserved.
4
+ \************************************************************/
5
+ /************************************************************\
6
+ ** Log : This file is generated by Anlogic IP Generator.
7
+ ** File : H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd/al_ip/ip_pll.v
8
+ ** Date : 2018 08 09
9
+ ** TD version : 4.2.217
10
+ \************************************************************/
11
+
12
+ ///////////////////////////////////////////////////////////////////////////////
13
+ // Input frequency: 24.000Mhz
14
+ // Clock multiplication factor: 18
15
+ // Clock division factor: 13
16
+ // Clock information:
17
+ // Clock name | Frequency | Phase shift
18
+ // C0 | 33.231 MHZ | 0 DEG
19
+ ///////////////////////////////////////////////////////////////////////////////
20
+ `timescale 1 ns / 100 fs
21
+
22
+ module ip_pll(refclk,
23
+ reset,
24
+ extlock,
25
+ clk0_out);
26
+
27
+ input refclk;
28
+ input reset;
29
+ output extlock;
30
+ output clk0_out;
31
+
32
+ wire clk0_buf;
33
+
34
+ EG_LOGIC_BUFG bufg_feedback( .i(clk0_buf), .o(clk0_out) );
35
+
36
+ EG_PHY_PLL #(.DPHASE_SOURCE("DISABLE"),
37
+ .DYNCFG("DISABLE"),
38
+ .FIN("24.000"),
39
+ .FEEDBK_MODE("NORMAL"),
40
+ .FEEDBK_PATH("CLKC0_EXT"),
41
+ .STDBY_ENABLE("DISABLE"),
42
+ .PLLRST_ENA("ENABLE"),
43
+ .SYNC_ENABLE("ENABLE"),
44
+ .DERIVE_PLL_CLOCKS("DISABLE"),
45
+ .GEN_BASIC_CLOCK("DISABLE"),
46
+ .GMC_GAIN(6),
47
+ .ICP_CURRENT(3),
48
+ .KVCO(6),
49
+ .LPF_CAPACITOR(3),
50
+ .LPF_RESISTOR(2),
51
+ .REFCLK_DIV(13),
52
+ .FBCLK_DIV(18),
53
+ .CLKC0_ENABLE("ENABLE"),
54
+ .CLKC0_DIV(30),
55
+ .CLKC0_CPHASE(30),
56
+ .CLKC0_FPHASE(0) )
57
+ pll_inst (.refclk(refclk),
58
+ .reset(reset),
59
+ .stdby(1'b0),
60
+ .extlock(extlock),
61
+ .psclk(1'b0),
62
+ .psdown(1'b0),
63
+ .psstep(1'b0),
64
+ .psclksel(3'b000),
65
+ .psdone(open),
66
+ .dclk(1'b0),
67
+ .dcs(1'b0),
68
+ .dwe(1'b0),
69
+ .di(8'b00000000),
70
+ .daddr(6'b000000),
71
+ .do({open, open, open, open, open, open, open, open}),
72
+ .fbclk(clk0_out),
73
+ .clkc({open, open, open, open, clk0_buf}));
74
+
75
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/2.LCD/al_ip/ip_pll_sim.v ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Verilog netlist created by TD v4.2.217
2
+ // Thu Aug 9 17:48:06 2018
3
+
4
+ `timescale 1ns / 1ps
5
+ module ip_pll // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd/al_ip/ip_pll.v(22)
6
+ (
7
+ refclk,
8
+ reset,
9
+ clk0_out,
10
+ extlock
11
+ );
12
+
13
+ input refclk; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd/al_ip/ip_pll.v(27)
14
+ input reset; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd/al_ip/ip_pll.v(28)
15
+ output clk0_out; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd/al_ip/ip_pll.v(30)
16
+ output extlock; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd/al_ip/ip_pll.v(29)
17
+
18
+ wire clk0_buf; // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd/al_ip/ip_pll.v(32)
19
+
20
+ EG_PHY_GCLK bufg_feedback (
21
+ .clki(clk0_buf),
22
+ .clko(clk0_out)); // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd/al_ip/ip_pll.v(34)
23
+ EG_PHY_CONFIG #(
24
+ .DONE_PERSISTN("ENABLE"),
25
+ .INIT_PERSISTN("ENABLE"),
26
+ .JTAG_PERSISTN("DISABLE"),
27
+ .PROGRAMN_PERSISTN("DISABLE"))
28
+ config_inst ();
29
+ EG_PHY_PLL #(
30
+ .CLKC0_CPHASE(30),
31
+ .CLKC0_DIV(30),
32
+ .CLKC0_DIV2_ENABLE("DISABLE"),
33
+ .CLKC0_ENABLE("ENABLE"),
34
+ .CLKC0_FPHASE(0),
35
+ .CLKC1_CPHASE(1),
36
+ .CLKC1_DIV(1),
37
+ .CLKC1_DIV2_ENABLE("DISABLE"),
38
+ .CLKC1_ENABLE("DISABLE"),
39
+ .CLKC1_FPHASE(0),
40
+ .CLKC2_CPHASE(1),
41
+ .CLKC2_DIV(1),
42
+ .CLKC2_DIV2_ENABLE("DISABLE"),
43
+ .CLKC2_ENABLE("DISABLE"),
44
+ .CLKC2_FPHASE(0),
45
+ .CLKC3_CPHASE(1),
46
+ .CLKC3_DIV(1),
47
+ .CLKC3_DIV2_ENABLE("DISABLE"),
48
+ .CLKC3_ENABLE("DISABLE"),
49
+ .CLKC3_FPHASE(0),
50
+ .CLKC4_CPHASE(1),
51
+ .CLKC4_DIV(1),
52
+ .CLKC4_DIV2_ENABLE("DISABLE"),
53
+ .CLKC4_ENABLE("DISABLE"),
54
+ .CLKC4_FPHASE(0),
55
+ .DERIVE_PLL_CLOCKS("DISABLE"),
56
+ .DPHASE_SOURCE("DISABLE"),
57
+ .DYNCFG("DISABLE"),
58
+ .FBCLK_DIV(18),
59
+ .FEEDBK_MODE("NORMAL"),
60
+ .FEEDBK_PATH("CLKC0_EXT"),
61
+ .FIN("24.000"),
62
+ .FREQ_LOCK_ACCURACY(2),
63
+ .GEN_BASIC_CLOCK("DISABLE"),
64
+ .GMC_GAIN(6),
65
+ .GMC_TEST(14),
66
+ .ICP_CURRENT(3),
67
+ .IF_ESCLKSTSW("DISABLE"),
68
+ .INTFB_WAKE("DISABLE"),
69
+ .KVCO(6),
70
+ .LPF_CAPACITOR(3),
71
+ .LPF_RESISTOR(2),
72
+ .NORESET("DISABLE"),
73
+ .ODIV_MUXC0("DIV"),
74
+ .ODIV_MUXC1("DIV"),
75
+ .ODIV_MUXC2("DIV"),
76
+ .ODIV_MUXC3("DIV"),
77
+ .ODIV_MUXC4("DIV"),
78
+ .PLLC2RST_ENA("DISABLE"),
79
+ .PLLC34RST_ENA("DISABLE"),
80
+ .PLLMRST_ENA("DISABLE"),
81
+ .PLLRST_ENA("ENABLE"),
82
+ .PLL_LOCK_MODE(0),
83
+ .PREDIV_MUXC0("VCO"),
84
+ .PREDIV_MUXC1("VCO"),
85
+ .PREDIV_MUXC2("VCO"),
86
+ .PREDIV_MUXC3("VCO"),
87
+ .PREDIV_MUXC4("VCO"),
88
+ .REFCLK_DIV(13),
89
+ .REFCLK_SEL("INTERNAL"),
90
+ .STDBY_ENABLE("DISABLE"),
91
+ .STDBY_VCO_ENA("DISABLE"),
92
+ .SYNC_ENABLE("ENABLE"),
93
+ .VCO_NORESET("DISABLE"))
94
+ pll_inst (
95
+ .daddr(6'b000000),
96
+ .dclk(1'b0),
97
+ .dcs(1'b0),
98
+ .di(8'b00000000),
99
+ .dwe(1'b0),
100
+ .fbclk(clk0_out),
101
+ .psclk(1'b0),
102
+ .psclksel(3'b000),
103
+ .psdown(1'b0),
104
+ .psstep(1'b0),
105
+ .refclk(refclk),
106
+ .reset(reset),
107
+ .stdby(1'b0),
108
+ .clkc({open_n47,open_n48,open_n49,open_n50,clk0_buf}),
109
+ .extlock(extlock)); // H:/Work/FPGA/AnLogic/LicheeTang/demo/test_lcd/al_ip/ip_pll.v(73)
110
+
111
+ endmodule
112
+
Lichee-Pi_Tang_FPGA_Examples/2.LCD/data_out.v ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module data_out
3
+ (
4
+ input wire clk_lcd,
5
+ output wire [7:0] R,
6
+ output wire [7:0] G,
7
+ output wire [7:0] B,
8
+ input wire den,
9
+ input wire [10:0] hsync,
10
+ input wire [10:0] vsync
11
+ );
12
+
13
+ reg [7:0] r_R;
14
+ reg [7:0] r_G;
15
+ reg [7:0] r_B;
16
+
17
+ parameter HSYNC_BLANK_WIDTH = 256; // thb
18
+ parameter HSYNC_WIDTH = 1056 + HSYNC_BLANK_WIDTH; // th
19
+
20
+ parameter VSYNC_BLANK_WIDTH = 45; //tvb
21
+ parameter VSYNC_WIDTH = 525 + VSYNC_BLANK_WIDTH; //tv
22
+
23
+ reg scan_dir;
24
+ reg [31:0]timecnt;
25
+
26
+ always@(posedge clk_lcd)
27
+ begin
28
+ timecnt<=timecnt+1'b1;
29
+ if(timecnt==32'd33_000_000)
30
+ begin
31
+ timecnt<=32'h0;
32
+ scan_dir = ~scan_dir;
33
+ end
34
+
35
+ if (den)
36
+ begin
37
+ if(scan_dir==1)
38
+ begin
39
+ if (vsync<(160+VSYNC_BLANK_WIDTH))
40
+ begin
41
+ r_R<=8'hff;
42
+ r_B<=8'h00;
43
+ r_G<=8'h00;
44
+ end
45
+ else if (vsync<(320+VSYNC_BLANK_WIDTH))
46
+ begin
47
+ r_R<=8'h00;
48
+ r_B<=8'hff;
49
+ r_G<=8'h00;
50
+ end
51
+ else if (vsync<VSYNC_WIDTH)
52
+ begin
53
+ r_R<=8'h00;
54
+ r_B<=8'h00;
55
+ r_G<=8'hff;
56
+ end
57
+ end
58
+ else
59
+ begin
60
+ if (hsync<(266+HSYNC_BLANK_WIDTH))
61
+ begin
62
+ r_R<=8'hff;
63
+ r_B<=8'h00;
64
+ r_G<=8'h00;
65
+ end
66
+ else if (hsync<(532+HSYNC_BLANK_WIDTH))
67
+ begin
68
+ r_R<=8'h00;
69
+ r_B<=8'hff;
70
+ r_G<=8'h00;
71
+ end
72
+ else if (hsync<HSYNC_WIDTH)
73
+ begin
74
+ r_R<=8'h00;
75
+ r_B<=8'h00;
76
+ r_G<=8'hff;
77
+ end
78
+ end
79
+ end
80
+ else
81
+ begin
82
+ r_R<=8'h00;
83
+ r_B<=8'h00;
84
+ r_G<=8'h00;
85
+ end
86
+ end
87
+
88
+ assign R = r_R;
89
+ assign G = r_G;
90
+ assign B = r_B;
91
+
92
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/2.LCD/lcd_sync.v ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module lcd_sync
3
+ #(
4
+ //display image at pos
5
+ parameter IMG_W = 100, //ͼƬص
6
+ parameter IMG_H = 100, //ͼƬص
7
+ parameter IMG_X = 0,
8
+ parameter IMG_Y = 0
9
+ )
10
+ (
11
+ input wire clk,
12
+ input wire rest_n,
13
+ output wire lcd_clk,
14
+ output wire lcd_pwm,
15
+ output wire lcd_hsync,
16
+ output wire lcd_vsync,
17
+ output wire lcd_de,
18
+ output wire [10:0] hsync_cnt,
19
+ output wire [10:0] vsync_cnt,
20
+ output wire img_ack,
21
+ output wire [15:0]addr
22
+ );
23
+
24
+ `define LCD_480800
25
+ `ifdef LCD_480800
26
+ //800*480
27
+ localparam TFT_H = 800; //TFTص
28
+ localparam TFT_V = 480; //TFTص
29
+
30
+ localparam thb = 256;
31
+ localparam th = 1056 + thb;
32
+
33
+ localparam tvb = 45;
34
+ localparam tv = 525 + tvb;
35
+
36
+
37
+ //640*480
38
+ // localparam TFT_H = 640; //TFTص
39
+ // localparam TFT_V = 480; //TFTص
40
+
41
+ // localparam thb = 160;
42
+ // localparam th = 640 + thb;
43
+
44
+ // localparam tvb = 45;
45
+ // localparam tv = 525 + tvb;
46
+ `else
47
+
48
+ localparam TFT_H = 480; //TFTص
49
+ localparam TFT_V = 272; //TFTص
50
+
51
+ localparam thb = 41;
52
+ localparam th = 533 + thb;
53
+
54
+ localparam tvb = 10;
55
+ localparam tv = 288 + tvb;
56
+ `endif
57
+
58
+ reg [10:0] counter_hs;
59
+ reg [10:0] counter_vs;
60
+
61
+ always@(posedge clk)begin
62
+ if(rest_n == 1'b0)begin
63
+ counter_hs <= 0;
64
+ counter_vs <= 0;
65
+ end
66
+ else begin
67
+ if(counter_hs == th )begin
68
+ if(counter_vs == tv)
69
+ counter_vs <= 0;
70
+ else
71
+ counter_vs <= counter_vs + 1;
72
+ counter_hs <= 0;
73
+ end
74
+ else
75
+ counter_hs <= counter_hs + 1;
76
+ end
77
+ end
78
+
79
+ reg [10:0]img_hbegin = 0; //ͼƬϽǵһصTFT
80
+ reg [10:0]img_vbegin = 0; //ͼƬϽǵһصTFTij
81
+
82
+ assign lcd_clk = (rest_n == 1) ? clk : 1'b0;
83
+ assign lcd_pwm = (rest_n == 1) ? 1'b1 : 1'b0;
84
+ assign lcd_hsync = (counter_hs >= (thb+4) && counter_hs < (th-5)) ? 0 : 1;
85
+ assign lcd_vsync = (counter_vs >= (tvb+2) && counter_vs < (tv-5)) ? 0 : 1;
86
+ assign lcd_de = (counter_hs >= thb && counter_hs <= th && counter_vs >= tvb && counter_vs < tv) ? 1 : 0;
87
+ assign hsync_cnt = counter_hs;
88
+ assign vsync_cnt = counter_hs;
89
+
90
+ assign img_ack = lcd_de &&
91
+ ((counter_hs - thb) >= IMG_X && (counter_hs - thb) < (IMG_X + IMG_W)) &&
92
+ ((counter_vs - tvb) >= IMG_Y && (counter_vs - tvb) < (IMG_Y + IMG_H))?1'b1:1'b0;
93
+
94
+ reg [15:0]read_addr; //ͼƬromַ
95
+ // wire [15:0]img_data; //ͼƬ
96
+ /*
97
+ img mif_img
98
+ (
99
+ .doa(img_data),
100
+ .addra(addr),
101
+ .clka(clk),
102
+ .rsta(!rest_n)
103
+ );
104
+ */
105
+
106
+ assign addr = read_addr;
107
+
108
+ always@(posedge clk or negedge rest_n)
109
+ begin
110
+ if(!rest_n)
111
+ read_addr <= 16'd0;
112
+ else if(img_ack)
113
+ read_addr <= (counter_hs - IMG_X - thb) + (counter_vs - IMG_Y - tvb)*IMG_W;
114
+ else
115
+ read_addr <= 16'd0;
116
+ end
117
+
118
+
119
+ // reg [20:0] pixel_counter;
120
+ //always@(posedge clk)
121
+ //begin
122
+ //if(reset == 1'b0)
123
+ // begin
124
+ // pixel_counter <= 0;
125
+ // end
126
+ // else
127
+ // begin
128
+ // if(counter_hs >= 46 && counter_hs <= 686 && counter_vs >= 23 && counter_vs < 503)
129
+ // begin
130
+ // pixel_counter <= pixel_counter + 1;
131
+ // end
132
+ // else
133
+ // if(counter_vs == 504)
134
+ // pixel_counter <= 0;
135
+ // end
136
+ //end
137
+
138
+
139
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/2.LCD/test_lcd.sdc ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # ## Log : This file is generated by Anlogic Timing Wizard.
2
+ # ## File : H:/Work/FPGA/AnLogic/tets_lcd/test_lcd/test_lcd.sdc
3
+ # ## Date : 15 07 2018
4
+
5
+ #Created Clock
6
+ ##create_clock -name clk_50m -period 20 [get_nets {clk_50m}]
Lichee-Pi_Tang_FPGA_Examples/2.LCD/test_lcd.v ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module test_lcd
3
+ (
4
+ input wire CLK_IN,
5
+ input wire RST_N,
6
+ output wire [0:7] R,
7
+ output wire [0:7] G,
8
+ output wire [0:7] B,
9
+ output wire LCD_CLK,
10
+ output wire LCD_HSYNC,
11
+ output wire LCD_VSYNC,
12
+ output wire LCD_DEN,
13
+ output wire LCD_PWM //backlight,set to high
14
+ );
15
+ wire clk_lcd;
16
+ wire clklock;
17
+ wire [10:0] hsync;
18
+ wire [10:0] vsync;
19
+
20
+ ip_pll pll
21
+ (
22
+ .refclk (CLK_IN),
23
+ .reset (~RST_N),
24
+ .extlock (clklock),
25
+ .clk0_out (clk_lcd)
26
+ );
27
+
28
+ //lcd display
29
+ wire [10:0] hsync_cnt;
30
+ wire [10:0] vsync_cnt;
31
+ wire lcd_rden;
32
+ wire [15:0]lcd_rddat; //lcd read
33
+ wire [15:0]lcd_rdaddr;
34
+
35
+ lcd_sync
36
+ #(
37
+ .IMG_W(800),
38
+ .IMG_H(480),
39
+ .IMG_X(0),
40
+ .IMG_Y(0)
41
+ )
42
+ u_lcd_sync
43
+ (
44
+ .clk (clk_lcd),
45
+ .rest_n (RST_N),
46
+ .lcd_clk (LCD_CLK),
47
+ .lcd_pwm (LCD_PWM),
48
+ .lcd_hsync (LCD_HSYNC),
49
+ .lcd_vsync (LCD_VSYNC),
50
+ .lcd_de (LCD_DEN),
51
+ .hsync_cnt (hsync_cnt),
52
+ .vsync_cnt (vsync_cnt),
53
+ .img_ack (lcd_rden),
54
+ .addr (lcd_rdaddr)
55
+ );
56
+
57
+ data_out datout
58
+ (
59
+ .clk_lcd (clk_lcd),
60
+ .R (R),
61
+ .G (G),
62
+ .B (B),
63
+ .den (lcd_rden),
64
+ .hsync (hsync_cnt),
65
+ .vsync (vsync_cnt)
66
+ );
67
+
68
+ endmodule
Lichee-Pi_Tang_FPGA_Examples/README.md ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # LicheeTang FPGA例程
2
+
3
+ #0. LED RGB led 闪烁
4
+
5
+ #1. Camera to LCD
6
+
7
+ ## IDE Download
8
+ [http://dl.sipeed.com/TANG/Premier/IDE](http://dl.sipeed.com/TANG/Premier/IDE)