Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multiple logic gates #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 58 additions & 1 deletion components.typ
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,21 @@

/// Logic gates

// BUF gate
// type: node, fillable
#let buf-gate = {
parts.buf-gate-body
parts.logic-gate-legs-single
}

// NOT gate
// type: node, fillable
#let not-gate = {
parts.buf-gate-body
parts.not-circle
parts.logic-gate-legs-single
}

/// AND gate
/// type: node, fillable
#let and-gate = {
Expand Down Expand Up @@ -227,6 +242,41 @@
parts.xor-bar
}

/// MUX gate
/// type: node, fillable
#let mux-gate = {
parts.mux-gate-body
parts.logic-gate-legs-mux
}

/// DEC gate
/// type: node, fillable
#let dec-gate = {
parts.dec-gate-body
parts.logic-gate-legs-dec
}

/// ADD gate
/// type: node, fillable
#let add-gate = {
parts.add-gate-body
parts.logic-gate-legs-add
}

/// LATCH gate
/// type: node, fillable
#let latch-gate = {
parts.latch-gate-body
parts.logic-gate-legs-dec
}

/// FF gate
/// type: node, fillable
#let ff-gate = {
latch-gate
parts.clk-signal
}

#let path = (
// Resistive bipoles
"short": short,
Expand All @@ -250,10 +300,17 @@
"op amp": op-amp,

// Logic gates
"buf gate": buf-gate,
"not gate": not-gate,
"and gate": and-gate,
"nand gate": nand-gate,
"or gate": or-gate,
"nor gate": nor-gate,
"xor gate": xor-gate,
"xnor gate": xnor-gate
"xnor gate": xnor-gate,
"mux gate": mux-gate,
"dec gate": dec-gate,
"add gate": add-gate,
"latch gate": latch-gate,
"ff gate": ff-gate
)
166 changes: 165 additions & 1 deletion parts.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,143 @@
#import "../typst-canvas/draw.typ": *
#import "utils.typ": anchors

#let add-gate-body = {
line(
(-0.5, 0.8),
(-0.5, 0.3),
(-0.2, 0),
(-0.5, -0.3),
(-0.5, -0.8),
(0.5, -0.6),
(0.5, 0.6),
(-0.5, 0.8)
)
line(
(0, 0),
(0.3, 0)
)
line(
(0.15, 0.15),
(0.15, -0.15)
)
anchors((
"bin 1": (-0.5, 0.55),
"in 1": (rel: (-0.5, 0)),
"bin 2": (-0.5, -0.55),
"in 2": (rel: (-0.5, 0)),
"bcin": (0, -0.7),
"cin": (rel: (0, -0.3)),
"bcout": (0, 0.7),
"cout": (rel: (0, 0.3)),
"bout": (0.5, 0),
"out": (rel: (0.5, 0)),
"north": (0, 1),
"south": (rel: (0, -1)),
"east": "out",
"west": ("in 1", "|-", "center"),
"left": ("bin 1", "|-", "center"),
"right": "bout"
))
}

#let mux-gate-body = {
line(
(-0.5, 0.8),
(-0.5, -0.8),
(0.5, -0.6),
(0.5, 0.6),
(-0.5, 0.8)
)
anchors((
"bin 1": (-0.5, 0.3),
"in 1": (rel: (-0.5, 0)),
"bin 2": (-0.5, -0.3),
"in 2": (rel: (-0.5, 0)),
"bsel": (0, 0.7),
"sel": (rel: (0, 0.3)),
"bout": (0.5, 0),
"out": (rel: (0.5, 0)),
"north": (0, 0.7),
"south": (0, -0.7),
"east": "out",
"west": ("in 1", "|-", "center"),
"left": ("bin 1", "|-", "center"),
"right": "bout"
))
}

#let dec-gate-body = {
line(
(-0.5, 0.6),
(-0.5, -0.6),
(0.5, -0.8),
(0.5, 0.8),
(-0.5, 0.6)
)
anchors((
"bin": (-0.5, 0),
"in": (rel: (-0.5, 0)),
"bout 1": (0.5, 0.3),
"out 1": (rel: (0.5, 0)),
"bout 2": (0.5, -0.3),
"out 2": (rel: (0.5, 0)),
"north": (0, 0.7),
"south": (0, -0.7),
"east": (0.5, 0),
"west": ("in", "|-", "center"),
"left": ("bin", "|-", "center"),
"right": (0.5, 0)
))
}

#let latch-gate-body = {
line(
(-0.5, 0.8),
(-0.5, -0.8),
(0.5, -0.8),
(0.5, 0.8),
(-0.5, 0.8)
)
content((-0.3, 0.3), $D$)
content((0.3, 0.3), $Q$)
content((0.3, -0.3), $overline(Q)$)
anchors((
"bin": (-0.5, 0.3),
"in": (rel: (-0.5, 0)),
"bout 1": (0.5, 0.3),
"out 1": (rel: (0.5, 0)),
"bout 2": (0.5, -0.3),
"out 2": (rel: (0.5, 0)),
"north": (0, 0.8),
"south": (0, -0.8),
"east": (0.5, 0),
"west": ("in", "|-", "center"),
"left": ("bin", "|-", "center"),
"right": (0.5, 0)
))
}

#let buf-gate-body = {
line(
(-0.5, 0.5),
(-0.5, -0.5),
(0.5, 0),
(-0.5, 0.5)
)
anchors((
"bin": (-0.5, 0),
"in": (rel: (-0.5, 0)),
"bout": (0.5, 0),
"out": (rel: (0.5, 0)),
"north": (0, 0.5),
"south": (rel: (0, -1)),
"east": "out",
"west": ("in", "|-", "center"),
"left": ("bin", "|-", "center"),
"right": "bout"
))
}

#let and-gate-body = {
merge-path(close: true, {
arc((0,0), -90deg, 90deg, radius: 0.5, name: "curve", anchor: "origin")
Expand Down Expand Up @@ -73,6 +211,32 @@
))
}

#let clk-signal = {
line(
"north",
(rel: (0.15, 0)),
(rel: (-0.15, -0.15)),
(rel: (-0.15, 0.15))
)
}

#let logic-gate-legs = for a in ("in 1", "in 2", "out") {
line("b" + a, a)
}
}

#let logic-gate-legs-single = for a in ("in", "out") {
line("b" + a, a)
}

#let logic-gate-legs-mux = for a in ("in 1", "in 2", "out", "sel") {
line("b" + a, a)
}

#let logic-gate-legs-dec = for a in ("in", "out 1", "out 2") {
line("b" + a, a)
}

#let logic-gate-legs-add = for a in ("in 1", "in 2", "cin", "out", "cout") {
line("b" + a, a)
}
>>>>>>> c311ec6 (feat: add multiple logic gates)