From 52eea713be6726c5047ec67458e078235b04d70b Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Fri, 5 Mar 2021 13:37:24 +0900 Subject: [PATCH] Version 3.6.1 --- changelog.txt | 10 +++++++++- config.c | 1 + config.h | 9 +++++---- requests.h | 2 ++ usbpad.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/changelog.txt b/changelog.txt index 39bf191..a4c854b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,7 +1,15 @@ -- Next release +- Future ideas / TODO - Add very basic N64 mouse support (detect and treat it like a controller) - Add support for Atmega32u4 MCU +- March 5, 2021 : Version 3.6.1 + - Alter timing so the brawler64 wireless gamepad will work. Those will now + work with a poll interval >= 2ms on single port adapters, and >= 4ms on dual + port adapters. + - Add a feature to swap the main analog stick and the D-Pad + - Save memory in usb.c (no user visible effects) + - Correct bootloader entry address (*maybe* less chances of failing) + - November 6, 2018 : Version 3.6.0 - Add gamecube keyboard support diff --git a/config.c b/config.c index e83bd5a..4eb8dba 100644 --- a/config.c +++ b/config.c @@ -52,6 +52,7 @@ static struct paramAndFlag paramsAndFlags[] = { { CFG_PARAM_FULL_SLIDERS, FLAG_GC_FULL_SLIDERS }, { CFG_PARAM_TRIGGERS_AS_BUTTONS, FLAG_GC_SLIDERS_AS_BUTTONS }, { CFG_PARAM_DISABLE_ANALOG_TRIGGERS, FLAG_DISABLE_ANALOG_TRIGGERS }, + { CFG_PARAM_SWAP_STICK_AND_DPAD, FLAG_SWAP_STICK_AND_DPAD }, { }, }; diff --git a/config.h b/config.h index dd27d20..70c182f 100644 --- a/config.h +++ b/config.h @@ -10,10 +10,11 @@ struct eeprom_cfg { uint32_t flags; }; -#define FLAG_GC_FULL_SLIDERS 1 -#define FLAG_GC_INVERT_TRIGS 2 -#define FLAG_GC_SLIDERS_AS_BUTTONS 4 -#define FLAG_DISABLE_ANALOG_TRIGGERS 8 +#define FLAG_GC_FULL_SLIDERS 0x01 +#define FLAG_GC_INVERT_TRIGS 0x02 +#define FLAG_GC_SLIDERS_AS_BUTTONS 0x04 +#define FLAG_DISABLE_ANALOG_TRIGGERS 0x08 +#define FLAG_SWAP_STICK_AND_DPAD 0x10 void eeprom_app_write_defaults(void); void eeprom_app_ready(void); diff --git a/requests.h b/requests.h index db0eb35..5f12383 100644 --- a/requests.h +++ b/requests.h @@ -47,6 +47,8 @@ #define CFG_PARAM_INVERT_TRIG 0x24 #define CFG_PARAM_TRIGGERS_AS_BUTTONS 0x25 +#define CFG_PARAM_DPAD_AS_AXES 0x31 #define CFG_PARAM_DISABLE_ANALOG_TRIGGERS 0x32 +#define CFG_PARAM_SWAP_STICK_AND_DPAD 0x34 #endif diff --git a/usbpad.c b/usbpad.c index f71bb0d..6c0caea 100644 --- a/usbpad.c +++ b/usbpad.c @@ -27,6 +27,8 @@ #include "hid_keycodes.h" #include "gc_kb.h" +#define STICK_TO_BTN_THRESHOLD 40 + #define REPORT_ID 1 // Output Report IDs for various functions @@ -140,6 +142,24 @@ static void buildReportFromGC(const gc_pad_data *gc_data, unsigned char dstbuf[U ltrig = gc_data->lt; rtrig = gc_data->rt; + if (g_eeprom_data.cfg.flags & FLAG_SWAP_STICK_AND_DPAD) { + + // Generate new D-Pad button status based on stick + gcbuttons &= ~(GC_BTN_DPAD_UP|GC_BTN_DPAD_DOWN|GC_BTN_DPAD_LEFT|GC_BTN_DPAD_RIGHT); + if (xval <= -STICK_TO_BTN_THRESHOLD) { gcbuttons |= GC_BTN_DPAD_LEFT; } + if (xval >= STICK_TO_BTN_THRESHOLD) { gcbuttons |= GC_BTN_DPAD_RIGHT; } + if (yval <= -STICK_TO_BTN_THRESHOLD) { gcbuttons |= GC_BTN_DPAD_DOWN; } + if (yval >= STICK_TO_BTN_THRESHOLD) { gcbuttons |= GC_BTN_DPAD_UP; } + + // Generate new stick values based on button (use gc_data here) + xval = 0; yval = 0; + if (gc_data->buttons & GC_BTN_DPAD_UP) { yval = 100; } + if (gc_data->buttons & GC_BTN_DPAD_DOWN) { yval = -100; } + if (gc_data->buttons & GC_BTN_DPAD_LEFT) { xval = -100; } + if (gc_data->buttons & GC_BTN_DPAD_RIGHT) { xval = 100; } + } + + /* Scale -100 ... + 1000 to -16000 ... +16000 */ xval *= 160; yval *= -160; @@ -212,15 +232,33 @@ static void buildReportFromGC(const gc_pad_data *gc_data, unsigned char dstbuf[U btnsToReport(buttons, dstbuf+13); } + static void buildReportFromN64(const n64_pad_data *n64_data, unsigned char dstbuf[USBPAD_REPORT_SIZE]) { int16_t xval, yval; - uint16_t buttons; + uint16_t usb_buttons, n64_buttons = n64_data->buttons; /* Force official range */ xval = minmax(n64_data->x, -80, 80); yval = minmax(n64_data->y, -80, 80); + if (g_eeprom_data.cfg.flags & FLAG_SWAP_STICK_AND_DPAD) { + + // Generate new D-Pad button status based on stick + n64_buttons &= ~(N64_BTN_DPAD_UP|N64_BTN_DPAD_DOWN|N64_BTN_DPAD_LEFT|N64_BTN_DPAD_RIGHT); + if (xval <= -STICK_TO_BTN_THRESHOLD) { n64_buttons |= N64_BTN_DPAD_LEFT; } + if (xval >= STICK_TO_BTN_THRESHOLD) { n64_buttons |= N64_BTN_DPAD_RIGHT; } + if (yval <= -STICK_TO_BTN_THRESHOLD) { n64_buttons |= N64_BTN_DPAD_DOWN; } + if (yval >= STICK_TO_BTN_THRESHOLD) { n64_buttons |= N64_BTN_DPAD_UP; } + + // Generate new stick values based on button (use n64_data here) + xval = 0; yval = 0; + if (n64_data->buttons & N64_BTN_DPAD_UP) { yval = 80; } + if (n64_data->buttons & N64_BTN_DPAD_DOWN) { yval = -80; } + if (n64_data->buttons & N64_BTN_DPAD_LEFT) { xval = -80; } + if (n64_data->buttons & N64_BTN_DPAD_RIGHT) { xval = 80; } + } + /* Scale -80 ... +80 to -16000 ... +16000 */ xval *= 200; yval *= 200; @@ -235,8 +273,8 @@ static void buildReportFromN64(const n64_pad_data *n64_data, unsigned char dstbu dstbuf[3] = ((uint8_t*)&yval)[0]; dstbuf[4] = ((uint8_t*)&yval)[1]; - buttons = mappings_do(MAPPING_N64_DEFAULT, n64_data->buttons); - btnsToReport(buttons, dstbuf+13); + usb_buttons = mappings_do(MAPPING_N64_DEFAULT, n64_buttons); + btnsToReport(usb_buttons, dstbuf+13); } void usbpad_update(struct usbpad *pad, const gamepad_data *pad_data)