-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_iot_fan.py
More file actions
152 lines (130 loc) · 6.2 KB
/
test_iot_fan.py
File metadata and controls
152 lines (130 loc) · 6.2 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
import unittest
from typing_extensions import override
from edg import *
from .util import run_test_board
class IotFan(JlcBoardTop):
"""IoT fan controller with a 12v barrel jack input and a CPU fan connector."""
@override
def contents(self) -> None:
super().contents()
RING_LEDS = 18 # number of RGBs for the ring indicator
self.pwr = self.Block(PowerBarrelJack(voltage_out=12 * Volt(tol=0.05), current_limits=(0, 5) * Amp))
self.v12 = self.connect(self.pwr.pwr)
self.gnd = self.connect(self.pwr.gnd)
self.tp_pwr = self.Block(VoltageTestPoint()).connected(self.pwr.pwr)
self.tp_gnd = self.Block(GroundTestPoint()).connected(self.pwr.gnd)
# POWER
with self.implicit_connect(
ImplicitConnect(self.gnd, [Common]),
) as imp:
(self.reg_5v, self.tp_5v, self.prot_5v), _ = self.chain(
self.v12,
imp.Block(VoltageRegulator(output_voltage=4 * Volt(tol=0.05))),
self.Block(VoltageTestPoint()),
imp.Block(ProtectionZenerDiode(voltage=(5.5, 6.8) * Volt)),
)
self.v5 = self.connect(self.reg_5v.pwr_out)
(self.reg_3v3, self.tp_3v3, self.prot_3v3), _ = self.chain(
self.v5,
imp.Block(VoltageRegulator(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.mcu.with_mixin(IoControllerWifi())
# debugging LEDs
(self.ledr,), _ = self.chain(imp.Block(IndicatorSinkLed(Led.Red)), self.mcu.gpio.request("led"))
self.enc = imp.Block(DigitalRotaryEncoder())
self.connect(self.enc.a, self.mcu.gpio.request("enc_a"))
self.connect(self.enc.b, self.mcu.gpio.request("enc_b"))
self.connect(self.enc.with_mixin(DigitalRotaryEncoderSwitch()).sw, self.mcu.gpio.request("enc_sw"))
(self.v12_sense,), _ = self.chain(
self.v12,
imp.Block(VoltageSenseDivider(full_scale_voltage=2.2 * Volt(tol=0.1), impedance=(1, 10) * kOhm)),
self.mcu.adc.request("v12_sense"),
)
# 5V DOMAIN
with self.implicit_connect(
ImplicitConnect(self.v5, [Power]),
ImplicitConnect(self.gnd, [Common]),
) as imp:
(self.rgb_ring,), _ = self.chain(self.mcu.gpio.request("rgb"), imp.Block(NeopixelArray(RING_LEDS)))
# 12V DOMAIN
self.fan = ElementDict[CpuFanConnector]()
self.fan_drv = ElementDict[HighSideSwitch]()
self.fan_sense = ElementDict[OpenDrainDriver]()
self.fan_ctl = ElementDict[OpenDrainDriver]()
with self.implicit_connect(
ImplicitConnect(self.v12, [Power]),
ImplicitConnect(self.gnd, [Common]),
) as imp:
for i in range(2):
fan = self.fan[i] = self.Block(CpuFanConnector())
fan_drv = self.fan_drv[i] = imp.Block(
HighSideSwitch(pull_resistance=4.7 * kOhm(tol=0.05), max_rds=0.3 * Ohm)
)
self.connect(fan.pwr, fan_drv.output)
self.connect(fan.gnd, self.gnd)
self.connect(self.mcu.gpio.request(f"fan_drv_{i}"), fan_drv.control)
self.connect(fan.sense, self.mcu.gpio.request(f"fan_sense_{i}"))
(self.fan_ctl[i],), _ = self.chain(
self.mcu.gpio.request(f"fan_ctl_{i}"),
imp.Block(OpenDrainDriver()),
fan.with_mixin(CpuFanPwmControl()).control,
)
@override
def refinements(self) -> Refinements:
return super().refinements() + Refinements(
instance_refinements=[
(["mcu"], Esp32c3),
(["reg_5v"], Tps54202h),
(["reg_3v3"], Ap7215),
],
instance_values=[
(["refdes_prefix"], "F"), # unique refdes for panelization
(
["mcu", "pin_assigns"],
[
"v12_sense=4",
"rgb=_GPIO2_STRAP_EXT_PU", # force using the strapping pin, since we're out of IOs
"led=_GPIO9_STRAP", # force using the strapping / boot mode pin
"fan_drv_0=5",
"fan_ctl_0=8",
"fan_sense_0=9",
"fan_drv_1=10",
"fan_ctl_1=13",
"fan_sense_1=12",
"enc_sw=25",
"enc_b=16",
"enc_a=26",
],
),
(["mcu", "programming"], "uart-auto"),
(["reg_5v", "power_path", "inductor", "manual_frequency_rating"], Range(0, 9e6)),
(["fan_drv[0]", "drv", "footprint_spec"], "Package_SO:SOIC-8_3.9x4.9mm_P1.27mm"),
(["fan_drv[0]", "drv", "part"], "AO4407A"), # default DMG4407 is out of stock
(["fan_drv[1]", "drv", "footprint_spec"], ParamValue(["fan_drv[0]", "drv", "footprint_spec"])),
(["fan_drv[1]", "drv", "part"], ParamValue(["fan_drv[0]", "drv", "part"])),
],
class_refinements=[
(EspProgrammingHeader, EspProgrammingTc2030),
(PowerBarrelJack, Pj_036ah),
(Neopixel, Sk6805_Ec15),
(TestPoint, CompactKeystone5015),
(TagConnect, TagConnectNonLegged),
],
class_values=[
(Esp32c3, ["not_recommended"], True),
(CompactKeystone5015, ["lcsc_part"], "C5199798"), # RH-5015, which is actually in stock
(DiscreteRfWarning, ["discrete_rf_warning"], False),
],
)
class IotFanTestCase(unittest.TestCase):
def test_design(self) -> None:
run_test_board(IotFan)