#!/usr/bin/env python3

from svg_schematic import (
    Schematic, offsets_to_coordinates, shift_x, shift_y, shift,
    Amp, Box, Ground, Label, Pin, Source, Wire
)

with Schematic(filename = 'pipeline-adc.svg', line_width=2):

    x_offsets = dict(
        i = 0,
        adc = 125,
        sh = 75,
        dac = 75,
        sum = 75,
        amp = 100,
    )
    y_offsets = dict(
        l1 = 0,
        l2 = 100,
        l3 = 75,
        l4 = 50,
        l5 = 100,
    )
    offsets_to_coordinates(locals(), x_offsets, y_offsets)

    s1 = Box((dac_x, (l1_y + l2_y)/2), w=10, h=4, background='lightgray')
    Label(s1.SE, loc='nw', name='Stage 1')

    i = Pin((i_x, l1_y), kind='in', name='in')
    adc = Box((adc_x, l2_y), name='2 bit', value='Flash')
    sh = Box((sh_x, l1_y), name='SAH')
    dac = Box((dac_x, l2_y), name='2 bit', value='DAC')
    sum = Source((sum_x, l1_y), kind='sum', orientation='h|')
    Label(sum.W, loc='nw', name='+')
    Label(sum.S, loc='se', name='−')
    amp = Amp((amp_x, l1_y), kind='se', name='4×')
    Wire([i.t[0], sh.t[1]])
    Wire([sh.t[0], sum.t[1]])
    Wire([sum.t[0], amp.t[1]])
    Wire([(adc.t[1][0]-25, l1_y), shift_x(adc.t[1], -25), adc.t[1]])
    Wire([adc.t[0], dac.t[1]])
    Wire([dac.t[0], (sum_x, l2_y), (sum_x, l1_y+25)])

    x_offsets = dict(
        s1 = sh_x,
        s2 = 100,
        s3 = 125,
        s4 = 125,
    )
    offsets_to_coordinates(locals(), x_offsets)

    s2 = Box((s2_x, l4_y), name='Stage 2')
    s3 = Box((s3_x, l4_y), name='Stage 3')
    s4 = Box((s4_x, l4_y), name='4 bit', value='Flash')
    Wire([s2.t[0], s3.t[1]])
    Wire([s3.t[0], s4.t[1]])
    Wire([amp.t[0], shift_x(amp.t[0], 50), (amp.t[0][0]+50, l3_y), (s2_x-75, l3_y), (s2_x-75, l4_y), s2.t[1]])
    Wire([(s1_x, l2_y), (s1_x, l5_y-25)])

    ec = Box(((s1_x + s4_x)/2, l5_y), name='Digital Error Correction', w=8, h=1)
    out = Pin(shift_x(ec.t[0], 50), kind='out', name='out', w=2)
    Wire([ec.t[0], out.t[0]])
    Wire([(s2_x, l4_y+37.5), (s2_x, l5_y-25)])
    Wire([(s3_x, l4_y+37.5), (s3_x, l5_y-25)])
    Wire([(s4_x, l4_y+37.5), (s4_x, l5_y-25)])
    Label(shift_x(ec.E, 25), kind='slash', loc='s', name='10')

    # Add bus width labels
    Label((s1_x, l5_y-45), kind='slash', loc='w', name='2', nudge=8)
    Label((s2_x, l5_y-45), kind='slash', loc='w', name='2', nudge=8)
    Label((s3_x, l5_y-45), kind='slash', loc='w', name='2', nudge=8)
    Label((s4_x, l5_y-45), kind='slash', loc='w', name='4', nudge=8)


e664d14198b4c4725d6309bcc8c36ad081f8d519
<mask token>

