aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/src/components/interconnect-tabs.tsx
blob: 8a7a0a4e38e51a72736b1fd7911eddf83bf87c22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

import { HardwareMetadata, Interconnect } from "../hardware-metadata";
import { groupedMetadata, InterconnectDetails } from "./hardware-utils";

interface InterconnectTabsProps {
  items: HardwareMetadata[];
}

function mapInterconnect(interconnect: Interconnect) {
  let content = require(`@site/src/data/interconnects/${interconnect.id}/design_guideline.md`);
  let imageUrl = require(`@site/docs/assets/interconnects/${interconnect.id}/pinout.png`);

  return (
    <TabItem value={interconnect.id} key={interconnect.id}>
      <img src={imageUrl.default} />

      <content.default />

      {interconnect.node_labels && (
        <>
          The following node labels are available:
          <ul>
            <li>
              GPIO: <code>&{interconnect.node_labels.gpio}</code>
            </li>
            {interconnect.node_labels.i2c && (
              <li>
                I2C bus: <code>&{interconnect.node_labels.i2c}</code>
              </li>
            )}
            {interconnect.node_labels.spi && (
              <li>
                SPI bus: <code>&{interconnect.node_labels.spi}</code>
              </li>
            )}
            {interconnect.node_labels.uart && (
              <li>
                UART: <code>&{interconnect.node_labels.uart}</code>
              </li>
            )}
            {interconnect.node_labels.adc && (
              <li>
                ADC: <code>&{interconnect.node_labels.adc}</code>
              </li>
            )}
          </ul>
        </>
      )}
    </TabItem>
  );
}

function mapInterconnectValue(interconnect: Interconnect) {
  return { label: `${interconnect.name} Shields`, value: interconnect.id };
}

function InterconnectTabs({ items }: InterconnectTabsProps) {
  let grouped = Object.values(groupedMetadata(items).interconnects)
    .map((i) => i?.interconnect as Interconnect)
    .filter((i) => i?.design_guideline)
    .sort((a, b) => a.id.localeCompare(b.id));

  return (
    <Tabs defaultValue={"pro_micro"} values={grouped.map(mapInterconnectValue)}>
      {grouped.map(mapInterconnect)}
    </Tabs>
  );
}

export default InterconnectTabs;