-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_iot_display.py
More file actions
215 lines (184 loc) · 9.32 KB
/
test_iot_display.py
File metadata and controls
215 lines (184 loc) · 9.32 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import unittest
from typing_extensions import override
from edg import *
from .util import run_test_board
class PmosHighSideSwitch(PowerSwitch):
"""Single PMOS switch.
TODO: this should be generated by HighSideSwitch if the voltage is low enough,
but making it smart depends on the voltage which is not available until the current is solved for
(need some sort of phased generator support)"""
def __init__(self, frequency: RangeLike = RangeExpr.ZERO, max_rds: FloatLike = 1 * Ohm) -> None:
super().__init__()
self.pwr = self.Port(VoltageSink(current_draw=RangeExpr()), [Power])
self.output = self.Port(
VoltageSource(voltage_out=self.pwr.link().voltage, current_limits=RangeExpr()),
[Output],
)
self.control = self.Port(DigitalSink(), [Input])
self.frequency = self.ArgParameter(frequency)
self.max_rds = self.ArgParameter(max_rds)
@override
def contents(self) -> None:
super().contents()
self.drv = self.Block(
SwitchFet.PFet(
drain_voltage=self.pwr.link().voltage,
drain_current=self.output.link().current_drawn,
gate_voltage=self.control.link().voltage
- self.pwr.link().voltage, # TODO needs to be diff from pwr.voltage
rds_on=(0, self.max_rds),
frequency=self.frequency,
drive_current=self.control.link().current_limits, # TODO this is kind of a max drive current
)
)
self.connect(self.pwr.net, self.drv.source)
self.connect(self.output.net, self.drv.drain)
self.connect(self.control.net, self.drv.gate)
self.assign(self.pwr.current_draw, self.output.link().current_drawn)
self.assign(self.output.current_limits, self.drv.actual_drain_current_rating)
class IotDisplay(JlcBoardTop):
"""Battery-powered IoT e-paper display with deep sleep."""
@override
def contents(self) -> None:
super().contents()
BATTERY_VOLTAGE = (4 * 1.15, 6 * 1.6) * Volt
self.usb = self.Block(UsbCReceptacle(current_limits=(0, 3) * Amp))
self.batt = self.Block(LipoConnector(voltage=BATTERY_VOLTAGE, actual_voltage=BATTERY_VOLTAGE)) # 2-6 AA
self.gnd = self.connect(self.usb.gnd, self.batt.gnd)
self.tp_pwr = self.Block(VoltageTestPoint("batt")).connected(self.batt.pwr)
self.tp_gnd = self.Block(GroundTestPoint()).connected(self.usb.gnd)
# POWER
with self.implicit_connect(
ImplicitConnect(self.gnd, [Common]),
) as imp:
(self.vbat_prot, self.reg_3v3, self.tp_3v3), _ = self.chain(
self.batt.pwr,
imp.Block(PmosReverseProtection()),
imp.Block(BuckConverter(output_voltage=3.3 * Volt(tol=0.05))),
self.Block(VoltageTestPoint()),
)
self.vbat = self.connect(self.vbat_prot.pwr_out)
self.v3v3 = self.connect(self.reg_3v3.pwr_out)
self.vbat_sense_gate = imp.Block(HighSideSwitch())
self.connect(self.vbat_sense_gate.pwr, self.vbat)
# 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())
# need to name the USB chain so the USB net has the _N and _P postfix for differential traces
(self.usb_esd,), self.usb_chain = self.chain(self.usb.usb, imp.Block(UsbEsdDiode()), self.mcu.usb.request())
# DEBUGGING UI ELEMENTS
(self.ledr,), _ = self.chain(imp.Block(IndicatorLed(Led.Red)), self.mcu.gpio.request("ledr"))
(self.ledg,), _ = self.chain(imp.Block(IndicatorLed(Led.Yellow)), self.mcu.gpio.request("ledg"))
(self.ledb,), _ = self.chain(imp.Block(IndicatorLed(Led.White)), self.mcu.gpio.request("ledb"))
(self.sw,), _ = self.chain(imp.Block(DigitalSwitch()), self.mcu.gpio.request(f"sw"))
# SENSING
self.connect(self.vbat_sense_gate.control, self.mcu.gpio.request("vbat_sense_gate"))
(self.vbat_sense,), _ = self.chain(
self.vbat_sense_gate.output,
imp.Block(VoltageSenseDivider(full_scale_voltage=(0, 2.9) * Volt, impedance=(10, 100) * kOhm)),
self.mcu.adc.request("vbat_sense"),
)
mcu_touch = self.mcu.with_mixin(IoControllerTouchDriver())
(self.touch_duck,), _ = self.chain(
mcu_touch.touch.request("touch_duck"), imp.Block(FootprintTouchPad("edg:Symbol_DucklingSolid"))
)
(self.touch_lemur,), _ = self.chain(
mcu_touch.touch.request("touch_lemur"), imp.Block(FootprintTouchPad("edg:Symbol_LemurSolid"))
)
gate_model = PmosHighSideSwitch(max_rds=0.1 * Ohm)
(self.epd_gate,), _ = self.chain(self.mcu.gpio.request("epd_gate"), imp.Block(gate_model))
(self.mem_gate,), _ = self.chain(self.mcu.gpio.request("mem_gate"), imp.Block(gate_model))
# DISPLAY POWER DOMAIN
with self.implicit_connect(
ImplicitConnect(self.epd_gate.output, [Power]),
ImplicitConnect(self.gnd, [Common]),
) as imp:
self.epd = imp.Block(Waveshare_Epd())
(self.tp_epd,), _ = self.chain(self.mcu.spi.request("epd"), imp.Block(SpiTestPoint("epd")), self.epd.spi)
(self.tp_erst,), _ = self.chain(
self.mcu.gpio.request("epd_rst"), imp.Block(DigitalTestPoint("rst")), self.epd.reset
)
(self.tp_dc,), _ = self.chain(
self.mcu.gpio.request("epd_dc"), imp.Block(DigitalTestPoint("dc")), self.epd.dc
)
(self.tp_epd_cs,), _ = self.chain(
self.mcu.gpio.request("epd_cs"), imp.Block(DigitalTestPoint("cs")), self.epd.cs
)
(self.tp_busy,), _ = self.chain(
self.mcu.gpio.request("epd_busy"), imp.Block(DigitalTestPoint("bsy")), self.epd.busy
)
# MEMORY POWER DOMAIN
with self.implicit_connect(
ImplicitConnect(self.mem_gate.output, [Power]),
ImplicitConnect(self.gnd, [Common]),
) as imp:
self.mem_spi = self.mcu.spi.request("sd")
self.sd = imp.Block(SdCard())
self.flash = imp.Block(W25q(Range.from_lower(16 * 1024 * 1024))) # at least 16Mbit
(self.tp_sd,), _ = self.chain(self.mem_spi, imp.Block(SpiTestPoint("sd")))
self.connect(self.mem_spi, self.sd.spi, self.flash.spi)
(self.tp_sd_cs,), _ = self.chain(
self.mcu.gpio.request("sd_cs"), imp.Block(DigitalTestPoint("sd_cs")), self.sd.cs
)
self.connect(self.mcu.gpio.request("fl_cs"), self.flash.cs) # no test point, clip the SOIC
@override
def refinements(self) -> Refinements:
return super().refinements() + Refinements(
instance_refinements=[
(["mcu"], Esp32s3_Wroom_1),
(["reg_3v3"], Tps54202h),
(["batt", "conn"], JstPhKHorizontal),
],
instance_values=[
(
["mcu", "pin_assigns"],
[
# note: for ESP32-S3 compatibility: IO35/36/37 (pins 28-30) are used by PSRAM
# note: for ESP32-C6 compatibility: pin 34 (22 on dedicated -C6 pattern) is NC
"ledr=39",
"ledg=38",
"ledb=4",
"sw=5",
"epd_dc=31",
"epd_cs=32",
"epd.sck=33",
"epd.mosi=35",
"epd.miso=NC",
"epd_rst=8",
"epd_busy=9",
"epd_gate=10",
"touch_duck=GPIO13",
"touch_lemur=GPIO14",
"vbat_sense=7",
"vbat_sense_gate=6",
"sd.miso=15",
"sd.sck=17",
"sd.mosi=18",
"sd_cs=19",
"fl_cs=20",
"mem_gate=23",
],
),
(["mcu", "programming"], "uart-auto-button"),
(["reg_3v3", "power_path", "inductor", "manual_frequency_rating"], Range(0, 10e6)),
(["reg_3v3", "fb", "impedance"], Range(20000.0, 100000.0)),
(["epd", "boost", "sense", "require_basic_part"], False), # 3R is not a basic part
(["epd", "boost", "inductor", "part"], "CBC3225T680KR"), # automated selection OOS
],
class_refinements=[
(EspProgrammingHeader, EspProgrammingTc2030),
(TestPoint, CompactKeystone5015),
(Fpc050Bottom, Fpc050BottomFlip), # top-contact so board is side-by-side with display
(SdCard, Molex1040310811),
],
class_values=[
(CompactKeystone5015, ["lcsc_part"], "C5199798"), # RH-5015, which is actually in stock
],
)
class IotDisplayTestCase(unittest.TestCase):
def test_design(self) -> None:
run_test_board(IotDisplay)