code wiki / (root) / nx_input_gpio.nx

nx_input_gpio.nx

buildroot/runtime/nx_input_gpio.nx

5304 B154 linesdepth 2pulls 2 transitivereach 4 importersview sourcekind librarytopic input
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_tier.nx nx_input_gpio.nx nx_game_engine_compose_test.nx nx_game_session_drive.nx nx_input_gpio_test.nx nx_minecraft_mcu_compose_test.nx

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

43struct NxButtonState
50struct NxInputGpio

consts

22const NX_BTN_UP: nx_int = 0
23const NX_BTN_DOWN: nx_int = 1
24const NX_BTN_LEFT: nx_int = 2
25const NX_BTN_RIGHT: nx_int = 3
26const NX_BTN_ACTION_A: nx_int = 4
27const NX_BTN_ACTION_B: nx_int = 5
28const NX_BTN_N_BUTTONS: nx_int = 6
32const NX_BE_NONE: nx_int = 0
33const NX_BE_PRESSED: nx_int = 1 // rising edge: was OFF, now ON
34const NX_BE_RELEASED: nx_int = 2 // falling edge: was ON, now OFF
35const NX_BE_HELD: nx_int = 3 // ON for held_threshold_us
36const NX_BE_N_EDGES: nx_int = 4
38const NX_GPIO_OK: nx_int = 0
39const NX_GPIO_ERR_BAD_BTN: nx_int = 1
56const NX_BTN_STATE_BYTES: nx_size = 32
57const NX_GPIO_DEBOUNCE_DEFAULT_US: nx_size = 20000 // 20ms
58const NX_GPIO_HELD_DEFAULT_US: nx_size = 500000 // 500ms

functions

60func nx_btn_is_valid(b: nx_int) -> nx_int
66func nx_be_edge_is_valid(e: nx_int) -> nx_int
called by 1: main
72func nx_input_gpio_new(debounce_us: nx_size, held_threshold_us: nx_size) -> *NxInputGpio
called by 3: mainmainmain calls 1: sys_mmap
90func _gpio_state(g: *NxInputGpio, button: nx_int) -> *NxButtonState
100func nx_input_gpio_poll(g: *NxInputGpio,
138func nx_input_gpio_is_pressed(g: *NxInputGpio, button: nx_int) -> nx_int
149func nx_input_gpio_held_us(g: *NxInputGpio, button: nx_int, now_us: nx_size) -> nx_size
called by 1: main calls 2: nx_btn_is_valid_gpio_state