circuit-json-to-tscircuit 0.0.49 → 0.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-YHGRHULT.js → chunk-6TIIS52N.js} +79 -0
- package/dist/cli/main.js +2 -2
- package/dist/lib/index.js +1 -1
- package/lib/get-component-using-template.ts +3 -0
- package/lib/get-pin-attributes.ts +91 -0
- package/package.json +1 -1
- package/tests/fixtures/pin-attributes/ap2127k-2.8trg1.json +91 -0
- package/tests/fixtures/pin-attributes/f1c100s.json +1644 -0
- package/tests/test22-pin-attributes.test.tsx +198 -0
|
@@ -869,6 +869,83 @@ var generateSymbolTsx = (circuitJson) => {
|
|
|
869
869
|
`.trim();
|
|
870
870
|
};
|
|
871
871
|
|
|
872
|
+
// lib/get-pin-attributes.ts
|
|
873
|
+
var attributeNames = {
|
|
874
|
+
is_input: "isInput",
|
|
875
|
+
is_output: "isOutput",
|
|
876
|
+
is_bidirectional: "isBidirectional",
|
|
877
|
+
is_passive: "isPassive",
|
|
878
|
+
can_use_tri_state: "canUseTriState",
|
|
879
|
+
is_using_tri_state: "isUsingTriState",
|
|
880
|
+
can_use_open_collector: "canUseOpenCollector",
|
|
881
|
+
is_using_open_collector: "isUsingOpenCollector",
|
|
882
|
+
can_use_open_emitter: "canUseOpenEmitter",
|
|
883
|
+
is_using_open_emitter: "isUsingOpenEmitter",
|
|
884
|
+
is_gpio: "isGpio",
|
|
885
|
+
highlight_color: "highlightColor",
|
|
886
|
+
must_be_connected: "mustBeConnected",
|
|
887
|
+
provides_power: "providesPower",
|
|
888
|
+
requires_power: "requiresPower",
|
|
889
|
+
provides_ground: "providesGround",
|
|
890
|
+
requires_ground: "requiresGround",
|
|
891
|
+
provides_voltage: "providesVoltage",
|
|
892
|
+
requires_voltage: "requiresVoltage",
|
|
893
|
+
do_not_connect: "doNotConnect",
|
|
894
|
+
include_in_board_pinout: "includeInBoardPinout",
|
|
895
|
+
can_use_internal_pullup: "canUseInternalPullup",
|
|
896
|
+
is_using_internal_pullup: "isUsingInternalPullup",
|
|
897
|
+
needs_external_pullup: "needsExternalPullup",
|
|
898
|
+
can_use_internal_pulldown: "canUseInternalPulldown",
|
|
899
|
+
is_using_internal_pulldown: "isUsingInternalPulldown",
|
|
900
|
+
needs_external_pulldown: "needsExternalPulldown",
|
|
901
|
+
can_use_open_drain: "canUseOpenDrain",
|
|
902
|
+
is_using_open_drain: "isUsingOpenDrain",
|
|
903
|
+
can_use_push_pull: "canUsePushPull",
|
|
904
|
+
is_using_push_pull: "isUsingPushPull",
|
|
905
|
+
should_have_decoupling_capacitor: "shouldHaveDecouplingCapacitor",
|
|
906
|
+
recommended_decoupling_capacitor_capacitance: "recommendedDecouplingCapacitorCapacitance"
|
|
907
|
+
};
|
|
908
|
+
var capabilities = [
|
|
909
|
+
"i2c_sda",
|
|
910
|
+
"i2c_scl",
|
|
911
|
+
"spi_mosi",
|
|
912
|
+
"spi_miso",
|
|
913
|
+
"spi_sck",
|
|
914
|
+
"spi_cs",
|
|
915
|
+
"uart_tx",
|
|
916
|
+
"uart_rx"
|
|
917
|
+
];
|
|
918
|
+
var getPinAttributes = (circuitJson) => {
|
|
919
|
+
const components = circuitJson.filter((e) => e.type === "source_component");
|
|
920
|
+
if (components.length > 1) return void 0;
|
|
921
|
+
const componentId = components[0]?.source_component_id;
|
|
922
|
+
const pins = /* @__PURE__ */ new Map();
|
|
923
|
+
for (const port of circuitJson) {
|
|
924
|
+
if (port.type !== "source_port") continue;
|
|
925
|
+
if (componentId && port.source_component_id && port.source_component_id !== componentId)
|
|
926
|
+
continue;
|
|
927
|
+
const source = { ...port };
|
|
928
|
+
const attributes = {};
|
|
929
|
+
for (const [sourceName, propName] of Object.entries(attributeNames)) {
|
|
930
|
+
if (source[sourceName] !== void 0) {
|
|
931
|
+
attributes[propName] = source[sourceName];
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
const supported = capabilities.filter(
|
|
935
|
+
(c) => source[`supports_${c}`] === true
|
|
936
|
+
);
|
|
937
|
+
const active = capabilities.filter(
|
|
938
|
+
(c) => source[`is_configured_for_${c}`] === true
|
|
939
|
+
);
|
|
940
|
+
if (supported.length) attributes.capabilities = supported;
|
|
941
|
+
if (active.length) attributes.activeCapabilities = active;
|
|
942
|
+
if (Object.keys(attributes).length === 0) continue;
|
|
943
|
+
const key = port.pin_number !== void 0 ? `pin${port.pin_number}` : port.name;
|
|
944
|
+
pins.set(key, { ...pins.get(key), ...attributes });
|
|
945
|
+
}
|
|
946
|
+
return pins.size ? Object.fromEntries(pins) : void 0;
|
|
947
|
+
};
|
|
948
|
+
|
|
872
949
|
// lib/get-component-using-template.ts
|
|
873
950
|
var getComponentUsingTemplate = ({
|
|
874
951
|
pinLabels,
|
|
@@ -880,6 +957,7 @@ var getComponentUsingTemplate = ({
|
|
|
880
957
|
}) => {
|
|
881
958
|
const footprintTsx = generateFootprintTsx(circuitJson);
|
|
882
959
|
const symbolTsx = generateSymbolTsx(circuitJson);
|
|
960
|
+
const pinAttributes = getPinAttributes(circuitJson);
|
|
883
961
|
return `
|
|
884
962
|
import { type ChipProps } from "tscircuit"
|
|
885
963
|
${pinLabels ? `const pinLabels = ${JSON.stringify(pinLabels, null, " ")} as const
|
|
@@ -888,6 +966,7 @@ ${pinLabels ? `const pinLabels = ${JSON.stringify(pinLabels, null, " ")} as con
|
|
|
888
966
|
${footprintTsx ? `footprint={${footprintTsx}}` : ""}
|
|
889
967
|
${symbolTsx ? `symbol={${symbolTsx}}` : ""}
|
|
890
968
|
${pinLabels ? "pinLabels={pinLabels}" : ""}
|
|
969
|
+
${pinAttributes ? `pinAttributes={${JSON.stringify(pinAttributes, null, " ")}}` : ""}
|
|
891
970
|
${objUrl ? `cadModel={{
|
|
892
971
|
objUrl: "${objUrl}",
|
|
893
972
|
rotationOffset: { x: 0, y: 0, z: 0 },
|
package/dist/cli/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
convertCircuitJsonToTscircuit
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-6TIIS52N.js";
|
|
5
5
|
|
|
6
6
|
// cli/main.ts
|
|
7
7
|
import { Command } from "commander";
|
|
@@ -16,7 +16,7 @@ var package_default = {
|
|
|
16
16
|
"./cli": "./dist/cli/main.js"
|
|
17
17
|
},
|
|
18
18
|
type: "module",
|
|
19
|
-
version: "0.0.
|
|
19
|
+
version: "0.0.49",
|
|
20
20
|
repository: {
|
|
21
21
|
type: "git",
|
|
22
22
|
url: "https://github.com/tscircuit/circuit-json-to-tscircuit.git"
|
package/dist/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AnyCircuitElement } from "circuit-json"
|
|
2
2
|
import { generateFootprintTsx } from "./generate-footprint-tsx"
|
|
3
3
|
import { generateSymbolTsx } from "./generate-symbol-tsx"
|
|
4
|
+
import { getPinAttributes } from "./get-pin-attributes"
|
|
4
5
|
|
|
5
6
|
export interface ComponentTemplateParams {
|
|
6
7
|
pinLabels?: Record<string, string[]> | Record<string, string> // ChipProps["pinLabels"]
|
|
@@ -21,6 +22,7 @@ export const getComponentUsingTemplate = ({
|
|
|
21
22
|
}: ComponentTemplateParams) => {
|
|
22
23
|
const footprintTsx = generateFootprintTsx(circuitJson)
|
|
23
24
|
const symbolTsx = generateSymbolTsx(circuitJson)
|
|
25
|
+
const pinAttributes = getPinAttributes(circuitJson)
|
|
24
26
|
return `
|
|
25
27
|
import { type ChipProps } from "tscircuit"
|
|
26
28
|
${pinLabels ? `const pinLabels = ${JSON.stringify(pinLabels, null, " ")} as const\n` : ""}export const ${componentName} = (props: ChipProps${pinLabels ? `<typeof pinLabels>` : ""}) => (
|
|
@@ -28,6 +30,7 @@ ${pinLabels ? `const pinLabels = ${JSON.stringify(pinLabels, null, " ")} as con
|
|
|
28
30
|
${footprintTsx ? `footprint={${footprintTsx}}` : ""}
|
|
29
31
|
${symbolTsx ? `symbol={${symbolTsx}}` : ""}
|
|
30
32
|
${pinLabels ? "pinLabels={pinLabels}" : ""}
|
|
33
|
+
${pinAttributes ? `pinAttributes={${JSON.stringify(pinAttributes, null, " ")}}` : ""}
|
|
31
34
|
${objUrl ? `cadModel={{\n objUrl: \"${objUrl}\",\n rotationOffset: { x: 0, y: 0, z: 0 },\n positionOffset: { x: 0, y: 0, z: 0 },\n }}` : ""}
|
|
32
35
|
${supplierPartNumbers ? `supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}` : ""}
|
|
33
36
|
${manufacturerPartNumber ? `manufacturerPartNumber=\"${manufacturerPartNumber}\"` : ""}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { AnyCircuitElement } from "circuit-json"
|
|
2
|
+
|
|
3
|
+
// Explicitly select electrical attributes; source-port IDs and other metadata
|
|
4
|
+
// must not become chip props. Newer Circuit JSON fields are read without parsing
|
|
5
|
+
// through an older schema, which would strip them from imported JSON.
|
|
6
|
+
const attributeNames = {
|
|
7
|
+
is_input: "isInput",
|
|
8
|
+
is_output: "isOutput",
|
|
9
|
+
is_bidirectional: "isBidirectional",
|
|
10
|
+
is_passive: "isPassive",
|
|
11
|
+
can_use_tri_state: "canUseTriState",
|
|
12
|
+
is_using_tri_state: "isUsingTriState",
|
|
13
|
+
can_use_open_collector: "canUseOpenCollector",
|
|
14
|
+
is_using_open_collector: "isUsingOpenCollector",
|
|
15
|
+
can_use_open_emitter: "canUseOpenEmitter",
|
|
16
|
+
is_using_open_emitter: "isUsingOpenEmitter",
|
|
17
|
+
is_gpio: "isGpio",
|
|
18
|
+
highlight_color: "highlightColor",
|
|
19
|
+
must_be_connected: "mustBeConnected",
|
|
20
|
+
provides_power: "providesPower",
|
|
21
|
+
requires_power: "requiresPower",
|
|
22
|
+
provides_ground: "providesGround",
|
|
23
|
+
requires_ground: "requiresGround",
|
|
24
|
+
provides_voltage: "providesVoltage",
|
|
25
|
+
requires_voltage: "requiresVoltage",
|
|
26
|
+
do_not_connect: "doNotConnect",
|
|
27
|
+
include_in_board_pinout: "includeInBoardPinout",
|
|
28
|
+
can_use_internal_pullup: "canUseInternalPullup",
|
|
29
|
+
is_using_internal_pullup: "isUsingInternalPullup",
|
|
30
|
+
needs_external_pullup: "needsExternalPullup",
|
|
31
|
+
can_use_internal_pulldown: "canUseInternalPulldown",
|
|
32
|
+
is_using_internal_pulldown: "isUsingInternalPulldown",
|
|
33
|
+
needs_external_pulldown: "needsExternalPulldown",
|
|
34
|
+
can_use_open_drain: "canUseOpenDrain",
|
|
35
|
+
is_using_open_drain: "isUsingOpenDrain",
|
|
36
|
+
can_use_push_pull: "canUsePushPull",
|
|
37
|
+
is_using_push_pull: "isUsingPushPull",
|
|
38
|
+
should_have_decoupling_capacitor: "shouldHaveDecouplingCapacitor",
|
|
39
|
+
recommended_decoupling_capacitor_capacitance:
|
|
40
|
+
"recommendedDecouplingCapacitorCapacitance",
|
|
41
|
+
} as const
|
|
42
|
+
|
|
43
|
+
const capabilities = [
|
|
44
|
+
"i2c_sda",
|
|
45
|
+
"i2c_scl",
|
|
46
|
+
"spi_mosi",
|
|
47
|
+
"spi_miso",
|
|
48
|
+
"spi_sck",
|
|
49
|
+
"spi_cs",
|
|
50
|
+
"uart_tx",
|
|
51
|
+
"uart_rx",
|
|
52
|
+
] as const
|
|
53
|
+
|
|
54
|
+
/** Electrical props for the single component represented by a chip template. */
|
|
55
|
+
export const getPinAttributes = (circuitJson: AnyCircuitElement[]) => {
|
|
56
|
+
const components = circuitJson.filter((e) => e.type === "source_component")
|
|
57
|
+
// Pin numbers are local to a component. Never combine multiple components'
|
|
58
|
+
// attributes into a single chip.
|
|
59
|
+
if (components.length > 1) return undefined
|
|
60
|
+
const componentId = components[0]?.source_component_id
|
|
61
|
+
const pins = new Map<string, Record<string, unknown>>()
|
|
62
|
+
for (const port of circuitJson) {
|
|
63
|
+
if (port.type !== "source_port") continue
|
|
64
|
+
if (
|
|
65
|
+
componentId &&
|
|
66
|
+
port.source_component_id &&
|
|
67
|
+
port.source_component_id !== componentId
|
|
68
|
+
)
|
|
69
|
+
continue
|
|
70
|
+
const source: Record<string, unknown> = { ...port }
|
|
71
|
+
const attributes: Record<string, unknown> = {}
|
|
72
|
+
for (const [sourceName, propName] of Object.entries(attributeNames)) {
|
|
73
|
+
if (source[sourceName] !== undefined) {
|
|
74
|
+
attributes[propName] = source[sourceName]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const supported = capabilities.filter(
|
|
78
|
+
(c) => source[`supports_${c}`] === true,
|
|
79
|
+
)
|
|
80
|
+
const active = capabilities.filter(
|
|
81
|
+
(c) => source[`is_configured_for_${c}`] === true,
|
|
82
|
+
)
|
|
83
|
+
if (supported.length) attributes.capabilities = supported
|
|
84
|
+
if (active.length) attributes.activeCapabilities = active
|
|
85
|
+
if (Object.keys(attributes).length === 0) continue
|
|
86
|
+
const key =
|
|
87
|
+
port.pin_number !== undefined ? `pin${port.pin_number}` : port.name
|
|
88
|
+
pins.set(key, { ...pins.get(key), ...attributes })
|
|
89
|
+
}
|
|
90
|
+
return pins.size ? Object.fromEntries(pins) : undefined
|
|
91
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"circuitJson": [
|
|
3
|
+
{
|
|
4
|
+
"type": "source_component",
|
|
5
|
+
"ftype": "simple_chip",
|
|
6
|
+
"source_component_id": "source_component_1",
|
|
7
|
+
"name": "U1",
|
|
8
|
+
"manufacturer_part_number": "AP2127K-28TRG1"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"type": "source_port",
|
|
12
|
+
"source_port_id": "source_port_1",
|
|
13
|
+
"source_component_id": "source_component_1",
|
|
14
|
+
"name": "pin1",
|
|
15
|
+
"pin_number": 1,
|
|
16
|
+
"port_hints": ["VIN"],
|
|
17
|
+
"must_be_connected": true,
|
|
18
|
+
"requires_power": true,
|
|
19
|
+
"should_have_decoupling_capacitor": true,
|
|
20
|
+
"recommended_decoupling_capacitor_capacitance": "1uF"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"type": "source_port",
|
|
24
|
+
"source_port_id": "source_port_2",
|
|
25
|
+
"source_component_id": "source_component_1",
|
|
26
|
+
"name": "pin2",
|
|
27
|
+
"pin_number": 2,
|
|
28
|
+
"port_hints": ["GND"],
|
|
29
|
+
"must_be_connected": true,
|
|
30
|
+
"requires_ground": true
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"type": "source_port",
|
|
34
|
+
"source_port_id": "source_port_3",
|
|
35
|
+
"source_component_id": "source_component_1",
|
|
36
|
+
"name": "pin3",
|
|
37
|
+
"pin_number": 3,
|
|
38
|
+
"port_hints": ["N_SHUTDOWN"],
|
|
39
|
+
"is_input": true,
|
|
40
|
+
"must_be_connected": true
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"type": "source_port",
|
|
44
|
+
"source_port_id": "source_port_4",
|
|
45
|
+
"source_component_id": "source_component_1",
|
|
46
|
+
"name": "pin4",
|
|
47
|
+
"pin_number": 4,
|
|
48
|
+
"port_hints": ["NC"],
|
|
49
|
+
"do_not_connect": true
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"type": "source_port",
|
|
53
|
+
"source_port_id": "source_port_5",
|
|
54
|
+
"source_component_id": "source_component_1",
|
|
55
|
+
"name": "pin5",
|
|
56
|
+
"pin_number": 5,
|
|
57
|
+
"port_hints": ["VOUT"],
|
|
58
|
+
"is_output": true,
|
|
59
|
+
"provides_power": true,
|
|
60
|
+
"provides_voltage": 2.8,
|
|
61
|
+
"should_have_decoupling_capacitor": true,
|
|
62
|
+
"recommended_decoupling_capacitor_capacitance": "1uF"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"pinAttributes": {
|
|
66
|
+
"pin1": {
|
|
67
|
+
"requiresPower": true,
|
|
68
|
+
"mustBeConnected": true,
|
|
69
|
+
"shouldHaveDecouplingCapacitor": true,
|
|
70
|
+
"recommendedDecouplingCapacitorCapacitance": "1uF"
|
|
71
|
+
},
|
|
72
|
+
"pin2": {
|
|
73
|
+
"requiresGround": true,
|
|
74
|
+
"mustBeConnected": true
|
|
75
|
+
},
|
|
76
|
+
"pin3": {
|
|
77
|
+
"isInput": true,
|
|
78
|
+
"mustBeConnected": true
|
|
79
|
+
},
|
|
80
|
+
"pin4": {
|
|
81
|
+
"doNotConnect": true
|
|
82
|
+
},
|
|
83
|
+
"pin5": {
|
|
84
|
+
"isOutput": true,
|
|
85
|
+
"providesPower": true,
|
|
86
|
+
"providesVoltage": 2.8,
|
|
87
|
+
"shouldHaveDecouplingCapacitor": true,
|
|
88
|
+
"recommendedDecouplingCapacitorCapacitance": "1uF"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|