Skip to content

Commit

Permalink
add logo (temporary commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
htfab committed Jan 18, 2025
1 parent 9d3ca84 commit c5fe99f
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 0 deletions.
3 changes: 3 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from config import Config
from documentation import Docs
from logo import LogoGenerator
from project import Project
from rom import ROMFile
from shuttle import ShuttleConfig
Expand Down Expand Up @@ -305,6 +306,7 @@ def build_metrics(self):
docs = Docs(config, projects.projects)
shuttle = ShuttleConfig(config, projects.projects, modules_yaml_name)
rom = ROMFile(config)
logo = LogoGenerator(config)

if args.list:
shuttle.list()
Expand All @@ -315,6 +317,7 @@ def build_metrics(self):
if args.update_shuttle:
shuttle.configure_mux()
rom.write_rom()
logo.gen_logo("bottom", "logo/tt_logo_bottom.gds")
if not args.test:
docs.build_index()

Expand Down
95 changes: 95 additions & 0 deletions logo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env python3

import sys

import gdstk
from git.repo import Repo
from PIL import Image, ImageDraw, ImageFont

from config import Config


class LogoGenerator:
def __init__(self, config: Config | None):
self.config = config

def gen_logo(self, variant, gds_file, shuttle=None, commit=None):

assert variant in ("top", "bottom")
if variant == "top":
# use included bitmap
img = Image.open("logo/tt_logo.png")
img = img.convert("L") # convert to greyscale

elif variant == "bottom":
# generate bitmap from shuttle ID & commit hash
if shuttle is None:
shuttle = self.config["id"]
if commit is None:
commit = Repo(".").commit().hexsha

img = Image.new("L", (200, 200), (0,))
draw = ImageDraw.Draw(img)

font_file = "logo/UbuntuSansMono.ttf"
font = {}
for size in (88, 50, 32):
font[size] = ImageFont.truetype(font_file, size)
font[size].set_variation_by_axes([700])

draw.text((2, -15), shuttle, fill=(255,), font=font[88])
draw.text((2, 67), commit[:7], fill=(255,), font=font[50])
for i in range(3):
text = commit[7 + 11 * i : 7 + 11 * (i + 1)]
draw.text((1, 111 + i * 27), text, fill=(255,), font=font[32])

PRBOUNDARY_LAYER = 235
PRBOUNDARY_DATATYPE = 4
MET4_LAYER = 71
DRAWING_DATATYPE = 20
PIXEL_SIZE = 0.5 # um

lib = gdstk.Library()
cell = lib.new_cell(f"tt_logo_{variant}")
boundary = gdstk.rectangle(
(0, 0),
(img.width * PIXEL_SIZE, img.height * PIXEL_SIZE),
layer=PRBOUNDARY_LAYER,
datatype=PRBOUNDARY_DATATYPE,
)
cell.add(boundary)

for y in range(img.height):
for x in range(img.width):
color = img.getpixel((x, y))
if color >= 128:
flipped_y = img.height - y - 1 # flip vertically
rect = gdstk.rectangle(
(x * PIXEL_SIZE, flipped_y * PIXEL_SIZE),
((x + 1) * PIXEL_SIZE, (flipped_y + 1) * PIXEL_SIZE),
layer=MET4_LAYER,
datatype=DRAWING_DATATYPE,
)
cell.add(rect)

lib.write_gds(gds_file)


if __name__ == "__main__":

try:
if sys.argv[1] == "--top":
LogoGenerator(None).gen_logo("top", "logo/tt_logo_top.gds")

elif sys.argv[1] == "--bottom":
shuttle = sys.argv[2] # e.g. "TT10"
commit = sys.argv[3] # e.g. "0123456789abcdef0123456789abcdef01234567"
LogoGenerator(None).gen_logo(
"bottom", "logo/tt_logo_bottom.gds", shuttle, commit
)

except IndexError:
print(
f"Usage:\n {sys.argv[0]} --top\n {sys.argv[0]} --bottom <shuttle> <commit>",
file=sys.stderr,
)
Binary file added logo/UbuntuSansMono.ttf
Binary file not shown.
Binary file added logo/tt_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions logo/tt_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions logo/tt_logo_bottom.lef
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
VERSION 5.7 ;
NOWIREEXTENSIONATPIN ON ;
DIVIDERCHAR "/" ;
BUSBITCHARS "[]" ;
MACRO tt_logo_bottom
CLASS BLOCK ;
FOREIGN tt_logo_bottom ;
ORIGIN 0.000 0.000 ;
SIZE 100.000 BY 100.000 ;
OBS
LAYER met4 ;
RECT 0.000 0.000 100.000 100.000 ;
END
END tt_logo_bottom
END LIBRARY

4 changes: 4 additions & 0 deletions logo/tt_logo_bottom.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
`default_nettype none

module tt_logo_bottom ();
endmodule
Binary file added logo/tt_logo_top.gds
Binary file not shown.
16 changes: 16 additions & 0 deletions logo/tt_logo_top.lef
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
VERSION 5.7 ;
NOWIREEXTENSIONATPIN ON ;
DIVIDERCHAR "/" ;
BUSBITCHARS "[]" ;
MACRO tt_logo_top
CLASS BLOCK ;
FOREIGN tt_logo_top ;
ORIGIN 0.000 0.000 ;
SIZE 100.000 BY 100.000 ;
OBS
LAYER met4 ;
RECT 0.000 0.000 100.000 100.000 ;
END
END tt_logo_top
END LIBRARY

4 changes: 4 additions & 0 deletions logo/tt_logo_top.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
`default_nettype none

module tt_logo_top ();
endmodule
18 changes: 18 additions & 0 deletions shuttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ def copy_mux_macro(self, source_dir: str, name: str):
f"tt-multiplexer/ol2/tt_top/verilog/{name}.v",
)

def copy_logo_macro(self, name: str):
copy_print(
f"logo/{name}.gds",
f"tt-multiplexer/ol2/tt_top/gds/{name}.gds",
)
copy_print(
f"logo/{name}.lef",
f"tt-multiplexer/ol2/tt_top/lef/{name}.lef",
)
copy_print(
f"logo/{name}.v",
f"tt-multiplexer/ol2/tt_top/verilog/{name}.v",
)

def copy_macros(self):
logging.info("copying macros to tt_top:")
copy_print_glob("projects/*/*.gds", "tt-multiplexer/ol2/tt_top/gds")
Expand Down Expand Up @@ -250,6 +264,10 @@ def copy_macros(self):
self.copy_mux_macro("pg/tt_pg_3v3_2", "tt_pg_3v3_2")
self.copy_mux_macro("asw/tt_asw_3v3", "tt_asw_3v3")

# Copy logo & shuttle ID
self.copy_logo_macro("tt_logo_top")
self.copy_logo_macro("tt_logo_bottom")

def copy_final_results(self):
macros = ["tt_um_chip_rom", "tt_ctrl", "tt_mux", "tt_top"]

Expand Down

0 comments on commit c5fe99f

Please sign in to comment.