
UsbSourceMeasure
BerkeleyHCI/PolymorphicBlocks
A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.

A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.
DeskController is an open-source printed circuit board by BerkeleyHCI, from the BerkeleyHCI/PolymorphicBlocks repository on GitHub, published under the BSD-3-Clause licence. It is a 2-layer board of 142 × 20 mm with 69 parts on 50 nets, routed with 520 tracks and 89 vias.
It is built around the ESP32-C3-WROOM-02-H4, TPA2005D1DRB and SK6812MINI-E, with the AFC07-S30ECA-00, B2B-PH-K and B6B-PH-K among its other parts. It belongs with the ESP32 and RISC-V boards of this library.
subcircuit generator library based hardware description language for circuit board design
Polymorphic Blocks is an open-source, Python-based hardware description language (HDL) for schematic-equivalent design of printed circuit boards (PCBs). Its library of components provide a high-level abstraction for circuit design while subcircuit generators automate the calculation of fine details. Abstract component interfaces enable these libraries to be general across applications and component vendors.
Generates stable KiCad netlists to be routed in the KiCad PCB Editor.
Many boards have been built with this system, from a mechanical keyboard macropad, to battery-powered IoT devices, to a USB source-measure unit. Check out the examples page!
Overall flow: write HDL -> generate netlist -> import into KiCad PCB editor -> place and route (optionally iterating with HDL) -> export BoM and Gerbers -> optionally generate JLC PCBA data
A simplified version of the getting started tutorial is this snippet for a 3x4 mechanical keyboard:
from edg import *
class Keyboard(SimpleBoardTop):
def contents(self) -> None:
super().contents()
self.usb = self.Block(UsbCReceptacle())
self.reg = self.Block(LinearRegulator(3.3 * Volt(tol=0.05)))
self.connect(self.usb.gnd, self.reg.gnd)
self.connect(self.usb.pwr, self.reg.pwr_in)
with self.implicit_connect(
ImplicitConnect(self.reg.pwr_out, [Power]),
ImplicitConnect(self.reg.gnd, [Common]),
) as imp:
self.mcu = imp.Block(IoController())
self.connect(self.usb.usb, self.mcu.usb.request())
self.sw = self.Block(SwitchMatrix(ncols=3, nrows=4))
self.connect(self.sw.cols, self.mcu.gpio.request_vector("sw_col"))
self.connect(self.sw.rows, self.mcu.gpio.request_vector("sw_row"))
self.enc = imp.Block(DigitalRotaryEncoder())
self.connect(self.enc.a, self.mcu.gpio.request("enc_a"))The system:
This generates:

Advanced capabilities include:
pip install edgOn first run, the system will automatically download a compatible Java runtime for the core compiler.
Then, work through building a mechanical keyboard (including subcircuit layout replication) in the getting started tutorial.
Also check out the reference documentation for a concise list of capabilities.
Some documentation is available for library parts construction. Be warned, this is more complex and less polished. See the library block definition tutorial using KiCad schematic import and the library construction reference.
The main goal of this HDL is to enable the creation of general subcircuit libraries that can be reused across many applications.
While graphical schematic tools support hierarchical sheets, direct re-use is limited because the sheets encode a lot of per-design information, like a specific resistor values or footprints. Different users may have different requirements (e.g., different resistor values for a LED based on its input voltage, or preference for through-hole vs. surface-mount components).
This HDL addresses those limitations with two mechanisms:
Both of these combined also present a higher level of abstraction for the board designer, more at the system architecture level-of-design than schematics. We suspect this will also make it easier for novices to design boards, reducing the knowledge barrier to entry.
The fundamental design structure is the hierarchical block diagram, and we expect graphical tooling can layer cleanly on top of the HDL core. Our current focus is on the HDL core and parts libraries, but we are open to collaborations with those interested in building graphical tooling. We suspect this may be particularly useful for novice users.
We built a proof-of-concept mixed textual / graphical IDE plugin for IntelliJ / PyCharm. It has some nifty concepts (including a block diagram visualizer and design space sweep) but is rough around the edges and only sees basic maintenance. It could be a good source for ideas for community developers.
This is functional has been used to produce a wide variety of boards over the years. While the core is reasonably stable, as a pre-v1.0-release there are no formal guarantees of API stability. In practice, deprecation shims are / will be maintained for common features if APIs change.
This started as an academic research project and continues to be developed as a personal project post-graduation, including for designing boards for fun.
Many functional boards have been built with this system and most of the library parts have been physically tested (some across many designs), but there may still be bugs and edge cases. You are recommended to sanity check generated designs during layout.
Be prepared for things to be rough around the edges. The error messages in particular are not great and need work.
Building boards with the included libraries should be relatively straightforward, but building custom library parts is a more complex process.
The current libraries best support intermediate-level (and simpler) PCB designs. This includes circuits with discrete microcontrollers, microcontroller modules (like ESP32s), and socketed dev boards. Libraries include common subcircuits like switch matrices, digitally attached peripherals like I2C sensors, voltage converters, and some analog signal conditioning circuits. Check out the subcircuits library folder and parts library folder.
There is no prescribed architecture and microcontrollers are not required.
ESPHome boards are a great fit.
Designs that do not decompose neatly(ish) into subcircuits blocks are a poor fit.
There is no support for high-speed digital design (like DDR memories). There are some experimental RF subcircuits.
The electrical checks are not a design assurance tool and only automate some of the most common datasheet checks. More advanced parameters, especially performance characteristics not related to maximum ratings, are currently out of scope of the electronics model.
This system has a concept of parameters (variables, think voltages and currents) that can be attached to blocks and propagate through ports. This is limited to directed assignments, with the goal of deterministic, predictable compilation.
Assertions are supported on parameters to enforce electrical correctness checks.
Solving may happen within a single block with arbitrary Python code (for example, find the best set of E12 resistor values to implement a divider), but not across multiple blocks. Search involving multiple blocks must be handled by the block exposing tuning knobs and the user turning those knobs with recompilation.
Most passive parts / discretes are selected from a 2022 JLCPCB parts table (included in this repository). JLC no longer makes parts tables publicly available.
This parts table still works well and boards have been built using this table as recently as 2026. Some basic parts have drifted and some parts may be no longer stocked.
We take pull requests and would love to see contributions and collaborations!
See CONTRIBUTING.md for details.
This started as an academic project, though with the goal of broader adoption. Check out our papers (all open-access), which have more details:
edg.
But, for the purposes of writing research papers, naming collisions are confusing and bad, and we chose to keep the repo and paper name consistent.| Qty | Value | Footprint | References |
|---|---|---|---|
| 7 | 50V 1uF X5R ±10% 0603 Multilayer Ceramic Capacitors MLCC - SMD/SMT ROHS | Capacitor_SMD:C_0603_1608Metric | DC5, DC6, DC7, DC9, DC10, DC15, DC16 |
| 6 | 100mW Thick Film Resistors 75V ±100ppm/? ±1% 4.7k? 0603 Chip Resistor - Surface Mount ROHS | Resistor_SMD:R_0603_1608Metric | DR1, DR2, DR6, DR7, DR8, DR12 |
| 6 | 40V 600mV@1A 1A SOD-323 Schottky Diodes ROHS | Diode_SMD:D_SOD-323 | DD2, DD3, DD4, DD5, DD6, DD7 |
| 6 | PG151101S11 | Switch_Keyboard_Hotswap_Kailh:SW_Hotswap_Kailh_MX | DSW1, DSW2, DSW3, DSW4, DSW5, DSW6 |
| 6 | SK6812MINI-E | edg:LED_SK6812MINI-E | DD9, DD10, DD11, DD12, DD13, DD14 |
| 3 | edg:JlcToolingHole_1.152mm | DH1, DH2, DH3 | |
| 3 | 25V 10uF X5R ±10% 0805 Multilayer Ceramic Capacitors MLCC - SMD/SMT ROHS | Capacitor_SMD:C_0805_2012Metric | DC3, DC11, DC14 |
| 3 | 30V 5.7A 26.5m?@10V,5.7A 1.4W 1.5V@250uA 1PCSNChannel SOT-23-3L MOSFETs ROHS | Package_TO_SOT_SMD:SOT-23 | DQ1, DQ2, DQ3 |
| 3 | 50V 100nF X7R ±10% 0603 Multilayer Ceramic Capacitors MLCC - SMD/SMT ROHS | Capacitor_SMD:C_0603_1608Metric | DC1, DC4, DC13 |
| 2 | 100mW Thick Film Resistors 75V ±100ppm/? ±1% 68k? 0603 Chip Resistor - Surface Mount ROHS | Resistor_SMD:R_0603_1608Metric | DR10, DR11 |
| 2 | 25V 4.7uF X5R ±10% 0805 Multilayer Ceramic Capacitors MLCC - SMD/SMT ROHS | Capacitor_SMD:C_0805_2012Metric | DC2, DC8 |
| 1 | Connector:Tag-Connect_TC2030-IDC-NL_2x03_P1.27mm_Vertical | DJ2 | |
| 1 | -40?~+85? Red 0603 LED Indication - Discrete ROHS | LED_SMD:LED_0603_1608Metric | DD8 |
| 1 | 100mW Thick Film Resistors 75V ±100ppm/? ±1% 10k? 0603 Chip Resistor - Surface Mount ROHS | Resistor_SMD:R_0603_1608Metric | DR3 |
| 1 | 100mW Thick Film Resistors 75V ±100ppm/? ±1% 1k? 0603 Chip Resistor - Surface Mount ROHS | Resistor_SMD:R_0603_1608Metric | DR9 |
| 1 | 100mW Thick Film Resistors 75V ±100ppm/? ±1% 470k? 0603 Chip Resistor - Surface Mount ROHS | Resistor_SMD:R_0603_1608Metric | DR5 |
| 1 | 100mW Thick Film Resistors 75V ±100ppm/? ±1% 820? 0603 Chip Resistor - Surface Mount ROHS | Resistor_SMD:R_0603_1608Metric | DR4 |
| 1 | 3.6V~3.8V 200mW 3.6V SOD-323 Zener Diodes ROHS | Diode_SMD:D_SOD-323 | DD1 |
| 1 | 50V 33nF X7R ±10% 0603 Multilayer Ceramic Capacitors MLCC - SMD/SMT ROHS | Capacitor_SMD:C_0603_1608Metric | DC12 |
| 1 | AFC07-S30ECA-00 | Connector_FFC-FPC:TE_3-1734839-0_1x30-1MP_P0.5mm_Horizontal | DJ3 |
| 1 | B2B-PH-K | Connector_JST:JST_PH_B2B-PH-K_1x02_P2.00mm_Vertical | DJ4 |
| 1 | B6B-PH-K | Connector_JST:JST_PH_B6B-PH-K_1x06_P2.00mm_Vertical | DJ1 |
| 1 | ER-OLED-0.96-1.1 | edg:Lcd_Er_Oled0.96_1.1_Outline | DU3 |
| 1 | ESP32-C3-WROOM-02 | RF_Module:ESP-WROOM-02 | DU2 |
| 1 | G*** | edg:Symbol_DucklingSolid | svg2mod |
| 1 | LDL1117S33R | Package_TO_SOT_SMD:SOT-223-3_TabPin2 | DU1 |
| 1 | TPA2005D1 | Package_SO:MSOP-8-1EP_3x3mm_P0.65mm_EP1.68x1.88mm_ThermalVias | DU4 |
| 1 | gnd | edg:TestPoint_TE_RCT_0805 | DTP1 |
| 1 | npx | edg:TestPoint_TE_RCT_0805 | DTP5 |
| 1 | pwr | edg:TestPoint_TE_RCT_0805 | DTP2 |
| 1 | spk_chain_1 | edg:TestPoint_TE_RCT_0805 | DTP4 |
| 1 | v3v3 | edg:TestPoint_TE_RCT_0805 | DTP3 |
| 1 | ±25% 100?@100MHz 0805 Ferrite Beads ROHS | Inductor_SMD:L_0805_2012Metric | DFB1 |
It measures 142 × 20 mm and has 2 copper layers, 1.6 mm thick.
69 parts, built around the ESP32-C3-WROOM-02-H4, TPA2005D1DRB, SK6812MINI-E and AFC07-S30ECA-00. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.
From the BerkeleyHCI/PolymorphicBlocks repository on GitHub, at the commit this page was made from: the board is examples/DeskController/DeskController.kicad_pcb. PCBKit opens the board in the browser, with nothing to install.
Its repository publishes it under the BSD-3-Clause licence: you may reuse it on that licence's terms (keep the author's notice, and for a copyleft licence share your changes alike).

