libdragon icon indicating copy to clipboard operation
libdragon copied to clipboard

Joypad APIs for individual buttons

Open meeq opened this issue 3 weeks ago • 0 comments

Introduces convenience functions to assist with dynamic button mapping.

  • Adds joypad_button_t enum to joypad.h: Button constants mapped to bit positions 0-15
  • Adds accessor functions for getting individual buttons using joypad_button_t:
    • joypad_get_button(port, button): current state
    • joypad_get_button_pressed(port, button): just pressed this frame
    • joypad_get_button_released(port, button): just released this frame
    • joypad_get_button_held(port, button): held across frames
  • Adds joypad_get_axis function for dynamic analog mapping

Example usage:

struct InputMap {
  joypad_button_t jump;
  joypad_button_t attack;
}

struct InputMap inputMap = {
  .jump = JOYPAD_BUTTON_A,
  .attack = JOYPAD_BUTTON_B
};

bool jumping = joypad_get_button_pressed(port, inputMap.jump);
bool attacking = joypad_get_button_pressed(port, inputMap.attack);

meeq avatar Dec 16 '25 19:12 meeq