Skip to content

Instantly share code, notes, and snippets.

@urish
Last active June 28, 2025 13:22
Show Gist options
  • Save urish/7d5e0a6e7b0cafadb5a823b287022086 to your computer and use it in GitHub Desktop.
Save urish/7d5e0a6e7b0cafadb5a823b287022086 to your computer and use it in GitHub Desktop.
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2025, Uri Shaked
import struct
from ttboard.mode import RPMode
import ttboard.util.platform as platform
UI_START = 1 << 0
UI_LOAD_CR = 1 << 1
UI_LOAD_CI = 1 << 2
UO_UNBOUNDED = 1 << 0
def mandelbrot_load_register(value: float):
value_int = int.from_bytes(struct.pack(">f", value), "big")
platform.write_ui_in_byte(0)
platform.write_uio_byte(value_int & 0xff)
tt.clock_project_once()
platform.write_uio_byte((value_int >> 8) & 0xff)
tt.clock_project_once()
platform.write_uio_byte((value_int >> 16) & 0xff)
tt.clock_project_once()
platform.write_uio_byte((value_int >> 24) & 0xff)
def mandelbrot_init():
tt.shuttle.tt_um_mandelbrot_accel.enable()
tt.mode = RPMode.ASIC_RP_CONTROL
platform.write_ui_in_byte(0)
tt.uio_in.value = 0
tt.uio_oe_pico.value = 0xff
tt.reset_project(True)
tt.clock_project_once()
tt.reset_project(False)
def mandelbrot_run(Cr: float, Ci: float, max_iter: int = 64) -> int:
mandelbrot_load_register(Cr)
platform.write_ui_in_byte(UI_LOAD_CR)
tt.clock_project_once()
mandelbrot_load_register(Ci)
platform.write_ui_in_byte(UI_LOAD_CI | UI_START)
tt.clock_project_once()
platform.write_ui_in_byte(0)
for iter in range(max_iter):
if platform.read_uo_out_byte() & UO_UNBOUNDED:
return iter
tt.clock_project_once()
return max_iter
mandelbrot_init()
mandelbrot_run(1.2, 1.4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment