From d4a16f9ddb66839d162c416d5b67a4315cd337b0 Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Tue, 18 Aug 2015 21:09:53 -0400 Subject: [PATCH] Use 0-30000 range for input reports --- n64.c | 83 +++++++++++++++++++++++++++++++++++++++------------- reportdesc.c | 13 ++++---- 2 files changed, 70 insertions(+), 26 deletions(-) diff --git a/n64.c b/n64.c index cedc1f4..54eaaf9 100644 --- a/n64.c +++ b/n64.c @@ -22,7 +22,7 @@ #include "n64.h" #include "gcn64_protocol.h" -#define GCN64_REPORT_SIZE 9 +#define GCN64_REPORT_SIZE 15 #undef BUTTON_A_RUMBLE_TEST @@ -236,31 +236,72 @@ static char n64Update(void) for (i=0; i<4; i++) // Up down left right rb2 |= btns1 & (0x08 >> i) ? (0x04<80) xval = 80; else if (xval<-80) xval = -80; + if (yval>80) yval = 80; else if (yval<-80) yval = -80; + + // Scale -80 ... +80 to -16000 ... +16000 + + xval *= 200; + yval *= 200; + yval = -yval; + + xval += 16000; + yval += 16000; + + printf("x: 0x%04x -> ", xval, yval); + + last_built_report[1] = ((uint8_t*)&xval)[0]; + last_built_report[2] = ((uint8_t*)&xval)[1]; + + last_built_report[3] = ((uint8_t*)&yval)[0]; + last_built_report[4] = ((uint8_t*)&yval)[1]; + } +#ifdef CLASSIC_MODE // Adapter V1/V2 which required calibration + if (1) { + // Convert to unsigned + x = (x ^ 0x80) - 1; + y = ((y ^ 0x80) ) ^ 0xFF; + + // The following helps a cheap TTX controller + // which uses the full 8 bit range instead + // of +/- 80. The specific test here prevents + // receiving a value of 128 (instead of -127). + // + // This will have no effect on "normal" controllers. + if (x == 0xFF) + x = 0; + + last_built_report[1] = 0; + last_built_report[2] = x; + + last_built_report[3] = 0; + last_built_report[4] = y; + } +#endif + last_built_report[5] = 0x80; + last_built_report[6] = 0x3e; + + last_built_report[7] = 0x80; + last_built_report[8] = 0x3e; + + last_built_report[9] = 0x80; + last_built_report[10] = 0x3e; + + last_built_report[11] = 0x80; + last_built_report[12] = 0x3e; // buttons - last_built_report[7] = rb1; - last_built_report[8] = rb2; + last_built_report[13] = rb1; + last_built_report[14] = rb2; return 0; } diff --git a/reportdesc.c b/reportdesc.c index 506c862..7bac34c 100644 --- a/reportdesc.c +++ b/reportdesc.c @@ -37,12 +37,15 @@ const uint8_t gcn64_usbHidReportDescriptor[] PROGMEM = { 0x09, 0x01, // usage pointer 0xA1, 0x00, // COLLECTION (phys) 0x05, 0x01, // USAGE_PAGE (Generic desktop) - 0x75, 0x08, // REPORT_SIZE (8) + 0x75, 0x10, // REPORT_SIZE (16) 0x95, 0x06, // REPORT_COUNT (6) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x26, 0xFF, 0x00, // LOGICAL_MAXIMUM (255) - 0x35, 0x00, // Physical Minimum (0) - 0x46, 0xFF, 0x00, // Physical Minimum (255) + + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x26, 0x00, 0x7D, // LOGICAL_MAXIMUM (32000) + +// 0x16, 0x00, // Physical Minimum (0) +// 0x46, 0x00, 0x7D, // Physical Maximum (32000) + 0x09, 0x30, // USAGE (X) 0x09, 0x31, // USAGE (Y) 0x09, 0x33, // USAGE (Rx)