gesture ws2812

main
lincaigui 7 months ago
commit ebda40a5cd

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,283 @@
module data_cfg(
input wire [4: 0] cnt_bit ,
input wire [6: 0] cnt_pixel ,
input wire [3: 0] ges_data ,
output wire bit
);
reg [1: 0] ges_pic;
wire [23: 0] data[255: 0];
wire [23: 0] data_temp;
wire [23: 0] data_reduce;
assign data_temp = data[ges_pic * 64 + cnt_pixel];//
assign data_reduce = {data_temp[23: 16] >> 3, data_temp[15: 8] >> 3, data_temp[7: 0] >> 3};//
assign bit = data_reduce[23 - cnt_bit];
always @(*) begin
case(ges_data)
4'b0001: ges_pic = 2'd0;
4'b0010: ges_pic = 2'd1;
4'b0100: ges_pic = 2'd2;
4'b1000: ges_pic = 2'd3;
default: ges_pic = 2'd0;
endcase
end
//U
assign data[00] = {8'h00,8'h00,8'h00} ;//0
assign data[01] = {8'hff,8'hff,8'hff} ;
assign data[02] = {8'h00,8'h00,8'h00} ;
assign data[03] = {8'h00,8'h00,8'h00} ;
assign data[04] = {8'h00,8'h00,8'h00} ;
assign data[05] = {8'h00,8'h00,8'h00} ;
assign data[06] = {8'hff,8'hff,8'hff} ;
assign data[07] = {8'h00,8'h00,8'h00} ;
assign data[08] = {8'h00,8'h00,8'h00} ;//1
assign data[09] = {8'hff,8'hff,8'hff} ;
assign data[10] = {8'h00,8'h00,8'h00} ;
assign data[11] = {8'h00,8'h00,8'h00} ;
assign data[12] = {8'h00,8'h00,8'h00} ;
assign data[13] = {8'h00,8'h00,8'h00} ;
assign data[14] = {8'hff,8'hff,8'hff} ;
assign data[15] = {8'h00,8'h00,8'h00} ;
assign data[16] = {8'h00,8'h00,8'h00} ;//2
assign data[17] = {8'hff,8'hff,8'hff} ;
assign data[18] = {8'h00,8'h00,8'h00} ;
assign data[19] = {8'h00,8'h00,8'h00} ;
assign data[20] = {8'h00,8'h00,8'h00} ;
assign data[21] = {8'h00,8'h00,8'h00} ;
assign data[22] = {8'hff,8'hff,8'hff} ;
assign data[23] = {8'h00,8'h00,8'h00} ;
assign data[24] = {8'h00,8'h00,8'h00} ;//3
assign data[25] = {8'hff,8'hff,8'hff} ;
assign data[26] = {8'h00,8'h00,8'h00} ;
assign data[27] = {8'h00,8'h00,8'h00} ;
assign data[28] = {8'h00,8'h00,8'h00} ;
assign data[29] = {8'h00,8'h00,8'h00} ;
assign data[30] = {8'hff,8'hff,8'hff} ;
assign data[31] = {8'h00,8'h00,8'h00} ;
assign data[32] = {8'h00,8'h00,8'h00} ;//4
assign data[33] = {8'hff,8'hff,8'hff} ;
assign data[34] = {8'h00,8'h00,8'h00} ;
assign data[35] = {8'h00,8'h00,8'h00} ;
assign data[36] = {8'h00,8'h00,8'h00} ;
assign data[37] = {8'h00,8'h00,8'h00} ;
assign data[38] = {8'hff,8'hff,8'hff} ;
assign data[39] = {8'h00,8'h00,8'h00} ;
assign data[40] = {8'h00,8'h00,8'h00} ;//5
assign data[41] = {8'hff,8'hff,8'hff} ;
assign data[42] = {8'h00,8'h00,8'h00} ;
assign data[43] = {8'h00,8'h00,8'h00} ;
assign data[44] = {8'h00,8'h00,8'h00} ;
assign data[45] = {8'h00,8'h00,8'h00} ;
assign data[46] = {8'hff,8'hff,8'hff} ;
assign data[47] = {8'h00,8'h00,8'h00} ;
assign data[48] = {8'h00,8'h00,8'h00} ;//6
assign data[49] = {8'h00,8'h00,8'h00} ;
assign data[50] = {8'hff,8'hff,8'hff} ;
assign data[51] = {8'h00,8'h00,8'h00} ;
assign data[52] = {8'h00,8'h00,8'h00} ;
assign data[53] = {8'hff,8'hff,8'hff} ;
assign data[54] = {8'h00,8'h00,8'h00} ;
assign data[55] = {8'h00,8'h00,8'h00} ;
assign data[56] = {8'h00,8'h00,8'h00} ;//7
assign data[57] = {8'h00,8'h00,8'h00} ;
assign data[58] = {8'h00,8'h00,8'h00} ;
assign data[59] = {8'hff,8'hff,8'hff} ;
assign data[60] = {8'hff,8'hff,8'hff} ;
assign data[61] = {8'h00,8'h00,8'h00} ;
assign data[62] = {8'h00,8'h00,8'h00} ;
assign data[63] = {8'h00,8'h00,8'h00} ;//8
//D
assign data[64] = {8'h00,8'h00,8'h00} ;//0
assign data[65] = {8'hff,8'hff,8'hff} ;
assign data[66] = {8'hff,8'hff,8'hff} ;
assign data[67] = {8'hff,8'hff,8'hff} ;
assign data[68] = {8'hff,8'hff,8'hff} ;
assign data[69] = {8'h00,8'h00,8'h00} ;
assign data[70] = {8'h00,8'h00,8'h00} ;
assign data[71] = {8'h00,8'h00,8'h00} ;
assign data[72] = {8'h00,8'h00,8'h00} ;//1
assign data[73] = {8'hff,8'hff,8'hff} ;
assign data[74] = {8'h00,8'h00,8'h00} ;
assign data[75] = {8'h00,8'h00,8'h00} ;
assign data[76] = {8'h00,8'h00,8'h00} ;
assign data[77] = {8'hff,8'hff,8'hff} ;
assign data[78] = {8'h00,8'h00,8'h00} ;
assign data[79] = {8'h00,8'h00,8'h00} ;
assign data[80] = {8'h00,8'h00,8'h00} ;//2
assign data[81] = {8'hff,8'hff,8'hff} ;
assign data[82] = {8'h00,8'h00,8'h00} ;
assign data[83] = {8'h00,8'h00,8'h00} ;
assign data[84] = {8'h00,8'h00,8'h00} ;
assign data[85] = {8'h00,8'h00,8'h00} ;
assign data[86] = {8'hff,8'hff,8'hff} ;
assign data[87] = {8'h00,8'h00,8'h00} ;
assign data[88] = {8'h00,8'h00,8'h00} ;//3
assign data[89] = {8'hff,8'hff,8'hff} ;
assign data[90] = {8'h00,8'h00,8'h00} ;
assign data[91] = {8'h00,8'h00,8'h00} ;
assign data[92] = {8'h00,8'h00,8'h00} ;
assign data[93] = {8'h00,8'h00,8'h00} ;
assign data[94] = {8'hff,8'hff,8'hff} ;
assign data[95] = {8'h00,8'h00,8'h00} ;
assign data[96] = {8'h00,8'h00,8'h00} ;//4
assign data[97] = {8'hff,8'hff,8'hff} ;
assign data[98] = {8'h00,8'h00,8'h00} ;
assign data[99] = {8'h00,8'h00,8'h00} ;
assign data[100] = {8'h00,8'h00,8'h00} ;
assign data[101] = {8'h00,8'h00,8'h00} ;
assign data[102] = {8'hff,8'hff,8'hff} ;
assign data[103] = {8'h00,8'h00,8'h00} ;
assign data[104] = {8'h00,8'h00,8'h00} ;//5
assign data[105] = {8'hff,8'hff,8'hff} ;
assign data[106] = {8'h00,8'h00,8'h00} ;
assign data[107] = {8'h00,8'h00,8'h00} ;
assign data[108] = {8'h00,8'h00,8'h00} ;
assign data[109] = {8'h00,8'h00,8'h00} ;
assign data[110] = {8'hff,8'hff,8'hff} ;
assign data[111] = {8'h00,8'h00,8'h00} ;
assign data[112] = {8'h00,8'h00,8'h00} ;//6
assign data[113] = {8'hff,8'hff,8'hff} ;
assign data[114] = {8'h00,8'h00,8'h00} ;
assign data[115] = {8'h00,8'h00,8'h00} ;
assign data[116] = {8'h00,8'h00,8'h00} ;
assign data[117] = {8'hff,8'hff,8'hff} ;
assign data[118] = {8'h00,8'h00,8'h00} ;
assign data[119] = {8'h00,8'h00,8'h00} ;
assign data[120] = {8'h00,8'h00,8'h00} ;//7
assign data[121] = {8'hff,8'hff,8'hff} ;
assign data[122] = {8'hff,8'hff,8'hff} ;
assign data[123] = {8'hff,8'hff,8'hff} ;
assign data[124] = {8'hff,8'hff,8'hff} ;
assign data[125] = {8'h00,8'h00,8'h00} ;
assign data[126] = {8'h00,8'h00,8'h00} ;
assign data[127] = {8'h00,8'h00,8'h00} ;
//L
assign data[128] = {8'h00,8'h00,8'h00} ;//0
assign data[129] = {8'hff,8'hff,8'hff} ;
assign data[130] = {8'h00,8'h00,8'h00} ;
assign data[131] = {8'h00,8'h00,8'h00} ;
assign data[132] = {8'h00,8'h00,8'h00} ;
assign data[133] = {8'h00,8'h00,8'h00} ;
assign data[134] = {8'h00,8'h00,8'h00} ;
assign data[135] = {8'h00,8'h00,8'h00} ;
assign data[136] = {8'h00,8'h00,8'h00} ;//1
assign data[137] = {8'hff,8'hff,8'hff} ;
assign data[138] = {8'h00,8'h00,8'h00} ;
assign data[139] = {8'h00,8'h00,8'h00} ;
assign data[140] = {8'h00,8'h00,8'h00} ;
assign data[141] = {8'h00,8'h00,8'h00} ;
assign data[142] = {8'h00,8'h00,8'h00} ;
assign data[143] = {8'h00,8'h00,8'h00} ;
assign data[144] = {8'h00,8'h00,8'h00} ;//2
assign data[145] = {8'hff,8'hff,8'hff} ;
assign data[146] = {8'h00,8'h00,8'h00} ;
assign data[147] = {8'h00,8'h00,8'h00} ;
assign data[148] = {8'h00,8'h00,8'h00} ;
assign data[149] = {8'h00,8'h00,8'h00} ;
assign data[150] = {8'h00,8'h00,8'h00} ;
assign data[151] = {8'h00,8'h00,8'h00} ;
assign data[152] = {8'h00,8'h00,8'h00} ;//3
assign data[153] = {8'hff,8'hff,8'hff} ;
assign data[154] = {8'h00,8'h00,8'h00} ;
assign data[155] = {8'h00,8'h00,8'h00} ;
assign data[156] = {8'h00,8'h00,8'h00} ;
assign data[157] = {8'h00,8'h00,8'h00} ;
assign data[158] = {8'h00,8'h00,8'h00} ;
assign data[159] = {8'h00,8'h00,8'h00} ;
assign data[160] = {8'h00,8'h00,8'h00} ;//4
assign data[161] = {8'hff,8'hff,8'hff} ;
assign data[162] = {8'h00,8'h00,8'h00} ;
assign data[163] = {8'h00,8'h00,8'h00} ;
assign data[164] = {8'h00,8'h00,8'h00} ;
assign data[165] = {8'h00,8'h00,8'h00} ;
assign data[166] = {8'h00,8'h00,8'h00} ;
assign data[167] = {8'h00,8'h00,8'h00} ;
assign data[168] = {8'h00,8'h00,8'h00} ;//5
assign data[169] = {8'hff,8'hff,8'hff} ;
assign data[170] = {8'h00,8'h00,8'h00} ;
assign data[171] = {8'h00,8'h00,8'h00} ;
assign data[172] = {8'h00,8'h00,8'h00} ;
assign data[173] = {8'h00,8'h00,8'h00} ;
assign data[174] = {8'h00,8'h00,8'h00} ;
assign data[175] = {8'h00,8'h00,8'h00} ;
assign data[176] = {8'h00,8'h00,8'h00} ;//6
assign data[177] = {8'hff,8'hff,8'hff} ;
assign data[178] = {8'h00,8'h00,8'h00} ;
assign data[179] = {8'h00,8'h00,8'h00} ;
assign data[180] = {8'h00,8'h00,8'h00} ;
assign data[181] = {8'h00,8'h00,8'h00} ;
assign data[182] = {8'h00,8'h00,8'h00} ;
assign data[183] = {8'h00,8'h00,8'h00} ;
assign data[184] = {8'h00,8'h00,8'h00} ;//7
assign data[185] = {8'hff,8'hff,8'hff} ;
assign data[186] = {8'hff,8'hff,8'hff} ;
assign data[187] = {8'hff,8'hff,8'hff} ;
assign data[188] = {8'hff,8'hff,8'hff} ;
assign data[189] = {8'hff,8'hff,8'hff} ;
assign data[190] = {8'hff,8'hff,8'hff} ;
assign data[191] = {8'h00,8'h00,8'h00} ;
//R
assign data[192]= {8'h00,8'h00,8'h00} ;//0
assign data[193]= {8'hff,8'hff,8'hff} ;
assign data[194]= {8'hff,8'hff,8'hff} ;
assign data[195]= {8'hff,8'hff,8'hff} ;
assign data[196]= {8'hff,8'hff,8'hff} ;
assign data[197]= {8'h00,8'h00,8'h00} ;
assign data[198]= {8'h00,8'h00,8'h00} ;
assign data[199]= {8'h00,8'h00,8'h00} ;
assign data[200]= {8'h00,8'h00,8'h00} ;//1
assign data[201]= {8'hff,8'hff,8'hff} ;
assign data[202]= {8'h00,8'h00,8'h00} ;
assign data[203]= {8'h00,8'h00,8'h00} ;
assign data[204]= {8'h00,8'h00,8'h00} ;
assign data[205]= {8'hff,8'hff,8'hff} ;
assign data[206]= {8'h00,8'h00,8'h00} ;
assign data[207]= {8'h00,8'h00,8'h00} ;
assign data[208]= {8'h00,8'h00,8'h00} ;//2
assign data[209]= {8'hff,8'hff,8'hff} ;
assign data[210]= {8'h00,8'h00,8'h00} ;
assign data[211]= {8'h00,8'h00,8'h00} ;
assign data[212]= {8'h00,8'h00,8'h00} ;
assign data[213]= {8'hff,8'hff,8'hff} ;
assign data[214]= {8'h00,8'h00,8'h00} ;
assign data[215]= {8'h00,8'h00,8'h00} ;
assign data[216]= {8'h00,8'h00,8'h00} ;//3
assign data[217]= {8'hff,8'hff,8'hff} ;
assign data[218]= {8'hff,8'hff,8'hff} ;
assign data[219]= {8'hff,8'hff,8'hff} ;
assign data[220]= {8'hff,8'hff,8'hff} ;
assign data[221]= {8'h00,8'h00,8'h00} ;
assign data[222]= {8'h00,8'h00,8'h00} ;
assign data[223]= {8'h00,8'h00,8'h00} ;
assign data[224]= {8'h00,8'h00,8'h00} ;//4
assign data[225]= {8'hff,8'hff,8'hff} ;
assign data[226]= {8'hff,8'hff,8'hff} ;
assign data[227]= {8'h00,8'h00,8'h00} ;
assign data[228] = {8'h00,8'h00,8'h00} ;
assign data[229] = {8'h00,8'h00,8'h00} ;
assign data[230] = {8'h00,8'h00,8'h00} ;
assign data[231] = {8'h00,8'h00,8'h00} ;
assign data[232] = {8'h00,8'h00,8'h00} ;//5
assign data[233] = {8'hff,8'hff,8'hff} ;
assign data[234] = {8'h00,8'h00,8'h00} ;
assign data[235] = {8'hff,8'hff,8'hff} ;
assign data[236] = {8'h00,8'h00,8'h00} ;
assign data[237] = {8'h00,8'h00,8'h00} ;
assign data[238] = {8'h00,8'h00,8'h00} ;
assign data[239] = {8'h00,8'h00,8'h00} ;
assign data[240] = {8'h00,8'h00,8'h00} ;//6
assign data[241] = {8'hff,8'hff,8'hff} ;
assign data[242] = {8'h00,8'h00,8'h00} ;
assign data[243] = {8'h00,8'h00,8'h00} ;
assign data[244] = {8'hff,8'hff,8'hff} ;
assign data[245] = {8'h00,8'h00,8'h00} ;
assign data[246] = {8'h00,8'h00,8'h00} ;
assign data[247] = {8'h00,8'h00,8'h00} ;
assign data[248] = {8'h00,8'h00,8'h00} ;//7
assign data[249] = {8'hff,8'hff,8'hff} ;
assign data[250] = {8'h00,8'h00,8'h00} ;
assign data[251] = {8'h00,8'h00,8'h00} ;
assign data[252] = {8'h00,8'h00,8'h00} ;
assign data[253] = {8'hff,8'hff,8'hff} ;
assign data[254] = {8'h00,8'h00,8'h00} ;
assign data[255] = {8'h00,8'h00,8'h00} ;
endmodule

@ -0,0 +1,72 @@
module ges_ws2812(
input wire sys_clk ,
input wire sys_rst_n ,
output wire scl ,
inout wire sda ,
output wire [3: 0] led ,
output wire dout
);
wire [2: 0] step ;
wire [5: 0] cfg_num ;
wire [15: 0] cfg_data ;
wire cfg_start ;
wire i2c_clk ;
wire i2c_start ;
wire [7: 0] po_data ;
wire [3: 0] ges_data ;
wire bit ;
wire [4: 0] cnt_bit ;
wire [6: 0] cnt_pixel ;
assign ges_data = po_data[3: 0];
paj7620_cfg paj7620_cfg_inst(
.i2c_clk (i2c_clk ),
.sys_rst_n (sys_rst_n ),
.cfg_start (cfg_start ),
.step (step ),
.cfg_num (cfg_num ),
.cfg_data (cfg_data ),
.i2c_start (i2c_start )
);
i2c_ctrl i2c_ctrl_inst(
.sys_clk (sys_clk ),
.sys_rst_n (sys_rst_n ),
.i2c_start (i2c_start ),
.cfg_num (cfg_num ),
.cfg_data (cfg_data ),
.cfg_start (cfg_start ),
.step (step ),
.i2c_clk (i2c_clk ),
.scl (scl ),
.sda (sda ),
.po_data (po_data )
);
led_ctrl led_ctrl_inst(
.sys_clk (sys_clk ),
.sys_rst_n (sys_rst_n ),
.ges_data (ges_data ),
.led (led )
);
ws2812_ctrl ws2812_ctrl_inst(
.sys_clk (sys_clk ),
.sys_rst_n (sys_rst_n ),
.bit (bit ),//01
.cnt_bit (cnt_bit ),
.cnt_pixel (cnt_pixel ),
.dout (dout )
);
data_cfg data_cfg_inst(
.cnt_bit (cnt_bit ),
.cnt_pixel (cnt_pixel ),
.ges_data (ges_data ),
.bit (bit )
);
endmodule

@ -0,0 +1,754 @@
module i2c_ctrl(
input wire sys_clk ,
input wire sys_rst_n ,
input wire i2c_start ,
input wire [5: 0] cfg_num ,
input wire [15: 0] cfg_data ,
output reg cfg_start ,
output reg [2: 0] step ,
output reg i2c_clk ,
output wire scl ,
inout wire sda ,
output reg [7: 0] po_data
);
parameter I2C_CLK_DIV = 5'd24,
MAX = 10'd1000,
SLAVE_ID = 7'h73;
//
parameter IDLE = 4'd0,
START = 4'd1,
SLAVE_ADDR = 4'd2,
ACK_1 = 4'd3,
ACK_2 = 4'd4,
ACK_3 = 4'd5,
DEVICE_ADDR = 4'd6,
DATA = 4'd7,
WAIT = 4'd8,
NACK = 4'd9,
STOP = 4'd10;
reg [3: 0] state_c;
reg [3: 0] state_n;
////
//i2c
reg [4: 0] cnt_clk;
/////
//
reg [9: 0] cnt_wait ;//1000us
reg skip_en_1 ;//1,
reg skip_en_2 ;//2,bank0
reg skip_en_3 ;//3,0x00
reg skip_en_4 ;//4,0x20
reg skip_en_5 ;//5,51
reg skip_en_6 ;//6,0x43
reg skip_en_7 ;//7,0x43
reg [1: 0] cnt_i2c_clk ;//i2c
reg [2: 0] cnt_bit ;//bit
reg i2c_end ;//i2c
wire sda_en ;
wire sda_in ;
reg i2c_sda ;
reg i2c_scl ;
reg [7: 0] slave_addr ;
reg [7: 0] device_addr ;
reg [7: 0] wr_data ;
reg [7: 0] recv_data ;//0x20
reg ack ;//
reg err_en ;//0x20
//
assign sda_en = ((state_c == ACK_1) || (state_c == ACK_2) || (state_c == ACK_3) || (state_c == DATA && (step == 3'd3 || step == 3'd6))) ? 1'b0: 1'b1;//
assign sda_in = sda;
assign sda = (sda_en == 1'b1)? i2c_sda : 1'bz;
//cfg_start
always @(posedge i2c_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cfg_start <= 1'b0;
end
else begin
cfg_start <= i2c_end;//
end
end
//i2c
always @(posedge sys_clk or negedge sys_rst_n) begin
if(!sys_rst_n)begin
cnt_clk <= 5'd0;
end
else if(cnt_clk == I2C_CLK_DIV)begin
cnt_clk <= 5'd0;
end
else begin
cnt_clk <= cnt_clk + 1;
end
end
always @(posedge sys_clk or negedge sys_rst_n) begin
if(!sys_rst_n)begin
i2c_clk <= 1'b1;
end
else if(cnt_clk == I2C_CLK_DIV)begin
i2c_clk <= ~i2c_clk;
end
else begin
i2c_clk <= i2c_clk;
end
end
/////////
//
always @(posedge i2c_clk or negedge sys_rst_n) begin
if(!sys_rst_n)begin
state_c <= IDLE;
end
else begin
state_c <= state_n;
end
end
//
always @(*)begin
case(state_c)
IDLE: if((skip_en_1 == 1'b1) || (skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_4 == 1'b1) || (skip_en_5 == 1'b1) || (skip_en_6 == 1'b1) || (skip_en_7 == 1'b1))begin
state_n = START;
end
else begin
state_n = IDLE;
end
START: if((skip_en_1 == 1'b1) || (skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_4 == 1'b1) || (skip_en_5 == 1'b1) || (skip_en_6 == 1'b1) || (skip_en_7 == 1'b1))begin
state_n = SLAVE_ADDR;
end
else begin
state_n = START;
end
SLAVE_ADDR: if(skip_en_1 == 1'b1)begin
state_n = WAIT;
end
else if((skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_4 == 1'b1) || (skip_en_5 == 1'b1) || (skip_en_6 == 1'b1) || (skip_en_7 == 1'b1))begin
state_n = ACK_1;
end
else begin
state_n = SLAVE_ADDR;
end
ACK_1: if((skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_5 == 1'b1) || (skip_en_6 == 1'b1))begin
state_n = DEVICE_ADDR;
end
else if((skip_en_4 == 1'b1) || (skip_en_7 == 1'b1))begin
state_n = DATA;
end
else begin
state_n = ACK_1;
end
DEVICE_ADDR:if((skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_5 == 1'b1) || (skip_en_6 == 1'b1))begin
state_n = ACK_2;
end
else begin
state_n = DEVICE_ADDR;
end
ACK_2: if((skip_en_2 == 1'b1) || (skip_en_5 == 1'b1))begin
state_n = DATA;
end
else if((skip_en_3 == 1'b1) || (skip_en_6 == 1'b1))begin
state_n = STOP;
end
else begin
state_n = ACK_2;
end
DATA: if((skip_en_2 == 1'b1) || (skip_en_5 == 1'b1))begin
state_n = ACK_3;
end
else if((skip_en_4 == 1'b1) || (skip_en_7 == 1'b1))begin
state_n = NACK;
end
else if(err_en == 1'b1)begin
state_n = IDLE;
end
else begin
state_n = DATA;
end
NACK: if((skip_en_4 == 1'b1) || (skip_en_7 == 1'b1))begin
state_n = STOP;
end
else begin
state_n = NACK;
end
ACK_3: if((skip_en_2 == 1'b1) || (skip_en_5 == 1'b1))begin
state_n = STOP;
end
else begin
state_n = ACK_3;
end
WAIT: if(skip_en_1 == 1'b1)begin
state_n = STOP;
end
else begin
state_n = WAIT;
end
STOP: if((skip_en_1 == 1'b1) || (skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_4 == 1'b1) || (skip_en_5 == 1'b1) || (skip_en_6 == 1'b1) || (skip_en_7 == 1'b1))begin
state_n = IDLE;
end
else begin
state_n = STOP;
end
default: begin
state_n = IDLE;
end
endcase
end
//
always @(posedge i2c_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_wait <= 10'd0;
skip_en_1 <= 1'b0;//1
skip_en_2 <= 1'b0;//2
skip_en_3 <= 1'b0;//3
skip_en_4 <= 1'b0;//4
skip_en_5 <= 1'b0;//5
skip_en_6 <= 1'b0;//6
skip_en_7 <= 1'b0;//7
step <= 3'd0;
err_en <= 1'b0;
cnt_i2c_clk <= 2'd0;
cnt_bit <= 3'd0;
i2c_end <= 1'b0;
end
else begin
case(state_c)
IDLE: begin
if(cnt_wait == MAX - 1)begin
cnt_wait <= 10'd0;
end
else begin
cnt_wait <= cnt_wait + 1;
end
if((cnt_wait == MAX - 2'd2) && (step == 3'd0))begin
skip_en_1 <= 1'b1;
end
else begin
skip_en_1 <= 1'b0;
end
if((cnt_wait == MAX - 2'd2) && (step == 3'd1))begin
skip_en_2 <= 1'b1;
end
else begin
skip_en_2 <= 1'b0;
end
if((cnt_wait == MAX - 2'd2) && (step == 3'd2))begin
skip_en_3 <= 1'b1;
end
else begin
skip_en_3 <= 1'b0;
end
if((cnt_wait == MAX - 2'd2) && (step == 3'd3))begin
skip_en_4 <= 1'b1;
end
else begin
skip_en_4 <= 1'b0;
end
if((cnt_wait == MAX - 2'd2) && (step == 3'd4))begin
skip_en_5 <= 1'b1;
end
else begin
skip_en_5 <= 1'b0;
end
if((cnt_wait == MAX - 2'd2) && (step == 3'd5))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
if((cnt_wait == MAX - 2'd2) && (step == 3'd6))begin
skip_en_7 <= 1'b1;
end
else begin
skip_en_7 <= 1'b0;
end
end
START: begin
cnt_i2c_clk <= cnt_i2c_clk + 1'd1;
if((cnt_i2c_clk == 2'd2) && (step == 3'd0))begin
skip_en_1 <= 1'b1;
end
else begin
skip_en_1 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd1))begin
skip_en_2 <= 1'b1;
end
else begin
skip_en_2 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd2))begin
skip_en_3 <= 1'b1;
end
else begin
skip_en_3 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd3))begin
skip_en_4 <= 1'b1;
end
else begin
skip_en_4 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd4))begin
skip_en_5 <= 1'b1;
end
else begin
skip_en_5 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd5))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd6))begin
skip_en_7 <= 1'b1;
end
else begin
skip_en_7 <= 1'b0;
end
end
SLAVE_ADDR: begin
cnt_i2c_clk <= cnt_i2c_clk + 1'd1;
if((cnt_i2c_clk == 2'd2) && (step == 3'd0) && (cnt_bit == 3'd7))begin
skip_en_1 <= 1'b1;
end
else begin
skip_en_1 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd1) && (cnt_bit == 3'd7))begin
skip_en_2 <= 1'b1;
end
else begin
skip_en_2 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd2) && (cnt_bit == 3'd7))begin
skip_en_3 <= 1'b1;
end
else begin
skip_en_3 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd3) && (cnt_bit == 3'd7))begin
skip_en_4 <= 1'b1;
end
else begin
skip_en_4 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd4) && (cnt_bit == 3'd7))begin
skip_en_5 <= 1'b1;
end
else begin
skip_en_5 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd5) && (cnt_bit == 3'd7))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd6) && (cnt_bit == 3'd7))begin
skip_en_7 <= 1'b1;
end
else begin
skip_en_7 <= 1'b0;
end
if((cnt_bit == 3'd7) && (cnt_i2c_clk == 2'd3))begin
cnt_bit <= 3'd0;
end
else if(cnt_i2c_clk == 2'd3)begin
cnt_bit <= cnt_bit + 1'd1;
end
else begin
cnt_bit <= cnt_bit;
end
end
ACK_1: begin
cnt_i2c_clk <= cnt_i2c_clk + 1'd1;
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd1))begin
skip_en_2 <= 1'b1;
end
else begin
skip_en_2 <= 1'b0;
end
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd2))begin
skip_en_3 <= 1'b1;
end
else begin
skip_en_3 <= 1'b0;
end
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd3))begin
skip_en_4 <= 1'b1;
end
else begin
skip_en_4 <= 1'b0;
end
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd4))begin
skip_en_5 <= 1'b1;
end
else begin
skip_en_5 <= 1'b0;
end
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd5))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd6))begin
skip_en_7 <= 1'b1;
end
else begin
skip_en_7 <= 1'b0;
end
end
DEVICE_ADDR:begin
cnt_i2c_clk <= cnt_i2c_clk + 1'b1;
if((cnt_i2c_clk == 2'd3) && (cnt_bit == 3'd7))begin
cnt_bit <= 3'd0;
end
else if(cnt_i2c_clk == 2'd3)begin
cnt_bit <= cnt_bit + 1'b1;
end
else begin
cnt_bit <= cnt_bit;
end
if((cnt_i2c_clk == 2'd2) && (cnt_bit == 3'd7) && (step == 3'd1))begin
skip_en_2 <= 1'b1;
end
else begin
skip_en_2 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (cnt_bit == 3'd7) && (step == 3'd2))begin
skip_en_3 <= 1'b1;
end
else begin
skip_en_3 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (cnt_bit == 3'd7) && (step == 3'd4))begin
skip_en_5 <= 1'b1;
end
else begin
skip_en_5 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (cnt_bit == 3'd7) && (step == 3'd5))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
end
ACK_2: begin
cnt_i2c_clk <= cnt_i2c_clk + 1;
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd1))begin
skip_en_2 <= 1'b1;
end
else begin
skip_en_2 <= 1'b0;
end
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd2))begin
skip_en_3 <= 1'b1;
end
else begin
skip_en_3 <= 1'b0;
end
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd4))begin
skip_en_5 <= 1'b1;
end
else begin
skip_en_5 <= 1'b0;
end
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd5))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
end
DATA: begin
cnt_i2c_clk <= cnt_i2c_clk + 1'b1;
if((cnt_i2c_clk == 2'd3) && (cnt_bit == 3'd7))begin
cnt_bit <= 3'd0;
end
else if(cnt_i2c_clk == 2'd3)begin
cnt_bit <= cnt_bit + 1'b1;
end
else begin
cnt_bit <= cnt_bit;
end
if((cnt_i2c_clk == 2'd2) && (cnt_bit == 3'd7) && (step == 3'd1))begin
skip_en_2 <= 1'b1;
end
else begin
skip_en_2 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (cnt_bit == 3'd7) && (step == 3'd3) && (recv_data == 8'h20))begin
skip_en_4 <= 1'b1;
end
else begin
skip_en_4 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (cnt_bit == 3'd7) && (step == 3'd4))begin
skip_en_5 <= 1'b1;
end
else begin
skip_en_5 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (cnt_bit == 3'd7) && (step == 3'd6))begin
skip_en_7 <= 1'b1;
end
else begin
skip_en_7 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (cnt_bit == 3'd7) && (step == 3'd3) && (recv_data != 8'h20))begin
begin
err_en <= 1'b1;
step <= 3'd0;
end
end
else begin
begin
err_en <= 1'b0;
step <= step;
end
end
end
NACK: begin
cnt_i2c_clk <= cnt_i2c_clk + 1;
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd3))begin
skip_en_4 <= 1'b1;
end
else begin
skip_en_4 <= 1'b0;
end
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd6))begin
skip_en_7 <= 1'b1;
end
else begin
skip_en_7 <= 1'b0;
end
end
ACK_3: begin
cnt_i2c_clk <= cnt_i2c_clk + 1;
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd1))begin
skip_en_2 <= 1'b1;
end
else begin
skip_en_2 <= 1'b0;
end
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd4))begin
skip_en_5 <= 1'b1;
end
else begin
skip_en_5 <= 1'b0;
end
end
WAIT: begin
if(cnt_wait == MAX - 1'd1)begin
cnt_wait <= 10'd0;
end
else begin
cnt_wait <= cnt_wait + 1'd1;
end
if((cnt_wait == MAX - 2'd2) && (step == 3'd0))begin
skip_en_1 <= 1'b1;
end
else begin
skip_en_1 <= 1'b0;
end
end
STOP: begin
cnt_i2c_clk <= cnt_i2c_clk + 1'd1;
if((cnt_i2c_clk == 2'd2) && (step == 3'd0))begin
skip_en_1 <= 1'b1;
end
else begin
skip_en_1 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd1))begin
skip_en_2 <= 1'b1;
end
else begin
skip_en_2 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd2))begin
skip_en_3 <= 1'b1;
end
else begin
skip_en_3 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd3))begin
skip_en_4 <= 1'b1;
end
else begin
skip_en_4 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd4))begin
skip_en_5 <= 1'b1;
end
else begin
skip_en_5 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd5))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd6))begin
skip_en_7 <= 1'b1;
end
else begin
skip_en_7 <= 1'b0;
end
if(cnt_i2c_clk == 2'd2)begin
i2c_end <= 1'b1;
end
else begin
i2c_end <= 1'b0;
end
if((i2c_end == 1'b1) && ((step <= 3'd3) || step == 3'd5))begin
step <= step + 1'd1;
end
else if((i2c_end == 1'b1) && (step == 3'd4) && (cfg_num == 6'd51))begin
step <= step + 1'd1;
end
else begin
step <= step;
end
end
default: begin
cnt_wait <= 10'd0;
skip_en_1 <= 1'b0;
skip_en_2 <= 1'b0;
skip_en_3 <= 1'b0;
skip_en_4 <= 1'b0;
skip_en_5 <= 1'b0;
skip_en_6 <= 1'b0;
skip_en_7 <= 1'b0;
err_en <= 1'b0;
step <= step;
cnt_i2c_clk <= 2'd0;
cnt_bit <= 3'd0;
i2c_end <= 1'b0;
end
endcase
end
end
//recv_data
always @(posedge i2c_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
recv_data <= 8'h0;
end
else begin
case(state_c)
DATA: begin
if((cnt_i2c_clk == 2'd1) && ((step == 3'd3) || (step == 3'd6)))begin
recv_data <= {recv_data[6:0], sda_in};
end
else begin
recv_data <= recv_data;
end
end
default: recv_data <= recv_data;
endcase
end
end
//ack
always @(*)begin
case(state_c)
ACK_1, ACK_2, ACK_3: ack = ~sda_in;
NACK: ack = i2c_sda;//NACK
default: ack = 1'b0;
endcase
end
//step
always @(*)begin
case(step)
3'd0: begin
slave_addr = {SLAVE_ID, 1'b0};
device_addr = 8'h0;
wr_data = 8'h0;
end
3'd1: begin
slave_addr = {SLAVE_ID, 1'b0};
device_addr= {8'hef};
wr_data = {8'h00};
end
3'd2: begin
slave_addr = {SLAVE_ID, 1'b0};
device_addr= {8'h00};
wr_data = {8'h00};
end
3'd3: begin
slave_addr = {SLAVE_ID, 1'b1};//
device_addr= {8'h00};
wr_data = {8'h00};
end
3'd4: begin
slave_addr = {SLAVE_ID, 1'b0};
device_addr= cfg_data[15: 8];
wr_data = cfg_data[7: 0];
end
3'd5: begin
slave_addr = {SLAVE_ID, 1'b0};//
device_addr= 8'h43;
wr_data = 8'h00;
end
3'd6: begin
slave_addr = {SLAVE_ID, 1'b1};//
device_addr= 8'h43;
wr_data = 8'h00;
end
default:begin
slave_addr = 8'h0;
device_addr = 8'h0;
wr_data = 8'h0;
end
endcase
end
//i2c_scl
always @(*)begin
case(state_c)
IDLE: i2c_scl = 1'b1;
START: i2c_scl = (cnt_i2c_clk <= 2'd2) ? 1'b1 : 1'b0;
SLAVE_ADDR, DEVICE_ADDR, DATA, ACK_1, ACK_2, ACK_3, NACK:
i2c_scl = ((cnt_i2c_clk == 2'd1) || (cnt_i2c_clk == 2'd2)) ? 1'b1 : 1'b0;
WAIT: i2c_scl = 1'b0;
STOP: i2c_scl = (cnt_i2c_clk >= 2'd1) ? 1'b1 : 1'b0;
endcase
end
//i2c_sda
always @(*)begin
case(state_c)
IDLE: i2c_sda = 1'b1;
START: i2c_sda = (cnt_i2c_clk > 2'd1) ? 1'b0 : 1'b1;
SLAVE_ADDR: i2c_sda = slave_addr[7 - cnt_bit];
DEVICE_ADDR:i2c_sda = device_addr[7 - cnt_bit];
DATA: if((step == 3'd3) || (step == 3'd6))begin
i2c_sda = sda_in;
end
else begin
i2c_sda = wr_data[7 - cnt_bit];
end
ACK_1, ACK_2, ACK_3:
i2c_sda = 1'b0;
WAIT: i2c_sda = 1'b0;
NACK: i2c_sda = 1'b1;//1
STOP: i2c_sda = (cnt_i2c_clk >= 2'd2) ? 1'b1 : 1'b0;
default: i2c_sda = 1'b1;
endcase
end
assign scl = i2c_scl;
always @(posedge i2c_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
po_data <= 8'h0;
end
else if((state_c == DATA) && (step == 3'd6) && (cnt_bit == 3'd7) && (cnt_i2c_clk == 2'd3) && (recv_data != 8'h00))begin
po_data <= recv_data;
end
else begin
po_data <= po_data;
end
end
endmodule

@ -0,0 +1,17 @@
module led_ctrl(
input wire sys_clk ,
input wire sys_rst_n ,
input wire [3: 0] ges_data ,
output reg [3: 0] led
);
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
led <= 4'b0000;
end
else begin
led <= ges_data;
end
end
endmodule

@ -0,0 +1,86 @@
module paj7620_cfg(
input wire i2c_clk ,
input wire sys_rst_n ,
input wire cfg_start ,
input wire [2: 0] step ,
output reg [5: 0] cfg_num ,
output wire [15: 0] cfg_data ,
output reg i2c_start
);
wire [15: 0] cfg_data_reg[50: 0];
always @(posedge i2c_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cfg_num <= 6'd0;
end
else if((cfg_start == 1'b1) && (step == 3'd4))begin
cfg_num <= cfg_num + 1'd1;
end
else begin
cfg_num <= cfg_num;
end
end
always @(posedge i2c_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
i2c_start <= 1'b0;
end
else if((cfg_data == 1'b1) && (step == 3'd4))begin
i2c_start <= 1'b1;
end
else begin
i2c_start <= 1'b0;
end
end
assign cfg_data = (step == 3'd4) ? cfg_data_reg[cfg_num - 1]:16'h0;
assign cfg_data_reg[00] = {8'hEF,8'h00};
assign cfg_data_reg[01] = {8'h37,8'h07};
assign cfg_data_reg[02] = {8'h38,8'h17};
assign cfg_data_reg[03] = {8'h39,8'h06};
assign cfg_data_reg[04] = {8'h42,8'h01};
assign cfg_data_reg[05] = {8'h46,8'h2D};
assign cfg_data_reg[06] = {8'h47,8'h0F};
assign cfg_data_reg[07] = {8'h48,8'h3C};
assign cfg_data_reg[08] = {8'h49,8'h00};
assign cfg_data_reg[09] = {8'h4A,8'h1E};
assign cfg_data_reg[10] = {8'h4C,8'h20};
assign cfg_data_reg[11] = {8'h51,8'h10};
assign cfg_data_reg[12] = {8'h5E,8'h10};
assign cfg_data_reg[13] = {8'h60,8'h27};
assign cfg_data_reg[14] = {8'h80,8'h42};
assign cfg_data_reg[15] = {8'h81,8'h44};
assign cfg_data_reg[16] = {8'h82,8'h04};
assign cfg_data_reg[17] = {8'h8B,8'h01};
assign cfg_data_reg[18] = {8'h90,8'h06};
assign cfg_data_reg[19] = {8'h95,8'h0A};
assign cfg_data_reg[20] = {8'h96,8'h0C};
assign cfg_data_reg[21] = {8'h97,8'h05};
assign cfg_data_reg[22] = {8'h9A,8'h14};
assign cfg_data_reg[23] = {8'h9C,8'h3F};
assign cfg_data_reg[24] = {8'hA5,8'h19};
assign cfg_data_reg[25] = {8'hCC,8'h19};
assign cfg_data_reg[26] = {8'hCD,8'h0B};
assign cfg_data_reg[27] = {8'hCE,8'h13};
assign cfg_data_reg[28] = {8'hCF,8'h64};
assign cfg_data_reg[29] = {8'hD0,8'h21};
assign cfg_data_reg[30] = {8'hEF,8'h01};
assign cfg_data_reg[31] = {8'h02,8'h0F};
assign cfg_data_reg[32] = {8'h03,8'h10};
assign cfg_data_reg[33] = {8'h04,8'h02};
assign cfg_data_reg[34] = {8'h25,8'h01};
assign cfg_data_reg[35] = {8'h27,8'h39};
assign cfg_data_reg[36] = {8'h28,8'h7F};
assign cfg_data_reg[37] = {8'h29,8'h08};
assign cfg_data_reg[38] = {8'h3E,8'hFF};
assign cfg_data_reg[39] = {8'h5E,8'h3D};
assign cfg_data_reg[40] = {8'h65,8'h96};
assign cfg_data_reg[41] = {8'h67,8'h97};
assign cfg_data_reg[42] = {8'h69,8'hCD};
assign cfg_data_reg[43] = {8'h6A,8'h01};
assign cfg_data_reg[44] = {8'h6D,8'h2C};
assign cfg_data_reg[45] = {8'h6E,8'h01};
assign cfg_data_reg[46] = {8'h72,8'h01};
assign cfg_data_reg[47] = {8'h73,8'h35};
assign cfg_data_reg[48] = {8'h74,8'h00};
assign cfg_data_reg[49] = {8'h77,8'h01};
assign cfg_data_reg[50] = {8'hEF,8'h00};
endmodule

@ -0,0 +1,161 @@
module ws2812_ctrl(
input wire sys_clk ,
input wire sys_rst_n ,
input wire bit ,//01
output reg [4: 0] cnt_bit ,
output reg [6: 0] cnt_pixel ,
output wire dout
);
parameter T0H = 30 ,
T0L = 15 ,
T1H = 30 ,
T1L = 30 ,
RST = 15000 ;
reg [5: 0] cnt_0 ;//bit0
wire add_cnt_0 ;
wire end_cnt_0 ;
reg [5: 0] cnt_1 ;//bit1
wire add_cnt_1 ;
wire end_cnt_1 ;
//RGB
wire add_cnt_bit ;
wire end_cnt_bit ;
//64
wire add_cnt_pixel;
wire end_cnt_pixel;
reg [13: 0] cnt_rst ;//
wire add_cnt_rst ;
wire end_cnt_rst ;
reg flag_0 ;
reg flag_1 ;
reg flag_rst ;
//bit0
always @(posedge sys_clk or negedge sys_rst_n) begin
if(!sys_rst_n)begin
cnt_0 <= 0;
end
else if(add_cnt_0)begin
if(end_cnt_0)begin
cnt_0 <= 0;
end
else begin
cnt_0 <= cnt_0 + 1;
end
end
else begin
cnt_0 <= 0;
end
end
assign add_cnt_0 = flag_0 && flag_rst != 1'b1;
assign end_cnt_0 = add_cnt_0 && (cnt_0 == T0H + T0L -1);
//bit1
always @(posedge sys_clk or negedge sys_rst_n) begin
if(!sys_rst_n)begin
cnt_1 <= 0;
end
else if(add_cnt_1)begin
if(end_cnt_1)begin
cnt_1 <= 0;
end
else begin
cnt_1 <= cnt_1 + 1;
end
end
else begin
cnt_1 <= 0;
end
end
assign add_cnt_1 = flag_1 && flag_rst != 1'b1;
assign end_cnt_1 = add_cnt_1 && (cnt_1 == T1H + T1L -1);
//RGB
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_bit <= 0;
end
else if(add_cnt_bit)begin
if(end_cnt_bit)begin
cnt_bit <= 0;
end
else begin
cnt_bit <= cnt_bit + 1;
end
end
else begin
cnt_bit <= cnt_bit;
end
end
assign add_cnt_bit = end_cnt_0 || end_cnt_1;
assign end_cnt_bit = add_cnt_bit && (cnt_bit == 5'd23);
//64
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_pixel <= 0;
end
else if(add_cnt_pixel)begin
if(end_cnt_pixel)begin
cnt_pixel <= 0;
end
else begin
cnt_pixel <= cnt_pixel + 1;
end
end
else begin
cnt_pixel <= cnt_pixel;
end
end
assign add_cnt_pixel = end_cnt_bit;
assign end_cnt_pixel = add_cnt_pixel && (cnt_pixel == 7'd63);
//
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_rst <= 0;
end
else if(add_cnt_rst)begin
if(end_cnt_rst)begin
cnt_rst <= 0;
end
else begin
cnt_rst <= cnt_rst + 1;
end
end
else begin
cnt_rst <= 0;
end
end
assign add_cnt_rst = flag_rst;
assign end_cnt_rst = add_cnt_rst && (cnt_rst == RST - 1);
//01
always @(*)begin
case(bit)
0: begin
flag_0 = 1;
flag_1 = 0;
end
1: begin
flag_0 = 0;
flag_1 = 1;
end
endcase
end
//flag_rst
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
flag_rst <= 0;
end
else if(end_cnt_pixel)begin
flag_rst <= 1;
end
else if(end_cnt_rst)begin
flag_rst <= 0;
end
else begin
flag_rst <= flag_rst;
end
end
assign dout = (flag_rst != 1'b1)? (((bit == 0) && (cnt_0 < T0L)) || ((bit == 1) &&(cnt_1 < T1L))): 1'b0;
endmodule

@ -0,0 +1,29 @@
# Copyright (C) 2018 Intel Corporation. All rights reserved.
# Your use of Intel Corporation's design tools, logic functions
# and other software and tools, and its AMPP partner logic
# functions, and any output files from any of the foregoing
# (including device programming or simulation files), and any
# associated documentation or information are expressly subject
# to the terms and conditions of the Intel Program License
# Subscription Agreement, the Intel Quartus Prime License Agreement,
# the Intel FPGA IP License Agreement, or other applicable license
# agreement, including, without limitation, that your use is for
# the sole purpose of programming logic devices manufactured by
# Intel and sold by Intel or its authorized distributors. Please
# refer to the applicable agreement for further details.
# Quartus Prime Version 18.1.0 Build 625 09/12/2018 SJ Lite Edition
# File: C:\Users\Stark-lin\Desktop\gesture_ws2812\tcl\gesture_ws2812.tcl
# Generated on: Thu Apr 18 09:26:34 2024
package require ::quartus::project
set_location_assignment PIN_E15 -to sys_rst_n
set_location_assignment PIN_E1 -to sys_clk
set_location_assignment PIN_D8 -to scl
set_location_assignment PIN_E7 -to sda
set_location_assignment PIN_K6 -to dout
set_location_assignment PIN_G15 -to led[0]
set_location_assignment PIN_F16 -to led[1]
set_location_assignment PIN_F15 -to led[2]
set_location_assignment PIN_D16 -to led[3]
Loading…
Cancel
Save