Skip to content

Commit

Permalink
misc: code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
redchenjs committed Jun 2, 2020
1 parent 6f38afd commit ae39d7f
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 66 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WS2812 LED Controller
=====================
WS281X Cube Controller
======================

Music Light Cube WS2812 LED Controller based on MAX10 FPGA.
WS281X Cube Controller based on MAX10 FPGA.

## Main Features

Expand Down Expand Up @@ -65,7 +65,7 @@ Limits:
### Obtain the source

```
git clone https://github.com/redchenjs/ws2812_led_controller_max10.git
git clone https://github.com/redchenjs/ws281x_cube_controller_max10.git
```

### Update an existing repository
Expand Down
8 changes: 4 additions & 4 deletions rtl/layer_code.sv
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module layer_code(
input logic [ 7:0] t1l_cnt_in,
input logic [15:0] rst_cnt_in,

output logic ws2812_code_out
output logic ws281x_code_out
);

logic rd_en;
Expand All @@ -42,7 +42,7 @@ ram64 ram64(
.q(rd_data)
);

ws2812_ctrl ws2812_ctrl(
ws281x_ctrl ws281x_ctrl(
.clk_in(clk_in),
.rst_n_in(rst_n_in),

Expand All @@ -59,7 +59,7 @@ ws2812_ctrl ws2812_ctrl(
.rd_addr_out(rd_addr)
);

ws2812_code ws2812_code(
ws281x_code ws281x_code(
.clk_in(clk_in),
.rst_n_in(rst_n_in),

Expand All @@ -72,7 +72,7 @@ ws2812_code ws2812_code(
.t1l_cnt_in(t1l_cnt_in),

.bit_done_out(bit_done),
.bit_code_out(ws2812_code_out)
.bit_code_out(ws281x_code_out)
);

endmodule
2 changes: 1 addition & 1 deletion rtl/spi_slave.sv
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ edge_detect spi_sclk_edge(
.pos_edge_out(spi_sclk)
);

always @(posedge clk_in or negedge spi_rst_n)
always_ff @(posedge clk_in or negedge spi_rst_n)
begin
if (!spi_rst_n) begin
bit_sel <= 3'h0;
Expand Down
20 changes: 10 additions & 10 deletions rtl/top.sv
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Author: Jack Chen <redchenjs@live.com>
*/

module ws2812_led_controller(
module ws281x_cube_controller(
input logic clk_in, // clk_in = 12 MHz
input logic rst_n_in, // rst_n_in, active low

Expand All @@ -14,7 +14,7 @@ module ws2812_led_controller(
input logic spi_mosi_in,
input logic spi_cs_n_in,

output logic [7:0] ws2812_code_out,
output logic [7:0] ws281x_code_out,

output logic [7:0] water_led_out, // Optional, FPS Counter
output logic [8:0] segment_led_1_out, // Optional, FPS Counter
Expand Down Expand Up @@ -104,7 +104,7 @@ layer_code layer_code7(
.t1l_cnt_in(t1l_cnt),
.rst_cnt_in(rst_cnt),

.ws2812_code_out(ws2812_code_out[7])
.ws281x_code_out(ws281x_code_out[7])
);

layer_code layer_code6(
Expand All @@ -123,7 +123,7 @@ layer_code layer_code6(
.t1l_cnt_in(t1l_cnt),
.rst_cnt_in(rst_cnt),

.ws2812_code_out(ws2812_code_out[6])
.ws281x_code_out(ws281x_code_out[6])
);

layer_code layer_code5(
Expand All @@ -142,7 +142,7 @@ layer_code layer_code5(
.t1l_cnt_in(t1l_cnt),
.rst_cnt_in(rst_cnt),

.ws2812_code_out(ws2812_code_out[5])
.ws281x_code_out(ws281x_code_out[5])
);

layer_code layer_code4(
Expand All @@ -161,7 +161,7 @@ layer_code layer_code4(
.t1l_cnt_in(t1l_cnt),
.rst_cnt_in(rst_cnt),

.ws2812_code_out(ws2812_code_out[4])
.ws281x_code_out(ws281x_code_out[4])
);

layer_code layer_code3(
Expand All @@ -180,7 +180,7 @@ layer_code layer_code3(
.t1l_cnt_in(t1l_cnt),
.rst_cnt_in(rst_cnt),

.ws2812_code_out(ws2812_code_out[3])
.ws281x_code_out(ws281x_code_out[3])
);

layer_code layer_code2(
Expand All @@ -199,7 +199,7 @@ layer_code layer_code2(
.t1l_cnt_in(t1l_cnt),
.rst_cnt_in(rst_cnt),

.ws2812_code_out(ws2812_code_out[2])
.ws281x_code_out(ws281x_code_out[2])
);

layer_code layer_code1(
Expand All @@ -218,7 +218,7 @@ layer_code layer_code1(
.t1l_cnt_in(t1l_cnt),
.rst_cnt_in(rst_cnt),

.ws2812_code_out(ws2812_code_out[1])
.ws281x_code_out(ws281x_code_out[1])
);

layer_code layer_code0(
Expand All @@ -237,7 +237,7 @@ layer_code layer_code0(
.t1l_cnt_in(t1l_cnt),
.rst_cnt_in(rst_cnt),

.ws2812_code_out(ws2812_code_out[0])
.ws281x_code_out(ws281x_code_out[0])
);

pulse_counter fps_counter(
Expand Down
4 changes: 2 additions & 2 deletions rtl/ws2812_code.sv → rtl/ws281x_code.sv
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* ws2812_code.sv
* ws281x_code.sv
*
* Created on: 2020-04-06 23:09
* Author: Jack Chen <redchenjs@live.com>
*/

module ws2812_code(
module ws281x_code(
input logic clk_in,
input logic rst_n_in,

Expand Down
4 changes: 2 additions & 2 deletions rtl/ws2812_ctrl.sv → rtl/ws281x_ctrl.sv
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* ws2812_ctrl.sv
* ws281x_ctrl.sv
*
* Created on: 2020-04-06 23:09
* Author: Jack Chen <redchenjs@live.com>
*/

module ws2812_ctrl(
module ws281x_ctrl(
input logic clk_in,
input logic rst_n_in,

Expand Down
40 changes: 20 additions & 20 deletions simulation/test.sv
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ logic spi_sclk_in;
logic spi_mosi_in;
logic spi_cs_n_in;

logic [7:0] ws2812_data_out;
logic [7:0] ws281x_code_out;

ws2812_led_controller test(
ws281x_cube_controller test(
.clk_in(clk_in),
.rst_n_in(rst_n_in),

Expand All @@ -28,32 +28,32 @@ ws2812_led_controller test(
.spi_mosi_in(spi_mosi_in),
.spi_cs_n_in(spi_cs_n_in),

.ws2812_data_out(ws2812_data_out)
.ws281x_code_out(ws281x_code_out)
);

always begin
clk_in <= 0;
rst_n_in <= 1;
clk_in <= 1'b0;
rst_n_in <= 1'b1;

dc_in <= 0;
spi_sclk_in <= 0;
spi_mosi_in <= 0;
spi_cs_n_in <= 1;
dc_in <= 1'b0;
spi_sclk_in <= 1'b0;
spi_mosi_in <= 1'b0;
spi_cs_n_in <= 1'b1;

#500 spi_cs_n_in <= 0;
#50 spi_cs_n_in <= 1'b0;

spi_mosi_in <= 1; // 0
#25 spi_mosi_in <= 1; // 1
#25 spi_mosi_in <= 0; // 2
#25 spi_mosi_in <= 1; // 3
#25 spi_mosi_in <= 1; // 4
#25 spi_mosi_in <= 0; // 5
#25 spi_mosi_in <= 1; // 6
#25 spi_mosi_in <= 0; // 7
spi_mosi_in <= 1'b1; // 0
#25 spi_mosi_in <= 1'b1; // 1
#25 spi_mosi_in <= 1'b0; // 2
#25 spi_mosi_in <= 1'b1; // 3
#25 spi_mosi_in <= 1'b1; // 4
#25 spi_mosi_in <= 1'b0; // 5
#25 spi_mosi_in <= 1'b1; // 6
#25 spi_mosi_in <= 1'b0; // 7

#25 spi_cs_n_in <= 1;
#25 spi_cs_n_in <= 1'b1;

#500 $stop;
#50 $stop;
end

always begin
Expand Down
2 changes: 1 addition & 1 deletion ws2812_led_controller.qpf → ws281x_cube_controller.qpf
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ DATE = "07:48:26 April 25, 2020"

# Revisions

PROJECT_REVISION = "ws2812_led_controller"
PROJECT_REVISION = "ws281x_cube_controller"
44 changes: 22 additions & 22 deletions ws2812_led_controller.qsf → ws281x_cube_controller.qsf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# Notes:
#
# 1) The default values for assignments are stored in the file:
# ws2812_led_controller_assignment_defaults.qdf
# ws281x_cube_controller_assignment_defaults.qdf
# If this file doesn't exist, see file:
# assignment_defaults.qdf
#
Expand All @@ -53,8 +53,8 @@ set_global_assignment -name SYSTEMVERILOG_FILE rtl/spi_slave.sv
set_global_assignment -name SYSTEMVERILOG_FILE rtl/layer_ctrl.sv
set_global_assignment -name SYSTEMVERILOG_FILE rtl/layer_conf.sv
set_global_assignment -name SYSTEMVERILOG_FILE rtl/layer_code.sv
set_global_assignment -name SYSTEMVERILOG_FILE rtl/ws2812_ctrl.sv
set_global_assignment -name SYSTEMVERILOG_FILE rtl/ws2812_code.sv
set_global_assignment -name SYSTEMVERILOG_FILE rtl/ws281x_ctrl.sv
set_global_assignment -name SYSTEMVERILOG_FILE rtl/ws281x_code.sv
set_global_assignment -name SYSTEMVERILOG_FILE rtl/segment_led.sv
set_global_assignment -name SYSTEMVERILOG_FILE rtl/pulse_counter.sv
set_global_assignment -name QIP_FILE ip/pll/pll.qip
Expand All @@ -69,14 +69,14 @@ set_location_assignment PIN_P15 -to dc_in
set_location_assignment PIN_R14 -to spi_sclk_in
set_location_assignment PIN_P12 -to spi_mosi_in
set_location_assignment PIN_R11 -to spi_cs_n_in
set_location_assignment PIN_R5 -to ws2812_code_out[7]
set_location_assignment PIN_L7 -to ws2812_code_out[6]
set_location_assignment PIN_P4 -to ws2812_code_out[5]
set_location_assignment PIN_L6 -to ws2812_code_out[4]
set_location_assignment PIN_R3 -to ws2812_code_out[3]
set_location_assignment PIN_M5 -to ws2812_code_out[2]
set_location_assignment PIN_P3 -to ws2812_code_out[1]
set_location_assignment PIN_M4 -to ws2812_code_out[0]
set_location_assignment PIN_R5 -to ws281x_code_out[7]
set_location_assignment PIN_L7 -to ws281x_code_out[6]
set_location_assignment PIN_P4 -to ws281x_code_out[5]
set_location_assignment PIN_L6 -to ws281x_code_out[4]
set_location_assignment PIN_R3 -to ws281x_code_out[3]
set_location_assignment PIN_M5 -to ws281x_code_out[2]
set_location_assignment PIN_P3 -to ws281x_code_out[1]
set_location_assignment PIN_M4 -to ws281x_code_out[0]
set_location_assignment PIN_N15 -to water_led_out[7]
set_location_assignment PIN_N14 -to water_led_out[6]
set_location_assignment PIN_M14 -to water_led_out[5]
Expand Down Expand Up @@ -119,7 +119,7 @@ set_global_assignment -name OPTIMIZATION_MODE "AGGRESSIVE PERFORMANCE"
set_global_assignment -name FAMILY "MAX 10"
set_global_assignment -name VHDL_INPUT_VERSION VHDL_2008
set_global_assignment -name VERILOG_INPUT_VERSION SYSTEMVERILOG_2005
set_global_assignment -name TOP_LEVEL_ENTITY ws2812_led_controller
set_global_assignment -name TOP_LEVEL_ENTITY ws281x_cube_controller

# Fitter Assignments
# ==================
Expand Down Expand Up @@ -205,7 +205,7 @@ set_global_assignment -name POWER_USE_DEVICE_CHARACTERISTICS MAXIMUM
# --------------------------------------------------------

# -----------------------------------
# start ENTITY(ws2812_led_controller)
# start ENTITY(ws281x_cube_controller)

# Fitter Assignments
# ==================
Expand All @@ -215,14 +215,14 @@ set_global_assignment -name POWER_USE_DEVICE_CHARACTERISTICS MAXIMUM
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to spi_sclk_in
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to spi_mosi_in
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to spi_cs_n_in
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws2812_code_out[7]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws2812_code_out[6]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws2812_code_out[5]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws2812_code_out[4]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws2812_code_out[3]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws2812_code_out[2]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws2812_code_out[1]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws2812_code_out[0]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws281x_code_out[7]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws281x_code_out[6]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws281x_code_out[5]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws281x_code_out[4]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws281x_code_out[3]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws281x_code_out[2]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws281x_code_out[1]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to ws281x_code_out[0]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to water_led_out[7]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to water_led_out[6]
set_instance_assignment -name IO_STANDARD "3.3-V LVCMOS" -to water_led_out[5]
Expand Down Expand Up @@ -262,6 +262,6 @@ set_global_assignment -name POWER_USE_DEVICE_CHARACTERISTICS MAXIMUM
# end DESIGN_PARTITION(Top)
# -------------------------

# end ENTITY(ws2812_led_controller)
# end ENTITY(ws281x_cube_controller)
# ---------------------------------
set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top
File renamed without changes.

0 comments on commit ae39d7f

Please sign in to comment.