Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gateware/ice40: add mux stage and direct register drive to LED block #167

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
[submodule "third_party/migen"]
path = third_party/migen
url = https://github.com/m-labs/migen.git
[submodule "third_party/litex-renode"]
path = third_party/litex-renode
url = https://github.com/litex-hub/litex-renode.git
147 changes: 80 additions & 67 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,89 +44,102 @@ env:
# cores.
- JOBS=2
matrix:
# C=cpu.variant TC="toolchain" P=platform T="target1 t2" F=firmware
#--------------------------------------------
# Base targets
# Bare-metal firmware, base targets
#--------------------------------------------
# lm32 Base targets
- C=lm32 P=arty T="base net"
- C=lm32 P=atlys T="base net"
- C=lm32 P=basys3 T="base"
- C=lm32 P=cmod_a7 T="base"
- C=lm32 P=galatea T="base"
- C=lm32 P=mimas_a7 T="base net"
- C=lm32 P=mimasv2 T="base"
- C=lm32 P=minispartan6 T="base"
- C=lm32 P=neso T="base"
- C=lm32 P=nexys_video T="base net"
- C=lm32 P=opsis T="base net"
- C=lm32 P=pipistrello T="base"
- C=lm32 P=saturn T="base"
- C=lm32 P=waxwing T="base"
# lm32 lite
- C=lm32.lite P=ice40_hx8k_b_evn T="base" F=stub
- C=lm32.lite P=ice40_up5k_b_evn T="base" F=stub
- C=lm32.lite P=icebreaker T="base" F=stub
- C=lm32.lite P=tinyfpga_bx T="base" F=stub
- C=lm32.lite P=upduino_v1 T="base" F=stub
# lm32 minimal
- C=lm32.minimal P=ice40_hx8k_b_evn T="base" F=stub
- C=lm32.minimal P=ice40_up5k_b_evn T="base" F=stub
- C=lm32.minimal P=icebreaker T="base" F=stub
- C=lm32.minimal P=tinyfpga_bx T="base" F=stub
- C=lm32.minimal P=upduino_v1 T="base" F=stub
# or1k base targets
- C=mor1kx P=arty T="base net"
- C=mor1kx P=atlys T="base net"
- C=mor1kx P=mimas_a7 T="base net"
- C=mor1kx P=mimasv2 T="base"
- C=mor1kx P=opsis T="base net"
- C=mor1kx P=pipistrello T="base"
# vexriscv Base targets
- C=vexriscv P=arty T="base net"
- C=vexriscv P=mimas_a7 T="base net"
- C=vexriscv P=mimasv2 T="base"
- C=vexriscv P=opsis T="base net"
# vexriscv lite
- C=vexriscv.lite P=upduino_v1 T="base"
# picorv32 Base targets
- C=picorv32 P=arty T="base net"
- C=picorv32 P=mimas_a7 T="base net"
- C=picorv32 P=mimasv2 T="base"
- C=picorv32 P=opsis T="base net"
- C=picorv32 P=tinyfpga_bx T="base" F=stub
# picorv32 minimal
- C=picorv32.minimal P=arty T="base net"
- C=picorv32.minimal P=icebreaker T="base" F=stub
# LatticeMico32
- C=lm32 TC="vivado" P=arty T="base net"
- C=lm32 TC="vivado" P=basys3 T="base"
- C=lm32 TC="vivado" P=cmod_a7 T="base"
- C=lm32 TC="vivado" P=mimas_a7 T="base net"
- C=lm32 TC="vivado" P=neso T="base"
- C=lm32 TC="vivado" P=nexys_video T="base net"
- C=lm32 TC="ise" P=atlys T="base net"
- C=lm32 TC="ise" P=galatea T="base"
- C=lm32 TC="ise" P=mimasv2 T="base"
- C=lm32 TC="ise" P=minispartan6 T="base"
- C=lm32 TC="ise" P=opsis T="base net"
- C=lm32 TC="ise" P=pipistrello T="base"
- C=lm32 TC="ise" P=saturn T="base"
- C=lm32 TC="ise" P=waxwing T="base"
- C=lm32.lite TC="icestorm" P=ice40_hx8k_b_evn T="base" F=stub
- C=lm32.lite TC="icestorm" P=ice40_up5k_b_evn T="base" F=stub
- C=lm32.lite TC="icestorm" P=icebreaker T="base" F=stub
- C=lm32.lite TC="icestorm" P=tinyfpga_bx T="base" F=stub
- C=lm32.lite TC="icestorm" P=upduino_v1 T="base" F=stub
- C=lm32.lite TC="vivado" P=arty T="base net"
- C=lm32.lite P=opsis T="base net"
- C=lm32.minimal TC="icestorm" P=ice40_hx8k_b_evn T="base" F=stub
- C=lm32.minimal TC="icestorm" P=ice40_up5k_b_evn T="base" F=stub
- C=lm32.minimal TC="icestorm" P=icebreaker T="base" F=stub
- C=lm32.minimal TC="icestorm" P=tinyfpga_bx T="base" F=stub
- C=lm32.minimal TC="icestorm" P=upduino_v1 T="base" F=stub
- C=lm32.minimal TC="vivado" P=arty T="base net"
- C=lm32.minimal TC="ise" P=opsis T="base net"
# OpenRISC1000
- C=mor1kx TC="vivado" P=arty T="base net"
- C=mor1kx TC="vivado" P=mimas_a7 T="base net"
- C=mor1kx TC="vivado" P=atlys T="base net"
- C=mor1kx TC="ise" P=mimasv2 T="base"
- C=mor1kx TC="ise" P=opsis T="base net"
- C=mor1kx TC="ise" P=pipistrello T="base"
# VexRISCV
- C=vexriscv TC="vivado" P=arty T="base net"
- C=vexriscv TC="vivado" P=mimas_a7 T="base net"
- C=vexriscv TC="ise" P=mimasv2 T="base"
- C=vexriscv TC="ise" P=opsis T="base net"
- C=vexriscv.lite TC="icestorm" P=ice40_hx8k_b_evn T="base" F=stub
- C=vexriscv.lite TC="icestorm" P=ice40_up5k_b_evn T="base" F=stub
- C=vexriscv.lite TC="icestorm" P=icebreaker T="base" F=stub
- C=vexriscv.lite TC="icestorm" P=tinyfpga_bx T="base" F=stub
- C=vexriscv.lite TC="icestorm" P=upduino_v1 T="base" F=stub
- C=vexriscv.lite TC="vivado" P=arty T="base net"
- C=vexriscv.lite TC="ise" P=opsis T="base net"
# PicoRV32
- C=picorv32 TC="vivado" P=arty T="base net"
- C=picorv32 TC="vivado" P=mimas_a7 T="base net"
- C=picorv32 TC="ise" P=opsis T="base net"
- C=picorv32.minimal TC="icestorm" P=icebreaker T="base" F=stub
- C=picorv32.minimal TC="vivado" P=arty T="base net"
- C=picorv32.minimal TC="ise" P=opsis T="base net"
# minerva target
- C=minerva P=arty T="base net"
#--------------------------------------------
# Linux Targets
#--------------------------------------------
- C=mor1kx.linux P=arty T="net" F=linux
- C=mor1kx.linux P=atlys T="net" F=linux
- C=mor1kx.linux P=nexys_video T="net" F=linux
- C=mor1kx.linux P=opsis T="net" F=linux
- C=minerva TC="vivado" P=arty T="base net"
- C=minerva TC="ise" P=opsis T="base net"
#--------------------------------------------
# Video Targets
#--------------------------------------------
- C=lm32 P=atlys T="video"
- C=lm32 P=nexys_video T="video"
- C=lm32 P=opsis T="video"
- C=lm32 TC="vivado" P=nexys_video T="video"
- C=lm32 TC="ise" P=atlys T="video"
- C=lm32 TC="ise" P=opsis T="video"
#--------------------------------------------
# HDMI2USB Targets
#--------------------------------------------
- C=lm32 P=atlys T="hdmi2usb"
- C=lm32 P=opsis T="hdmi2usb"
- C=lm32 TC="ise" P=atlys T="hdmi2usb"
- C=lm32 TC="ise" P=opsis T="hdmi2usb"
#--------------------------------------------
# MicroPython Targets
#--------------------------------------------
# FIXME: Add some here
#--------------------------------------------
# Linux Targets
#--------------------------------------------
- C=mor1kx.linux TC="vivado" P=arty T="net" F=linux
- C=mor1kx.linux TC="vivado" P=nexys_video T="net" F=linux
- C=mor1kx.linux TC="ise" P=atlys T="net" F=linux
- C=mor1kx.linux TC="ise" P=opsis T="net" F=linux
# FIXME: Add vexriscv.linux
# FIXME: Add rocket.linux
#--------------------------------------------
# Zephyr Targets
#--------------------------------------------
- C=vexriscv.lite P=arty T="net" F=zephyr
- C=vexriscv.lite TC="icestorm" P=icebreaker T="base" F=zephyr
- C=vexriscv.lite TC="vivado" P=arty T="net" F=zephyr
- C=vexriscv.lite TC="ise" P=atlys T="net" F=zephyr

