Compare commits

...

20 commits

Author SHA1 Message Date
Limor "Ladyada" Fried
40ed46a3a1
Merge pull request #4 from adafruit/gamepad_gb
Some checks failed
Build mcume / bins (push) Has been cancelled
add usb gamepad to gameboy emulator
2025-04-09 11:58:58 -04:00
Liz
8deda0cbe4 up, down, left and right working, try a, b 2025-04-08 16:02:12 -04:00
Liz
5434e35f39 off by 1? 2025-04-08 15:51:42 -04:00
Liz
a5a4294f9c Update hid_app.c 2025-04-08 15:40:15 -04:00
Liz
547136cf39 Revert "Update hid_app.c"
This reverts commit ff4dc4d916.
2025-04-08 14:32:05 -04:00
Liz
ff4dc4d916 Update hid_app.c 2025-04-08 12:37:29 -04:00
Liz
a1f85ec1b8 Update hid_app.c 2025-04-08 12:24:53 -04:00
Liz
29c62811f0 left/right 2025-04-08 12:09:23 -04:00
Liz
054436b8ce mapping update 2025-04-08 11:59:41 -04:00
Liz
858205c3dc invert mappings 2025-04-08 11:50:20 -04:00
Liz
44fa2b265d progress, swap up/down; map to gameboy buttons 2025-04-08 11:35:09 -04:00
Liz
d8462656c8 try hid_app instead 2025-04-08 11:20:26 -04:00
Liz
d9a62efb62 Revert "try to add usb gamepad to gameboy emulator"
This reverts commit 9843fdf625.
2025-04-08 11:16:20 -04:00
Liz
561c082fd4 Revert "move kbd_signal_raw_key"
This reverts commit dfadcf2f8d.
2025-04-08 11:16:15 -04:00
Liz
6f72a4fd1f Revert "change bool to void"
This reverts commit cd50ce6db7.
2025-04-08 11:16:11 -04:00
Liz
ff06fe5494 Revert "remove returns"
This reverts commit f9c0a1628d.
2025-04-08 11:16:01 -04:00
Liz
f9c0a1628d remove returns 2025-04-08 11:12:36 -04:00
Liz
cd50ce6db7 change bool to void 2025-04-08 11:10:15 -04:00
Liz
dfadcf2f8d move kbd_signal_raw_key 2025-04-08 11:05:10 -04:00
Liz
9843fdf625 try to add usb gamepad to gameboy emulator 2025-04-08 11:00:32 -04:00

View file

@ -373,56 +373,50 @@ static void process_kbd_report (hid_keyboard_report_t const *report)
}
prev_report = *report;
}
// this mapping is hard coded for a certain snes-style gamepad and picogb!
static void process_gamepad_report (const uint8_t *report) {
uint16_t decoded_report = 0;
// X coordinate
if (report[0] == 0) {
decoded_report |= MASK_JOY2_RIGHT;
} else if(report[0] == 0xff) {
decoded_report |= MASK_JOY2_LEFT;
}
static void process_gamepad_report(const uint8_t *report) {
uint16_t decoded_report = 0;
// Y coordinate
if (report[1] == 0) {
decoded_report |= MASK_JOY2_UP;
} else if(report[1] == 0xff) {
decoded_report |= MASK_JOY2_DOWN;
}
// Directional Controls
// Left is when byte 2 is close to 0x00
if (report[0] < 0x40) {
decoded_report |= MASK_JOY2_RIGHT; // Note: swapped due to gameboy mapping
}
// Right is when byte 2 is close to 0xFF
if (report[0] > 0xB0) {
decoded_report |= MASK_JOY2_LEFT; // Note: swapped due to gameboy mapping
}
// Up is when byte 1 is close to 0x00
if (report[1] < 0x40) {
decoded_report |= MASK_JOY2_UP;
}
// Down is when byte 1 is close to 0xFF
if (report[1] > 0xB0) {
decoded_report |= MASK_JOY2_DOWN;
}
// X A B Y = top bits of byte 5 . Let's just have X/Y double A/B
if (report[5] & 0x10) {
decoded_report |= MASK_JOY2_BTN; // X
}
if (report[5] & 0x20) {
decoded_report |= MASK_KEY_USER3; // A -- this is picogb numbering
}
if (report[5] & 0x40) {
decoded_report |= MASK_JOY2_BTN; // B
}
if (report[5] & 0x80) {
decoded_report |= MASK_KEY_USER3; // Y
}
// A Button (check for 0x2F or 0x1F in byte 6)
if ((report[5] & 0x20) || (report[5] & 0x10)) {
decoded_report |= MASK_KEY_USER3;
}
// SELECT START = top bits of byte 6
if (report[6] & 0x10) {
decoded_report |= MASK_KEY_USER1; // SELECT
}
if (report[6] & 0x20) {
decoded_report |= MASK_KEY_USER2; // START
}
// B Button (check for 0x4F or 0x8F in byte 6)
if ((report[5] & 0x40) || (report[5] & 0x80)) {
decoded_report |= MASK_JOY2_BTN;
}
// Decode shoulder buttons into B/A too
if (report[6] & 0x1) {
decoded_report |= MASK_JOY2_BTN; // B
}
if (report[6] & 0x2) {
decoded_report |= MASK_KEY_USER3; // Y
}
kbd_signal_raw_gamepad(decoded_report);
// Select Button (byte 7, bit 0x10)
if (report[6] & 0x10) {
decoded_report |= MASK_KEY_USER1;
}
// Start Button (byte 7, bit 0x20)
if (report[6] & 0x20) {
decoded_report |= MASK_KEY_USER2;
}
// Send the decoded gamepad state
kbd_signal_raw_gamepad(decoded_report);
}
//--------------------------------------------------------------------+
@ -487,10 +481,10 @@ int proto = tuh_hid_interface_protocol (dev_addr, instance);
process_kbd_report ((hid_keyboard_report_t const*) report);
break;
case HID_ITF_PROTOCOL_NONE:
if (len == 8) {
process_gamepad_report (report);
}
break;
if (len >= 8) {
process_gamepad_report(report);
}
break;
#if 0 // you get to implement it, hoss!
case HID_ITF_PROTOCOL_MOUSE:
printf("MOUSE len=%d\n", len);