<mask token>
with Schematic(filename='pipeline-adc.svg', line_width=2):
    x_offsets = dict(i=0, adc=125, sh=75, dac=75, sum=75, amp=100)
    y_offsets = dict(l1=0, l2=100, l3=75, l4=50, l5=100)
    offsets_to_coordinates(locals(), x_offsets, y_offsets)
    s1 = Box((dac_x, (l1_y + l2_y) / 2), w=10, h=4, background='lightgray')
    Label(s1.SE, loc='nw', name='Stage 1')
    i = Pin((i_x, l1_y), kind='in', name='in')
    adc = Box((adc_x, l2_y), name='2 bit', value='Flash')
    sh = Box((sh_x, l1_y), name='SAH')
    dac = Box((dac_x, l2_y), name='2 bit', value='DAC')
    sum = Source((sum_x, l1_y), kind='sum', orientation='h|')
    Label(sum.W, loc='nw', name='+')
    Label(sum.S, loc='se', name='−')
    amp = Amp((amp_x, l1_y), kind='se', name='4×')
    Wire([i.t[0], sh.t[1]])
    Wire([sh.t[0], sum.t[1]])
    Wire([sum.t[0], amp.t[1]])
    Wire([(adc.t[1][0] - 25, l1_y), shift_x(adc.t[1], -25), adc.t[1]])
    Wire([adc.t[0], dac.t[1]])
    Wire([dac.t[0], (sum_x, l2_y), (sum_x, l1_y + 25)])
    x_offsets = dict(s1=sh_x, s2=100, s3=125, s4=125)
    offsets_to_coordinates(locals(), x_offsets)
    s2 = Box((s2_x, l4_y), name='Stage 2')
    s3 = Box((s3_x, l4_y), name='Stage 3')
    s4 = Box((s4_x, l4_y), name='4 bit', value='Flash')
    Wire([s2.t[0], s3.t[1]])
    Wire([s3.t[0], s4.t[1]])
    Wire([amp.t[0], shift_x(amp.t[0], 50), (amp.t[0][0] + 50, l3_y), (s2_x -
        75, l3_y), (s2_x - 75, l4_y), s2.t[1]])
    Wire([(s1_x, l2_y), (s1_x, l5_y - 25)])
    ec = Box(((s1_x + s4_x) / 2, l5_y), name='Digital Error Correction', w=
        8, h=1)
    out = Pin(shift_x(ec.t[0], 50), kind='out', name='out', w=2)
    Wire([ec.t[0], out.t[0]])
    Wire([(s2_x, l4_y + 37.5), (s2_x, l5_y - 25)])
    Wire([(s3_x, l4_y + 37.5), (s3_x, l5_y - 25)])
    Wire([(s4_x, l4_y + 37.5), (s4_x, l5_y - 25)])
    Label(shift_x(ec.E, 25), kind='slash', loc='s', name='10')
    Label((s1_x, l5_y - 45), kind='slash', loc='w', name='2', nudge=8)
    Label((s2_x, l5_y - 45), kind='slash', loc='w', name='2', nudge=8)
    Label((s3_x, l5_y - 45), kind='slash', loc='w', name='2', nudge=8)
    Label((s4_x, l5_y - 45), kind='slash', loc='w', name='4', nudge=8)

from svg_schematic import Schematic, offsets_to_coordinates, shift_x, shift_y, shift, Amp, Box, Ground, Label, Pin, Source, Wire
with Schematic(filename='pipeline-adc.svg', line_width=2):
    x_offsets = dict(i=0, adc=125, sh=75, dac=75, sum=75, amp=100)
    y_offsets = dict(l1=0, l2=100, l3=75, l4=50, l5=100)
    offsets_to_coordinates(locals(), x_offsets, y_offsets)
    s1 = Box((dac_x, (l1_y + l2_y) / 2), w=10, h=4, background='lightgray')
    Label(s1.SE, loc='nw', name='Stage 1')
    i = Pin((i_x, l1_y), kind='in', name='in')
    adc = Box((adc_x, l2_y), name='2 bit', value='Flash')
    sh = Box((sh_x, l1_y), name='SAH')
    dac = Box((dac_x, l2_y), name='2 bit', value='DAC')
    sum = Source((sum_x, l1_y), kind='sum', orientation='h|')
    Label(sum.W, loc='nw', name='+')
    Label(sum.S, loc='se', name='−')
    amp = Amp((amp_x, l1_y), kind='se', name='4×')
    Wire([i.t[0], sh.t[1]])
    Wire([sh.t[0], sum.t[1]])
    Wire([sum.t[0], amp.t[1]])
    Wire([(adc.t[1][0] - 25, l1_y), shift_x(adc.t[1], -25), adc.t[1]])
    Wire([adc.t[0], dac.t[1]])
    Wire([dac.t[0], (sum_x, l2_y), (sum_x, l1_y + 25)])
    x_offsets = dict(s1=sh_x, s2=100, s3=125, s4=125)
    offsets_to_coordinates(locals(), x_offsets)
    s2 = Box((s2_x, l4_y), name='Stage 2')
    s3 = Box((s3_x, l4_y), name='Stage 3')
    s4 = Box((s4_x, l4_y), name='4 bit', value='Flash')
    Wire([s2.t[0], s3.t[1]])
    Wire([s3.t[0], s4.t[1]])
    Wire([amp.t[0], shift_x(amp.t[0], 50), (amp.t[0][0] + 50, l3_y), (s2_x -
        75, l3_y), (s2_x - 75, l4_y), s2.t[1]])
    Wire([(s1_x, l2_y), (s1_x, l5_y - 25)])
    ec = Box(((s1_x + s4_x) / 2, l5_y), name='Digital Error Correction', w=
        8, h=1)
    out = Pin(shift_x(ec.t[0], 50), kind='out', name='out', w=2)
    Wire([ec.t[0], out.t[0]])
    Wire([(s2_x, l4_y + 37.5), (s2_x, l5_y - 25)])
    Wire([(s3_x, l4_y + 37.5), (s3_x, l5_y - 25)])
    Wire([(s4_x, l4_y + 37.5), (s4_x, l5_y - 25)])
    Label(shift_x(ec.E, 25), kind='slash', loc='s', name='10')
    Label((s1_x, l5_y - 45), kind='slash', loc='w', name='2', nudge=8)
    Label((s2_x, l5_y - 45), kind='slash', loc='w', name='2', nudge=8)
    Label((s3_x, l5_y - 45), kind='slash', loc='w', name='2', nudge=8)
    Label((s4_x, l5_y - 45), kind='slash', loc='w', name='4', nudge=8)

