| 410 | } |
| 411 | |
| 412 | function 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 | |
| 425 | struct modZephyrGPIOBank { |
| 426 | const char *label; |
| 427 | const struct device *device; |
| 428 | uint8_t bankIndex; |
| 429 | uint8_t gpioCount; |
| 430 | }; |
| 431 | |
| 432 | extern const struct modZephyrGPIOBank *modZephyrGetGPIOBank(const char *label); |
| 433 | |
| 434 | `; |
| 435 | |
| 436 | state.gpioBanks = []; |
| 437 | state.cCode +=` |
| 438 | static 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 | |
| 455 | const 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 += ` |
| 467 | import Digital from "embedded:io/digital"; |
| 468 | device.io.Digital = Digital; |
| 469 | |