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

Commit

Permalink
Core: Introduce fab ll & Refactor library to it (#7)
Browse files Browse the repository at this point in the history
This is a big commit changing the faebryk design api (now called fab ll).
The new "language" looks a lot like dataclasses. Its cleaner & simpler.
This commit breaks basically any project using faebryk. So need to version bump.

- (Re)design fab ll
- Refactor library, examples & tests to new fab ll
- Small library improvements: e.g is_power_source

---------

Co-authored-by: ruben-iteng <[email protected]>
  • Loading branch information
iopapamanoglou and ruben-iteng authored Sep 2, 2024
1 parent 60856b7 commit 6f41c26
Show file tree
Hide file tree
Showing 271 changed files with 7,145 additions and 8,794 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,20 @@ In short faebryk is a python library that allows you to design ready-to-order el

```python
import faebryk.library._F as F
from faebryk.core.core import Module
from faebryk.core.module import Module
from faebryk.libs.brightness import TypicalLuminousIntensity
from faebryk.libs.examples.buildutil import apply_design_to_pcb

class App(Module):
def __init__(self) -> None:
super().__init__()
led : F.PoweredLED
battery : F.Battery

class _NODES(Module.NODES()):
led = F.PoweredLED()
battery = F.Battery()

self.NODEs = _NODES(self)

self.NODEs.led.IFs.power.connect(self.NODEs.battery.IFs.power)
def __preinit__(self) -> None:
self.led.power.connect(self.battery.power)

# Parametrize
self.NODEs.led.NODEs.led.PARAMs.color.merge(F.LED.Color.YELLOW)
self.NODEs.led.NODEs.led.PARAMs.brightness.merge(
self.led.led.color.merge(F.LED.Color.YELLOW)
self.led.led.brightness.merge(
TypicalLuminousIntensity.APPLICATION_LED_INDICATOR_INSIDE.value.value
)

Expand Down
69 changes: 28 additions & 41 deletions examples/iterative_design_nand.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,37 @@
import typer

import faebryk.library._F as F
from faebryk.core.core import Module
from faebryk.core.module import Module
from faebryk.core.util import (
get_all_nodes_with_trait,
specialize_interface,
specialize_module,
)
from faebryk.library._F import Constant
from faebryk.libs.brightness import TypicalLuminousIntensity
from faebryk.libs.examples.buildutil import apply_design_to_pcb
from faebryk.libs.library import L
from faebryk.libs.logging import setup_basic_logging
from faebryk.libs.units import P
from faebryk.libs.util import times

logger = logging.getLogger(__name__)


class PowerSource(Module):
def __init__(self) -> None:
super().__init__()

class IFS(Module.IFS()):
power = F.ElectricPower()

self.IFs = IFS(self)
power: F.ElectricPower


class XOR_with_NANDS(F.LogicGates.XOR):
def __init__(
self,
):
super().__init__(Constant(2))

class NODES(Module.NODES()):
nands = times(4, lambda: F.LogicGates.NAND(Constant(2)))
nands = L.list_field(4, lambda: F.LogicGates.NAND(F.Constant(2)))

self.NODEs = NODES(self)
def __init__(self):
super().__init__(F.Constant(2))

A = self.IFs.inputs[0]
B = self.IFs.inputs[1]
def __preinit__(self):
A = self.inputs[0]
B = self.inputs[1]

G = self.NODEs.nands
Q = self.IFs.outputs[0]
G = self.nands
Q = self.outputs[0]

# ~(a&b)
q0 = G[0].get_trait(F.LogicOps.can_logic_nand).nand(A, B)
Expand All @@ -81,18 +70,18 @@ def App():
power_source = PowerSource()

# alias
power = power_source.IFs.power
power = power_source.power

# logic
logic_in = F.Logic()
logic_out = F.Logic()

xor = F.LogicGates.XOR(Constant(2))
xor = F.LogicGates.XOR(F.Constant(2))
logic_out.connect(xor.get_trait(F.LogicOps.can_logic_xor).xor(logic_in, on))

# led
led = F.LEDIndicator()
led.IFs.power_in.connect(power)
led.power_in.connect(power)

# application
switch = F.Switch(F.Logic)()
Expand All @@ -104,15 +93,15 @@ def App():
e_out = specialize_interface(logic_out, F.ElectricLogic())
e_on = specialize_interface(on, F.ElectricLogic())
e_off = specialize_interface(off, F.ElectricLogic())
e_in.IFs.reference.connect(power)
e_out.IFs.reference.connect(power)
e_on.IFs.reference.connect(power)
e_off.IFs.reference.connect(power)
e_in.reference.connect(power)
e_out.reference.connect(power)
e_on.reference.connect(power)
e_off.reference.connect(power)
e_in.set_weak(on=False)
e_on.set(on=True)
e_off.set(on=False)

e_out.connect(led.IFs.logic_in)
e_out.connect(led.logic_in)

nxor = specialize_module(xor, XOR_with_NANDS())
battery = specialize_module(power_source, F.Battery())
Expand All @@ -122,36 +111,34 @@ def App():
e_switch = specialize_module(
el_switch,
e_switch,
matrix=[
(e, el.IFs.signal)
for e, el in zip(e_switch.IFs.unnamed, el_switch.IFs.unnamed)
],
matrix=[(e, el.signal) for e, el in zip(e_switch.unnamed, el_switch.unnamed)],
)

# build graph
app = Module()
app.NODEs.components = [
for c in [
led,
switch,
battery,
e_switch,
]
]:
app.add(c)

# parametrizing
for _, t in get_all_nodes_with_trait(app.get_graph(), F.ElectricLogic.has_pulls):
for pull_resistor in (r for r in t.get_pulls() if r):
pull_resistor.PARAMs.resistance.merge(100 * P.kohm)
power_source.IFs.power.PARAMs.voltage.merge(3 * P.V)
led.NODEs.led.NODEs.led.PARAMs.brightness.merge(
pull_resistor.resistance.merge(100 * P.kohm)
power_source.power.voltage.merge(3 * P.V)
led.led.led.brightness.merge(
TypicalLuminousIntensity.APPLICATION_LED_INDICATOR_INSIDE.value.value
)

# packages single nands as explicit IC
nand_ic = F.TI_CD4011BE()
for ic_nand, xor_nand in zip(nand_ic.NODEs.gates, nxor.NODEs.nands):
for ic_nand, xor_nand in zip(nand_ic.gates, nxor.nands):
specialize_module(xor_nand, ic_nand)

app.NODEs.nand_ic = nand_ic
app.add(nand_ic)

return app

Expand Down
23 changes: 8 additions & 15 deletions examples/minimal_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,24 @@
import typer

import faebryk.library._F as F
from faebryk.core.core import Module
from faebryk.core.module import Module
from faebryk.libs.brightness import TypicalLuminousIntensity
from faebryk.libs.examples.buildutil import (
apply_design_to_pcb,
)
from faebryk.libs.examples.buildutil import apply_design_to_pcb
from faebryk.libs.logging import setup_basic_logging

logger = logging.getLogger(__name__)


class App(Module):
def __init__(self) -> None:
super().__init__()
led: F.PoweredLED
battery: F.Battery

class _NODES(Module.NODES()):
led = F.PoweredLED()
battery = F.Battery()

self.NODEs = _NODES(self)

self.NODEs.led.IFs.power.connect(self.NODEs.battery.IFs.power)
def __preinit__(self) -> None:
self.led.power.connect(self.battery.power)

# Parametrize
self.NODEs.led.NODEs.led.PARAMs.color.merge(F.LED.Color.YELLOW)
self.NODEs.led.NODEs.led.PARAMs.brightness.merge(
self.led.led.color.merge(F.LED.Color.YELLOW)
self.led.led.brightness.merge(
TypicalLuminousIntensity.APPLICATION_LED_INDICATOR_INSIDE.value.value
)

Expand Down
34 changes: 12 additions & 22 deletions examples/pcb_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,33 @@
import typer

import faebryk.library._F as F
from faebryk.core.core import Module
from faebryk.core.module import Module
from faebryk.exporters.pcb.layout.absolute import LayoutAbsolute
from faebryk.exporters.pcb.layout.extrude import LayoutExtrude
from faebryk.exporters.pcb.layout.typehierarchy import LayoutTypeHierarchy
from faebryk.library.has_pcb_layout_defined import has_pcb_layout_defined
from faebryk.library.has_pcb_position import has_pcb_position
from faebryk.library.has_pcb_position_defined import has_pcb_position_defined
from faebryk.libs.brightness import TypicalLuminousIntensity
from faebryk.libs.examples.buildutil import (
apply_design_to_pcb,
)
from faebryk.libs.examples.buildutil import apply_design_to_pcb
from faebryk.libs.logging import setup_basic_logging

logger = logging.getLogger(__name__)


class App(Module):
def __init__(self) -> None:
super().__init__()
leds: F.PoweredLED
battery: F.Battery

class _NODES(Module.NODES()):
leds = F.PoweredLED()
battery = F.Battery()

self.NODEs = _NODES(self)

self.NODEs.leds.IFs.power.connect(self.NODEs.battery.IFs.power)
def __preinit__(self) -> None:
self.leds.power.connect(self.battery.power)

# Parametrize
self.NODEs.leds.NODEs.led.PARAMs.color.merge(F.LED.Color.YELLOW)
self.NODEs.leds.NODEs.led.PARAMs.brightness.merge(
self.leds.led.color.merge(F.LED.Color.YELLOW)
self.leds.led.brightness.merge(
TypicalLuminousIntensity.APPLICATION_LED_INDICATOR_INSIDE.value.value
)

# Layout
Point = has_pcb_position.Point
L = has_pcb_position.layer_type
Point = F.has_pcb_position.Point
L = F.has_pcb_position.layer_type

layout = LayoutTypeHierarchy(
layouts=[
Expand All @@ -68,8 +58,8 @@ class _NODES(Module.NODES()):
),
]
)
self.add_trait(has_pcb_layout_defined(layout))
self.add_trait(has_pcb_position_defined(Point((50, 50, 0, L.NONE))))
self.add_trait(F.has_pcb_layout_defined(layout))
self.add_trait(F.has_pcb_position_defined(Point((50, 50, 0, L.NONE))))


# Boilerplate -----------------------------------------------------------------
Expand Down
Loading

0 comments on commit 6f41c26

Please sign in to comment.