Update hid_app.c

This commit is contained in:
Liz 2025-04-08 12:37:29 -04:00
parent a1f85ec1b8
commit ff4dc4d916

View file

@ -375,45 +375,64 @@ static void process_kbd_report (hid_keyboard_report_t const *report)
} }
static void process_gamepad_report(const uint8_t *report) { static void process_gamepad_report(const uint8_t *report) {
// Print the first few bytes of the report for debugging
printf("GP: %02x %02x %02x %02x %02x %02x %02x %02x\n",
report[0], report[1], report[2], report[3],
report[4], report[5], report[6], report[7]);
uint16_t decoded_report = 0; uint16_t decoded_report = 0;
// Directional Controls // Directional Controls
// Left is when byte 2 is close to 0x00 // Check both bytes 1 and 2 for each direction
if (report[2] < 0x40) { // LEFT: byte 2 is 0x00 and byte 1 is 0x7F
decoded_report |= MASK_JOY2_RIGHT; // Note: swapped due to gameboy mapping if (report[2] == 0x00 && report[1] == 0x7F) {
decoded_report |= MASK_JOY2_LEFT;
} }
// Right is when byte 2 is close to 0xFF // RIGHT: byte 2 is 0xFF and byte 1 is 0x7F
if (report[2] > 0xB0) { if (report[2] == 0xFF && report[1] == 0x7F) {
decoded_report |= MASK_JOY2_LEFT; // Note: swapped due to gameboy mapping decoded_report |= MASK_JOY2_RIGHT;
} }
// Up is when byte 1 is close to 0x00 // UP: byte 1 is 0x00 and byte 2 is 0x7F
if (report[1] < 0x40) { if (report[1] == 0x00 && report[2] == 0x7F) {
decoded_report |= MASK_JOY2_UP; decoded_report |= MASK_JOY2_UP;
} }
// Down is when byte 1 is close to 0xFF // DOWN: byte 1 is 0xFF and byte 2 is 0x7F
if (report[1] > 0xB0) { if (report[1] == 0xFF && report[2] == 0x7F) {
decoded_report |= MASK_JOY2_DOWN; decoded_report |= MASK_JOY2_DOWN;
} }
// A Button (check for 0x2F or 0x1F in byte 6) // A button -> maps to MASK_KEY_USER3 (byte 6 is 0x2F)
if ((report[6] & 0x20) || (report[6] & 0x10)) { if (report[6] == 0x2F) {
decoded_report |= MASK_KEY_USER3; decoded_report |= MASK_KEY_USER3;
} }
// B Button (check for 0x4F or 0x8F in byte 6) // B button -> maps to MASK_JOY2_BTN (byte 6 is 0x4F or 0x8F)
if ((report[6] & 0x40) || (report[6] & 0x80)) { if ((report[6] == 0x4F) || (report[6] == 0x8F)) {
decoded_report |= MASK_JOY2_BTN; decoded_report |= MASK_JOY2_BTN;
} }
// Select Button (byte 7, bit 0x10) // X button (debugging) (byte 6 is 0x1F)
if (report[7] & 0x10) { if (report[6] == 0x1F) {
printf("X button pressed\n");
}
// Y button (debugging) (byte 6 is 0x8F)
if (report[6] == 0x8F) {
printf("Y button pressed\n");
}
// Start button -> maps to MASK_KEY_USER2 (byte 7 is 0x20)
if (report[7] == 0x20) {
decoded_report |= MASK_KEY_USER2;
}
// Select button -> maps to MASK_KEY_USER1 (byte 7 is 0x10)
if (report[7] == 0x10) {
decoded_report |= MASK_KEY_USER1; decoded_report |= MASK_KEY_USER1;
} }
// Start Button (byte 7, bit 0x20) // Additional debug for button mappings
if (report[7] & 0x20) { printf("Decoded report: %04x\n", decoded_report);
decoded_report |= MASK_KEY_USER2;
}
// Send the decoded gamepad state // Send the decoded gamepad state
kbd_signal_raw_gamepad(decoded_report); kbd_signal_raw_gamepad(decoded_report);