abse/smart-ring-flex
A tscircuit package created by abse.
- Version
- 0.0.24
- License
- unset
- Stars
- 0
src/wired-cutoff-service.tsx
import {BM05B_SURS_TF_LF__SN_} from '../imports/BM05B_SURS_TF_LF__SN_/BM05B_SURS_TF_LF__SN_'
import {AO3400A} from '../imports/AO3400A/AO3400A'
import {DockRoot} from './contact-root-lands'
import {schematicFor} from './schematic-layout'
import {wiredDockGeometry as wg} from './wired-dock-geometry'
import {compactFold as cf,compactX as sx} from './compact-service-geometry'
import {Fragment} from 'react'
import SavedRouting from './saved-routing'
import serviceCopper from '../routing/wired-service-copper.json'
import linkCopper from '../routing/ch552-link-copper.json'
import servicePlacement from './service-placement.json'
const svcAt=(name:string)=>{const p=(servicePlacement as Record<string,{pcbX:number;pcbY:number;pcbRotation?:number}>)[name];return p?{...p,pcbX:sx(p.pcbX)}:{}}
import {CH552E} from '../imports/CH552E/CH552E'
import {TXS0102DCUR} from '../imports/TXS0102DCUR/TXS0102DCUR'
import {TPS2553DBVR} from '../imports/TPS2553DBVR/TPS2553DBVR'
import {AP2112K_3_3TRG1} from '../imports/AP2112K_3_3TRG1/AP2112K_3_3TRG1'
import {TYPE_C_31_M_12} from '../imports/TYPE_C_31_M_12/TYPE_C_31_M_12'
import {SM02B_SRSS_TB_LF__SN_} from '../imports/SM02B_SRSS_TB_LF__SN_'
import {SKRPACE010} from '../imports/SKRPACE010/SKRPACE010'
import {A_2N7002} from '../imports/A_2N7002/A_2N7002'
import {serviceGeometry as g} from './cutoff-geometry'
const n=(s:string)=>`net.${s}`
// Unpopulated 1x5 probe fixture, not a claim of an ARM-standard connector pinout.
export const testRow=[
['TP101','GND','D_GND'],['TP102','1V8','D_VREF'],['TP103','DIO','D_IO1V8'],
['TP104','CLK','D_CLK1V8'],['TP106','5V','D_CHARGE5V']
] as const
const caps=[
['C101',-94.4,2.9,'1uF','USB_5V','C52923'],['C102',-94.4,1.4,'1uF','D_3V3','C52923'],
['C103',-92.2,2.8,'100nF','D_3V3','C1525'],
['C105',-76.8,1.2,'100nF','D_VREF','C1525'],['C106',-72.8,1.2,'100nF','D_3V3','C1525'],
['C107',-67.4,1.8,'1uF','USB_5V','C52923'],['C108',-62.4,1.8,'1uF','D_CHARGE5V','C52923']
] as const
const rs=[
['R101',-94.4,-.2,'5.1k','D_CC1','D_GND','C25905'],['R102',-94.4,-1.4,'5.1k','D_CC2','D_GND','C25905'],
['R103',-94.4,-3.1,'10k','D_BOOT','D_3V3','C25744'],
['R104',-76.8,3,'1k','D_XLAT_EN','D_GND','C11702'],['R105',-72.8,3,'100','D_XLAT_EN','D_MCU_ENABLE','C25076'],
['R106',-78.4,0,'100','D_MCU_DIO','D_SWDIO_3V3','C25076'],['R107',-78.4,-1.4,'100','D_MCU_CLK','D_SWCLK_3V3','C25076'],
['R109',-66,3.4,'100k','D_FAULT','D_3V3','C25741']
] as const
export const cutLinks=[
['R130','D_CLK1V8','.TP4 > .pin1',3.3],['R131','D_IO1V8','.TP3 > .pin1',2.0],
['R132','D_VREF','.TP6 > .pin1',.7],['R133','D_GND','.TP7 > .pin1',-.6],
['R134','D_CHARGE5V','.C1 > .pin1',-1.9]
] as const
const nets=['USB_5V','D_3V3','D_CC1','D_CC2','D_USB_DP','D_USB_DM','D_BOOT','D_FAULT','D_XLAT_EN','D_SWCLK_3V3','D_SWDIO_3V3','D_MCU_CLK','D_MCU_DIO','D_GND','D_CHARGE5V','D_VREF','D_CLK1V8','D_IO1V8','D_MCU_ENABLE','D_RESET_GATE','D_RESET1V8']
const capSch:Record<string,{schX:number;schY:number}>={C101:{schX:-20,schY:4},C107:{schX:-18.5,schY:4},C102:{schX:-13,schY:4},C103:{schX:-11.5,schY:4},C106:{schX:-10,schY:4},C105:{schX:-5,schY:4},C108:{schX:0,schY:4}}
const rSch:Record<string,{schX:number;schY:number;schRotation:number}>={R101:{schX:-17,schY:11,schRotation:-90},R102:{schX:-13,schY:9,schRotation:-90},R103:{schX:13,schY:10,schRotation:90},R104:{schX:-14,schY:-11,schRotation:-90},R105:{schX:-11,schY:-11,schRotation:-90},R106:{schX:-19,schY:-6,schRotation:0},R107:{schX:-19,schY:-9,schRotation:0},R108:{schX:-4.5,schY:-9.7,schRotation:-90},R109:{schX:2,schY:26,schRotation:90}}
const sheet={schSheetName:'DockDebug'}
export default function WiredCutoffService({connectRing=true,useSavedService=true,captureOnly=false,externalCopper=false,foldDock=false}:{connectRing?:boolean;useSavedService?:boolean;captureOnly?:boolean;externalCopper?:boolean;foldDock?:boolean}={}) {return <>
{nets.map(name=><net key={name} name={name} routingPhaseIndex={useSavedService?undefined:0} isGroundNet={name==='D_GND'} isPowerNet={['USB_5V','D_3V3','D_VREF','D_CHARGE5V'].includes(name)}/>)}
{!useSavedService&&<autoroutingphase name="USB_PROGRAMMER" phaseIndex={0} minBoardEdgeClearance="0.3mm" minTraceWidth="0.1mm" minViaHoleDiameter="0.1mm" minViaPadDiameter="0.3mm" minTraceToPadEdgeClearance="0.15mm" minViaEdgeToPadEdgeClearance="0.15mm" />}
<TYPE_C_31_M_12 name="J101" layer="top" allowOffBoard pcbX={wg.usbX} pcbY={wg.usbY} pcbRotation={wg.usbRotation} {...sheet} schSheetName="DockPower" schSectionName="D_POWER" schX={-18} schY={14} schWidth={2.05} noConnect={['SBU1','SBU2']}
{...schematicFor('J101')} connections={{EH1:n('D_GND'),EH2:n('D_GND'),EH3:n('D_GND'),EH4:n('D_GND'),GND1:n('D_GND'),GND2:n('D_GND'),VBUS1:n('USB_5V'),VBUS2:n('USB_5V'),CC1:n('D_CC1'),CC2:n('D_CC2'),DP1:n('D_USB_DP'),DP2:n('D_USB_DP'),DN1:n('D_USB_DM'),DN2:n('D_USB_DM')}}/>
<AP2112K_3_3TRG1 name="U102" layer="top" pcbX={sx(-97.0)} pcbY={2.9} pcbRotation={90} {...sheet} schSheetName="DockPower" schSectionName="D_POWER" schX={-9} schY={14} noConnect={['NC']}
{...schematicFor('U102')} connections={{VIN:n('USB_5V'),GND:n('D_GND'),EN:n('USB_5V'),VOUT:n('D_3V3')}}/>
<CH552E name="U104" layer="top" pcbX={sx(-85.8)} pcbY={0} {...sheet} schSheetName="UsbProgrammer" schSectionName="D_MCU" schX={4} schY={12} schWidth={1.95} schHeight={1.2} noConnect={['pin5']}
{...schematicFor('U104')} connections={{VCC:n('D_3V3'),V33:n('D_3V3'),GND:n('D_GND'),UDP:n('D_USB_DP'),UDM:n('D_USB_DM'),P1_5:n('D_MCU_DIO'),P1_6:n('D_MCU_CLK'),P1_4:n('D_MCU_ENABLE'),P1_7:n('D_RESET_GATE')}}/>
<SKRPACE010 name="SW101" layer="top" pcbX={sx(-97)} pcbY={-1.7} pcbRotation={90} internallyConnectedPins={[["pin1","pin2"],["pin3","pin4"]]} {...sheet} schSheetName="UsbProgrammer" schSectionName="D_MCU" schX={13} schY={14} {...schematicFor('SW101')} connections={{pin1:n('D_BOOT'),pin2:n('D_BOOT'),pin3:n('D_USB_DP'),pin4:n('D_USB_DP')}}/>
<TXS0102DCUR name="U103" layer="top" pcbX={sx(-74.8)} pcbY={1.4} pcbRotation={90} {...sheet} schSectionName="D_DEBUG" schX={-14} schY={-8} schWidth={1.95}
{...schematicFor('U103')} connections={{VCCA:n('D_VREF'),VCCB:n('D_3V3'),GND:n('D_GND'),OE:n('D_XLAT_EN'),A1:n('D_CLK1V8'),A2:n('D_IO1V8'),B1:n('D_SWCLK_3V3'),B2:n('D_SWDIO_3V3')}}/>
<TPS2553DBVR name="U101" layer="top" pcbX={sx(-64.8)} pcbY={1.6} {...sheet} schSheetName="DockPower" schSectionName="D_POWER" schX={0} schY={22} schWidth={1.95}
{...schematicFor('U101')} connections={{IN:n('USB_5V'),GND:n('D_GND'),EN:n('USB_5V'),ILIM:n('USB_5V'),OUT:n('D_CHARGE5V'),FAULT:n('D_FAULT')}}/>
<BM05B_SURS_TF_LF__SN_ name="J105" layer="top" pcbX={-58.0} pcbY={-1.25} pcbRotation={0}
{...sheet} {...schematicFor('J105')}
connections={{pin1:n('D_CLK1V8'),pin2:n('D_IO1V8'),pin3:n('D_GND'),pin4:n('D_RESET1V8'),pin5:n('D_VREF'),pin6:n('D_GND'),pin7:n('D_GND')}}/>
<AO3400A name="Q106" layer="top" pcbX={-87.0} pcbY={-1.4}
{...sheet} {...schematicFor('Q106')} connections={{G:n('D_RESET_GATE'),S:n('D_GND'),D:n('D_RESET1V8')}}/>
<silkscreencircle pcbX={-85.15} pcbY={-2.35} radius={.10} strokeWidth={.08} layer="top"/>
<resistor name="R110" resistance="1k" footprint="0402" supplierPartNumbers={{jlcpcb:['C11702']}}
layer="top" pcbX={-87.7} pcbY={3.1} {...sheet} {...schematicFor('R110')}
connections={{pin1:n('D_RESET_GATE'),pin2:n('D_GND')}}/>
<silkscreentext text="J105 TARGET 1V8" pcbX={-58} pcbY={2.35} pcbRotation={0} fontSize={.3} layer="top"/>
<silkscreentext text="1" pcbX={-60.25} pcbY={.55} fontSize={.4} layer="top"/>
<silkscreentext text="1" pcbX={-85.1} pcbY={-2.35} fontSize={.3} layer="top"/>
<DockRoot/>
{caps.map(([name,x,y,value,net,part],i)=><capacitor key={name} name={name} capacitance={value} footprint="0402" supplierPartNumbers={{jlcpcb:[part]}} layer="top" pcbX={sx(x)} pcbY={y} {...svcAt(name)} {...sheet} schSheetName={['C105','C106'].includes(name)?'DockDebug':name==='C103'?'UsbProgrammer':'DockPower'} schSectionName={['C105','C106'].includes(name)?'D_DEBUG':name==='C103'?'D_MCU':'D_POWER'} schX={-18+i%4*6} schY={5-Math.floor(i/4)*4} {...capSch[name]} {...(name==='C103'?{schX:8,schY:12}:name==='C105'?{schX:-17,schY:-8}:name==='C106'?{schX:-11,schY:-8}:{})} schRotation={-90} {...schematicFor(String(name))} connections={{pin1:n(net),pin2:n('D_GND')}}/>)}
{rs.map(([name,x,y,value,a,b,part],i)=><resistor key={name} name={name} resistance={value} footprint="0402" supplierPartNumbers={{jlcpcb:[part]}} layer="top" pcbX={sx(x)} pcbY={y} {...svcAt(name)} {...sheet} schSheetName={['R101','R102','R109'].includes(name)?'DockPower':name==='R103'?'UsbProgrammer':'DockDebug'} schSectionName={['R101','R102','R109'].includes(name)?'D_POWER':name==='R103'?'D_MCU':'D_DEBUG'} schX={-18+i%5*6} schY={-17-Math.floor(i/5)*4} {...rSch[name]} {...schematicFor(String(name))} connections={{pin1:n(a),pin2:n(b)}}/>)}
{testRow.map(([name,label,net],i)=><Fragment key={name}>
<testpoint name={name} pcbX={-78+i*2.54} pcbY={-2.8} layer="top" footprintVariant="pad" padDiameter={1.2} doNotPlace {...sheet} schSectionName="D_DEBUG" schX={-18+i*5} schY={-28} {...schematicFor(String(name))} connections={{pin1:n(net)}} footprint={<footprint><smtpad portHints={['pin1']} shape="circle" radius={.6} noSolderPaste/><courtyardcircle radius={.75}/></footprint>}/>
<silkscreentext text={`${i+1}:${label}`} pcbX={-78+i*2.54} pcbY={-3.8} fontSize={.4} layer="top"/>
</Fragment>)}
{cutLinks.map(([name,net,target,y],i)=><Fragment key={name}>
<resistor name={name} resistance="0" footprint="0402" supplierPartNumbers={{jlcpcb:['C17168']}} noConnect={connectRing?undefined:['pin2']} layer="top" pcbX={sx(-52)} pcbY={y} {...svcAt(name)} {...sheet} schSectionName="D_DEBUG" schX={-18+i*5} schY={-34} schRotation={name==='R133'?90:['R132','R134'].includes(name)?-90:0} {...schematicFor(String(name))} connections={{pin1:n(net)}}/>
{connectRing&&<trace name={`LINK_${name}`} from={`.${name} > .pin2`} to={target} routingPhaseIndex={undefined}/>}
</Fragment>)}
<keepout name="CUT_BOTTOM_CLEAR" shape="rect" pcbX={(g.cutA+g.cutB)/2} width={6.02} height={8.6} layers={['bottom']}/>
{[g.cutA,g.cutB].map((x,i)=><Fragment key={i}>{Array.from({length:9},(_,k)=><silkscreenline key={k} x1={x} y1={-4+k-.22} x2={x} y2={-4+k+.22} strokeWidth={.12} layer="top"/>)}</Fragment>)}
<silkscreentext text="CUT / POWER OFF" pcbX={sx(-47.72)} pcbY={0} pcbRotation={90} fontSize={.5} layer="top"/>
<pcbstiffener name="DOCK_BACKING_0" material="fr4" shape="polygon" pcbX={0} pcbY={0} outline={[{x:wg.left+.5,y:-3.6},{x:-109.3,y:-3.6},{x:-109.3,y:-4},{x:cf.start-.5,y:-4},{x:cf.start-.5,y:4},{x:-109.3,y:4},{x:-109.3,y:3.6},{x:wg.left+.5,y:3.6}]} thickness={.6} adhesiveThickness={.05} layer="bottom"/>
<pcbstiffener name="DOCK_BACKING_1" material="fr4" shape="rect" pcbX={(cf.end+cf.right)/2} width={cf.right-cf.end-1} height={8} thickness={.6} adhesiveThickness={.05} layer="bottom"/>
<pcbbend name="DOCK_U_FOLD" x1={cf.center} y1={-4.75} x2={cf.center} y2={4.75} bendRadius={cf.radius} bendAngle={foldDock?-180:0} bendSide="left"/>
<silkscreentext text="FOLD R1.4 / NO STIFFENER" pcbX={cf.center} pcbY={0} pcbRotation={90} fontSize={.35} layer="top"/>
{connectRing&&!captureOnly&&!externalCopper&&<SavedRouting copper={linkCopper as any} namePrefix="BRIDGE" coordinateAnchor={{selector:".VBC1 > .top",cx:-41.34654630478713,cy:-3.825,rotation:0}}/>}
{useSavedService&&!externalCopper&&<SavedRouting copper={serviceCopper as any} namePrefix="CH552" coordinateAnchor={{selector:".CHV1 > .top",cx:serviceCopper.nets.flatMap(n=>n.vias).find(v=>v.name==='CHV1')!.x,cy:serviceCopper.nets.flatMap(n=>n.vias).find(v=>v.name==='CHV1')!.y,rotation:0}}/>}
</>}