tools/litex_client/run_gui: Add Identifier/Leds/Buttons peripherals support.

This commit is contained in:
Florent Kermarrec 2022-08-05 15:25:13 +02:00
parent 95a4814184
commit b792bfd8b2
1 changed files with 65 additions and 4 deletions

View File

@ -156,7 +156,10 @@ def run_gui(host, csr_csv, port):
# Board capabilities.
# -------------------
with_xadc = hasattr(bus.regs, "xadc_temperature")
with_identifier = hasattr(bus.bases, "identifier_mem")
with_leds = hasattr(bus.regs, "leds_out")
with_buttons = hasattr(bus.regs, "buttons_in")
with_xadc = hasattr(bus.regs, "xadc_temperature")
# Board functions.
# ----------------
@ -164,6 +167,32 @@ def run_gui(host, csr_csv, port):
bus.regs.ctrl_reset.write(1)
bus.regs.ctrl_reset.write(0)
if with_identifier:
def get_identifier():
identifier = ""
for i in range(256):
c = chr(bus.read(bus.bases.identifier_mem + 4*i) & 0xff)
identifier += c
if c == "\0":
break
return identifier
if with_leds:
def get_leds(led):
reg = bus.regs.leds_out.read()
return (reg >> led) & 0b1
def set_leds(led, val):
reg = bus.regs.leds_out.read()
reg &= ~(1<<led)
reg |= (val & 0b1)<<led
bus.regs.leds_out.write(reg)
if with_buttons:
def get_buttons(button):
reg = bus.regs.buttons_in.read()
return (reg >> button) & 0b1
if with_xadc:
def get_xadc_temp():
return bus.regs.xadc_temperature.read()*503.975/4096 - 273.15
@ -187,14 +216,13 @@ def run_gui(host, csr_csv, port):
# Create Main Window.
# -------------------
dpg.create_context()
dpg.create_viewport(title="LiteX CLI GUI", always_on_top=True)
dpg.create_viewport(title="LiteX CLI GUI", width=1920, height=1080, always_on_top=True)
dpg.setup_dearpygui()
# Create CSR Window.
# ------------------
with dpg.window(label="FPGA CSR Registers", autosize=True):
dpg.add_text("Control/Status")
dpg.add_button(label="Reboot", callback=reboot)
def filter_callback(sender, filter_str):
dpg.set_value("csr_filter", filter_str)
dpg.add_input_text(label="CSR Filter (inc, -exc)", callback=filter_callback)
@ -218,10 +246,33 @@ def run_gui(host, csr_csv, port):
width = 200
)
# Create Peripheral Window.
# -------------------------
with dpg.window(label="FPGA Peripherals", autosize=True, pos=(550, 0)):
dpg.add_text("SoC")
dpg.add_button(label="Reboot", callback=reboot)
if with_identifier:
dpg.add_text(f"Identifier: {get_identifier()}")
if with_leds:
dpg.add_text("Leds")
with dpg.group(horizontal=True):
def led_callback(sender):
for i in range(8): # FIXME: Get num.
if sender == f"led{i}":
val = get_leds(i)
set_leds(i, ~val)
for i in range(8): # FIXME: Get num.
dpg.add_checkbox(id=f"led{i}", callback=led_callback)
if with_buttons:
dpg.add_text("Buttons")
with dpg.group(horizontal=True):
for i in range(8): # FIXME: Get num.
dpg.add_checkbox(id=f"btn{i}")
# Create XADC Window.
# -------------------
if with_xadc:
with dpg.window(label="FPGA XADC", width=600, height=600, pos=(600, 0)):
with dpg.window(label="FPGA XADC", width=600, height=600, pos=(950, 0)):
with dpg.subplots(2, 2, label="", width=-1, height=-1) as subplot_id:
# Temperature.
with dpg.plot(label=f"Temperature (°C)"):
@ -276,6 +327,16 @@ def run_gui(host, csr_csv, port):
dpg.set_item_label(name, name)
dpg.set_axis_limits_auto(f"{name}_x")
dpg.fit_axis_data(f"{name}_x")
# Peripherals.
if with_leds:
for i in range(8): # FIXME; Get num.
dpg.set_value(f"led{i}", bool(get_leds(i)))
if with_buttons:
for i in range(8): # FIXME; Get num.
dpg.set_value(f"btn{i}", bool(get_buttons(i)))
time.sleep(refresh)
timer_thread = threading.Thread(target=timer_callback)