-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_tofarray.py
More file actions
172 lines (144 loc) · 6.84 KB
/
test_tofarray.py
File metadata and controls
172 lines (144 loc) · 6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import unittest
from typing_extensions import override
from edg import *
from .util import run_test_board
class CanConnector(Connector):
def __init__(self) -> None:
super().__init__()
self.pwr = self.Port(
VoltageSource(
voltage_out=(7, 14) * Volt, # TODO get limits from CAN power brick?
current_limits=(0, 0.15) * Amp, # TODO get actual limits from ???
),
optional=True,
)
self.gnd = self.Port(Ground())
self.differential = self.Port(CanDiffPort(), [Output])
self.conn = self.Block(PassiveConnector()).connected(
{"2": self.pwr, "3": self.gnd, "4": self.differential.canh, "5": self.differential.canl}
)
class TofArray(JlcBoardTop):
"""A ToF LiDAR array with application as emulating a laser harp and demonstrating another array topology."""
def __init__(self) -> None:
super().__init__()
# design configuration variables
self.tof_count = self.Parameter(IntExpr(5))
@override
def contents(self) -> None:
super().contents()
self.usb = self.Block(UsbCReceptacle())
self.can = self.Block(CanConnector())
self.vusb = self.connect(self.usb.pwr)
self.gnd = self.connect(self.usb.gnd, self.can.gnd)
self.tp_vusb = self.Block(VoltageTestPoint()).connected(self.usb.pwr)
self.tp_gnd = self.Block(GroundTestPoint()).connected(self.usb.gnd)
# POWER
with self.implicit_connect(
ImplicitConnect(self.gnd, [Common]),
) as imp:
(self.reg_3v3, self.tp_3v3, self.prot_3v3), _ = self.chain(
self.vusb,
imp.Block(LinearRegulator(output_voltage=3.3 * Volt(tol=0.05))),
self.Block(VoltageTestPoint()),
imp.Block(ProtectionZenerDiode(voltage=(3.45, 3.9) * Volt)),
)
self.v3v3 = self.connect(self.reg_3v3.pwr_out)
# 3V3 DOMAIN
with self.implicit_connect(
ImplicitConnect(self.v3v3, [Power]),
ImplicitConnect(self.gnd, [Common]),
) as imp:
self.mcu = imp.Block(IoController())
(self.sw1,), self.sw1_chain = self.chain(imp.Block(DigitalSwitch()), self.mcu.gpio.request("sw1"))
# realistically it would be cleaner for the RGB to be separate, but this demonstrates packing
(self.leds,), self.leds_chain = self.chain(
imp.Block(IndicatorSinkLedArray(self.tof_count + 3)), self.mcu.gpio.request_vector("leds")
)
self.tof = imp.Block(Vl53l0xArray(self.tof_count))
(self.i2c_pull, self.i2c_tp), self.i2c_chain = self.chain(
self.mcu.i2c.request("i2c"), imp.Block(I2cPullup()), imp.Block(I2cTestPoint()), self.tof.i2c
)
self.connect(self.mcu.gpio.request_vector("tof_reset"), self.tof.reset)
(self.usb_esd,), self.usb_chain = self.chain(self.usb.usb, imp.Block(UsbEsdDiode()), self.mcu.usb.request())
(self.tp_can, self.xcvr, self.can_esd), self.can_chain = self.chain(
self.mcu.with_mixin(IoControllerCan()).can.request("can"),
imp.Block(CanControllerTestPoint()),
imp.Block(Sn65hvd230()),
imp.Block(CanEsdDiode()),
self.can.differential,
)
# 5V DOMAIN
with self.implicit_connect(
ImplicitConnect(self.gnd, [Common]),
) as imp:
(self.tp_spk, self.spk_dac, self.tp_spk_in, self.spk_drv, self.spk), self.spk_chain = self.chain(
self.mcu.gpio.request("spk"),
imp.Block(DigitalTestPoint()),
imp.Block(LowPassRcDac(1 * kOhm(tol=0.05), 5 * kHertz(tol=0.5))),
imp.Block(AnalogTestPoint()),
imp.Block(Tpa2005d1(gain=Range.from_tolerance(10, 0.2))),
self.Block(Speaker()),
)
# limit the power draw of the speaker to not overcurrent the USB source
# this indicates that the device will only be run at partial power
(self.spk_pwr,), _ = self.chain(
self.vusb, self.Block(ForcedVoltageCurrentDraw((0, 0.05) * Amp)), self.spk_drv.pwr
)
@override
def multipack(self) -> None:
self.res1 = self.PackedBlock(ResistorArray())
self.pack(self.res1.elements.request("0"), ["leds", "led[0]", "res"])
self.pack(self.res1.elements.request("1"), ["leds", "led[1]", "res"])
self.pack(self.res1.elements.request("2"), ["rgb", "device", "red_res"])
self.pack(self.res1.elements.request("3"), ["rgb", "device", "green_res"])
self.res2 = self.PackedBlock(ResistorArray())
self.pack(self.res2.elements.request("0"), ["rgb", "device", "blue_res"])
self.pack(self.res2.elements.request("1"), ["leds", "led[2]", "res"])
self.pack(self.res2.elements.request("2"), ["leds", "led[3]", "res"])
self.pack(self.res2.elements.request("3"), ["leds", "led[4]", "res"])
self.rgb = self.PackedBlock(IndicatorSinkPackedRgbLed())
self.pack(self.rgb.red, ["leds", "led[5]"])
self.pack(self.rgb.green, ["leds", "led[6]"])
self.pack(self.rgb.blue, ["leds", "led[7]"])
@override
def refinements(self) -> Refinements:
return super().refinements() + Refinements(
instance_refinements=[
(["mcu"], Stm32f103_48),
(["reg_3v3"], Ldl1117), # TBD find one that is in stock
(["spk", "conn"], JstPhKVertical),
(["can", "conn"], MolexSl),
],
instance_values=[
(["mcu", "crystal", "frequency"], Range.from_tolerance(12000000, 0.005)), # legacy default crystal
(["mcu", "swd_connect_swo"], True),
(
["mcu", "pin_assigns"],
[
"spk=11", # PWMable pin, with TIMx_CHx function
"sw1=19",
"leds_0=20",
"leds_1=25",
"leds_5=26", # RGB R
"leds_6=27", # RGB G
"leds_7=28", # RGB B
"leds_2=29",
"leds_3=30",
"leds_4=31",
"tof_reset_0=42",
"tof_reset_1=41",
"tof_reset_2=4",
"tof_reset_3=3",
"tof_reset_4=2",
"swd_swo=PB3",
],
),
],
class_refinements=[
(SwdCortexTargetConnector, SwdCortexTargetTc2050),
(Speaker, ConnectorSpeaker),
],
)
class TofArrayTestTestCase(unittest.TestCase):
def test_design(self) -> None:
run_test_board(TofArray)