abse/smart-ring-flex
A tscircuit package created by abse.
- Version
- 0.0.24
- License
- unset
- Stars
- 0
src/cutoff-service.tsx
import {Fragment} from 'react'
import SavedRouting from './saved-routing'
import serviceCopper from '../routing/ch552-service-copper.json'
import linkCopper from '../routing/ch552-link-copper.json'
import servicePlacement from './service-placement.json'
const svcAt=(name:string)=>(servicePlacement as Record<string,{pcbX:number;pcbY:number}>)[name]??{}
import {CH552G} from '../imports/CH552G/CH552G'
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 {BM03B_SRSS_TB_LF__SN_} from '../imports/BM03B_SRSS_TB_LF__SN_/BM03B_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,'100k','D_XLAT_EN','D_GND','C25741'],['R105',-72.8,3,'10k','D_VREF','D_XLAT_EN','C25744'],
['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']
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 CutoffService({connectRing=true,useSavedService=true,captureOnly=false,externalCopper=false}:{connectRing?:boolean;useSavedService?:boolean;captureOnly?:boolean;externalCopper?: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" />}
{['DockPower','UsbProgrammer','DockDebug'].map((name,i)=><schematicsheet key={name} name={name} displayName={['Dock USB-C power','USB CMSIS-DAP bridge','1.8V SWD and test fixture'][i]} sheetWidth={140} sheetHeight={120}/>)}
<schematicsection name="D_POWER" displayName="USB-C and 75mA dock supply"/>
<schematicsection name="D_MCU" displayName="USB programmer controller"/>
<schematicsection name="D_DEBUG" displayName="Ring programming interface"/>
<TYPE_C_31_M_12 name="J101" layer="top" pcbX={-104.3} pcbY={1.25} {...sheet} schSheetName="DockPower" schSectionName="D_POWER" schX={-18} schY={14} schWidth={2.05} noConnect={['SBU1','SBU2']}
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={-97.0} pcbY={2.9} pcbRotation={90} {...sheet} schSheetName="DockPower" schSectionName="D_POWER" schX={-9} schY={14} noConnect={['NC']}
connections={{VIN:n('USB_5V'),GND:n('D_GND'),EN:n('USB_5V'),VOUT:n('D_3V3')}}/>
<CH552G name="U104" layer="top" pcbX={-85.8} pcbY={0} {...sheet} schSheetName="UsbProgrammer" schSectionName="D_MCU" schX={4} schY={12} schWidth={1.95} schHeight={1.8} noConnect={['pin1','pin2','pin6','pin7','pin8','pin9','pin10','pin11','pin5']}
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')}}/>
<SKRPACE010 name="SW101" layer="top" pcbX={-97} pcbY={-1.7} pcbRotation={90} internallyConnectedPins={[["pin1","pin2"],["pin3","pin4"]]} {...sheet} schSheetName="UsbProgrammer" schSectionName="D_MCU" schX={13} schY={14} 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={-74.8} pcbY={1.4} pcbRotation={90} {...sheet} schSectionName="D_DEBUG" schX={-14} schY={-8} schWidth={1.95}
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={-64.8} pcbY={1.6} {...sheet} schSheetName="DockPower" schSectionName="D_POWER" schX={0} schY={22} schWidth={1.95}
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')}}/>
<BM03B_SRSS_TB_LF__SN_ name="J102" layer="top" pcbX={-57.6} pcbY={.4} {...sheet} schSectionName="D_DEBUG" schX={-3} schY={-31}
connections={{pin1:n('D_SWCLK_3V3'),pin2:n('D_GND'),pin3:n('D_SWDIO_3V3'),pin4:n('D_GND'),pin5:n('D_GND')}}/>
{caps.map(([name,x,y,value,net,part],i)=><capacitor key={name} name={name} capacitance={value} footprint="0402" supplierPartNumbers={{jlcpcb:[part]}} layer="top" pcbX={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} 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={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]} 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} 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={-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} 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={-47.72} pcbY={0} pcbRotation={90} fontSize={.5} layer="top"/>
<pcbstiffener name="DOCK_BACKING" material="fr4" shape="rect" pcbX={g.dockCenterX} width={58} height={8} thickness={.6} adhesiveThickness={.05} layer="bottom"/>
{[
['J101','USB-C power and USB 2.0 data; no PD negotiation'],['U101','75mA typical current-limited dock supply; charger stays on ring'],['U102','3.3V supply for USB programmer; not ring power'],['U104','CH552 USB to SWD bridge; firmware adaptation and bench test required'],['SW101','Hold BOOT while plugging USB to install programmer firmware'],['U103','1.8V/3.3V SWD translation; short traces and slow initial SWD clock'],['J102','Optional JST SWD input; never drive alongside active onboard probe'],['TP101-104 / TP106','1x5 2.54mm fixture; GND,1V8,DIO,CLK,5V; top pads without paste'],
...testRow.map(([ref,label])=>[ref,`Exposed 1.2mm probe pad: ${label}; 2.54mm fixture pitch`]),
...caps.map(([ref,,,v,net])=>[ref,`${v} bypass for ${net}`]),...rs.map(([ref,,,v,a,b])=>[ref,`${v} between ${a} and ${b}`]),...cutLinks.map(([ref])=>[ref,'Factory-fitted 0 ohm temporary service link; power off before cutting'])
].map(([ref,text],i)=><schematictext key={ref} text={`${ref}: ${text}`} {...sheet} schSheetName={['J101','U101','U102','C101','C102','C107','C108','R101','R102','R109'].includes(ref)?'DockPower':['U104','SW101','C103','R103'].includes(ref)?'UsbProgrammer':'DockDebug'} schX={-20+Math.floor(i/12)*27} schY={-40-(i%12)*.65} fontSize={.2} anchor="left"/>)}
{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}}/>}
</>}