Skip to content

Commit f822372

Browse files
committed
WIP
1 parent c896238 commit f822372

File tree

4 files changed

+74
-39
lines changed

4 files changed

+74
-39
lines changed

app/DTNode.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const meta = {
1111
baseAddr: {},
1212
compat: {},
1313
},
14-
status: { control: 'radio', options: ['okay', 'disabled'] },
14+
status: { control: 'radio', options: ['okay', 'disabled', undefined] },
1515
},
1616
} satisfies Meta<typeof DataNode>;
1717

@@ -23,6 +23,7 @@ export const Simple: Story = {
2323
data: {
2424
label: "UART",
2525
baseAddr: "0x0c00_0000",
26+
compat: "ns16550a",
2627
},
2728
status: "okay",
2829
},

app/DTNode.tsx

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
11
import { memo, useState } from "react";
22
import { Handle, NodeProps, Position } from "reactflow";
33
import compatDb from "./compat-db.json";
4+
import genericNames from "./generic-names.json";
45

56
type DTStatus = "okay" | "disabled";
67

7-
type DotColor = "blue" | "red";
8-
9-
const getDotColor = (status?: DTStatus): DotColor | null => {
10-
switch(status) {
11-
case "okay": return "blue";
12-
case "disabled": return "red";
13-
default: return null;
14-
}
15-
}
8+
const dotColors: Record<DTStatus, string> = {
9+
okay: "blue",
10+
disabled: "red"
11+
};
1612

1713
export const Dot: FC<{ status?: DTStatus }> = ({ status }) => {
1814
if (!status) {
1915
return null;
2016
}
21-
const color = getDotColor(status);
17+
const color = dotColors[status];
2218
return (
23-
<div className="dot">
19+
<div className="dot" style={{ background: color }}>
2420
<style>{`
2521
div.dot {
2622
width: 10px;
2723
height: 10px;
28-
background: ${color};
2924
border-radius: 100%;
3025
}
3126
`}</style>
3227
</div>
3328
);
3429
};
3530

36-
const docsbaseUrl = "https://docs.kernel.org"
31+
const docsBaseUrl = "https://docs.kernel.org"
32+
const drvBaseUrl = "https://elixir.bootlin.com/linux/HEAD/source/drivers";
33+
//const drvBaseUrl = "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers";
3734
const dtBaseUrl = "https://www.kernel.org/doc/Documentation/devicetree/bindings";
3835

39-
type DocsCategory = "binding" | "docs";
36+
type DocsCategory = "binding" | "docs" | "driver";
4037

4138
type DocsEntry = {
4239
category: DocsCategory;
@@ -46,7 +43,8 @@ type DocsEntry = {
4643
const getBaseUrl = (category: DocsCategory): string => {
4744
switch(category) {
4845
case "binding": return dtBaseUrl;
49-
case "docs": return docsbaseUrl;
46+
case "docs": return docsBaseUrl;
47+
case "driver": return drvBaseUrl;
5048
}
5149
};
5250

@@ -87,33 +85,47 @@ export const DataNode: FC<{ data: object; status?: DTStatus }> = ({
8785
data,
8886
status,
8987
}) => {
90-
if (!data) {
91-
return null;
92-
}
93-
88+
const extraClass = genericNames.includes(data.label) ? "generic" : "";
9489
return (
9590
<div className="node">
96-
<span>{data.label}</span>
97-
<span>{data.baseAddr}</span>
98-
<Compat compat={data.compat} />
99-
<Dot status={status} />
91+
<header className={extraClass}>{data.label}</header>
92+
<main>
93+
<span>{data.model}</span>
94+
<span>{data.baseAddr}</span>
95+
<Compat compat={data.compat} />
96+
<Dot status={status} />
97+
<span>{data.extra}</span>
98+
</main>
10099
<style>{`
101100
div.node {
102101
white-space: pre-wrap;
103-
padding: 4px;
104-
border: 2px solid #789789;
105-
background: #0c0c0c;
106-
color: #fff;
107-
width: 150px;
108-
font-size: 12px;
102+
border: 4px solid #789789;
103+
border-radius: 6px;
104+
width: 250px;
105+
font-size: 14px;
109106
font-family: "Fira Code";
110-
display: flex;
111-
flex-direction: column;
112107
}
113108
div.node:hover {
114109
border-color: #987987;
115110
border-style: dotted;
116111
}
112+
div.node header {
113+
color: #0c0c0c;
114+
background: #ccddcc;
115+
font-weight: bold;
116+
padding: 4px;
117+
}
118+
div.node header.generic {
119+
color: #fff;
120+
background: #850150;
121+
}
122+
div.node main {
123+
color: #fff;
124+
background: #0c0c0c;
125+
padding: 4px;
126+
display: flex;
127+
flex-direction: column;
128+
}
117129
`}</style>
118130
</div>
119131
);

app/compat-db.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
"category": "binding",
2828
"path": "arm/cpus.yaml"
2929
},
30+
"arm,cortex-a7-pmu": {
31+
"category": "binding",
32+
"path": "arm/pmu.yaml"
33+
},
3034
"brcm,bcm2835-cprman": {
3135
"category": "binding",
3236
"path": "clock/brcm,bcm2835-cprman.txt"
@@ -38,5 +42,9 @@
3842
"spidev": {
3943
"category": "docs",
4044
"path": "spi/spidev.html"
45+
},
46+
"brcm,bcm2835-audio": {
47+
"category": "driver",
48+
"path": "staging/vc04_services/bcm2835-audio/bcm2835.c"
4149
}
4250
}

app/lib.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ const getPropStr = (n: DTNode, pname: string): string | null => {
6666
return p ? p.join(", ") : null;
6767
};
6868

69+
const getExtra = (n: DTNode) => {
70+
if (n.name === "aliases" | n.name === "chosen") {
71+
const ps = n.props.map((p) => {
72+
const [k, v] = p;
73+
return `${k}=${u8ArrToStr(v)}`;
74+
});
75+
return ps.join("\n");
76+
}
77+
return null;
78+
};
79+
6980
// transform a node's props into numbers and strings, omitting many
7081
const transformNode = (n: DTNode): DTNode => {
7182
const name = n.name || "root";
@@ -81,6 +92,8 @@ const transformNode = (n: DTNode): DTNode => {
8192
const cnames = getStringProp(n, "clock-names");
8293
const compat = getStringProp(n, "compatible");
8394
const status = getStringProp(n, "status");
95+
const model = getStringProp(n, "model");
96+
const extra = getExtra(n);
8497
return {
8598
name,
8699
...(phandle ? { phandle: phandle[0] } : null),
@@ -92,6 +105,8 @@ const transformNode = (n: DTNode): DTNode => {
92105
...(cnames ? { cnames } : null),
93106
...(compat ? { compat } : null),
94107
...(status ? { status } : null),
108+
...(model ? { model } : null),
109+
extra,
95110
};
96111
};
97112

@@ -103,7 +118,7 @@ export const transform = (n: DTNode, id: string = "10000") => {
103118
}
104119
};
105120

106-
const NODE_WIDTH = 160;
121+
const NODE_WIDTH = 260;
107122
const NODE_HEIGHT = 80;
108123

109124
const weightedNode = (node: DTNode): DTNode => {
@@ -142,22 +157,21 @@ export const getNodesEdges = (tree: DTNode) => {
142157
const nodes: TransformedNode[] = [];
143158
const edges: TransformedEdge[] = [];
144159
const rec = (n: DTNode, d: number = 1, baseX: number = 0, baseY: number = 0) => {
145-
const [name, addr] = n.name.split("@");
160+
const { id, name, ...data } = n;
161+
const [label, addr] = name.split("@");
146162
const baseAddr = transformAddr(addr);
147163

148164
nodes.push({
149-
id: n.id,
165+
id,
150166
type: NodeType.custom,
151167
position: {
152168
x: baseX + n.size * NODE_WIDTH / 2,
153169
y: baseY + d * NODE_HEIGHT,
154170
},
155171
data: {
156-
label: name,
172+
label,
157173
baseAddr,
158-
size: n.size,
159-
compat: n.compat,
160-
status: n.status,
174+
...data,
161175
},
162176
});
163177
let offset = baseX;

0 commit comments

Comments
 (0)