Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Library: PoweredLED: Option to move resistor on A or K side (#51)
Browse files Browse the repository at this point in the history
* Option to move resistor on A or K side

---------

Co-authored-by: iopapamanoglou <[email protected]>
  • Loading branch information
ruben-iteng and iopapamanoglou authored Sep 11, 2024
1 parent 38ef043 commit af0f385
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/faebryk/library/LED.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions src/faebryk/library/LEDIndicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
7 changes: 4 additions & 3 deletions src/faebryk/library/PoweredLED.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/faebryk/library/_F.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit af0f385

Please sign in to comment.