summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Blake Kongslie2022-06-04 00:10:32 -0700
committerJulian Blake Kongslie2022-06-04 00:15:22 -0700
commit08cac544980a9de9bcb3b13f2e6f0846097caa75 (patch)
tree6173c03572fa6f271f28665ada848c57db6bc86c
parentMore complex library functionality for ICs with subcomponents. (diff)
downloadlace-08cac544980a9de9bcb3b13f2e6f0846097caa75.tar.xz
Make IC definitions more self-contained
Diffstat (limited to '')
-rw-r--r--library.rb43
-rwxr-xr-xtest.rb8
2 files changed, 20 insertions, 31 deletions
diff --git a/library.rb b/library.rb
index 0ba7cbc..1963b6e 100644
--- a/library.rb
+++ b/library.rb
@@ -24,13 +24,23 @@ end
24 24
25$ic = "TSSOP" 25$ic = "TSSOP"
26 26
27IC = Struct.new(:value, :pincount, :subparts, :automatic)
28
29$ic_definitions = {}
30$ic_available_parts = {}
31
32def define_ic(name, value, pincount, *subparts, &automatic) 27def define_ic(name, value, pincount, *subparts, &automatic)
33 $ic_definitions[name] = IC.new(value, pincount, subparts, automatic) 28 parts = []
29 proc do
30 if parts.size < 1
31 ic = comp("U", "#{$ic}-#{pincount}", name, value)
32 automatic.call(ic)
33 subs = subparts.map { | sub | sub.map { | pin | ic[pin] } }
34 subs.each do | sub |
35 if sub.size == 2
36 parts << pair(*sub)
37 else
38 parts << sub
39 end
40 end
41 end
42 parts.shift
43 end
34end 44end
35 45
36def stock_ic(name, value, &automatic) 46def stock_ic(name, value, &automatic)
@@ -40,27 +50,6 @@ def stock_ic(name, value, &automatic)
40 end 50 end
41end 51end
42 52
43def ic(name)
44 parts = $ic_available_parts.fetch(name, [])
45 if parts.size < 1
46 raise "IC #{name} not defined!" unless $ic_definitions.member?(name)
47 info = $ic_definitions[name]
48 ic = comp("U", "#{$ic}-#{info.pincount}", name, info.value)
49 info.automatic.call(ic)
50 subs = info.subparts.map { | sub | sub.map { | pin | ic[pin] } }
51 subs.each do | sub |
52 if sub.size == 2
53 parts << pair(*sub)
54 else
55 parts << sub
56 end
57 end
58 end
59 part = parts.shift
60 $ic_available_parts[name] = parts
61 return part
62end
63
64def probe(attenuation=20, impedance=50) 53def probe(attenuation=20, impedance=50)
65 jack = comp("J", "SMB", "SMB jack", "#{attenuation}x #{impedance}Ω probe") 54 jack = comp("J", "SMB", "SMB jack", "#{attenuation}x #{impedance}Ω probe")
66 jack[2] - jack[3] - jack[4] - jack[5] 55 jack[2] - jack[3] - jack[4] - jack[5]
diff --git a/test.rb b/test.rb
index d6cfbe2..e7f8b49 100755
--- a/test.rb
+++ b/test.rb
@@ -7,18 +7,18 @@ nl = Lace::Netlist.new do
7 vcc = net("vcc") 7 vcc = net("vcc")
8 gnd = net("gnd") 8 gnd = net("gnd")
9 9
10 stock_ic("inverter", "CD74HC04") do | ic | 10 define_singleton_method(:inverter, stock_ic("inverter", "CD74HC04") do | ic |
11 vcc - ic[14] - c("100nF") - ic[7] - gnd 11 vcc - ic[14] - c("100nF") - ic[7] - gnd
12 end 12 end)
13 13
14 vcc - led(220) - gnd 14 vcc - led(220) - gnd
15 15
16 vcc - btn - led(220, "green") - gnd 16 vcc - btn - led(220, "green") - gnd
17 vcc - btn("orange") - ic("inverter") - led(220, "white") - gnd 17 vcc - btn("orange") - inverter - led(220, "white") - gnd
18 18
19 x = vcc - btn("white") 19 x = vcc - btn("white")
20 x - net("x") - led(220, "amber") - gnd 20 x - net("x") - led(220, "amber") - gnd
21 x - ic("inverter") - net("xbar") - led(220, "blue") - gnd 21 x - inverter - net("xbar") - led(220, "blue") - gnd
22 x - probe - gnd 22 x - probe - gnd
23end 23end
24 24