diff --git a/src/fn/msop.ts b/src/fn/msop.ts index e0d899c4..91d4e8d8 100644 --- a/src/fn/msop.ts +++ b/src/fn/msop.ts @@ -64,7 +64,9 @@ const getMsopCoords = (pinCount: number, pn: number, w: number, p: number) => { const half = pinCount / 2 const rowIndex = (pn - 1) % half const col = pn <= half ? -1 : 1 - const row = (half - 1) / 2 - rowIndex + // Pins are numbered counterclockwise: the left column runs top to bottom, + // the right column runs bottom to top + const row = col === -1 ? (half - 1) / 2 - rowIndex : rowIndex - (half - 1) / 2 return { x: col * length.parse("2mm"), diff --git a/src/fn/son.ts b/src/fn/son.ts index d27441ad..4f143eef 100644 --- a/src/fn/son.ts +++ b/src/fn/son.ts @@ -170,7 +170,9 @@ export const getSonPadCoord = ( const half = num_pins / 2 const rowIndex = (pn - 1) % half const col = pn <= half ? -1 : 1 - const row = (half - 1) / 2 - rowIndex + // Pins are numbered counterclockwise: the left column runs top to bottom, + // the right column runs bottom to top + const row = col === -1 ? (half - 1) / 2 - rowIndex : rowIndex - (half - 1) / 2 return { x: col * length.parse("1.4mm"), diff --git a/tests/msop.test.ts b/tests/msop.test.ts index 5d595b19..92618a20 100644 --- a/tests/msop.test.ts +++ b/tests/msop.test.ts @@ -52,3 +52,16 @@ test("msop16", () => { const svgContent = convertCircuitJsonToPcbSvg(circuitJson) expect(svgContent).toMatchSvgSnapshot(import.meta.path, "msop16") }) + +test("msop8 pins are numbered counterclockwise", () => { + const circuitJson = fp.string("msop8").circuitJson() as any[] + const pad = (pin: string) => + circuitJson.find( + (el) => el.type === "pcb_smtpad" && el.port_hints?.[0] === pin, + ) + // Pins 1-4 run down the left side, pins 5-8 run up the right side, + // so pin 5 sits across from pin 4 and pin 8 across from pin 1 + expect(pad("5").y).toBeCloseTo(pad("4").y) + expect(pad("8").y).toBeCloseTo(pad("1").y) + expect(pad("5").y).toBeLessThan(pad("8").y) +}) diff --git a/tests/son.test.ts b/tests/son.test.ts index aa11a5ad..a1e50ad7 100644 --- a/tests/son.test.ts +++ b/tests/son.test.ts @@ -68,3 +68,29 @@ test("son6", () => { const svgContent = convertCircuitJsonToPcbSvg(circuitJson) expect(svgContent).toMatchSvgSnapshot(import.meta.path, "son6") }) + +test("son8 pins are numbered counterclockwise", () => { + const circuitJson = fp.string("son8").circuitJson() as any[] + const pad = (pin: string) => + circuitJson.find( + (el) => el.type === "pcb_smtpad" && el.port_hints?.[0] === pin, + ) + // Pins 1-4 run down the left side, pins 5-8 run up the right side, + // so pin 5 sits across from pin 4 and pin 8 across from pin 1 + expect(pad("5").y).toBeCloseTo(pad("4").y) + expect(pad("8").y).toBeCloseTo(pad("1").y) + expect(pad("5").y).toBeLessThan(pad("8").y) +}) + +test("son6 pins are numbered counterclockwise", () => { + const circuitJson = fp.string("son6").circuitJson() as any[] + const pad = (pin: string) => + circuitJson.find( + (el) => el.type === "pcb_smtpad" && el.port_hints?.[0] === pin, + ) + // Pins 1-3 run down the left side, pins 4-6 run up the right side, + // so pin 4 sits across from pin 3 and pin 6 across from pin 1 + expect(pad("4").y).toBeCloseTo(pad("3").y) + expect(pad("6").y).toBeCloseTo(pad("1").y) + expect(pad("4").y).toBeLessThan(pad("6").y) +})