Skip to content

Commit

Permalink
Add UltraPlus LED driver support and demo
Browse files Browse the repository at this point in the history
  • Loading branch information
gatecat committed Nov 17, 2017
1 parent e7d22f2 commit c71db50
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 11 deletions.
12 changes: 12 additions & 0 deletions examples/up5k_rgb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.bin
*.blif
*.asc
*.rpt
*.glb
*.psb
*.sdf
*.vsb
*.bin
*.tmp/
*.exp
*.vlog
36 changes: 36 additions & 0 deletions examples/up5k_rgb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
PROJ = rgb
PIN_DEF = rgb.pcf
DEVICE = up5k
# Relative paths for easier development without messing with installed version
ARACHNE = ../../../arachne-pnr/bin/arachne-pnr
ARACHNE_ARGS = -c ../../icebox/chipdb-5k.txt
ICEPACK = ../../icepack/icepack
ICETIME = ../../icetime/icetime
ICEPROG = ../../iceprog/iceprog

all: $(PROJ).bin

%.blif: %.v
yosys -p 'synth_ice40 -top top -blif $@' $<

%.asc: $(PIN_DEF) %.blif
$(ARACHNE) $(ARACHNE_ARGS) -d $(subst up,,$(subst hx,,$(subst lp,,$(DEVICE)))) -o $@ -p $^

%.bin: %.asc
$(ICEPACK) $< $@

%.rpt: %.asc
$(ICETIME) -d $(DEVICE) -mtr $@ $<

prog: $(PROJ).bin
$(ICEPROG) -S $<

sudo-prog: $(PROJ).bin
@echo 'Executing prog as root!!!'
sudo $(ICEPROG) -S $<

clean:
rm -f $(PROJ).blif $(PROJ).asc $(PROJ).rpt $(PROJ).bin

.SECONDARY:
.PHONY: all prog clean
3 changes: 3 additions & 0 deletions examples/up5k_rgb/rgb.pcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set_io RGB0 39
set_io RGB1 40
set_io RGB2 41
81 changes: 81 additions & 0 deletions examples/up5k_rgb/rgb.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
module top(
output RGB0, RGB1, RGB2
);

wire clk;