BerkeleyHCI/PolymorphicBlocks
A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.

BerkeleyHCI/PolymorphicBlocks
A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.

BerkeleyHCI/PolymorphicBlocks
A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.

BerkeleyHCI/PolymorphicBlocks
A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.

BerkeleyHCI/PolymorphicBlocks
A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.

BerkeleyHCI/PolymorphicBlocks
A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.

BerkeleyHCI/PolymorphicBlocks
A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.

BerkeleyHCI/PolymorphicBlocks
A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.

BerkeleyHCI/PolymorphicBlocks
A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.

BerkeleyHCI/PolymorphicBlocks
A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.

BerkeleyHCI/PolymorphicBlocks
A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.

BerkeleyHCI/PolymorphicBlocks
A Python-based hardware description language for PCBs for higher-level (block-diagram / system-architecture level) PCB design through libraries of directly reusable subcircuit generators.


omelia-iliffe/creature-control-board
Use this circuit board to create your own creatures!




Iva0108/Pulse-Oximeter
A pulse oximeter design that includes PCB design in KiCad, Arduino IDE code (to be used with STM32), and a simple Android app to display data trasmitted via Bluetooth.

cjg-1/FPV-RC-CAR
A wireless FPV control system for RC vehicles featuring real-time video transmission and custom embedded power management. Enables immersive first-person vehicle teleoperation with low-latency wireless architecture.