jobs:
fail_fast: true
allow_failures:
# picorv32 config doesn't really fit on tinyfpga_bx
- env: C=picorv32 P=tinyfpga_bx T="base" F=stub
# Issue #454 - missing `pix5x_o` clock
- env: C=lm32 P=nexys_video T="video"

Expand Down
36 changes: 24 additions & 12 deletions gateware/ice40.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,29 +115,41 @@ def __init__(self, width=32, size=64*1024):


class LED(Module, AutoCSR):
def __init__(self, pads):
def __init__(self, led_defs, pads):

rgba_pwm = Signal(3)
pwm_src = Signal(3)
led_drv = Signal(3)

self.dat = CSRStorage(8)
self.addr = CSRStorage(4)
self.ctrl = CSRStorage(4)
self.ctrl = CSRStorage(3)
self.raw = CSRStorage(3)
self.mux = CSRStorage(3)

rev_map = {}
for key,value in led_defs.items():
rev_map[value["SIGNAL_INDEX"]] = key

self.specials += Instance("SB_RGBA_DRV",
i_CURREN = self.ctrl.storage[1],
i_RGBLEDEN = self.ctrl.storage[2],
i_RGB0PWM = rgba_pwm[0],
i_RGB1PWM = rgba_pwm[1],
i_RGB2PWM = rgba_pwm[2],
i_RGB0PWM = led_drv[0],
i_RGB1PWM = led_drv[1],
i_RGB2PWM = led_drv[2],
o_RGB0 = pads.rgb0,
o_RGB1 = pads.rgb1,
o_RGB2 = pads.rgb2,
p_CURRENT_MODE = "0b1",
p_RGB0_CURRENT = "0b000011",
p_RGB1_CURRENT = "0b000001",
p_RGB2_CURRENT = "0b000011",
p_RGB0_CURRENT = led_defs[rev_map[0]]["CURRENT"],
p_RGB1_CURRENT = led_defs[rev_map[1]]["CURRENT"],
p_RGB2_CURRENT = led_defs[rev_map[2]]["CURRENT"],
)

