diff --git a/configure.py b/configure.py index 03c30d1..ea0cb41 100755 --- a/configure.py +++ b/configure.py @@ -15,6 +15,7 @@ import yaml from config import Config from documentation import Docs +from logo import LogoGenerator from project import Project from rom import ROMFile from shuttle import ShuttleConfig @@ -305,6 +306,7 @@ if __name__ == "__main__": docs = Docs(config, projects.projects) shuttle = ShuttleConfig(config, projects.projects, modules_yaml_name) rom = ROMFile(config) + logo = LogoGenerator("tt", config) if args.list: shuttle.list() @@ -315,6 +317,7 @@ if __name__ == "__main__": if args.update_shuttle: shuttle.configure_mux() rom.write_rom() + logo.gen_logo("bottom", "tt/logo/tt_logo_bottom.gds") if not args.test: docs.build_index() diff --git a/logo.py b/logo.py new file mode 100755 index 0000000..8b0ca16 --- /dev/null +++ b/logo.py @@ -0,0 +1,97 @@ +#!/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, tt_dir, config: Config | None = None): + self.tt_dir = tt_dir + self.config = config + + def gen_logo(self, variant: str, gds_file: str, shuttle=None, commit=None): + + assert variant in ("top", "bottom") + if variant == "top": + # use included bitmap + img = Image.open(f"{self.tt_dir}/logo/tt_logo.png").convert("L") + + elif variant == "bottom": + # generate bitmap from shuttle ID & commit hash + if shuttle is None: + assert self.config is not 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 = f"{self.tt_dir}/logo/font/UbuntuSansMono.ttf" + + def font(size): + f = ImageFont.truetype(font_file, size) + f.set_variation_by_axes([700]) + return f + + draw.text((2, -15), shuttle, fill=255, font=font(88)) + draw.text((2, 68), commit[:8], fill=255, font=font(44)) + draw.text((2, 107), commit[8:18], fill=255, font=font(35)) + draw.text((1, 137), commit[18:29], fill=255, font=font(32)) + draw.text((1, 165), commit[29:], 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: int = img.getpixel((x, y)) # type: ignore + 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(".").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(".").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 ", + file=sys.stderr, + ) diff --git a/logo/font/LICENSE b/logo/font/LICENSE new file mode 100644 index 0000000..6e722c8 --- /dev/null +++ b/logo/font/LICENSE @@ -0,0 +1,96 @@ +------------------------------- +UBUNTU FONT LICENCE Version 1.0 +------------------------------- + +PREAMBLE +This licence allows the licensed fonts to be used, studied, modified and +redistributed freely. The fonts, including any derivative works, can be +bundled, embedded, and redistributed provided the terms of this licence +are met. The fonts and derivatives, however, cannot be released under +any other licence. The requirement for fonts to remain under this +licence does not require any document created using the fonts or their +derivatives to be published under this licence, as long as the primary +purpose of the document is not to be a vehicle for the distribution of +the fonts. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this licence and clearly marked as such. This may +include source files, build scripts and documentation. + +"Original Version" refers to the collection of Font Software components +as received under this licence. + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to +a new environment. + +"Copyright Holder(s)" refers to all individuals and companies who have a +copyright ownership of the Font Software. + +"Substantially Changed" refers to Modified Versions which can be easily +identified as dissimilar to the Font Software by users of the Font +Software comparing the Original Version with the Modified Version. + +To "Propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification and with or without charging +a redistribution fee), making available to the public, and in some +countries other activities as well. + +PERMISSION & CONDITIONS +This licence does not grant any rights under trademark law and all such +rights are reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of the Font Software, to propagate the Font Software, subject to +the below conditions: + +1) Each copy of the Font Software must contain the above copyright +notice and this licence. These can be included either as stand-alone +text files, human-readable headers or in the appropriate machine- +readable metadata fields within text or binary files as long as those +fields can be easily viewed by the user. + +2) The font name complies with the following: +(a) The Original Version must retain its name, unmodified. +(b) Modified Versions which are Substantially Changed must be renamed to +avoid use of the name of the Original Version or similar names entirely. +(c) Modified Versions which are not Substantially Changed must be +renamed to both (i) retain the name of the Original Version and (ii) add +additional naming elements to distinguish the Modified Version from the +Original Version. The name of such Modified Versions must be the name of +the Original Version, with "derivative X" where X represents the name of +the new work, appended to that name. + +3) The name(s) of the Copyright Holder(s) and any contributor to the +Font Software shall not be used to promote, endorse or advertise any +Modified Version, except (i) as required by this licence, (ii) to +acknowledge the contribution(s) of the Copyright Holder(s) or (iii) with +their explicit written permission. + +4) The Font Software, modified or unmodified, in part or in whole, must +be distributed entirely under this licence, and must not be distributed +under any other licence. The requirement for fonts to remain under this +licence does not affect any document created using the Font Software, +except any version of the Font Software extracted from a document +created using the Font Software may only be distributed under this +licence. + +TERMINATION +This licence becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF +COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER +DEALINGS IN THE FONT SOFTWARE. diff --git a/logo/font/UbuntuSansMono.ttf b/logo/font/UbuntuSansMono.ttf new file mode 100644 index 0000000..b2da099 Binary files /dev/null and b/logo/font/UbuntuSansMono.ttf differ diff --git a/logo/tt_logo.png b/logo/tt_logo.png new file mode 100644 index 0000000..ef83db9 Binary files /dev/null and b/logo/tt_logo.png differ diff --git a/logo/tt_logo.svg b/logo/tt_logo.svg new file mode 100644 index 0000000..f81e1c4 --- /dev/null +++ b/logo/tt_logo.svg @@ -0,0 +1,55 @@ + + + + + + + + diff --git a/logo/tt_logo_bottom.lef b/logo/tt_logo_bottom.lef new file mode 100644 index 0000000..87c1faf --- /dev/null +++ b/logo/tt_logo_bottom.lef @@ -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 + diff --git a/logo/tt_logo_bottom.v b/logo/tt_logo_bottom.v new file mode 100644 index 0000000..b8a768c --- /dev/null +++ b/logo/tt_logo_bottom.v @@ -0,0 +1,4 @@ +`default_nettype none + +module tt_logo_bottom (); +endmodule diff --git a/logo/tt_logo_top.gds b/logo/tt_logo_top.gds new file mode 100644 index 0000000..0203512 Binary files /dev/null and b/logo/tt_logo_top.gds differ diff --git a/logo/tt_logo_top.lef b/logo/tt_logo_top.lef new file mode 100644 index 0000000..95bcf04 --- /dev/null +++ b/logo/tt_logo_top.lef @@ -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 + diff --git a/logo/tt_logo_top.v b/logo/tt_logo_top.v new file mode 100644 index 0000000..ccabfc4 --- /dev/null +++ b/logo/tt_logo_top.v @@ -0,0 +1,4 @@ +`default_nettype none + +module tt_logo_top (); +endmodule diff --git a/shuttle.py b/shuttle.py index d80ae66..a9b1abb 100644 --- a/shuttle.py +++ b/shuttle.py @@ -203,6 +203,20 @@ class ShuttleConfig: f"tt-multiplexer/ol2/tt_top/verilog/{name}.v", ) + def copy_logo_macro(self, name: str): + copy_print( + f"tt/logo/{name}.gds", + f"tt-multiplexer/ol2/tt_top/gds/{name}.gds", + ) + copy_print( + f"tt/logo/{name}.lef", + f"tt-multiplexer/ol2/tt_top/lef/{name}.lef", + ) + copy_print( + f"tt/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") @@ -250,6 +264,10 @@ class ShuttleConfig: 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"]