| 868 | probably needs changes for non-Espressif silicon |
| 869 | */ |
| 870 | function 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 ??= {}; |
| 903 | device.network.interface ??= {}; |
| 904 | `; |
| 905 | |
| 906 | nics.forEach(nic => { |
| 907 | state.jsCode += ` |
| 908 | import ${nic.name} from "${nic.import}"; |
| 909 | device.network.interface.${nic.label} = Object.freeze({io: ${nic.name}, kind: "${nic.kind}"}); |
| 910 | |
| 911 | `; |
| 912 | |
| 913 | state.tsCode += ` |
| 914 | declare 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 | |