nx_input_gpio.nx
buildroot/runtime/nx_input_gpio.nx
about
nx_input_gpio.nx -- GPIO button input abstraction.
4-button input (UP/DOWN/LEFT/RIGHT or W/A/S/D pattern). Substrate
layer is OS-binding-free; the integration layer wires
/sys/class/gpio (Linux) or Arduino digitalRead (ESP32). This
primitive provides the debounce + edge-detection logic so the
integration layer just hands raw raw bits.
Per nx_brane CAP_HARDWARE_IO: input poller requires that capability
token granted; refuses to read GPIO without it.
Composes:
nx_brane -- CAP_HARDWARE_IO check
nx_clock -- monotonic clock for debounce
nx_raycast_voxel -- input drives camera direction
dependencies 2 imports · 4 importers
imports: nx_syscalls.nxnx_tier.nx
imported by: nx_game_engine_compose_test.nxnx_game_session_drive.nxnx_input_gpio_test.nxnx_minecraft_mcu_compose_test.nx
structs
| 43 | struct NxButtonState |
| 50 | struct NxInputGpio |
consts
| 22 | const NX_BTN_UP: nx_int = 0 |
| 23 | const NX_BTN_DOWN: nx_int = 1 |
| 24 | const NX_BTN_LEFT: nx_int = 2 |
| 25 | const NX_BTN_RIGHT: nx_int = 3 |
| 26 | const NX_BTN_ACTION_A: nx_int = 4 |
| 27 | const NX_BTN_ACTION_B: nx_int = 5 |
| 28 | const NX_BTN_N_BUTTONS: nx_int = 6 |
| 32 | const NX_BE_NONE: nx_int = 0 |
| 33 | const NX_BE_PRESSED: nx_int = 1 // rising edge: was OFF, now ON |
| 34 | const NX_BE_RELEASED: nx_int = 2 // falling edge: was ON, now OFF |
| 35 | const NX_BE_HELD: nx_int = 3 // ON for held_threshold_us |
| 36 | const NX_BE_N_EDGES: nx_int = 4 |
| 38 | const NX_GPIO_OK: nx_int = 0 |
| 39 | const NX_GPIO_ERR_BAD_BTN: nx_int = 1 |
| 56 | const NX_BTN_STATE_BYTES: nx_size = 32 |
| 57 | const NX_GPIO_DEBOUNCE_DEFAULT_US: nx_size = 20000 // 20ms |
| 58 | const NX_GPIO_HELD_DEFAULT_US: nx_size = 500000 // 500ms |
functions
| 60 | func nx_btn_is_valid(b: nx_int) -> nx_int |
| 66 | func nx_be_edge_is_valid(e: nx_int) -> nx_int called by 1: main |
| 72 | func nx_input_gpio_new(debounce_us: nx_size, held_threshold_us: nx_size) -> *NxInputGpio |
| 90 | func _gpio_state(g: *NxInputGpio, button: nx_int) -> *NxButtonState |
| 100 | func nx_input_gpio_poll(g: *NxInputGpio, |
| 138 | func nx_input_gpio_is_pressed(g: *NxInputGpio, button: nx_int) -> nx_int |
| 149 | func nx_input_gpio_held_us(g: *NxInputGpio, button: nx_int, now_us: nx_size) -> nx_size |