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

Function doGPIOBanks

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

Source from the content-addressed store, hash-verified

410}
411
412function doGPIOBanks(state, dts) {
413 const gpios = getNodes(state, dts, "gpio");
414
415 state.hCode += `
416#define kModZephyrGPIOBankCount (${gpios.length})
417`;
418
419 if (0 === gpios.length)
420 return;
421
422 state.hCode += `
423#include <zephyr/drivers/gpio.h>
424
425struct modZephyrGPIOBank {
426 const char *label;
427 const struct device *device;
428 uint8_t bankIndex;
429 uint8_t gpioCount;
430};
431
432extern const struct modZephyrGPIOBank *modZephyrGetGPIOBank(const char *label);
433
434`;
435
436 state.gpioBanks = [];
437 state.cCode +=`
438static const struct modZephyrGPIOBank gGPIOBank[] = {
439`;
440
441 gpios.forEach((gpio, bankIndex) => {
442 const ngpios = gpio.properties?.ngpios?.value.value[0];
443 state.cCode += ` {
444 .label = "${gpio.label}",
445 .device = DEVICE_DT_GET(DT_NODELABEL(${gpio.label})),
446 .bankIndex = ${bankIndex},
447 .gpioCount = ${ngpios ? parseInt(ngpios) : "GPIO_MAX_PINS_PER_PORT"}
448 },
449`;
450 state.gpioBanks.push(gpio.label);
451 });
452
453 state.cCode += `};
454
455const struct modZephyrGPIOBank *modZephyrGetGPIOBank(const char *label)
456{
457 for (int i = 0; i < ARRAY_SIZE(gGPIOBank); i++) {
458 if (0 == c_strcmp(gGPIOBank[i].label, label))
459 return &gGPIOBank[i];
460 }
461
462 return C_NULL;
463}
464`;
465
466 state.jsCode += `
467import Digital from "embedded:io/digital";
468device.io.Digital = Digital;
469

Callers 1

runMethod · 0.85

Calls 2

getNodesFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected