rushabhcodes/usb-c-e-paper-display

USB-C powered RP2354B controller board with protected power regulation, EPD display interface and charge-pump rails, crystal timing, user/boot switches, status LEDs, and SWD test points.

Version
1.4.1
License
unset
Stars
0

Use with the tscircuit CLI

tsci is the tscircuit CLI. Install it with npm install -g tscircuit.

tsci clone rushabhcodes/usb-c-e-paper-display  # download the package files into ./usb-c-e-paper-display
tsci add rushabhcodes/usb-c-e-paper-display    # add it to your project as @tsci/rushabhcodes.usb-c-e-paper-display

In a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.

scripts/check-fabrication-artwork.py

"""Check the actual JLCPCB legend against exposed soldermask openings.

Install scripts/fabrication-requirements.txt in a virtual environment. This reads
Gerbers; it never modifies copper, routes, or exported artwork.
"""
import argparse
import hashlib
import json
import tempfile
import zipfile
from collections import Counter
from pathlib import Path

from gerbonara import GerberFile
from gerbonara import graphic_primitives as gp
from gerbonara.utils import MM
from shapely.geometry import LineString, Point, Polygon
from shapely.ops import nearest_points, unary_union


def geometry(p):
    if isinstance(p, gp.Circle):
        return Point(p.x, p.y).buffer(p.r, quad_segs=128)
    if isinstance(p, gp.Line):
        return LineString([(p.x1, p.y1), (p.x2, p.y2)]).buffer(p.width / 2, quad_segs=128)
    if not isinstance(p, gp.ArcPoly):
        p = p.to_arc_poly()
    return Polygon(p.approximate_arcs(max_error=0.000001).outline)


def read_layer(path):
    text = path.read_text()
    assert '%LR' not in text, 'Unsupported aperture rotation in legend/mask'
    primitives = [p for o in GerberFile.open(path).objects for p in o.to_primitives(unit=MM)]
    assert all(p.polarity_dark for p in primitives), 'Unexpected clear polarity'
    return primitives, unary_union([geometry(p) for p in primitives])


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('archive', nargs='?', default='manufacturing/JLCPCB-Gerbers-RevD.zip')
    parser.add_argument('--report', default='manufacturing/checks/fabrication-artwork.json')
    args = parser.parse_args()
    archive = Path(args.archive)
    with tempfile.TemporaryDirectory(prefix='epaper-artwork-') as directory:
        with zipfile.ZipFile(archive) as z:
            for name in ['F_SilkScreen.gbr', 'F_Mask.gbr']:
                Path(directory, name).write_bytes(z.read(name))
        primitives, silk = read_layer(Path(directory, 'F_SilkScreen.gbr'))
        _, mask = read_layer(Path(directory, 'F_Mask.gbr'))
        fiducials = [(-40, 24), (12, 24), (-40, -24)]
        exposed_marks = sum(mask.covers(Point(x, y).buffer(.99, quad_segs=128)) for x, y in fiducials)
        widths = [p.width for p in primitives if hasattr(p, 'width')]
        assert widths, 'Missing legend strokes'
        clearance = silk.distance(mask)
        report = {'result': 'PASS' if min(widths) >= .15 - 1e-6 and clearance >= .15 - 1e-6 and exposed_marks == 3 else 'FAIL',
            'archive_sha256': hashlib.sha256(archive.read_bytes()).hexdigest(),
            'minimum_legend_stroke_mm': min(widths),
            'legend_stroke_counts': dict(Counter(str(round(w, 6)) for w in widths)),
            'minimum_legend_to_mask_opening_mm': clearance,
            'nearest_points_mm': [list(p.coords)[0] for p in nearest_points(silk, mask)],
            'minimum_required_stroke_mm': .15, 'minimum_required_clearance_mm': .15,
            'exposed_fiducials': exposed_marks,
            'source': 'https://jlcpcb.com/capabilities/pcb-capabilities'}
        target = Path(args.report)
        target.parent.mkdir(parents=True, exist_ok=True)
        target.write_text(json.dumps(report, indent=2) + '\n')
        print(json.dumps(report, indent=2))
        assert report['result'] == 'PASS', 'Fabrication legend fails supplier requirements'


if __name__ == '__main__':
    main()