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

Function doBus

tools/mcdevicetree.js:622–746  ·  view source on GitHub ↗
(state, dts, options)

Source from the content-addressed store, hash-verified

620}
621
622function doBus(state, dts, options) {
623 const nodes = getNodes(state, dts, options.binding);
624
625 state.hCode += `
626#define kModZephyr${options.name}BusCount (${nodes.length})
627`;
628
629 if (0 === nodes.length)
630 return;
631
632 let busSpecific = "";
633 if ("spi" === options.binding)
634 busSpecific = "\n struct gpio_dt_spec cs;"
635
636 state.hCode += `
637${options.header}
638
639struct modZephyr${options.name} {
640 const char *label;
641 const struct device *device;
642 uint8_t busIndex;${busSpecific}
643};
644
645extern const struct modZephyr${options.name} *modZephyrGet${options.name}(const char *label);
646
647`;
648
649 state.cCode +=`
650static const struct modZephyr${options.name} g${options.name}[] = {
651`;
652
653 nodes.forEach((node, index) => {
654 busSpecific = "";
655 if ("spi" === options.binding) {
656 const cs = node.properties["cs-gpios"]?.value?.value;
657 if (cs) {
658 busSpecific = `\n .cs.port = DEVICE_DT_GET(DT_NODELABEL(${cs[0].slice(1)})),
659 .cs.pin = ${parseInt(cs[1])},
660 .cs.dt_flags = ${parseInt(cs[2])},`;
661 }
662 }
663
664 state.cCode += ` {
665 .label = "${node.label}",
666 .device = DEVICE_DT_GET(DT_NODELABEL(${node.label})),
667 .busIndex = ${index},${busSpecific}
668 },
669`;
670 });
671
672 state.cCode += `};
673
674const struct modZephyr${options.name} *modZephyrGet${options.name}(const char *label)
675{
676 for (int i = 0; i < ARRAY_SIZE(g${options.name}); i++) {
677 if (0 == c_strcmp(g${options.name}[i].label, label))
678 return &g${options.name}[i];
679 }

Callers 1

runMethod · 0.85

Calls 2

getNodesFunction · 0.85
sliceMethod · 0.65

Tested by

no test coverage detected