From 38ef04338831947693249ff23eeb036d5097485f Mon Sep 17 00:00:00 2001 From: RubenB-ITENG <94007802+ruben-iteng@users.noreply.github.com> Date: Wed, 11 Sep 2024 15:00:22 +0200 Subject: [PATCH 1/2] Library: Mounting_Hole: Variable diameter and padtype (#50) --------- Co-authored-by: iopapamanoglou --- src/faebryk/library/Mounting_Hole.py | 36 +++++++++++++------ src/faebryk/libs/iso_metric_screw_thread.py | 39 +++++++++++++++++++++ 2 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 src/faebryk/libs/iso_metric_screw_thread.py diff --git a/src/faebryk/library/Mounting_Hole.py b/src/faebryk/library/Mounting_Hole.py index 2babd569..c397275a 100644 --- a/src/faebryk/library/Mounting_Hole.py +++ b/src/faebryk/library/Mounting_Hole.py @@ -2,32 +2,46 @@ # SPDX-License-Identifier: MIT import logging +from enum import StrEnum, auto import faebryk.library._F as F from faebryk.core.module import Module +from faebryk.libs.iso_metric_screw_thread import Iso262_MetricScrewThreadSizes from faebryk.libs.library import L -from faebryk.libs.units import P, Quantity logger = logging.getLogger(__name__) class Mounting_Hole(Module): - diameter: F.TBD[Quantity] + class PadType(StrEnum): + NoPad = "" + Pad = auto() + Pad_TopBottom = auto() + Pad_TopOnly = auto() + Pad_Via = auto() attach_to_footprint: F.can_attach_to_footprint_symmetrically designator_prefix = L.f_field(F.has_designator_prefix_defined)("H") - def __preinit__(self): - # Only 3.2mm supported for now - self.diameter.merge(F.Constant(3.2 * P.mm)) + def __init__(self, diameter: Iso262_MetricScrewThreadSizes, pad_type: PadType): + super().__init__() + self._diameter = diameter + self._pad_type = pad_type - # footprint = L.f_field(F.has_footprint_defined)( - # F.KicadFootprint("MountingHole:MountingHole_3.2mm_M3_Pad", pin_names=[]) - # ) - - # TODO make back to f_field, rt_field because of imports @L.rt_field def footprint(self): + size_mm = f"{self._diameter.value:.1f}mm" + size_name = self._diameter.name.replace("_", ".") + padtype = self._pad_type + + if size_name: + size_name = f"_{size_name}" + if padtype: + padtype = f"_{padtype}" + return F.has_footprint_defined( - F.KicadFootprint("MountingHole:MountingHole_3.2mm_M3_Pad", pin_names=[]) + F.KicadFootprint( + f"MountingHole:MountingHole_{size_mm}{size_name}{padtype}", + pin_names=[], + ) ) diff --git a/src/faebryk/libs/iso_metric_screw_thread.py b/src/faebryk/libs/iso_metric_screw_thread.py new file mode 100644 index 00000000..5293e6ed --- /dev/null +++ b/src/faebryk/libs/iso_metric_screw_thread.py @@ -0,0 +1,39 @@ +# This file is part of the faebryk project +# SPDX-License-Identifier: MIT + + +import logging +from enum import Enum + +logger = logging.getLogger(__name__) + + +class Iso262_MetricScrewThreadSizes(Enum): + # TODO add tolerance etc + # i think values are wrong, but api is ok + M1 = 1.2 + M1_2 = 1.4 + M1_4 = 1.6 + M1_6 = 1.8 + M1_8 = 2.0 + M2 = 2.2 + M2_5 = 2.7 + M3 = 3.2 + M3_5 = 3.7 + M4 = 4.3 + M5 = 5.3 + M6 = 6.4 + M8 = 8.4 + M10 = 10.4 + M12 = 12.4 + M14 = 14.4 + M16 = 16.4 + M20 = 20.4 + M24 = 24.4 + M30 = 30.4 + M36 = 36.4 + M42 = 42.4 + M48 = 48.4 + M56 = 56.4 + M60 = 60.4 + M64 = 64.4 From af0f3858e1cf1805b8e059d918dfa5942ee5e6c7 Mon Sep 17 00:00:00 2001 From: RubenB-ITENG <94007802+ruben-iteng@users.noreply.github.com> Date: Wed, 11 Sep 2024 15:16:49 +0200 Subject: [PATCH 2/2] Library: PoweredLED: Option to move resistor on A or K side (#51) * Option to move resistor on A or K side --------- Co-authored-by: iopapamanoglou --- src/faebryk/library/LED.py | 6 ++++++ src/faebryk/library/LEDIndicator.py | 13 +++++++++++-- src/faebryk/library/PoweredLED.py | 7 ++++--- src/faebryk/library/_F.py | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/faebryk/library/LED.py b/src/faebryk/library/LED.py index 32e280c7..12b9f60b 100644 --- a/src/faebryk/library/LED.py +++ b/src/faebryk/library/LED.py @@ -69,10 +69,16 @@ def connect_via_current_limiting_resistor( resistor.resistance.merge( self.get_needed_series_resistance_for_current_limit(input_voltage), ) + resistor.allow_removal_if_zero() def connect_via_current_limiting_resistor_to_power( self, resistor: F.Resistor, power: F.ElectricPower, low_side: bool ): + if low_side: + self.anode.connect(power.hv) + else: + self.cathode.connect(power.lv) + self.connect_via_current_limiting_resistor( power.voltage, resistor, diff --git a/src/faebryk/library/LEDIndicator.py b/src/faebryk/library/LEDIndicator.py index fa1f66bb..f9710910 100644 --- a/src/faebryk/library/LEDIndicator.py +++ b/src/faebryk/library/LEDIndicator.py @@ -16,9 +16,18 @@ class LEDIndicator(Module): led: F.PoweredLED - # TODO make generic - power_switch = L.f_field(F.PowerSwitchMOSFET)(lowside=True, normally_closed=False) + power_switch = L.f_field(F.PowerSwitch)(normally_closed=False) + + def __init__(self, use_mosfet: bool = True): + self._use_mosfet = use_mosfet def __preinit__(self): self.power_in.connect_via(self.power_switch, self.led.power) self.power_switch.logic_in.connect(self.logic_in) + + if self._use_mosfet: + self.power_switch.specialize( + F.PowerSwitchMOSFET(lowside=True, normally_closed=False) + ) + else: + self.power_switch.specialize(F.PowerSwitchStatic()) diff --git a/src/faebryk/library/PoweredLED.py b/src/faebryk/library/PoweredLED.py index 95db8264..71e85e3f 100644 --- a/src/faebryk/library/PoweredLED.py +++ b/src/faebryk/library/PoweredLED.py @@ -11,14 +11,15 @@ class PoweredLED(Module): current_limiting_resistor: F.Resistor led: F.LED + def __init__(self, low_side_resistor: bool = True): + self._low_side_resistor = low_side_resistor + def __preinit__(self): - self.power.hv.connect(self.led.anode) self.led.connect_via_current_limiting_resistor_to_power( self.current_limiting_resistor, self.power, - low_side=True, + low_side=self._low_side_resistor, ) - self.current_limiting_resistor.allow_removal_if_zero() @L.rt_field def can_bridge(self): diff --git a/src/faebryk/library/_F.py b/src/faebryk/library/_F.py index 891280d3..f62ca0db 100644 --- a/src/faebryk/library/_F.py +++ b/src/faebryk/library/_F.py @@ -212,5 +212,5 @@ from faebryk.library.ESP32_C3_MINI_1_Reference_Design import ESP32_C3_MINI_1_Reference_Design from faebryk.library.USB_C_5V_PSU import USB_C_5V_PSU from faebryk.library.USB_C_PowerOnly import USB_C_PowerOnly -from faebryk.library.LEDIndicator import LEDIndicator from faebryk.library.Powered_Relay import Powered_Relay +from faebryk.library.LEDIndicator import LEDIndicator