SB_HFOSC inthosc (
.CLKHFPU(1'b1),
.CLKHFEN(1'b1),
.CLKHF(clk)
);

localparam counter_width = 30;

reg [counter_width-1:0] ctr;

always@(posedge clk)
begin
ctr <= ctr + 1;
end

localparam pwm_width = 12;

localparam pwm_max = (2**pwm_width) - 1;
localparam pwm_max_div4 = (2**(pwm_width-2)) - 1;


wire [1:0] phase = ctr[counter_width - 1 : counter_width - 2];
wire [pwm_width-1:0] fade = ctr[counter_width - 3 : counter_width - (2 + pwm_width)];
wire [pwm_width-1:0] fade_div4 = ctr[counter_width - 3 : counter_width - (pwm_width)];

wire [pwm_width-1:0] r_val, g_val, b_val;

// Fade R->G->B->W->
assign r_val = (phase == 0) ? pwm_max_div4 + (3 * fade_div4) :
(phase == 1) ? pwm_max - fade :
(phase == 3) ? fade_div4 :
0;

assign g_val = (phase == 0) ? pwm_max_div4 - fade_div4:
(phase == 1) ? fade :
(phase == 2) ? pwm_max - fade :
(phase == 3) ? fade_div4 :
0;

assign b_val = (phase == 0) ? pwm_max_div4 - fade_div4:
(phase == 2) ? fade :
(phase == 3) ? pwm_max - (3 * fade_div4) :
0;

reg [pwm_width-1:0] pwm_ctr;

reg pwm_r, pwm_g, pwm_b;

always@(posedge clk)
begin
pwm_ctr <= pwm_ctr + 1;
pwm_r <= (pwm_ctr < r_val) ? 1'b1 : 1'b0;
pwm_g <= (pwm_ctr < g_val) ? 1'b1 : 1'b0;
pwm_b <= (pwm_ctr < b_val) ? 1'b1 : 1'b0;
end

SB_RGBA_DRV RGBA_DRIVER (
.CURREN(1'b1),
.RGBLEDEN(1'b1),
.RGB0PWM(pwm_g),
.RGB1PWM(pwm_b),
.RGB2PWM(pwm_r),
.RGB0(RGB0),
.RGB1(RGB1),
.RGB2(RGB2)
);


defparam RGBA_DRIVER.CURRENT_MODE = "0b1";
defparam RGBA_DRIVER.RGB0_CURRENT = "0b000001";
defparam RGBA_DRIVER.RGB1_CURRENT = "0b000011";
defparam RGBA_DRIVER.RGB2_CURRENT = "0b000011";


endmodule
48 changes: 38 additions & 10 deletions icebox/icebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -4444,18 +4444,46 @@ def parse_db(text, device="1k"):
extra_cells_db = {
"5k" : {
("HFOSC", (0, 31, 1)) : {
"CLKHFPU": (0, 29, "lutff_0/in_1"),
"CLKHFEN": (0, 29, "lutff_7/in_3"),
"CLKHF": (0, 29, "glb_netwk_4"),
"CLKHF_FABRIC": (0, 28, "slf_op_7"),
"CLKHF_DIV_1": (0, 16, "CBIT_4"),
"CLKHF_DIV_0": (0, 16, "CBIT_3")
"CLKHFPU": (0, 29, "lutff_0/in_1"),
"CLKHFEN": (0, 29, "lutff_7/in_3"),
"CLKHF": (0, 29, "glb_netwk_4"),
"CLKHF_FABRIC": (0, 28, "slf_op_7"),
"CLKHF_DIV_1": (0, 16, "CBIT_4"),
"CLKHF_DIV_0": (0, 16, "CBIT_3")
},
("LFOSC", (25, 31, 1)) : {
"CLKLFPU": (25, 29, "lutff_0/in_1"),
"CLKLFEN": (25, 29, "lutff_7/in_3"),
"CLKLF": (25, 29, "glb_netwk_5"),
"CLKLF_FABRIC": (25, 29, "slf_op_0")
"CLKLFPU": (25, 29, "lutff_0/in_1"),
"CLKLFEN": (25, 29, "lutff_7/in_3"),
"CLKLF": (25, 29, "glb_netwk_5"),
"CLKLF_FABRIC": (25, 29, "slf_op_0")
},
("RGBA_DRV", (0, 30, 0)) : {
"CURREN": (25, 29, "lutff_6/in_3"),
"RGBLEDEN": (0, 30, "lutff_1/in_1"),
"RGB0PWM": (0, 30, "lutff_2/in_1"),
"RGB1PWM": (0, 30, "lutff_3/in_1"),
"RGB2PWM": (0, 30, "lutff_4/in_1"),
"RGBA_DRV_EN": (0, 28, "CBIT_5"),
"RGB0_CURRENT_0": (0, 28, "CBIT_6"),
"RGB0_CURRENT_1": (0, 28, "CBIT_7"),
"RGB0_CURRENT_2": (0, 29, "CBIT_0"),
"RGB0_CURRENT_3": (0, 29, "CBIT_1"),
"RGB0_CURRENT_4": (0, 29, "CBIT_2"),
"RGB0_CURRENT_5": (0, 29, "CBIT_3"),
"RGB1_CURRENT_0": (0, 29, "CBIT_4"),
"RGB1_CURRENT_1": (0, 29, "CBIT_5"),
"RGB1_CURRENT_2": (0, 29, "CBIT_6"),
"RGB1_CURRENT_3": (0, 29, "CBIT_7"),
"RGB1_CURRENT_4": (0, 30, "CBIT_0"),
"RGB1_CURRENT_5": (0, 30, "CBIT_1"),
"RGB2_CURRENT_0": (0, 30, "CBIT_2"),
"RGB2_CURRENT_1": (0, 30, "CBIT_3"),
"RGB2_CURRENT_2": (0, 30, "CBIT_4"),
"RGB2_CURRENT_3": (0, 30, "CBIT_5"),
"RGB2_CURRENT_4": (0, 30, "CBIT_6"),
"RGB2_CURRENT_5": (0, 30, "CBIT_7"),
"CURRENT_MODE": (0, 28, "CBIT_4"),

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion icebox/icebox_chipdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def print_tile_nonrouting_bits(tile_type, idx):
cellinfo = icebox.extra_cells_db[ic.device][cell]
for key in sorted(cellinfo):
print("%s %s" % (key, " ".join([str(k) for k in cellinfo[key]])))
print()
print()

print(".extra_bits")
extra_bits = dict()
Expand Down

0 comments on commit c71db50

Please sign in to comment.