From 417b26bbb3597183a5b1c877217d4af2571883f5 Mon Sep 17 00:00:00 2001 From: Matthew Wildoer Date: Thu, 15 Aug 2024 12:10:15 -0700 Subject: [PATCH] Library: Add NetTie to library --- src/faebryk/library/KicadFootprint.py | 4 +++ src/faebryk/library/NetTie.py | 51 +++++++++++++++++++++++++++ src/faebryk/library/_F.py | 1 + 3 files changed, 56 insertions(+) create mode 100644 src/faebryk/library/NetTie.py diff --git a/src/faebryk/library/KicadFootprint.py b/src/faebryk/library/KicadFootprint.py index 9026c68f..a942d110 100644 --- a/src/faebryk/library/KicadFootprint.py +++ b/src/faebryk/library/KicadFootprint.py @@ -9,6 +9,10 @@ class KicadFootprint(F.Footprint): def __init__(self, kicad_identifier: str, pin_names: list[str]) -> None: super().__init__() + assert ":" in kicad_identifier, ( + 'kicad_identifier must be in the format "library:footprint".' + " If not, it'll cause downstream problems" + ) unique_pin_names = sorted(set(pin_names)) self.pin_names_sorted = list(enumerate(unique_pin_names)) diff --git a/src/faebryk/library/NetTie.py b/src/faebryk/library/NetTie.py new file mode 100644 index 00000000..cabca41d --- /dev/null +++ b/src/faebryk/library/NetTie.py @@ -0,0 +1,51 @@ +# This file is part of the faebryk project +# SPDX-License-Identifier: MIT + +import logging +from enum import Enum + +import faebryk.library._F as F +from faebryk.core.module import Module +from faebryk.core.moduleinterface import ModuleInterface +from faebryk.library.Electrical import Electrical +from faebryk.library.KicadFootprint import KicadFootprint +from faebryk.libs.picker.picker import has_part_picked_remove + +logger = logging.getLogger(__name__) + + +class NetTie[T: ModuleInterface](Module): + class Size(float, Enum): + _2_0MM = 2.0 + _0_5MM = 0.5 + + unnamed: list[T] + + def __init__( + self, + width: Size, + interface_type: type[T] = Electrical, + ) -> None: + super().__init__() + + # dynamically construct the interfaces + self.unnamed = self.add([interface_type(), interface_type()], "unnamed") + + # add dem trairs + self.add(F.can_bridge_defined(*self.unnamed)) + + width_mm = NetTie.Size(width).value + + self.add(F.can_attach_to_footprint_symmetrically()) + self.add(F.has_designator_prefix_defined("H")) + # TODO: "removed" isn't really true, but seems to work + self.add(has_part_picked_remove()) + + # TODO: generate the kicad footprint instead of loading it + self.add( + F.has_footprint_defined( + KicadFootprint( + f"NetTie:NetTie-2_SMD_Pad{width_mm:.1f}mm", pin_names=["1", "2"] + ) + ) + ) diff --git a/src/faebryk/library/_F.py b/src/faebryk/library/_F.py index 891280d3..c6353e3b 100644 --- a/src/faebryk/library/_F.py +++ b/src/faebryk/library/_F.py @@ -114,6 +114,7 @@ from faebryk.library.Capacitor import Capacitor from faebryk.library.Fuse import Fuse from faebryk.library.Inductor import Inductor +from faebryk.library.NetTie import NetTie from faebryk.library.Resistor import Resistor from faebryk.library.Switch import Switch from faebryk.library.B4B_ZR_SM4_TF import B4B_ZR_SM4_TF