-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_esp_programmer.py
More file actions
96 lines (77 loc) · 3.58 KB
/
test_esp_programmer.py
File metadata and controls
96 lines (77 loc) · 3.58 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
import unittest
from typing_extensions import override
from edg import *
from .util import run_test_board
class EspProgrammerTc2030Inline(Connector, Block):
"""UART connector, follows the TXD, RXD, GND, +5 pinning of cheap CP2102 dongles."""
def __init__(self, *, pwr_current_draw: RangeLike = (0, 0) * mAmp):
super().__init__()
self.gnd = self.Port(Ground(), [Common])
self.pwr = self.Port(VoltageSink(current_draw=pwr_current_draw), [Power])
self.uart = self.Port(UartPort(), [InOut])
self.en = self.Port(DigitalSink())
self.boot = self.Port(DigitalSink())
# note that RX and TX here are from the connected device, so they're flipped from the CP2102's view
self.conn = self.Block(PinHeader254DualShroudedInline(6)).connected(
{
"1": self.pwr,
"5": self.gnd,
"4": self.uart.rx,
"3": self.uart.tx,
"6": self.en, # RTS
"2": self.boot, # CTS
}
)
class EspProgrammer(JlcBoardTop):
"""USB UART converter board set up for ESP programming including auto-program circuit."""
@override
def contents(self) -> None:
super().contents()
self.usb_uart = self.Block(UsbCReceptacle())
self.vusb = self.connect(self.usb_uart.pwr)
self.gnd = self.connect(self.usb_uart.gnd)
# 5v DOMAIN
with self.implicit_connect(
ImplicitConnect(self.vusb, [Power]),
ImplicitConnect(self.gnd, [Common]),
) as imp:
self.vusb_protect = imp.Block(ProtectionZenerDiode(voltage=(5.25, 6) * Volt))
self.usbconv = imp.Block(Cp2102())
(self.usb_esd,), self.usb_chain = self.chain(self.usb_uart.usb, imp.Block(UsbEsdDiode()), self.usbconv.usb)
# for target power only
self.reg_3v3 = imp.Block(LinearRegulator(output_voltage=3.3 * Volt(tol=0.05)))
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.out = imp.Block(EspProgrammerTc2030Inline())
self.connect(self.usbconv.uart, self.out.uart)
self.auto = imp.Block(EspAutoProgram())
self.connect(self.usbconv.dtr, self.auto.dtr)
self.connect(self.usbconv.rts, self.auto.rts)
self.connect(self.auto.en, self.out.en)
self.connect(self.auto.boot, self.out.boot)
(self.led,), _ = self.chain(self.usbconv.suspend, imp.Block(IndicatorSinkLed(Led.White)))
(self.led_en,), _ = self.chain(self.usbconv.rts, imp.Block(IndicatorSinkLed(Led.Red)))
@override
def refinements(self) -> Refinements:
return super().refinements() + Refinements(
instance_refinements=[
(["reg_3v3"], Ap2204k),
],
instance_values=[
(["refdes_prefix"], "U"), # unique refdes for panelization
# 2.2uF generates a 1206, but 4.7uF allows a 0805
(["reg_3v3", "out_cap", "cap", "capacitance"], Range.from_tolerance(4.7e-6, 0.2)),
],
class_refinements=[],
class_values=[
(SelectorArea, ["footprint_area"], Range.from_lower(1.5)), # at least 0402
(TableBjt, ["part"], "BC846BW 1B"), # default option is OOS
],
)
class EspProgrammerTestCase(unittest.TestCase):
def test_design(self) -> None:
run_test_board(EspProgrammer)