#!/usr/bin/env python3

from svg_schematic import (
    Schematic, offsets_to_coordinates, shift_x, shift_y, shift,
    Amp, Box, Ground, Label, Pin, Source, Wire
)

with Schematic(filename = 'pipeline-adc.svg', line_width=2):

    x_offsets = dict(
        i = 0,
        adc = 125,
        sh = 75,
        dac = 75,
        sum = 75,
        amp = 100,
    )
    y_offsets = dict(
        l1 = 0,
        l2 = 100,
        l3 = 75,
        l4 = 50,
        l5 = 100,
    )
    offsets_to_coordinates(locals(), x_offsets, y_offsets)

    s1 = Box((dac_x, (l1_y + l2_y)/2), w=10, h=4, background='lightgray')
    Label(s1.SE, loc='nw', name='Stage 1')

    i = Pin((i_x, l1_y), kind='in', name='in')
    adc = Box((adc_x, l2_y), name='2 bit', value='Flash')
    sh = Box((sh_x, l1_y), name='SAH')
    dac = Box((dac_x, l2_y), name='2 bit', value='DAC')
    sum = Source((sum_x, l1_y), kind='sum', orientation='h|')
    Label(sum.W, loc='nw', name='+')
    Label(sum.S, loc='se', name='−')
    amp = Amp((amp_x, l1_y), kind='se', name='4×')
    Wire([i.t[0], sh.t[1]])
    Wire([sh.t[0], sum.t[1]])
    Wire([sum.t[0], amp.t[1]])
    Wire([(adc.t[1][0]-25, l1_y), shift_x(adc.t[1], -25), adc.t[1]])
    Wire([adc.t[0], dac.t[1]])
    Wire([dac.t[0], (sum_x, l2_y), (sum_x, l1_y+25)])

    x_offsets = dict(
        s1 = sh_x,
        s2 = 100,
        s3 = 125,
        s4 = 125,
    )
    offsets_to_coordinates(locals(), x_offsets)

    s2 = Box((s2_x, l4_y), name='Stage 2')
    s3 = Box((s3_x, l4_y), name='Stage 3')
    s4 = Box((s4_x, l4_y), name='4 bit', value='Flash')
    Wire([s2.t[0], s3.t[1]])
    Wire([s3.t[0], s4.t[1]])
    Wire([amp.t[0], shift_x(amp.t[0], 50), (amp.t[0][0]+50, l3_y), (s2_x-75, l3_y), (s2_x-75, l4_y), s2.t[1]])
    Wire([(s1_x, l2_y), (s1_x, l5_y-25)])

    ec = Box(((s1_x + s4_x)/2, l5_y), name='Digital Error Correction', w=8, h=1)
    out = Pin(shift_x(ec.t[0], 50), kind='out', name='out', w=2)
    Wire([ec.t[0], out.t[0]])
    Wire([(s2_x, l4_y+37.5), (s2_x, l5_y-25)])
    Wire([(s3_x, l4_y+37.5), (s3_x, l5_y-25)])
    Wire([(s4_x, l4_y+37.5), (s4_x, l5_y-25)])
    Label(shift_x(ec.E, 25), kind='slash', loc='s', name='10')

    # Add bus width labels
    Label((s1_x, l5_y-45), kind='slash', loc='w', name='2', nudge=8)
    Label((s2_x, l5_y-45), kind='slash', loc='w', name='2', nudge=8)
    Label((s3_x, l5_y-45), kind='slash', loc='w', name='2', nudge=8)
    Label((s4_x, l5_y-45), kind='slash', loc='w', name='4', nudge=8)

