Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/convert-easyeda-json-to-tscircuit-soup-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import type {
ViaSchema,
} from "./schemas/package-detail-shape-schema"
import { mil10ToMm } from "./utils/easyeda-unit-to-mm"
import { expandPinLabelAliases } from "./utils/expand-pin-label-aliases"
import { getPolarizedPinMetadata } from "./utils/get-polarized-pin-metadata"
import { normalizePinLabels } from "./utils/normalize-pin-labels"
import { normalizeSymbolName } from "./utils/normalize-symbol-name"
import { isDiodeCategoryComponent } from "./websafe/convert-to-typescript-component/is-diode-category-component"
import { isLedCategoryComponent } from "./websafe/convert-to-typescript-component/is-led-category-component"
import { getCadModelOffsetMmFromBounds } from "./websafe/get-easyeda-cad-placement-helpers"
Expand Down Expand Up @@ -444,7 +444,7 @@ export const convertEasyEdaJsonToCircuitJson = (
if (pad.number) labels.push(pad.number.toString())

const pin = pins.find((p) => p.pinNumber === pad.number)
if (pin) labels.push(normalizeSymbolName(pin.label))
if (pin) labels.push(...expandPinLabelAliases(pin.label))

return labels
})
Expand Down
23 changes: 16 additions & 7 deletions lib/schemas/single-letter-shape-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,23 @@ const parsePin = (pinString: string): z.infer<typeof PinShapeOutputSchema> => {
const parts = pinString.split("~")
const [, visibility, , pinNumber, x, y, rotation, id] = parts

const nameMatch = pinString.match(/~([\w+#-]+)~(start|end)~/)
let label = nameMatch ? nameMatch[1] : ""
if (label.endsWith("+")) label = `${label.slice(0, -1)}_POS`
if (label.endsWith("-")) label = `${label.slice(0, -1)}_NEG`
// A pin name is the text immediately before its EasyEDA alignment marker.
// Match the delimiters instead of restricting the characters in the name so
// multiplexed labels such as RST/NMI/SBWTDIO are preserved.
const nameMatch = pinString.match(/~([^~]*)~(?:start|end)~/)
let label = nameMatch?.[1] ?? ""
if (label !== "+/-" && label.endsWith("+")) {
label = `${label.slice(0, -1)}_POS`
}
if (label !== "+/-" && label.endsWith("-")) {
label = `${label.slice(0, -1)}_NEG`
}
label = normalizeActiveLowPinLabel(label)
if (/^\+\d+(?:\.\d+)?V$/i.test(label)) label = `V${label.slice(1, -1)}`
if (label.startsWith("+")) label = `${label.slice(1)}_POS`
if (label.startsWith("-")) label = `${label.slice(1)}_NEG`
if (label !== "+/-") {
if (/^\+\d+(?:\.\d+)?V$/i.test(label)) label = `V${label.slice(1, -1)}`
if (label.startsWith("+")) label = `${label.slice(1)}_POS`
if (label.startsWith("-")) label = `${label.slice(1)}_NEG`
}

const colorMatch = pinString.match(/#[0-9A-F]{6}/)
const labelColor = colorMatch ? colorMatch[0] : ""
Expand Down
42 changes: 42 additions & 0 deletions lib/utils/expand-pin-label-aliases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { normalizeSymbolName } from "./normalize-symbol-name"

const cleanAlias = (alias: string): string => {
const trimmedAlias = alias.trim()
const withoutActiveLowSuffix = trimmedAlias.endsWith("#")
? trimmedAlias.slice(0, -1)
: trimmedAlias
const match = withoutActiveLowSuffix.match(/^(.*?)([+\-\u2013\u2212])$/u)
if (!match) return normalizeSymbolName(withoutActiveLowSuffix)

const [, name, polarity] = match
if (!name) return ""
return `${name}_${polarity === "+" ? "POS" : "NEG"}`
}

export const expandPinLabelAliases = (rawLabel: string): string[] => {
const label = rawLabel.trim()
if (!label || label === "+/-") return []
if (label === "+") return ["_POS"]
if (/^[\-\u2013\u2212]$/u.test(label)) return ["_NEG"]

const leadingAliases = label.match(/^\(([^)]*\/[^)]*)\)(.+)$/)
if (leadingAliases) {
return [leadingAliases[2], ...leadingAliases[1].split("/")]
.map(cleanAlias)
.filter(Boolean)
}

const trailingAliases = label.match(/^([^()]+)\(([^)]*\/[^)]*)\)$/)
if (trailingAliases) {
return [trailingAliases[1], ...trailingAliases[2].split("/")]
.map(cleanAlias)
.filter(Boolean)
}

const nonAliasParentheses = label.match(/^([^()]+)\([^)]*\)$/)
const aliases = nonAliasParentheses
? [nonAliasParentheses[1]]
: label.split("/")

return aliases.map(cleanAlias).filter(Boolean)
}
2 changes: 1 addition & 1 deletion tests/convert-to-ts/C105419-to-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ it("should convert C105419 into typescript file", async () => {

const pinLabels = {
pin1: ["DAT2"],
pin2: ["pin2"],
pin2: ["CD","DAT3"],
pin3: ["CMD"],
pin4: ["VDD"],
pin5: ["CLK"],
Expand Down
46 changes: 23 additions & 23 deletions tests/convert-to-ts/C14877-to-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,38 @@ it("should convert C14877 into typescript file", async () => {
"import type { ChipProps } from "@tscircuit/props"

const pinLabels = {
pin1: ["pin1"],
pin2: ["pin2"],
pin1: ["PD3","PCINT19","OC2B","INT1"],
pin2: ["PD4","PCINT20","XCK","T0"],
pin3: ["GND3"],
pin4: ["VCC2"],
pin5: ["GND2"],
pin6: ["VCC1"],
pin7: ["pin7"],
pin8: ["pin8"],
pin9: ["pin9"],
pin10: ["pin10"],
pin11: ["pin11"],
pin12: ["pin12"],
pin13: ["pin13"],
pin14: ["pin14"],
pin15: ["pin15"],
pin16: ["pin16"],
pin17: ["pin17"],
pin7: ["PB6","PCINT6","XTAL1","TOSC1"],
pin8: ["PB7","PCINT7","XTAL2","TOSC2"],
pin9: ["PD5","PCINT21","OC0B","T1"],
pin10: ["PD6","PCINT22","OC0A","AIN0"],
pin11: ["PD7","PCINT23","AIN1"],
pin12: ["PB0","PCINT0","CLKO","ICP1"],
pin13: ["PB1","PCINT1","OC1A"],
pin14: ["PB2","PCINT2","SS","OC1B"],
pin15: ["PB3","PCINT3","OC2A","MOSI"],
pin16: ["PB4","PCINT4","MISO"],
pin17: ["PB5","SCK","PCINT5"],
pin18: ["AVCC"],
pin19: ["ADC6"],
pin20: ["AREF"],
pin21: ["GND1"],
pin22: ["ADC7"],
pin23: ["pin23"],
pin24: ["pin24"],
pin25: ["pin25"],
pin26: ["pin26"],
pin27: ["pin27"],
pin28: ["pin28"],
pin29: ["pin29"],
pin30: ["pin30"],
pin31: ["pin31"],
pin32: ["pin32"]
pin23: ["PC0","ADC0","PCINT8"],
pin24: ["PC1","ADC1","PCINT9"],
pin25: ["PC2","ADC2","PCINT10"],
pin26: ["PC3","ADC3","PCINT11"],
pin27: ["PC4","ADC4","SDA","PCINT12"],
pin28: ["PC5","ADC5","SCL","PCINT13"],
pin29: ["PC6","RESET","PCINT14"],
pin30: ["PD0","RXD","PCINT16"],
pin31: ["PD1","TXD","PCINT17"],
pin32: ["PD2","INT0","PCINT18"]
} as const

const pinAttributes = {
Expand Down
6 changes: 3 additions & 3 deletions tests/convert-to-ts/C2886621-to-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ it("should convert C2886621 into typescript file", async () => {
const pinLabels = {
pin1: ["TRIOUT"],
pin2: ["SINEIN_POS"],
pin3: ["pin3"],
pin3: ["SINEIN_NEG"],
pin4: ["AUX1IN"],
pin5: ["AUX2IN"],
pin6: ["HFTRACK"],
pin7: ["EXPOFREQ"],
pin8: ["pin8"],
pin8: ["V_NEG"],
pin9: ["TRIMIX"],
pin10: ["SAWMIX"],
pin11: ["PULSEMIX"],
Expand All @@ -53,7 +53,7 @@ it("should convert C2886621 into typescript file", async () => {
pin28: ["SQUAREOUT"],
pin29: ["SAWOUT"],
pin30: ["PULSEOUT"],
pin31: ["pin31"],
pin31: ["PWMIN_NEG"],
pin32: ["PWMIN_POS"],
pin33: ["EP"]
} as const
Expand Down
4 changes: 2 additions & 2 deletions tests/convert-to-ts/C393941-to-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ it("should convert C393941 into typescript file", async () => {

const pinLabels = {
pin1: ["DAT2"],
pin2: ["pin2"],
pin2: ["CD1","DAT3"],
pin3: ["CMD"],
pin4: ["VDD"],
pin5: ["CLX"],
Expand All @@ -37,7 +37,7 @@ it("should convert C393941 into typescript file", async () => {
pin11: ["pin11"],
pin12: ["pin12"],
pin13: ["pin13"],
pin14: ["CD"]
pin14: ["CD2"]
} as const

const pinAttributes = {
Expand Down
4 changes: 2 additions & 2 deletions tests/convert-to-ts/C410353-to-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ it("should convert C410353 into typescript file", async () => {
"import type { ChipProps } from "@tscircuit/props"

const pinLabels = {
pin1: ["pin1"],
pin1: ["CD1","DAT3"],
pin2: ["CMD"],
pin3: ["VSS1"],
pin4: ["VDD"],
Expand All @@ -32,7 +32,7 @@ it("should convert C410353 into typescript file", async () => {
pin7: ["DAT0"],
pin8: ["DAT1"],
pin9: ["DAT2"],
pin10: ["CD"],
pin10: ["CD2"],
pin11: ["WP"],
pin12: ["EP1"],
pin13: ["EP2"]
Expand Down
2 changes: 1 addition & 1 deletion tests/convert-to-ts/C46497-to-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ it("should convert C46497 into typescript file", async () => {
pin5: ["RINN"],
pin6: ["PLIMIT"],
pin7: ["GVDD"],
pin8: ["pin8"],
pin8: ["GAIN","SLV"],
pin9: ["GND1"],
pin10: ["LINP"],
pin11: ["LINN"],
Expand Down
108 changes: 54 additions & 54 deletions tests/convert-to-ts/C472489-to-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,70 +23,70 @@ it("should convert C472489 into typescript file", async () => {
"import type { ChipProps } from "@tscircuit/props"

const pinLabels = {
pin1: ["pin1"],
pin2: ["pin2"],
pin3: ["pin3"],
pin4: ["pin4"],
pin5: ["pin5"],
pin6: ["pin6"],
pin7: ["pin7"],
pin8: ["pin8"],
pin9: ["pin9"],
pin10: ["pin10"],
pin11: ["pin11"],
pin12: ["pin12"],
pin13: ["pin13"],
pin14: ["pin14"],
pin15: ["pin15"],
pin16: ["pin16"],
pin1: ["P4.3","UCA0SOMI1","UCA0RXD1","UCB1STE1","S4"],
pin2: ["P1.4","UCB0CLK","UCA0STE1","TA1.01","S3"],
pin3: ["P1.5","UCB0STE","UCA0CLK1","TA0.01","S2"],
pin4: ["P1.6","UCB0SIMO","UCB0SDA","TA0.11","S1"],
pin5: ["P1.7","UCB0SOMI","UCB0SCL","TA0.21","S0"],
pin6: ["R33","LCDCAP"],
pin7: ["P6.0","R23"],
pin8: ["P6.1","R13","LCDREF"],
pin9: ["P6.2","COUT1","R03"],
pin10: ["P6.3","COM0"],
pin11: ["P6.4","TB0.01","COM1","S30"],
pin12: ["P6.5","TB0.11","COM2","S29"],
pin13: ["P6.6","TB0.21","COM3","S28"],
pin14: ["P3.0","UCB1CLK1","TA3.2","S27"],
pin15: ["P3.1","UCB1SIMO1","UCB1SDA1","TA3.3","S26"],
pin16: ["P3.2","UCB1SOMI1","UCB1SCL1","TA3.4","S25"],
pin17: ["DVSS1"],
pin18: ["DVCC1"],
pin19: ["pin19"],
pin20: ["pin20"],
pin21: ["pin21"],
pin22: ["pin22"],
pin23: ["pin23"],
pin24: ["pin24"],
pin25: ["pin25"],
pin26: ["pin26"],
pin27: ["pin27"],
pin28: ["pin28"],
pin29: ["pin29"],
pin30: ["pin30"],
pin31: ["pin31"],
pin32: ["pin32"],
pin33: ["pin33"],
pin34: ["pin34"],
pin35: ["pin35"],
pin36: ["pin36"],
pin37: ["pin37"],
pin38: ["pin38"],
pin19: ["TEST","SBWTCK"],
pin20: ["N_RST","NMI","SBWTDIO"],
pin21: ["PJ.0","TDO","TB0OUTH1","SMCLK1","SRSCG1"],
pin22: ["PJ.1","TDI","TCLK","MCLK","SRSCG0"],
pin23: ["PJ.2","TMS","ACLK1","SROSCOFF"],
pin24: ["PJ.3","TCK","COUT2","SRCPUOFF"],
pin25: ["P3.3","TA1.11","TBOCLK1","S24"],
pin26: ["P3.4","UCA1SIMO","UCA1TXD","TB0.02","S23"],
pin27: ["P3.5","UCA1SOMI","UCA1RXD","TB0.12","S22"],
pin28: ["P3.6","UCA1CLK","TB0.22","S21"],
pin29: ["P3.7","UCA1STE1","TB0.3","S20"],
pin30: ["P2.3","UCA0STE2","TB0OUTH2","S19"],
pin31: ["P2.2","UCA0CLK2","TB0.4","RTCCLK1","S18"],
pin32: ["P2.1","UCA0SOMI2","UCA0RXD2","TB0.5","DMAE01","S17"],
pin33: ["P2.0","UCA0SIMO1","UCA0TXD1","TB0.6","TB0CLK","S16"],
pin34: ["P7.0","TA0CLK1","S15"],
pin35: ["P7.1","TA0.02","ACLK2","S14"],
pin36: ["P7.2","TA0.12","S13"],
pin37: ["P7.3","TA0.22","S12"],
pin38: ["P7.4","SMCLK2","S11"],
pin39: ["DVSS2"],
pin40: ["DVCC2"],
pin41: ["pin41"],
pin42: ["pin42"],
pin43: ["pin43"],
pin44: ["pin44"],
pin45: ["pin45"],
pin46: ["pin46"],
pin47: ["pin47"],
pin48: ["pin48"],
pin41: ["P1.3","TA1.21","A3","C3"],
pin42: ["P1.2","TA1.12","TA0CLK2","COUT3","A2","C2"],
pin43: ["P1.1","TA0.23","TA1CLK1","COUT4","A1","C1","VREF_POS","VeREF_POS"],
pin44: ["P1.0","TA0.13","DMAE02","RTCCLK2","A0","C0","VREF_NEG","VeREF_NEG"],
pin45: ["P9.4","A12","C12"],
pin46: ["P9.5","A13","C13"],
pin47: ["P9.6","A14","C14"],
pin48: ["P9.7","A15","C15"],
pin49: ["AVCC1"],
pin50: ["AVSS1"],
pin51: ["pin51"],
pin52: ["pin52"],
pin51: ["PJ.4","LFXIN"],
pin52: ["PJ.5","LFXOUT"],
pin53: ["AVSS2"],
pin54: ["pin54"],
pin55: ["pin55"],
pin54: ["PJ.7","HFXOUT"],
pin55: ["PJ.6","HFXIN"],
pin56: ["AVSS3"],
pin57: ["pin57"],
pin58: ["pin58"],
pin59: ["pin59"],
pin60: ["pin60"],
pin61: ["pin61"],
pin57: ["P5.7","UCA1STE2","TBOCLK2","S10"],
pin58: ["P4.4","UCB1STE2","TA1CLK2","S9"],
pin59: ["P4.5","UCB1CLK2","TA1.02","S8"],
pin60: ["P4.6","UCB1SIMO2","UCB1SDA2","TA1.13","S7"],
pin61: ["P4.7","UCB1SOMI2","UCB1SCL2","TA1.22","S6"],
pin62: ["DVSS3"],
pin63: ["DVCC3"],
pin64: ["pin64"]
pin64: ["P4.2","UCA0SIMO2","UCA0TXD2","UCB1CLK3","S5"]
} as const

export const MSP430FR6972IPMR = (props: ChipProps<typeof pinLabels>) => {
Expand Down
6 changes: 3 additions & 3 deletions tests/convert-to-ts/C51950748-to-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ it("should convert C51950748 into typescript file", async () => {
pin16: ["IO5"],
pin17: ["IO4"],
pin18: ["IO27"],
pin19: ["pin19"],
pin20: ["NC1"],
pin19: ["NC1","IO15"],
pin20: ["NC2"],
pin21: ["IO23"],
pin22: ["NC2"],
pin22: ["NC3"],
pin23: ["IO24"],
pin24: ["RX0"],
pin25: ["TX0"],
Expand Down
2 changes: 1 addition & 1 deletion tests/convert-to-ts/C7203002-to-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ it("should convert C7203002 into typescript file", async () => {
pin33: ["GND5"],
pin34: ["GP28"],
pin35: ["ADC_VREF"],
pin36: ["pin36"],
pin36: ["3V3"],
pin37: ["3V3_EN"],
pin38: ["GND7"],
pin39: ["VSYS"],
Expand Down
4 changes: 2 additions & 2 deletions tests/convert-to-ts/C9900017879-to-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ it("should convert C9900017879 into typescript file", async () => {
"import type { ChipProps } from "@tscircuit/props"

const pinLabels = {
pin1: ["pin1"],
pin2: ["pin2"],
pin1: ["D1","TX"],
pin2: ["D0","RX"],
pin3: ["RESET1"],
pin4: ["GND2"],
pin5: ["D2"],
Expand Down
Loading
Loading