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

KiCAD Schematic Exporter MVP #125

Closed
wants to merge 102 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
57abb3b
Readd "crud for later"
mawildoer Sep 24, 2024
b9b4a88
Add geometry bbox methods to sch transformer
mawildoer Sep 24, 2024
32df741
Make dataclass for options
mawildoer Sep 24, 2024
d474bfa
Tidy symbol layout traits
mawildoer Sep 24, 2024
c968600
Minor transformer cleanup
mawildoer Sep 24, 2024
1fbf21f
Too many modifications to the original code. Trying another method
mawildoer Sep 24, 2024
0ebae9a
Revert "Too many modifications to the original code. Trying another m…
mawildoer Sep 24, 2024
876a6a0
Restart with skidl
mawildoer Sep 24, 2024
6c62d62
Re-add fresh sch layout lib
mawildoer Sep 24, 2024
027ef7d
Repoint imports
mawildoer Sep 24, 2024
0b36b1e
Remove fucked up globals
mawildoer Sep 24, 2024
fe51c95
Part as a trait
mawildoer Sep 24, 2024
5e601bc
Pre-typing
mawildoer Sep 24, 2024
e2bb4d0
Add typing to first few functions of place.py
mawildoer Sep 24, 2024
98f4960
Typing progress
mawildoer Sep 24, 2024
1fb55cb
More typing...
mawildoer Sep 24, 2024
402f6c6
NetTerminal sufficently together
mawildoer Sep 24, 2024
11061df
Finish typing place.py!
mawildoer Sep 24, 2024
adb2ab7
Type options
mawildoer Sep 24, 2024
2b4fc04
Continue typing, over on route
mawildoer Sep 24, 2024
99b1f1b
Typing....
mawildoer Sep 24, 2024
2af7fa9
Finish module-level typing route.py
mawildoer Sep 24, 2024
f2a3985
Typing on route done too!
mawildoer Sep 24, 2024
a46270f
Type geometry
mawildoer Sep 24, 2024
83f15dd
NamedTuples -> dataclasses and largely type bbox. I reckon we might r…
mawildoer Sep 24, 2024
d64d168
Add circuit and types to node.py
mawildoer Sep 24, 2024
43b5276
Add noqa for line-length
mawildoer Sep 24, 2024
b5399b9
Add typing to gen_schematic and pre-empt modifying functions to pull …
mawildoer Sep 25, 2024
dedb3f3
Sort shim attrs and add add attrs from `getattr`
mawildoer Sep 25, 2024
466dca2
Organise shim attributes into required and not
mawildoer Sep 25, 2024
794c8fe
First information across boundary
mawildoer Sep 25, 2024
922a9a6
Type debug_draw
mawildoer Sep 25, 2024
82cf8ca
Add property markers to transformer
mawildoer Sep 25, 2024
24e7642
Add bare_bbox attr to shim
mawildoer Sep 25, 2024
26fa130
Add shim builders!
mawildoer Sep 26, 2024
987f423
Cleanup so tests import
mawildoer Sep 26, 2024
04947f0
We pass audit!!!!
mawildoer Sep 28, 2024
d084613
Format transformer.py
mawildoer Sep 28, 2024
1c12de9
Progress on auto-sch layout generator. Basically runs, but there are …
mawildoer Sep 30, 2024
6871b6e
Auto-place/route runs to completion
mawildoer Oct 1, 2024
83f5650
Format place and route
mawildoer Oct 1, 2024
ce8f1ab
Print tables only when debugging
mawildoer Oct 1, 2024
46fc4ba
Add interface to Pad. Seems simpler with a reference, but I don't wan…
mawildoer Oct 2, 2024
fb14e9f
Add skeleton helpers to fileformats_sch
mawildoer Oct 2, 2024
5719db9
Add separate logging levels to core
mawildoer Oct 2, 2024
9d2937f
Optional Reference
mawildoer Oct 11, 2024
ffbadf9
Format
mawildoer Oct 11, 2024
71d70ed
Download symbols properly
mawildoer Oct 11, 2024
ad6b738
Add explicit flag to has_overridden_name
mawildoer Oct 12, 2024
880ed8c
OMG it's working
mawildoer Oct 12, 2024
438b128
Improve debug view
mawildoer Oct 22, 2024
b561075
Spit out come schematic
mawildoer Oct 22, 2024
7104764
Fix pin orientations
mawildoer Oct 23, 2024
d47898a
Improve marking
mawildoer Oct 23, 2024
e193614
Fix attachment of existing symbols
mawildoer Oct 23, 2024
0a815de
Fix hierarchy strings to flatten design
mawildoer Oct 23, 2024
bf16649
Fix and test marking
mawildoer Oct 23, 2024
ee43883
Explain hierarchy
mawildoer Oct 23, 2024
edd57f0
pre-commit tidy up
mawildoer Oct 23, 2024
b3af051
Fix power and ground pin detection
mawildoer Oct 23, 2024
46f96f6
Rotate the net-terminals correctly
mawildoer Oct 24, 2024
955ac65
Wire segments were out of order, which made them netty
mawildoer Oct 24, 2024
8865114
Test marking on wires as well
mawildoer Oct 24, 2024
511f6f2
Hide faebryk mark
mawildoer Oct 24, 2024
84b9cee
Allow rotations of things without symtx
mawildoer Oct 24, 2024
128e163
Improve some hierarchy shenanigans
mawildoer Oct 25, 2024
2aba47b
Unorthodox (eg. no SKiddilish) mechanism to flatten parts before addi…
mawildoer Oct 25, 2024
c408d43
Add safety in case of missing tracks for routing
mawildoer Oct 25, 2024
010a147
Remove content that was commented out on Skidl anyway
mawildoer Oct 25, 2024
89c7ce0
Reenable flattened node offsets
mawildoer Oct 25, 2024
714b1ec
Modify flattening logic in export
mawildoer Oct 25, 2024
2a58508
Find simultaneous flipping and rotations
mawildoer Oct 25, 2024
0f693a9
Tidy
mawildoer Oct 25, 2024
dcff02b
Ignore all skidl imported files because they use different linting rules
mawildoer Oct 28, 2024
c624107
Accelerated minimal LED failing
mawildoer Oct 29, 2024
c2a2144
Skip picking
mawildoer Oct 31, 2024
50ec178
Format
mawildoer Oct 31, 2024
d5d0729
Protect indexing files
mawildoer Oct 31, 2024
6352877
Stabalise dev_schematics
mawildoer Nov 1, 2024
41e8fb4
Battery is the right way up
mawildoer Nov 1, 2024
2610665
Add schematic hints
mawildoer Nov 1, 2024
70c2f73
Fix motherfucking backwards-ass rotation matrices
mawildoer Nov 1, 2024
527f2fa
Rotations work! Yeeeeewwww!
mawildoer Nov 2, 2024
2c86701
Add basic options to the schematic transformer
mawildoer Nov 2, 2024
cde6ad1
Fix for alternative circle definition
mawildoer Nov 3, 2024
e0b989c
Core: Allow references to be set to None when optional
mawildoer Nov 5, 2024
1fde9bc
Iterative design NAND works!
mawildoer Nov 5, 2024
32c99f0
Move gen_schematic functionality to schematics.Transformer
mawildoer Nov 5, 2024
651ac68
Some bug fixes beyond iterative NAND
mawildoer Nov 5, 2024
d1d92a5
Test bounding box geometry
mawildoer Nov 5, 2024
cc9cefe
Pad out pin connections
mawildoer Nov 6, 2024
ffe2779
Improve has_schematic_hints trait semantics
mawildoer Nov 6, 2024
4081767
Rotation schematic hint
mawildoer Nov 6, 2024
19d2ca9
Polish up examples for schematic generation
mawildoer Nov 6, 2024
80adb8b
Merge branch 'main' of github.com:atopile/faebryk into mawildoer/kica…
mawildoer Nov 6, 2024
0f4d2fd
Fix tests and formatting
mawildoer Nov 6, 2024
d44e838
Remove separated core log level
mawildoer Nov 6, 2024
e42b4fd
Improve lib indexing
mawildoer Nov 6, 2024
de2eb46
Add linux support for os_open
mawildoer Nov 7, 2024
5293933
Merge branch 'main' of github.com:atopile/faebryk into mawildoer/kica…
mawildoer Nov 7, 2024
6e90d4c
Fixes from C++ core upgrade
mawildoer Nov 7, 2024
1b91629
Fix dud merge
mawildoer Nov 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions examples/dev_schematics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
This is developer-targeted example for generating schematics.
Schematics are an alpha feature-in-progress, which means they're not bundled up nicely
with the rest of the exporter.
"""

import logging
from pathlib import Path

import iterative_design_nand
import minimal_led

from faebryk.exporters.schematic.kicad.transformer import Transformer
from faebryk.libs.examples.buildutil import apply_design_to_pcb
from faebryk.libs.kicad.fileformats_sch import C_kicad_sch_file
from faebryk.libs.logging import setup_basic_logging
from faebryk.libs.util import CouldntOSOpen, os_open

logger = logging.getLogger(__name__)


def build(module) -> Path:
build_dir = Path(".") / "build"
lib_path = build_dir / "kicad" / "libs"

sch_file = C_kicad_sch_file.skeleton()

logger.info("Building app")
app = module.App()

logger.info("Applying design to PCB")
apply_design_to_pcb(app)

logger.info("Generating schematic")
full_transformer = Transformer(sch_file.kicad_sch, app.get_graph(), app)
full_transformer.index_symbol_files(lib_path, load_globals=False)

full_transformer.generate_schematic()

output_path = build_dir / f"{module.__name__}.kicad_sch"
sch_file.dumps(output_path)
return output_path


if __name__ == "__main__":
setup_basic_logging()

for module in [minimal_led, iterative_design_nand]:
logger.info(f"Building {module.__name__}")
path = build(module)

logger.info(f"Opening {path}")
try:
os_open(path)
except CouldntOSOpen as ex:
logger.error(f"Can't open {path}: {ex}")
2 changes: 2 additions & 0 deletions examples/iterative_design_nand.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def App():
for ic_nand, xor_nand in zip(nand_ic.gates, nxor.nands):
xor_nand.specialize(ic_nand)

nand_ic.add(F.has_schematic_hints(symbol_rotation=0))

# connect power to IC
nand_ic.power.connect(power_source.power)

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,12 @@ exclude = [
"node_modules",
"venv",
]
per-file-ignores = {}

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.lint.per-file-ignores]
# SKiDL imported files are ignored because they use different linting rules to us
"src/faebryk/exporters/schematic/kicad/skidl/*" = ["ALL"]

[tool.ruff.lint.mccabe]
# Unlike Flake8, default to a complexity level of 10.
Expand Down
13 changes: 10 additions & 3 deletions src/faebryk/core/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ class Reference[O: Node](constructed_field):
class UnboundError(Exception):
"""Cannot resolve unbound reference"""

def __init__(self, out_type: type[O] | None = None):
def __init__(self, out_type: type[O] | None = None, optional: bool = False):
self.gifs: dict[Node, GraphInterfaceReference] = defaultdict(
GraphInterfaceReference
)
self.is_set: set[Node] = set()
self.optional = optional

def get(instance: Node) -> O:
try:
return cast(O, self.gifs[instance].get_reference())
except GraphInterfaceReferenceUnboundError as ex:
if self.optional:
return None
raise Reference.UnboundError from ex

def set_(instance: Node, value: O):
Expand All @@ -39,6 +42,8 @@ def set_(instance: Node, value: O):
self.is_set.add(instance)

if out_type is not None and not isinstance(value, out_type):
if value is None and self.optional:
return
raise TypeError(f"Expected {out_type} got {type(value)}")

# attach our gif to what we're referring to
Expand All @@ -54,10 +59,12 @@ def __construct__(self, obj: Node) -> None:
return None


def reference[O: Node](out_type: type[O] | None = None) -> O | Reference:
def reference[O: Node](
out_type: type[O] | None = None, optional: bool = False
) -> O | Reference:
"""
Create a simple reference to other nodes properly encoded in the graph.

This final wrapper is primarily to fudge the typing.
"""
return Reference(out_type=out_type)
return Reference(out_type=out_type, optional=optional)
3 changes: 2 additions & 1 deletion src/faebryk/exporters/netlist/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def get_or_set_name_and_value_of_node(c: Module):
c.get_full_name(),
type(c).__name__,
value,
)
),
explicit=False,
)
)

Expand Down
Empty file.
Loading