====== std.hardware.gpio_mmio ====== Der **direkte Registerzugriff** auf den GPIO-Block des BCM2711 (Raspberry Pi 4). Die Unit bildet den Peripheriebereich einmal per ''mmap'' in den Prozess ein; danach kostet jedes Setzen oder Lesen eines Pins **keinen Syscall mehr**, sondern nur einen Speicherzugriff. Das ist der Weg für Bit-Bang-Protokolle und Software-PWM, wo jede Mikrosekunde zählt. Der Kontext (''GpioCtxAlloc'') ist ein 24-Byte-Block mit drei Feldern: Basisadresse der Abbildung, ein Flag ob sie steht, und ob der Chip die neue Pull-Up/Down-Registerform kennt. Er gehört mit ''GpioClose'' geschlossen und mit ''GpioCtxFree'' freigegeben — in dieser Reihenfolge. **Rechte:** ''GpioInit'' öffnet ''/dev/gpiomem'' bzw. ''/dev/mem'' und braucht entsprechende Rechte. Wer ohne sie startet, bekommt einen Fehler zurück — kein Absturz. [[lyx_-_programmiersprache:units:hardware:gpio|std.hardware.gpio — Übersicht]] · [[lyx_-_programmiersprache:guides:gpio|GPIO-Guide]] · [[lyx_-_programmiersprache:units|Standard Library]] ---- ===== Schnittstelle ===== ^ Signatur ^ | ''GpioCtxAlloc(): int64'' | | ''GpioCtxFree(ctx: int64)'' | | ''GpioGetMem(ctx: int64): int64'' | | ''GpioIsMapped(ctx: int64): int64'' | | ''GpioHasNewPull(ctx: int64): int64'' | | ''GpioInit(ctx: int64): int64'' | | ''GpioClose(ctx: int64)'' | | ''GpioSetPinMode(ctx: int64, pin: int64, mode: int64): int64'' | | ''GpioWritePin(ctx: int64, pin: int64, state: int64): int64'' | | ''GpioReadPin(ctx: int64, pin: int64): int64'' | | ''GpioSetPullMode(ctx: int64, pin: int64, mode: int64): int64'' | ^ Konstante ^ Wert ^ Bedeutung ^ | ''GPIO_CTX_SIZE'' | ''24'' | – | | ''GPIO_PIN_INPUT'' | ''0'' | RPI4_MODE_INPUT | | ''GPIO_PIN_OUTPUT'' | ''1'' | RPI4_MODE_OUTPUT | | ''GPIO_PIN_LOW'' | ''0'' | – | | ''GPIO_PIN_HIGH'' | ''1'' | – | | ''GPIO_PULL_NONE'' | ''0'' | – | | ''GPIO_PULL_DOWN'' | ''1'' | – | | ''GPIO_PULL_UP'' | ''2'' | – | ---- ===== Zusammenspiel ===== ''gpio_mmio'' liefert die rohe Ebene. Darüber liegen [[lyx_-_programmiersprache:units:hardware:gpio_pin|std.hardware.gpio_pin]] (typsichere Ein-/Ausgabe-Pins) und [[lyx_-_programmiersprache:units:hardware:gpio_ext|std.hardware.gpio_ext]] (Alt-Modi, Edge-Detection, Software-PWM). Wer mehrere Pins **atomar** schalten oder auf Flanken warten will, ist mit [[lyx_-_programmiersprache:units:hardware:gpio_ioctl|std.hardware.gpio_ioctl]] besser bedient. Quelle: ''std/hardware/gpio_mmio.lyx'' · geprüft mit ''lyxc 1.0.21A'' · Stand 2026-08-12 ---- Letzte Aktualisierung: 2026-08-16 (Dateistand)