self.comb += [If(self.mux.storage[0], led_drv[led_defs["R"]["SIGNAL_INDEX"]].eq(self.raw.storage[0])).Else(led_drv[led_defs["R"]["SIGNAL_INDEX"]].eq(pwm_src[0])),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline here.

If(self.mux.storage[1], led_drv[led_defs["G"]["SIGNAL_INDEX"]].eq(self.raw.storage[1])).Else(led_drv[led_defs["R"]["SIGNAL_INDEX"]].eq(pwm_src[1])),
If(self.mux.storage[2], led_drv[led_defs["B"]["SIGNAL_INDEX"]].eq(self.raw.storage[2])).Else(led_drv[led_defs["R"]["SIGNAL_INDEX"]].eq(pwm_src[2])),
]

self.specials += Instance("SB_LEDDA_IP",
i_LEDDCS = self.dat.re,
i_LEDDCLK = ClockSignal(),
Expand All @@ -157,8 +169,8 @@ def __init__(self, pads):
i_LEDDEXE = self.ctrl.storage[0],
# o_LEDDON = led_is_on, # Indicates whether LED is on or not
# i_LEDDRST = ResetSignal(), # This port doesn't actually exist
o_PWMOUT0 = rgba_pwm[0],
o_PWMOUT1 = rgba_pwm[1],
o_PWMOUT2 = rgba_pwm[2],
o_PWMOUT0 = pwm_src[0],
o_PWMOUT1 = pwm_src[1],
o_PWMOUT2 = pwm_src[2],
o_LEDDON = Signal(),
)
7 changes: 7 additions & 0 deletions platforms/icebreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@
),
]

# 8mA (0b00000011) seems reasonable current to use here
rgb_led_defs = {
"R" : { "CURRENT" : "0b00000011", "SIGNAL_INDEX" : 0 },
"G" : { "CURRENT" : "0b00000011", "SIGNAL_INDEX" : 1 },
"B" : { "CURRENT" : "0b00000011", "SIGNAL_INDEX" : 2 },
}


class Platform(LatticePlatform):
default_clk_name = "clk12"
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-renode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ RENODE_RESC="$RENODE_SCRIPTS_DIR/litex_buildenv.resc"
RENODE_REPL="$RENODE_SCRIPTS_DIR/litex_buildenv.repl"

mkdir -p $RENODE_SCRIPTS_DIR
python $SCRIPT_DIR/generate-renode-scripts.py $LITEX_CONFIG_FILE \
python $TOP_DIR/third_party/litex-renode/generate-renode-scripts.py $LITEX_CONFIG_FILE \
--repl "$RENODE_REPL" \
--resc "$RENODE_RESC" \
--bios-binary "$TARGET_BUILD_DIR/software/bios/bios.bin" \
Expand Down
4 changes: 2 additions & 2 deletions scripts/download-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ if [ -z "${CPU_ARCH}" ]; then
fi

# Figure out the PLATFORM value
PLATFORMS=$(ls targets/ | grep -v ".py" | grep -v "common" | sed -e"s+targets/++")
if [ -z "$PLATFORM" -o ! -e targets/$PLATFORM ]; then
PLATFORMS=$(ls ${TOP_DIR}/targets/ | grep -v ".py" | grep -v "common" | sed -e"s+targets/++")
if [ -z "$PLATFORM" -o ! -e ${TOP_DIR}/targets/$PLATFORM ]; then
echo
echo "Unknown platform '$PLATFORM'"
echo
Expand Down
4 changes: 2 additions & 2 deletions scripts/enter-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ if [ -z "${CPU_ARCH}" ]; then
fi

# Figure out the PLATFORM value
PLATFORMS=$(ls targets/ | grep -v ".py" | grep -v "common" | sed -e"s+targets/++")
if [ -z "$PLATFORM" -o ! -e targets/$PLATFORM ]; then
PLATFORMS=$(ls ${TOP_DIR}/targets/ | grep -v ".py" | grep -v "common" | sed -e"s+targets/++")
if [ -z "$PLATFORM" -o ! -e ${TOP_DIR}/targets/$PLATFORM ]; then
echo
echo "Unknown platform '$PLATFORM'"
echo
Expand Down
Loading