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

Function doGPIOs

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

Source from the content-addressed store, hash-verified

474}
475
476function doGPIOs(state, dts) {
477 if (!state.gpioBanks?.length)
478 return;
479
480 const root = dts.nodes['/'];
481 const gpios = [];
482 ["gpio-leds", "gpio-keys"].forEach(kind => {
483 for (let what in root.children) {
484 const node = root.children[what];
485 if (kind !== node.properties.compatible?.value.value)
486 continue;
487
488 for (let item in node.children) {
489 item = node.children[item];
490 const g = item.properties.gpios.value.value;
491 const bus = g[0].slice(1);
492 const labels = item.labels ?? (item.label ? [item.label] : []);
493 gpios.push({
494 kind,
495 name: item.name,
496 labels,
497 userName: item.properties?.label?.value?.value,
498 bankIndex: state.gpioBanks.indexOf(bus),
499 bus,
500 pin: parseInt(g[1]),
501 flags: parseInt(g[2])
502 });
503 }
504 return;
505 }
506 });
507
508 if (0 === gpios.length)
509 return;
510
511 state.tsCode += `
512declare module "embedded:provider/builtin" {
513 import Digital from "embedded:io/digital";
514 import DigitalBank from "embedded:io/digitalbank";
515
516 interface DeviceIO {
517 Digital: typeof Digital;
518 DigitalBank: typeof DigitalBank;
519 }
520`;
521 state.tsDeviceIO = true;
522
523 const kinds = new Set, leds = new Set, buttons = new Set;
524 gpios.forEach(gpio => {
525 let mode = [], kindName, edge;
526 if ("gpio-leds" == gpio.kind) {
527 mode.push("Digital.Output");
528 kindName = "led";
529 //@@ flags OutputOpenDrain
530 if (gpio.flags & (1 << 0)) // GPIO_ACTIVE_LOW
531 mode.push("Digital.ActiveLow");
532 leds.add(gpio.name);
533 }

Callers 1

runMethod · 0.85

Calls 5

sliceMethod · 0.65
addMethod · 0.65
getMethod · 0.65
pushMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected