MCPcopy Index your code
hub / github.com/Moddable-OpenSource/moddable / doNetworkInterfaces

Function doNetworkInterfaces

tools/mcdevicetree.js:870–925  ·  view source on GitHub ↗
(state, dts)

Source from the content-addressed store, hash-verified

868 probably needs changes for non-Espressif silicon
869*/
870function doNetworkInterfaces(state, dts) {
871 const root = dts.nodes['/'];
872 const nics = [];
873
874 if (root.children.wifi && ("y" === state.zephyrConfig.get("CONFIG_WIFI"))) {
875 const status = root.children.wifi.properties.status?.value?.value ?? "okay";
876 if ("okay" === status) {
877 nics.push({
878 label: root.children.wifi.label,
879 kind: "wifi",
880 name: `WiFi`,
881 import: "embedded:network/interface/wifi",
882 });
883 }
884 }
885
886 if (root.children.eth && ("y" === state.zephyrConfig.get("CONFIG_NET_L2_ETHERNET"))) {
887 const status = root.children.wifi.properties.status?.value?.value ?? "okay";
888 if ("okay" === status) {
889 nics.push({
890 label: root.children.eth.label,
891 kind: "ethernet",
892 name: `Ethernet`,
893 import: "embedded:network/interface/ethernet",
894 });
895 }
896 }
897
898 if (0 === nics.length)
899 return;
900
901 state.jsCode +=
902`device.network ??= {};
903device.network.interface ??= {};
904`;
905
906 nics.forEach(nic => {
907 state.jsCode += `
908import ${nic.name} from "${nic.import}";
909device.network.interface.${nic.label} = Object.freeze({io: ${nic.name}, kind: "${nic.kind}"});
910
911`;
912
913 state.tsCode += `
914declare module "embedded:provider/builtin" {
915 import ${nic.name} from "${nic.import}";
916 import type {PortSpecifier} from "embedded:io/_common";
917
918 interface DeviceNetworkInterface {
919 ${nic.label}: {io: typeof ${nic.name}, kind: string, port: PortSpecifier};
920 }
921}
922`;
923 });
924 state.tsDeviceNetworkInterface = true;
925}
926
927

Callers 1

runMethod · 0.85

Calls 2

getMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected